TPCCLIB
Loading...
Searching...
No Matches
simrtcm.c
Go to the documentation of this file.
1
4/*****************************************************************************/
5#include "tpcclibConfig.h"
6/*****************************************************************************/
7#include <stdio.h>
8#include <stdlib.h>
9#include <math.h>
10#include <time.h>
11#include <string.h>
12/*****************************************************************************/
13#include "tpccm.h"
14/*****************************************************************************/
15
16/*****************************************************************************/
34 double *t,
36 double *cr,
38 const int nr,
40 const double R1,
42 const double k2,
44 const double k3,
46 const double k4,
48 double *ct,
50 double *cta,
52 double *ctb
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}
100/*****************************************************************************/
101
102/*****************************************************************************/
116 double *t,
118 double *cr,
120 const int nr,
122 const double R1,
124 const double k2,
126 const double BP,
128 double *ct
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}
166/*****************************************************************************/
167
168/*****************************************************************************/
184 double *t,
186 double *cr,
188 const int nr,
190 const double R1,
192 const double k2,
194 const double k3,
196 double *ct
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}
233/*****************************************************************************/
234
235/*****************************************************************************/
int simTRTM(double *t, double *cr, const int nr, const double R1, const double k2, const double k3, double *ct)
Definition simrtcm.c:182
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)
Definition simrtcm.c:32
int simSRTM(double *t, double *cr, const int nr, const double R1, const double k2, const double BP, double *ct)
Definition simrtcm.c:114
Header file for libtpccm.