Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
ImmersedBoundaryMorseInteractionForce.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 "ImmersedBoundaryMorseInteractionForce.hpp"
37#include "ImmersedBoundaryEnumerations.hpp"
38
39template <unsigned DIM>
42 mWellDepth(1e3),
43 mRestLength(0.25),
44 mLaminaWellDepthMult(1.0),
45 mLaminaRestLengthMult(1.0),
46 mWellWidth(0.25)
47{
48}
49
50template <unsigned DIM>
54
55template <unsigned DIM>
57 std::vector<std::pair<Node<DIM>*, Node<DIM>*> >& rNodePairs,
59{
60 for (unsigned pair = 0; pair < rNodePairs.size(); ++pair)
61 {
62 // Interactions only exist between pairs of nodes that are not in the same boundary / lamina
63 if (rCellPopulation.rGetMesh().NodesInDifferentElementOrLamina(rNodePairs[pair].first, rNodePairs[pair].second))
64 {
65 Node<DIM>* p_node_a = rNodePairs[pair].first;
66 Node<DIM>* p_node_b = rNodePairs[pair].second;
67
68 c_vector<double, DIM> vec_a2b = rCellPopulation.rGetMesh().GetVectorFromAtoB(p_node_a->rGetLocation(),
69 p_node_b->rGetLocation());
70 double normed_dist = norm_2(vec_a2b);
71
72 // Force non-zero only within interaction distance, by definition
73 if (normed_dist < rCellPopulation.GetInteractionDistance())
74 {
75 // Need the average spacing of the containing element; this depends on whether it's a lamina or element
76 bool a_lamina = p_node_a->GetRegion() == LAMINA_REGION;
77 bool b_lamina = p_node_b->GetRegion() == LAMINA_REGION;
78
79 unsigned a_idx = *(p_node_a->ContainingElementsBegin());
80 unsigned b_idx = *(p_node_b->ContainingElementsBegin());
81
82 double node_a_elem_spacing = a_lamina ? rCellPopulation.rGetMesh().GetAverageNodeSpacingOfLamina(a_idx, false)
83 : rCellPopulation.rGetMesh().GetAverageNodeSpacingOfElement(a_idx, false);
84
85 double node_b_elem_spacing = b_lamina ? rCellPopulation.rGetMesh().GetAverageNodeSpacingOfLamina(b_idx, false)
86 : rCellPopulation.rGetMesh().GetAverageNodeSpacingOfElement(b_idx, false);
87
88 double elem_spacing = 0.5 * (node_a_elem_spacing + node_b_elem_spacing);
89
90 double eff_well_depth = mWellDepth * elem_spacing / rCellPopulation.GetIntrinsicSpacing();
91 double eff_rest_length = mRestLength * rCellPopulation.GetInteractionDistance();
92 double eff_well_width = mWellWidth * rCellPopulation.GetInteractionDistance();
93
94 if (a_lamina || b_lamina)
95 {
96 eff_well_depth *= mLaminaWellDepthMult;
97 eff_rest_length *= mLaminaRestLengthMult;
98
99 // Bit of a hack
100 bool apical_lam = (a_lamina && p_node_a->rGetLocation()[1] > 0.5) ||
101 (b_lamina && p_node_b->rGetLocation()[1] > 0.5);
102
103 if (apical_lam)
104 {
105 eff_well_depth *= 1.0;
106 }
107 }
108
109 double morse_exp = exp((eff_rest_length - normed_dist) / eff_well_width);
110
111 /*
112 * We must scale each applied force by a factor of elem_spacing / local spacing, so that forces
113 * balance when spread to the grid later (where the multiplicative factor is the local spacing)
114 */
115 vec_a2b *= 2.0 * eff_well_width * eff_well_depth * morse_exp * (1.0 - morse_exp) / normed_dist;
116
117 c_vector<double, DIM> force_a2b = vec_a2b * (elem_spacing / node_a_elem_spacing);
118 p_node_a->AddAppliedForceContribution(force_a2b);
119
120 c_vector<double, DIM> force_b2a = vec_a2b * (-1.0 * elem_spacing / node_b_elem_spacing);
121 p_node_b->AddAppliedForceContribution(force_b2a);
122 }
123 }
124 }
125
126 if (this->mAdditiveNormalNoise)
127 {
128 this->AddNormalNoiseToNodes(rCellPopulation);
129 }
130}
131
132template <unsigned DIM>
134 out_stream& rParamsFile)
135{
136 *rParamsFile << "\t\t\t<WellDepth>" << mWellDepth << "</WellDepth>\n";
137 *rParamsFile << "\t\t\t<RestLength>" << mRestLength << "</RestLength>\n";
138 *rParamsFile << "\t\t\t<LaminaWellDepthMult>" << mLaminaWellDepthMult << "</LaminaWellDepthMult>\n";
139 *rParamsFile << "\t\t\t<LaminaRestLengthMult>" << mLaminaRestLengthMult << "</LaminaRestLengthMult>\n";
140 *rParamsFile << "\t\t\t<WellWidth>" << mWellWidth << "</WellWidth>\n";
141
142 // Call method on direct parent class
144}
145
146template <unsigned DIM>
148{
149 return mWellDepth;
150}
151
152template <unsigned DIM>
154{
155 mWellDepth = wellDepth;
156}
157
158template <unsigned DIM>
160{
161 return mRestLength;
162}
163
164template <unsigned DIM>
166{
167 mRestLength = restLength;
168}
169
170template <unsigned DIM>
172{
173 return mLaminaWellDepthMult;
174}
175
176template <unsigned DIM>
178 double laminaWellDepthMult)
179{
180 mLaminaWellDepthMult = laminaWellDepthMult;
181}
182
183template <unsigned DIM>
185{
186 return mLaminaRestLengthMult;
187}
188
189template <unsigned DIM>
191 double laminaRestLengthMult)
192{
193 mLaminaRestLengthMult = laminaRestLengthMult;
194}
195
196template <unsigned DIM>
198{
199 return mWellWidth;
200}
201
202template <unsigned DIM>
204{
205 mWellWidth = wellWidth;
206}
207
208// Explicit instantiation
212
213// Serialization for Boost >= 1.36
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
virtual void OutputImmersedBoundaryForceParameters(out_stream &rParamsFile)=0
ImmersedBoundaryMesh< DIM, DIM > & rGetMesh()
bool NodesInDifferentElementOrLamina(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
double GetAverageNodeSpacingOfElement(unsigned index, bool recalculate=true)
double GetAverageNodeSpacingOfLamina(unsigned index, bool recalculate=true)
c_vector< double, SPACE_DIM > GetVectorFromAtoB(const c_vector< double, SPACE_DIM > &rLocation1, const c_vector< double, SPACE_DIM > &rLocation2)
void AddImmersedBoundaryForceContribution(std::vector< std::pair< Node< DIM > *, Node< DIM > * > > &rNodePairs, ImmersedBoundaryCellPopulation< DIM > &rCellPopulation)
Definition Node.hpp:59
ContainingElementIterator ContainingElementsBegin() const
Definition Node.hpp:485
const c_vector< double, SPACE_DIM > & rGetLocation() const
Definition Node.cpp:139
void AddAppliedForceContribution(const c_vector< double, SPACE_DIM > &rForceContribution)
Definition Node.cpp:224
unsigned GetRegion() const
Definition Node.cpp:437