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 ELEMENT_DIM, unsigned SPACE_DIM>
00052 c_matrix<double,1*(ELEMENT_DIM+1),1*(ELEMENT_DIM+1)> MonodomainRhsMatrixAssembler<ELEMENT_DIM,SPACE_DIM>::ComputeMatrixTerm(
00053 c_vector<double, ELEMENT_DIM+1> &rPhi,
00054 c_matrix<double, SPACE_DIM, ELEMENT_DIM+1> &rGradPhi,
00055 ChastePoint<SPACE_DIM> &rX,
00056 c_vector<double,1> &u,
00057 c_matrix<double,1,SPACE_DIM> &rGradU ,
00058 Element<ELEMENT_DIM,SPACE_DIM>* pElement)
00059 {
00060 return outer_prod(rPhi, rPhi);
00061 }
00062
00063 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00064 c_vector<double,1*(ELEMENT_DIM+1)> MonodomainRhsMatrixAssembler<ELEMENT_DIM,SPACE_DIM>::ComputeVectorTerm(
00065 c_vector<double, ELEMENT_DIM+1> &rPhi,
00066 c_matrix<double, SPACE_DIM, ELEMENT_DIM+1> &rGradPhi,
00067 ChastePoint<SPACE_DIM> &rX,
00068 c_vector<double,1> &u,
00069 c_matrix<double, 1, SPACE_DIM> &rGradU ,
00070 Element<ELEMENT_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 ELEMENT_DIM, unsigned SPACE_DIM>
00079 c_vector<double, ELEMENT_DIM> MonodomainRhsMatrixAssembler<ELEMENT_DIM, SPACE_DIM>::ComputeVectorSurfaceTerm(
00080 const BoundaryElement<ELEMENT_DIM-1,SPACE_DIM> &rSurfaceElement,
00081 c_vector<double, ELEMENT_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 ELEMENT_DIM, unsigned SPACE_DIM>
00092 MonodomainRhsMatrixAssembler<ELEMENT_DIM,SPACE_DIM>::MonodomainRhsMatrixAssembler(AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* pMesh)
00093 : AbstractLinearAssembler<ELEMENT_DIM,SPACE_DIM,1,false,MonodomainRhsMatrixAssembler<ELEMENT_DIM,SPACE_DIM> >()
00094 {
00095 this->mpMesh = pMesh;
00096
00097
00098 this->mpBoundaryConditions = new BoundaryConditionsContainer<ELEMENT_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 ELEMENT_DIM, unsigned SPACE_DIM>
00109 MonodomainRhsMatrixAssembler<ELEMENT_DIM, SPACE_DIM>::~MonodomainRhsMatrixAssembler()
00110 {
00111 delete this->mpBoundaryConditions;
00112 }
00113
00114 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00115 Mat* MonodomainRhsMatrixAssembler<ELEMENT_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
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00209 void MonodomainMatrixBasedAssembler<ELEMENT_DIM,SPACE_DIM>::ConstructVectorForMatrixBasedRhsAssembly(
00210 Vec existingSolution)
00211 {
00212 DistributedVectorFactory* p_factory = this->mpMesh->GetDistributedVectorFactory();
00213
00214
00215 DistributedVector distributed_current_solution = p_factory->CreateDistributedVector(existingSolution);
00216
00217
00218 DistributedVector dist_vec_matrix_based = p_factory->CreateDistributedVector(this->mVectorForMatrixBasedRhsAssembly);
00219
00220 double Am = HeartConfig::Instance()->GetSurfaceAreaToVolumeRatio();
00221 double Cm = HeartConfig::Instance()->GetCapacitance();
00222
00223 for (DistributedVector::Iterator index = dist_vec_matrix_based.Begin();
00224 index!= dist_vec_matrix_based.End();
00225 ++index)
00226 {
00227 double V = distributed_current_solution[index];
00228 double F = - Am*this->mpMonodomainPde->rGetIionicCacheReplicated()[index.Global]
00229 - this->mpMonodomainPde->rGetIntracellularStimulusCacheReplicated()[index.Global];
00230
00231 dist_vec_matrix_based[index] = Am*Cm*V*this->mDtInverse + F;
00232 }
00233
00234 dist_vec_matrix_based.Restore();
00235
00236 VecAssemblyBegin(this->mVectorForMatrixBasedRhsAssembly);
00237 VecAssemblyEnd(this->mVectorForMatrixBasedRhsAssembly);
00238 }
00239
00240
00241
00243
00245
00246 template class MonodomainMatrixBasedAssembler<1,1>;
00247 template class MonodomainMatrixBasedAssembler<1,2>;
00248 template class MonodomainMatrixBasedAssembler<1,3>;
00249 template class MonodomainMatrixBasedAssembler<2,2>;
00250 template class MonodomainMatrixBasedAssembler<3,3>;
00251
00252 template class MonodomainRhsMatrixAssembler<1,1>;
00253 template class MonodomainRhsMatrixAssembler<1,2>;
00254 template class MonodomainRhsMatrixAssembler<1,3>;
00255 template class MonodomainRhsMatrixAssembler<2,2>;
00256 template class MonodomainRhsMatrixAssembler<3,3>;