|
Layers
Diffusion in heterogeneous environments
|
Header file for program 3layer. More...
#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <getopt.h>#include <string.h>#include <strings.h>#include <time.h>#include <math.h>#include <gsl/gsl_multimin.h>

Go to the source code of this file.
Data Structures | |
| struct | mse_rti_params_struct_type |
| struct | source_struct_type |
| struct | more_sources_struct_type |
Macros | |
| #define | MAXNUM_LINES 10000 |
| Maximum number of lines in input file. | |
| #define | MAX_LINELENGTH 100 |
| Maximum length of any line in input file. | |
| #define | MAXNUM_COMMENTLINES 1000 |
| Maximum number of comment lines of input file to copy to output file. | |
| #define | MAX_COMMAND_LENGTH 1000 |
| Maximum number of characters of command to copy to output file. | |
| #define | ADDITIONAL_SOURCES_STRING_LENGTH 500 |
| Maximum length of string argument to additional_sources option. | |
| #define | FALSE 0 |
| FALSE assigned to 0. | |
| #define | TRUE 1 |
| TRUE assigned to 1. | |
| #define | PI (4*atan(1.0)) |
Sets constant PI to M_PI if that is defined; otherwise, computes PI as . | |
| #define | FARADAY 96485.3399 |
| Faraday constant in C/mol. | |
| #define | SMALLNUM 2.2204460492503131e-16 |
| For comparing doubles with 0: Sets SMALLNUM to DBL_EPSILON or to GSL_DBL_EPSILON if they're defined; otherwise set to another small number. | |
| #define | IS_ZERO(x) (fabs(x) < (SMALLNUM) ? (TRUE) : (FALSE)) |
| Evaluates to TRUE if |x| < SMALLNUM, FALSE otherwise. | |
| #define | STREQ(s1, s2) (strcmp(s1,s2) == 0) |
| Compares strings s1 and s2; evaluates to TRUE if strings are equal, FALSE if not. | |
| #define | SQR(x) ((x) * (x)) |
| Computes the square of x. | |
| #define | MAX(x, y) ((x) > (y) ? (x) : (y)) |
| Computes the maximum of x and y. | |
| #define | MIN(x, y) ((x) < (y) ? (x) : (y)) |
| Computes the minimum of x and y. | |
| #define | INDEX(i, j) ((i)*(nr+1)+(j)) |
| Computes the 1D index for concentration or alpha arrays, given pseudo-2D indices i (z index) and j (r index); uses column-major ordering. | |
| #define | INDEX_FULL_P(i, j) ((i)*(2*nr-1)+nr+(j)-2) |
| Computes the 1D index for r >= 0 part of a concentration image, given pseudo-2D indices i (z index) and j (r index); uses column-major ordering. | |
| #define | INDEX_FULL_N(i, j) ((i)*(2*nr-1)+nr-(j)) |
| Computes the 1D index for r >= 0 part of a concentration image, given pseudo-2D indices i (z index) and j (r index); uses column-major ordering. | |
Functions | |
| 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 coordinates; also scales by . More... | |
| void | error (char *errorstring,...) |
| Print an error message to stderr and exit with status EXIT_FAILURE. More... | |
| void | print_usage (char *program) |
| Print usage message and exit with status EXIT_FAILURE. More... | |
| double * | create_array (int N, char *string) |
| Create an array of doubles of the specified size. More... | |
| void | get_filename (char *in, char *out) |
| Make sure that the filename is not too long. More... | |
| 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. More... | |
| int | assemble_command (int argc, char *argv[], char *command) |
| Create a string containing the command used to run the program. More... | |
| double | read_source_parameter (char *string, int nsource) |
| Read a parameter from the string argument to the additional_sources option. More... | |
| 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 function of time; also outputs the concentration as images if that option was chosen. More... | |
| double | calc_mse_rti (const gsl_vector *x, void *params) |
| Mean squared error function for simplex fitting. More... | |
| 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 an equation) More... | |
Header file for program 3layer.
Definition in file header.h.
| int assemble_command | ( | int | argc, |
| char * | argv[], | ||
| char * | command | ||
| ) |
Create a string containing the command used to run the program.
It can be very useful for the program's output file to have a comment line that contains the command used to run the program. This function assembles that command into a string from the argc and argv parameters so it can be added to the output file.
| [in] | argc | Argument count (parameter passed to main) |
| [in] | argv | Argument vector (parameter passed to main) |
| [out] | command | String containing the command line |
Definition at line 91 of file io.c.

