Chaste Commit::6e4f5fe395bca70eb7641cf6e0e87f450383ca5a
SphereGeometryBoundaryCondition.cpp
1/*
2
3Copyright (c) 2005-2026, 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 "SphereGeometryBoundaryCondition.hpp"
37#include "NodeBasedCellPopulation.hpp"
38
39template<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
62template<unsigned DIM>
64{
65 return mCentreOfSphere;
66}
67
68template<unsigned DIM>
70{
71 return mRadiusOfSphere;
72}
73
74template<unsigned DIM>
75void 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 = mCentreOfSphere + mRadiusOfSphere*(cell_location - mCentreOfSphere)/radius;
92
93 unsigned node_index = this->mpCellPopulation->GetLocationIndexUsingCell(*cell_iter);
94 Node<DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
95
96 p_node->rGetModifiableLocation() = location_on_sphere;
97 }
98 }
99}
100
101template<unsigned DIM>
103{
104 bool condition_satisfied = true;
105
106 // Iterate over the cell population
107 for (typename AbstractCellPopulation<DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
108 cell_iter != this->mpCellPopulation->End();
109 ++cell_iter)
110 {
111 // Find the radial distance between this cell and the surface of the sphere
112 c_vector<double,DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
113 double radius = norm_2(cell_location - mCentreOfSphere);
114
115 // If the cell is too far from the surface of the sphere...
116 if (fabs(radius - mRadiusOfSphere) > mMaximumDistance)
117 {
118 // ...then the boundary condition is not satisfied
119 condition_satisfied = false;
120 break;
121 }
122 }
123 return condition_satisfied;
124}
125
126template<unsigned DIM>
128{
129 *rParamsFile << "\t\t\t<CentreOfSphere>";
130 for (unsigned index=0; index != DIM-1U; index++) // Note: inequality avoids testing index < 0U when DIM=1
131 {
132 *rParamsFile << mCentreOfSphere[index] << ",";
133 }
134 *rParamsFile << mCentreOfSphere[DIM-1] << "</CentreOfSphere>\n";
135
136 *rParamsFile << "\t\t\t<RadiusOfSphere>" << mRadiusOfSphere << "</RadiusOfSphere>\n";
137 *rParamsFile << "\t\t\t<MaximumDistance>" << mMaximumDistance << "</MaximumDistance>\n";
138
139 // Call method on direct parent class
141}
142
143// Explicit instantiation
147
148// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
AbstractCellPopulation< ELEMENT_DIM, ELEMENT_DIM > * mpCellPopulation
virtual void OutputCellPopulationBoundaryConditionParameters(out_stream &rParamsFile)=0
Definition Node.hpp:59
c_vector< double, SPACE_DIM > & rGetModifiableLocation()
Definition Node.cpp:151
void ImposeBoundaryCondition(const std::map< Node< DIM > *, c_vector< double, DIM > > &rOldLocations)
void OutputCellPopulationBoundaryConditionParameters(out_stream &rParamsFile)
const c_vector< double, DIM > & rGetCentreOfSphere() const
SphereGeometryBoundaryCondition(AbstractCellPopulation< DIM > *pCellPopulation, c_vector< double, DIM > centre, double radius, double distance=1e-5)