BasicBidomainSolver.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 "BasicBidomainSolver.hpp"
00030 
00031 
00032 
00033 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00034 BasicBidomainSolver<ELEMENT_DIM,SPACE_DIM>::BasicBidomainSolver(
00035             bool bathSimulation,
00036             AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* pMesh,
00037             BidomainTissue<SPACE_DIM>* pTissue,
00038             BoundaryConditionsContainer<ELEMENT_DIM, SPACE_DIM, 2>* pBcc,
00039             unsigned numQuadPoints)
00040     : AbstractBidomainSolver<ELEMENT_DIM,SPACE_DIM>(bathSimulation,pMesh,pTissue,pBcc,numQuadPoints)
00041 {
00042     pTissue->SetCacheReplication(true);
00043 
00044     if(HeartConfig::Instance()->GetUseStateVariableInterpolation())
00045     {
00046         EXCEPTION("State variable interpolation only available when matrix-based assembly is switched on");
00047     }
00048 }
00049 
00050 
00051 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00052 void BasicBidomainSolver<ELEMENT_DIM,SPACE_DIM>::SetupLinearSystem(Vec currentSolution, bool computeMatrix)
00053 {
00054     assert(this->mpLinearSystem->rGetLhsMatrix() != NULL);
00055     assert(this->mpLinearSystem->rGetRhsVector() != NULL);
00056     assert(currentSolution != NULL);
00057 
00058     // create assembler
00059     if(!this->mpBidomainAssembler)
00060     {
00061         InitialiseAssembler();
00062     } 
00063 
00064     // use assembler to assemble LHS matrix and RHS vector
00065 
00066     this->mpBidomainAssembler->SetMatrixToAssemble(this->mpLinearSystem->rGetLhsMatrix());
00067     this->mpBidomainAssembler->SetVectorToAssemble(this->mpLinearSystem->rGetRhsVector(), true);
00068 
00069     // MUST be called every timestep in case the bcc has been reset, see comment in
00070     // this->ResetBoundaryConditionsContainer()
00071     this->mpBidomainAssembler->SetApplyNeummanBoundaryConditionsToVector(this->mpBoundaryConditions);
00072 
00073     this->mpBidomainAssembler->SetCurrentSolution(currentSolution);
00074    
00075     if(computeMatrix)
00076     {
00077         this->mpBidomainAssembler->Assemble();
00078     }
00079     else
00080     {
00081         this->mpBidomainAssembler->AssembleVector();
00082     }
00083 
00084     this->mpLinearSystem->AssembleRhsVector();
00085     
00086     this->mpBoundaryConditions->ApplyDirichletToLinearProblem(*(this->mpLinearSystem), computeMatrix);
00087 
00088     if(this->mBathSimulation)
00089     {
00090         this->mpLinearSystem->AssembleFinalLhsMatrix();
00091         this->FinaliseForBath(computeMatrix,true);
00092     }
00093 
00094     this->mpLinearSystem->AssembleRhsVector();
00095     this->mpLinearSystem->AssembleFinalLhsMatrix();
00096 }
00097 
00098 
00099 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00100 void BasicBidomainSolver<ELEMENT_DIM,SPACE_DIM>::InitialiseAssembler()
00101 {
00102     if(!this->mpBidomainAssembler)
00103     {
00104         if(this->mBathSimulation)
00105         {
00106             this->mpBidomainAssembler = new BidomainWithBathAssembler<ELEMENT_DIM,SPACE_DIM>(this->mpMesh,this->mpBidomainTissue,this->mNumQuadPoints);
00107         }
00108         else
00109         {
00110             this->mpBidomainAssembler = new BidomainAssembler<ELEMENT_DIM,SPACE_DIM>(this->mpMesh,this->mpBidomainTissue,this->mNumQuadPoints);
00111         }
00112     }        
00113 }
00114 
00115 
00117 // explicit instantiation
00119 
00120 template class BasicBidomainSolver<1,1>;
00121 template class BasicBidomainSolver<2,2>;
00122 template class BasicBidomainSolver<3,3>;
00123 

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