AxisymmetricConductivityTensors.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #include <vector>
00030 #include "UblasIncludes.hpp"
00031 #include "AxisymmetricConductivityTensors.hpp"
00032 #include "Exception.hpp"
00033 
00034 
00035 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00036 AxisymmetricConductivityTensors<ELEMENT_DIM, SPACE_DIM>::AxisymmetricConductivityTensors()
00037 {
00038     if (SPACE_DIM != 3)
00039     {
00040         EXCEPTION("Axisymmetric anisotropic conductivity only makes sense in 3D");
00041     }
00042 }
00043 
00044 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00045 void AxisymmetricConductivityTensors<ELEMENT_DIM, SPACE_DIM>::SetConstantConductivities(c_vector<double, 3> constantConductivities)
00046 {
00047     //assert(SPACE_DIM == 3);//Otherwise constructor would have thrown
00048     if (constantConductivities[1] != constantConductivities[2])
00049     {
00050         EXCEPTION("Axisymmetric media defined: transversal and normal conductivities should have the same value");
00051     }
00052 
00053     this->mUseNonConstantConductivities = false;
00054     this->mConstantConductivities = constantConductivities;
00055 }
00056 
00057 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00058 void AxisymmetricConductivityTensors<ELEMENT_DIM, SPACE_DIM>::Init(AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> *pMesh) throw (Exception)
00059 {
00060     this->mpMesh = pMesh;
00061 
00062     if (!this->mUseNonConstantConductivities && !this->mUseFibreOrientation)
00063     {
00064         // Constant tensor for every element
00065         c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
00066 
00067         for (unsigned dim=0; dim<SPACE_DIM; dim++)
00068         {
00069             assert(this->mConstantConductivities(dim) != DBL_MAX);
00070             conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
00071         }
00072         this->mTensors.push_back(conductivity_matrix);
00073     }
00074     else
00075     {
00076         c_vector<double,SPACE_DIM> fibre_vector((zero_vector<double>(SPACE_DIM)));
00077         fibre_vector[0]=1.0;
00078 
00079         if (this->mUseFibreOrientation)
00080         {
00081             // open file
00082             this->mFileReader.reset(new FibreReader<SPACE_DIM>(this->mFibreOrientationFile, AXISYM));
00083             if(this->mFileReader->GetNumLinesOfData() != this->mpMesh->GetNumElements())
00084             {
00085                 EXCEPTION("The size of the fibre file does not match the number of elements in the mesh");
00086             }
00087         }
00088 
00089         if (this->mUseNonConstantConductivities)
00090         {
00091             if(this->mpNonConstantConductivities->size() != this->mpMesh->GetNumLocalElements())
00092             {
00093                 EXCEPTION("The size of the conductivities vector does not match the number of elements in the mesh");
00094             }
00095         }
00096 
00097         // reserve() allocates all the memory at once, more efficient than relying
00098         // on the automatic reallocation scheme.
00099         this->mTensors.reserve(this->mpMesh->GetNumLocalElements());
00100 
00101         c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
00102 
00103        unsigned local_element_index = 0;
00104 
00105        for (typename AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>::ElementIterator it = this->mpMesh->GetElementIteratorBegin();
00106              it != this->mpMesh->GetElementIteratorEnd();
00107              ++it)
00108         {
00109             /*
00110              *  For every element of the mesh we compute its tensor like (from
00111              * "Laminar Arrangement of VentricularMyocites Influences Electrical
00112              * Behavior of the Heart", Darren et al. 2007):
00113              *
00114              *                         [g_f  0   0 ] [a_f']
00115              *  tensor = [a_f a_l a_n] [ 0  g_l  0 ] [a_l']
00116              *                         [ 0   0  g_n] [a_n']
00117              *
00118              *              [x_i]
00119              *  where a_i = [y_i], i={f,l,n} are read from the fibre orientation file and
00120              *              [z_i]
00121              *
00122              *  g_f = fibre/longitudinal conductivity (constant or element specific)
00123              *  g_l = laminar/transverse conductivity (constant or element specific)
00124              *  g_n = normal conductivity (constant or element specific)
00125              *
00126              *
00127              *  For axisymmetric anisotropic media (g_l = g_n) we can simplify previous expression to
00128              *
00129              *
00130              *  tensor = g_l * I + (g_f - g_l) * a_f * a_f'
00131              *
00132              */
00133 
00134             if (this->mUseNonConstantConductivities)
00135             {
00136                 for (unsigned dim=0; dim<SPACE_DIM; dim++)
00137                 {
00138                     conductivity_matrix(dim,dim) = (*this->mpNonConstantConductivities)[local_element_index][dim];
00139                 }
00140             }
00141             else
00142             {
00143                 for (unsigned dim=0; dim<SPACE_DIM; dim++)
00144                 {
00145                     assert(this->mConstantConductivities(dim) != DBL_MAX);
00146                     conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
00147                 }
00148             }
00149 
00150 
00151             if (this->mUseFibreOrientation)
00152             {
00153                 this->mFileReader->GetNextFibreVector(fibre_vector);
00154             }
00155 
00156             this->mTensors.push_back( conductivity_matrix(1,1) * identity_matrix<double>(SPACE_DIM) +
00157                                       (conductivity_matrix(0,0) - conductivity_matrix(1,1)) * outer_prod(fibre_vector,fibre_vector));
00158                                       
00159             local_element_index++;
00160         }
00161 
00162         assert(this->mTensors.size() == this->mpMesh->GetNumLocalElements());
00163         assert(this->mTensors.size() == local_element_index);
00164 
00165         if (this->mUseFibreOrientation)
00166         {
00167             // close fibre file
00168             this->mFileReader.reset();
00169         }
00170     }
00171 
00172     this->mInitialised = true;
00173 }
00174 
00175 
00176 
00178 // Explicit instantiation
00180 
00181 // only makes sense for 3d elements in 3d, but we need the other to compile
00182 // AbstractCardiacTissue and BidomainTissue.
00183 template class AxisymmetricConductivityTensors<1,1>;
00184 template class AxisymmetricConductivityTensors<1,2>;
00185 template class AxisymmetricConductivityTensors<1,3>;
00186 template class AxisymmetricConductivityTensors<2,2>;
00187 template class AxisymmetricConductivityTensors<2,3>;
00188 template class AxisymmetricConductivityTensors<3,3>;

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5