Chaste Release::3.1
ExplicitCardiacMechanicsSolver.cpp
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 "ExplicitCardiacMechanicsSolver.hpp"
00037 #include "Nash2004ContractionModel.hpp"
00038 #include "Kerchoffs2003ContractionModel.hpp"
00039 #include "NonPhysiologicalContractionModel.hpp"
00040 #include "FakeBathContractionModel.hpp"
00041 
00042 template<class ELASTICITY_SOLVER,unsigned DIM>
00043 ExplicitCardiacMechanicsSolver<ELASTICITY_SOLVER,DIM>::ExplicitCardiacMechanicsSolver(ContractionModelName contractionModelName,
00044                                                                                       QuadraticMesh<DIM>& rQuadMesh,
00045                                                                                       ElectroMechanicsProblemDefinition<DIM>& rProblemDefinition,
00046                                                                                       std::string outputDirectory)
00047     : AbstractCardiacMechanicsSolver<ELASTICITY_SOLVER,DIM>(rQuadMesh,
00048                                                             contractionModelName,
00049                                                             rProblemDefinition,
00050                                                             outputDirectory)
00051 {
00052 
00053 }
00054 
00055 
00056 
00057 template<class ELASTICITY_SOLVER,unsigned DIM>
00058 void ExplicitCardiacMechanicsSolver<ELASTICITY_SOLVER,DIM>::InitialiseContractionModels(ContractionModelName contractionModelName)
00059 {
00060     for(std::map<unsigned,DataAtQuadraturePoint>::iterator iter = this->mQuadPointToDataAtQuadPointMap.begin();
00061         iter != this->mQuadPointToDataAtQuadPointMap.end();
00062         iter++)
00063     {
00064         AbstractContractionModel* p_contraction_model;
00065 
00066         if (iter->second.Active == true)
00067         {
00068             //tissue node
00069             switch(contractionModelName)
00070             {
00071                 case NONPHYSIOL1:
00072                 case NONPHYSIOL2:
00073                 case NONPHYSIOL3:
00074                 {
00075                     unsigned option = (contractionModelName==NONPHYSIOL1 ? 1 : (contractionModelName==NONPHYSIOL2? 2 : 3));
00076                     p_contraction_model = new NonPhysiologicalContractionModel(option);
00077                     break;
00078                 }
00079                 case NASH2004: //stretch dependent, will this work with explicit??
00080                 {
00081                     p_contraction_model = new Nash2004ContractionModel;
00082                     break;
00083                 }
00084                 case KERCHOFFS2003: //stretch dependent, will this work with explicit? Answer: can be unstable
00085                 {
00086                     p_contraction_model = new Kerchoffs2003ContractionModel;
00087                     break;
00088                 }
00089                 default:
00090                 {
00091                     EXCEPTION("Unknown or stretch-rate-dependent contraction model");
00092                 }
00093             }
00094 
00095             iter->second.ContractionModel = p_contraction_model;
00096         }
00097         else
00098         {
00099             //bath
00100             p_contraction_model = new FakeBathContractionModel;
00101             iter->second.ContractionModel = p_contraction_model;
00102         }
00103     }
00104 }
00105 
00106 template<class ELASTICITY_SOLVER,unsigned DIM>
00107 ExplicitCardiacMechanicsSolver<ELASTICITY_SOLVER,DIM>::~ExplicitCardiacMechanicsSolver()
00108 {
00109 }
00110 
00111 template<class ELASTICITY_SOLVER,unsigned DIM>
00112 void ExplicitCardiacMechanicsSolver<ELASTICITY_SOLVER,DIM>::GetActiveTensionAndTensionDerivs(double currentFibreStretch,
00113                                                                                              unsigned currentQuadPointGlobalIndex,
00114                                                                                              bool assembleJacobian,
00115                                                                                              double& rActiveTension,
00116                                                                                              double& rDerivActiveTensionWrtLambda,
00117                                                                                              double& rDerivActiveTensionWrtDLambdaDt)
00118 {
00119     // The iterator should be pointing to the right place (note: it is incremented at the end of this method)
00120     // This iterator is used so that we don't have to search the map
00121     assert(this->mMapIterator->first==currentQuadPointGlobalIndex);
00122     DataAtQuadraturePoint& r_data_at_quad_point = this->mMapIterator->second;
00123 
00124     // the active tensions have already been computed for each contraction model, so can
00125     // return it straightaway..
00126     rActiveTension = r_data_at_quad_point.ContractionModel->GetActiveTension();
00127 
00128     // these are unset
00129     rDerivActiveTensionWrtLambda = 0.0;
00130     rDerivActiveTensionWrtDLambdaDt = 0.0;
00131 
00132     // store the value of given for this quad point, so that it can be used when computing
00133     // the active tension at the next timestep
00134     r_data_at_quad_point.Stretch = currentFibreStretch;
00135 
00136     // increment the iterator
00137     this->mMapIterator++;
00138     if(this->mMapIterator==this->mQuadPointToDataAtQuadPointMap.end())
00139     {
00140         this->mMapIterator = this->mQuadPointToDataAtQuadPointMap.begin();
00141     }
00142 
00143 }
00144 
00145 template<class ELASTICITY_SOLVER,unsigned DIM>
00146 void ExplicitCardiacMechanicsSolver<ELASTICITY_SOLVER,DIM>::Solve(double time, double nextTime, double odeTimestep)
00147 {
00148     assert(time < nextTime);
00149     this->mCurrentTime = time;
00150     this->mNextTime = nextTime;
00151     this->mOdeTimestep = odeTimestep;
00152 
00153     // assemble the residual again so that mStretches is set (in GetActiveTensionAndTensionDerivs)
00154     // using the current deformation.
00155     this->AssembleSystem(true,false);
00156 
00157     // integrate contraction models
00158     for(std::map<unsigned,DataAtQuadraturePoint>::iterator iter = this->mQuadPointToDataAtQuadPointMap.begin();
00159         iter != this->mQuadPointToDataAtQuadPointMap.end();
00160         iter++)
00161     {
00162         AbstractContractionModel* p_contraction_model = iter->second.ContractionModel;
00163         double stretch = iter->second.Stretch;
00164         p_contraction_model->SetStretchAndStretchRate(stretch, 0.0 /*dlam_dt*/);
00165         p_contraction_model->RunAndUpdate(time, nextTime, odeTimestep);
00166     }
00167 
00168     // solve
00169     ELASTICITY_SOLVER::Solve();
00170 }
00171 
00172 
00173 
00174 template class ExplicitCardiacMechanicsSolver<IncompressibleNonlinearElasticitySolver<2>,2>;
00175 template class ExplicitCardiacMechanicsSolver<IncompressibleNonlinearElasticitySolver<3>,3>;
00176 template class ExplicitCardiacMechanicsSolver<CompressibleNonlinearElasticitySolver<2>,2>;
00177 template class ExplicitCardiacMechanicsSolver<CompressibleNonlinearElasticitySolver<3>,3>;