Chaste  Release::2017.1
BidomainProblem.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 BIDOMAINPROBLEM_HPP_
38 #define BIDOMAINPROBLEM_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 "AbstractBidomainSolver.hpp"
50 #include "AbstractCardiacCellFactory.hpp"
51 #include "Electrodes.hpp"
52 #include "BidomainTissue.hpp"
53 #include "HeartRegionCodes.hpp"
54 #include "DistributedTetrahedralMesh.hpp"
55 
64 template<unsigned DIM>
65 class BidomainProblem : public AbstractCardiacProblem<DIM,DIM, 2>
66 {
69 
70  // #1082
71  friend class TestPCTwoLevelsBlockDiagonal;
72 
79  template<class Archive>
80  void save(Archive & archive, const unsigned int version) const
81  {
82  archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 2> >(*this);
83  archive & mpBidomainTissue;
84  //archive & mExtracelluarColumnId; // Created by InitialiseWriter, called from Solve
85  archive & mRowForAverageOfPhiZeroed;
86  archive & mHasBath;
87  archive & mpElectrodes;
88  }
89 
96  template<class Archive>
97  void load(Archive & archive, const unsigned int version)
98  {
99  archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 2> >(*this);
100  archive & mpBidomainTissue;
101  //archive & mExtracelluarColumnId; // Created by InitialiseWriter, called from Solve
102  archive & mRowForAverageOfPhiZeroed;
103  archive & mHasBath;
104  archive & mpElectrodes;
105 
106  if (mHasBath)
107  {
108  // We only save element annotations, so annotate bath nodes from these
110  }
111  }
112  BOOST_SERIALIZATION_SPLIT_MEMBER()
113 
114  friend class TestBidomainWithBathProblem;
115  friend class TestCardiacSimulationArchiver;
116 
117 protected:
120 
122  std::vector<unsigned> mFixedExtracellularPotentialNodes;
130 
132  bool mHasBath;
133 
135  boost::shared_ptr<Electrodes<DIM> > mpElectrodes;
136 
143 
148  void AnalyseMeshForBath();
149 
156 
159 
162 
163 public:
173  BidomainProblem(AbstractCardiacCellFactory<DIM>* pCellFactory, bool hasBath=false);
174 
178  BidomainProblem();
179 
190  void SetFixedExtracellularPotentialNodes(std::vector<unsigned> nodes);
191 
199  void SetNodeForAverageOfPhiZeroed(unsigned node);
200 
205 
210  void WriteInfo(double time);
211 
217  virtual void DefineWriterColumns(bool extending);
218 
226  virtual void WriteOneStep(double time, Vec voltageVec);
227 
232  void PreSolveChecks();
233 
241  void AtBeginningOfTimestep(double time);
242 
250  void OnEndOfTimestep(double time);
251 
259  void SetUpAdditionalStoppingTimes(std::vector<double>& rAdditionalStoppingTimes);
260 
278  template<class Archive>
279  void LoadExtraArchiveForBidomain(Archive & archive, unsigned version);
280 
284  bool GetHasBath();
285 
290  void SetElectrodes();
291 };
292 
293 #include "SerializationExportWrapper.hpp" // Must be last
295 
296 
297 template<unsigned DIM>
298 template<class Archive>
299 void BidomainProblem<DIM>::LoadExtraArchiveForBidomain(Archive & archive, unsigned version)
300 {
301  // Not all bidomain problems have electrodes...
302  if (mpElectrodes)
303  {
304  // Electrodes will always have a BCC object by this point
305  assert(mpElectrodes->GetBoundaryConditionsContainer());
306  // We might need to get some of the boundary conditions from this archive, but it might be
307  // the case that the problem's BCC is the same object as the Electrodes' (if they are turned
308  // on) in which case we need to do 'nothing'.
309  boost::shared_ptr<BoundaryConditionsContainer<DIM, DIM, 2> > p_bcc;
310  archive >> p_bcc;
311  if (mpElectrodes->GetBoundaryConditionsContainer() != this->mpBoundaryConditionsContainer)
312  {
313  // The BCs will only actually be different if using a distributed tetrahedral mesh
315  if (p_dist_mesh)
316  {
317  mpElectrodes->GetBoundaryConditionsContainer()->MergeFromArchive(archive, this->mpMesh);
318  }
319  else
320  {
321  // Load into the temporary container, which will get thrown away shortly
322  p_bcc->LoadFromArchive(archive, this->mpMesh);
324  }
325  }
326  }
327 }
328 
329 #endif /*BIDOMAINPROBLEM_HPP_*/
boost::shared_ptr< Electrodes< DIM > > mpElectrodes
unsigned mExtracelluarColumnId
AbstractBidomainSolver< DIM, DIM > * mpSolver
void LoadExtraArchiveForBidomain(Archive &archive, unsigned version)
BidomainTissue< DIM > * GetBidomainTissue()
void SetUpAdditionalStoppingTimes(std::vector< double > &rAdditionalStoppingTimes)
void SetFixedExtracellularPotentialNodes(std::vector< unsigned > nodes)
friend class boost::serialization::access
std::vector< unsigned > mFixedExtracellularPotentialNodes
void WriteInfo(double time)
AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > * mpMesh
void load(Archive &archive, const unsigned int version)
virtual void DefineWriterColumns(bool extending)
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void OnEndOfTimestep(double time)
virtual void WriteOneStep(double time, Vec voltageVec)
unsigned mRowForAverageOfPhiZeroed
BidomainTissue< DIM > * mpBidomainTissue
void SetNodeForAverageOfPhiZeroed(unsigned node)
void AtBeginningOfTimestep(double time)
gcov doesn&#39;t like this file...
void save(Archive &archive, const unsigned int version) const
virtual AbstractCardiacTissue< DIM > * CreateCardiacTissue()
virtual AbstractDynamicLinearPdeSolver< DIM, DIM, 2 > * CreateSolver()