Chaste Commit::8b5d759ac2eb95e67ae57699734101efccb0a0a9
OrthotropicConductivityTensors.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 "OrthotropicConductivityTensors.hpp"
37#include "Exception.hpp"
38
39template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
41{
42 this->mpMesh = pMesh;
43
44 if (!this->mUseNonConstantConductivities && !this->mUseFibreOrientation)
45 {
46 // Constant tensor for every element
47 c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
48
49 for (unsigned dim=0; dim<SPACE_DIM; dim++)
50 {
51 assert(this->mConstantConductivities(dim) != DBL_MAX);
52 conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
53 }
54
55 this->mTensors.push_back(conductivity_matrix);
56 }
57 else
58 {
59 c_matrix<double,SPACE_DIM,SPACE_DIM> orientation_matrix((identity_matrix<double>(SPACE_DIM)));
60
61 if (this->mUseFibreOrientation)
62 {
63 // open file
64 this->mFileReader.reset(new FibreReader<SPACE_DIM>(this->mFibreOrientationFile, ORTHO));
65 if (this->mFileReader->GetNumLinesOfData() != this->mpMesh->GetNumElements())
66 {
67 EXCEPTION("The size of the fibre file does not match the number of elements in the mesh");
68 }
69 }
70
71 if (this->mUseNonConstantConductivities)
72 {
73 if (this->mpNonConstantConductivities->size() != this->mpMesh->GetNumLocalElements())
74 {
75 EXCEPTION("The size of the conductivities vector does not match the number of elements in the mesh");
76 }
77 }
78
79 // reserve() allocates all the memory at once, more efficient than relying
80 // on the automatic reallocation scheme.
81 this->mTensors.reserve(this->mpMesh->GetNumLocalElements());
82
83 c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
84
85 unsigned local_element_index = 0;
86
87 for (typename AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>::ElementIterator it = this->mpMesh->GetElementIteratorBegin();
88 it != this->mpMesh->GetElementIteratorEnd();
89 ++it)
90 {
91 /*
92 * For every element of the mesh we compute its tensor like (from
93 * "Laminar Arrangement of Ventricular Myocytes Influences Electrical
94 * Behavior of the Heart, DA Hooks et al. 2007):
95 *
96 *
97 * [g_f 0 0 ] [a_f']
98 * tensor = [a_f a_l a_n] [ 0 g_l 0 ] [a_l']
99 * [ 0 0 g_n] [a_n']
100 *
101 * [x_i]
102 * where a_i = [y_i], i={f,l,n} are read from the fibre orientation file and
103 * [z_i]
104 *
105 * g_f = fibre/longitudinal conductivity (constant or element specific)
106 * g_l = laminar/transverse conductivity (constant or element specific)
107 * g_n = normal conductivity (constant or element specific)
108 *
109 */
110 if (this->mUseNonConstantConductivities)
111 {
112 for (unsigned dim=0; dim<SPACE_DIM; dim++)
113 {
114 conductivity_matrix(dim,dim) = (*this->mpNonConstantConductivities)[local_element_index][dim];
115 }
116 }
117 else
118 {
119 for (unsigned dim=0; dim<SPACE_DIM; dim++)
120 {
121 assert(this->mConstantConductivities(dim) != DBL_MAX);
122 conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
123 }
124 }
125
126 if (this->mUseFibreOrientation)
127 {
128 unsigned current_fibre_global_index = it->GetIndex();
129 this->mFileReader->GetFibreSheetAndNormalMatrix(current_fibre_global_index, orientation_matrix);
130 }
131
132 c_matrix<double,SPACE_DIM,SPACE_DIM> temp;
133 noalias(temp) = prod(orientation_matrix, conductivity_matrix);
134 this->mTensors.push_back( prod(temp, trans(orientation_matrix) ) );
135
136 local_element_index++;
137 }
138 assert(this->mTensors.size() == this->mpMesh->GetNumLocalElements());
139 assert(this->mTensors.size() == local_element_index);
140
141 if (this->mUseFibreOrientation)
142 {
143 // Close fibre file
144 this->mFileReader.reset();
145 }
146 }
147
148 this->mInitialised = true;
149}
150
151// Explicit instantiation
#define EXCEPTION(message)
void Init(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh)