Chaste  Release::2017.1
AdhesionPottsUpdateRule.cpp
1 /*
2 
3 Copyright (c) 2005-2017, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include "AdhesionPottsUpdateRule.hpp"
37 
38 template<unsigned DIM>
40  : AbstractPottsUpdateRule<DIM>(),
41  mCellCellAdhesionEnergyParameter(0.1), // Educated guess
42  mCellBoundaryAdhesionEnergyParameter(0.2) // Educated guess
43 {
44 }
45 
46 template<unsigned DIM>
48 {
49 }
50 
51 template<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 
154 template<unsigned DIM>
155 double AdhesionPottsUpdateRule<DIM>::GetCellCellAdhesionEnergy(CellPtr pCellA, CellPtr pCellB)
156 {
158 }
159 
160 template<unsigned DIM>
162 {
164 }
165 
166 template<unsigned DIM>
168 {
170 }
171 
172 template<unsigned DIM>
174 {
176 }
177 
178 template<unsigned DIM>
179 void AdhesionPottsUpdateRule<DIM>::SetCellCellAdhesionEnergyParameter(double cellCellAdhesionEnergyParameter)
180 {
181  mCellCellAdhesionEnergyParameter = cellCellAdhesionEnergyParameter;
182 }
183 
184 template<unsigned DIM>
185 void AdhesionPottsUpdateRule<DIM>::SetCellBoundaryAdhesionEnergyParameter(double cellBoundaryAdhesionEnergyParameter)
186 {
187  mCellBoundaryAdhesionEnergyParameter = cellBoundaryAdhesionEnergyParameter;
188 }
189 
190 template<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
201 template class AdhesionPottsUpdateRule<1>;
202 template class AdhesionPottsUpdateRule<2>;
203 template class AdhesionPottsUpdateRule<3>;
204 
205 // Serialization for Boost >= 1.36
virtual void OutputUpdateRuleParameters(out_stream &rParamsFile)
virtual CellPtr GetCellUsingLocationIndex(unsigned index)
Node< DIM > * GetNode(unsigned index)
virtual double GetCellCellAdhesionEnergy(CellPtr pCellA, CellPtr pCellB)
#define EXCEPTION(message)
Definition: Exception.hpp:143
void OutputUpdateRuleParameters(out_stream &rParamsFile)
virtual double GetCellBoundaryAdhesionEnergy(CellPtr pCell)
double EvaluateHamiltonianContribution(unsigned currentNodeIndex, unsigned targetNodeIndex, PottsBasedCellPopulation< DIM > &rCellPopulation)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void SetCellBoundaryAdhesionEnergyParameter(double cellBoundaryAdhesionEnergyParameter)
void SetCellCellAdhesionEnergyParameter(double cellCellAdhesionEnergyEnergyParameter)