Chaste  Release::2024.1
PeriodicNodesOnlyMesh.hpp
1 /*
2 
3 Copyright (c) 2005-2021, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #ifndef PERIODICNODESONLYMESH_HPP_
37 #define PERIODICNODESONLYMESH_HPP_
38 
39 #include "ChasteSerialization.hpp"
40 #include <boost/serialization/base_object.hpp>
41 
42 #include "NodesOnlyMesh.hpp"
43 
52 template<unsigned SPACE_DIM>
53 class PeriodicNodesOnlyMesh: public NodesOnlyMesh<SPACE_DIM>
54 {
55 private:
59  c_vector<double,SPACE_DIM> mWidth;
60 
61  /*
62  * Whether a dimension is periodic
63  */
64  c_vector<bool,SPACE_DIM> mIsDimPeriodic;
65 
66  friend class TestPeriodicNodesOnlyMesh;
67 
81  template<class Archive>
82  void serialize(Archive & archive, const unsigned int version)
83  {
84  archive & boost::serialization::base_object<NodesOnlyMesh<SPACE_DIM> >(*this);
85  archive & mWidth;
86  archive & mIsDimPeriodic;
87  }
88 
89 public:
90 
97  PeriodicNodesOnlyMesh(c_vector<double,SPACE_DIM> width);
98 
107  virtual void SetUpBoxCollection(double cutOffLength, c_vector<double, 2*SPACE_DIM> domainSize, int numLocalRows = PETSC_DECIDE, c_vector<bool,SPACE_DIM> isDimPeriodic = zero_vector<bool>(SPACE_DIM));
108 
119  c_vector<double, SPACE_DIM> GetVectorFromAtoB(const c_vector<double, SPACE_DIM>& rLocation1, const c_vector<double, SPACE_DIM>& rLocation2);
120 
130  double GetWidth(const unsigned& rDimension) const;
131 
132  /*
133  * Method to get the width of the periodic dimensions
134  * @return The value of the mWidth vector
135  */
136  c_vector<double,SPACE_DIM> GetPeriodicWidths() const;
137 
138  /*
139  * Overridden SetNode() method.
140  *
141  * If the location should be set outside a cylindrical boundary
142  * move it back onto the cylinder.
143  *
144  * @param nodeIndex is the index of the node to be moved
145  * @param point is the new target location of the node
146  * @param concreteMove is set to false if we want to skip the signed area tests in the parent Class Note this should always be false here
147  */
148 
149  void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM> point, bool concreteMove = false);
150 
157  unsigned AddNode(Node<SPACE_DIM>* pNewNode);
158 
165  void RefreshMesh();
166 };
167 
168 namespace boost
169 {
170 namespace serialization
171 {
175 template<class Archive, unsigned SPACE_DIM>
176 inline void save_construct_data(
177  Archive & ar, const PeriodicNodesOnlyMesh<SPACE_DIM> * t, const unsigned int file_version)
178 {
179  // Save data required to construct instance
180  const c_vector<double,SPACE_DIM> width = t->GetPeriodicWidths();
181  for ( unsigned i=0; i < SPACE_DIM; i++ )
182  {
183  ar << width(i);
184  }
185 }
186 
190 template<class Archive, unsigned SPACE_DIM>
191 inline void load_construct_data(
192  Archive & ar, PeriodicNodesOnlyMesh<SPACE_DIM> * t, const unsigned int file_version)
193 {
194  // Retrieve data from archive required to construct new instance of the mesh
195  c_vector<double,SPACE_DIM> width;
196  for (unsigned i=0; i<SPACE_DIM; i++)
197  {
198  double current_width;
199  ar & current_width;
200  width(i) = current_width;
201  }
202 
203  // Invoke inplace constructor to initialise instance
204  ::new(t)PeriodicNodesOnlyMesh<SPACE_DIM>(width);
205 }
206 }
207 } // namespace ...
208 
211 
212 #endif /*PERIODICNODESONLYMESH_HPP_*/
Definition: Node.hpp:58
virtual void SetUpBoxCollection(double cutOffLength, c_vector< double, 2 *SPACE_DIM > domainSize, int numLocalRows=PETSC_DECIDE, c_vector< bool, SPACE_DIM > isDimPeriodic=zero_vector< bool >(SPACE_DIM))
c_vector< double, SPACE_DIM > mWidth
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void SetNode(unsigned nodeIndex, ChastePoint< SPACE_DIM > point, bool concreteMove=false)
void serialize(Archive &archive, const unsigned int version)
friend class boost::serialization::access
PeriodicNodesOnlyMesh(c_vector< double, SPACE_DIM > width)
unsigned AddNode(Node< SPACE_DIM > *pNewNode)
double GetWidth(const unsigned &rDimension) const
gcov doesn&#39;t like this file...
c_vector< double, SPACE_DIM > GetVectorFromAtoB(const c_vector< double, SPACE_DIM > &rLocation1, const c_vector< double, SPACE_DIM > &rLocation2)