/*
 *	$Source: /mit/hst/src/sim/RCS/CVDefs.h,v $
 *	$Header: /mit/hst/src/sim/RCS/CVDefs.h,v 2.0 90/08/06 17:54:51 tldavis Stab Locker: tldavis $
 */

/*
 *	$Source: /mit/hst/src/sim/RCS/CVDefs.h,v $
 *	$Header: /mit/hst/src/sim/RCS/CVDefs.h,v 2.0 90/08/06 17:54:51 tldavis Stab Locker: tldavis $
 */

/* file: cvdefs.h      Tim Davis, G. Moody, R. Sah
 *                     Copyright 1988 Timothy L. Davis

Constants, macros, and typedefs for CV simulator

Dimensions of variables:

	Quantity	Units
	--------	-----
	pressure	mmHg
	capacitance	ml/mm Hg
	resistance	mm Hg-sec/ml
	volume		ml
	flow		ml/sec
*/
/* These cause a compiler error... endless loop "too much pushback"
extern Display *dpy;
#define screen      DefaultScreen(dpy)
#define white_pixel WhitePixel(dpy, screen)
#define black_pixel BlackPixel(dpy, screen)
#define root        DefaultRootWindow(dpy)
*/

#include <stdio.h>
#include <math.h>

#define	RWMOD		000644
#define MINTSTP		.003999999
#define	SYSTOLESEGS	528	/* # table segments during systole */
#define	TBLSEGS		792	/* 3/2 SYSTOLESEGS */
#define	TBLSEGSPLUS2	TBLSEGS+2

#define	xpl	x[0]		/* left heart pressure */
#define	xpa	x[1]		/* peripheral arterial pressure */
#define	xpv	x[2]		/* peripheral venous pressure */
#define	xpr	x[3]		/* right heart pressure */
#define	xpPa	x[4]		/* pulmonary arterial pressure */
#define	xpPv	x[5]		/* pulmonary venous pressure */
#define xt      x[6]
#define xCl     x[7]
#define xCr     x[8]
#define	dpldt	dxdt[0]		/* left heart pressure */
#define	dpadt	dxdt[1]		/* peripheral arterial pressure */
#define	dpvdt	dxdt[2]		/* peripheral venous pressure */
#define	dprdt	dxdt[3]		/* right heart pressure */
#define	dpPadt	dxdt[4]		/* pulmonary arterial pressure */
#define	dpPvdt	dxdt[5]		/* pulmonary venous pressure */

/* The saved simulation values in parameter.c (structure cvstat) */
#define CURRENT         0
#define	NORMAL		1

#ifndef TRUE
#define FALSE		0
#define TRUE		1
#endif

#define	TIME		0       /* type codes for getval(), setval(), etc*/
#define	FLOW		1
#define	PRESSURE	2
#define	VOLUME		3
#define CAPACITANCE     4
#define CAPACITANCE_DIAS 5
#define CAPACITANCE_SYS 6
#define ZPVOLUME        7
#define RESISTANCE      8
#define HEARTRATE       9
#define ENDVAR  (-1)

#define RESISTOR 0 /* Device codes for user interface */
#define CAPACITOR 1
#define VARCAPACITOR 2
#define SYSTEMOR 3 /* This is a dummy component holding non-localizable vars */

#define DEPENDENT 0 /* variable types */
#define INDEPENDENT 1

#define LV              0      /* place codes for getval(), setval() */
#define SA              1
#define SV              2
#define RV              3
#define PA              4
#define PV              5
#define SC              6
#define PC              7
#define SYSTEM          8

#define LVl 9           /*corresponding flow lines */
#define SCl 10
#define SVl 11
#define RVl 12
#define PCl 13
#define PVl 14

#define	NVL0		15.       /* Normal SIMULATION parameter values */
#define	NVR0		15.
#define	NVA0		715.
#define	NVV0		2500.
#define	NVPA0		90.
#define	NVPV0		490.
#define	NBV		5000.

#define	NRA		1.
#define	NRV		0.05
#define	NRPV		0.08
#define	NRLI		0.010
#define	NRLO		0.006
#define	NRRO		0.003

#define	NCA		1.6
#define	NCV		100.
#define	NCPA		4.3
#define	NCPV		8.4
#define	NCLDIAS		10.0
#define	NCLSYS		0.4
#define	NCRDIAS		20.0
#define	NCRSYS		1.2

#define	NPTH		(-4.0)
#define NHR             72.0

typedef struct simulation_ {
  double Vl0;	/* left heart volume at 0 pressure */
  double Vr0;	/* right heart volume at 0 pressure */
  double Va0;	/* peripheral arterial volume at 0 pressure */
  double Vv0;	/* peripheral venous volume at 0 pressure */
  double VPa0;	/* pulmonary arterial volume at 0 pressure */
  double VPv0;	/* pulmonary venous volume at 0 pressure */
  double bv;	/* total blood volume */
  
  double Ra;	/* peripheral arterial resistance */
  double Rv;	/* peripheral venous resistance */
  double RPv;	/* pulmonary vascular resistance */
  double Rli;	/* left ventricular inflow resistance */
  double Rlo;	/* left ventricular outflow resistance */
  double Rro;	/* right ventricular outflow resistance */

  double Ca;	/* peripheral arterial capacitance */
  double Cv;	/* peripheral venous capacitance */
  double CPa;	/* pulmonary arterial capacitance */
  double CPv;	/* pulmonary venous capacitance */
  double Cldias;	/* left heart diastolic capacitance */
  double Clsys;	/* left heart systolic capacitance */
  double Crdias;	/* right heart diastolic capacitance */
  double Crsys;	/* right heart systolic capacitance */
  
  double pth;	/* intrathoracic pressure */
  double hr;	/* heart rate in beats per minute */
} SIMULATION;

typedef struct var_data_node_ {
  int var;
  int dep;
  char *name;
  double min, max, normal;
  double gmin, gmax;
  char *units;
} VarData;
