ExtendedBidomainProblem.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 EXTENDEDBIDOMAINPROBLEM_HPP_
00038 #define EXTENDEDBIDOMAINPROBLEM_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 "AbstractExtendedBidomainSolver.hpp"
00050 #include "AbstractCardiacCellFactory.hpp"
00051 #include "Electrodes.hpp"
00052 #include "ExtendedBidomainTissue.hpp"
00053 
00054 #include "HeartRegionCodes.hpp"
00055 #include "DistributedTetrahedralMesh.hpp"
00056 #include "AbstractStimulusFactory.hpp"
00057 #include "ElectrodesStimulusFactory.hpp"
00058 
00084 template<unsigned DIM>
00085 class ExtendedBidomainProblem : public AbstractCardiacProblem<DIM,DIM, 3>
00086 {
00088     friend class boost::serialization::access;
00089 
00090     friend class TestArchivingExtendedBidomain;//for testing
00091 
00098     template<class Archive>
00099     void save(Archive & archive, const unsigned int version) const
00100     {
00101         archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 3> >(*this);
00102         archive & mpExtendedBidomainTissue;
00103         archive & mFixedExtracellularPotentialNodes;
00104         //archive & mIntracellularConductivitiesSecondCell; not allowed in some versions of boost
00105         archive & mVariablesIDs;
00106         archive & mUserSpecifiedSecondCellConductivities;
00107         archive & mUserHasSetBidomainValuesExplicitly;
00108         archive & mAmFirstCell;
00109         archive & mAmSecondCell;
00110         archive & mAmGap;
00111         archive & mCmFirstCell;
00112         archive & mCmSecondCell;
00113         archive & mGGap;
00114         archive & mGgapHeterogeneityRegions;
00115         archive & mGgapHeterogenousValues;
00116         archive & mRowForAverageOfPhiZeroed;
00117         archive & mApplyAveragePhieZeroConstraintAfterSolving;
00118         archive & mUserSuppliedExtracellularStimulus;
00119         archive & mHasBath;
00120         //archive & mpSolver;
00121 
00122         //archive the values for the conductivies of the second cell
00123         for (unsigned i = 0; i < DIM; i++)
00124         {
00125             double conductivity = mIntracellularConductivitiesSecondCell(i);
00126             archive & conductivity;
00127         }
00128 
00129         bool has_solution = (this->mSolution != NULL);
00130         archive & has_solution;
00131         if (has_solution)
00132         {
00133             // Please see the todo tag (#1317) in AbstractCardiacProblem
00134             Hdf5DataWriter writer(*this->mpMesh->GetDistributedVectorFactory(), ArchiveLocationInfo::GetArchiveRelativePath(), "AbstractCardiacProblem_mSolution", false);
00135             writer.DefineFixedDimension(this->mpMesh->GetDistributedVectorFactory()->GetProblemSize());
00136             writer.DefineUnlimitedDimension("Time", "msec", 1);
00137 
00138             int V = writer.DefineVariable("V","mV");
00139             int V_2 = writer.DefineVariable("V_2","mV");
00140             int phie = writer.DefineVariable("Phi_e","mV");
00141             std::vector<int> variable_ids;
00142             variable_ids.push_back(V);
00143             variable_ids.push_back(V_2);
00144             variable_ids.push_back(phie);
00145             writer.EndDefineMode();
00146             writer.PutUnlimitedVariable(0.0);
00147 
00148 
00149             writer.PutStripedVector(variable_ids, this->mSolution);
00150         }
00151     }
00152 
00159     template<class Archive>
00160     void load(Archive & archive, const unsigned int version)
00161     {
00162         archive & boost::serialization::base_object<AbstractCardiacProblem<DIM, DIM, 3> >(*this);
00163         archive & mpExtendedBidomainTissue;
00164         archive & mFixedExtracellularPotentialNodes;
00165         //archive & mIntracellularConductivitiesSecondCell; not allowed in some versions of boost
00166         archive & mVariablesIDs;
00167         archive & mUserSpecifiedSecondCellConductivities;
00168         archive & mUserHasSetBidomainValuesExplicitly;
00169         archive & mAmFirstCell;
00170         archive & mAmSecondCell;
00171         archive & mAmGap;
00172         archive & mCmFirstCell;
00173         archive & mCmSecondCell;
00174         archive & mGGap;
00175         archive & mGgapHeterogeneityRegions;
00176         archive & mGgapHeterogenousValues;
00177         archive & mRowForAverageOfPhiZeroed;
00178         archive & mApplyAveragePhieZeroConstraintAfterSolving;
00179         archive & mUserSuppliedExtracellularStimulus;
00180         archive & mHasBath;
00181         //archive & mpSolver;
00182 
00183         //load the values for the conductivies of the second cell
00184         for (unsigned i = 0; i < DIM; i++)
00185         {
00186             double conductivity;
00187             archive & conductivity;
00188             mIntracellularConductivitiesSecondCell(i) = conductivity;
00189         }
00190 
00191         bool has_solution;
00192         archive & has_solution;
00193 
00194         if (has_solution)
00195         {
00196             this->mSolution = this->mpMesh->GetDistributedVectorFactory()->CreateVec(3);
00197             DistributedVector mSolution_distri = this->mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(this->mSolution);
00198 
00199             std::string archive_dir = ArchiveLocationInfo::GetArchiveRelativePath();
00200             Hdf5DataReader reader(archive_dir, "AbstractCardiacProblem_mSolution", !FileFinder::IsAbsolutePath(archive_dir));
00201 
00202             Vec V = this->mpMesh->GetDistributedVectorFactory()->CreateVec();
00203             Vec V_2 = this->mpMesh->GetDistributedVectorFactory()->CreateVec();
00204             Vec phie = this->mpMesh->GetDistributedVectorFactory()->CreateVec();
00205 
00206             reader.GetVariableOverNodes(V, "V", 0);
00207             reader.GetVariableOverNodes(V_2, "V_2", 0);
00208             reader.GetVariableOverNodes(phie, "Phi_e", 0);
00209 
00210             //from transmembrane voltages back to phi_i now...
00211             DistributedVector vm_first_cell_distri = this->mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(V);
00212             DistributedVector vm_second_cell_distri = this->mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(V_2);
00213             DistributedVector phie_distri = this->mpMesh->GetDistributedVectorFactory()->CreateDistributedVector(phie);
00214 
00215             DistributedVector::Stripe mSolution_V_1(mSolution_distri,0);
00216             DistributedVector::Stripe mSolution_V_2(mSolution_distri,1);
00217             DistributedVector::Stripe mSolution_phie(mSolution_distri,2);
00218 
00219             for (DistributedVector::Iterator index = mSolution_distri.Begin();
00220                  index != mSolution_distri.End();
00221                  ++index)
00222             {
00223                 mSolution_V_1[index] = vm_first_cell_distri[index];
00224                 mSolution_V_2[index] = vm_second_cell_distri[index];
00225                 mSolution_phie[index] = phie_distri[index];
00226             }
00227             PetscTools::Destroy(V);
00228             PetscTools::Destroy(V_2);
00229             PetscTools::Destroy(phie);
00230 
00231             mSolution_distri.Restore();
00232         }
00233     }
00234     BOOST_SERIALIZATION_SPLIT_MEMBER()
00235 
00236 
00237 protected:
00238 
00240     AbstractCardiacCellFactory<DIM,DIM>* mpSecondCellFactory;
00241 
00243     ExtendedBidomainTissue<DIM>* mpExtendedBidomainTissue;
00244 
00246     std::vector<unsigned> mFixedExtracellularPotentialNodes;
00247 
00249     c_vector<double, DIM>  mIntracellularConductivitiesSecondCell;
00250 
00252     unsigned mVoltageColumnId_Vm1;
00254     unsigned mVoltageColumnId_Vm2;
00256     unsigned mVoltageColumnId_Phie;
00258     std::vector<signed int> mVariablesIDs;
00259 
00262     bool mUserSpecifiedSecondCellConductivities;
00263 
00265     bool mUserHasSetBidomainValuesExplicitly;
00266 
00268     double mAmFirstCell;
00270     double mAmSecondCell;
00272     double mAmGap;
00274     double mCmFirstCell;
00276     double mCmSecondCell;
00279     double mGGap;
00280 
00286     std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > > mGgapHeterogeneityRegions;
00287 
00289     std::vector<double> mGgapHeterogenousValues;
00290 
00291 
00293     AbstractStimulusFactory<DIM>* mpExtracellularStimulusFactory;
00294 
00299     int mRowForAverageOfPhiZeroed;
00300 
00308     unsigned mApplyAveragePhieZeroConstraintAfterSolving;
00309 
00311     bool mUserSuppliedExtracellularStimulus;
00312 
00314     bool mHasBath;
00315 
00321     Vec CreateInitialCondition();
00322 
00327     void AnalyseMeshForBath();
00328 
00338     void ProcessExtracellularStimulus();
00339 
00345     AbstractExtendedBidomainSolver<DIM,DIM>* mpSolver;
00346 
00348     virtual AbstractCardiacTissue<DIM> *CreateCardiacTissue();
00349 
00351     virtual AbstractDynamicLinearPdeSolver<DIM,DIM,3>* CreateSolver();
00352 
00353 public:
00364     ExtendedBidomainProblem(AbstractCardiacCellFactory<DIM>* pCellFactory, AbstractCardiacCellFactory<DIM>* pSecondCellFactory, bool hasBath = false);
00365 
00369     ExtendedBidomainProblem();
00370 
00374     virtual ~ExtendedBidomainProblem();
00375 
00386     void SetFixedExtracellularPotentialNodes(std::vector<unsigned> nodes);
00387 
00393     void SetIntracellularConductivitiesForSecondCell(c_vector<double, DIM> conductivities);
00394 
00407     void SetExtendedBidomainParameters(double Am1, double Am2, double AmGap, double Cm1, double Cm2, double Ggap);
00408 
00417     void SetGgapHeterogeneities ( std::vector<boost::shared_ptr<AbstractChasteRegion<DIM> > >& rGgapHeterogeneityRegions, std::vector<double>& rGgapValues);
00418 
00424     void SetExtracellularStimulusFactory( AbstractStimulusFactory<DIM>* pFactory);
00425 
00426 
00434     void SetNodeForAverageOfPhiZeroed(unsigned node);
00435 
00436 
00440     ExtendedBidomainTissue<DIM>* GetExtendedBidomainTissue();
00441 
00447     void WriteInfo(double time);
00448 
00457     virtual void DefineWriterColumns(bool extending);
00458 
00474     virtual void WriteOneStep(double time, Vec voltageVec);
00475 
00480     void PreSolveChecks();
00481 
00482 
00486     bool GetHasBath();
00487 
00494     void SetHasBath(bool hasBath);
00495 
00496 };
00497 
00498 #include "SerializationExportWrapper.hpp" // Must be last
00499 EXPORT_TEMPLATE_CLASS_SAME_DIMS(ExtendedBidomainProblem)
00500 
00501 #endif /*EXTENDEDBIDOMAINPROBLEM_HPP_*/

Generated by  doxygen 1.6.2