Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
ImmersedBoundaryLinearInteractionForce.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 "ImmersedBoundaryLinearInteractionForce.hpp"
37#include "ImmersedBoundaryEnumerations.hpp"
38
39template <unsigned DIM>
42 mSpringConst(1e3),
43 mRestLength(0.25),
44 mLaminaSpringConstMult(1.0),
45 mLaminaRestLengthMult(1.0)
46{
47}
48
49template<unsigned DIM>
53
54template <unsigned DIM>
56 std::vector<std::pair<Node<DIM>*, Node<DIM>*> >& rNodePairs,
58{
59 for (unsigned pair = 0; pair < rNodePairs.size(); ++pair)
60 {
61 /*
62 * Interactions only exist between pairs of nodes that are not in the
63 * same boundary / lamina.
64 */
65 if (rCellPopulation.rGetMesh().NodesInDifferentElementOrLamina(rNodePairs[pair].first, rNodePairs[pair].second))
66 {
67 Node<DIM>* p_node_a = rNodePairs[pair].first;
68 Node<DIM>* p_node_b = rNodePairs[pair].second;
69
70 c_vector<double, DIM> vec_a2b = rCellPopulation.rGetMesh().GetVectorFromAtoB(p_node_a->rGetLocation(),
71 p_node_b->rGetLocation());
72 double normed_dist = norm_2(vec_a2b);
73
74 // Force non-zero only within interaction distance, by definition
75 if (normed_dist < rCellPopulation.GetInteractionDistance())
76 {
77 // Need the average spacing of the containing element; this depends on whether it's a lamina or element
78 bool a_lamina = p_node_a->GetRegion() == LAMINA_REGION;
79 bool b_lamina = p_node_b->GetRegion() == LAMINA_REGION;
80
81 unsigned a_idx = *(p_node_a->ContainingElementsBegin());
82 unsigned b_idx = *(p_node_b->ContainingElementsBegin());
83
84 double node_a_elem_spacing = a_lamina ? rCellPopulation.rGetMesh().GetAverageNodeSpacingOfLamina(a_idx, false)
85 : rCellPopulation.rGetMesh().GetAverageNodeSpacingOfElement(a_idx, false);
86
87 double node_b_elem_spacing = b_lamina ? rCellPopulation.rGetMesh().GetAverageNodeSpacingOfLamina(b_idx, false)
88 : rCellPopulation.rGetMesh().GetAverageNodeSpacingOfElement(b_idx, false);
89
90 double elem_spacing = 0.5 * (node_a_elem_spacing + node_b_elem_spacing);
91
92 double eff_spring_const = mSpringConst * elem_spacing / rCellPopulation.GetIntrinsicSpacing();
93 double eff_rest_length = mRestLength * rCellPopulation.GetInteractionDistance();
94
95 if (a_lamina || b_lamina)
96 {
97 eff_spring_const *= mLaminaSpringConstMult;
98 eff_rest_length *= mLaminaRestLengthMult;
99 }
100
101 /*
102 * We must scale each applied force by a factor of elem_spacing
103 * / local spacing, so that forces balance when spread to the
104 * grid later (where the multiplicative factor is the local
105 * spacing).
106 */
107 vec_a2b *= eff_spring_const * (normed_dist - eff_rest_length) / normed_dist;
108
109 c_vector<double, DIM> force_a2b = vec_a2b * (elem_spacing / node_a_elem_spacing);
110 p_node_a->AddAppliedForceContribution(force_a2b);
111
112 c_vector<double, DIM> force_b2a = vec_a2b * (-1.0 * elem_spacing / node_b_elem_spacing);
113 p_node_b->AddAppliedForceContribution(force_b2a);
114 }
115 }
116 }
117
118 if (this->mAdditiveNormalNoise)
119 {
120 this->AddNormalNoiseToNodes(rCellPopulation);
121 }
122}
123
124
125template<unsigned DIM>
127 out_stream& rParamsFile)
128{
129 *rParamsFile << "\t\t\t<SpringConstant>" << mSpringConst << "</SpringConstant>\n";
130 *rParamsFile << "\t\t\t<RestLength>" << mRestLength << "</RestLength>\n";
131 *rParamsFile << "\t\t\t<LaminaSpringConstMult>" << mLaminaSpringConstMult << "</LaminaSpringConstMult>\n";
132 *rParamsFile << "\t\t\t<LaminaRestLengthMult>" << mLaminaRestLengthMult << "</LaminaRestLengthMult>\n";
133
134 // Call method on direct parent class
136}
137
138template<unsigned DIM>
140{
141 return mSpringConst;
142}
143
144template<unsigned DIM>
146 double springConst)
147{
148 mSpringConst = springConst;
149}
150
151template<unsigned DIM>
153{
154 return mRestLength;
155}
156
157template<unsigned DIM>
159{
160 mRestLength = restLength;
161}
162
163template<unsigned DIM>
165{
166 return mLaminaSpringConstMult;
167}
168
169template<unsigned DIM>
171 double laminaSpringConstMult)
172{
173 mLaminaSpringConstMult = laminaSpringConstMult;
174}
175
176template<unsigned DIM>
178{
179 return mLaminaRestLengthMult;
180}
181
182template<unsigned DIM>
184 double laminaRestLengthMult)
185{
186 mLaminaRestLengthMult = laminaRestLengthMult;
187}
188
189// Explicit instantiation
193
194// Serialization for Boost >= 1.36
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
virtual void OutputImmersedBoundaryForceParameters(out_stream &rParamsFile)=0
ImmersedBoundaryMesh< DIM, DIM > & rGetMesh()
void AddImmersedBoundaryForceContribution(std::vector< std::pair< Node< DIM > *, Node< DIM > * > > &rNodePairs, ImmersedBoundaryCellPopulation< DIM > &rCellPopulation)
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)
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