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

Simulation of 3-tissue CM with compartments in series. More...

#include "tpcclibConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "tpccm.h"

Go to the source code of this file.

Functions

int simC3s (double *t, double *ca, const int nr, double k1, double k2, double k3, double k4, double k5, double k6, double *ct, double *cta, double *ctb, double *ctc)
int simC3vs (double *t, double *ca, double *cb, const int nr, const double k1, const double k2, const double k3, const double k4, const double k5, const double k6, const double f, const double vb, const double fa, const int vvm, double *cpet, double *cta, double *ctb, double *ctc, double *ctab, double *ctvb)

Detailed Description

Simulation of 3-tissue CM with compartments in series.

Definition in file sim3cms.c.

Function Documentation

◆ simC3s()

int simC3s ( double * t,
double * ca,
const int nr,
double k1,
double k2,
double k3,
double k4,
double k5,
double k6,
double * ct,
double * cta,
double * ctb,
double * ctc )

Simulate tissue TAC using 1-3 tissue compartment model (compartments in series) and plasma TAC, at plasma TAC times.

Memory for ct must be allocated in the calling program. To retrieve the separate tissue compartment TACs, pointer to allocated memory for cta, ctb and/or ctc can be given; if compartmental TACs are not required, NULL pointer can be given instead.

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, simC2l, simDispersion, simDelay
Parameters
tArray of time values.
caArray of arterial activities.
nrNumber of values in TACs.
k1Rate constant of the model.
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.
ctPointer for TAC array to be simulated; must be allocated.
ctaPointer for 1st compartment TAC to be simulated, or NULL.
ctbPointer for 2nd compartment TAC to be simulated, or NULL.
ctcPointer for 3rd compartment TAC to be simulated, or NULL.

Definition at line 32 of file sim3cms.c.

59 {
60 int i;
61 double b, c, d, w, z, dt2;
62 double cai, ca_last, t_last;
63 double ct1, ct1_last, ct2, ct2_last, ct3, ct3_last;
64 double ct1i, ct1i_last, ct2i, ct2i_last, ct3i, ct3i_last;
65
66
67 /* Check for data */
68 if(nr<2) return 1;
69 if(ct==NULL) return 2;
70
71 /* Check actual parameter number */
72 if(k1<0.0) return 3;
73 if(k3<=0.0) {k3=0.0; if(k2<=0.0) k2=0.0;}
74 else if(k5<=0.0) {k5=0.0; if(k4<=0.0) k4=0.0;}
75 else {if(k6<=0.0) k6=0.0;}
76
77 /* Calculate curves */
78 t_last=0.0; if(t[0]<t_last) t_last=t[0];
79 cai=ca_last=0.0;
80 ct1_last=ct2_last=ct3_last=ct1i_last=ct2i_last=ct3i_last=0.0;
81 ct1=ct2=ct3=ct1i=ct2i=ct3i=0.0;
82 for(i=0; i<nr; i++) {
83 /* delta time / 2 */
84 dt2=0.5*(t[i]-t_last);
85 /* calculate values */
86 if(dt2<0.0) {
87 return 5;
88 } else if(dt2>0.0) {
89 /* arterial integral */
90 cai+=(ca[i]+ca_last)*dt2;
91 /* partial results */
92 b=ct1i_last+dt2*ct1_last;
93 c=ct2i_last+dt2*ct2_last;
94 d=ct3i_last+dt2*ct3_last;
95 w=k4 + k5 - (k5*k6*dt2)/(1.0+k6*dt2);
96 z=1.0+w*dt2;
97 /* 1st tissue compartment and its integral */
98 ct1 = (
99 + k1*z*cai + (k3*k4*dt2 - (k2+k3)*z)*b
100 + k4*c + k4*k6*dt2*d/(1.0+k6*dt2)
101 ) / ( z*(1.0 + dt2*(k2+k3)) - k3*k4*dt2*dt2 );
102 ct1i = ct1i_last + dt2*(ct1_last+ct1);
103 /* 2nd tissue compartment and its integral */
104 ct2 = (k3*ct1i - w*c + k6*d/(1.0+k6*dt2)) / z;
105 ct2i = ct2i_last + dt2*(ct2_last+ct2);
106 /* 3rd tissue compartment and its integral */
107 ct3 = (k5*ct2i - k6*d) / (1.0 + k6*dt2);
108 ct3i = ct3i_last + dt2*(ct3_last+ct3);
109 }
110 /* copy values to argument arrays */
111 ct[i]=ct1+ct2+ct3;
112 if(cta!=NULL) cta[i]=ct1;
113 if(ctb!=NULL) ctb[i]=ct2;
114 if(ctc!=NULL) ctc[i]=ct3;
115 /* prepare to the next loop */
116 t_last=t[i]; ca_last=ca[i];
117 ct1_last=ct1; ct1i_last=ct1i;
118 ct2_last=ct2; ct2i_last=ct2i;
119 ct3_last=ct3; ct3i_last=ct3i;
120 }
121
122 return 0;
123}

◆ simC3vs()

int simC3vs ( double * t,
double * ca,
double * cb,
const int nr,
const double k1,
const double k2,
const double k3,
const double k4,
const double k5,
const double k6,
const double f,
const double vb,
const double fa,
const int vvm,
double * cpet,
double * cta,
double * ctb,
double * ctc,
double * ctab,
double * ctvb )

Simulate tissue TAC using 1-3 tissue compartment model (compartments in series) and plasma TAC, at plasma TAC times, considering also arterial and venous vasculature.

