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