AbstractTwoBodyInteractionForce.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "AbstractTwoBodyInteractionForce.hpp"
00030
00031 template<unsigned DIM>
00032 AbstractTwoBodyInteractionForce<DIM>::AbstractTwoBodyInteractionForce()
00033 : AbstractForce<DIM>(),
00034 mUseCutOffLength(false),
00035 mMechanicsCutOffLength(DBL_MAX)
00036 {
00037 }
00038
00039 template<unsigned DIM>
00040 bool AbstractTwoBodyInteractionForce<DIM>::GetUseCutOffLength()
00041 {
00042 return mUseCutOffLength;
00043 }
00044
00045 template<unsigned DIM>
00046 void AbstractTwoBodyInteractionForce<DIM>::SetCutOffLength(double cutOffLength)
00047 {
00048 assert(cutOffLength > 0.0);
00049 mUseCutOffLength = true;
00050 mMechanicsCutOffLength = cutOffLength;
00051 }
00052
00053 template<unsigned DIM>
00054 double AbstractTwoBodyInteractionForce<DIM>::GetCutOffLength()
00055 {
00056 return mMechanicsCutOffLength;
00057 }
00058
00059 template<unsigned DIM>
00060 void AbstractTwoBodyInteractionForce<DIM>::AddForceContribution(std::vector<c_vector<double, DIM> >& rForces,
00061 AbstractCellPopulation<DIM>& rCellPopulation)
00062 {
00063
00064 if (dynamic_cast<AbstractCentreBasedCellPopulation<DIM>*>(&rCellPopulation) == NULL)
00065 {
00066 EXCEPTION("Subclasses of AbstractTwoBodyInteractionForce are to be used with subclasses of AbstractCentreBasedCellPopulation only");
00067 }
00068
00069 if (dynamic_cast<MeshBasedCellPopulation<DIM>*>(&rCellPopulation))
00070 {
00071 MeshBasedCellPopulation<DIM>* p_static_cast_cell_population = static_cast<MeshBasedCellPopulation<DIM>*>(&rCellPopulation);
00072
00073
00074 for (typename MeshBasedCellPopulation<DIM>::SpringIterator spring_iterator = p_static_cast_cell_population->SpringsBegin();
00075 spring_iterator != p_static_cast_cell_population->SpringsEnd();
00076 ++spring_iterator)
00077 {
00078 unsigned nodeA_global_index = spring_iterator.GetNodeA()->GetIndex();
00079 unsigned nodeB_global_index = spring_iterator.GetNodeB()->GetIndex();
00080
00081
00082 c_vector<double, DIM> force = CalculateForceBetweenNodes(nodeA_global_index, nodeB_global_index, rCellPopulation);
00083
00084
00085 rForces[nodeB_global_index] -= force;
00086 rForces[nodeA_global_index] += force;
00087 }
00088 }
00089 else
00090 {
00091 std::set< std::pair<Node<DIM>*, Node<DIM>* > >& r_node_pairs = (static_cast<NodeBasedCellPopulation<DIM>*>(&rCellPopulation))->rGetNodePairs();
00092
00093
00094
00095 for (typename std::set< std::pair<Node<DIM>*, Node<DIM>* > >::iterator iter = r_node_pairs.begin();
00096 iter != r_node_pairs.end();
00097 iter++)
00098 {
00099 std::pair<Node<DIM>*, Node<DIM>* > pair = *iter;
00100
00101 unsigned node_a_index = pair.first->GetIndex();
00102 unsigned node_b_index = pair.second->GetIndex();
00103
00104
00105 c_vector<double, DIM> force = CalculateForceBetweenNodes(node_a_index, node_b_index, rCellPopulation);
00106 for (unsigned j=0; j<DIM; j++)
00107 {
00108 assert(!std::isnan(force[j]));
00109 }
00110
00111
00112 rForces[node_a_index] += force;
00113 rForces[node_b_index] -= force;
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 }
00135 }
00136
00137 template<unsigned DIM>
00138 void AbstractTwoBodyInteractionForce<DIM>::OutputForceParameters(out_stream& rParamsFile)
00139 {
00140 *rParamsFile << "\t\t\t<UseCutOffLength>" << mUseCutOffLength << "</UseCutOffLength>\n";
00141 *rParamsFile << "\t\t\t<CutOffLength>" << mMechanicsCutOffLength << "</CutOffLength>\n";
00142
00143
00144 AbstractForce<DIM>::OutputForceParameters(rParamsFile);
00145 }
00146
00148
00150
00151 template class AbstractTwoBodyInteractionForce<1>;
00152 template class AbstractTwoBodyInteractionForce<2>;
00153 template class AbstractTwoBodyInteractionForce<3>;