Chaste  Release::3.4
AxisymmetricConductivityTensors.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF 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 
42 template<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 
51 template<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 
64 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
66 {
67  this->mpMesh = pMesh;
68 
69  if (!this->mUseNonConstantConductivities && !this->mUseFibreOrientation)
70  {
71  // Constant tensor for every element
72  c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
73 
74  for (unsigned dim=0; dim<SPACE_DIM; dim++)
75  {
76  assert(this->mConstantConductivities(dim) != DBL_MAX);
77  conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
78  }
79  this->mTensors.push_back(conductivity_matrix);
80  }
81  else
82  {
83  c_vector<double,SPACE_DIM> fibre_vector((zero_vector<double>(SPACE_DIM)));
84  fibre_vector[0]=1.0;
85 
86  if (this->mUseFibreOrientation)
87  {
88  // open file
89  this->mFileReader.reset(new FibreReader<SPACE_DIM>(this->mFibreOrientationFile, AXISYM));
90  if(this->mFileReader->GetNumLinesOfData() != this->mpMesh->GetNumElements())
91  {
92  EXCEPTION("The size of the fibre file does not match the number of elements in the mesh");
93  }
94  }
95 
96  if (this->mUseNonConstantConductivities)
97  {
98  if(this->mpNonConstantConductivities->size() != this->mpMesh->GetNumLocalElements())
99  {
100  EXCEPTION("The size of the conductivities vector does not match the number of elements in the mesh");
101  }
102  }
103 
104  // reserve() allocates all the memory at once, more efficient than relying
105  // on the automatic reallocation scheme.
106  this->mTensors.reserve(this->mpMesh->GetNumLocalElements());
107 
108  c_matrix<double, SPACE_DIM, SPACE_DIM> conductivity_matrix(zero_matrix<double>(SPACE_DIM,SPACE_DIM));
109 
110  unsigned local_element_index = 0;
111 
112  for (typename AbstractTetrahedralMesh<ELEMENT_DIM,SPACE_DIM>::ElementIterator it = this->mpMesh->GetElementIteratorBegin();
113  it != this->mpMesh->GetElementIteratorEnd();
114  ++it)
115  {
116  /*
117  * For every element of the mesh we compute its tensor like (from
118  * "Laminar Arrangement of VentricularMyocites Influences Electrical
119  * Behavior of the Heart", Darren et al. 2007):
120  *
121  * [g_f 0 0 ] [a_f']
122  * tensor = [a_f a_l a_n] [ 0 g_l 0 ] [a_l']
123  * [ 0 0 g_n] [a_n']
124  *
125  * [x_i]
126  * where a_i = [y_i], i={f,l,n} are read from the fibre orientation file and
127  * [z_i]
128  *
129  * g_f = fibre/longitudinal conductivity (constant or element specific)
130  * g_l = laminar/transverse conductivity (constant or element specific)
131  * g_n = normal conductivity (constant or element specific)
132  *
133  *
134  * For axisymmetric anisotropic media (g_l = g_n) we can simplify previous expression to
135  *
136  *
137  * tensor = g_l * I + (g_f - g_l) * a_f * a_f'
138  *
139  */
140 
141  if (this->mUseNonConstantConductivities)
142  {
143  for (unsigned dim=0; dim<SPACE_DIM; dim++)
144  {
145  conductivity_matrix(dim,dim) = (*this->mpNonConstantConductivities)[local_element_index][dim];
146  }
147  }
148  else
149  {
150  for (unsigned dim=0; dim<SPACE_DIM; dim++)
151  {
152  assert(this->mConstantConductivities(dim) != DBL_MAX);
153  conductivity_matrix(dim,dim) = this->mConstantConductivities(dim);
154  }
155  }
156 
157  if (this->mUseFibreOrientation)
158  {
159  unsigned current_fibre_global_index = it->GetIndex();
160  this->mFileReader->GetFibreVector(current_fibre_global_index, fibre_vector);
161  }
162 
163  this->mTensors.push_back( conductivity_matrix(1,1) * identity_matrix<double>(SPACE_DIM) +
164  (conductivity_matrix(0,0) - conductivity_matrix(1,1)) * outer_prod(fibre_vector,fibre_vector));
165 
166  local_element_index++;
167  }
168 
169  assert(this->mTensors.size() == this->mpMesh->GetNumLocalElements());
170  assert(this->mTensors.size() == local_element_index);
171 
172  if (this->mUseFibreOrientation)
173  {
174  // close fibre file
175  this->mFileReader.reset();
176  }
177  }
178 
179  this->mInitialised = true;
180 }
181 
182 
183 
185 // 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)
Definition: Exception.hpp:143
void SetConstantConductivities(c_vector< double, 3 > constantConductivities)
void Init(AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM > *pMesh)