Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
PopulationTestingForce.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 "PopulationTestingForce.hpp"
37
38template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
40 :AbstractForce<ELEMENT_DIM, SPACE_DIM>(),
41 mWithPositionDependence(hasPositionDependence)
42{
43}
44
45template<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 {
54 if (mWithPositionDependence)
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
68template<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 {
77 if (mWithPositionDependence)
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
89template<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
107template<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
121template<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
135template<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
143template class PopulationTestingForce<1,1>;
144template class PopulationTestingForce<1,2>;
145template class PopulationTestingForce<2,2>;
146template class PopulationTestingForce<1,3>;
147template class PopulationTestingForce<2,3>;
148template class PopulationTestingForce<3,3>;
149
150// Serialization for Boost >= 1.36
#define NEVER_REACHED
#define EXPORT_TEMPLATE_CLASS_ALL_DIMS(CLASS)
virtual Node< SPACE_DIM > * GetNode(unsigned index)=0
virtual unsigned GetNumNodes()=0
c_vector< double, SPACE_DIM > GetExpectedOneStepLocationAM2(unsigned nodeIndex, double damping, c_vector< double, SPACE_DIM > &oldLocation, double dt)
c_vector< double, SPACE_DIM > GetExpectedOneStepLocationFE(unsigned nodeIndex, double damping, c_vector< double, SPACE_DIM > &oldLocation, double dt)
virtual void OutputForceParameters(out_stream &rParamsFile)
PopulationTestingForce(bool hasPositionDependence=true)
c_vector< double, SPACE_DIM > GetExpectedOneStepLocationRK4(unsigned nodeIndex, double damping, c_vector< double, SPACE_DIM > &oldLocation, double dt)
void AddForceContribution(AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation)
c_vector< double, SPACE_DIM > GetExpectedOneStepLocationBE(unsigned nodeIndex, double damping, c_vector< double, SPACE_DIM > &oldLocation, double dt)