| 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 function of time; also outputs the concentration as images if that option was chosen.
This function solves the diffusion equation in each layer
,
subject to the continuity conditions at the interfaces between layers
and the boundary condition
(total absorption) at the top, the bottom, and the side of the cylinder, where
= concentration in layer 
= free diffusion coefficient
= permeability in layer 
= source in layer 
= extracellular volume fraction in layer 
= nonspecific clearance factor in layer 
This function calls convolve3() to compute the Laplacian in cylindrical coordinates.
| [in] | nt | Number of support points in time |
| [in] | nz | Number of rows of concentration matrix |
| [in] | nr | Number of columns of concentration matrix |
| [in] | iprobe | z-index of probe location |
| [in] | jprobe | r-index of probe location |
| [in] | iz1 | z-index of SR-SP boundary |
| [in] | iz2 | z-index of SP-SO boundary |
| [in] | nolayer | Flag for whether to model a single homogeneous environment (true) or to model a 3-layer environment |
| [in] | dt | Spacing in time ( ) |
| [in] | dr | Spacing in r (in this program, ) |
| [in] | sdelay | Source delay (time before source starts) |
| [in] | sduration | Duration of source |
| [in] | alpha_so | Extracellular volume fraction in SO layer |
| [in] | theta_so | Permeability in SO layer |
| [in] | kappa_so | Nonspecific clearance factor in SO layer |
| [in] | alpha_sp | Extracellular volume fraction in SP layer |
| [in] | theta_sp | Permeability in SP layer |
| [in] | kappa_sp | Nonspecific clearance factor in SP layer |
| [in] | alpha_sr | Extracellular volume fraction in SR layer |
| [in] | theta_sr | Permeability in SR layer |
| [in] | kappa_sr | Nonspecific clearance factor in SR layer |
| [in] | dfree | Free diffusion coefficient |
| [in] | t | Time array |
| [in] | s | Source array |
| [in] | invr | Array for values |
| [out] | p | Probe array (concentration as a function of time) |
Definition at line 101 of file model.c.


| double calc_mse_rti | ( | const gsl_vector * | x, |
| void * | params | ||
| ) |
Mean squared error function for simplex fitting.
The 3layer program uses a minimization function in GSL to minimize the mean squared error between the diffusion curve calculated from the multilayer model and a diffusion curve calculated from a formula that assumes an isotropic homogeneous environment. It does so to calculate the apparent parameters and characteristic diffusion curve (for comparison purposes).
This function calculates the mean squared error between the two curves. The GSL minimization routine needs the first parameter to be a vector of doubles which represent the parameters to be fit and the second parameter to be a pointer to parameters of the function to fit (rti_theory).
The second parameter actually points to a struct of parameters. The characteristic curve calculated from rti_theory is stored in the p_theory array of this struct.
| [in] | x | Vector of doubles representing parameters to fit (alpha and theta) |
| [in,out] | params | Vector of parameters needed by rti_theory |
Definition at line 42 of file rti-theory.c.


| 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 coordinates; also scales by
.
Calculates the update terms
or
where
= output array
= scaling factors
= input array (concentration)
means convolution
= 3x3 Laplace operator (see above)
= 3x3 Laplace operator modified for 
= 3x3 derivative operator for 
Note that the index
corresponds to
.
| [in] | M | Number of columns of input matrix (z) |
| [in] | N | Number of rows of input matrix (r) |
| [in] | a | Input matrix (concentration, c) |
| [in] | scale1 | Scaling factor #1 |
| [in] | scale2 | Scaling factor #2 |
| [in] | invr | Vector of 1/r values |
| [out] | out | Output matrix |
| double* create_array | ( | int | N, |
| char * | string | ||
| ) |
| void error | ( | char * | errorstring, |
| ... | |||
| ) |
| void get_filename | ( | char * | in, |
| char * | out | ||
| ) |
Make sure that the filename is not too long.
If the input string is not to big, copy it to the output string. Otherwise, exit with an error message. This function is used to check that the user input filename is not too long.
| [in] | in | Input string = the user input filename (or base filename) |
| [out] | out | Output string = the input string, if not too long |
Definition at line 25 of file io.c.


| 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.
From the last argument on the command line, determine the input file name and the default output file name. (If the output file name is specified on the command line, it will be used instead of the default output file name determined here.)
If the argument has an extension, it is the input filename; remove the extension to get the basename and add the default output filename extension to get the default output filename.
If the argument has no extension, it is the basename; then add the default extensions to get the input filename and the default output filename.
| [in] | argstring | Final command-line argument |
| [in] | inf_extension | Default extension for input file |
| [in] | outf_extension | Default extension for output file |
| [out] | infilename | Name of input file |
| [out] | outfilename | Name of output file |
Definition at line 60 of file io.c.


| void print_usage | ( | char * | program | ) |
| double read_source_parameter | ( | char * | string, |
| int | nsource | ||
| ) |
Read a parameter from the string argument to the additional_sources option.
The additional_sources option to 3layer takes several arguments. (The total number of arguments depends on the number of extra sources.) The getopt_long function (used in the main() function to parse 3layer's options) takes only one argument per option, so for additional_sources's argument use a string that contains the several arguments that additional_sources needs.
This function uses strtok to parse the string to obtain the next parameter. The two arguments for this function are used only for diagnostic purposes – if there is an error, the function aborts with an error message that lists these two arguments.
The first element of the string (the number of extra sources) was previously obtained with the first call to strtok, and subsequent calls to strtok (via this function) use NULL rather than the name of the string.
| [in] | string | String containing the type of parameter to be read |
| [out] | nsource | The number of the source whose parameter is being read |
Definition at line 153 of file io.c.


| 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 an equation)
| [in] | nt | Number of time points of calculation |
| [in] | spdist | Distance between source and probe |
| [in] | samplitude | Amplitude of source |
| [in] | sdelay | Source delay (time before source starts) |
| [in] | sduration | Duration of source |
| [in] | kappa | Nonspecific clearance factor |
| [in] | dfree | Free diffusion coefficient |
| [in] | alpha | Extracellular volume fraction |
| [in] | theta | Permeability |
| [in] | t | Time array |
| [out] | p_theory | Probe array (concentration as a function of time) |
Definition at line 88 of file rti-theory.c.

1.8.11