LinearSpringWithVariableSpringConstantsForce.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 "LinearSpringWithVariableSpringConstantsForce.hpp"
00030 #include "MeshBasedCellPopulation.hpp"
00031 #include "VanLeeuwen2009WntSwatCellCycleModelHypothesisOne.hpp"
00032 #include "VanLeeuwen2009WntSwatCellCycleModelHypothesisTwo.hpp"
00033 #include "ApoptoticCellProperty.hpp"
00034 
00035 template<unsigned DIM>
00036 LinearSpringWithVariableSpringConstantsForce<DIM>::LinearSpringWithVariableSpringConstantsForce()
00037     : GeneralisedLinearSpringForce<DIM>(),
00038       mUseEdgeBasedSpringConstant(false),
00039       mUseMutantSprings(false),
00040       mMutantMutantMultiplier(DOUBLE_UNSET),
00041       mNormalMutantMultiplier(DOUBLE_UNSET),
00042       mUseBCatSprings(false),
00043       mUseApoptoticSprings(false),
00044       mBetaCatSpringScaler(18.14/6.0), // scale spring constant with beta-catenin level (divided by 6 for heaxagonal cells)
00045       mApoptoticSpringTensionStiffness(15.0*0.25),
00046       mApoptoticSpringCompressionStiffness(15.0*0.75)
00047 {
00048 }
00049 
00050 template<unsigned DIM>
00051 LinearSpringWithVariableSpringConstantsForce<DIM>::~LinearSpringWithVariableSpringConstantsForce()
00052 {
00053 }
00054 
00055 template<unsigned DIM>
00056 void LinearSpringWithVariableSpringConstantsForce<DIM>::SetEdgeBasedSpringConstant(bool useEdgeBasedSpringConstant)
00057 {
00058     assert(DIM == 2);
00059     mUseEdgeBasedSpringConstant = useEdgeBasedSpringConstant;
00060 }
00061 
00062 template<unsigned DIM>
00063 void LinearSpringWithVariableSpringConstantsForce<DIM>::SetMutantSprings(bool useMutantSprings, double mutantMutantMultiplier, double normalMutantMultiplier)
00064 {
00065     mUseMutantSprings = useMutantSprings;
00066     mMutantMutantMultiplier = mutantMutantMultiplier;
00067     mNormalMutantMultiplier = normalMutantMultiplier;
00068 }
00069 
00070 template<unsigned DIM>
00071 void LinearSpringWithVariableSpringConstantsForce<DIM>::SetBetaCateninSprings(bool useBCatSprings)
00072 {
00073     mUseBCatSprings = useBCatSprings;
00074 }
00075 
00076 template<unsigned DIM>
00077 void LinearSpringWithVariableSpringConstantsForce<DIM>::SetApoptoticSprings(bool useApoptoticSprings)
00078 {
00079     mUseApoptoticSprings = useApoptoticSprings;
00080 }
00081 
00082 template<unsigned DIM>
00083 double LinearSpringWithVariableSpringConstantsForce<DIM>::VariableSpringConstantMultiplicationFactor(
00084     unsigned nodeAGlobalIndex,
00085     unsigned nodeBGlobalIndex,
00086     AbstractCellPopulation<DIM>& rCellPopulation,
00087     bool isCloserThanRestLength)
00088 {
00089 
00090     double multiplication_factor = GeneralisedLinearSpringForce<DIM>::VariableSpringConstantMultiplicationFactor(nodeAGlobalIndex,
00091                                                                                                             nodeBGlobalIndex,
00092                                                                                                             rCellPopulation,
00093                                                                                                             isCloserThanRestLength);
00094 
00095     CellPtr p_cell_A = rCellPopulation.GetCellUsingLocationIndex(nodeAGlobalIndex);
00096     CellPtr p_cell_B = rCellPopulation.GetCellUsingLocationIndex(nodeBGlobalIndex);
00097 
00098     if (mUseEdgeBasedSpringConstant)
00099     {
00100         assert(dynamic_cast<MeshBasedCellPopulation<DIM>*>(&rCellPopulation));
00101         assert(!mUseBCatSprings);   // don't want to do both (both account for edge length)
00102 
00103         multiplication_factor = (static_cast<MeshBasedCellPopulation<DIM>*>(&rCellPopulation))->GetVoronoiEdgeLength(nodeAGlobalIndex, nodeBGlobalIndex)*sqrt(3);
00104     }
00105 
00106     if (mUseMutantSprings)
00107     {
00108         unsigned number_of_mutants = 0;
00109 
00110         if (p_cell_A->GetMutationState()->IsType<ApcTwoHitCellMutationState>() || p_cell_A->GetMutationState()->IsType<BetaCateninOneHitCellMutationState>())
00111         {
00112             // If cell A is mutant
00113             number_of_mutants++;
00114         }
00115 
00116         if (p_cell_B->GetMutationState()->IsType<ApcTwoHitCellMutationState>() || p_cell_B->GetMutationState()->IsType<BetaCateninOneHitCellMutationState>())
00117         {
00118             // If cell B is mutant
00119             number_of_mutants++;
00120         }
00121 
00122         switch (number_of_mutants)
00123         {
00124             case 1u:
00125             {
00126                 multiplication_factor *= mNormalMutantMultiplier;
00127                 break;
00128             }
00129             case 2u:
00130             {
00131                 multiplication_factor *= mMutantMutantMultiplier;
00132                 break;
00133             }
00134         }
00135     }
00136 
00137     if (mUseBCatSprings)
00138     {
00139         assert(dynamic_cast<MeshBasedCellPopulation<DIM>*>(&rCellPopulation));
00140 
00141         // If using beta-cat dependent springs, both cell-cycle models had better be VanLeeuwen2009WntSwatCellCycleModel
00142         AbstractVanLeeuwen2009WntSwatCellCycleModel* p_model_A = dynamic_cast<AbstractVanLeeuwen2009WntSwatCellCycleModel*>(p_cell_A->GetCellCycleModel());
00143         AbstractVanLeeuwen2009WntSwatCellCycleModel* p_model_B = dynamic_cast<AbstractVanLeeuwen2009WntSwatCellCycleModel*>(p_cell_B->GetCellCycleModel());
00144 
00145         assert(!mUseEdgeBasedSpringConstant);   // This already adapts for edge lengths - don't want to do it twice.
00146         double beta_cat_cell_1 = p_model_A->GetMembraneBoundBetaCateninLevel();
00147         double beta_cat_cell_2 = p_model_B->GetMembraneBoundBetaCateninLevel();
00148 
00149         MeshBasedCellPopulation<DIM>* p_static_cast_cell_population = (static_cast<MeshBasedCellPopulation<DIM>*>(&rCellPopulation));
00150 
00151         double perim_cell_1 = p_static_cast_cell_population->GetSurfaceAreaOfVoronoiElement(nodeAGlobalIndex);
00152         double perim_cell_2 = p_static_cast_cell_population->GetSurfaceAreaOfVoronoiElement(nodeBGlobalIndex);
00153         double edge_length_between_1_and_2 = p_static_cast_cell_population->GetVoronoiEdgeLength(nodeAGlobalIndex, nodeBGlobalIndex);
00154 
00155         double beta_cat_on_cell_1_edge = beta_cat_cell_1 *  edge_length_between_1_and_2 / perim_cell_1;
00156         double beta_cat_on_cell_2_edge = beta_cat_cell_2 *  edge_length_between_1_and_2 / perim_cell_2;
00157 
00158         double min_beta_Cat_of_two_cells = std::min(beta_cat_on_cell_1_edge, beta_cat_on_cell_2_edge);
00159 
00160         multiplication_factor *= min_beta_Cat_of_two_cells / mBetaCatSpringScaler;
00161     }
00162 
00163     if (mUseApoptoticSprings)
00164     {
00165         bool cell_A_is_apoptotic = p_cell_A->HasCellProperty<ApoptoticCellProperty>();
00166         bool cell_B_is_apoptotic = p_cell_B->HasCellProperty<ApoptoticCellProperty>();
00167 
00168         if (cell_A_is_apoptotic || cell_B_is_apoptotic)
00169         {
00170             double spring_a_stiffness = 2.0 * this->GetMeinekeSpringStiffness();
00171             double spring_b_stiffness = 2.0 * this->GetMeinekeSpringStiffness();
00172 
00173             if (cell_A_is_apoptotic)
00174             {
00175                 if (!isCloserThanRestLength) // if under tension
00176                 {
00177                     spring_a_stiffness = mApoptoticSpringTensionStiffness;
00178                 }
00179                 else // if under compression
00180                 {
00181                     spring_a_stiffness = mApoptoticSpringCompressionStiffness;
00182                 }
00183             }
00184             if (cell_B_is_apoptotic)
00185             {
00186                 if (!isCloserThanRestLength) // if under tension
00187                 {
00188                     spring_b_stiffness = mApoptoticSpringTensionStiffness;
00189                 }
00190                 else // if under compression
00191                 {
00192                     spring_b_stiffness = mApoptoticSpringCompressionStiffness;
00193                 }
00194             }
00195 
00196             multiplication_factor /= (1.0/spring_a_stiffness + 1.0/spring_b_stiffness)*this->GetMeinekeSpringStiffness();
00197         }
00198     }
00199 
00200     return multiplication_factor;
00201 }
00202 
00203 template<unsigned DIM>
00204 void LinearSpringWithVariableSpringConstantsForce<DIM>::AddForceContribution(std::vector<c_vector<double, DIM> >& rForces,
00205                                                                              AbstractCellPopulation<DIM>& rCellPopulation)
00206 {
00207     // Throw an exception message if not using a MeshBasedCellPopulation
00208     if (dynamic_cast<MeshBasedCellPopulation<DIM>*>(&rCellPopulation) == NULL)
00209     {
00210         EXCEPTION("LinearSpringWithVariableSpringConstantsForce is to be used with a subclass of MeshBasedCellPopulation only");
00211     }
00212 
00213     MeshBasedCellPopulation<DIM>* p_static_cast_cell_population = static_cast<MeshBasedCellPopulation<DIM>*>(&rCellPopulation);
00214 
00215     for (typename MeshBasedCellPopulation<DIM>::SpringIterator spring_iterator = p_static_cast_cell_population->SpringsBegin();
00216         spring_iterator != p_static_cast_cell_population->SpringsEnd();
00217         ++spring_iterator)
00218     {
00219         unsigned nodeA_global_index = spring_iterator.GetNodeA()->GetIndex();
00220         unsigned nodeB_global_index = spring_iterator.GetNodeB()->GetIndex();
00221 
00222         c_vector<double, DIM> force = CalculateForceBetweenNodes(nodeA_global_index, nodeB_global_index, rCellPopulation);
00223 
00224         rForces[nodeB_global_index] -= force;
00225         rForces[nodeA_global_index] += force;
00226     }
00227 }
00228 
00229 template<unsigned DIM>
00230 double LinearSpringWithVariableSpringConstantsForce<DIM>::GetBetaCatSpringScaler()
00231 {
00232     return mBetaCatSpringScaler;
00233 }
00234 
00235 template<unsigned DIM>
00236 void LinearSpringWithVariableSpringConstantsForce<DIM>::SetBetaCatSpringScaler(double betaCatSpringScaler)
00237 {
00238     assert(betaCatSpringScaler > 0.0);
00239     mBetaCatSpringScaler = betaCatSpringScaler;
00240 }
00241 
00242 template<unsigned DIM>
00243 double LinearSpringWithVariableSpringConstantsForce<DIM>::GetApoptoticSpringTensionStiffness()
00244 {
00245     return mApoptoticSpringTensionStiffness;
00246 }
00247 
00248 template<unsigned DIM>
00249 void LinearSpringWithVariableSpringConstantsForce<DIM>::SetApoptoticSpringTensionStiffness(double apoptoticSpringTensionStiffness)
00250 {
00251     assert(apoptoticSpringTensionStiffness >= 0.0);
00252     mApoptoticSpringTensionStiffness = apoptoticSpringTensionStiffness;
00253 }
00254 
00255 template<unsigned DIM>
00256 double LinearSpringWithVariableSpringConstantsForce<DIM>::GetApoptoticSpringCompressionStiffness()
00257 {
00258     return mApoptoticSpringCompressionStiffness;
00259 }
00260 
00261 template<unsigned DIM>
00262 void LinearSpringWithVariableSpringConstantsForce<DIM>::SetApoptoticSpringCompressionStiffness(double apoptoticSpringCompressionStiffness)
00263 {
00264     assert(apoptoticSpringCompressionStiffness >= 0.0);
00265     mApoptoticSpringCompressionStiffness = apoptoticSpringCompressionStiffness;
00266 }
00267 
00268 template<unsigned DIM>
00269 void LinearSpringWithVariableSpringConstantsForce<DIM>::OutputForceParameters(out_stream& rParamsFile)
00270 {
00271     *rParamsFile << "\t\t\t<UseEdgeBasedSpringConstant>" << mUseEdgeBasedSpringConstant << "</UseEdgeBasedSpringConstant>\n";
00272     *rParamsFile << "\t\t\t<UseMutantSprings>" << mUseMutantSprings << "</UseMutantSprings>\n";
00273     *rParamsFile << "\t\t\t<MutantMutantMultiplier>" << mMutantMutantMultiplier << "</MutantMutantMultiplier>\n";
00274     *rParamsFile << "\t\t\t<NormalMutantMultiplier>" << mNormalMutantMultiplier << "</NormalMutantMultiplier>\n";
00275     *rParamsFile << "\t\t\t<UseBCatSprings>" << mUseBCatSprings << "</UseBCatSprings>\n";
00276     *rParamsFile << "\t\t\t<UseApoptoticSprings>" << mUseApoptoticSprings << "</UseApoptoticSprings>\n";
00277     *rParamsFile << "\t\t\t<BetaCatSpringScaler>" << mBetaCatSpringScaler << "</BetaCatSpringScaler>\n";
00278     *rParamsFile << "\t\t\t<ApoptoticSpringTensionStiffness>" << mApoptoticSpringTensionStiffness << "</ApoptoticSpringTensionStiffness>\n";
00279     *rParamsFile << "\t\t\t<ApoptoticSpringCompressionStiffness>" << mApoptoticSpringCompressionStiffness << "</ApoptoticSpringCompressionStiffness>\n";
00280 
00281     // Call method on direct parent class
00282     GeneralisedLinearSpringForce<DIM>::OutputForceParameters(rParamsFile);
00283 }
00284 
00286 // Explicit instantiation
00288 
00289 template class LinearSpringWithVariableSpringConstantsForce<1>;
00290 template class LinearSpringWithVariableSpringConstantsForce<2>;
00291 template class LinearSpringWithVariableSpringConstantsForce<3>;
00292 
00293 
00294 // Serialization for Boost >= 1.36
00295 #include "SerializationExportWrapperForCpp.hpp"
00296 EXPORT_TEMPLATE_CLASS_SAME_DIMS(LinearSpringWithVariableSpringConstantsForce)
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3