Memory for ct must be allocated in the calling program. To retrieve the separate tissue compartment TACs, pointer to allocated memory for cta, ctb, ctc, ctab, and/or ctvb can be given; if compartmental TACs are not required, NULL pointer can be given instead.

The units of rate constants must be related to the time unit; 1/min and min, or 1/sec and sec. If blood flow is set to 0, function assumes that f>>k1, and Cvb=Cab.,

Returns
Function returns 0 when successful, else a value >= 1.
Author
Vesa Oikonen
See also
simC3vp, simC3s, simC3p, simC2l, simC3vpKLoss, simC3DIvs, simC4DIvs, parExamplePerfectBolus
Parameters
tArray of time values.
caArray of arterial plasma activities.
cbArray of arterial blood activities.
nrNumber of values in TACs.
k1Rate constant of the model.
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.
fBlood flow; if 0, function assumes that f>>k1, and Cvb=Cab.
vbVascular volume fraction.
faArterial fraction of vascular volume.
vvmVascular volume modelling: set to 0 to use Cpet = Vb*Cb + (1-Vb)*Ct, or set to 1 to use Cpet = Vb*Cb + Ct.
cpetPointer for TAC array to be simulated; must be allocated.
ctaPointer for 1st compartment TAC to be simulated, or NULL.
ctbPointer for 2nd compartment TAC to be simulated, or NULL.
ctcPointer for 3rd compartment TAC to be simulated, or NULL.
ctabPointer for arterial TAC in tissue, or NULL.
ctvbPointer for venous TAC in tissue, or NULL.

Definition at line 143 of file sim3cms.c.

186 {
187 int i;
188 double b, c, d, w, z, dt2, va, vv;
189 double cai, ca_last, t_last, dct, cvb;
190 double ct1, ct1_last, ct2, ct2_last, ct3, ct3_last;
191 double ct1i, ct1i_last, ct2i, ct2i_last, ct3i, ct3i_last;
192
193
194 /* Check for data */
195 if(nr<2) return 1;
196 if(cpet==NULL) return 2;
197
198 /* Check parameters */
199 if(k1<0.0) return 3;
200 if(vb<0.0 || vb>=1.0) return 4;
201 if(fa<=0.0 || fa>1.0) return 5;
202 va=fa*vb; vv=(1.0-fa)*vb;
203
204 /* Calculate curves */
205 t_last=0.0; if(t[0]<t_last) t_last=t[0];
206 cai=ca_last=0.0;
207 ct1_last=ct2_last=ct3_last=ct1i_last=ct2i_last=ct3i_last=0.0;
208 ct1=ct2=ct3=ct1i=ct2i=ct3i=0.0;
209 for(i=0; i<nr; i++) {
210 /* delta time / 2 */
211 dt2=0.5*(t[i]-t_last);
212 /* calculate values */
213 if(dt2<0.0) {
214 return 5;
215 } else if(dt2>0.0) {
216 /* arterial integral */
217 cai+=(ca[i]+ca_last)*dt2;
218 /* partial results */
219 b=ct1i_last+dt2*ct1_last;
220 c=ct2i_last+dt2*ct2_last;
221 d=ct3i_last+dt2*ct3_last;
222 w=k4 + k5 - (k5*k6*dt2)/(1.0+k6*dt2);
223 z=1.0+w*dt2;
224 /* 1st tissue compartment and its integral */
225 ct1 = (
226 + k1*z*cai + (k3*k4*dt2 - (k2+k3)*z)*b
227 + k4*c + k4*k6*dt2*d/(1.0+k6*dt2)
228 ) / ( z*(1.0 + dt2*(k2+k3)) - k3*k4*dt2*dt2 );
229 ct1i = ct1i_last + dt2*(ct1_last+ct1);
230 /* 2nd tissue compartment and its integral */
231 ct2 = (k3*ct1i - w*c + k6*d/(1.0+k6*dt2)) / z;
232 ct2i = ct2i_last + dt2*(ct2_last+ct2);
233 /* 3rd tissue compartment and its integral */
234 ct3 = (k5*ct2i - k6*d) / (1.0 + k6*dt2);
235 ct3i = ct3i_last + dt2*(ct3_last+ct3);
236 }
237 /* Venous curve */
238 if(f>0.) {dct = k1*ca[i] - k2*ct1; cvb = cb[i] - dct/f;} else cvb=cb[i];
239 /* copy values to argument arrays */
240 if(vvm==0) cpet[i]= va*cb[i] + vv*cvb + (1.0-vb)*(ct1+ct2+ct3);
241 else cpet[i]= va*cb[i] + vv*cvb + (ct1+ct2+ct3);
242 if(cta!=NULL) {cta[i]=ct1; if(vvm==0) cta[i]*=(1.0-vb);}
243 if(ctb!=NULL) {ctb[i]=ct2; if(vvm==0) ctb[i]*=(1.0-vb);}
244 if(ctc!=NULL) {ctc[i]=ct3; if(vvm==0) ctc[i]*=(1.0-vb);}
245 if(ctab!=NULL) {ctab[i]=va*cb[i];}
246 if(ctvb!=NULL) {ctvb[i]=vv*cvb;}
247 /* prepare to the next loop */
248 t_last=t[i]; ca_last=ca[i];
249 ct1_last=ct1; ct1i_last=ct1i;
250 ct2_last=ct2; ct2i_last=ct2i;
251 ct3_last=ct3; ct3i_last=ct3i;
252 }
253
254 return 0;
255}