AFVP - A Realistic Ventricular Rhythm Model During AF 1.0.0

File: <base>/afvp/afvp.h (7,018 bytes)
/***********************************************************
  afvp.h

  Header file for the AF-VP model

  Author: Jie Lian
************************************************************/
#ifndef _AFVP_H_
#define _AFVP_H_

#define MAX_AVJ_TM  3 // max count of waves allowed in AVJ
#define MAX_VENT_TM 3 // max count of waves allowed in ventricle
#define BUFLIM     80 // string buffer length

enum {ANTEGRADE,RETROGRADE,BIDIRECTION}; // direction of activation
enum {REFRACTORY,PHASE4};                // AVJ phases
enum {SENSE,PACE};                       // A/V event type

typedef struct {      // data structure of simulation environment
  // programmable parameters
  char fnRR[BUFLIM];  // output RR interval filename
  char fnAA[BUFLIM];  // output AA interval filename
  char fnAV[BUFLIM];  // output AVJ status filename
  char fnLOG[BUFLIM]; // output event log filename
  long MAX_RR;        // max RR intervals to run
  double MAX_TIME;    // max running time in seconds
  double Ts;          // sampling interval
  double RR0;         // initial RR interval
  // working parameters
  FILE *fprr;         // point to fnRR
  FILE *fpaa;         // point to fnAA
  FILE *fpav;         // point to fnAV
  FILE *fplog;        // point to fnLog
  long beat;          // beat counter [0 .. MAX_RR]
  double t;           // simulation time [0 .. MAX_TIME]
} EnvStruct;

typedef struct {      // data structure of atrium model
  // programmable parameters
  int    AA_MODEL;    // AA interval generator method
  double lambda;      // mean rate of Afib bombardment on AV junction
  double AAstd;       // standard deviation of AA interval
  double dVmean;      // mean potential increment by Afib bombardment
  double dVstd;       // standard deviation of dV
  double AtrDly;      // atrial conduction delay from SA node to AVJ
  double S1S2;        // atrial pacing protocol S1S2 interval
  double S2S3;        // atrial pacing protocol S2S3 interval
  // working parameters
  double dV;          // actual calculated dV
  double NextAA;      // time interval to the next Afib impulse
  double t;           // timer started after A event
  long   nF[2];       // number of atrial fusions in phase 4 & refr period
  long   nAf[2];      // number of AF events in phase 4 & refr period
} AtrStruct;

typedef struct {      // data structure of AV junction model
  // programmable parameters
  double Vt;          // AV junction threshold potential
  double Vr;          // AV junction resting potential
  double dVdt;        // original V4 (AVJ spontaneous depolarization slope)
  double MinAVDa;     // minimum anterograde AV conduction delay
  double MinAVDr;     // minimum retrograde AV conduction delay
  double MinRef;      // minimum AVJ refractory period
  double Ref_std;     // standard deviation of the AVJ refractory period
  double alpha;       // max extension of AV conduction time
  double beta;        // max extension of AVJ refractory period
  double tau_c;       // time constant for AV conduction curve
  double tau_r;       // time constant for AVJ recovery curve
  double delta;       // electrotonic modulation control parameter (strength)
  double theta;       // electrotonic modulation control parameter (time)
  // working parameters
  int    phase;       // AVJ phase flag (phase4 or refractory)
  int    dir;         // direction of most recent activation
  double Vm;          // AVJ membrane potential
  double V4;          // actual AVJ spontaneous depolarization slope
  double ref;         // actually calculated refractory period
  double AVDa;        // corrected antegrade AV delay
  double AVDr;        // corrected retrograde AV delay
  double RT;          // AVJ recovery time
  double RT0;         // time at the start of AVJ recovery period
  double tmA[MAX_AVJ_TM][2]; // AVJ ante activation timer & conduction time
  double tmR[MAX_AVJ_TM][2]; // AVJ retr activation timer & conduction time
  int    nA;          // number of active ante. AV conduction timers
  int    nR;          // number of active retr. AV conduction timers
  double t;           // timer started after AVJ enters refractory period
  long   nF[2];       // number of AVJ fusions in phase 4 & refr period
  long   nB[2];       // number of blocked impulses (ante & retr)
} AvjStruct;

typedef struct {      // data structure of ventricle model
  // programmable parameters
  double AntDly;      // anterograde conduction delay from AVJ to RV electrode
  double RetDly;      // retrograde conduction delay from RV electrode to AVJ
  double ref;         // ventricular refractory period
  // working parameters
  double tmA[MAX_VENT_TM]; // timer starts after AV depol, ante cond for Vs
  double tmR[MAX_VENT_TM]; // timer starts after Vp for retr conduction
  int    nA;          // number of active retrograde conduction timers
  int    nR;          // number of active antegrade conduction timers
  double tmA0;        // time of last ante AV timeout, start ante cond
  double tmR0;        // time of last Vp delivery, start retr cond
  double t;           // timer started after V event
  long   nF[2];       // number of ventricular fusions in phase 4 & refr period
  long   nB[2];       // number of blocked impulses (ante & retr)
} VtrStruct;

typedef struct {      // data structure of RV electrode model
  // programmable parameters
  int    VP_MODEL;    // ventricular pacing method
  double BI;          // standby ventricular pacing basic interval
  // working parameters
  int    VpFlg;       // ventricular pacing flag, 1-Vp, 0-Vs
  double NextVV;      // ventricular pacing interval (escape interval)
  double RR;          // measured RR interval
  double t;           // clock timer for Vp
  long   cnt[2];      // event counters for Vp and Vs
} VeleStruct;

// functions defined by AF-VP model

//double gamdev(int x, long *idum);
double poidev(double xm, long *idum);
double expdev(double xm, long *idum);
double gaussian(double mean, double sd, double r1, double r2);
double ran2(long *i);
double ran3(int *i);

void   ErrMsg(char *msg, int errcode);
void   ReadConfig(char *fn);
double ReadLine(FILE *fp, double v, char *str);
void   LogConfig(FILE *fp);
void   LogEvent(FILE *fp, char *msg);
void   LogStat(FILE *fp);
void   ModelInit(void);
void   ModelExit(void);
void   UpdateAtTs(void);
void   AnteHitAvj(void);
void   RetrHitAvj(void);
void   StartAvjTm(int dir);
void   StopAvjTm(int dir);
void   StartVtrTm(int dir);
void   StopVtrTm(int dir);
void   AnteEscAvj(void);
void   RetrEscAvj(void);
void   ActivateAvj(void);
void   StartAvjRef(void);
void   StartAvjPh4(void);
void   VtrFusion(void);
void   VtrSense(void);
void   VtrPace(void);
void   RegEventV(int event);
double GetVpIntv(double RR, double BI, double VpIntv, int method);
double GetAfIntv(double lambda, double sd, int method);

#endif  // #ifndef _AFVP_H_