BidomainProblem.hpp

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 
00037 #ifndef BIDOMAINPROBLEM_HPP_
00038 #define BIDOMAINPROBLEM_HPP_
00039 
00040 #include "ChasteSerialization.hpp"
00041 #include <boost/serialization/base_object.hpp>
00042 
00043 #include <vector>
00044 #include <boost/shared_ptr.hpp>
00045 #include <boost/serialization/shared_ptr.hpp>
00046 
00047 #include "AbstractCardiacProblem.hpp"
00048 #include "AbstractCardiacTissue.hpp"
00049 #include "AbstractBidomainSolver.hpp"
00050 #include "AbstractCardiacCellFactory.hpp"
00051 #include "Electrodes.hpp"
00052 #include "BidomainTissue.hpp"
00053 #include "HeartRegionCodes.hpp"
00054 #include "DistributedTetrahedralMesh.hpp"
00055 
00064 template<unsigned DIM>
00065 class BidomainProblem : public AbstractCardiacProblem<DIM,DIM, 2>
00066 {
00068     friend class boost::serialization::access;
00069 
00070     // #1082
00071     friend class TestPCTwoLevelsBlockDiagonal;
00072 
00079     template<class Archive>
00080     void save(Archive & archive, const unsigned int version) const
00081     {
00082         archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 2> >(*this);
00083         archive & mpBidomainTissue;
00084         //archive & mExtracelluarColumnId; // Created by InitialiseWriter, called from Solve
00085         archive & mRowForAverageOfPhiZeroed;
00086         archive & mHasBath;
00087         archive & mpElectrodes;
00088     }
00089 
00096     template<class Archive>
00097     void load(Archive & archive, const unsigned int version)
00098     {
00099         archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 2> >(*this);
00100         archive & mpBidomainTissue;
00101         //archive & mExtracelluarColumnId; // Created by InitialiseWriter, called from Solve
00102         archive & mRowForAverageOfPhiZeroed;
00103         archive & mHasBath;
00104         archive & mpElectrodes;
00105 
00106         if (mHasBath)
00107         {
00108             // We only save element annotations, so annotate bath nodes from these
00109             AnalyseMeshForBath();
00110         }
00111     }
00112     BOOST_SERIALIZATION_SPLIT_MEMBER()
00113 
00114     friend class TestBidomainWithBathProblem;
00115     friend class TestCardiacSimulationArchiver;
00116 
00117 protected:
00119     BidomainTissue<DIM>* mpBidomainTissue;
00120 
00122     std::vector<unsigned> mFixedExtracellularPotentialNodes;
00124     unsigned mExtracelluarColumnId;
00129     unsigned mRowForAverageOfPhiZeroed;
00130 
00132     bool mHasBath;
00133 
00135     boost::shared_ptr<Electrodes<DIM> > mpElectrodes;
00136 
00142     Vec CreateInitialCondition();
00143 
00148     void AnalyseMeshForBath();
00149 
00155     AbstractBidomainSolver<DIM,DIM>* mpSolver;
00156 
00158     virtual AbstractCardiacTissue<DIM> *CreateCardiacTissue();
00159 
00161     virtual AbstractDynamicLinearPdeSolver<DIM,DIM,2>* CreateSolver();
00162 
00163 public:
00173     BidomainProblem(AbstractCardiacCellFactory<DIM>* pCellFactory, bool hasBath=false);
00174 
00178     BidomainProblem();
00179 
00190     void SetFixedExtracellularPotentialNodes(std::vector<unsigned> nodes);
00191 
00199     void SetNodeForAverageOfPhiZeroed(unsigned node);
00200 
00204     BidomainTissue<DIM>* GetBidomainTissue();
00205 
00210     void WriteInfo(double time);
00211 
00217     virtual void DefineWriterColumns(bool extending);
00218 
00226     virtual void WriteOneStep(double time, Vec voltageVec);
00227 
00232     void PreSolveChecks();
00233 
00234 
00235 
00243     void AtBeginningOfTimestep(double time);
00244 
00252     void OnEndOfTimestep(double time);
00253 
00261     void SetUpAdditionalStoppingTimes(std::vector<double>& rAdditionalStoppingTimes);
00262 
00280     template<class Archive>
00281     void LoadExtraArchiveForBidomain(Archive & archive, unsigned version);
00282 
00286     bool GetHasBath();
00287 
00292     void SetElectrodes();
00293 };
00294 
00295 #include "SerializationExportWrapper.hpp" // Must be last
00296 EXPORT_TEMPLATE_CLASS_SAME_DIMS(BidomainProblem)
00297 
00298 
00299 template<unsigned DIM>
00300 template<class Archive>
00301 void BidomainProblem<DIM>::LoadExtraArchiveForBidomain(Archive & archive, unsigned version)
00302 {
00303     // Not all bidomain problems have electrodes...
00304     if (mpElectrodes)
00305     {
00306         // Electrodes will always have a BCC object by this point
00307         assert(mpElectrodes->GetBoundaryConditionsContainer());
00308         // We might need to get some of the boundary conditions from this archive, but it might be
00309         // the case that the problem's BCC is the same object as the Electrodes' (if they are turned
00310         // on) in which case we need to do 'nothing'.
00311         boost::shared_ptr<BoundaryConditionsContainer<DIM, DIM, 2> > p_bcc;
00312         archive >> p_bcc;
00313         if (mpElectrodes->GetBoundaryConditionsContainer() != this->mpBoundaryConditionsContainer)
00314         {
00315             // The BCs will only actually be different if using a distributed tetrahedral mesh
00316             DistributedTetrahedralMesh<DIM,DIM>* p_dist_mesh = dynamic_cast<DistributedTetrahedralMesh<DIM,DIM>*>(this->mpMesh);
00317             if (p_dist_mesh)
00318             {
00319                 mpElectrodes->GetBoundaryConditionsContainer()->MergeFromArchive(archive, this->mpMesh);
00320             }
00321             else
00322             {
00323                 // Load into the temporary container, which will get thrown away shortly
00324                 p_bcc->LoadFromArchive(archive, this->mpMesh);
00326             }
00327         }
00328     }
00329 }
00330 
00331 #endif /*BIDOMAINPROBLEM_HPP_*/

Generated by  doxygen 1.6.2