Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
AbstractTwoBodyInteractionForce.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 "AbstractTwoBodyInteractionForce.hpp"
37
38template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
40 : AbstractForce<ELEMENT_DIM,SPACE_DIM>(),
41 mUseCutOffLength(false),
42 mMechanicsCutOffLength(DBL_MAX)
43{
44}
45
46template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
51
52template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
54{
55 assert(cutOffLength > 0.0);
56 mUseCutOffLength = true;
57 mMechanicsCutOffLength = cutOffLength;
58}
59
60template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
62{
63 return mMechanicsCutOffLength;
64}
65
66template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
68{
69 // Throw an exception message if not using a subclass of AbstractCentreBasedCellPopulation
70 if (dynamic_cast<AbstractCentreBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>*>(&rCellPopulation) == nullptr)
71 {
72 EXCEPTION("Subclasses of AbstractTwoBodyInteractionForce are to be used with subclasses of AbstractCentreBasedCellPopulation only");
73 }
74
76 if (bool(dynamic_cast<MeshBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>*>(&rCellPopulation)))
77 {
78 MeshBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>* p_static_cast_cell_population = static_cast<MeshBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>*>(&rCellPopulation);
79
80 // Iterate over all springs and add force contributions
81 for (typename MeshBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>::SpringIterator spring_iterator = p_static_cast_cell_population->SpringsBegin();
82 spring_iterator != p_static_cast_cell_population->SpringsEnd();
83 ++spring_iterator)
84 {
85 unsigned nodeA_global_index = spring_iterator.GetNodeA()->GetIndex();
86 unsigned nodeB_global_index = spring_iterator.GetNodeB()->GetIndex();
87
88 // Calculate the force between nodes
89 c_vector<double, SPACE_DIM> force = CalculateForceBetweenNodes(nodeA_global_index, nodeB_global_index, rCellPopulation);
90
91 // Add the force contribution to each node
92 c_vector<double, SPACE_DIM> negative_force = -1.0*force;
93 spring_iterator.GetNodeB()->AddAppliedForceContribution(negative_force);
94 spring_iterator.GetNodeA()->AddAppliedForceContribution(force);
95 }
96 }
97 else // This is a NodeBasedCellPopulation
98 {
100
101 std::vector< std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>* > >& r_node_pairs = p_static_cast_cell_population->rGetNodePairs();
102
103 for (typename std::vector< std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>* > >::iterator iter = r_node_pairs.begin();
104 iter != r_node_pairs.end();
105 iter++)
106 {
107 std::pair<Node<SPACE_DIM>*, Node<SPACE_DIM>* > pair = *iter;
109 unsigned node_a_index = pair.first->GetIndex();
110 unsigned node_b_index = pair.second->GetIndex();
111
112 // Calculate the force between nodes
113 c_vector<double, SPACE_DIM> force = CalculateForceBetweenNodes(node_a_index, node_b_index, rCellPopulation);
114 for (unsigned j=0; j<SPACE_DIM; j++)
115 {
116 assert(!std::isnan(force[j]));
117 }
118
119 // Add the force contribution to each node
120 c_vector<double, SPACE_DIM> negative_force = -1.0*force;
121 pair.first->AddAppliedForceContribution(force);
122 pair.second->AddAppliedForceContribution(negative_force);
123 }
124 }
125}
126
127template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
129{
130 *rParamsFile << "\t\t\t<UseCutOffLength>" << mUseCutOffLength << "</UseCutOffLength>\n";
131 *rParamsFile << "\t\t\t<CutOffLength>" << mMechanicsCutOffLength << "</CutOffLength>\n";
132
133 // Call method on direct parent class
135}
136
137template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
139{
140 *pVizSetupFile << "Cutoff\t" << mMechanicsCutOffLength << "\n";
141}
142
143// Explicit instantiation
#define EXCEPTION(message)
virtual std::vector< std::pair< Node< SPACE_DIM > *, Node< SPACE_DIM > * > > & rGetNodePairs()=0
virtual void OutputForceParameters(out_stream &rParamsFile)=0
void AddForceContribution(AbstractCellPopulation< ELEMENT_DIM, SPACE_DIM > &rCellPopulation)
virtual void WriteDataToVisualizerSetupFile(out_stream &pVizSetupFile)
virtual void OutputForceParameters(out_stream &rParamsFile)
Definition Node.hpp:59
unsigned GetIndex() const
Definition Node.cpp:158