Chaste  Release::2017.1
PopulationTestingForce.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 "PopulationTestingForce.hpp"
37 
38 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
40  :AbstractForce<ELEMENT_DIM, SPACE_DIM>(),
41  mWithPositionDependence(hasPositionDependence)
42 {
43 }
44 
45 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
47 {
48  for (unsigned i=0; i<rCellPopulation.GetNumNodes(); i++)
49  {
50  c_vector<double, SPACE_DIM> force;
51 
52  for (unsigned j=0; j<SPACE_DIM; j++)
53  {
55  {
56  force[j] = (j+1)*i*0.01*rCellPopulation.GetNode(i)->rGetLocation()[j];
57  }
58  else
59  {
60  force[j] = (j+1)*i*0.01;
61  }
62  }
63  rCellPopulation.GetNode(i)->ClearAppliedForce();
64  rCellPopulation.GetNode(i)->AddAppliedForceContribution(force);
65  }
66 }
67 
68 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
70  double damping,
71  c_vector<double, SPACE_DIM>& oldLocation,
72  double dt)
73 {
74  c_vector<double, SPACE_DIM> result;
75  for (unsigned j = 0; j < SPACE_DIM; j++)
76  {
78  {
79  result[j] = oldLocation[j] + dt * (j+1)*0.01*nodeIndex * oldLocation[j] / damping;
80  }
81  else
82  {
83  result[j] = oldLocation[j] + dt * (j+1)*0.01*nodeIndex/damping;
84  }
85  }
86  return result;
87 }
88 
89 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
91  double damping,
92  c_vector<double, SPACE_DIM>& oldLocation,
93  double dt)
94 {
95  c_vector<double, SPACE_DIM> result;
96  for (unsigned j = 0; j < SPACE_DIM; j++)
97  {
98  double k1 = (j+1)*0.01*nodeIndex * oldLocation[j] / damping;
99  double k2 = (j+1)*0.01*nodeIndex * (oldLocation[j] + (dt/2.0)*k1) / damping;
100  double k3 = (j+1)*0.01*nodeIndex * (oldLocation[j] + (dt/2.0)*k2) / damping;
101  double k4 = (j+1)*0.01*nodeIndex * (oldLocation[j] + dt*k3) / damping;
102  result[j] = oldLocation[j] + (1.0/6.0)*dt*(k1 + 2*k2 + 2*k3 + k4);
103  }
104  return result;
105 }
106 
107 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
109  double damping,
110  c_vector<double, SPACE_DIM>& oldLocation,
111  double dt)
112 {
113  c_vector<double, SPACE_DIM> result;
114  for (unsigned j = 0; j < SPACE_DIM; j++)
115  {
116  result[j] = oldLocation[j] * (1 + 0.5*dt*0.01*(j+1)*nodeIndex / damping) / (1 - 0.5*dt*0.01*(j+1)*nodeIndex / damping);
117  }
118  return result;
119 }
120 
121 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
123  double damping,
124  c_vector<double, SPACE_DIM>& oldLocation,
125  double dt)
126 {
127  c_vector<double, SPACE_DIM> result;
128  for (unsigned j = 0; j < SPACE_DIM; j++)
129  {
130  result[j] = oldLocation[j] / (1 - dt*0.01*(j+1)*nodeIndex/damping);
131  }
132  return result;
133 }
134 
135 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
137 {
138  // This force is not used in a simulation so this method is never called
140 }
141 
142 // Explicit instantiation
143 template class PopulationTestingForce<1,1>;
144 template class PopulationTestingForce<1,2>;
145 template class PopulationTestingForce<2,2>;
146 template class PopulationTestingForce<1,3>;
147 template class PopulationTestingForce<2,3>;
148 template class PopulationTestingForce<3,3>;
149 
150 // Serialization for Boost >= 1.36
virtual Node< SPACE_DIM > * GetNode(unsigned index)=0
c_vector< double, SPACE_DIM > GetExpectedOneStepLocationRK4(unsigned nodeIndex, double damping, c_vector< double, SPACE_DIM > &oldLocation, double dt)
virtual void OutputForceParameters(out_stream &rParamsFile)
PopulationTestingForce(bool hasPositionDependence=true)
#define NEVER_REACHED
Definition: Exception.hpp:206
c_vector< double, SPACE_DIM > GetExpectedOneStepLocationAM2(unsigned nodeIndex, double damping, c_vector< double, SPACE_DIM > &oldLocation, double dt)
c_vector< double, SPACE_DIM > GetExpectedOneStepLocationBE(unsigned nodeIndex, double damping, c_vector< double, SPACE_DIM > &oldLocation, double dt)
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
void AddForceContribution(AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation)
c_vector< double, SPACE_DIM > GetExpectedOneStepLocationFE(unsigned nodeIndex, double damping, c_vector< double, SPACE_DIM > &oldLocation, double dt)
virtual unsigned GetNumNodes()=0