OrthotropicConductivityTensors.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 "OrthotropicConductivityTensors.hpp"
00030 #include "Exception.hpp"
00031 
00032 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00033 void OrthotropicConductivityTensors<ELEMENT_DIM, SPACE_DIM>::Init(AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> *pMesh) throw (Exception)
00034 {
00035     this->mpMesh = pMesh;
00036 
00037     if (!this->mUseNonConstantConductivities && !this->mUseFibreOrientation)
00038     {
00039         // Constant tensor for every element
00040         c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
00041 
00042         for (unsigned dim=0; dim<SPACE_DIM; dim++)
00043         {
00044             assert(this->mConstantConductivities(dim) != DBL_MAX);
00045             conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
00046         }
00047 
00048         this->mTensors.push_back(conductivity_matrix);
00049     }
00050     else
00051     {
00052         c_matrix<double,SPACE_DIM,SPACE_DIM> orientation_matrix((identity_matrix<double>(SPACE_DIM)));
00053 
00054         if (this->mUseFibreOrientation)
00055         {
00056             // open file
00057             this->mFileReader.reset(new FibreReader<SPACE_DIM>(this->mFibreOrientationFile, ORTHO));
00058             if(this->mFileReader->GetNumLinesOfData() != this->mpMesh->GetNumElements())
00059             {
00060                 EXCEPTION("The size of the fibre file does not match the number of elements in the mesh");
00061             }
00062         }
00063  
00064         if (this->mUseNonConstantConductivities)
00065         {
00066             if(this->mpNonConstantConductivities->size() != this->mpMesh->GetNumLocalElements())
00067             {
00068                 EXCEPTION("The size of the conductivities vector does not match the number of elements in the mesh");
00069             }
00070         }
00071 
00072         // reserve() allocates all the memory at once, more efficient than relying
00073         // on the automatic reallocation scheme.
00074         this->mTensors.reserve(this->mpMesh->GetNumLocalElements());
00075 
00076         c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
00077 
00078         unsigned local_element_index = 0;
00079         for (typename AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>::ElementIterator it = this->mpMesh->GetElementIteratorBegin();
00080              it != this->mpMesh->GetElementIteratorEnd();
00081              ++it)
00082         {
00083             /*
00084              *  For every element of the mesh we compute its tensor like (from
00085              * "Laminar Arrangement of VentricularMyocites Influences Electrical
00086              * Behavior of the Heart", Darren et al. 2007):
00087              *
00088              *                         [g_f  0   0 ] [a_f']
00089              *  tensor = [a_f a_l a_n] [ 0  g_l  0 ] [a_l']
00090              *                         [ 0   0  g_n] [a_n']
00091              *
00092              *              [x_i]
00093              *  where a_i = [y_i], i={f,l,n} are read from the fibre orientation file and
00094              *              [z_i]
00095              *
00096              *  g_f = fibre/longitudinal conductivity (constant or element specific)
00097              *  g_l = laminar/transverse conductivity (constant or element specific)
00098              *  g_n = normal conductivity (constant or element specific)
00099              *
00100              */
00101             if (this->mUseNonConstantConductivities)
00102             {
00103                 for (unsigned dim=0; dim<SPACE_DIM; dim++)
00104                 {
00105                     conductivity_matrix(dim,dim) = (*this->mpNonConstantConductivities)[local_element_index][dim];
00106                 }
00107             }
00108             else
00109             {
00110                 for (unsigned dim=0; dim<SPACE_DIM; dim++)
00111                 {
00112                     assert(this->mConstantConductivities(dim) != DBL_MAX);
00113                     conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
00114                 }
00115             }
00116 
00117             if (this->mUseFibreOrientation)
00118             {
00119                 this->mFileReader->GetNextFibreSheetAndNormalMatrix(orientation_matrix);
00120             }
00121 
00122             c_matrix<double,SPACE_DIM,SPACE_DIM> temp;
00123             noalias(temp) = prod(orientation_matrix, conductivity_matrix);
00124             this->mTensors.push_back( prod(temp, trans(orientation_matrix) ) );
00125             
00126             local_element_index++;
00127         }
00128         assert(this->mTensors.size() == this->mpMesh->GetNumLocalElements());
00129         assert(this->mTensors.size() == local_element_index);
00130 
00131         if (this->mUseFibreOrientation)
00132         {
00133             // close fibre file
00134             this->mFileReader.reset();
00135         }
00136     }
00137 
00138     this->mInitialised = true;
00139 }
00140 
00141 
00143 // Explicit instantiation
00145 
00146 template class OrthotropicConductivityTensors<1,1>;
00147 template class OrthotropicConductivityTensors<1,2>;
00148 template class OrthotropicConductivityTensors<1,3>;
00149 template class OrthotropicConductivityTensors<2,2>;
00150 template class OrthotropicConductivityTensors<2,3>;
00151 template class OrthotropicConductivityTensors<3,3>;

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