Layers
Diffusion in heterogeneous environments
header.h
Go to the documentation of this file.
1 
13 // Includes
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <stdarg.h>
17 #include <getopt.h>
18 #include <string.h>
19 #include <strings.h>
20 #include <time.h>
21 #include <math.h>
22 #include <gsl/gsl_multimin.h>
23 
24 
25 // Constants
26 
28 #define MAXNUM_LINES 10000
29 
31 #define MAX_LINELENGTH 100
32 
34 #define MAXNUM_COMMENTLINES 1000
35 
37 #define MAX_COMMAND_LENGTH 1000
38 
40 #define ADDITIONAL_SOURCES_STRING_LENGTH 500
41 
43 #define FALSE 0
44 
46 #define TRUE 1
47 
49 #ifdef M_PI
50 # define PI M_PI
51 #else
52 # define PI (4*atan(1.0))
53 #endif
54 
56 #define FARADAY 96485.3399
57 
59 #ifdef DBL_EPSILON
60 # define SMALLNUM DBL_EPSILON
61 #elif defined GSL_DBL_EPSILON
62 # define SMALLNUM GSL_DBL_EPSILON
63 #else
64 # define SMALLNUM 2.2204460492503131e-16
65 #endif
66 
67 
68 // Macros
69 
74 #define IS_ZERO(x) (fabs(x) < (SMALLNUM) ? (TRUE) : (FALSE))
75 
82 #define STREQ(s1,s2) (strcmp(s1,s2) == 0)
83 
88 #define SQR(x) ((x) * (x))
89 
94 #define MAX(x,y) ((x) > (y) ? (x) : (y))
95 
100 #define MIN(x,y) ((x) < (y) ? (x) : (y))
101 
102 
103 /* Define a macro for calculating the 1D index of the arrays
104  * from the 2D indices i and j, in order to make the code simpler.
105  * The 2D indices are: i corresponds to z and j corresponds to r.
106  * The number of rows in most of these matrices is (nr+1)
107  */
112 #define INDEX(i,j) ((i)*(nr+1)+(j))
113 
114 
115 /* Define macros for calculating the 1D indices of the arrays
116  * that have -rmax < r < rmax, which I output as images in model.c.
117  * The parts of the array corresponding to r >= 0 are taken from the
118  * concentration arrays in cylindrical coordinates (indexed with
119  * INDEX(i,j)) and the parts of the array corresponding to r < 0
120  * are obtained from symmetry. The first macro is for r >=0 and
121  * the second is for r < 0.
122  */
127 #define INDEX_FULL_P(i,j) ((i)*(2*nr-1)+nr+(j)-2)
128 
133 #define INDEX_FULL_N(i,j) ((i)*(2*nr-1)+nr-(j))
134 
135 
136 // Struct typedefs
137 
141 typedef struct {
142  int nt;
143  double spdist;
144  double samplitude;
145  double sdelay;
146  double sduration;
147  double kappa;
148  double dfree;
149  double alpha;
150  double theta;
151  double *t;
152  double *p_model;
153  double *p_theory;
155 
159 typedef struct {
160  double sz;
161  double sr;
162  double crnt;
164 
168 typedef struct {
169  int n;
172 
173 
174 
175 
176 // Function prototypes
177 
178 // convo.c
179 void convolve3(int M, int N, double *a, double scale1, double scale2, double *invr, double *out);
180 
181 // extras.c
182 void error(char *errorstring, ...);
183 
184 void print_usage(char *program);
185 
186 double *create_array(int N, char *string);
187 
188 //io.c
189 void get_filename(char *in, char *out);
190 
191 void get_io_filenames(char *argstring, const char *inf_extension, const char *outf_extension, char *infilename, char *outfilename);
192 
193 int assemble_command(int argc, char *argv[], char *command);
194 
195 double read_source_parameter(char *string, int nsource);
196 
197 // model.c
198 void calc_diffusion_curve_layer(int nt, int nz, int nr, int iprobe, int jprobe, int iz1, int iz2, int nolayer, double dt, double dr, double sdelay, double sduration, double alpha_so, double theta_so, double kappa_so, double alpha_sp, double theta_sp, double kappa_sp, double alpha_sr, double theta_sr, double kappa_sr, double dfree, double *t, double *s, double *invr, char *imagebasename, double image_spacing, double *p);
199 
200 // rti-theory.c
201 double calc_mse_rti(const gsl_vector *x, void *params);
202 
203 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);
204 
int n
Number of additional sources.
Definition: header.h:169
double sr
r-coordinate of additional source
Definition: header.h:161
double * p_theory
Probe concentration from homogeneous model (characteristic curve)
Definition: header.h:153
void get_io_filenames(char *argstring, const char *inf_extension, const char *outf_extension, char *infilename, char *outfilename)
Determine the input filename and the default output file name.
Definition: io.c:60
double * create_array(int N, char *string)
Create an array of doubles of the specified size.
Definition: extras.c:105
void get_filename(char *in, char *out)
Make sure that the filename is not too long.
Definition: io.c:25
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
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
double * p_model
Probe concentration from multilayer model.
Definition: header.h:152
double sz
z-coordinate of additional source
Definition: header.h:160
double * t
Time array.
Definition: header.h:151
double samplitude
Amplitude of source.
Definition: header.h:144
void convolve3(int M, int N, double *a, double scale1, double scale2, double *invr, double *out)
Calculates updates to the concentration in a layer by applying the Laplacian in cylindrical coordinat...
Definition: convo.c:133
double dfree
Free diffusion coefficient.
Definition: header.h:148
double spdist
Distance between source and probe.
Definition: header.h:143
source_struct_type * source
Struct of parameters for each additional source.
Definition: header.h:170
int assemble_command(int argc, char *argv[], char *command)
Create a string containing the command used to run the program.
Definition: io.c:91
void calc_diffusion_curve_layer(int nt, int nz, int nr, int iprobe, int jprobe, int iz1, int iz2, int nolayer, double dt, double dr, double sdelay, double sduration, double alpha_so, double theta_so, double kappa_so, double alpha_sp, double theta_sp, double kappa_sp, double alpha_sr, double theta_sr, double kappa_sr, double dfree, double *t, double *s, double *invr, char *imagebasename, double image_spacing, double *p)
Calculates the concentration as a function of space and time and returns the probe concentration as a...
Definition: model.c:101
double alpha
Extracellular volume fraction.
Definition: header.h:149
double crnt
Current of additional source.
Definition: header.h:162
void print_usage(char *program)
Print usage message and exit with status EXIT_FAILURE.
Definition: extras.c:40
void error(char *errorstring,...)
Print an error message to stderr and exit with status EXIT_FAILURE.
Definition: extras.c:20
double theta
Permeability.
Definition: header.h:150
int nt
Number of time points of calculation.
Definition: header.h:142
double read_source_parameter(char *string, int nsource)
Read a parameter from the string argument to the additional_sources option.
Definition: io.c:153
double calc_mse_rti(const gsl_vector *x, void *params)
Mean squared error function for simplex fitting.
Definition: rti-theory.c:42