ElectroMechanicsProblemDefinition.cpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, 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 "ElectroMechanicsProblemDefinition.hpp"
00037 #include "LabelBasedContractionCellFactory.hpp"
00038 
00039 template<unsigned DIM>
00040 ElectroMechanicsProblemDefinition<DIM>::ElectroMechanicsProblemDefinition(QuadraticMesh<DIM>& rMesh)
00041     : SolidMechanicsProblemDefinition<DIM>(rMesh),
00042       mContractionModelOdeTimeStep(-1.0),
00043       mMechanicsSolveTimestep(-1.0),
00044       mDeformationAffectsConductivity(false),
00045       mDeformationAffectsCellModels(false),
00046       mpDefaultMaterialLaw(NULL),
00047       mReadFibreSheetInformationFromFile(false),
00048       mNumIncrementsForInitialDeformation(1),
00049       mApplyCrossFibreTension(false),
00050       mSheetTensionFraction(DOUBLE_UNSET),
00051       mSheetNormalTensionFraction(DOUBLE_UNSET),
00052       mpContractionCellFactory(NULL),
00053       mWeMadeCellFactory(false),
00054       mSolverType(IMPLICIT) // default solver is implicit
00055 {
00056 }
00057 
00058 template<unsigned DIM>
00059 ElectroMechanicsProblemDefinition<DIM>::~ElectroMechanicsProblemDefinition()
00060 {
00061     if(mpDefaultMaterialLaw)
00062     {
00063         delete mpDefaultMaterialLaw;
00064     }
00065 
00066     if (mWeMadeCellFactory)
00067     {
00068         delete mpContractionCellFactory;
00069     }
00070 }
00071 
00072 template<unsigned DIM>
00073 void ElectroMechanicsProblemDefinition<DIM>::SetContractionModel(ContractionModelName contractionModel, double timestep)
00074 {
00075     assert(timestep > 0.0);
00076     SetContractionModelOdeTimestep(timestep);
00077 
00078     if (contractionModel == NASH2004 || contractionModel == CONSTANT)
00079     {
00080         // These models can use an Explicit solver, default is Implicit.
00081         SetSolverType(EXPLICIT);
00082     }
00083 
00084     // Make sure we aren't overwriting a problem that has been set up with a cell factory.
00085     assert(mpContractionCellFactory==NULL);
00086 
00087     AbstractContractionCellFactory<DIM>* p_factory = new LabelBasedContractionCellFactory<DIM>(contractionModel);
00088     mWeMadeCellFactory = true;
00089     SetContractionCellFactory(p_factory);
00090 }
00091 
00092 template<unsigned DIM>
00093 void ElectroMechanicsProblemDefinition<DIM>::SetUseDefaultCardiacMaterialLaw(CompressibilityType compressibilityType)
00094 {
00095     if(mpDefaultMaterialLaw)
00096     {
00097         delete mpDefaultMaterialLaw;
00098     }
00099 
00100     if(compressibilityType == INCOMPRESSIBLE)
00101     {
00102         mpDefaultMaterialLaw = new NashHunterPoleZeroLaw<DIM>();
00103         this->SetMaterialLaw(INCOMPRESSIBLE, mpDefaultMaterialLaw);
00104     }
00105     else
00106     {
00107         mpDefaultMaterialLaw = new CompressibleExponentialLaw<DIM>();
00108         this->SetMaterialLaw(COMPRESSIBLE, mpDefaultMaterialLaw);
00109     }
00110 }
00111 
00112 template<unsigned DIM>
00113 void ElectroMechanicsProblemDefinition<DIM>::SetDeformationAffectsElectrophysiology(bool deformationAffectsConductivity, bool deformationAffectsCellModels)
00114 {
00115     mDeformationAffectsConductivity = deformationAffectsConductivity;
00116     mDeformationAffectsCellModels = deformationAffectsCellModels;
00117 }
00118 
00119 template<unsigned DIM>
00120 void ElectroMechanicsProblemDefinition<DIM>::SetMechanicsSolveTimestep(double timestep)
00121 {
00122     assert(timestep > 0.0);
00123     mMechanicsSolveTimestep = timestep;
00124 }
00125 
00126 template<unsigned DIM>
00127 void ElectroMechanicsProblemDefinition<DIM>::SetVariableFibreSheetDirectionsFile(const FileFinder& rFibreSheetDirectionsFile, bool definedPerQuadraturePoint)
00128 {
00129     mReadFibreSheetInformationFromFile = true;
00130     mFibreSheetDirectionsFile = rFibreSheetDirectionsFile;
00131     mFibreSheetDirectionsDefinedPerQuadraturePoint = definedPerQuadraturePoint;
00132 }
00133 
00134 template<unsigned DIM>
00135 void ElectroMechanicsProblemDefinition<DIM>::SetApplyIsotropicCrossFibreTension(bool applyCrossFibreTension, double crossFibreTensionFraction)
00136 {
00137     mApplyCrossFibreTension = applyCrossFibreTension;
00138     mSheetTensionFraction = crossFibreTensionFraction;
00139     mSheetNormalTensionFraction = crossFibreTensionFraction;
00140 }
00141 
00142 template<unsigned DIM>
00143 void ElectroMechanicsProblemDefinition<DIM>::SetApplyAnisotropicCrossFibreTension(bool applyCrossFibreTension, double sheetTensionFraction, double sheetNormalTensionFraction)
00144 {
00145     if (DIM!=3)
00146     {
00147         EXCEPTION("You can only apply anisotropic cross fibre tensions in a 3D simulation.");
00148     }
00149     mApplyCrossFibreTension = applyCrossFibreTension;
00150     mSheetTensionFraction = sheetTensionFraction;
00151     mSheetNormalTensionFraction = sheetNormalTensionFraction;
00152 }
00153 
00154 template<unsigned DIM>
00155 void ElectroMechanicsProblemDefinition<DIM>::SetContractionCellFactory(AbstractContractionCellFactory<DIM>* pCellFactory)
00156 {
00157     // Make sure we aren't overwriting a problem that has been set up with a cell factory already.
00158     assert(mpContractionCellFactory == NULL);
00159 
00160     mpContractionCellFactory = pCellFactory;
00161     mpContractionCellFactory->SetMechanicsMesh(static_cast<QuadraticMesh<DIM>*>(&(this->mrMesh)));
00162 }
00163 
00164 template<unsigned DIM>
00165 void ElectroMechanicsProblemDefinition<DIM>::Validate()
00166 {
00167     SolidMechanicsProblemDefinition<DIM>::Validate();
00168 
00169     if(mMechanicsSolveTimestep < 0.0)
00170     {
00171         EXCEPTION("Timestep for mechanics solve hasn't been set yet");
00172     }
00173 
00174     if(mContractionModelOdeTimeStep < 0.0)
00175     {
00176         std::string message =  "Contraction model or contraction model ODE timestep have not been set. "
00177                                "Make sure SetContractionModel(), or SetContractionCellFactory() AND SetContractionModelOdeTimestep "
00178                                "are called. (Pass in a timestep even if contraction model is algebraic and won't use it). ";
00179         EXCEPTION(message);
00180     }
00181 
00182     if(mDeformationAffectsConductivity && this->GetCompressibilityType()==COMPRESSIBLE)
00183     {
00184         // the conductivity depends on the deformation gradient and also scales in some way with
00185         // J=det(F), which is not equal to 1 in the compressible case. The F dependence
00186         // is implemented but the J dependence is not yet.
00187         EXCEPTION("Deformation affecting the conductivity is currently not implemented fully for compressible problems");
00188     }
00189 
00190     if(mDeformationAffectsCellModels && mReadFibreSheetInformationFromFile && mFibreSheetDirectionsDefinedPerQuadraturePoint)
00191     {
00192         // This combination is not allowed. For explanation see doxygen for SetDeformationAffectsElectrophysiology()
00193         std::stringstream message;
00194         message << "Deformation affecting cell models cannot be done when fibres-sheet information is defined for each quadrature point.";
00195         message << "Define fibre-sheet information for each element instead.";
00196         EXCEPTION(message.str());
00197     }
00198 }
00199 
00201 // Explicit instantiation
00203 
00204 template class ElectroMechanicsProblemDefinition<2>;
00205 template class ElectroMechanicsProblemDefinition<3>;

Generated by  doxygen 1.6.2