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

Simulation of 1-tissue compartmental models. 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 simMBF (double *t, double *ci, const int nr, const double k1, const double k2, const double Vfit, double *ct)
int simC1 (double *t, double *ca, const int nr, const double k1, const double k2, double *ct)
int simC1_i (double *t, double *cai, const int nr, const double k1, const double k2, double *ct)
int simC1_d (double *t, double *ca, const int nr, const double k1, const double k2, double *ct)

Detailed Description

Simulation of 1-tissue compartmental models.

Definition in file sim1cm.c.

Function Documentation

◆ simC1()

int simC1 ( double * t,
double * ca,
const int nr,
const double k1,
const double k2,
double * ct )

Simulate tissue TAC using 1 tissue compartmental model and plasma TAC, at plasma TAC times.

Memory for ct must be allocated in the calling program.

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

See also
simC1_d, simC1_i, simDispersion, simMBF, simC2, simOxygen, simC3vs, convolve1D, simC1DI, simSamples, parExampleTTACs, parExamplePerfectBolus
Returns
Function returns 0 when successful, else a value >= 1.
Author
Vesa Oikonen
Parameters
tArray of time values.
caArray of arterial activities.
nrNumber of values in TACs.
k1Rate constant of the model.
k2Rate constant of the model.
ctPointer for TAC array to be simulated; must be allocated.

Definition at line 93 of file sim1cm.c.

106 {
107 int i;
108 double dt2;
109 double cai, ca_last, t_last;
110 double ct1, ct1_last;
111 double ct1i, ct1i_last;
112
113
114 /* Check for data */
115 if(nr<2) return 1;
116 if(t==NULL || ca==NULL || ct==NULL) return 2;
117
118 /* Check actual parameter number */
119 if(!(k1>=0.0)) return 3;
120
121 /* Calculate curves */
122 t_last=0.0; if(t[0]<t_last) t_last=t[0];
123 cai=ca_last=0.0;
124 ct1_last=ct1i_last=0.0;
125 ct1=ct1i=0.0;
126 for(i=0; i<nr; i++) {
127 /* delta time / 2 */
128 dt2=0.5*(t[i]-t_last);
129 /* calculate values */
130 if(dt2<0.0) {
131 return 5;
132 } else if(dt2>0.0) {
133 /* arterial integral */
134 cai+=(ca[i]+ca_last)*dt2;
135 /* tissue compartment and its integral */
136 ct1 = (k1*cai - k2*(ct1i_last+dt2*ct1_last)) / (1.0 + dt2*k2);
137 ct1i = ct1i_last + dt2*(ct1_last+ct1);
138 }
139 /* copy values to argument arrays */
140 ct[i]=ct1;
141 /* prepare to the next loop */
142 t_last=t[i]; ca_last=ca[i];
143 ct1_last=ct1; ct1i_last=ct1i;
144 }
145
146 return 0;
147}

Referenced by bfm1TCM(), and simDispersion().

◆ simC1_d()

int simC1_d ( double * t,
double * ca,
const int nr,
const double k1,
const double k2,
double * ct )

Simulate tissue TAC using 1 tissue compartmental model and input TAC, at input TAC times.

This version is directly based on ODE, and does not use integral of input TAC.

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

See also
simC1, simDelay, simDispersion
Returns
Function returns 0 when successful, else a value >= 1.
Author
Vesa Oikonen
Parameters
tArray of time values.
caArray of arterial activities.
nrNumber of values in TACs.
k1Rate constant of the model.
k2Rate constant of the model.
ctPointer for TAC array to be simulated; must be allocated.

Definition at line 229 of file sim1cm.c.

242 {
243 int i;
244 double dt2;
245 double cap, ctp, tp; // 'p' marks previous
246
247
248 /* Check for data */
249 if(nr<2) return 1;
250 if(t==NULL || ca==NULL || ct==NULL) return 2;
251
252 /* Check actual parameter number */
253 if(!(k1>=0.0)) return 3;
254
255 /* Set 'previous' sample */
256 tp=0.0; if(t[0]<tp) tp=t[0];
257 cap=ctp=0.0;
258 /* Calculate curves */
259 for(i=0; i<nr; i++) {
260 /* delta time / 2 */
261 dt2=0.5*(t[i]-tp);
262 /* calculate values */
263 if(dt2<0.0) {
264 return 5;
265 } else if(dt2>=0.0) { // must be >= because ct[0] is not set elsewhere
266 ct[i]=(k1*dt2*(cap+ca[i]) + (1.0 - k2*dt2)*ctp) / (1.0 + k2*dt2);
267 }
268 /* prepare to the next sample */
269 tp=t[i]; cap=ca[i];
270 ctp=ct[i];
271 }
272
273 return 0;
274}

