MonodomainProblem.cpp

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 #include "MonodomainProblem.hpp"
00030 
00031 #include "Exception.hpp"
00032 #include "ReplicatableVector.hpp"
00033 #include "MonodomainSolver.hpp"
00034 #include "OperatorSplittingMonodomainSolver.hpp"
00035 
00036 
00037 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00038 AbstractCardiacTissue<ELEMENT_DIM,SPACE_DIM>* MonodomainProblem<ELEMENT_DIM, SPACE_DIM>::CreateCardiacTissue()
00039 {
00040     mpMonodomainTissue = new MonodomainTissue<ELEMENT_DIM,SPACE_DIM>(this->mpCellFactory, HeartConfig::Instance()->GetUseStateVariableInterpolation());
00041     return mpMonodomainTissue;
00042 }
00043 
00044 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00045 AbstractDynamicLinearPdeSolver<ELEMENT_DIM, SPACE_DIM, 1>* MonodomainProblem<ELEMENT_DIM, SPACE_DIM>::CreateSolver()
00046 {
00047     assert(mpMonodomainTissue);
00048     /*
00049      * NOTE: The this->mpBoundaryConditionsContainer.get() lines below convert a
00050      * boost::shared_ptr to a normal pointer, as this is what the solvers are
00051      * expecting. We have to be a bit careful though as boost could decide to delete
00052      * them whenever it feels like as it won't count the assembers as using them.
00053      *
00054      * As long as they are kept as member variables here for as long as they are
00055      * required in the solvers it should all work OK.
00056      */
00057 
00058     if (HeartConfig::Instance()->GetUseReactionDiffusionOperatorSplitting())
00059     {
00060         return new OperatorSplittingMonodomainSolver<ELEMENT_DIM,SPACE_DIM>(this->mpMesh,
00061                                                                             mpMonodomainTissue,
00062                                                                             this->mpBoundaryConditionsContainer.get(),
00063                                                                             2);
00064     }
00065     else
00066     {
00067         return new MonodomainSolver<ELEMENT_DIM,SPACE_DIM>(this->mpMesh,
00068                                                            mpMonodomainTissue,
00069                                                            this->mpBoundaryConditionsContainer.get(),
00070                                                            2);
00071     }
00072 }
00073 
00074 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00075 MonodomainProblem<ELEMENT_DIM, SPACE_DIM>::MonodomainProblem(AbstractCardiacCellFactory<ELEMENT_DIM,SPACE_DIM>* pCellFactory)
00076         : AbstractCardiacProblem<ELEMENT_DIM, SPACE_DIM, 1>(pCellFactory),
00077           mpMonodomainTissue(NULL)
00078 {
00079 }
00080 
00081 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00082 MonodomainProblem<ELEMENT_DIM, SPACE_DIM>::MonodomainProblem()
00083     : AbstractCardiacProblem<ELEMENT_DIM, SPACE_DIM, 1>(),
00084       mpMonodomainTissue(NULL)
00085 {
00086 }
00087 
00088 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00089 MonodomainProblem<ELEMENT_DIM, SPACE_DIM>::~MonodomainProblem()
00090 {
00091 }
00092 
00093 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00094 MonodomainTissue<ELEMENT_DIM,SPACE_DIM> * MonodomainProblem<ELEMENT_DIM, SPACE_DIM>::GetMonodomainTissue()
00095 {
00096     assert(mpMonodomainTissue != NULL);
00097     return mpMonodomainTissue;
00098 }
00099 
00100 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00101 void MonodomainProblem<ELEMENT_DIM, SPACE_DIM>::WriteInfo(double time)
00102 {
00103     if (PetscTools::AmMaster())
00104     {
00105         std::cout << "Solved to time " << time << "\n" << std::flush;
00106     }
00107 
00108     double v_max, v_min;
00109 
00110     VecMax( this->mSolution, PETSC_NULL, &v_max );
00111     VecMin( this->mSolution, PETSC_NULL, &v_min );
00112 
00113     if (PetscTools::AmMaster())
00114     {
00115         std::cout << " V = " << "[" <<v_min << ", " << v_max << "]" << "\n" << std::flush;
00116     }
00117 }
00118 
00119 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00120 void MonodomainProblem<ELEMENT_DIM, SPACE_DIM>::DefineWriterColumns(bool extending)
00121 {
00122     AbstractCardiacProblem<ELEMENT_DIM,SPACE_DIM,1>::DefineWriterColumns(extending);
00123     AbstractCardiacProblem<ELEMENT_DIM,SPACE_DIM,1>::DefineExtraVariablesWriterColumns(extending);
00124 }
00125 
00126 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00127 void MonodomainProblem<ELEMENT_DIM, SPACE_DIM>::WriteOneStep(double time, Vec voltageVec)
00128 {
00129     this->mpWriter->PutUnlimitedVariable(time);
00130     this->mpWriter->PutVector(this->mVoltageColumnId, voltageVec);
00131     AbstractCardiacProblem<ELEMENT_DIM,SPACE_DIM,1>::WriteExtraVariablesOneStep();
00132 }
00133 
00134 
00136 // Explicit instantiation
00138 
00139 template class MonodomainProblem<1,1>;
00140 template class MonodomainProblem<1,2>;
00141 template class MonodomainProblem<1,3>;
00142 template class MonodomainProblem<2,2>;
00143 template class MonodomainProblem<3,3>;
00144 
00145 
00146 
00147 // Serialization for Boost >= 1.36
00148 #include "SerializationExportWrapperForCpp.hpp"
00149 EXPORT_TEMPLATE_CLASS2(MonodomainProblem, 1, 1)
00150 EXPORT_TEMPLATE_CLASS2(MonodomainProblem, 1, 2)
00151 EXPORT_TEMPLATE_CLASS2(MonodomainProblem, 1, 3)
00152 EXPORT_TEMPLATE_CLASS2(MonodomainProblem, 2, 2)
00153 EXPORT_TEMPLATE_CLASS2(MonodomainProblem, 3, 3)
Generated on Thu Dec 22 13:00:06 2011 for Chaste by  doxygen 1.6.3