AbstractLinearPdeSolver.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 #ifndef ABSTRACTLINEARPDESOLVER_HPP_
00030 #define ABSTRACTLINEARPDESOLVER_HPP_
00031 
00032 #include "LinearSystem.hpp"
00033 #include "BoundaryConditionsContainer.hpp"
00034 #include "AbstractTetrahedralMesh.hpp"
00035 #include "HeartEventHandler.hpp"
00036 
00041 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00042 class AbstractLinearPdeSolver : boost::noncopyable
00043 {
00044 protected:
00045 
00047     LinearSystem* mpLinearSystem;
00048 
00050     AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* mpMesh;
00051 
00052 public:
00053 
00059     AbstractLinearPdeSolver(AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* pMesh)
00060         : mpLinearSystem(NULL),
00061           mpMesh(pMesh)
00062     {
00063         assert(pMesh!=NULL);
00064     }
00065 
00069     virtual ~AbstractLinearPdeSolver()
00070     {
00071         if (mpLinearSystem)
00072         {
00073             delete mpLinearSystem;
00074         }
00075     }
00076 
00086     virtual void InitialiseForSolve(Vec initialSolution = NULL);
00087 
00094     virtual void PrepareForSetupLinearSystem(Vec currentSolution)
00095     {
00096     }
00097 
00105     virtual void FinaliseLinearSystem(Vec currentSolution)
00106     {
00107     }
00108 
00118     virtual void FollowingSolveLinearSystem(Vec currentSolution)
00119     {
00120     }
00121 
00133     virtual void SetupLinearSystem(Vec currentSolution, bool computeMatrix)=0;
00134 
00138     LinearSystem* GetLinearSystem()
00139     {
00140         return mpLinearSystem;
00141     }
00142 };
00143 
00144 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
00145 void AbstractLinearPdeSolver<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM>::InitialiseForSolve(Vec initialSolution)
00146 {
00147     if (this->mpLinearSystem == NULL)
00148     {
00149         unsigned preallocation=(mpMesh->CalculateMaximumContainingElementsPerProcess() + ELEMENT_DIM);
00150         if (ELEMENT_DIM > 1)
00151         {
00152             // Highest connectivity is closed
00153             preallocation--;
00154         }
00155         preallocation *= PROBLEM_DIM;
00156 
00157         HeartEventHandler::BeginEvent(HeartEventHandler::COMMUNICATION);
00158         if (initialSolution == NULL)
00159         {
00160             /*
00161              * Static problem, create linear system. The following ensures
00162              * all the unknowns for a particular node are on the same processor.
00163              */
00164             Vec template_vec = mpMesh->GetDistributedVectorFactory()->CreateVec(PROBLEM_DIM);
00165 
00166             this->mpLinearSystem = new LinearSystem(template_vec, preallocation);
00167 
00168             VecDestroy(template_vec);
00169         }
00170         else
00171         {
00172             /*
00173              * Use the current solution (ie the initial solution)
00174              * as the template in the alternative constructor of
00175              * LinearSystem. This is to avoid problems with VecScatter.
00176              */
00177             this->mpLinearSystem = new LinearSystem(initialSolution, preallocation);
00178         }
00179 
00180         HeartEventHandler::EndEvent(HeartEventHandler::COMMUNICATION);
00181     }
00182 }
00183 
00184 #endif /*ABSTRACTLINEARPDESOLVER_HPP_*/
Generated on Thu Dec 22 13:00:17 2011 for Chaste by  doxygen 1.6.3