Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
PlaneBoundaryCondition.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 "PlaneBoundaryCondition.hpp"
37#include "AbstractCentreBasedCellPopulation.hpp"
38#include "VertexBasedCellPopulation.hpp"
39
40template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
42 c_vector<double, SPACE_DIM> point,
43 c_vector<double, SPACE_DIM> normal)
44 : AbstractCellPopulationBoundaryCondition<ELEMENT_DIM,SPACE_DIM>(pCellPopulation),
45 mPointOnPlane(point),
46 mUseJiggledNodesOnPlane(false)
47{
48 assert(norm_2(normal) > 0.0);
49 mNormalToPlane = normal/norm_2(normal);
50}
51
52template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
54{
55 return mPointOnPlane;
56}
57
58template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
60{
61 return mNormalToPlane;
62}
63
64
65template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
67{
68 mUseJiggledNodesOnPlane = useJiggledNodesOnPlane;
69}
70
71template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
73{
74 return mUseJiggledNodesOnPlane;
75}
76
77template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
79 [[maybe_unused]] const std::map<Node<SPACE_DIM>*, c_vector<double, SPACE_DIM> >& rOldLocations)
80{
81 if constexpr ((SPACE_DIM == 2) || (SPACE_DIM == 3))
82 {
84 if (dynamic_cast<AbstractOffLatticeCellPopulation<ELEMENT_DIM,SPACE_DIM>*>(this->mpCellPopulation)==nullptr)
85 {
86 EXCEPTION("PlaneBoundaryCondition requires a subclass of AbstractOffLatticeCellPopulation.");
87 }
88
89 assert((dynamic_cast<AbstractCentreBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>*>(this->mpCellPopulation))
90 || (SPACE_DIM==ELEMENT_DIM && (dynamic_cast<VertexBasedCellPopulation<SPACE_DIM>*>(this->mpCellPopulation))) );
91
92 // This is a magic number
93 double max_jiggle = 1e-4;
94
95 if (dynamic_cast<AbstractCentreBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>*>(this->mpCellPopulation))
96 {
97 for (typename AbstractCellPopulation<ELEMENT_DIM,SPACE_DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
98 cell_iter != this->mpCellPopulation->End();
99 ++cell_iter)
100 {
101 unsigned node_index = this->mpCellPopulation->GetLocationIndexUsingCell(*cell_iter);
102 Node<SPACE_DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
103
104 c_vector<double, SPACE_DIM> node_location = p_node->rGetLocation();
105
106 double signed_distance = inner_prod(node_location - mPointOnPlane, mNormalToPlane);
107 if (signed_distance > 0.0)
108 {
109 // For the closest point on the plane we travel from node_location the signed_distance in the direction of -mNormalToPlane
110 c_vector<double, SPACE_DIM> nearest_point;
111 if (mUseJiggledNodesOnPlane)
112 {
113 nearest_point = node_location - (signed_distance+max_jiggle*RandomNumberGenerator::Instance()->ranf())*mNormalToPlane;
114 }
115 else
116 {
117 nearest_point = node_location - signed_distance*mNormalToPlane;
118 }
119 p_node->rGetModifiableLocation() = nearest_point;
120 }
121 }
122 }
123 else
124 {
125 assert(SPACE_DIM == ELEMENT_DIM); // LCOV_EXCL_LINE
126 assert(dynamic_cast<VertexBasedCellPopulation<SPACE_DIM>*>(this->mpCellPopulation));
127
128 // Iterate over all nodes and update their positions according to the boundary conditions
129 unsigned num_nodes = this->mpCellPopulation->GetNumNodes();
130 for (unsigned node_index=0; node_index<num_nodes; node_index++)
131 {
132 Node<SPACE_DIM>* p_node = this->mpCellPopulation->GetNode(node_index);
133 c_vector<double, SPACE_DIM> node_location = p_node->rGetLocation();
134
135 double signed_distance = inner_prod(node_location - mPointOnPlane, mNormalToPlane);
136 if (signed_distance > 0.0)
137 {
138 // For the closest point on the plane we travel from node_location the signed_distance in the direction of -mNormalToPlane
139 c_vector<double, SPACE_DIM> nearest_point;
140 if (mUseJiggledNodesOnPlane)
141 {
142 nearest_point = node_location - (signed_distance+max_jiggle*RandomNumberGenerator::Instance()->ranf())*mNormalToPlane;
143 }
144 else
145 {
146 nearest_point = node_location - signed_distance*mNormalToPlane;
147 }
148 p_node->rGetModifiableLocation() = nearest_point;
149 }
150 }
151 }
152 }
153 else
154 {
156 }
157}
158
159template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
161{
162 bool condition_satisfied = true;
163
164 if (SPACE_DIM == 1)
165 {
166 EXCEPTION("PlaneBoundaryCondition is not implemented in 1D");
167 }
168 else
169 {
170 for (typename AbstractCellPopulation<ELEMENT_DIM, SPACE_DIM>::Iterator cell_iter = this->mpCellPopulation->Begin();
171 cell_iter != this->mpCellPopulation->End();
172 ++cell_iter)
173 {
174 c_vector<double, SPACE_DIM> cell_location = this->mpCellPopulation->GetLocationOfCellCentre(*cell_iter);
175
176 if (inner_prod(cell_location - mPointOnPlane, mNormalToPlane) > 0.0)
177 {
178 condition_satisfied = false;
179 break;
180 }
181 }
182 }
183
184 return condition_satisfied;
185}
186
187template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
189{
190 *rParamsFile << "\t\t\t<PointOnPlane>";
191 for (unsigned index=0; index != SPACE_DIM-1U; index++) // Note: inequality avoids testing index < 0U when DIM=1
192 {
193 *rParamsFile << mPointOnPlane[index] << ",";
194 }
195 *rParamsFile << mPointOnPlane[SPACE_DIM-1] << "</PointOnPlane>\n";
196
197 *rParamsFile << "\t\t\t<NormalToPlane>";
198 for (unsigned index=0; index != SPACE_DIM-1U; index++) // Note: inequality avoids testing index < 0U when DIM=1
199 {
200 *rParamsFile << mNormalToPlane[index] << ",";
201 }
202 *rParamsFile << mNormalToPlane[SPACE_DIM-1] << "</NormalToPlane>\n";
203 *rParamsFile << "\t\t\t<UseJiggledNodesOnPlane>" << mUseJiggledNodesOnPlane << "</UseJiggledNodesOnPlane>\n";
204
205 // Call method on direct parent class
207}
208
209// Explicit instantiation
210template class PlaneBoundaryCondition<1,1>;
211template class PlaneBoundaryCondition<1,2>;
212template class PlaneBoundaryCondition<2,2>;
213template class PlaneBoundaryCondition<1,3>;
214template class PlaneBoundaryCondition<2,3>;
215template class PlaneBoundaryCondition<3,3>;
216
217// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define NEVER_REACHED
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
virtual void OutputCellPopulationBoundaryConditionParameters(out_stream &rParamsFile)=0
Definition Node.hpp:59
c_vector< double, SPACE_DIM > & rGetModifiableLocation()
Definition Node.cpp:151
const c_vector< double, SPACE_DIM > & rGetLocation() const
Definition Node.cpp:139
const c_vector< double, SPACE_DIM > & rGetNormalToPlane() const
void ImposeBoundaryCondition(const std::map< Node< SPACE_DIM > *, c_vector< double, SPACE_DIM > > &rOldLocations)
void OutputCellPopulationBoundaryConditionParameters(out_stream &rParamsFile)
PlaneBoundaryCondition(AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > *pCellPopulation, c_vector< double, SPACE_DIM > point, c_vector< double, SPACE_DIM > normal)
c_vector< double, SPACE_DIM > mNormalToPlane
const c_vector< double, SPACE_DIM > & rGetPointOnPlane() const
void SetUseJiggledNodesOnPlane(bool useJiggledNodesOnPlane)
static RandomNumberGenerator * Instance()