BidomainProblem.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 "AbstractCardiacTissue.hpp"
00042 #include "AbstractBidomainSolver.hpp"
00043 #include "AbstractCardiacCellFactory.hpp"
00044 #include "Electrodes.hpp"
00045 #include "BidomainTissue.hpp"
00046 #include "HeartRegionCodes.hpp"
00047 #include "DistributedTetrahedralMesh.hpp"
00048 
00057 template<unsigned DIM>
00058 class BidomainProblem : public AbstractCardiacProblem<DIM,DIM, 2>
00059 {
00061     friend class boost::serialization::access;
00062     
00063     // #1082
00064     friend class TestPCTwoLevelsBlockDiagonal;    
00065     
00072     template<class Archive>
00073     void save(Archive & archive, const unsigned int version) const
00074     {
00075         archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 2> >(*this);
00076         archive & mpBidomainTissue;
00077         //archive & mExtracelluarColumnId; // Created by InitialiseWriter, called from Solve
00078         archive & mRowForAverageOfPhiZeroed;
00079         archive & mHasBath;
00080         archive & mpElectrodes;
00081     }
00082 
00089     template<class Archive>
00090     void load(Archive & archive, const unsigned int version)
00091     {
00092         archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 2> >(*this);
00093         archive & mpBidomainTissue;
00094         //archive & mExtracelluarColumnId; // Created by InitialiseWriter, called from Solve
00095         archive & mRowForAverageOfPhiZeroed;
00096         archive & mHasBath;
00097         archive & mpElectrodes;
00098 
00099         if (mHasBath)
00100         {
00101             // We only save element annotations, so annotate bath nodes from these
00102             AnalyseMeshForBath();
00103         }
00104     }
00105     BOOST_SERIALIZATION_SPLIT_MEMBER()
00106 
00107     friend class TestBidomainWithBathProblem;
00108     friend class TestCardiacSimulationArchiver;
00109 
00110 protected:
00112     BidomainTissue<DIM>* mpBidomainTissue;
00113 
00115     std::vector<unsigned> mFixedExtracellularPotentialNodes;
00117     unsigned mExtracelluarColumnId;
00122     unsigned mRowForAverageOfPhiZeroed;
00123 
00125     bool mHasBath;
00126 
00128     boost::shared_ptr<Electrodes<DIM> > mpElectrodes;
00129 
00134     Vec CreateInitialCondition();
00135 
00140     void AnalyseMeshForBath();
00141 
00147     AbstractBidomainSolver<DIM,DIM>* mpSolver;
00148 
00150     virtual AbstractCardiacTissue<DIM> *CreateCardiacTissue();
00151 
00153     virtual AbstractDynamicLinearPdeSolver<DIM,DIM,2>* CreateSolver();
00154     
00155 public:
00165     BidomainProblem(AbstractCardiacCellFactory<DIM>* pCellFactory, bool hasBath=false);
00166 
00170     BidomainProblem();
00171 
00182     void SetFixedExtracellularPotentialNodes(std::vector<unsigned> nodes);
00183 
00191     void SetNodeForAverageOfPhiZeroed(unsigned node);
00192 
00196     BidomainTissue<DIM>* GetBidomainTissue();
00197 
00202     void WriteInfo(double time);
00203 
00209     virtual void DefineWriterColumns(bool extending);
00210 
00218     virtual void WriteOneStep(double time, Vec voltageVec);
00219 
00224     void PreSolveChecks();
00225 
00226    
00227 
00235     void AtBeginningOfTimestep(double time);
00236 
00244     void OnEndOfTimestep(double time);
00245     
00253     void SetUpAdditionalStoppingTimes(std::vector<double>& rAdditionalStoppingTimes);
00254 
00272     template<class Archive>
00273     void LoadExtraArchiveForBidomain(Archive & archive, unsigned version);
00274     
00278     bool GetHasBath();
00279     
00284     void SetElectrodes();    
00285 };
00286 
00287 #include "SerializationExportWrapper.hpp" // Must be last
00288 EXPORT_TEMPLATE_CLASS_SAME_DIMS(BidomainProblem)
00289 
00290 
00291 template<unsigned DIM>
00292 template<class Archive>
00293 void BidomainProblem<DIM>::LoadExtraArchiveForBidomain(Archive & archive, unsigned version)
00294 {
00295     // Not all bidomain problems have electrodes...
00296     if (mpElectrodes)
00297     {
00298         // Electrodes will always have a BCC object by this point
00299         assert(mpElectrodes->GetBoundaryConditionsContainer());
00300         // We might need to get some of the boundary conditions from this archive, but it might be
00301         // the case that the problem's BCC is the same object as the Electrodes' (if they are turned
00302         // on) in which case we need to do 'nothing'.
00303         boost::shared_ptr<BoundaryConditionsContainer<DIM, DIM, 2> > p_bcc;
00304         archive >> p_bcc;
00305         if (mpElectrodes->GetBoundaryConditionsContainer() != this->mpBoundaryConditionsContainer)
00306         {
00307             // The BCs will only actually be different if using a distributed tetrahedral mesh
00308             DistributedTetrahedralMesh<DIM,DIM>* p_dist_mesh = dynamic_cast<DistributedTetrahedralMesh<DIM,DIM>*>(this->mpMesh);
00309             if (p_dist_mesh)
00310             {
00311                 mpElectrodes->GetBoundaryConditionsContainer()->MergeFromArchive(archive, this->mpMesh);
00312             }
00313             else
00314             {
00315                 // Load into the temporary container, which will get thrown away shortly
00316                 p_bcc->LoadFromArchive(archive, this->mpMesh);
00318             }
00319         }
00320     }
00321 }
00322 
00323 #endif /*BIDOMAINPROBLEM_HPP_*/

Generated on Mon Apr 18 11:35:28 2011 for Chaste by  doxygen 1.5.5