Chaste Commit::baa90ac2819b962188b7562f2326be23c47859a7
AxisymmetricConductivityTensors.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 <vector>
37#include "UblasIncludes.hpp"
38#include "AxisymmetricConductivityTensors.hpp"
39#include "Exception.hpp"
40
41
42template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
44{
45 if (SPACE_DIM != 3)
46 {
47 EXCEPTION("Axisymmetric anisotropic conductivity only makes sense in 3D");
48 }
49}
50
51template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
53{
54 //assert(SPACE_DIM == 3);//Otherwise constructor would have thrown
55 if (constantConductivities[1] != constantConductivities[2])
56 {
57 EXCEPTION("Axisymmetric media defined: transversal and normal conductivities should have the same value");
58 }
59
60 this->mUseNonConstantConductivities = false;
61 this->mConstantConductivities = constantConductivities;
62}
63
64template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
66{
67 if (SPACE_DIM != 3)
68 {
69 EXCEPTION("Axisymmetric anisotropic conductivity only makes sense in 3D"); // LCOV_EXCL_LINE
70 }
71 this->mpMesh = pMesh;
72
73 if (!this->mUseNonConstantConductivities && !this->mUseFibreOrientation)
74 {
75 // Constant tensor for every element
76 c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
77
78 for (unsigned dim=0; dim<SPACE_DIM; dim++)
79 {
80 assert(this->mConstantConductivities(dim) != DBL_MAX);
81 conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
82 }
83 this->mTensors.push_back(conductivity_matrix);
84 }
85 else
86 {
87 c_vector<double,SPACE_DIM> fibre_vector((zero_vector<double>(SPACE_DIM)));
88 fibre_vector[0]=1.0;
89
90 if (this->mUseFibreOrientation)
91 {
92 // open file
93 this->mFileReader.reset(new FibreReader<SPACE_DIM>(this->mFibreOrientationFile, AXISYM));
94 if (this->mFileReader->GetNumLinesOfData() != this->mpMesh->GetNumElements())
95 {
96 EXCEPTION("The size of the fibre file does not match the number of elements in the mesh");
97 }
98 }
99
100 if (this->mUseNonConstantConductivities)
101 {
102 if (this->mpNonConstantConductivities->size() != this->mpMesh->GetNumLocalElements())
103 {
104 EXCEPTION("The size of the conductivities vector does not match the number of elements in the mesh");
105 }
106 }
107
108 // reserve() allocates all the memory at once, more efficient than relying
109 // on the automatic reallocation scheme.
110 this->mTensors.reserve(this->mpMesh->GetNumLocalElements());
111
112 c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
113
114 unsigned local_element_index = 0;
115
116 for (typename AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>::ElementIterator it = this->mpMesh->GetElementIteratorBegin();
117 it != this->mpMesh->GetElementIteratorEnd();
118 ++it)
119 {
120 /*
121 * For every element of the mesh we compute its tensor like (from
122 * "Laminar Arrangement of VentricularMyocites Influences Electrical
123 * Behavior of the Heart", Darren et al. 2007):
124 *
125 * [g_f 0 0 ] [a_f']
126 * tensor = [a_f a_l a_n] [ 0 g_l 0 ] [a_l']
127 * [ 0 0 g_n] [a_n']
128 *
129 * [x_i]
130 * where a_i = [y_i], i={f,l,n} are read from the fibre orientation file and
131 * [z_i]
132 *
133 * g_f = fibre/longitudinal conductivity (constant or element specific)
134 * g_l = laminar/transverse conductivity (constant or element specific)
135 * g_n = normal conductivity (constant or element specific)
136 *
137 *
138 * For axisymmetric anisotropic media (g_l = g_n) we can simplify previous expression to
139 *
140 *
141 * tensor = g_l * I + (g_f - g_l) * a_f * a_f'
142 *
143 */
144
145 if (this->mUseNonConstantConductivities)
146 {
147 for (unsigned dim=0; dim<SPACE_DIM; dim++)
148 {
149 conductivity_matrix(dim,dim) = (*this->mpNonConstantConductivities)[local_element_index][dim];
150 }
151 }
152 else
153 {
154 for (unsigned dim=0; dim<SPACE_DIM; dim++)
155 {
156 assert(this->mConstantConductivities(dim) != DBL_MAX);
157 conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
158 }
159 }
160
161 if (this->mUseFibreOrientation)
162 {
163 unsigned current_fibre_global_index = it->GetIndex();
164 this->mFileReader->GetFibreVector(current_fibre_global_index, fibre_vector);
165 }
166
167 this->mTensors.push_back( conductivity_matrix(1,1) * identity_matrix<double>(SPACE_DIM) +
168 (conductivity_matrix(0,0) - conductivity_matrix(1,1)) * outer_prod(fibre_vector,fibre_vector));
169
170 local_element_index++;
171 }
172
173 assert(this->mTensors.size() == this->mpMesh->GetNumLocalElements());
174 assert(this->mTensors.size() == local_element_index);
175
176 if (this->mUseFibreOrientation)
177 {
178 // close fibre file
179 this->mFileReader.reset();
180 }
181 }
182
183 this->mInitialised = true;
184}
185
186// Explicit instantiation
187
188// only makes sense for 3d elements in 3d, but we need the other to compile
189// AbstractCardiacTissue and BidomainTissue.
#define EXCEPTION(message)
void SetConstantConductivities(c_vector< double, 3 > constantConductivities)
void Init(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh)