AdhesionPottsUpdateRule.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 "AdhesionPottsUpdateRule.hpp"
00030 
00031 template<unsigned DIM>
00032 AdhesionPottsUpdateRule<DIM>::AdhesionPottsUpdateRule()
00033     : AbstractPottsUpdateRule<DIM>(),
00034       mCellCellAdhesionEnergyParameter(0.1), // Educated guess
00035       mCellBoundaryAdhesionEnergyParameter(0.2) // Educated guess
00036 {
00037 }
00038 
00039 template<unsigned DIM>
00040 AdhesionPottsUpdateRule<DIM>::~AdhesionPottsUpdateRule()
00041 {
00042 }
00043 
00044 template<unsigned DIM>
00045 double AdhesionPottsUpdateRule<DIM>::EvaluateHamiltonianContribution(unsigned currentNodeIndex,
00046                                                                 unsigned targetNodeIndex,
00047                                                                 PottsBasedCellPopulation<DIM>& rCellPopulation)
00048 {
00049     std::set<unsigned> containing_elements = rCellPopulation.GetNode(currentNodeIndex)->rGetContainingElementIndices();
00050     std::set<unsigned> new_location_containing_elements = rCellPopulation.GetNode(targetNodeIndex)->rGetContainingElementIndices();
00051 
00052     bool current_node_contained = !containing_elements.empty();
00053     bool target_node_contained = !new_location_containing_elements.empty();
00054 
00055 
00056     // Every node must each be in at most one element.
00057     assert(new_location_containing_elements.size() < 2);
00058 
00059     if(!current_node_contained && !target_node_contained)
00060     {
00061         EXCEPTION("At least one of the current node or target node must be in an element.");
00062     }
00063 
00064     if (current_node_contained && target_node_contained)
00065     {
00066         if(*(new_location_containing_elements.begin()) == *(containing_elements.begin()))
00067         {
00068             EXCEPTION("The current node and target node must not be in the same element.");
00069         }
00070     }
00071 
00072     // Iterate over nodes neighbouring the target node to work out the contact energy contribution
00073     double delta_H = 0.0;
00074     std::set<unsigned> target_neighbouring_node_indices = rCellPopulation.rGetMesh().GetVonNeumannNeighbouringNodeIndices(targetNodeIndex);
00075     for (std::set<unsigned>::iterator iter = target_neighbouring_node_indices.begin();
00076          iter != target_neighbouring_node_indices.end();
00077          ++iter)
00078     {
00079         std::set<unsigned> neighbouring_node_containing_elements = rCellPopulation.rGetMesh().GetNode(*iter)->rGetContainingElementIndices();
00080 
00081         // Every node must each be in at most one element
00082         assert(neighbouring_node_containing_elements.size() < 2);
00083 
00084         bool neighbouring_node_contained = !neighbouring_node_containing_elements.empty();
00085 
00092         if (neighbouring_node_contained && target_node_contained)
00093         {
00094             unsigned neighbour_element = (*neighbouring_node_containing_elements.begin());
00095             unsigned target_element = (*new_location_containing_elements.begin());
00096             if (target_element != neighbour_element)
00097             {
00098                 // The nodes are currently contained in different elements
00099                 delta_H -= GetCellCellAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(target_element), rCellPopulation.GetCellUsingLocationIndex(neighbour_element));
00100             }
00101         }
00102         else if (neighbouring_node_contained && !target_node_contained)
00103         {
00104             // The neighbouring node is contained in a Potts element, but the target node is not
00105             unsigned neighbour_element = (*neighbouring_node_containing_elements.begin());
00106             delta_H -= GetCellBoundaryAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(neighbour_element));
00107         }
00108         else if (!neighbouring_node_contained && target_node_contained)
00109         {
00110             // The target node is contained in a Potts element, but the neighbouring node is not
00111             unsigned target_element = (*new_location_containing_elements.begin());
00112             delta_H -= GetCellBoundaryAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(target_element));
00113         }
00114 
00121         if (neighbouring_node_contained && current_node_contained)
00122         {
00123             unsigned neighbour_element = (*neighbouring_node_containing_elements.begin());
00124             unsigned current_element = (*containing_elements.begin());
00125             if (current_element != neighbour_element)
00126             {
00127                 // The nodes are currently contained in different elements
00128                 delta_H += GetCellCellAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(current_element),rCellPopulation.GetCellUsingLocationIndex(neighbour_element));
00129             }
00130         }
00131         else if (neighbouring_node_contained && !current_node_contained)
00132         {
00133             // The neighbouring node is contained in a Potts element, but the current node is not
00134             unsigned neighbour_element = (*neighbouring_node_containing_elements.begin());
00135             delta_H += GetCellBoundaryAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(neighbour_element));
00136         }
00137         else if (!neighbouring_node_contained && current_node_contained)
00138         {
00139             // The current node is contained in a Potts element, but the neighbouring node is not
00140             unsigned current_element = (*containing_elements.begin());
00141             delta_H += GetCellBoundaryAdhesionEnergy(rCellPopulation.GetCellUsingLocationIndex(current_element));
00142         }
00143     }
00144 
00145     return delta_H;
00146 }
00147 
00148 template<unsigned DIM>
00149 double AdhesionPottsUpdateRule<DIM>::GetCellCellAdhesionEnergy(CellPtr pCellA, CellPtr pCellB)
00150 {
00151     return GetCellCellAdhesionEnergyParameter();
00152 }
00153 
00154 template<unsigned DIM>
00155 double AdhesionPottsUpdateRule<DIM>::GetCellBoundaryAdhesionEnergy(CellPtr pCell)
00156 {
00157     return GetCellBoundaryAdhesionEnergyParameter();
00158 }
00159 
00160 template<unsigned DIM>
00161 double AdhesionPottsUpdateRule<DIM>::GetCellCellAdhesionEnergyParameter()
00162 {
00163     return mCellCellAdhesionEnergyParameter;
00164 }
00165 
00166 template<unsigned DIM>
00167 double AdhesionPottsUpdateRule<DIM>::GetCellBoundaryAdhesionEnergyParameter()
00168 {
00169     return mCellBoundaryAdhesionEnergyParameter;
00170 }
00171 
00172 template<unsigned DIM>
00173 void AdhesionPottsUpdateRule<DIM>::SetCellCellAdhesionEnergyParameter(double cellCellAdhesionEnergyParameter)
00174 {
00175     mCellCellAdhesionEnergyParameter = cellCellAdhesionEnergyParameter;
00176 }
00177 
00178 template<unsigned DIM>
00179 void AdhesionPottsUpdateRule<DIM>::SetCellBoundaryAdhesionEnergyParameter(double cellBoundaryAdhesionEnergyParameter)
00180 {
00181     mCellBoundaryAdhesionEnergyParameter = cellBoundaryAdhesionEnergyParameter;
00182 }
00183 
00184 template<unsigned DIM>
00185 void AdhesionPottsUpdateRule<DIM>::OutputUpdateRuleParameters(out_stream& rParamsFile)
00186 {
00187     *rParamsFile << "\t\t\t<CellCellAdhesionEnergyParameter>" << mCellCellAdhesionEnergyParameter << "</CellCellAdhesionEnergyParameter>\n";
00188     *rParamsFile << "\t\t\t<CellBoundaryAdhesionEnergyParameter>" << mCellBoundaryAdhesionEnergyParameter << "</CellBoundaryAdhesionEnergyParameter>\n";
00189 
00190     // Call method on direct parent class
00191     AbstractPottsUpdateRule<DIM>::OutputUpdateRuleParameters(rParamsFile);
00192 }
00193 
00195 // Explicit instantiation
00197 
00198 template class AdhesionPottsUpdateRule<1>;
00199 template class AdhesionPottsUpdateRule<2>;
00200 template class AdhesionPottsUpdateRule<3>;
00201 
00202 // Serialization for Boost >= 1.36
00203 #include "SerializationExportWrapperForCpp.hpp"
00204 EXPORT_TEMPLATE_CLASS_SAME_DIMS(AdhesionPottsUpdateRule)
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3