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

Simulation reference tissue input 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 simRTCM (double *t, double *cr, const int nr, const double R1, const double k2, const double k3, const double k4, double *ct, double *cta, double *ctb)
int simSRTM (double *t, double *cr, const int nr, const double R1, const double k2, const double BP, double *ct)
int simTRTM (double *t, double *cr, const int nr, const double R1, const double k2, const double k3, double *ct)

Detailed Description

Simulation reference tissue input compartmental models.

Definition in file simrtcm.c.

Function Documentation

◆ simRTCM()

int simRTCM ( double * t,
double * cr,
const int nr,
const double R1,
const double k2,
const double k3,
const double k4,
double * ct,
double * cta,
double * ctb )

Simulate tissue TAC using full reference tissue compartment model (original) and reference region TAC, at reference region TAC times.

Memory for ct must be allocated in the calling program. To retrieve the separate tissue compartment TACs, pointer to allocated memory for cf and/or cb 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.

See also
simSRTM, simTRTM, simC2, parExampleTTACs, parExamplePerfectBolus
Returns
Function returns 0 when successful, else a value >= 1.
Author
Vesa Oikonen
Parameters
tArray of time values.
crReference region activities.
nrNumber of values in TACs.
R1Ratio K1/K1'.
k2Rate constant of the model.
k3Rate constant of the model.
k4Rate 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.

Definition at line 32 of file simrtcm.c.

53 {
54 int i;
55 double f, b, w, dt2;
56 double cri, cr_last, t_last;
57 double cf, cf_last, cb, cb_last;
58 double cfi, cfi_last, cbi, cbi_last;
59
60
61 /* Check for data */
62 if(nr<2) return 1;
63 if(ct==NULL) return 2;
64
65 /* Calculate curves */
66 t_last=0.0; if(t[0]<t_last) t_last=t[0];
67 cri=cr_last=0.0; cf_last=cb_last=cfi_last=cbi_last=cf=cb=cfi=cbi=0.0;
68 for(i=0; i<nr; i++) {
69 /* delta time / 2 */
70 dt2=0.5*(t[i]-t_last);
71 /* calculate values */
72 if(dt2<0.0) {
73 return 5;
74 } else if(dt2>0.0) {
75 /* reference integral */
76 cri+=(cr[i]+cr_last)*dt2;
77 /* partial results */
78 f=cfi_last+dt2*cf_last;
79 b=cbi_last+dt2*cb_last;
80 w=k2 + k3 + k2*k4*dt2;
81 /* 1st tissue compartment and its integral */
82 cf = ( (1.0 + k4*dt2)*(R1*cr[i] + k2*cri) + k4*b - w*f ) / ( 1.0 + dt2*(w+k4) );
83 cfi = cfi_last + dt2*(cf_last+cf);
84 /* 2nd tissue compartment and its integral */
85 cb = (k3*cfi - k4*b) / (1.0 + k4*dt2);
86 cbi = cbi_last + dt2*(cb_last+cb);
87 }
88 /* copy values to argument arrays */
89 ct[i]=cf+cb;
90 if(cta!=NULL) cta[i]=cf;
91 if(ctb!=NULL) ctb[i]=cb;
92 /* prepare to the next loop */
93 t_last=t[i]; cr_last=cr[i];
94 cf_last=cf; cfi_last=cfi;
95 cb_last=cb; cbi_last=cbi;
96 }
97
98 return 0;
99}

◆ simSRTM()

int simSRTM ( double * t,
double * cr,
const int nr,
const double R1,
const double k2,
const double BP,
double * ct )

Simulate tissue TAC using simplified reference tissue input 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.

See also
simRTCM, simTRTM, simC2, simC1_i
Returns
Function returns 0 when successful, else a value >= 1.
Author
Vesa Oikonen
Parameters
tArray of time values.
crReference region activities.
nrNumber of values in TACs.
R1Ratio K1/K1'.
k2Rate constant of the model.
BPBinding potential.
ctPointer for TAC array to be simulated; must be allocated.

Definition at line 114 of file simrtcm.c.

129 {
130 int i;
131 double dt2;
132 double cri, cr_last, t_last;
133 double ct_last, cti, cti_last;
134
135
136 /* Check for data */
137 if(nr<2) return 1;
138 if(ct==NULL) return 2;
139
140 /* Calculate curves */
141 t_last=0.0; if(t[0]<t_last) t_last=t[0];
142 cri=cr_last=0.0; cti=ct_last=cti_last=0.0;
143 for(i=0; i<nr; i++) {
144 /* delta time / 2 */
145 dt2=0.5*(t[i]-t_last);
146 /* calculate values */
147 if(dt2<0.0) {
148 return 5;
149 } else if(dt2>0.0) {
150 /* reference integral */
151 cri+=(cr[i]+cr_last)*dt2;
152 /* Tissue compartment and its integral */
153 ct[i] = ( R1*cr[i] + k2*cri - (k2/(1.0+BP))*(cti_last+dt2*ct_last) ) /
154 ( 1.0 + dt2*(k2/(1.0+BP)) );
155 cti = cti_last + dt2*(ct_last+ct[i]);
156 } else { // dt==0
157 ct[i]=ct_last;
158 }
159 /* prepare to the next loop */
160 t_last=t[i]; cr_last=cr[i];
161 ct_last=ct[i]; cti_last=cti;
162 }
163
164 return 0;
165}

◆ simTRTM()

int simTRTM ( double * t,
double * cr,
const int nr,
const double R1,
const double k2,
const double k3,
double * ct )

Simulate tissue TAC using reference tissue compartment model (transport limited in ref region) and reference region TAC, at reference region 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
simSRTM, simSRTM, simC2
Returns
Function returns 0 when successful, else a value >= 1.
Author
Vesa Oikonen
Parameters
tArray of time values.
crReference region activities.
nrNumber of values in TACs.
R1Ratio K1/K1'.
k2Rate constant of the model.
k3Rate constant of the model.
ctPointer for TAC array to be simulated; must be allocated.

Definition at line 182 of file simrtcm.c.

197 {
198 int i;
199 double dt2;
200 double cri, cr_last, t_last;
201 double ct_last, cti, cti_last;
202
203
204 /* Check for data */
205 if(nr<2) return 1;
206 if(ct==NULL) return 2;
207
208 /* Calculate curves */
209 t_last=0.0; if(t[0]<t_last) t_last=t[0];
210 cri=cr_last=0.0; cti=ct_last=cti_last=0.0;
211 for(i=0; i<nr; i++) {
212 /* delta time / 2 */
213 dt2=0.5*(t[i]-t_last);
214 /* calculate values */
215 if(dt2<0.0) {
216 return 5;
217 } else if(dt2>0.0) {
218 /* reference integral */
219 cri+=(cr[i]+cr_last)*dt2;
220 /* Tissue compartment and its integral */
221 ct[i] = ( R1*cr[i] + R1*k3*cri - (k2+k3)*(cti_last+dt2*ct_last) ) / ( 1.0 + dt2*(k2+k3) );
222 cti = cti_last + dt2*(ct_last+ct[i]);
223 } else { // dt==0
224 ct[i]=ct_last;
225 }
226 /* prepare to the next loop */
227 t_last=t[i]; cr_last=cr[i];
228 ct_last=ct[i]; cti_last=cti;
229 }
230
231 return 0;
232}