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
00032 template<unsigned DIM>
00033 AbstractTwoBodyInteractionForce<DIM>::AbstractTwoBodyInteractionForce()
00034 : AbstractForce<DIM>(),
00035 mUseCutoffPoint(false)
00036 {
00037 }
00038
00039
00040 template<unsigned DIM>
00041 void AbstractTwoBodyInteractionForce<DIM>::UseCutoffPoint(double cutoffPoint)
00042 {
00043 assert(cutoffPoint > 0.0);
00044 mUseCutoffPoint = true;
00045 TissueConfig::Instance()->SetMechanicsCutOffLength(cutoffPoint);
00046 }
00047
00048
00049 template<unsigned DIM>
00050 double AbstractTwoBodyInteractionForce<DIM>::GetCutoffPoint()
00051 {
00052 return TissueConfig::Instance()->GetMechanicsCutOffLength();
00053 }
00054
00055
00056 template<unsigned DIM>
00057 void AbstractTwoBodyInteractionForce<DIM>::AddForceContribution(std::vector<c_vector<double, DIM> >& rForces,
00058 AbstractTissue<DIM>& rTissue)
00059 {
00060 if (rTissue.HasMesh())
00061 {
00062 MeshBasedTissue<DIM>* p_static_cast_tissue = static_cast<MeshBasedTissue<DIM>*>(&rTissue);
00063
00064
00065 for (typename MeshBasedTissue<DIM>::SpringIterator spring_iterator = p_static_cast_tissue->SpringsBegin();
00066 spring_iterator != p_static_cast_tissue->SpringsEnd();
00067 ++spring_iterator)
00068 {
00069 unsigned nodeA_global_index = spring_iterator.GetNodeA()->GetIndex();
00070 unsigned nodeB_global_index = spring_iterator.GetNodeB()->GetIndex();
00071
00072
00073 c_vector<double, DIM> force = CalculateForceBetweenNodes(nodeA_global_index, nodeB_global_index, rTissue);
00074
00075
00076 rForces[nodeB_global_index] -= force;
00077 rForces[nodeA_global_index] += force;
00078 }
00079 }
00080 else
00081 {
00082 std::set< std::pair<Node<DIM>*, Node<DIM>* > >& r_node_pairs = (static_cast<NodeBasedTissue<DIM>*>(&rTissue))->rGetNodePairs();
00083
00084 assert(DIM==2);
00085
00086 for (typename std::set< std::pair<Node<DIM>*, Node<DIM>* > >::iterator iter = r_node_pairs.begin();
00087 iter != r_node_pairs.end();
00088 iter++)
00089 {
00090 std::pair<Node<DIM>*, Node<DIM>* > pair = *iter;
00091
00092 unsigned node_a_index = pair.first->GetIndex();
00093 unsigned node_b_index = pair.second->GetIndex();
00094
00095
00096 c_vector<double, DIM> force = CalculateForceBetweenNodes(node_a_index, node_b_index, rTissue);
00097 for (unsigned j=0; j<DIM; j++)
00098 {
00099 assert(!std::isnan(force[j]));
00100 }
00101
00102
00103 rForces[node_a_index] += force;
00104 rForces[node_b_index] -= force;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 }
00126 }
00127
00128
00129
00131
00133
00134 template class AbstractTwoBodyInteractionForce<1>;
00135 template class AbstractTwoBodyInteractionForce<2>;
00136 template class AbstractTwoBodyInteractionForce<3>;