TPCCLIB
Loading...
Searching...
No Matches
sim_av.c File Reference

Simulation of A-V difference using compartmental model. More...

Go to the source code of this file.

Functions

int simC3vb (double *t, double *cab, const int nr, double f, double k1, double k2, double k3, double k4, double k5, double k6, double *cvb, double *ct)

Detailed Description

Simulation of A-V difference using compartmental model.

Author
Vesa Oikonen

Definition in file sim_av.c.

Function Documentation

◆ simC3vb()

int simC3vb ( double * t,
double * cab,
const int nr,
double f,
double k1,
double k2,
double k3,
double k4,
double k5,
double k6,
double * cvb,
double * ct )

Simulate venous blood TAC using 1-3 tissue compartment model (compartments in series)

Memory for cvb must be allocated in the calling program. To retrieve the tissue TAC, pointer to allocated memory for ct can be given.

The units of rate constants must be related to the time unit; 1/min and min, or 1/sec and sec.

Returns
Function returns 0 when successful, else a value >= 1.
Author
Vesa Oikonen
See also
simC3vs, simC1, simC3p, simC3vp
Parameters
tArray of time values; must be in increasing order.
cabArray of arterial blood activities.
nrNumber of values (samples) in TACs.
fPerfusion; must be f>=K1.
k1Rate constant of the model; must be K1<=f.
k2Rate constant of the model.
k3Rate constant of the model.
k4Rate constant of the model.
k5Rate constant of the model.
k6Rate constant of the model.
cvbPointer for venous blood TAC array to be simulated; must be allocated
ctPointer for tissue TAC to be simulated, or NULL

Definition at line 88 of file sim_av.c.

113 {
114 int i;
115 double b, c, d, w, z, dt2;
116 double cai, ca_last, t_last;
117 double ct1, ct1_last, ct2, ct2_last, ct3, ct3_last;
118 double ct1i, ct1i_last, ct2i, ct2i_last, ct3i, ct3i_last;
119
120
121 /* Check for data */
122 if(nr<2) return 1;
123 if(cvb==NULL) return 2;
124
125 /* Check actual parameter number */
126 if(!(f>=0.0) || !(k1>=0.0) || k1>f) return 3;
127 if(k3<=0.0) {k3=0.0; if(k2<=0.0) k2=0.0;}
128 else if(k5<=0.0) {k5=0.0; if(k4<=0.0) k4=0.0;}
129 else {if(k6<=0.0) k6=0.0;}
130
131 /* Calculate curves */
132 t_last=0.0; if(t[0]<t_last) t_last=t[0];
133 cai=ca_last=0.0;
134 ct1_last=ct2_last=ct3_last=ct1i_last=ct2i_last=ct3i_last=0.0;
135 ct1=ct2=ct3=ct1i=ct2i=ct3i=0.0;
136 for(i=0; i<nr; i++) {
137 /* delta time / 2 */
138 dt2=0.5*(t[i]-t_last);
139 /* calculate values */
140 if(dt2<0.0) {
141 return 5;
142 } else if(dt2>0.0) {
143 /* arterial integral */
144 cai+=(cab[i]+ca_last)*dt2;
145 /* partial results */
146 b=ct1i_last+dt2*ct1_last;
147 c=ct2i_last+dt2*ct2_last;
148 d=ct3i_last+dt2*ct3_last;
149 w=k4 + k5 - (k5*k6*dt2)/(1.0+k6*dt2);
150 z=1.0+w*dt2;
151 /* 1st tissue compartment and its integral */
152 ct1 = (
153 + k1*z*cai + (k3*k4*dt2 - (k2+k3)*z)*b
154 + k4*c + k4*k6*dt2*d/(1.0+k6*dt2)
155 ) / ( z*(1.0 + dt2*(k2+k3)) - k3*k4*dt2*dt2 );
156 ct1i = ct1i_last + dt2*(ct1_last+ct1);
157 /* 2nd tissue compartment and its integral */
158 ct2 = (k3*ct1i - w*c + k6*d/(1.0+k6*dt2)) / z;
159 ct2i = ct2i_last + dt2*(ct2_last+ct2);
160 /* 3rd tissue compartment and its integral */
161 ct3 = (k5*ct2i - k6*d) / (1.0 + k6*dt2);
162 ct3i = ct3i_last + dt2*(ct3_last+ct3);
163 }
164 if(f>0.0) {
165 double dct = k1*cab[i] - k2*ct1;
166 cvb[i] = cab[i] - dct/f;
167 } else
168 cvb[i]=cab[i];
169
170 /* copy values to argument arrays; set very small values to zero */
171 if(ct!=NULL) {ct[i]=ct1+ct2+ct3; if(fabs(ct[i])<1.0e-12) ct[i]=0.0;}
172
173 /* prepare to the next loop */
174 t_last=t[i]; ca_last=cab[i];
175 ct1_last=ct1; ct1i_last=ct1i;
176 ct2_last=ct2; ct2i_last=ct2i;
177 ct3_last=ct3; ct3i_last=ct3i;
178 }
179
180 return 0;
181}