Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
ChastePoint.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "ChastePoint.hpp"
37#include "Exception.hpp"
38
40// Implementation
42
43template<unsigned DIM>
44ChastePoint<DIM>::ChastePoint(double v1, double v2, double v3)
45{
46 if (DIM > 0)
47 {
48 mLocation[0] = v1;
49 }
50 if (DIM > 1)
51 {
52 mLocation[1] = v2;
53 }
54 if (DIM > 2)
55 {
56 mLocation[2] = v3;
57 }
58}
59
60template<unsigned DIM>
61ChastePoint<DIM>::ChastePoint(std::vector<double> coords)
62{
63 for (unsigned i=0; i<DIM; i++)
64 {
65 mLocation(i) = coords.at(i);
66 }
67}
68
69template<unsigned DIM>
70ChastePoint<DIM>::ChastePoint(c_vector<double, DIM> location)
71 : mLocation(location)
72{
73}
74
75template<unsigned DIM>
76c_vector<double, DIM>& ChastePoint<DIM>::rGetLocation()
77{
78 return mLocation;
79}
80
81template<unsigned DIM>
82const c_vector<double, DIM>& ChastePoint<DIM>::rGetLocation() const
83{
84 return mLocation;
85}
87template<unsigned DIM>
88double ChastePoint<DIM>::operator[] (unsigned i) const
89{
90 assert(i<DIM);
91 return mLocation(i);
92}
93
94template<unsigned DIM>
95double ChastePoint<DIM>::GetWithDefault(unsigned i, double def) const
96{
97 if (i<DIM)
98 {
99 return mLocation(i);
100 }
101 else
103 return def;
104 }
105}
106
107template<unsigned DIM>
108void ChastePoint<DIM>::SetCoordinate(unsigned i, double value)
109{
110 assert(i < DIM);
111 mLocation(i) = value;
113
114template<unsigned DIM>
116{
117 bool returned_value = true;
118 for (unsigned dim=0; dim<DIM; dim++)
120 if (rPoint[dim] != mLocation[dim])
121 {
122 returned_value = false;
123 break;
124 }
125 }
126 return returned_value;
127}
128
129// Methods of the 0d version
130
131ChastePoint<0>::ChastePoint(double v1, double v2, double v3)
132{
133}
135double ChastePoint<0>::operator[] (unsigned i) const
136{
137 EXCEPTION("Zero-dimensional point has no data");
138}
139
140// Explicit instantiation
141template class ChastePoint<1>;
142template class ChastePoint<2>;
143template class ChastePoint<3>;
144
145// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
c_vector< double, DIM > & rGetLocation()
double operator[](unsigned i) const
ChastePoint(double v1=0, double v2=0, double v3=0)
bool IsSamePoint(const ChastePoint< DIM > &rPoint) const
double GetWithDefault(unsigned i, double def=0.0) const
void SetCoordinate(unsigned i, double value)