AxisymmetricConductivityTensors.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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 template<unsigned SPACE_DIM>
00035 void AxisymmetricConductivityTensors<SPACE_DIM>::ReadOrientationVectorFromFile (c_vector<double,SPACE_DIM>& orientVector)
00036 {
00037     std::vector<double> tokens;
00038 
00039     unsigned num_elems = this->GetTokensAtNextLine(tokens);
00040 
00041     if (num_elems != 3u)
00042     {
00043         this->CloseFibreOrientationFile();
00044         EXCEPTION("Axisymmetric media defined. Fibre orientation file should contain 3 values per element");
00045     }
00046 
00047     for (unsigned i=0; i<SPACE_DIM; i++)
00048     {
00049         orientVector[i] = tokens[i];
00050     }
00051 }
00052 
00053 template<unsigned SPACE_DIM>
00054 AxisymmetricConductivityTensors<SPACE_DIM>::AxisymmetricConductivityTensors()
00055 {
00056     if (SPACE_DIM != 3)
00057     {
00058         EXCEPTION("Axisymmetric anisotropic conductivity only makes sense in 3D");
00059     }
00060 }
00061 
00062 template<unsigned SPACE_DIM>
00063 void AxisymmetricConductivityTensors<SPACE_DIM>::SetConstantConductivities(c_vector<double, 3> constantConductivities)
00064 {
00065     //assert(SPACE_DIM == 3);//Otherwise constructor would have thrown 
00066     if (constantConductivities[1] != constantConductivities[2])
00067     {
00068         EXCEPTION("Axisymmetric media defined: transversal and normal conductivities should have the same value");
00069     }
00070 
00071     this->mUseNonConstantConductivities = false;
00072     this->mConstantConductivities = constantConductivities;
00073 }
00074 
00075 template<unsigned SPACE_DIM>
00076 void AxisymmetricConductivityTensors<SPACE_DIM>::Init() throw (Exception)
00077 {
00078     if (!this->mUseNonConstantConductivities && !this->mUseFibreOrientation)
00079     {
00080         // Constant tensor for every element
00081         c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
00082 
00083         for (unsigned dim=0; dim<SPACE_DIM; dim++)
00084         {
00085             assert(this->mConstantConductivities(dim) != DBL_MAX);
00086             conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
00087         }
00088         this->mTensors.push_back(conductivity_matrix);
00089     }
00090     else
00091     {
00092         c_vector<double,SPACE_DIM> fibre_vector((zero_vector<double>(SPACE_DIM)));
00093         fibre_vector[0]=1.0;
00094 
00095         if (this->mUseFibreOrientation)
00096         {
00097             this->OpenFibreOrientationFile();
00098             this->mNumElements = this->GetNumElementsFromFile();
00099         }
00100         else
00101         {
00102             this->mNumElements = this->mpNonConstantConductivities->size();
00103         }
00104 
00105         // reserve() allocates all the memory at once, more efficient than relying
00106         // on the automatic reallocation scheme.
00107         this->mTensors.reserve(this->mNumElements);
00108         
00109         c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
00110 
00111         for (unsigned element_index=0; element_index<this->mNumElements; element_index++)
00112         {
00113             /*
00114              *  For every element of the mesh we compute its tensor like (from
00115              * "Laminar Arrangement of VentricularMyocites Influences Electrical
00116              * Behavior of the Heart", Darren et al. 2007):
00117              *
00118              *                         [g_f  0   0 ] [a_f']
00119              *  tensor = [a_f a_l a_n] [ 0  g_l  0 ] [a_l']
00120              *                         [ 0   0  g_n] [a_n']
00121              *
00122              *              [x_i]
00123              *  where a_i = [y_i], i={f,l,n} are read from the fibre orientation file and
00124              *              [z_i]
00125              *
00126              *  g_f = fibre/longitudinal conductivity (constant or element specific)
00127              *  g_l = laminar/transverse conductivity (constant or element specific)
00128              *  g_n = normal conductivity (constant or element specific)
00129              *
00130              * 
00131              *  For axisymmetric anisotropic media (g_l = g_n) we can simplify previous expression to
00132              * 
00133              * 
00134              *  tensor = g_l * I + (g_f - g_l) * a_f * a_f' 
00135              * 
00136              */
00137 
00138             if (this->mUseNonConstantConductivities)
00139             {
00140                 for (unsigned dim=0; dim<SPACE_DIM; dim++)
00141                 {
00142                     conductivity_matrix(dim,dim) = (*this->mpNonConstantConductivities)[element_index][dim];
00143                 }
00144             }
00145             else
00146             {
00147                 for (unsigned dim=0; dim<SPACE_DIM; dim++)
00148                 {
00149                     assert(this->mConstantConductivities(dim) != DBL_MAX);
00150                     conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
00151                 }                                       
00152             }
00153             
00154 
00155             if (this->mUseFibreOrientation)
00156             {
00157                 ReadOrientationVectorFromFile(fibre_vector);
00158             }
00159 
00160             this->mTensors.push_back( conductivity_matrix(1,1) * identity_matrix<double>(SPACE_DIM) +
00161                                       (conductivity_matrix(0,0) - conductivity_matrix(1,1)) * outer_prod(fibre_vector,fibre_vector));
00162         }
00163 
00164         if (this->mUseFibreOrientation)
00165         {
00166             this->CloseFibreOrientationFile();
00167         }
00168     }
00169 
00170     this->mInitialised = true;
00171 }
00172 
00173 
00174 
00176 // Explicit instantiation
00178 
00179 // only makes sense in 3d, but we need the other to compile
00180 // AbstractCardiacPde and BidomainPde.
00181 template class AxisymmetricConductivityTensors<1>;
00182 template class AxisymmetricConductivityTensors<2>;
00183 template class AxisymmetricConductivityTensors<3>;

Generated on Wed Mar 18 12:51:52 2009 for Chaste by  doxygen 1.5.5