Chaste  Release::2018.1
WelikyOsterForce.cpp
1 /*
2 
3 Copyright (c) 2005-2018, 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 "WelikyOsterForce.hpp"
37 
38 template<unsigned DIM>
40  : AbstractForce<DIM>(),
41  mWelikyOsterAreaParameter(1.0),
42  mWelikyOsterPerimeterParameter(1.0)
43 {
44 }
45 
46 template<unsigned DIM>
48 {
49 }
50 
51 template<unsigned DIM>
53 {
54  // Make sure that we are in the correct dimension - this code will be eliminated at compile time
55  assert(DIM == 2); // LCOV_EXCL_LINE // this method only works in 2D at present
56 
57  // Throw an exception message if not using a VertexBasedCellPopulation
58  if (dynamic_cast<VertexBasedCellPopulation<DIM>*>(&rCellPopulation) == nullptr)
59  {
60  EXCEPTION("WelikyOsterForce is to be used with a VertexBasedCellPopulation only");
61  }
62 
63  // Helper variable that is a static cast of the cell population
64  VertexBasedCellPopulation<DIM>* p_cell_population = static_cast<VertexBasedCellPopulation<DIM>*>(&rCellPopulation);
65 
66  /*
67  * The force on each node is given by the interaction between the area and
68  * the perimeter of the element containing the node.
69  */
70 
71  // Iterate over elements in the cell population
72  for (typename VertexMesh<DIM,DIM>::VertexElementIterator element_iter = p_cell_population->rGetMesh().GetElementIteratorBegin();
73  element_iter != p_cell_population->rGetMesh().GetElementIteratorEnd();
74  ++element_iter)
75  {
76  unsigned element_index = element_iter->GetIndex();
77 
78  /******** Start of deformation force calculation ********/
79 
80  // Compute the area of this element
81  double element_area = p_cell_population->rGetMesh().GetVolumeOfElement(element_index);
82 
83  double deformation_coefficient = GetWelikyOsterAreaParameter()/element_area;
84 
85  /******** End of deformation force calculation *************/
86 
87  /******** Start of membrane force calculation ***********/
88 
89  // Compute the perimeter of the element
90  double element_perimeter = p_cell_population->rGetMesh().GetSurfaceAreaOfElement(element_index);
91 
92  double membrane_surface_tension_coefficient = GetWelikyOsterPerimeterParameter()*element_perimeter;
93 
94  /******** End of membrane force calculation **********/
95 
96  unsigned num_nodes = element_iter->GetNumNodes();
97  for (unsigned node_local_index = 0; node_local_index < num_nodes; node_local_index++)
98  {
99  unsigned node_global_index = element_iter->GetNodeGlobalIndex(node_local_index);
100 
101  c_vector<double, DIM> current_node = element_iter->GetNodeLocation(node_local_index);
102  c_vector<double, DIM> next_node = element_iter->GetNodeLocation((node_local_index + 1)%(element_iter->GetNumNodes()));
103  c_vector<double, DIM> previous_node = element_iter->GetNodeLocation((node_local_index + element_iter->GetNumNodes() - 1)%(element_iter->GetNumNodes()));
104 
105  c_vector<double, DIM> clockwise_unit_vector = p_cell_population->rGetMesh().GetVectorFromAtoB(current_node, previous_node);
106  clockwise_unit_vector /= norm_2(clockwise_unit_vector);
107 
108  c_vector<double, DIM> anti_clockwise_unit_vector = p_cell_population->rGetMesh().GetVectorFromAtoB(current_node, next_node);
109  anti_clockwise_unit_vector /= norm_2(anti_clockwise_unit_vector);
110 
111  // Calculate the outward normal at the node
112  c_vector<double, DIM> outward_normal = -0.5*clockwise_unit_vector - 0.5*anti_clockwise_unit_vector;
113  outward_normal /= norm_2(outward_normal);
114 
115  c_vector<double, DIM> deformation_contribution = deformation_coefficient * outward_normal;
116 
117  c_vector<double, DIM> membrane_surface_tension_contribution = membrane_surface_tension_coefficient * (clockwise_unit_vector + anti_clockwise_unit_vector);
118 
119  c_vector<double, DIM> force_on_node = deformation_contribution + membrane_surface_tension_contribution;
120 
121  p_cell_population->GetNode(node_global_index)->AddAppliedForceContribution(force_on_node);
122  }
123  }
124 }
125 
126 template<unsigned DIM>
128 {
129  return mWelikyOsterAreaParameter;
130 }
131 
132 template<unsigned DIM>
134 {
135  return mWelikyOsterPerimeterParameter;
136 }
137 
138 template<unsigned DIM>
139 void WelikyOsterForce<DIM>::SetWelikyOsterAreaParameter(double welikyOsterAreaParameter)
140 {
141  mWelikyOsterAreaParameter = welikyOsterAreaParameter;
142 }
143 
144 template<unsigned DIM>
145 void WelikyOsterForce<DIM>::SetWelikyOsterPerimeterParameter(double welikyOsterPerimeterParameter)
146 {
147  mWelikyOsterPerimeterParameter = welikyOsterPerimeterParameter;
148 }
149 
150 template<unsigned DIM>
151 void WelikyOsterForce<DIM>::OutputForceParameters(out_stream& rParamsFile)
152 {
153  *rParamsFile << "\t\t\t<WelikyOsterAreaParameter>" << mWelikyOsterAreaParameter << "</WelikyOsterAreaParameter>\n";
154  *rParamsFile << "\t\t\t<WelikyOsterPerimeterParameter>" << mWelikyOsterPerimeterParameter << "</WelikyOsterPerimeterParameter>\n";
155 
156  // Call method on direct parent class
158 }
159 
160 // Explicit instantiation
161 template class WelikyOsterForce<1>;
162 template class WelikyOsterForce<2>;
163 template class WelikyOsterForce<3>;
164 
165 // Serialization for Boost >= 1.36
virtual c_vector< double, SPACE_DIM > GetVectorFromAtoB(const c_vector< double, SPACE_DIM > &rLocationA, const c_vector< double, SPACE_DIM > &rLocationB)
double GetWelikyOsterAreaParameter()
#define EXCEPTION(message)
Definition: Exception.hpp:143
void SetWelikyOsterPerimeterParameter(double welikyOsterPerimeterParameter)
MutableVertexMesh< DIM, DIM > & rGetMesh()
VertexElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
Definition: VertexMesh.hpp:679
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
Node< DIM > * GetNode(unsigned index)
void SetWelikyOsterAreaParameter(double welikyOsterAreaParameter)
virtual double GetVolumeOfElement(unsigned index)
void AddForceContribution(AbstractCellPopulation< DIM > &rCellPopulation)
VertexElementIterator GetElementIteratorEnd()
Definition: VertexMesh.hpp:686
virtual double GetSurfaceAreaOfElement(unsigned index)
double GetWelikyOsterPerimeterParameter()
virtual void OutputForceParameters(out_stream &rParamsFile)=0
void OutputForceParameters(out_stream &rParamsFile)