RepulsionForce.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 "RepulsionForce.hpp"
00037 #include "IsNan.hpp"
00038
00039 template<unsigned DIM>
00040 RepulsionForce<DIM>::RepulsionForce()
00041 : GeneralisedLinearSpringForce<DIM>()
00042 {
00043 }
00044
00045 template<unsigned DIM>
00046 void RepulsionForce<DIM>::AddForceContribution(AbstractCellPopulation<DIM>& rCellPopulation)
00047 {
00048
00049 if (dynamic_cast<NodeBasedCellPopulation<DIM>*>(&rCellPopulation) == NULL)
00050 {
00051 EXCEPTION("RepulsionForce is to be used with a NodeBasedCellPopulation only");
00052 }
00053
00054 std::vector< std::pair<Node<DIM>*, Node<DIM>* > >& r_node_pairs = (static_cast<NodeBasedCellPopulation<DIM>*>(&rCellPopulation))->rGetNodePairs();
00055
00056 for (typename std::vector< std::pair<Node<DIM>*, Node<DIM>* > >::iterator iter = r_node_pairs.begin();
00057 iter != r_node_pairs.end();
00058 iter++)
00059 {
00060 std::pair<Node<DIM>*, Node<DIM>* > pair = *iter;
00061
00062 Node<DIM>* p_node_a = pair.first;
00063 Node<DIM>* p_node_b = pair.second;
00064
00065
00066 c_vector<double, DIM> node_a_location = p_node_a->rGetLocation();
00067 c_vector<double, DIM> node_b_location = p_node_b->rGetLocation();
00068
00069
00070 double node_a_radius = p_node_a->GetRadius();
00071 double node_b_radius = p_node_b->GetRadius();
00072
00073
00074 c_vector<double, DIM> unit_difference;
00075
00076 unit_difference = (static_cast<NodeBasedCellPopulation<DIM>*>(&rCellPopulation))->rGetMesh().GetVectorFromAtoB(node_a_location, node_b_location);
00077
00078
00079 double rest_length = node_a_radius+node_b_radius;
00080
00081 if (norm_2(unit_difference) < rest_length)
00082 {
00083
00084 c_vector<double, DIM> force = this->CalculateForceBetweenNodes(p_node_a->GetIndex(), p_node_b->GetIndex(), rCellPopulation);
00085 c_vector<double, DIM> negative_force = -1.0 * force;
00086 for (unsigned j=0; j<DIM; j++)
00087 {
00088 assert(!std::isnan(force[j]));
00089 }
00090
00091 p_node_a->AddAppliedForceContribution(force);
00092 p_node_b->AddAppliedForceContribution(negative_force);
00093 }
00094 }
00095 }
00096
00097 template<unsigned DIM>
00098 void RepulsionForce<DIM>::OutputForceParameters(out_stream& rParamsFile)
00099 {
00100
00101 GeneralisedLinearSpringForce<DIM>::OutputForceParameters(rParamsFile);
00102 }
00103
00105
00107
00108 template class RepulsionForce<1>;
00109 template class RepulsionForce<2>;
00110 template class RepulsionForce<3>;
00111
00112
00113 #include "SerializationExportWrapperForCpp.hpp"
00114 EXPORT_TEMPLATE_CLASS_SAME_DIMS(RepulsionForce)