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 "VolumeConstraintPottsUpdateRule.hpp" 00030 00031 template<unsigned DIM> 00032 VolumeConstraintPottsUpdateRule<DIM>::VolumeConstraintPottsUpdateRule() 00033 : AbstractPottsUpdateRule<DIM>(), 00034 mDeformationEnergyParameter(0.5), // Educated guess 00035 mMatureCellTargetVolume(16.0) // Defaults to a 4*4 cell size 00036 { 00038 } 00039 00040 template<unsigned DIM> 00041 VolumeConstraintPottsUpdateRule<DIM>::~VolumeConstraintPottsUpdateRule() 00042 { 00043 } 00044 00045 template<unsigned DIM> 00046 double VolumeConstraintPottsUpdateRule<DIM>::EvaluateHamiltonianContribution(unsigned currentNodeIndex, 00047 unsigned targetNodeIndex, 00048 PottsBasedCellPopulation<DIM>& rCellPopulation) 00049 { 00050 double delta_H = 0.0; 00051 00052 std::set<unsigned> containing_elements = rCellPopulation.GetNode(currentNodeIndex)->rGetContainingElementIndices(); 00053 std::set<unsigned> new_location_containing_elements = rCellPopulation.GetNode(targetNodeIndex)->rGetContainingElementIndices(); 00054 00055 bool current_node_contained = !containing_elements.empty(); 00056 bool target_node_contained = !new_location_containing_elements.empty(); 00057 00058 // Every node must each be in at most one element. 00059 assert(new_location_containing_elements.size() < 2); 00060 00061 if(!current_node_contained && !target_node_contained) 00062 { 00063 EXCEPTION("At least one of the current node or target node must be in an element."); 00064 } 00065 00066 if (current_node_contained && target_node_contained) 00067 { 00068 if(*(new_location_containing_elements.begin()) == *(containing_elements.begin())) 00069 { 00070 EXCEPTION("The current node and target node must not be in the same element."); 00071 } 00072 } 00073 00074 if (current_node_contained) // current node is in an element 00075 { 00076 unsigned current_element = (*containing_elements.begin()); 00077 double current_volume = rCellPopulation.rGetMesh().GetVolumeOfElement(current_element); 00078 double current_volume_difference = current_volume - mMatureCellTargetVolume; 00079 00080 delta_H += mDeformationEnergyParameter*((current_volume_difference + 1.0)*(current_volume_difference + 1.0) - current_volume_difference*current_volume_difference); 00081 } 00082 if (target_node_contained) // target node is in an element 00083 { 00084 unsigned target_element = (*new_location_containing_elements.begin()); 00085 double target_volume = rCellPopulation.rGetMesh().GetVolumeOfElement(target_element); 00086 double target_volume_difference = target_volume - mMatureCellTargetVolume; 00087 00088 delta_H += mDeformationEnergyParameter*((target_volume_difference - 1.0)*(target_volume_difference - 1.0) - target_volume_difference*target_volume_difference); 00089 } 00090 00091 return delta_H; 00092 } 00093 00094 template<unsigned DIM> 00095 double VolumeConstraintPottsUpdateRule<DIM>::GetDeformationEnergyParameter() 00096 { 00097 return mDeformationEnergyParameter; 00098 } 00099 00100 template<unsigned DIM> 00101 void VolumeConstraintPottsUpdateRule<DIM>::SetDeformationEnergyParameter(double deformationEnergyParameter) 00102 { 00103 mDeformationEnergyParameter = deformationEnergyParameter; 00104 } 00105 00106 template<unsigned DIM> 00107 double VolumeConstraintPottsUpdateRule<DIM>::GetMatureCellTargetVolume() const 00108 { 00109 return mMatureCellTargetVolume; 00110 } 00111 00112 template<unsigned DIM> 00113 void VolumeConstraintPottsUpdateRule<DIM>::SetMatureCellTargetVolume(double matureCellTargetVolume) 00114 { 00115 assert(matureCellTargetVolume >= 0.0); 00116 mMatureCellTargetVolume = matureCellTargetVolume; 00117 } 00118 00119 template<unsigned DIM> 00120 void VolumeConstraintPottsUpdateRule<DIM>::OutputUpdateRuleParameters(out_stream& rParamsFile) 00121 { 00122 *rParamsFile << "\t\t\t<DeformationEnergyParameter>" << mDeformationEnergyParameter << "</DeformationEnergyParameter>\n"; 00123 *rParamsFile << "\t\t\t<MatureCellTargetVolume>" << mMatureCellTargetVolume << "</MatureCellTargetVolume>\n"; 00124 00125 // Call method on direct parent class 00126 AbstractPottsUpdateRule<DIM>::OutputUpdateRuleParameters(rParamsFile); 00127 } 00128 00130 // Explicit instantiation 00132 00133 template class VolumeConstraintPottsUpdateRule<1>; 00134 template class VolumeConstraintPottsUpdateRule<2>; 00135 template class VolumeConstraintPottsUpdateRule<3>; 00136 00137 // Serialization for Boost >= 1.36 00138 #include "SerializationExportWrapperForCpp.hpp" 00139 EXPORT_TEMPLATE_CLASS_SAME_DIMS(VolumeConstraintPottsUpdateRule)