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

Simulation of 3-tissue CM with compartments 2 and 3 in parallel. 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 simC3p (double *t, double *ca, const int nr, const double k1, const double k2, const double k3, const double k4, const double k5, const double k6, double *ct, double *cta, double *ctb, double *ctc)
int simC3vp (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 2 and 3 in parallel.

Definition in file sim3cmp.c.

Function Documentation

◆ simC3p()

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

Simulate tissue TAC using 1-3 tissue compartment model (2nd and 3rd compartments in parallel) 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
simC3s, simC1, simC1DI, simC2, simC2l, simC3vp, simC3vs, simSamples, parExampleTTACs, parExamplePerfectBolus
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 33 of file sim3cmp.c.

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

◆ simC3vp()

int simC3vp ( 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 (2nd and 3rd compartments in parallel) 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
simC3vs, simC3p, simC3s, simC3vpKLoss, simC4DIvp, simSamples, simDispersion, simDelay, parExampleTTACs, 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 140 of file sim3cmp.c.

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