00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _ABSTRACTLINEARASSEMBLER_HPP_
00029 #define _ABSTRACTLINEARASSEMBLER_HPP_
00030
00031
00032 #include <vector>
00033 #include <iostream>
00034 #include <petscvec.h>
00035
00036 #include "AbstractStaticAssembler.hpp"
00037
00038
00042 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM, bool NON_HEART, class CONCRETE>
00043 class AbstractLinearAssembler : public AbstractStaticAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, NON_HEART, CONCRETE>
00044 {
00045 private:
00046
00048 bool mMatrixIsConstant;
00049
00050 protected:
00051
00057 void SetMatrixIsConst(bool matrixIsConstant=true);
00058
00065 void ApplyDirichletConditions(Vec unusedVector, bool applyToMatrix);
00066
00073 virtual void InitialiseForSolve(Vec initialSolution);
00074
00078 bool ProblemIsNonlinear();
00079
00091 virtual Vec StaticSolve(Vec currentSolutionOrGuess=NULL,
00092 double currentTime=0.0,
00093 bool assembleMatrix=true);
00094
00095 public:
00096
00102 AbstractLinearAssembler(unsigned numQuadPoints=2);
00103
00107 ~AbstractLinearAssembler();
00108
00118 virtual Vec Solve(Vec currentSolutionOrGuess=NULL, double currentTime=0.0);
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 };
00140
00141
00143
00145
00146
00147 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM, bool NON_HEART, class CONCRETE>
00148 void AbstractLinearAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, NON_HEART, CONCRETE>::SetMatrixIsConst(bool matrixIsConstant)
00149 {
00150 mMatrixIsConstant = matrixIsConstant;
00151 }
00152
00153 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM, bool NON_HEART, class CONCRETE>
00154 void AbstractLinearAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, NON_HEART, CONCRETE>::ApplyDirichletConditions(Vec unusedVector, bool applyToMatrix)
00155 {
00156 this->mpBoundaryConditions->ApplyDirichletToLinearProblem(*(this->mpLinearSystem), applyToMatrix);
00157 }
00158
00159 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM, bool NON_HEART, class CONCRETE>
00160 void AbstractLinearAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, NON_HEART, CONCRETE>::InitialiseForSolve(Vec initialSolution)
00161 {
00162 if (this->mpLinearSystem == NULL)
00163 {
00164 HeartEventHandler::BeginEvent(HeartEventHandler::COMMUNICATION);
00165 if (initialSolution == NULL)
00166 {
00167
00168
00169
00170 Vec template_vec = this->mpMesh->GetDistributedVectorFactory()->CreateVec(PROBLEM_DIM);
00171
00172 this->mpLinearSystem = new LinearSystem(template_vec);
00173
00174 VecDestroy(template_vec);
00175 }
00176 else
00177 {
00178
00179
00180
00181 this->mpLinearSystem = new LinearSystem(initialSolution);
00182 }
00183
00184 this->mpLinearSystem->SetMatrixIsConstant(mMatrixIsConstant);
00185 HeartEventHandler::EndEvent(HeartEventHandler::COMMUNICATION);
00186 }
00187 }
00188
00189 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM, bool NON_HEART, class CONCRETE>
00190 bool AbstractLinearAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, NON_HEART, CONCRETE>::ProblemIsNonlinear()
00191 {
00192 return false;
00193 }
00194
00195 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM, bool NON_HEART, class CONCRETE>
00196 Vec AbstractLinearAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, NON_HEART, CONCRETE>::StaticSolve(Vec currentSolutionOrGuess,
00197 double currentTime,
00198 bool assembleMatrix)
00199 {
00200 this->AssembleSystem(true, assembleMatrix, currentSolutionOrGuess, currentTime);
00201 return this->mpLinearSystem->Solve(currentSolutionOrGuess);
00202 }
00203
00204 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM, bool NON_HEART, class CONCRETE>
00205 AbstractLinearAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, NON_HEART, CONCRETE>::AbstractLinearAssembler(unsigned numQuadPoints)
00206 : AbstractStaticAssembler<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM, NON_HEART, CONCRETE>(numQuadPoints),
00207 mMatrixIsConstant(true)
00208 {
00209 }
00210
00211 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM, bool NON_HEART, class CONCRETE>
00212 AbstractLinearAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, NON_HEART, CONCRETE>::~AbstractLinearAssembler()
00213 {
00214 }
00215
00216 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM, bool NON_HEART, class CONCRETE>
00217 Vec AbstractLinearAssembler<ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM, NON_HEART, CONCRETE>::Solve(Vec currentSolutionOrGuess, double currentTime)
00218 {
00219
00220
00221
00222
00223 this->PrepareForSolve();
00224 this->InitialiseForSolve(currentSolutionOrGuess);
00225 return this->StaticSolve(currentSolutionOrGuess, currentTime);
00226 }
00227
00228 #endif //_ABSTRACTLINEARASSEMBLER_HPP_