Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
ChastePoint.hpp
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
37#ifndef _CHASTEPOINT_HPP_
38#define _CHASTEPOINT_HPP_
39
42#include <vector>
43
44
48template<unsigned DIM>
50{
59 template<class Archive>
60 void serialize(Archive & archive, const unsigned int version)
61 {
62 //archive & mLocation; //earlier versions of boost are unable to do this. See #1709
63 }
64
65private:
66
68 c_vector<double, DIM> mLocation;
69
70public:
71
86 ChastePoint(double v1=0, double v2=0, double v3=0);
87
95 ChastePoint(std::vector<double> coords);
96
102 ChastePoint(c_vector<double, DIM> location);
103
107 c_vector<double, DIM>& rGetLocation();
108
112 const c_vector<double, DIM>& rGetLocation() const;
113
119 double operator[] (unsigned i) const;
120
126 double GetWithDefault(unsigned i, double def=0.0) const;
127
134 void SetCoordinate(unsigned i, double value);
135
142 bool IsSamePoint(const ChastePoint<DIM>& rPoint) const;
143};
144
145
147// Declare identifier for the serializer
149
150namespace boost
151{
152namespace serialization
153{
154
155template<class Archive, unsigned SPACE_DIM>
156inline void save_construct_data(
157 Archive & ar, const ChastePoint<SPACE_DIM> * t, const unsigned int file_version)
158{
159 for (unsigned i = 0; i < SPACE_DIM; i ++)
160 {
161 //we archive coordinates of mLocation one by one
162 //this is because earlier version of boost (<1.40, I think) cannot archive c_vectors
163 double coord = t->GetWithDefault(i);
164 ar & coord;
165 }
166}
167
172template<class Archive,unsigned SPACE_DIM>
173inline void load_construct_data(
174 Archive & ar, ChastePoint<SPACE_DIM> * t, const unsigned int file_version)
175{
176 std::vector<double> coords;
177 coords.resize(SPACE_DIM);
178 for (unsigned i=0; i<SPACE_DIM; i++)
179 {
180 double coordinate;
181 ar & coordinate;//resume coordinates one by one
182 coords[i] = coordinate;
183 }
184 //use constructor with standard vectors to re-build the object
185 ::new(t)ChastePoint<SPACE_DIM>(coords);
186}
187}
188} // namespace ...
189
190
196template<>
198{
199public:
208 ChastePoint(double v1=0, double v2=0, double v3=0);
209
216 double operator[] (unsigned i) const;
217};
218
219#endif //_CHASTEPOINT_HPP_
gcov doesn't like this file...
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
c_vector< double, DIM > mLocation
void serialize(Archive &archive, const unsigned int version)
c_vector< double, DIM > & rGetLocation()
double operator[](unsigned i) const
bool IsSamePoint(const ChastePoint< DIM > &rPoint) const
friend class boost::serialization::access
double GetWithDefault(unsigned i, double def=0.0) const
void SetCoordinate(unsigned i, double value)