Chaste  Release::3.4
AbstractCorrectionTermAssembler.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 "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 
83 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
85 {
86  // reset ionic current, and state variables
87  mIionicInterp = 0;
88  for(unsigned i=0; i<mStateVariablesAtQuadPoint.size(); i++)
89  {
90  mStateVariablesAtQuadPoint[i] = 0;
91  }
92 }
93 
94 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
96  double phiI, const Node<SPACE_DIM>* pNode)
97 {
98  // interpolate ionic current
99  unsigned node_global_index = pNode->GetIndex();
100  mIionicInterp += phiI * this->mpCardiacTissue->rGetIionicCacheReplicated()[ node_global_index ];
101  // and state variables
102  std::vector<double> state_vars = this->mpCardiacTissue->GetCardiacCellOrHaloCell(node_global_index)->GetStdVecStateVariables();
103  for (unsigned i=0; i<mStateVariablesAtQuadPoint.size(); i++)
104  {
105  mStateVariablesAtQuadPoint[i] += phiI * state_vars[i];
106  }
107 }
108 
109 
110 
111 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM, unsigned PROBLEM_DIM>
113 {
114  // Check that SVI is allowed on this element
115  if (!mElementsCanDoSvi[rElement.GetIndex()])
116  {
117  return false;
118  }
119  double DELTA_IIONIC = 1; // tolerance
120 
121  //The criterion and the correction both need the ionic cache, so we better make sure that it's up-to-date
122  assert(this->mpCardiacTissue->GetDoCacheReplication());
123  ReplicatableVector& r_cache = this->mpCardiacTissue->rGetIionicCacheReplicated();
124 
125  double diionic = fabs(r_cache[rElement.GetNodeGlobalIndex(0)] - r_cache[rElement.GetNodeGlobalIndex(1)]);
126 
127  if (ELEMENT_DIM > 1)
128  {
129  diionic = std::max(diionic, fabs(r_cache[rElement.GetNodeGlobalIndex(0)] - r_cache[rElement.GetNodeGlobalIndex(2)]) );
130  diionic = std::max(diionic, fabs(r_cache[rElement.GetNodeGlobalIndex(1)] - r_cache[rElement.GetNodeGlobalIndex(2)]) );
131  }
132 
133  if (ELEMENT_DIM > 2)
134  {
135  diionic = std::max(diionic, fabs(r_cache[rElement.GetNodeGlobalIndex(0)] - r_cache[rElement.GetNodeGlobalIndex(3)]) );
136  diionic = std::max(diionic, fabs(r_cache[rElement.GetNodeGlobalIndex(1)] - r_cache[rElement.GetNodeGlobalIndex(3)]) );
137  diionic = std::max(diionic, fabs(r_cache[rElement.GetNodeGlobalIndex(2)] - r_cache[rElement.GetNodeGlobalIndex(3)]) );
138  }
139 
140  bool will_assemble = (diionic > DELTA_IIONIC);
141 
142  if (will_assemble)
143  {
144  unsigned any_node = rElement.GetNodeGlobalIndex(0);
145  mStateVariablesAtQuadPoint.resize(this->mpCardiacTissue->GetCardiacCellOrHaloCell(any_node)->GetNumberOfStateVariables() );
146  }
147 
148  return will_assemble;
149 }
150 
152 // explicit instantiation
154 
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:159