Chaste Release::3.1
ExtendedBidomainAssembler.cpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #include "ExtendedBidomainAssembler.hpp"
00037 #include <boost/numeric/ublas/vector_proxy.hpp>
00038 
00039 #include "Exception.hpp"
00040 #include "DistributedVector.hpp"
00041 #include "PdeSimulationTime.hpp"
00042 #include "ConstBoundaryCondition.hpp"
00043 
00044 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00045 c_matrix<double,3*(ELEMENT_DIM+1),3*(ELEMENT_DIM+1)>
00046     ExtendedBidomainAssembler<ELEMENT_DIM,SPACE_DIM>::ComputeMatrixTerm(
00047             c_vector<double, ELEMENT_DIM+1> &rPhi,
00048             c_matrix<double, SPACE_DIM, ELEMENT_DIM+1> &rGradPhi,
00049             ChastePoint<SPACE_DIM> &rX,
00050             c_vector<double,3> &rU,
00051             c_matrix<double, 3, SPACE_DIM> &rGradU /* not used */,
00052             Element<ELEMENT_DIM,SPACE_DIM>* pElement)
00053 {
00054     // get bidomain parameters
00055     double Am1 = mpExtendedBidomainTissue->GetAmFirstCell();
00056     double Am2 = mpExtendedBidomainTissue->GetAmSecondCell();
00057     double Cm1 = mpExtendedBidomainTissue->GetCmFirstCell();
00058     double Cm2 = mpExtendedBidomainTissue->GetCmSecondCell();
00059 
00060     const c_matrix<double, SPACE_DIM, SPACE_DIM>& sigma_i_first_cell = mpExtendedBidomainTissue->rGetIntracellularConductivityTensor(pElement->GetIndex());
00061     const c_matrix<double, SPACE_DIM, SPACE_DIM>& sigma_i_second_cell = mpExtendedBidomainTissue->rGetIntracellularConductivityTensorSecondCell(pElement->GetIndex());
00062     const c_matrix<double, SPACE_DIM, SPACE_DIM>& sigma_e = mpExtendedBidomainTissue->rGetExtracellularConductivityTensor(pElement->GetIndex());
00063 
00064     double delta_t = PdeSimulationTime::GetPdeTimeStep();
00065 
00066     c_matrix<double, SPACE_DIM, ELEMENT_DIM+1> temp_1 = prod(sigma_i_first_cell, rGradPhi);
00067     c_matrix<double, ELEMENT_DIM+1, ELEMENT_DIM+1> grad_phi_sigma_i_first_cell_grad_phi =
00068         prod(trans(rGradPhi), temp_1);
00069 
00070     c_matrix<double, SPACE_DIM, ELEMENT_DIM+1> temp_2 = prod(sigma_i_second_cell, rGradPhi);
00071     c_matrix<double, ELEMENT_DIM+1, ELEMENT_DIM+1> grad_phi_sigma_i_second_cell_grad_phi =
00072         prod(trans(rGradPhi), temp_2);
00073 
00074     c_matrix<double, ELEMENT_DIM+1, ELEMENT_DIM+1> basis_outer_prod =
00075         outer_prod(rPhi, rPhi);
00076 
00077     c_matrix<double, SPACE_DIM, ELEMENT_DIM+1> temp_ext = prod(sigma_e, rGradPhi);
00078     c_matrix<double, ELEMENT_DIM+1, ELEMENT_DIM+1> grad_phi_sigma_e_grad_phi =
00079         prod(trans(rGradPhi), temp_ext);
00080 
00081 
00082     c_matrix<double,3*(ELEMENT_DIM+1),3*(ELEMENT_DIM+1)> ret;
00083 
00084     // first equation, first unknown
00085     matrix_slice<c_matrix<double, 3*ELEMENT_DIM+3, 3*ELEMENT_DIM+3> >
00086     slice100(ret, slice (0, 3, ELEMENT_DIM+1), slice (0, 3, ELEMENT_DIM+1));
00087     slice100 = (Am1*Cm1/delta_t)*basis_outer_prod + grad_phi_sigma_i_first_cell_grad_phi;
00088 
00089     // first equation, second unknown
00090     matrix_slice<c_matrix<double, 3*ELEMENT_DIM+3, 3*ELEMENT_DIM+3> >
00091     slice200(ret, slice (0, 3, ELEMENT_DIM+1), slice (1, 3, ELEMENT_DIM+1));
00092     slice200 = zero_matrix<double>(ELEMENT_DIM+1, ELEMENT_DIM+1);
00093 
00094     // first equation, third unknown
00095     matrix_slice<c_matrix<double, 3*ELEMENT_DIM+3, 3*ELEMENT_DIM+3> >
00096     slice300(ret, slice (0, 3, ELEMENT_DIM+1), slice (2, 3, ELEMENT_DIM+1));
00097     slice300 = - (Am1*Cm1/delta_t)*basis_outer_prod;
00098 
00099     // second equation, first unknown
00100     matrix_slice<c_matrix<double, 3*ELEMENT_DIM+3, 3*ELEMENT_DIM+3> >
00101     slice010(ret, slice (1, 3, ELEMENT_DIM+1), slice (0, 3, ELEMENT_DIM+1));
00102     slice010 = zero_matrix<double>(ELEMENT_DIM+1, ELEMENT_DIM+1);
00103 
00104     // second equation, second unknown
00105     matrix_slice<c_matrix<double, 3*ELEMENT_DIM+3, 3*ELEMENT_DIM+3> >
00106     slice020(ret, slice (1, 3, ELEMENT_DIM+1), slice (1, 3, ELEMENT_DIM+1));
00107     slice020 = (Am2*Cm2/delta_t)*basis_outer_prod + grad_phi_sigma_i_second_cell_grad_phi;
00108 
00109     // second equation, third unknown
00110     matrix_slice<c_matrix<double, 3*ELEMENT_DIM+3, 3*ELEMENT_DIM+3> >
00111     slice030(ret, slice (1, 3, ELEMENT_DIM+1), slice (2, 3, ELEMENT_DIM+1));
00112     slice030 = - (Am2*Cm2/delta_t)*basis_outer_prod;
00113 
00114     // third equation, first unknown
00115     matrix_slice<c_matrix<double, 3*ELEMENT_DIM+3, 3*ELEMENT_DIM+3> >
00116     slice001(ret, slice (2, 3, ELEMENT_DIM+1), slice (0, 3, ELEMENT_DIM+1));
00117     slice001 =   - grad_phi_sigma_i_first_cell_grad_phi;
00118 
00119     // third equation, second unknown
00120     matrix_slice<c_matrix<double, 3*ELEMENT_DIM+3, 3*ELEMENT_DIM+3> >
00121     slice002(ret, slice (2, 3, ELEMENT_DIM+1), slice (1, 3, ELEMENT_DIM+1));
00122     slice002 =  - grad_phi_sigma_i_second_cell_grad_phi;
00123 
00124     // third equation, third unknown
00125     matrix_slice<c_matrix<double, 3*ELEMENT_DIM+3, 3*ELEMENT_DIM+3> >
00126     slice003(ret, slice (2, 3, ELEMENT_DIM+1), slice (2, 3, ELEMENT_DIM+1));
00127     slice003 =  - grad_phi_sigma_e_grad_phi;
00128 
00129     return ret;
00130 }
00131 
00132 
00133 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00134 ExtendedBidomainAssembler<ELEMENT_DIM,SPACE_DIM>::ExtendedBidomainAssembler(
00135                                 AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>* pMesh,
00136                                 ExtendedBidomainTissue<SPACE_DIM>* pTissue,
00137                                 unsigned numQuadPoints)
00138     : AbstractCardiacFeVolumeIntegralAssembler<ELEMENT_DIM,SPACE_DIM,3,true,true,NORMAL>(pMesh,pTissue,numQuadPoints),
00139               mpExtendedBidomainTissue(pTissue)
00140 {
00141     assert(pTissue != NULL);
00142     mpConfig = HeartConfig::Instance();
00143 }
00144 
00145 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00146 ExtendedBidomainAssembler<ELEMENT_DIM,SPACE_DIM>::~ExtendedBidomainAssembler()
00147 {
00148 }
00149 
00151 // Explicit instantiation
00153 
00154 template class ExtendedBidomainAssembler<1,1>;
00155 template class ExtendedBidomainAssembler<2,2>;
00156 template class ExtendedBidomainAssembler<3,3>;