Chaste Commit::8b5d759ac2eb95e67ae57699734101efccb0a0a9
ImmersedBoundaryLinearDifferentialAdhesionForce.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 "ImmersedBoundaryLinearDifferentialAdhesionForce.hpp"
37
38#include "CellLabel.hpp"
39
40template <unsigned DIM>
43 mLabelledCellToLabelledCellSpringConst(1e3),
44 mLabelledCellToCellSpringConst(1e3),
45 mCellToCellSpringConst(1e3),
46 mRestLength(0.25)
47{
48}
49
50template <unsigned DIM>
52 std::vector<std::pair<Node<DIM>*, Node<DIM>*> >& rNodePairs,
54{
55 if (rCellPopulation.rGetMesh().GetNumLaminas() > 0u)
56 {
57 EXCEPTION("This force class cannot be used in the presence of lamina elements.");
58 }
59
60 for (unsigned pair = 0; pair < rNodePairs.size(); ++pair)
61 {
62 /*
63 * Interactions only exist between pairs of nodes that are not in the
64 * same boundary / lamina.
65 */
66 if (rCellPopulation.rGetMesh().NodesInDifferentElementOrLamina(rNodePairs[pair].first, rNodePairs[pair].second))
67 {
68 Node<DIM>* p_node_a = rNodePairs[pair].first;
69 Node<DIM>* p_node_b = rNodePairs[pair].second;
70
71 c_vector<double, DIM> vec_a2b = rCellPopulation.rGetMesh().GetVectorFromAtoB(p_node_a->rGetLocation(),
72 p_node_b->rGetLocation());
73 const double normed_dist = norm_2(vec_a2b);
74
75 // Force non-zero only within interaction distance, by definition
76 if (normed_dist < rCellPopulation.GetInteractionDistance())
77 {
78 const unsigned a_elem_idx = *(p_node_a->ContainingElementsBegin());
79 const unsigned b_elem_idx = *(p_node_b->ContainingElementsBegin());
80
81 bool a_cell_labelled = rCellPopulation.GetCellUsingLocationIndex(a_elem_idx)->template HasCellProperty<CellLabel>();
82 bool b_cell_labelled = rCellPopulation.GetCellUsingLocationIndex(b_elem_idx)->template HasCellProperty<CellLabel>();
83
84 double node_a_elem_spacing = rCellPopulation.rGetMesh().GetAverageNodeSpacingOfElement(a_elem_idx, false);
85 double node_b_elem_spacing = rCellPopulation.rGetMesh().GetAverageNodeSpacingOfElement(b_elem_idx, false);
86
87 double elem_spacing = 0.5 * (node_a_elem_spacing + node_b_elem_spacing);
88
89 // Here we take account of whether the cells are labelled
90 double eff_spring_const = elem_spacing / rCellPopulation.GetIntrinsicSpacing();
91 if (a_cell_labelled && b_cell_labelled)
92 {
93 eff_spring_const *= mLabelledCellToLabelledCellSpringConst;
94 }
95 else if (a_cell_labelled || b_cell_labelled)
96 {
97 eff_spring_const *= mLabelledCellToCellSpringConst;
98 }
99 else
100 {
101 eff_spring_const *= mCellToCellSpringConst;
102 }
103
104 const double eff_rest_length = mRestLength * rCellPopulation.GetInteractionDistance();
105
106 /*
107 * We must scale each applied force by a factor of elem_spacing / local spacing, so that forces
108 * balance when spread to the grid later (where the multiplicative factor is the local spacing)
109 */
110 vec_a2b *= eff_spring_const * (normed_dist - eff_rest_length) / normed_dist;
111
112 c_vector<double, DIM> force_a2b = vec_a2b * (elem_spacing / node_a_elem_spacing);
113 p_node_a->AddAppliedForceContribution(force_a2b);
114
115 c_vector<double, DIM> force_b2a = vec_a2b * (-1.0 * elem_spacing / node_b_elem_spacing);
116 p_node_b->AddAppliedForceContribution(force_b2a);
117 }
118 }
119 }
120}
121
122template<unsigned DIM>
124 out_stream& rParamsFile)
125{
126 *rParamsFile << "\t\t\t<LabelledCellToLabelledCellSpringConst>" << mLabelledCellToLabelledCellSpringConst << "</LabelledCellToLabelledCellSpringConst>\n";
127 *rParamsFile << "\t\t\t<LabelledCellToCellSpringConst>" << mLabelledCellToCellSpringConst << "</LabelledCellToCellSpringConst>\n";
128 *rParamsFile << "\t\t\t<CellToCellSpringConst>" << mCellToCellSpringConst << "</CellToCellSpringConst>\n";
129 *rParamsFile << "\t\t\t<RestLength>" << mRestLength << "</RestLength>\n";
130
131 // Call method on direct parent class
133}
134
135template<unsigned DIM>
137{
138 return mRestLength;
139}
140
141template<unsigned DIM>
143 double restLength)
144{
145 mRestLength = restLength;
146}
147
148template<unsigned int DIM>
150{
151 return mLabelledCellToLabelledCellSpringConst;
152}
153
154template<unsigned int DIM>
156 double labelledCellToLabelledCellSpringConst)
157{
158 mLabelledCellToLabelledCellSpringConst = labelledCellToLabelledCellSpringConst;
159}
160
161template<unsigned int DIM>
163{
164 return mLabelledCellToCellSpringConst;
165}
166
167template<unsigned int DIM>
169 double labelledCellToCellSpringConst)
170{
171 mLabelledCellToCellSpringConst = labelledCellToCellSpringConst;
172}
173
174template<unsigned int DIM>
176{
177 return mCellToCellSpringConst;
178}
179
180template<unsigned int DIM>
182 double cellToCellSpringConst)
183{
184 mCellToCellSpringConst = cellToCellSpringConst;
185}
186
187// Explicit instantiation
191
192// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
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)
void SetLabelledCellToLabelledCellSpringConst(double labelledCellToLabelledCellSpringConst)
bool NodesInDifferentElementOrLamina(Node< SPACE_DIM > *pNodeA, Node< SPACE_DIM > *pNodeB)
double GetAverageNodeSpacingOfElement(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