AbstractTwoBodyInteractionForce.cpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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     // Throw an exception message if not using a subclass of AbstractCentreBasedCellPopulation
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         // Iterate over all springs and add force contributions
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             // Calculate the force between nodes
00090             c_vector<double, SPACE_DIM> force = CalculateForceBetweenNodes(nodeA_global_index, nodeB_global_index, rCellPopulation);
00091 
00092             // Add the force contribution to each node
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    // This is a NodeBasedCellPopulation
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             // Calculate the force between nodes
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             // Add the force contribution to each node
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     // Call method on direct parent class
00135     AbstractForce<ELEMENT_DIM,SPACE_DIM>::OutputForceParameters(rParamsFile);
00136 }
00137 
00139 // Explicit instantiation
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>;

Generated by  doxygen 1.6.2