AbstractFeAssemblerInterface.hpp
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
00029 #ifndef ABSTRACTFEASSEMBLERINTERFACE_HPP_
00030 #define ABSTRACTFEASSEMBLERINTERFACE_HPP_
00031
00032 #include <cassert>
00033 #include "UblasCustomFunctions.hpp"
00034 #include "PetscTools.hpp"
00035
00043 template <bool CAN_ASSEMBLE_VECTOR, bool CAN_ASSEMBLE_MATRIX>
00044 class AbstractFeAssemblerInterface : boost::noncopyable
00045 {
00046 protected:
00048 Vec mVectorToAssemble;
00049
00051 Mat mMatrixToAssemble;
00052
00058 bool mAssembleMatrix;
00059
00061 bool mAssembleVector;
00062
00064 bool mZeroMatrixBeforeAssembly;
00065
00067 bool mZeroVectorBeforeAssembly;
00068
00070 PetscInt mOwnershipRangeLo;
00071
00073 PetscInt mOwnershipRangeHi;
00074
00082 virtual void DoAssemble()=0;
00083
00084 public:
00085
00089 AbstractFeAssemblerInterface();
00090
00098 void SetMatrixToAssemble(Mat& rMatToAssemble, bool zeroMatrixBeforeAssembly=true);
00099
00107 void SetVectorToAssemble(Vec& rVecToAssemble, bool zeroVectorBeforeAssembly);
00108
00112 void Assemble()
00113 {
00114 mAssembleMatrix = CAN_ASSEMBLE_MATRIX;
00115 mAssembleVector = CAN_ASSEMBLE_VECTOR;
00116 DoAssemble();
00117 }
00118
00122 void AssembleMatrix()
00123 {
00124 assert(CAN_ASSEMBLE_MATRIX);
00125 mAssembleMatrix = true;
00126 mAssembleVector = false;
00127 DoAssemble();
00128 }
00129
00133 void AssembleVector()
00134 {
00135 assert(CAN_ASSEMBLE_VECTOR);
00136 mAssembleMatrix = false;
00137 mAssembleVector = true;
00138 DoAssemble();
00139 }
00140
00144 virtual ~AbstractFeAssemblerInterface()
00145 {
00146 }
00147 };
00148
00149 template <bool CAN_ASSEMBLE_VECTOR, bool CAN_ASSEMBLE_MATRIX>
00150 AbstractFeAssemblerInterface<CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX>::AbstractFeAssemblerInterface()
00151 : mVectorToAssemble(NULL),
00152 mMatrixToAssemble(NULL),
00153 mZeroMatrixBeforeAssembly(true),
00154 mZeroVectorBeforeAssembly(true)
00155 {
00156 assert(CAN_ASSEMBLE_VECTOR || CAN_ASSEMBLE_MATRIX);
00157 }
00158
00159 template <bool CAN_ASSEMBLE_VECTOR, bool CAN_ASSEMBLE_MATRIX>
00160 void AbstractFeAssemblerInterface<CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX>::SetMatrixToAssemble(Mat& rMatToAssemble, bool zeroMatrixBeforeAssembly)
00161 {
00162 assert(rMatToAssemble);
00163 MatGetOwnershipRange(rMatToAssemble, &mOwnershipRangeLo, &mOwnershipRangeHi);
00164
00165 mMatrixToAssemble = rMatToAssemble;
00166 mZeroMatrixBeforeAssembly = zeroMatrixBeforeAssembly;
00167 }
00168
00169 template <bool CAN_ASSEMBLE_VECTOR, bool CAN_ASSEMBLE_MATRIX>
00170 void AbstractFeAssemblerInterface<CAN_ASSEMBLE_VECTOR, CAN_ASSEMBLE_MATRIX>::SetVectorToAssemble(Vec& rVecToAssemble, bool zeroVectorBeforeAssembly)
00171 {
00172 assert(rVecToAssemble);
00173 VecGetOwnershipRange(rVecToAssemble, &mOwnershipRangeLo, &mOwnershipRangeHi);
00174
00175 mVectorToAssemble = rVecToAssemble;
00176 mZeroVectorBeforeAssembly = zeroVectorBeforeAssembly;
00177 }
00178
00179 #endif // ABSTRACTFEASSEMBLERINTERFACE_HPP_