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 "BidomainWithBathMatrixBasedAssembler.hpp"
00030
00031 #include <boost/numeric/ublas/vector_proxy.hpp>
00032
00033 #include "ConstBoundaryCondition.hpp"
00034 #include "HeartRegionCodes.hpp"
00035
00036
00038
00040
00041 template<unsigned DIM>
00042 c_matrix<double,2*(DIM+1),2*(DIM+1)> BidomainWithBathRhsMatrixAssembler<DIM>::ComputeMatrixTerm(
00043 c_vector<double, DIM+1> &rPhi,
00044 c_matrix<double, DIM, DIM+1> &rGradPhi,
00045 ChastePoint<DIM> &rX,
00046 c_vector<double,2> &rU,
00047 c_matrix<double,2,DIM> &rGradU ,
00048 Element<DIM,DIM>* pElement)
00049 {
00050 c_matrix<double,2*(DIM+1),2*(DIM+1)> ret = zero_matrix<double>(2*(DIM+1), 2*(DIM+1));
00051
00052 if (pElement->GetRegion() != HeartRegionCode::BATH)
00053 {
00054 c_matrix<double, DIM+1, DIM+1> basis_outer_prod = outer_prod(rPhi, rPhi);
00055
00056
00057 matrix_slice<c_matrix<double, 2*DIM+2, 2*DIM+2> >
00058 slice00(ret, slice (0, 2, DIM+1), slice (0, 2, DIM+1));
00059 slice00 = basis_outer_prod;
00060
00061
00062
00063
00064 }
00065
00066 return ret;
00067 }
00068
00069 template<unsigned DIM>
00070 c_vector<double,2*(DIM+1)> BidomainWithBathRhsMatrixAssembler<DIM>::ComputeVectorTerm(
00071 c_vector<double, DIM+1> &rPhi,
00072 c_matrix<double, DIM, DIM+1> &rGradPhi,
00073 ChastePoint<DIM> &rX,
00074 c_vector<double,2> &rU,
00075 c_matrix<double, 2, DIM> &rGradU ,
00076 Element<DIM,DIM>* pElement)
00077
00078 {
00079 #define COVERAGE_IGNORE
00080 NEVER_REACHED;
00081 return zero_vector<double>(2*(DIM+1));
00082 #undef COVERAGE_IGNORE
00083 }
00084
00085
00086 template<unsigned DIM>
00087 c_vector<double, 2*DIM> BidomainWithBathRhsMatrixAssembler<DIM>::ComputeVectorSurfaceTerm(
00088 const BoundaryElement<DIM-1,DIM> &rSurfaceElement,
00089 c_vector<double, DIM> &rPhi,
00090 ChastePoint<DIM> &rX )
00091 {
00092 #define COVERAGE_IGNORE
00093 NEVER_REACHED;
00094 return zero_vector<double>(2*DIM);
00095 #undef COVERAGE_IGNORE
00096 }
00097
00098
00099 template<unsigned DIM>
00100 BidomainWithBathRhsMatrixAssembler<DIM>::BidomainWithBathRhsMatrixAssembler(AbstractTetrahedralMesh<DIM,DIM>* pMesh)
00101 : AbstractLinearAssembler<DIM,DIM,2,false,BidomainWithBathRhsMatrixAssembler<DIM> >()
00102 {
00103 this->mpMesh = pMesh;
00104
00105
00106 this->mpBoundaryConditions = new BoundaryConditionsContainer<DIM,DIM,2>;
00107 this->mpBoundaryConditions->DefineZeroNeumannOnMeshBoundary(pMesh);
00108
00109
00110 Vec template_vec = this->mpMesh->GetDistributedVectorFactory()->CreateVec(2);
00111 this->mpLinearSystem = new LinearSystem(template_vec);
00112 VecDestroy(template_vec);
00113
00114
00115 this->AssembleSystem(false,true);
00116 }
00117
00118 template<unsigned DIM>
00119 BidomainWithBathRhsMatrixAssembler<DIM>::~BidomainWithBathRhsMatrixAssembler()
00120 {
00121 delete this->mpBoundaryConditions;
00122 }
00123
00124 template<unsigned DIM>
00125 Mat* BidomainWithBathRhsMatrixAssembler<DIM>::GetMatrix()
00126 {
00127 return &(this->mpLinearSystem->rGetLhsMatrix());
00128 }
00129
00131
00133
00134 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00135 BidomainWithBathMatrixBasedAssembler<ELEMENT_DIM,SPACE_DIM>::BidomainWithBathMatrixBasedAssembler(
00136 AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* pMesh,
00137 BidomainPde<SPACE_DIM>* pPde,
00138 BoundaryConditionsContainer<ELEMENT_DIM, SPACE_DIM, 2>* pBcc,
00139 unsigned numQuadPoints)
00140 : BidomainDg0Assembler<ELEMENT_DIM,SPACE_DIM>(pMesh, pPde, pBcc, numQuadPoints),
00141 BidomainMatrixBasedAssembler<ELEMENT_DIM,SPACE_DIM>(pMesh, pPde, pBcc, numQuadPoints),
00142 BidomainWithBathAssembler<ELEMENT_DIM,SPACE_DIM>(pMesh, pPde, pBcc, numQuadPoints)
00143
00144
00145 {
00146
00147 mpBidomainWithBathRhsMatrixAssembler = new BidomainWithBathRhsMatrixAssembler<SPACE_DIM>(pMesh);
00148 this->mpMatrixForMatrixBasedRhsAssembly = mpBidomainWithBathRhsMatrixAssembler->GetMatrix();
00149
00152 }
00153
00154 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00155 BidomainWithBathMatrixBasedAssembler<ELEMENT_DIM,SPACE_DIM>::~BidomainWithBathMatrixBasedAssembler()
00156 {
00157 delete mpBidomainWithBathRhsMatrixAssembler;
00158 }
00159
00160
00161 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00162 void BidomainWithBathMatrixBasedAssembler<ELEMENT_DIM,SPACE_DIM>::ConstructVectorForMatrixBasedRhsAssembly(
00163 Vec existingSolution)
00164 {
00165 DistributedVectorFactory* p_factory = this->mpMesh->GetDistributedVectorFactory();
00166
00167 DistributedVector distributed_current_solution = p_factory->CreateDistributedVector(existingSolution);
00168 DistributedVector::Stripe distributed_current_solution_vm(distributed_current_solution, 0);
00169
00170
00171 DistributedVector dist_vec_matrix_based = p_factory->CreateDistributedVector(this->mVectorForMatrixBasedRhsAssembly);
00172 DistributedVector::Stripe dist_vec_matrix_based_vm(dist_vec_matrix_based, 0);
00173 DistributedVector::Stripe dist_vec_matrix_based_phie(dist_vec_matrix_based, 1);
00174
00175 double Am = HeartConfig::Instance()->GetSurfaceAreaToVolumeRatio();
00176 double Cm = HeartConfig::Instance()->GetCapacitance();
00177
00178 for (DistributedVector::Iterator index = dist_vec_matrix_based.Begin();
00179 index != dist_vec_matrix_based.End();
00180 ++index)
00181 {
00182 if (this->mpMesh->GetNode(index.Global)->GetRegion() != HeartRegionCode::BATH)
00183 {
00184 double V = distributed_current_solution_vm[index];
00185 double F = - Am*this->mpBidomainPde->rGetIionicCacheReplicated()[index.Global]
00186 - this->mpBidomainPde->rGetIntracellularStimulusCacheReplicated()[index.Global];
00187
00188 dist_vec_matrix_based_vm[index] = Am*Cm*V*this->mDtInverse + F;
00189 }
00190 else
00191 {
00192 dist_vec_matrix_based_vm[index] = 0.0;
00193 }
00194
00195 dist_vec_matrix_based_phie[index] = 0.0;
00196 }
00197
00198 dist_vec_matrix_based.Restore();
00199
00200 VecAssemblyBegin(this->mVectorForMatrixBasedRhsAssembly);
00201 VecAssemblyEnd(this->mVectorForMatrixBasedRhsAssembly);
00202 }
00203
00204
00206
00208
00209 template class BidomainWithBathMatrixBasedAssembler<1,1>;
00210 template class BidomainWithBathMatrixBasedAssembler<2,2>;
00211 template class BidomainWithBathMatrixBasedAssembler<3,3>;
00212
00213 template class BidomainWithBathRhsMatrixAssembler<1>;
00214 template class BidomainWithBathRhsMatrixAssembler<2>;
00215 template class BidomainWithBathRhsMatrixAssembler<3>;