Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
AbstractConductivityTensors.cpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#include "AbstractConductivityTensors.hpp"
37#include "Exception.hpp"
38#include <sstream>
39
40template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
42 : mpMesh(NULL),
43 mUseNonConstantConductivities(false),
44 mUseFibreOrientation(false),
45 mInitialised(false)
46{
47 double init_data[]={DBL_MAX, DBL_MAX, DBL_MAX};
48
49 for (unsigned dim=0; dim<SPACE_DIM; dim++)
50 {
51 mConstantConductivities[dim] = init_data[dim];
52 }
53}
54
55template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
57{
58}
59
60template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
62{
63 mUseFibreOrientation = true;
64 mFibreOrientationFile = rFibreOrientationFile;
65}
66
67template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
69{
70 if (SPACE_DIM != 1)
71 {
72 EXCEPTION("Wrong number of conductivities provided");
73 }
74
75 mUseNonConstantConductivities = false;
76 mConstantConductivities = constantConductivities;
77}
78
79template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
81{
82 if (SPACE_DIM != 2)
83 {
84 EXCEPTION("Wrong number of conductivities provided");
85 }
86
87 mUseNonConstantConductivities = false;
88 mConstantConductivities = constantConductivities;
89}
90
91template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
93{
94 if (SPACE_DIM != 3)
95 {
96 EXCEPTION("Wrong number of conductivities provided");
97 }
98
99 mUseNonConstantConductivities = false;
100 mConstantConductivities = constantConductivities;
101}
102
103template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
104void AbstractConductivityTensors<ELEMENT_DIM,SPACE_DIM>::SetNonConstantConductivities(std::vector<c_vector<double, SPACE_DIM> >* pNonConstantConductivities)
105{
106 mUseNonConstantConductivities = true;
107 mpNonConstantConductivities = pNonConstantConductivities;
108}
110template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
111c_matrix<double,SPACE_DIM,SPACE_DIM>& AbstractConductivityTensors<ELEMENT_DIM,SPACE_DIM>::operator[](const unsigned global_index)
112{
113 assert(mInitialised);
114 if (global_index >= this->mpMesh->GetNumElements() )
115 {
116 EXCEPTION("Conductivity tensor requested for element with global_index=" << global_index << ", but there are only " << this->mpMesh->GetNumElements() << " elements in the mesh.");
117 }
119 if (!mUseNonConstantConductivities && !mUseFibreOrientation)
120 {
121 return mTensors[0];
122 }
123 else
124 {
125 unsigned local_index = mpMesh->SolveElementMapping(global_index); //This will throw if we don't own the element
126 return mTensors[local_index];
127 }
128}
129
130// Explicit instantiation
#define EXCEPTION(message)
Forward declaration which is going to be used for friendship.
void SetNonConstantConductivities(std::vector< c_vector< double, SPACE_DIM > > *pNonConstantConductivities)
c_matrix< double, SPACE_DIM, SPACE_DIM > & operator[](const unsigned global_index)
void SetConstantConductivities(c_vector< double, 1 > constantConductivities)
void SetFibreOrientationFile(const FileFinder &rFibreOrientationFile)