Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
ExtendedBidomainProblem.hpp
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
37#ifndef EXTENDEDBIDOMAINPROBLEM_HPP_
38#define EXTENDEDBIDOMAINPROBLEM_HPP_
39
41#include <boost/serialization/base_object.hpp>
42
43#include <vector>
44#include <boost/shared_ptr.hpp>
45#include <boost/serialization/shared_ptr.hpp>
46
47#include "AbstractCardiacProblem.hpp"
48#include "AbstractCardiacTissue.hpp"
49#include "AbstractExtendedBidomainSolver.hpp"
50#include "AbstractCardiacCellFactory.hpp"
51#include "Electrodes.hpp"
52#include "ExtendedBidomainTissue.hpp"
53
54#include "HeartRegionCodes.hpp"
55#include "DistributedTetrahedralMesh.hpp"
56#include "AbstractStimulusFactory.hpp"
57#include "ElectrodesStimulusFactory.hpp"
58
84template<unsigned DIM>
86{
89
90 friend class TestArchivingExtendedBidomain;//for testing
91
98 template<class Archive>
99 void save(Archive & archive, const unsigned int version) const
100 {
101 archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 3> >(*this);
102 archive & mpExtendedBidomainTissue;
104 //archive & mIntracellularConductivitiesSecondCell; not allowed in some versions of boost
105 archive & mVariablesIDs;
108 archive & mAmFirstCell;
109 archive & mAmSecondCell;
110 archive & mAmGap;
111 archive & mCmFirstCell;
112 archive & mCmSecondCell;
113 archive & mGGap;
115 archive & mGgapHeterogenousValues;
119 archive & mHasBath;
120 //archive & mpSolver;
121
122 //archive the values for the conductivies of the second cell
123 for (unsigned i = 0; i < DIM; i++)
124 {
125 double conductivity = mIntracellularConductivitiesSecondCell(i);
126 archive & conductivity;
127 }
128
129 bool has_solution = (this->mSolution != NULL);
130 archive & has_solution;
131 if (has_solution)
132 {
133 // Please see the todo tag (#1317) in AbstractCardiacProblem
134 Hdf5DataWriter writer(*this->mpMesh->GetDistributedVectorFactory(), ArchiveLocationInfo::GetArchiveRelativePath(), "AbstractCardiacProblem_mSolution", false);
135 writer.DefineFixedDimension(this->mpMesh->GetDistributedVectorFactory()->GetProblemSize());
136 writer.DefineUnlimitedDimension("Time", "msec", 1);
137
138 int V = writer.DefineVariable("V","mV");
139 int V_2 = writer.DefineVariable("V_2","mV");
140 int phie = writer.DefineVariable("Phi_e","mV");
141 std::vector<int> variable_ids;
142 variable_ids.push_back(V);
143 variable_ids.push_back(V_2);
144 variable_ids.push_back(phie);
145 writer.EndDefineMode();
146 writer.PutUnlimitedVariable(0.0);
147
148
149 writer.PutStripedVector(variable_ids, this->mSolution);
150 }
151 }
152
159 template<class Archive>
160 void load(Archive & archive, const unsigned int version)
161 {
162 archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 3> >(*this);
163 archive & mpExtendedBidomainTissue;
165 //archive & mIntracellularConductivitiesSecondCell; not allowed in some versions of boost
166 archive & mVariablesIDs;
169 archive & mAmFirstCell;
170 archive & mAmSecondCell;
171 archive & mAmGap;
172 archive & mCmFirstCell;
173 archive & mCmSecondCell;
174 archive & mGGap;
176 archive & mGgapHeterogenousValues;
180 archive & mHasBath;
181 //archive & mpSolver;
182
183 //load the values for the conductivies of the second cell
184 for (unsigned i = 0; i < DIM; i++)
185 {
186 double conductivity;
187 archive & conductivity;
189 }
190
191 bool has_solution;
192 archive & has_solution;
193
194 if (has_solution)
195 {
196 this->mSolution = this->mpMesh->GetDistributedVectorFactory()->CreateVec(3);
197 DistributedVector mSolution_distri = this->mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(this->mSolution);
198
199 std::string archive_dir = ArchiveLocationInfo::GetArchiveRelativePath();
200 Hdf5DataReader reader(archive_dir, "AbstractCardiacProblem_mSolution", !FileFinder::IsAbsolutePath(archive_dir));
201
202 Vec V = this->mpMesh->GetDistributedVectorFactory()->CreateVec();
203 Vec V_2 = this->mpMesh->GetDistributedVectorFactory()->CreateVec();
204 Vec phie = this->mpMesh->GetDistributedVectorFactory()->CreateVec();
205
206 reader.GetVariableOverNodes(V, "V", 0);
207 reader.GetVariableOverNodes(V_2, "V_2", 0);
208 reader.GetVariableOverNodes(phie, "Phi_e", 0);
209
210 //from transmembrane voltages back to phi_i now...
211 DistributedVector vm_first_cell_distri = this->mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(V);
212 DistributedVector vm_second_cell_distri = this->mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(V_2);
213 DistributedVector phie_distri = this->mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(phie);
214
215 DistributedVector::Stripe mSolution_V_1(mSolution_distri,0);
216 DistributedVector::Stripe mSolution_V_2(mSolution_distri,1);
217 DistributedVector::Stripe mSolution_phie(mSolution_distri,2);
218
219 for (DistributedVector::Iterator index = mSolution_distri.Begin();
220 index != mSolution_distri.End();
221 ++index)
222 {
223 mSolution_V_1[index] = vm_first_cell_distri[index];
224 mSolution_V_2[index] = vm_second_cell_distri[index];
225 mSolution_phie[index] = phie_distri[index];
226 }
230
231 mSolution_distri.Restore();
232 }
233 }
234 BOOST_SERIALIZATION_SPLIT_MEMBER()
235
236
237protected:
238
241
244
247
250
258 std::vector<signed int> mVariablesIDs;
259
263
266
272 double mAmGap;
279 double mGGap;
280
286 std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > > mGgapHeterogeneityRegions;
287
289 std::vector<double> mGgapHeterogenousValues;
290
291
294
300
309
312
315
322
328
339
346
349
351 virtual AbstractDynamicLinearPdeSolver<DIM,DIM,3>* CreateSolver();
352
353public:
364 ExtendedBidomainProblem(AbstractCardiacCellFactory<DIM>* pCellFactory, AbstractCardiacCellFactory<DIM>* pSecondCellFactory, bool hasBath = false);
365
370
374 virtual ~ExtendedBidomainProblem();
375
386 void SetFixedExtracellularPotentialNodes(std::vector<unsigned> nodes);
387
393 void SetIntracellularConductivitiesForSecondCell(c_vector<double, DIM> conductivities);
394
407 void SetExtendedBidomainParameters(double Am1, double Am2, double AmGap, double Cm1, double Cm2, double Ggap);
408
417 void SetGgapHeterogeneities ( std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rGgapHeterogeneityRegions, std::vector<double>& rGgapValues);
418
425
426
434 void SetNodeForAverageOfPhiZeroed(unsigned node);
435
440
446 void WriteInfo(double time);
447
456 virtual void DefineWriterColumns(bool extending);
457
473 virtual void WriteOneStep(double time, Vec voltageVec);
474
479 void PreSolveChecks();
480
484 bool GetHasBath();
485
492 void SetHasBath(bool hasBath);
493};
494
495#include "SerializationExportWrapper.hpp" // Must be last
497
498#endif /*EXTENDEDBIDOMAINPROBLEM_HPP_*/
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
static std::string GetArchiveRelativePath()
void SetFixedExtracellularPotentialNodes(std::vector< unsigned > nodes)
virtual void DefineWriterColumns(bool extending)
void SetGgapHeterogeneities(std::vector< boost::shared_ptr< AbstractChasteRegion< DIM > > > &rGgapHeterogeneityRegions, std::vector< double > &rGgapValues)
void save(Archive &archive, const unsigned int version) const
std::vector< double > mGgapHeterogenousValues
void SetExtendedBidomainParameters(double Am1, double Am2, double AmGap, double Cm1, double Cm2, double Ggap)
c_vector< double, DIM > mIntracellularConductivitiesSecondCell
void SetNodeForAverageOfPhiZeroed(unsigned node)
ExtendedBidomainTissue< DIM > * mpExtendedBidomainTissue
void SetIntracellularConductivitiesForSecondCell(c_vector< double, DIM > conductivities)
std::vector< signed int > mVariablesIDs
AbstractStimulusFactory< DIM > * mpExtracellularStimulusFactory
virtual AbstractCardiacTissue< DIM > * CreateCardiacTissue()
std::vector< boost::shared_ptr< AbstractChasteRegion< DIM > > > mGgapHeterogeneityRegions
virtual void WriteOneStep(double time, Vec voltageVec)
void SetExtracellularStimulusFactory(AbstractStimulusFactory< DIM > *pFactory)
ExtendedBidomainTissue< DIM > * GetExtendedBidomainTissue()
AbstractExtendedBidomainSolver< DIM, DIM > * mpSolver
void load(Archive &archive, const unsigned int version)
AbstractCardiacCellFactory< DIM, DIM > * mpSecondCellFactory
friend class boost::serialization::access
virtual AbstractDynamicLinearPdeSolver< DIM, DIM, 3 > * CreateSolver()
std::vector< unsigned > mFixedExtracellularPotentialNodes
static bool IsAbsolutePath(const std::string &rPath)
void GetVariableOverNodes(Vec data, const std::string &rVariableName, unsigned timestep=0)
void DefineUnlimitedDimension(const std::string &rVariableName, const std::string &rVariableUnits, unsigned estimatedLength=1)
void PutUnlimitedVariable(double value)
void DefineFixedDimension(long dimensionSize)
int DefineVariable(const std::string &rVariableName, const std::string &rVariableUnits)
virtual void EndDefineMode()
void PutStripedVector(std::vector< int > variableIDs, Vec petscVector)
static void Destroy(Vec &rVec)