◆ simC1_i()

int simC1_i ( double * t,
double * cai,
const int nr,
const double k1,
const double k2,
double * ct )

Simulate tissue TAC using 1 tissue compartmental model and plasma TAC, at plasma TAC times.

This version uses integral of arterial TAC as input function. Only advantage over simC1() is that the calculation of integral can be fully controlled and possibly more precise in some situations.

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

See also
simC1, simC2_i, simDelay, simDispersion
Returns
Function returns 0 when successful, else a value >= 1.
Author
Vesa Oikonen
Parameters
tArray of time values.
caiArray of AUC 0-t of arterial activities.
nrNumber of values in TACs.
k1Rate constant of the model.
k2Rate constant of the model.
ctPointer for TAC array to be simulated; must be allocated.

Definition at line 164 of file sim1cm.c.

177 {
178 int i;
179 double dt2;
180 double t_last;
181 double ct1, ct1_last;
182 double ct1i, ct1i_last;
183
184
185 /* Check for data */
186 if(nr<2) return 1;
187 if(t==NULL || cai==NULL || ct==NULL) return 2;
188
189 /* Check actual parameter number */
190 if(!(k1>=0.0)) return 3;
191
192 /* Calculate curves */
193 t_last=0.0; if(t[0]<t_last) t_last=t[0];
194 ct1_last=ct1i_last=0.0;
195 ct1=ct1i=0.0;
196 for(i=0; i<nr; i++) {
197 /* delta time / 2 */
198 dt2=0.5*(t[i]-t_last);
199 /* calculate values */
200 if(dt2<0.0) {
201 return 5;
202 } else if(dt2>0.0) {
203 /* tissue compartment and its integral */
204 ct1 = (k1*cai[i] - k2*(ct1i_last+dt2*ct1_last)) / (1.0 + dt2*k2);
205 ct1i = ct1i_last + dt2*(ct1_last+ct1);
206 }
207 /* copy values to argument arrays */
208 ct[i]=ct1;
209 /* prepare to the next loop */
210 t_last=t[i]; ct1_last=ct1; ct1i_last=ct1i;
211 }
212
213 return 0;
214}

Referenced by bfm1TCM(), and bfmSRTM().

◆ simMBF()

int simMBF ( double * t,
double * ci,
const int nr,
const double k1,
const double k2,
const double Vfit,
double * ct )

Simulate myocardial tissue TAC using Iida's compartment model.

Memory for ct must be allocated in the calling program. 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
simC1, simOxygen, simSamples, simDelay
Parameters
tArray of time values.
ciInput activities.
nrNumber of values in TACs.
k1Apparent k1.
k2Apparent k2.
VfitVfit
ctPointer for TAC array to be simulated; must be allocated.

Definition at line 28 of file sim1cm.c.

43 {
44 int i;
45 double dt2;
46 double cii, ci_last, t_last;
47 double ct_last, cti, cti_last;
48
49
50 /* Check for data */
51 if(nr<2) return(1);
52 if(t==NULL || ci==NULL || ct==NULL) return(2);
53
54 /* Calculate curves */
55 t_last=0.0; cii=ci_last=0.0;
56 cti=ct_last=cti_last=0.0;
57 for(i=0; i<nr; i++) {
58 /* delta time / 2 */
59 dt2=0.5*(t[i]-t_last);
60 /* calculate values */
61 if(dt2<0.0) {
62 return(5);
63 } else if(dt2>0.0) {
64 /* input integral */
65 cii+=(ci[i]+ci_last)*dt2;
66 /* Tissue compartment and its integral */
67 ct[i] = (Vfit*ci[i] + k1*cii - k2*(cti_last+dt2*ct_last)) / (1.0 + dt2*k2);
68 cti = cti_last + dt2*(ct_last+ct[i]);
69 }
70 /* set very small values to zero
71 if(fabs(ct[i])<1.0e-12) ct[i]=0.0; */
72 /* prepare to the next loop */
73 t_last=t[i]; ci_last=ci[i];
74 ct_last=ct[i]; cti_last=cti;
75 }
76 return(0);
77}