Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
AdhesionPottsUpdateRule.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 "AdhesionPottsUpdateRule.hpp"
37
38template<unsigned DIM>
41 mCellCellAdhesionEnergyParameter(0.1), // Educated guess
42 mCellBoundaryAdhesionEnergyParameter(0.2) // Educated guess
43{
44}
45
46template<unsigned DIM>
50
51template<unsigned DIM>
53 unsigned targetNodeIndex,
54 PottsBasedCellPopulation<DIM>& rCellPopulation)
55{
56 std::set<unsigned> containing_elements = rCellPopulation.GetNode(currentNodeIndex)->rGetContainingElementIndices();
57 std::set<unsigned> new_location_containing_elements = rCellPopulation.GetNode(targetNodeIndex)->rGetContainingElementIndices();
58
59 bool current_node_contained = !containing_elements.empty();
60 bool target_node_contained = !new_location_containing_elements.empty();
61
62 // Every node must each be in at most one element
63 assert(new_location_containing_elements.size() < 2);
64
65 if (!current_node_contained && !target_node_contained)
66 {
67 EXCEPTION("At least one of the current node or target node must be in an element.");
68 }
69
70 if (current_node_contained && target_node_contained)
71 {
72 if (*(new_location_containing_elements.begin()) == *(containing_elements.begin()))
73 {
74 EXCEPTION("The current node and target node must not be in the same element.");
75 }
76 }
77
78 // Iterate over nodes neighbouring the target node to work out the contact energy contribution
79 double delta_H = 0.0;
80 std::set<unsigned> target_neighbouring_node_indices = rCellPopulation.rGetMesh().GetVonNeumannNeighbouringNodeIndices(targetNodeIndex);
81 for (std::set<unsigned>::iterator iter = target_neighbouring_node_indices.begin();
82 iter != target_neighbouring_node_indices.end();
83 ++iter)
84 {
85 std::set<unsigned> neighbouring_node_containing_elements = rCellPopulation.rGetMesh().GetNode(*iter)->rGetContainingElementIndices();
86
87 // Every node must each be in at most one element
88 assert(neighbouring_node_containing_elements.size() < 2);
89
90 bool neighbouring_node_contained = !neighbouring_node_containing_elements.empty();
91
98 if (neighbouring_node_contained && target_node_contained)
99 {
100 unsigned neighbour_element = (*neighbouring_node_containing_elements.begin());
101 unsigned target_element = (*new_location_containing_elements.begin());
102 if (target_element != neighbour_element)
103 {
104 // The nodes are currently contained in different elements
105 delta_H -= GetCellCellAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(target_element), rCellPopulation.GetCellUsingLocationIndex(neighbour_element));
106 }
107 }
108 else if (neighbouring_node_contained && !target_node_contained)
109 {
110 // The neighbouring node is contained in a Potts element, but the target node is not
111 unsigned neighbour_element = (*neighbouring_node_containing_elements.begin());
112 delta_H -= GetCellBoundaryAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(neighbour_element));
113 }
114 else if (!neighbouring_node_contained && target_node_contained)
115 {
116 // The target node is contained in a Potts element, but the neighbouring node is not
117 unsigned target_element = (*new_location_containing_elements.begin());
118 delta_H -= GetCellBoundaryAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(target_element));
119 }
120
127 if (neighbouring_node_contained && current_node_contained)
128 {
129 unsigned neighbour_element = (*neighbouring_node_containing_elements.begin());
130 unsigned current_element = (*containing_elements.begin());
131 if (current_element != neighbour_element)
132 {
133 // The nodes are currently contained in different elements
134 delta_H += GetCellCellAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(current_element),rCellPopulation.GetCellUsingLocationIndex(neighbour_element));
135 }
136 }
137 else if (neighbouring_node_contained && !current_node_contained)
138 {
139 // The neighbouring node is contained in a Potts element, but the current node is not
140 unsigned neighbour_element = (*neighbouring_node_containing_elements.begin());
141 delta_H += GetCellBoundaryAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(neighbour_element));
142 }
143 else if (!neighbouring_node_contained && current_node_contained)
144 {
145 // The current node is contained in a Potts element, but the neighbouring node is not
146 unsigned current_element = (*containing_elements.begin());
147 delta_H += GetCellBoundaryAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(current_element));
148 }
149 }
150
151 return delta_H;
152}
153
154template<unsigned DIM>
156{
157 return GetCellCellAdhesionEnergyParameter();
158}
159
160template<unsigned DIM>
162{
163 return GetCellBoundaryAdhesionEnergyParameter();
164}
165
166template<unsigned DIM>
168{
169 return mCellCellAdhesionEnergyParameter;
170}
171
172template<unsigned DIM>
174{
175 return mCellBoundaryAdhesionEnergyParameter;
176}
177
178template<unsigned DIM>
180{
181 mCellCellAdhesionEnergyParameter = cellCellAdhesionEnergyParameter;
182}
183
184template<unsigned DIM>
185void AdhesionPottsUpdateRule<DIM>::SetCellBoundaryAdhesionEnergyParameter(double cellBoundaryAdhesionEnergyParameter)
186{
187 mCellBoundaryAdhesionEnergyParameter = cellBoundaryAdhesionEnergyParameter;
188}
189
190template<unsigned DIM>
192{
193 *rParamsFile << "\t\t\t<CellCellAdhesionEnergyParameter>" << mCellCellAdhesionEnergyParameter << "</CellCellAdhesionEnergyParameter>\n";
194 *rParamsFile << "\t\t\t<CellBoundaryAdhesionEnergyParameter>" << mCellBoundaryAdhesionEnergyParameter << "</CellBoundaryAdhesionEnergyParameter>\n";
195
196 // Call method on direct parent class
198}
199
200// Explicit instantiation
201template class AdhesionPottsUpdateRule<1>;
202template class AdhesionPottsUpdateRule<2>;
203template class AdhesionPottsUpdateRule<3>;
204
205// Serialization for Boost >= 1.36
#define EXCEPTION(message)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
virtual void OutputUpdateRuleParameters(out_stream &rParamsFile)
void SetCellCellAdhesionEnergyParameter(double cellCellAdhesionEnergyEnergyParameter)
double EvaluateHamiltonianContribution(unsigned currentNodeIndex, unsigned targetNodeIndex, PottsBasedCellPopulation< DIM > &rCellPopulation)
virtual double GetCellCellAdhesionEnergy(CellPtr pCellA, CellPtr pCellB)
void OutputUpdateRuleParameters(out_stream &rParamsFile)
virtual double GetCellBoundaryAdhesionEnergy(CellPtr pCell)
void SetCellBoundaryAdhesionEnergyParameter(double cellBoundaryAdhesionEnergyParameter)
std::set< unsigned > & rGetContainingElementIndices()
Definition Node.cpp:300
Node< DIM > * GetNode(unsigned index)