AbstractTwoBodyInteractionForce.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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         // Iterate over all springs and add force contributions
00063         for (typename MeshBasedTissue<DIM>::SpringIterator spring_iterator=(static_cast<MeshBasedTissue<DIM>*>(&rTissue))->SpringsBegin();
00064             spring_iterator!=(static_cast<MeshBasedTissue<DIM>*>(&rTissue))->SpringsEnd();
00065             ++spring_iterator)
00066         {
00067             unsigned nodeA_global_index = spring_iterator.GetNodeA()->GetIndex();
00068             unsigned nodeB_global_index = spring_iterator.GetNodeB()->GetIndex();
00069 
00070             // Calculate the force between nodes
00071             c_vector<double, DIM> force = CalculateForceBetweenNodes(nodeA_global_index, nodeB_global_index, rTissue);
00072 
00073             // Add the force contribution to each node
00074             rForces[nodeB_global_index] -= force;
00075             rForces[nodeA_global_index] += force;
00076         }
00077     }
00078     else
00079     {
00080         std::set< std::pair<Node<DIM>*, Node<DIM>* > >& r_node_pairs = (static_cast<NodeBasedTissue<DIM>*>(&rTissue))->rGetNodePairs();
00081 
00082         assert(DIM==2); // 3d boxes not implemented yet - if fails nightly uncomment the double node loop below
00083                         // and use that for the 3d case
00084         for (typename std::set< std::pair<Node<DIM>*, Node<DIM>* > >::iterator iter = r_node_pairs.begin();
00085             iter != r_node_pairs.end();
00086             iter++)
00087         {
00088             std::pair<Node<DIM>*, Node<DIM>* > pair = *iter;
00089 
00090             unsigned node_a_index = pair.first->GetIndex();
00091             unsigned node_b_index = pair.second->GetIndex();
00092 
00093             // Calculate the force between nodes
00094             c_vector<double, DIM> force = CalculateForceBetweenNodes(node_a_index, node_b_index, rTissue);
00095             for (unsigned j=0; j<DIM; j++)
00096             {
00097                 assert(!std::isnan(force[j]));
00098             }
00099 
00100             // Add the force contribution to each node
00101             rForces[node_a_index] += force;
00102             rForces[node_b_index] -= force;
00103         }
00104 
00105 //        // Iterate over nodes
00106 //        for (unsigned node_a_index=0; node_a_index<rTissue.GetNumNodes(); node_a_index++)
00107 //        {
00108 //            // Iterate over nodes
00109 //            for (unsigned node_b_index=node_a_index+1; node_b_index<rTissue.GetNumNodes(); node_b_index++)
00110 //            {
00111 //                // Calculate the force between nodes
00112 //                c_vector<double, DIM> force = CalculateForceBetweenNodes(node_a_index, node_b_index, rTissue);
00113 //                for (unsigned j=0; j<DIM; j++)
00114 //                {
00115 //                    assert(!std::isnan(force[j]));
00116 //                }
00117 //
00118 //                // Add the force contribution to each node
00119 //                rForces[node_a_index] += force;
00120 //                rForces[node_b_index] -= force;
00121 //            }
00122 //        }
00123     }
00124 }
00125 
00126 
00127 
00129 // Explicit instantiation
00131 
00132 template class AbstractTwoBodyInteractionForce<1>;
00133 template class AbstractTwoBodyInteractionForce<2>;
00134 template class AbstractTwoBodyInteractionForce<3>;

Generated on Tue Aug 4 16:10:21 2009 for Chaste by  doxygen 1.5.5