LifeV
benchmarkUtility.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief Set of utility for the electrophysiology benchmark
30 
31  @date 03 - 2014
32  @author Simone Rossi <simone.rossi@epfl.ch>
33 
34  @contributor
35  @mantainer Simone Rossi <simone.rossi@epfl.ch>
36  */
37 
38 #ifndef BENCHMARKUTILITY_HPP_
39 #define BENCHMARKUTILITY_HPP_
40 
41 
42 #include <Epetra_ConfigDefs.h>
43 #ifdef EPETRA_MPI
44 #include <mpi.h>
45 #include <Epetra_MpiComm.h>
46 #else
47 #include <Epetra_SerialComm.h>
48 #endif
49 
50 
51 // ---------------------------------------------------------------
52 // Include the ionic models
53 // ---------------------------------------------------------------
54 
55 #include <lifev/electrophysiology/solver/IonicModels/IonicMinimalModel.hpp>
56 #include <lifev/electrophysiology/solver/IonicModels/IonicLuoRudyI.hpp>
57 #include <lifev/electrophysiology/solver/IonicModels/IonicTenTusscher06.hpp>
58 #include <lifev/electrophysiology/solver/IonicModels/IonicHodgkinHuxley.hpp>
59 #include <lifev/electrophysiology/solver/IonicModels/IonicNoblePurkinje.hpp>
60 #include <lifev/electrophysiology/solver/IonicModels/IonicFox.hpp>
61 #include <lifev/electrophysiology/solver/IonicModels/IonicAlievPanfilov.hpp>
62 
63 // ---------------------------------------------------------------
64 // Include LifeV
65 // ---------------------------------------------------------------
66 
67 #include <lifev/core/LifeV.hpp>
68 
69 // ---------------------------------------------------------------
70 // In LifeV namespace we create the benchmarkUtility namespace
71 // ---------------------------------------------------------------
72 
73 namespace LifeV
74 {
75 
76 namespace BenchmarkUtility
77 {
78 
79 
80 // ---------------------------------------------------------------
81 // We define some useful typedefs
82 // ---------------------------------------------------------------
83 
84 typedef ElectroIonicModel ionicModel_Type;
85 typedef std::shared_ptr<ionicModel_Type> ionicModelPtr_Type;
86 typedef std::function < Real (const Real& t,
87  const Real& x,
88  const Real& y,
89  const Real& z,
90  const ID& i ) > function_Type;
91 
92 // ---------------------------------------------------------------
93 // This function is used to choose among the ionic models with an
94 // if among the ionic model names.
95 // ---------------------------------------------------------------
96 
97 Real chooseIonicModel (ionicModelPtr_Type& model, std::string ionic_model, Epetra_Comm& Comm )
98 {
99  Real activationThreshold (0.95);
100  bool ionicModelSet = false;
101  if ( Comm.MyPID() == 0 )
102  {
103  std::cout << "Constructing the ionic model ... !"; // << std::endl;
104  }
105 
106  if ( ionic_model == "AlievPanfilov" )
107  {
108  model.reset ( new IonicAlievPanfilov() );
109  ionicModelSet = true;
110  }
111  if ( ionic_model == "LuoRudyI" )
112  {
113  model.reset ( new IonicLuoRudyI() );
114  ionicModelSet = true;
115  }
116  if ( ionic_model == "TenTusscher06")
117  {
118  model.reset (new IonicTenTusscher06() );
119  ionicModelSet = true;
120  }
121  if ( ionic_model == "HodgkinHuxley")
122  {
123  model.reset (new IonicHodgkinHuxley() );
124  activationThreshold = 10.0;
125  ionicModelSet = true;
126  }
127  if ( ionic_model == "NoblePurkinje")
128  {
129  model.reset (new IonicNoblePurkinje() );
130  ionicModelSet = true;
131  }
132  if ( ionic_model == "MinimalModel")
133  {
134  model.reset ( new IonicMinimalModel() );
135  ionicModelSet = true;
136  }
137  if ( ionic_model == "Fox")
138  {
139  model.reset ( new IonicFox() );
140  if ( Comm.MyPID() == 0 )
141  {
142  // assert(0 && "Fox model is not properly working in 3D."); //TO DO: Fix It!
143  }
144  }
145 
146  if ( Comm.MyPID() == 0 )
147  {
148  std::cout << " Done!" << std::endl;
149  }
150 
151  assert (ionicModelSet && "Ionic model not specified.");
152 
153  model -> showMe();
154 
155  return activationThreshold;
156 }
157 
158 // ---------------------------------------------------------------
159 // This function is used to pace the minimal model (and the
160 // Aliev Panfilov model )
161 // ---------------------------------------------------------------
162 
163 Real PacingProtocolMM ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& /*id*/)
164 {
165 
166  Real pacingSite_X = 0.0;
167  Real pacingSite_Y = 0.0;
168  Real pacingSite_Z = 0.0;
169  Real stimulusRadius = 0.15;
170  Real stimulusValue = 10;
171 
172  Real returnValue;
173 
174  if ( std::abs ( x - pacingSite_X ) <= stimulusRadius
175  &&
176  std::abs ( z - pacingSite_Z ) <= stimulusRadius
177  &&
178  std::abs ( y - pacingSite_Y ) <= stimulusRadius
179  &&
180  t <= 2)
181  {
182  returnValue = stimulusValue;
183  }
184  else
185  {
186  returnValue = 0.;
187  }
188 
189  return returnValue;
190 }
191 
192 // ---------------------------------------------------------------
193 // This function is used to pace the Hodgkin-Huxley model
194 // ---------------------------------------------------------------
195 
196 Real PacingProtocolHH ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& /*id*/)
197 {
198 
199  Real pacingSite_X = 0.0;
200  Real pacingSite_Y = 0.0;
201  Real pacingSite_Z = 0.0;
202  Real stimulusRadius = 0.15;
203  Real stimulusValue = 500.;
204 
205  Real returnValue;
206 
207  if ( std::abs ( x - pacingSite_X ) <= stimulusRadius
208  &&
209  std::abs ( z - pacingSite_Z ) <= stimulusRadius
210  &&
211  std::abs ( y - pacingSite_Y ) <= stimulusRadius
212  &&
213  t <= 2)
214  {
215  returnValue = stimulusValue;
216  }
217  else
218  {
219  returnValue = 0.;
220  }
221 
222  return returnValue;
223 }
224 
225 // ---------------------------------------------------------------
226 // This function is used to pace the cardiac models
227 // ---------------------------------------------------------------
228 
229 Real PacingProtocol ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& /*id*/)
230 {
231 
232  Real pacingSite_X = 0.0;
233  Real pacingSite_Y = 0.0;
234  Real pacingSite_Z = 0.0;
235  Real stimulusRadius = 0.15;
236  Real stimulusValue = 40.0;
237 
238  Real returnValue;
239 
240  if ( std::abs ( x - pacingSite_X ) <= stimulusRadius
241  &&
242  std::abs ( z - pacingSite_Z ) <= stimulusRadius
243  &&
244  std::abs ( y - pacingSite_Y ) <= stimulusRadius
245  && t >= 0.1 && t <= 2)
246  {
247  returnValue = stimulusValue;
248  }
249  else
250  {
251  returnValue = 0.;
252  }
253 
254  return returnValue;
255 }
256 
257 // ---------------------------------------------------------------
258 // This function is used to set the external stimulus
259 // ---------------------------------------------------------------
260 
261 void setStimulus (function_Type& f, std::string ionic_model)
262 {
263  if (ionic_model == "MinimalModel" || ionic_model == "AlievPanfilov")
264  {
265  f = &BenchmarkUtility::PacingProtocolMM;
266  }
267  else if (ionic_model == "HodgkinHuxley" )
268  {
269  f = &BenchmarkUtility::PacingProtocolHH;
270  }
271  else
272  {
273  f = &BenchmarkUtility::PacingProtocol;
274  }
275 }
276 
277 }//BenchmarkUtility
278 
279 } //LifeV
280 
281 
282 #endif /* BENCHMARKUTILITY_HPP_ */