5#include "tpcclibConfig.h"
42 if(x==NULL || y==NULL || n<2)
return 1;
43 if(tau1<0.0 || tau2<0.0)
return 2;
47 if(tmp!=NULL) buf=tmp;
else buf=(
double*)malloc(n*
sizeof(
double));
48 if(buf==NULL)
return 3;
53 int ret=
simC1(x, y, n, k, k, buf);
55 if(tmp==NULL) free(buf);
58 for(
int i=0; i<n; i++) y[i]=buf[i];
64 int ret=
simC1(x, y, n, k, k, buf);
66 if(tmp==NULL) free(buf);
69 for(
int i=0; i<n; i++) y[i]=buf[i];
72 if(tmp==NULL) free(buf);
102 if(x==NULL || y==NULL || n<2)
return 1;
103 if(tau<0.0)
return 2;
104 if(x[0]<0.0)
return 3;
108 if(tmp!=NULL) buf=tmp;
else buf=(
double*)malloc(n*
sizeof(
double));
109 if(buf==NULL)
return 3;
112 buf[0]=0.5*y[0]*x[0];
113 for(
int i=1; i<n; i++) buf[i]=buf[i-1]+0.5*(y[i]+y[i-1])*(x[i]-x[i-1]);
116 for(
int i=0; i<n; i++) buf[i]+=tau*y[i];
122 if(dt>0.0) y[i]=2.0*buf[i]/dt;
else y[i]=0.0;
123 for(i=1; i<n-1; i++) {
124 dt=x[i+1]-x[i-1];
if(dt>0.0) y[i]=(buf[i+1]-buf[i-1])/dt;
else y[i]=y[i-1];
126 dt=x[i]-x[i-1];
if(dt>0.0) y[i]=(buf[i]-buf[i-1])/dt;
else y[i]=y[i-1];
129 if(tmp==NULL) free(buf);
159 if(n<2 || cn<1)
return(1);
160 if(t==NULL || c0==NULL || cout==NULL)
return(2);
162 if(!(k>=0.0))
return(3);
164 double c[cn+1], ci[cn+1];
165 double c_last[cn+1], ci_last[cn+1];
166 for(
int j=0; j<=cn; j++) c[j]=c_last[j]=ci[j]=ci_last[j]=0.0;
170 printf(
"\nTime\tC0\tiC0");
171 for(
int j=1; j<=cn; j++) printf(
"\tC%d", j);
174 double t_last=0.0;
if(t[0]<t_last) t_last=t[0];
175 double c0_last=0.0, c0i=0.0;
176 for(
int i=0; i<n; i++) {
178 double dt2=0.5*(t[i]-t_last);
if(!(dt2>=0.0))
return(5);
180 c0i+=(c0[i]+c0_last)*dt2;
182 double kdt=k/(1.0+dt2*k);
186 for(
int j=1; j<=cn; j++) {
187 c[j] = kdt * (ci[j-1] - ci_last[j] - dt2*c_last[j]);
188 ci[j] = ci_last[j] + dt2*(c_last[j]+c[j]);
191 for(
int j=0; j<=cn; j++) {
197 printf(
"%g\t%g\t%g", t[i], c0[i], ci[0]);
198 for(
int j=1; j<=cn; j++) printf(
"\t%g", c[j]);
203 t_last=t[i]; c0_last=c0[i];
204 for(
int j=0; j<=cn; j++) {
242 if(n<2 || cn<1)
return(1);
243 if(t==NULL || c0i==NULL || cout==NULL)
return(2);
245 if(!(k>=0.0))
return(3);
247 double c[cn+1], ci[cn+1];
248 double c_last[cn+1], ci_last[cn+1];
249 for(
int j=0; j<=cn; j++) c[j]=c_last[j]=ci[j]=ci_last[j]=0.0;
253 printf(
"\nTime\tiC0");
254 for(
int j=1; j<=cn; j++) printf(
"\tC%d", j);
257 double t_last=0.0;
if(t[0]<t_last) t_last=t[0];
258 for(
int i=0; i<n; i++) {
260 double dt2=0.5*(t[i]-t_last);
if(!(dt2>=0.0))
return(5);
262 double kdt=k/(1.0+dt2*k);
266 for(
int j=1; j<=cn; j++) {
267 c[j] = kdt * (ci[j-1] - ci_last[j] - dt2*c_last[j]);
268 ci[j] = ci_last[j] + dt2*(c_last[j]+c[j]);
271 for(
int j=0; j<=cn; j++) {
277 printf(
"%g\t%g", t[i], ci[0]);
278 for(
int j=1; j<=cn; j++) printf(
"\t%g", c[j]);
284 for(
int j=0; j<=cn; j++) {
int simC1(double *t, double *ca, const int nr, const double k1, const double k2, double *ct)
int simTTM_i(double *t, double *c0i, const int n, const double k, const int cn, double *cout)
int simDispersion(double *x, double *y, const int n, const double tau1, const double tau2, double *tmp)
int simTTM(double *t, double *c0, const int n, const double k, const int cn, double *cout)
int corDispersion(double *x, double *y, const int n, const double tau, double *tmp)
Header file for libtpccm.