BidomainProblem.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 
00030 #ifndef BIDOMAINPROBLEM_HPP_
00031 #define BIDOMAINPROBLEM_HPP_
00032 
00033 #include "ChasteSerialization.hpp"
00034 #include <boost/serialization/base_object.hpp>
00035 
00036 #include <vector>
00037 #include <boost/shared_ptr.hpp>
00038 #include <boost/serialization/shared_ptr.hpp>
00039 
00040 #include "AbstractCardiacProblem.hpp"
00041 #include "AbstractCardiacPde.hpp"
00042 #include "AbstractDynamicAssemblerMixin.hpp"
00043 #include "AbstractCardiacCellFactory.hpp"
00044 #include "Electrodes.hpp"
00045 #include "BidomainPde.hpp"
00046 #include "BidomainDg0Assembler.hpp"
00047 #include "HeartRegionCodes.hpp"
00048 #include "DistributedTetrahedralMesh.hpp"
00049 
00058 template<unsigned DIM>
00059 class BidomainProblem : public AbstractCardiacProblem<DIM,DIM, 2>
00060 {
00061 
00063     friend class boost::serialization::access;
00070     template<class Archive>
00071     void save(Archive & archive, const unsigned int version) const
00072     {
00073         archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 2> >(*this);
00074         archive & mpBidomainPde;
00075         //archive & mExtracelluarColumnId; // Created by InitialiseWriter, called from Solve
00076         archive & mRowForAverageOfPhiZeroed;
00077         archive & mHasBath;
00078         archive & mpElectrodes;
00079     }
00080 
00087     template<class Archive>
00088     void load(Archive & archive, const unsigned int version)
00089     {
00090         archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 2> >(*this);
00091         archive & mpBidomainPde;
00092         //archive & mExtracelluarColumnId; // Created by InitialiseWriter, called from Solve
00093         archive & mRowForAverageOfPhiZeroed;
00094         archive & mHasBath;
00095         archive & mpElectrodes;
00096 
00097         if (mHasBath)
00098         {
00099             // We only save element annotations, so annotate bath nodes from these
00100             AnalyseMeshForBath();
00101         }
00102     }
00103     BOOST_SERIALIZATION_SPLIT_MEMBER()
00104 
00105     friend class TestBidomainWithBathAssembler;
00106     friend class TestCardiacSimulationArchiver;
00107 
00108 protected:
00110     BidomainPde<DIM>* mpBidomainPde;
00111 
00113     std::vector<unsigned> mFixedExtracellularPotentialNodes;
00115     unsigned mExtracelluarColumnId;
00120     unsigned mRowForAverageOfPhiZeroed;
00121 
00123     bool mHasBath;
00124 
00126     boost::shared_ptr<Electrodes<DIM> > mpElectrodes;
00127 
00132     Vec CreateInitialCondition();
00133 
00138     void AnalyseMeshForBath();
00139 
00145     BidomainDg0Assembler<DIM,DIM>* mpAssembler;
00146 
00148     virtual AbstractCardiacPde<DIM> *CreateCardiacPde();
00149 
00151     virtual AbstractDynamicAssemblerMixin<DIM, DIM, 2>* CreateAssembler();
00152 
00153 public:
00163     BidomainProblem(AbstractCardiacCellFactory<DIM>* pCellFactory, bool hasBath=false);
00164 
00168     BidomainProblem();
00169 
00180     void SetFixedExtracellularPotentialNodes(std::vector<unsigned> nodes);
00181 
00189     void SetNodeForAverageOfPhiZeroed(unsigned node);
00190 
00194     BidomainPde<DIM>* GetBidomainPde();
00195 
00200     void WriteInfo(double time);
00201 
00207     virtual void DefineWriterColumns(bool extending);
00208 
00216     virtual void WriteOneStep(double time, Vec voltageVec);
00217 
00222     void PreSolveChecks();
00223 
00230     void SetElectrodes(boost::shared_ptr<Electrodes<DIM> > pElectrodes);
00231 
00239     void AtBeginningOfTimestep(double time);
00240 
00248     void OnEndOfTimestep(double time);
00249     
00257     void SetUpAdditionalStoppingTimes(std::vector<double>& rAdditionalStoppingTimes);
00258 
00276     template<class Archive>
00277     void LoadExtraArchiveForBidomain(Archive & archive, unsigned version);
00278 };
00279 
00280 #include "SerializationExportWrapper.hpp" // Must be last
00281 EXPORT_TEMPLATE_CLASS_SAME_DIMS(BidomainProblem);
00282 
00283 
00284 template<unsigned DIM>
00285 template<class Archive>
00286 void BidomainProblem<DIM>::LoadExtraArchiveForBidomain(Archive & archive, unsigned version)
00287 {
00288     // Not all bidomain problems have electrodes...
00289     if (mpElectrodes)
00290     {
00291         // Electrodes will always have a BCC object by this point
00292         assert(mpElectrodes->GetBoundaryConditionsContainer());
00293         // We might need to get some of the boundary conditions from this archive, but it might be
00294         // the case that the problem's BCC is the same object as the Electrodes' (if they are turned
00295         // on) in which case we need to do 'nothing'.
00296         boost::shared_ptr<BoundaryConditionsContainer<DIM, DIM, 2> > p_bcc;
00297         archive >> p_bcc;
00298         if (mpElectrodes->GetBoundaryConditionsContainer() != this->mpBoundaryConditionsContainer)
00299         {
00300             // The BCs will only actually be different if using a distributed tetrahedral mesh
00301             DistributedTetrahedralMesh<DIM,DIM>* p_dist_mesh = dynamic_cast<DistributedTetrahedralMesh<DIM,DIM>*>(this->mpMesh);
00302             if (p_dist_mesh)
00303             {
00304                 mpElectrodes->GetBoundaryConditionsContainer()->MergeFromArchive(archive, this->mpMesh);
00305             }
00306             else
00307             {
00308                 // Load into the temporary container, which will get thrown away shortly
00309                 p_bcc->LoadFromArchive(archive, this->mpMesh);
00311             }
00312         }
00313     }
00314 }
00315 
00316 #endif /*BIDOMAINPROBLEM_HPP_*/

Generated by  doxygen 1.6.2