Chaste  Release::2018.1
SphereGeometryBoundaryCondition.cpp
1 /*
2 
3 Copyright (c) 2005-2018, 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 #include "SphereGeometryBoundaryCondition.hpp"
37 #include "NodeBasedCellPopulation.hpp"
38 
39 template<unsigned DIM>
41  c_vector<double, DIM> centre,
42  double radius,
43  double distance)
44  : AbstractCellPopulationBoundaryCondition<DIM>(pCellPopulation),
45  mCentreOfSphere(centre),
46  mRadiusOfSphere(radius),
47  mMaximumDistance(distance)
48 {
49  assert(mRadiusOfSphere > 0.0);
50  assert(mMaximumDistance > 0.0);
51 
52  if (dynamic_cast<NodeBasedCellPopulation<DIM>*>(this->mpCellPopulation) == nullptr)
53  {
54  EXCEPTION("A NodeBasedCellPopulation must be used with this boundary condition object.");
55  }
56  if (DIM == 1)
57  {
58  EXCEPTION("This boundary condition is not implemented in 1D.");
59  }
60 }
61 
62 template<unsigned DIM>
64 {
65  return mCentreOfSphere;
66 }
67 
68 template<unsigned DIM>
70 {
71  return mRadiusOfSphere;
72 }
73 
74 template<unsigned DIM>
75 void SphereGeometryBoundaryCondition<DIM>::ImposeBoundaryCondition(const std::map<Node<DIM>*, c_vector<double, DIM> >& rOldLocations)
76 {
77  // Iterate over the cell population
78  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
79  cell_iter != this->mpCellPopulation->End();
80  ++cell_iter)
81  {
82  // Find the radial distance between this cell and the surface of the sphere
83  c_vector<double,DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
84  double radius = norm_2(cell_location - mCentreOfSphere);
85  assert(radius != 0.0); //Can't project the centre to anywhere sensible
86 
87  // If the cell is too far from the surface of the sphere...
88  if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
89  {
90  // ...move the cell back onto the surface of the sphere
91  c_vector<double, DIM> location_on_sphere =
92  mCentreOfSphere + mRadiusOfSphere*(cell_location - mCentreOfSphere)/radius;
93 
94  unsigned node_index = this->mpCellPopulation->GetLocationIndexUsingCell(*cell_iter);
95  Node<DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
96 
97  p_node->rGetModifiableLocation() = location_on_sphere;
98  }
99  }
100 }
101 
102 template<unsigned DIM>
104 {
105  bool condition_satisfied = true;
106 
107  // Iterate over the cell population
108  for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
109  cell_iter != this->mpCellPopulation->End();
110  ++cell_iter)
111  {
112  // Find the radial distance between this cell and the surface of the sphere
113  c_vector<double,DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
114  double radius = norm_2(cell_location - mCentreOfSphere);
115 
116  // If the cell is too far from the surface of the sphere...
117  if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
118  {
119  // ...then the boundary condition is not satisfied
120  condition_satisfied = false;
121  break;
122  }
123  }
124  return condition_satisfied;
125 }
126 
127 template<unsigned DIM>
129 {
130  *rParamsFile << "\t\t\t<CentreOfSphere>";
131  for (unsigned index=0; index != DIM-1U; index++) // Note: inequality avoids testing index < 0U when DIM=1
132  {
133  *rParamsFile << mCentreOfSphere[index] << ",";
134  }
135  *rParamsFile << mCentreOfSphere[DIM-1] << "</CentreOfSphere>\n";
136 
137  *rParamsFile << "\t\t\t<RadiusOfSphere>" << mRadiusOfSphere << "</RadiusOfSphere>\n";
138  *rParamsFile << "\t\t\t<MaximumDistance>" << mMaximumDistance << "</MaximumDistance>\n";
139 
140  // Call method on direct parent class
142 }
143 
144 // Explicit instantiation
148 
149 // Serialization for Boost >= 1.36
AbstractCellPopulation< ELEMENT_DIM, ELEMENT_DIM > * mpCellPopulation
Definition: Node.hpp:58
void ImposeBoundaryCondition(const std::map< Node< DIM > *, c_vector< double, DIM > > &rOldLocations)
#define EXCEPTION(message)
Definition: Exception.hpp:143
void OutputCellPopulationBoundaryConditionParameters(out_stream &rParamsFile)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
SphereGeometryBoundaryCondition(AbstractCellPopulation< DIM > *pCellPopulation, c_vector< double, DIM > centre, double radius, double distance=1e-5)
c_vector< double, SPACE_DIM > & rGetModifiableLocation()
Definition: Node.cpp:151
virtual void OutputCellPopulationBoundaryConditionParameters(out_stream &rParamsFile)=0
const c_vector< double, DIM > & rGetCentreOfSphere() const