Chaste  Release::2018.1
AbstractCorrectionTermAssembler.cpp
1 /*
2 
3 Copyright (c) 2005-2018, 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 "AbstractCorrectionTermAssembler.hpp"
37 #include <typeinfo>
38 
39 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
43  : AbstractCardiacFeVolumeIntegralAssembler<ELEMENT_DIM,SPACE_DIM,PROBLEM_DIM,true,false,CARDIAC>(pMesh,pTissue)
44 {
45  // Work out which elements can do SVI
46  mElementsCanDoSvi.resize(pMesh->GetNumElements(), true);
48  iter != pMesh->GetElementIteratorEnd();
49  ++iter)
50  {
51  Element<ELEMENT_DIM, SPACE_DIM>& r_element = *iter;
52  if (r_element.GetOwnership())
53  {
54  unsigned element_index = r_element.GetIndex();
55  // If bath element, don't try to use SVI
57  {
58  mElementsCanDoSvi[element_index] = false;
59  continue;
60  }
61  // See if the nodes in this element all use the same cell model
62  unsigned node_zero = r_element.GetNodeGlobalIndex(0);
63  AbstractCardiacCellInterface* p_cell_zero = this->mpCardiacTissue->GetCardiacCellOrHaloCell(node_zero);
64  const std::type_info& r_zero_info = typeid(*p_cell_zero);
65  // Check the other nodes match. If they don't, no SVI
66  for (unsigned local_index=1; local_index<r_element.GetNumNodes(); local_index++)
67  {
68  unsigned global_index = r_element.GetNodeGlobalIndex(local_index);
69  AbstractCardiacCellInterface* p_cell = this->mpCardiacTissue->GetCardiacCellOrHaloCell(global_index);
70  const std::type_info& r_info = typeid(*p_cell);
71  if (r_zero_info != r_info)
72  {
73  mElementsCanDoSvi[element_index] = false;
74  break;
75  }
76  }
77  }
78  }
79  // Note: the mStateVariables std::vector is resized if correction will be applied to a given element
80 }
81 
82 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
84 {
85  // reset ionic current, and state variables
86  mIionicInterp = 0;
87  for (unsigned i=0; i<mStateVariablesAtQuadPoint.size(); i++)
88  {
89  mStateVariablesAtQuadPoint[i] = 0;
90  }
91 }
92 
93 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
95  double phiI, const Node<SPACE_DIM>* pNode)
96 {
97  // interpolate ionic current
98  unsigned node_global_index = pNode->GetIndex();
99  mIionicInterp += phiI * this->mpCardiacTissue->rGetIionicCacheReplicated()[ node_global_index ];
100  // and state variables
101  std::vector<double> state_vars = this->mpCardiacTissue->GetCardiacCellOrHaloCell(node_global_index)->GetStdVecStateVariables();
102  for (unsigned i=0; i<mStateVariablesAtQuadPoint.size(); i++)
103  {
104  mStateVariablesAtQuadPoint[i] += phiI * state_vars[i];
105  }
106 }
107 
108 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
110 {
111  // Check that SVI is allowed on this element
112  if (!mElementsCanDoSvi[rElement.GetIndex()])
113  {
114  return false;
115  }
116  double DELTA_IIONIC = 1; // tolerance
117 
118  //The criterion and the correction both need the ionic cache, so we better make sure that it's up-to-date
119  assert(this->mpCardiacTissue->GetDoCacheReplication());
120  ReplicatableVector& r_cache = this->mpCardiacTissue->rGetIionicCacheReplicated();
121 
122  double diionic = fabs(r_cache[rElement.GetNodeGlobalIndex(0)] - r_cache[rElement.GetNodeGlobalIndex(1)]);
123 
124  if (ELEMENT_DIM > 1)
125  {
126  diionic = std::max(diionic, fabs(r_cache[rElement.GetNodeGlobalIndex(0)] - r_cache[rElement.GetNodeGlobalIndex(2)]) );
127  diionic = std::max(diionic, fabs(r_cache[rElement.GetNodeGlobalIndex(1)] - r_cache[rElement.GetNodeGlobalIndex(2)]) );
128  }
129 
130  if (ELEMENT_DIM > 2)
131  {
132  diionic = std::max(diionic, fabs(r_cache[rElement.GetNodeGlobalIndex(0)] - r_cache[rElement.GetNodeGlobalIndex(3)]) );
133  diionic = std::max(diionic, fabs(r_cache[rElement.GetNodeGlobalIndex(1)] - r_cache[rElement.GetNodeGlobalIndex(3)]) );
134  diionic = std::max(diionic, fabs(r_cache[rElement.GetNodeGlobalIndex(2)] - r_cache[rElement.GetNodeGlobalIndex(3)]) );
135  }
136 
137  bool will_assemble = (diionic > DELTA_IIONIC);
138 
139  if (will_assemble)
140  {
141  unsigned any_node = rElement.GetNodeGlobalIndex(0);
142  mStateVariablesAtQuadPoint.resize(this->mpCardiacTissue->GetCardiacCellOrHaloCell(any_node)->GetNumberOfStateVariables() );
143  }
144 
145  return will_assemble;
146 }
147 
148 // Explicit instantiation
ElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
AbstractCorrectionTermAssembler(AbstractTetrahedralMesh< ELEM_DIM, SPACE_DIM > *pMesh, AbstractCardiacTissue< ELEM_DIM, SPACE_DIM > *pTissue)
static bool IsRegionBath(HeartRegionType regionId)
Definition: Node.hpp:58
unsigned GetNodeGlobalIndex(unsigned localIndex) const
virtual unsigned GetNumElements() const
void IncrementInterpolatedQuantities(double phiI, const Node< SPACE_DIM > *pNode)
bool GetOwnership() const
bool ElementAssemblyCriterion(Element< ELEM_DIM, SPACE_DIM > &rElement)
unsigned GetNumNodes() const
unsigned GetUnsignedAttribute()
unsigned GetIndex() const
unsigned GetIndex() const
Definition: Node.cpp:158