AbstractConductivityTensors.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 "AbstractConductivityTensors.hpp"
00030 #include "Exception.hpp"
00031 #include <sstream>
00032 
00033 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00034 AbstractConductivityTensors<ELEMENT_DIM,SPACE_DIM>::AbstractConductivityTensors()
00035     : mpMesh(NULL),
00036       mUseNonConstantConductivities(false),
00037       mUseFibreOrientation(false),
00038       mInitialised(false)
00039 {
00040     double init_data[]={DBL_MAX, DBL_MAX, DBL_MAX};
00041 
00042     for (unsigned dim=0; dim<SPACE_DIM; dim++)
00043     {
00044          mConstantConductivities[dim] = init_data[dim];
00045     }
00046 }
00047 
00048 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00049 AbstractConductivityTensors<ELEMENT_DIM,SPACE_DIM>::~AbstractConductivityTensors()
00050 {
00051 }
00052 
00053 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00054 void AbstractConductivityTensors<ELEMENT_DIM,SPACE_DIM>::SetFibreOrientationFile(const FileFinder &rFibreOrientationFile)
00055 {
00056     mUseFibreOrientation = true;
00057     mFibreOrientationFile = rFibreOrientationFile;
00058 }
00059 
00060 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00061 void AbstractConductivityTensors<ELEMENT_DIM,SPACE_DIM>::SetConstantConductivities(c_vector<double, 1> constantConductivities)
00062 {
00063     if (SPACE_DIM != 1)
00064     {
00065         EXCEPTION("Wrong number of conductivities provided");
00066     }
00067 
00068     mUseNonConstantConductivities = false;
00069     mConstantConductivities = constantConductivities;
00070 }
00071 
00072 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00073 void AbstractConductivityTensors<ELEMENT_DIM,SPACE_DIM>::SetConstantConductivities(c_vector<double, 2> constantConductivities)
00074 {
00075     if (SPACE_DIM != 2)
00076     {
00077         EXCEPTION("Wrong number of conductivities provided");
00078     }
00079 
00080     mUseNonConstantConductivities = false;
00081     mConstantConductivities = constantConductivities;
00082 }
00083 
00084 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00085 void AbstractConductivityTensors<ELEMENT_DIM,SPACE_DIM>::SetConstantConductivities(c_vector<double, 3> constantConductivities)
00086 {
00087     if (SPACE_DIM != 3)
00088     {
00089         EXCEPTION("Wrong number of conductivities provided");
00090     }
00091 
00092     mUseNonConstantConductivities = false;
00093     mConstantConductivities = constantConductivities;
00094 }
00095 
00096 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00097 void AbstractConductivityTensors<ELEMENT_DIM,SPACE_DIM>::SetNonConstantConductivities(std::vector<c_vector<double, SPACE_DIM> >* pNonConstantConductivities)
00098 {
00099     mUseNonConstantConductivities = true;
00100     mpNonConstantConductivities = pNonConstantConductivities;
00101 }
00102 
00103 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00104 c_matrix<double,SPACE_DIM,SPACE_DIM>& AbstractConductivityTensors<ELEMENT_DIM,SPACE_DIM>::operator[](const unsigned global_index)
00105 {
00106     assert(mInitialised);
00107 
00108     if (!mUseNonConstantConductivities && !mUseFibreOrientation)
00109     {
00110         return mTensors[0];
00111     }
00112     else
00113     {
00114         assert(global_index < this->mpMesh->GetNumElements());
00115         unsigned local_index = mpMesh->SolveElementMapping(global_index); //This will throw if we don't own the element
00116         return mTensors[local_index];
00117     }
00118 }
00119 
00121 // Explicit instantiation
00123 
00124 template class AbstractConductivityTensors<1,1>;
00125 template class AbstractConductivityTensors<1,2>;
00126 template class AbstractConductivityTensors<1,3>;
00127 template class AbstractConductivityTensors<2,2>;
00128 template class AbstractConductivityTensors<2,3>;
00129 template class AbstractConductivityTensors<3,3>;

Generated on Tue May 31 14:31:41 2011 for Chaste by  doxygen 1.5.5