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