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 bool mMatrixIsConstant;
00047
00048 protected:
00049
00051 void SetMatrixIsConst(bool matrixIsConstant = true)
00052 {
00053 mMatrixIsConstant = matrixIsConstant;
00054 }
00055
00059 void ApplyDirichletConditions(Vec , bool applyToMatrix)
00060 {
00061 this->mpBoundaryConditions->ApplyDirichletToLinearProblem(*(this->mpLinearSystem), applyToMatrix);
00062 }
00063
00069 virtual void InitialiseForSolve(Vec initialSolution)
00070 {
00071 if (this->mpLinearSystem == NULL)
00072 {
00073 if (initialSolution == NULL)
00074 {
00075
00076
00077
00078 DistributedVector::SetProblemSize(this->mpMesh->GetNumNodes());
00079 Vec template_vec = DistributedVector::CreateVec(PROBLEM_DIM);
00080
00081 this->mpLinearSystem = new LinearSystem(template_vec);
00082
00083 VecDestroy(template_vec);
00084 }
00085 else
00086 {
00087
00088
00089
00090 this->mpLinearSystem = new LinearSystem(initialSolution);
00091 }
00092
00093 this->mpLinearSystem->SetMatrixIsConstant(mMatrixIsConstant);
00094 }
00095 }
00096
00097 bool ProblemIsNonlinear()
00098 {
00099 return false;
00100 }
00101
00107 virtual Vec StaticSolve(Vec currentSolutionOrGuess=NULL,
00108 double currentTime=0.0,
00109 bool assembleMatrix=true)
00110 {
00111 this->AssembleSystem(true, assembleMatrix, currentSolutionOrGuess, currentTime);
00112 return this->mpLinearSystem->Solve(currentSolutionOrGuess);
00113 }
00114
00115
00116 public:
00117 AbstractLinearAssembler(unsigned numQuadPoints = 2) :
00118 AbstractStaticAssembler<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM, NON_HEART, CONCRETE>(numQuadPoints),
00119 mMatrixIsConstant(true)
00120 {
00121 }
00122
00126 ~AbstractLinearAssembler()
00127 {
00128 }
00129
00136 virtual Vec Solve(Vec currentSolutionOrGuess=NULL, double currentTime=0.0)
00137 {
00139 assert(this->mpMesh!=NULL);
00140
00141
00142
00143
00144
00145 this->PrepareForSolve();
00146 this->InitialiseForSolve(currentSolutionOrGuess);
00147 return this->StaticSolve(currentSolutionOrGuess, currentTime);
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 };
00171
00172 #endif //_ABSTRACTLINEARASSEMBLER_HPP_