Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
ElectroMechanicsProblemDefinition.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "ElectroMechanicsProblemDefinition.hpp"
37#include "LabelBasedContractionCellFactory.hpp"
38
39template<unsigned DIM>
42 mContractionModelOdeTimeStep(-1.0),
43 mMechanicsSolveTimestep(-1.0),
44 mDeformationAffectsConductivity(false),
45 mDeformationAffectsCellModels(false),
46 mpDefaultMaterialLaw(NULL),
47 mReadFibreSheetInformationFromFile(false),
48 mNumIncrementsForInitialDeformation(1),
49 mApplyCrossFibreTension(false),
50 mSheetTensionFraction(DOUBLE_UNSET),
51 mSheetNormalTensionFraction(DOUBLE_UNSET),
52 mpContractionCellFactory(NULL),
53 mWeMadeCellFactory(false),
54 mSolverType(IMPLICIT) // default solver is implicit
55{
56}
57
58template<unsigned DIM>
60{
61 if (mpDefaultMaterialLaw)
62 {
63 delete mpDefaultMaterialLaw;
64 }
65
66 if (mWeMadeCellFactory)
67 {
68 delete mpContractionCellFactory;
69 }
70}
71
72template<unsigned DIM>
73void ElectroMechanicsProblemDefinition<DIM>::SetContractionModel(ContractionModelName contractionModel, double timestep)
74{
75 assert(timestep > 0.0);
76 SetContractionModelOdeTimestep(timestep);
77
78 if (contractionModel == NASH2004 || contractionModel == CONSTANT)
79 {
80 // These models can use an Explicit solver, default is Implicit.
81 SetSolverType(EXPLICIT);
82 }
83
84 // Make sure we aren't overwriting a problem that has been set up with a cell factory.
85 assert(mpContractionCellFactory==NULL);
86
88 mWeMadeCellFactory = true;
89 SetContractionCellFactory(p_factory);
90}
91
92template<unsigned DIM>
94{
95 if (mpDefaultMaterialLaw)
96 {
97 delete mpDefaultMaterialLaw;
98 }
99
100 if (compressibilityType == INCOMPRESSIBLE)
101 {
102 mpDefaultMaterialLaw = new NashHunterPoleZeroLaw<DIM>();
103 this->SetMaterialLaw(INCOMPRESSIBLE, mpDefaultMaterialLaw);
104 }
105 else
106 {
107 mpDefaultMaterialLaw = new CompressibleExponentialLaw<DIM>();
108 this->SetMaterialLaw(COMPRESSIBLE, mpDefaultMaterialLaw);
109 }
110}
111
112template<unsigned DIM>
113void ElectroMechanicsProblemDefinition<DIM>::SetDeformationAffectsElectrophysiology(bool deformationAffectsConductivity, bool deformationAffectsCellModels)
114{
115 mDeformationAffectsConductivity = deformationAffectsConductivity;
116 mDeformationAffectsCellModels = deformationAffectsCellModels;
117}
118
119template<unsigned DIM>
121{
122 assert(timestep > 0.0);
123 mMechanicsSolveTimestep = timestep;
124}
125
126template<unsigned DIM>
127void ElectroMechanicsProblemDefinition<DIM>::SetVariableFibreSheetDirectionsFile(const FileFinder& rFibreSheetDirectionsFile, bool definedPerQuadraturePoint)
128{
129 mReadFibreSheetInformationFromFile = true;
130 mFibreSheetDirectionsFile = rFibreSheetDirectionsFile;
131 mFibreSheetDirectionsDefinedPerQuadraturePoint = definedPerQuadraturePoint;
132}
133
134template<unsigned DIM>
135void ElectroMechanicsProblemDefinition<DIM>::SetApplyIsotropicCrossFibreTension(bool applyCrossFibreTension, double crossFibreTensionFraction)
136{
137 mApplyCrossFibreTension = applyCrossFibreTension;
138 mSheetTensionFraction = crossFibreTensionFraction;
139 mSheetNormalTensionFraction = crossFibreTensionFraction;
140}
141
142template<unsigned DIM>
143void ElectroMechanicsProblemDefinition<DIM>::SetApplyAnisotropicCrossFibreTension(bool applyCrossFibreTension, double sheetTensionFraction, double sheetNormalTensionFraction)
144{
145 if (DIM!=3)
146 {
147 EXCEPTION("You can only apply anisotropic cross fibre tensions in a 3D simulation.");
148 }
149 mApplyCrossFibreTension = applyCrossFibreTension;
150 mSheetTensionFraction = sheetTensionFraction;
151 mSheetNormalTensionFraction = sheetNormalTensionFraction;
152}
153
154template<unsigned DIM>
156{
157 // Make sure we aren't overwriting a problem that has been set up with a cell factory already.
158 assert(mpContractionCellFactory == NULL);
159
160 mpContractionCellFactory = pCellFactory;
161 mpContractionCellFactory->SetMechanicsMesh(static_cast<QuadraticMesh<DIM>*>(&(this->mrMesh)));
162}
163
164template<unsigned DIM>
166{
168
169 if (mMechanicsSolveTimestep < 0.0)
170 {
171 EXCEPTION("Timestep for mechanics solve hasn't been set yet");
172 }
173
174 if (mContractionModelOdeTimeStep < 0.0)
175 {
176 std::string message = "Contraction model or contraction model ODE timestep have not been set. "
177 "Make sure SetContractionModel(), or SetContractionCellFactory() AND SetContractionModelOdeTimestep "
178 "are called. (Pass in a timestep even if contraction model is algebraic and won't use it). ";
179 EXCEPTION(message);
180 }
181
182 if (mDeformationAffectsConductivity && this->GetCompressibilityType()==COMPRESSIBLE)
183 {
184 // the conductivity depends on the deformation gradient and also scales in some way with
185 // J=det(F), which is not equal to 1 in the compressible case. The F dependence
186 // is implemented but the J dependence is not yet.
187 EXCEPTION("Deformation affecting the conductivity is currently not implemented fully for compressible problems");
188 }
189
190 if (mDeformationAffectsCellModels && mReadFibreSheetInformationFromFile && mFibreSheetDirectionsDefinedPerQuadraturePoint)
191 {
192 // This combination is not allowed. For explanation see doxygen for SetDeformationAffectsElectrophysiology()
193 std::stringstream message;
194 message << "Deformation affecting cell models cannot be done when fibres-sheet information is defined for each quadrature point.";
195 message << "Define fibre-sheet information for each element instead.";
196 EXCEPTION(message.str());
197 }
198}
199
200// Explicit instantiation
const double DOUBLE_UNSET
Definition Exception.hpp:57
#define EXCEPTION(message)
void SetMechanicsMesh(QuadraticMesh< DIM > *pMesh)
void SetContractionModel(ContractionModelName contractionModel, double timestep)
void SetUseDefaultCardiacMaterialLaw(CompressibilityType compressibilityType)
void SetVariableFibreSheetDirectionsFile(const FileFinder &rFibreSheetDirectionsFile, bool definedPerQuadPoint)
ElectroMechanicsProblemDefinition(QuadraticMesh< DIM > &rMesh)
void SetApplyAnisotropicCrossFibreTension(bool applyCrossFibreTension, double sheetTensionFraction, double sheetNormalTensionFraction)
void SetDeformationAffectsElectrophysiology(bool deformationAffectsConductivity, bool deformationAffectsCellModels)
void SetApplyIsotropicCrossFibreTension(bool applyCrossFibreTension, double crossFibreTensionFraction)
void SetContractionCellFactory(AbstractContractionCellFactory< DIM > *pCellFactory)