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 #include "MonodomainMatrixBasedAssembler.hpp"
00030
00031
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00045
00046
00047
00049
00051 template<unsigned ELEM_DIM, unsigned SPACE_DIM>
00052 c_matrix<double,1*(ELEM_DIM+1),1*(ELEM_DIM+1)> MonodomainRhsMatrixAssembler<ELEM_DIM,SPACE_DIM>::ComputeMatrixTerm(
00053 c_vector<double, ELEM_DIM+1> &rPhi,
00054 c_matrix<double, SPACE_DIM, ELEM_DIM+1> &rGradPhi,
00055 ChastePoint<SPACE_DIM> &rX,
00056 c_vector<double,1> &u,
00057 c_matrix<double,1,SPACE_DIM> &rGradU ,
00058 Element<ELEM_DIM,SPACE_DIM>* pElement)
00059 {
00060 return outer_prod(rPhi, rPhi);
00061 }
00062
00063 template<unsigned ELEM_DIM, unsigned SPACE_DIM>
00064 c_vector<double,1*(ELEM_DIM+1)> MonodomainRhsMatrixAssembler<ELEM_DIM,SPACE_DIM>::ComputeVectorTerm(
00065 c_vector<double, ELEM_DIM+1> &rPhi,
00066 c_matrix<double, SPACE_DIM, ELEM_DIM+1> &rGradPhi,
00067 ChastePoint<SPACE_DIM> &rX,
00068 c_vector<double,1> &u,
00069 c_matrix<double, 1, SPACE_DIM> &rGradU ,
00070 Element<ELEM_DIM,SPACE_DIM>* pElement)
00071 {
00072 #define COVERAGE_IGNORE
00073 NEVER_REACHED;
00074 return zero_vector<double>(SPACE_DIM+1);
00075 #undef COVERAGE_IGNORE
00076 }
00077
00078 template<unsigned ELEM_DIM, unsigned SPACE_DIM>
00079 c_vector<double, ELEM_DIM> MonodomainRhsMatrixAssembler<ELEM_DIM, SPACE_DIM>::ComputeVectorSurfaceTerm(
00080 const BoundaryElement<ELEM_DIM-1,SPACE_DIM> &rSurfaceElement,
00081 c_vector<double, ELEM_DIM> &rPhi,
00082 ChastePoint<SPACE_DIM> &rX )
00083 {
00084 #define COVERAGE_IGNORE
00085 NEVER_REACHED;
00086 return zero_vector<double>(SPACE_DIM);
00087 #undef COVERAGE_IGNORE
00088 }
00089
00090
00091 template<unsigned ELEM_DIM, unsigned SPACE_DIM>
00092 MonodomainRhsMatrixAssembler<ELEM_DIM,SPACE_DIM>::MonodomainRhsMatrixAssembler(AbstractTetrahedralMesh<ELEM_DIM,SPACE_DIM>* pMesh)
00093 : AbstractLinearAssembler<ELEM_DIM,SPACE_DIM,1,false,MonodomainRhsMatrixAssembler<ELEM_DIM,SPACE_DIM> >()
00094 {
00095 this->mpMesh = pMesh;
00096
00097
00098 this->mpBoundaryConditions = new BoundaryConditionsContainer<ELEM_DIM,SPACE_DIM,1>;
00099 this->mpBoundaryConditions->DefineZeroNeumannOnMeshBoundary(pMesh);
00100
00101
00102 Vec temp_vec = pMesh->GetDistributedVectorFactory()->CreateVec();
00103 this->mpLinearSystem = new LinearSystem(temp_vec);
00104 VecDestroy(temp_vec);
00105 this->AssembleSystem(false,true);
00106 }
00107
00108 template<unsigned ELEM_DIM, unsigned SPACE_DIM>
00109 MonodomainRhsMatrixAssembler<ELEM_DIM, SPACE_DIM>::~MonodomainRhsMatrixAssembler()
00110 {
00111 delete this->mpBoundaryConditions;
00112 }
00113
00114 template<unsigned ELEM_DIM, unsigned SPACE_DIM>
00115 Mat* MonodomainRhsMatrixAssembler<ELEM_DIM,SPACE_DIM>::GetMatrix()
00116 {
00117 return &(this->mpLinearSystem->rGetLhsMatrix());
00118 }
00119
00120
00121
00122
00123
00125
00127
00128 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00129 MonodomainMatrixBasedAssembler<ELEMENT_DIM,SPACE_DIM>::MonodomainMatrixBasedAssembler(
00130 AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* pMesh,
00131 MonodomainPde<ELEMENT_DIM,SPACE_DIM>* pPde,
00132 BoundaryConditionsContainer<ELEMENT_DIM, SPACE_DIM, 1>* pBcc,
00133 unsigned numQuadPoints)
00134 : MonodomainDg0Assembler<ELEMENT_DIM,SPACE_DIM>(pMesh, pPde, pBcc, numQuadPoints)
00135 {
00136
00137 mpMonodomainRhsMatrixAssembler = new MonodomainRhsMatrixAssembler<ELEMENT_DIM,SPACE_DIM>(pMesh);
00138 this->mpMatrixForMatrixBasedRhsAssembly = mpMonodomainRhsMatrixAssembler->GetMatrix();
00139
00140
00141
00142 this->mUseMatrixBasedRhsAssembly = true;
00143 this->mVectorForMatrixBasedRhsAssembly = pMesh->GetDistributedVectorFactory()->CreateVec();
00144
00145
00146 pPde->SetCacheReplication(false);
00147 }
00148
00149 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00150 MonodomainMatrixBasedAssembler<ELEMENT_DIM,SPACE_DIM>::~MonodomainMatrixBasedAssembler()
00151 {
00152 delete mpMonodomainRhsMatrixAssembler;
00153 VecDestroy(this->mVectorForMatrixBasedRhsAssembly);
00154 }
00155
00156 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00157 void MonodomainMatrixBasedAssembler<ELEMENT_DIM,SPACE_DIM>::ConstructVectorForMatrixBasedRhsAssembly(Vec existingSolution)
00158 {
00159
00160 VecCopy(existingSolution, this->mVectorForMatrixBasedRhsAssembly);
00161
00162
00163 Vec force_term_at_nodes = this->mpMesh->GetDistributedVectorFactory()->CreateVec();
00164 PetscInt lo, hi;
00165 VecGetOwnershipRange(force_term_at_nodes, &lo, &hi);
00166 double *p_force_term;
00167 VecGetArray(force_term_at_nodes, &p_force_term);
00168 for (int global_index=lo; global_index<hi; global_index++)
00169 {
00170 unsigned local_index = global_index - lo;
00171 const Node<SPACE_DIM>* p_node = this->mpMesh->GetNode(global_index);
00172 p_force_term[local_index] = this->mpMonodomainPde->ComputeNonlinearSourceTermAtNode(*p_node, 0.0);
00173 }
00174 VecRestoreArray(force_term_at_nodes, &p_force_term);
00175 VecAssemblyBegin(force_term_at_nodes);
00176 VecAssemblyEnd(force_term_at_nodes);
00177
00178 double one=1.0;
00179 double scaling= this->mpMonodomainPde->ComputeDuDtCoefficientFunction(ChastePoint<SPACE_DIM>())
00180 *this->mDtInverse;
00181
00182 #if (PETSC_VERSION_MINOR == 2) //Old API
00183
00184 VecAXPBY(&one, &scaling, force_term_at_nodes, this->mVectorForMatrixBasedRhsAssembly);
00185 #else
00186
00187 VecAXPBY(this->mVectorForMatrixBasedRhsAssembly,
00188 one,
00189 scaling,
00190 force_term_at_nodes);
00191 #endif
00192
00193 VecAssemblyBegin(this->mVectorForMatrixBasedRhsAssembly);
00194 VecAssemblyEnd(this->mVectorForMatrixBasedRhsAssembly);
00195 VecDestroy(force_term_at_nodes);
00196 }
00197
00199
00201
00202 template class MonodomainMatrixBasedAssembler<1,1>;
00203 template class MonodomainMatrixBasedAssembler<1,2>;
00204 template class MonodomainMatrixBasedAssembler<1,3>;
00205 template class MonodomainMatrixBasedAssembler<2,2>;
00206 template class MonodomainMatrixBasedAssembler<3,3>;
00207
00208 template class MonodomainRhsMatrixAssembler<1,1>;
00209 template class MonodomainRhsMatrixAssembler<1,2>;
00210 template class MonodomainRhsMatrixAssembler<1,3>;
00211 template class MonodomainRhsMatrixAssembler<2,2>;
00212 template class MonodomainRhsMatrixAssembler<3,3>;