RepulsionForce.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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     // Throw an exception message if not using a NodeBasedCellPopulation
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         // Get the node locations
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         // Get the unit vector parallel to the line joining the two nodes
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             // Calculate the force between nodes
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             // Add the force contribution to each node
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     // Call direct parent class
00088     GeneralisedLinearSpringForce<DIM>::OutputForceParameters(rParamsFile);
00089 }
00090 
00092 // Explicit instantiation
00094 
00095 template class RepulsionForce<1>;
00096 template class RepulsionForce<2>;
00097 template class RepulsionForce<3>;
00098 
00099 // Serialization for Boost >= 1.36
00100 #include "SerializationExportWrapperForCpp.hpp"
00101 EXPORT_TEMPLATE_CLASS_SAME_DIMS(RepulsionForce)
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3