Chaste Commit::f841a6fa79bd6f7a205054452b95ddf6d10aae23
AbstractOffLatticeCellPopulation.cpp
1/*
2
3Copyright (c) 2005-2026, 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 "AbstractOffLatticeCellPopulation.hpp"
37#include "StepSizeException.hpp"
38
39template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
41 std::vector<CellPtr>& rCells,
42 const std::vector<unsigned> locationIndices)
43 : AbstractCellPopulation<ELEMENT_DIM, SPACE_DIM>(rMesh, rCells, locationIndices),
44 mDampingConstantNormal(1.0),
45 mDampingConstantMutant(1.0),
46 mAbsoluteMovementThreshold(2.0)
47{
48}
49
50template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
55
56template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
57void AbstractOffLatticeCellPopulation<ELEMENT_DIM, SPACE_DIM>::CheckForStepSizeException(unsigned nodeIndex, c_vector<double,SPACE_DIM>& rDisplacement, double dt)
58{
59 double length = norm_2(rDisplacement);
60
61 if (length > this->mAbsoluteMovementThreshold)
62 {
63 std::ostringstream message;
64 message << "Cells are moving by " << length;
65 message << ", which is more than the AbsoluteMovementThreshold: use a smaller timestep to avoid this exception.";
66
67 /* Divide dt by the smallest power of 2 such that the node moves less than the threshold
68 * Note that this is the optimal power of 2 to divide by for the Forward Euler Method.
69 * For higher order methods, the optimal divisor may be different, but this is an upper bound that works for all methods.
70 */
71 double divisor = 1.0;
72 while (length / divisor >= this->mAbsoluteMovementThreshold)
73 {
74 divisor *= 2.0;
75 }
76 double new_step = dt / divisor;
77
78 throw StepSizeException(new_step, message.str(), true); // terminate
79 }
80}
81
82// LCOV_EXCL_START
83template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
85{
86 // This method is deprecated by the NumericalMethod class hierarchy; the only population that calls this method is the NodeBasedCellPopulationWithBuskeUpdate.
88}
89// LCOV_EXCL_STOP
90
91template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
93{
94 assert(dampingConstantNormal > 0.0);
95 mDampingConstantNormal = dampingConstantNormal;
96}
97
98template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
100{
101 assert(dampingConstantMutant > 0.0);
102 mDampingConstantMutant = dampingConstantMutant;
103}
104
105template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
107{
108 mAbsoluteMovementThreshold = absoluteMovementThreshold;
109}
110
111template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
116
117template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
120 return mDampingConstantMutant;
121}
122
123template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
128
129template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
130const std::vector<std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>*> >& AbstractOffLatticeCellPopulation<ELEMENT_DIM, SPACE_DIM>::rGetNodePairs() const
131{
132 return mNodePairs;
133}
134
135template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
137{
138 return mNodePairs;
139}
140
141template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
143{
144 *rParamsFile << "\t\t<DampingConstantNormal>" << mDampingConstantNormal << "</DampingConstantNormal>\n";
145 *rParamsFile << "\t\t<DampingConstantMutant>" << mDampingConstantMutant << "</DampingConstantMutant>\n";
146
147 // Call method on direct parent class
149}
150
151// Explicit instantiation
#define NEVER_REACHED
virtual void OutputCellPopulationParameters(out_stream &rParamsFile)=0
void SetDampingConstantMutant(double dampingConstantMutant)
virtual void CheckForStepSizeException(unsigned nodeIndex, c_vector< double, SPACE_DIM > &rDisplacement, double dt)
AbstractOffLatticeCellPopulation(AbstractMesh< ELEMENT_DIM, SPACE_DIM > &rMesh)
virtual std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > & rGetModifiableNodePairs()
virtual void OutputCellPopulationParameters(out_stream &rParamsFile)
void SetAbsoluteMovementThreshold(double absoluteMovementThreshold)
void SetDampingConstantNormal(double dampingConstantNormal)
virtual const std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > & rGetNodePairs() const
Definition Node.hpp:59