Chaste  Release::2017.1
ExtendedBidomainProblem.hpp
1 /*
2 
3 Copyright (c) 2005-2017, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF 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 
40 #include "ChasteSerialization.hpp"
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 
84 template<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;
114  archive & mGgapHeterogeneityRegions;
115  archive & mGgapHeterogenousValues;
116  archive & mRowForAverageOfPhiZeroed;
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;
175  archive & mGgapHeterogeneityRegions;
176  archive & mGgapHeterogenousValues;
177  archive & mRowForAverageOfPhiZeroed;
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;
188  mIntracellularConductivitiesSecondCell(i) = 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  }
228  PetscTools::Destroy(V_2);
229  PetscTools::Destroy(phie);
230 
231  mSolution_distri.Restore();
232  }
233  }
234  BOOST_SERIALIZATION_SPLIT_MEMBER()
235 
236 
237 protected:
238 
241 
244 
246  std::vector<unsigned> mFixedExtracellularPotentialNodes;
247 
250 
258  std::vector<signed int> mVariablesIDs;
259 
263 
266 
268  double mAmFirstCell;
272  double mAmGap;
274  double mCmFirstCell;
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 
314  bool mHasBath;
315 
322 
327  void AnalyseMeshForBath();
328 
339 
346 
349 
352 
353 public:
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_*/
void SetExtendedBidomainParameters(double Am1, double Am2, double AmGap, double Cm1, double Cm2, double Ggap)
virtual AbstractDynamicLinearPdeSolver< DIM, DIM, 3 > * CreateSolver()
virtual AbstractCardiacTissue< DIM > * CreateCardiacTissue()
AbstractStimulusFactory< DIM > * mpExtracellularStimulusFactory
ExtendedBidomainTissue< DIM > * GetExtendedBidomainTissue()
void SetExtracellularStimulusFactory(AbstractStimulusFactory< DIM > *pFactory)
static bool IsAbsolutePath(const std::string &rPath)
Definition: FileFinder.cpp:526
virtual void WriteOneStep(double time, Vec voltageVec)
void SetIntracellularConductivitiesForSecondCell(c_vector< double, DIM > conductivities)
void SetGgapHeterogeneities(std::vector< boost::shared_ptr< AbstractChasteRegion< DIM > > > &rGgapHeterogeneityRegions, std::vector< double > &rGgapValues)
void SetNodeForAverageOfPhiZeroed(unsigned node)
void GetVariableOverNodes(Vec data, const std::string &rVariableName, unsigned timestep=0)
friend class boost::serialization::access
virtual void DefineWriterColumns(bool extending)
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
AbstractExtendedBidomainSolver< DIM, DIM > * mpSolver
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void SetFixedExtracellularPotentialNodes(std::vector< unsigned > nodes)
void load(Archive &archive, const unsigned int version)
std::vector< boost::shared_ptr< AbstractChasteRegion< DIM > > > mGgapHeterogeneityRegions
static void Destroy(Vec &rVec)
Definition: PetscTools.hpp:352
void DefineFixedDimension(long dimensionSize)
std::vector< signed int > mVariablesIDs
ExtendedBidomainTissue< DIM > * mpExtendedBidomainTissue
AbstractCardiacCellFactory< DIM, DIM > * mpSecondCellFactory
void save(Archive &archive, const unsigned int version) const
static std::string GetArchiveRelativePath()
gcov doesn&#39;t like this file...
std::vector< double > mGgapHeterogenousValues
c_vector< double, DIM > mIntracellularConductivitiesSecondCell
std::vector< unsigned > mFixedExtracellularPotentialNodes