AbstractTwoBodyInteractionForce.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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 "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         // Iterate over all springs and add force contributions
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             // Calculate the force between nodes
00073             c_vector<double, DIM> force = CalculateForceBetweenNodes(nodeA_global_index, nodeB_global_index, rTissue);
00074 
00075             // Add the force contribution to each node
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); // 3d boxes not implemented yet - if fails nightly uncomment the double node loop below
00085                         // and use that for the 3d case
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             // Calculate the force between nodes
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             // Add the force contribution to each node
00103             rForces[node_a_index] += force;
00104             rForces[node_b_index] -= force;
00105         }
00106 
00107 //        // Iterate over nodes
00108 //        for (unsigned node_a_index=0; node_a_index<rTissue.GetNumNodes(); node_a_index++)
00109 //        {
00110 //            // Iterate over nodes
00111 //            for (unsigned node_b_index=node_a_index+1; node_b_index<rTissue.GetNumNodes(); node_b_index++)
00112 //            {
00113 //                // Calculate the force between nodes
00114 //                c_vector<double, DIM> force = CalculateForceBetweenNodes(node_a_index, node_b_index, rTissue);
00115 //                for (unsigned j=0; j<DIM; j++)
00116 //                {
00117 //                    assert(!std::isnan(force[j]));
00118 //                }
00119 //
00120 //                // Add the force contribution to each node
00121 //                rForces[node_a_index] += force;
00122 //                rForces[node_b_index] -= force;
00123 //            }
00124 //        }
00125     }
00126 }
00127 
00128 
00129 
00131 // Explicit instantiation
00133 
00134 template class AbstractTwoBodyInteractionForce<1>;
00135 template class AbstractTwoBodyInteractionForce<2>;
00136 template class AbstractTwoBodyInteractionForce<3>;

Generated by  doxygen 1.6.2