openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
Lapicque.cc
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: LicenseRef-APL-1.1
3 
4 #include "Lapicque.h"
5 #include <iostream>
6 
17 Lapicque:: Lapicque( opencarp::timer_manager *to, float pmin, float pmax, int np, float tol, float delay ):
18  _tmo(to),_delay(delay),_tol(tol)
19 {
20  _widths.resize(np);
21  _thresh.resize(np);
22  float dlog = _widths.size()>1 ? (log(pmax)-log(pmin))/(_widths.size()-1) : 0;
23  for( int i=0; i<_widths.size(); i++ ) {
24  _widths[i] = pmin*exp(dlog*i);
25  }
26  _ap = new Bisect( 0, INFINITY, tol );
27 }
28 
29 
44 bool
45 Lapicque::check( bool fire, float &curr, int doppind, int stimind )
46 {
47  if( _ap->update( curr, fire ) ){
48  std::cout << _widths[_currw] << " " << curr << std::endl;
49  _thresh[_currw++] = curr;
50  if( _currw == _thresh.size() )
51  return true;
52  else {
53  delete _ap;
54  _ap = new Bisect( 0, INFINITY, _tol );
55  }
56  }
57  delete _tmo->timers[doppind];
58  double ttime = _tmo->time+_widths[_currw]+_delay;
59  _tmo->initialize_singlestep_timer( ttime, 1, doppind, "dopple" );
60  delete _tmo->timers[stimind];
61  _tmo->initialize_singlestep_timer( _tmo->time, _widths[_currw], stimind, "STIM_TIMER" );
62  return false;
63 }
64 
65 
66 void
67 Lapicque:: print( std::ostream &ofs )
68 {
69  ofs << "# stimDuration(ms) stimStrength(pA/pF)" << std::endl;
70  for( int i=0; i<_widths.size(); i++ )
71  ofs << _widths[i] << " " << _thresh[i] << std::endl;
72 }
73 
74 
86 bool
87 Lapicque::init( int doppind, int stimind )
88 {
89  if( _init ) return true;
90  _init = true;
91  double ttime = _tmo->time+_widths[0]+_delay;
92  delete _tmo->timers[doppind];
93  _tmo->initialize_singlestep_timer( ttime, 0, doppind, "dopple" );
94  delete _tmo->timers[stimind];
95  _tmo->initialize_singlestep_timer( _tmo->time, _widths[0], stimind, "STIM_TIMER" );
96  return false;
97 }
98 
bool update(float &val, bool success)
update search
Definition: bench_utils.h:32
Lapicque(opencarp::timer_manager *to, float pmin, float pmax, int np, float tol, float delay)
constructor
Definition: Lapicque.cc:17
void print(std::ostream &)
Definition: Lapicque.cc:67
bool init(int, int)
initial first step
Definition: Lapicque.cc:87
bool check(bool fire, float &, int, int)
check if the Lapicque curve is finished and update current
Definition: Lapicque.cc:45
centralize time managment and output triggering
Definition: timer_utils.h:59
void initialize_singlestep_timer(double tg, double idur, int ID, const char *iname, const char *poolname=nullptr)
Definition: timer_utils.h:142
std::vector< base_timer * > timers
vector containing individual timers
Definition: timer_utils.h:70
double time
current time
Definition: timer_utils.h:62