Layers
Diffusion in heterogeneous environments
rti-theory.c
Go to the documentation of this file.
1 
14 #include "header.h"
15 
42 double calc_mse_rti(const gsl_vector *x, void *params)
43 {
44  int i = -1;
46  int nt = p->nt;
47 
48 
49  p->alpha = gsl_vector_get(x, 0);
50  p->theta = gsl_vector_get(x, 1);
51  if (p->alpha <= 0.001) p->alpha = 0.001;
52  if (p->theta <= 0.001) p->theta = 0.001;
53 
54  /* Call the rti_theory function */
55  rti_theory(nt, p->spdist, p->samplitude, p->sdelay, p->sduration, p->kappa, p->dfree,
56  p->alpha, p->theta, p->t, p->p_theory);
57 
58  double mse = 0.;
59 
60  for (i=1; i<nt; i++) {
61  mse += SQR(p->p_model[i] - p->p_theory[i]);
62  }
63  mse /= nt;
64 
65  return mse;
66 }
67 
68 
88 void rti_theory(int nt, double spdist, double samplitude, double sdelay, double sduration, double kappa, double dfree, double alpha, double theta, double *t, double *p_theory)
89 {
90  int i;
91 
92  double dstar = theta * dfree;
93  double ampl = samplitude / (4.0 * PI * alpha * dstar * spdist);
94 
95  for (i=0; i<nt; i++) {
96  if (t[i] <= sdelay) {
97  p_theory[i] = 0.;
98  } else {
99  p_theory[i] = ampl * erfc( spdist /
100  (2.0 * sqrt(dstar * (t[i] - sdelay))) );
101  if (t[i] > sdelay + sduration)
102  p_theory[i] = p_theory[i] - ampl * erfc( spdist /
103  (2.0 * sqrt(dstar * (t[i] - (sdelay + sduration)))) );
104  }
105  }
106 }
107 
#define SQR(x)
Computes the square of x.
Definition: header.h:88
double * p_theory
Probe concentration from homogeneous model (characteristic curve)
Definition: header.h:153
Header file for program 3layer.
double sduration
Duration of source.
Definition: header.h:146
double kappa
Nonspecific clearance factor.
Definition: header.h:147
double sdelay
Source delay (time before source starts)
Definition: header.h:145
double * p_model
Probe concentration from multilayer model.
Definition: header.h:152
double calc_mse_rti(const gsl_vector *x, void *params)
Mean squared error function for simplex fitting.
Definition: rti-theory.c:42
double * t
Time array.
Definition: header.h:151
double samplitude
Amplitude of source.
Definition: header.h:144
double dfree
Free diffusion coefficient.
Definition: header.h:148
double spdist
Distance between source and probe.
Definition: header.h:143
double alpha
Extracellular volume fraction.
Definition: header.h:149
void rti_theory(int nt, double spdist, double samplitude, double sdelay, double sduration, double kappa, double dfree, double alpha, double theta, double *t, double *p_theory)
Calculates RTI data for diffusion in an isotropic, homogeneous environment (direct calculation from a...
Definition: rti-theory.c:88
#define PI
Sets constant PI to M_PI if that is defined; otherwise, computes PI as .
Definition: header.h:52
double theta
Permeability.
Definition: header.h:150
int nt
Number of time points of calculation.
Definition: header.h:142