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