Layers
Diffusion in heterogeneous environments
Macros | Functions
header.h File Reference

Header file for program fit-layer. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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 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 $ 4 \: tan^{-1}(1) $.
 
#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.
 

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 $ \theta D_{free} $. More...
 
void error (char *errorstring,...)
 Print an error message to stderr and exit with status EXIT_FAILURE. More...
 
void print_usage_fit_layer (char *program)
 Print usage message and exit with status EXIT_FAILURE. More...
 
void check_filename (char *in, char *out)
 Make sure that the filename is not too long. More...
 
double * create_array (int N, char *string)
 Create an array of doubles of the specified size. More...
 
int assemble_command (int argc, char *argv[], char *command)
 Create a string containing the command used to run the program. More...
 
void calc_diffusion_curve_layer_fit_layer (int nt, int nz, int nr, int iprobe, int jprobe, int iz1, int iz2, int nolayer, double dt, double dr, double sd, double st, 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, double *p)
 Calculates the concentration as a function of space and time and returns the probe concentration as a function of time. More...
 

Detailed Description

Header file for program fit-layer.

Author
David Lewis, CABI, NKI
Date
2012-2013

Definition in file header.h.

Function Documentation

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.

Parameters
[in]argcArgument count (parameter passed to main)
[in]argvArgument vector (parameter passed to main)
[out]commandString containing the command line
Returns
Number of elements on the command line

Definition at line 91 of file io.c.

void calc_diffusion_curve_layer_fit_layer ( int  nt,
int  nz,
int  nr,
int  iprobe,
int  jprobe,
int  iz1,
int  iz2,
int  nolayer,
double  dt,
double  dr,
double  sd,
double  st,
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,
double *  p 
)

Calculates the concentration as a function of space and time and returns the probe concentration as a function of time.

This function solves the diffusion equation in each layer $ k $ ,

\[ \frac{\partial c_k(\vec r, t)}{\partial t} = D_{free} \theta_k \nabla^2{c_k(\vec r, t)} + s/\alpha_k - \kappa_k c_k(\vec r, t) \quad , \]

subject to the continuity conditions at the interfaces between layers

\[ c(\vec r_k, t) = c(\vec r_{k+1}, t) \quad \]

\[ \alpha_k \theta_k \nabla c(\vec r_k, t) = \alpha_{k+1} \theta_{k+1} \nabla c(\vec r_{k+1}, t) \quad \]

and the boundary condition $ c(\vec r, t) = 0 $ (total absorption) at the top, the bottom, and the side of the cylinder, where

$ c_k(\vec r, t) $ = concentration in layer $ k $

$ D_{free} $ = free diffusion coefficient

$ \theta_k $ = permeability in layer $ k $

$ s_k(\vec r, t) $ = source in layer $ k $

$ \alpha_k $ = extracellular volume fraction in layer $ k $

$ \kappa_k $ = nonspecific clearance factor in layer $ k $

This function calls convolve3() to compute the Laplacian in cylindrical coordinates.

Parameters
[in]ntNumber of support points in time
[in]nzNumber of rows of concentration matrix
[in]nrNumber of columns of concentration matrix
[in]iprobez-index of probe location
[in]jprober-index of probe location
[in]iz1z-index of SR-SP boundary
[in]iz2z-index of SP-SO boundary
[in]nolayerFlag for whether to model a single homogeneous environment (true) or to model a 3-layer environment
[in]dtSpacing in time ( $ t_{i+1} = t_i + \Delta t $)
[in]drSpacing in r (in this program, $ \Delta z = \Delta r $)
[in]sdSource delay (time before source starts)
[in]stDuration of source
[in]alpha_soExtracellular volume fraction in SO layer
[in]theta_soPermeability in SO layer
[in]kappa_soNonspecific clearance factor in SO layer
[in]alpha_spExtracellular volume fraction in SP layer
[in]theta_spPermeability in SP layer
[in]kappa_spNonspecific clearance factor in SP layer
[in]alpha_srExtracellular volume fraction in SR layer
[in]theta_srPermeability in SR layer
[in]kappa_srNonspecific clearance factor in SR layer
[in]dfreeFree diffusion coefficient
[in]tTime array
[in]sSource array
[in]invrArray for $ 1/r $ values
[out]pProbe array (concentration as a function of time)

Definition at line 94 of file model.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void check_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.

Parameters
[in]inInput string = the user input filename (or base filename)
[out]outOutput string = the input string, if not too long

Definition at line 103 of file extras.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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 $ \theta D_{free} $.

Calculates the update terms

\[ \mathbf{out} = s_1 \mathbf{L} * \mathbf{a} + \frac{s_2}{r} \mathbf{D} * \mathbf{a} \qquad (r \neq 0) \]

or

\[ \mathbf{out} = s_1 \mathbf{L0} * \mathbf{a} \qquad (r = 0) \]

where

$ \mathbf{out} $ = output array

$ s_1, s_2 $ = scaling factors

$ \mathbf{a} $ = input array (concentration)

$ * $ means convolution

$ \mathbf{L} $ = 3x3 Laplace operator (see above)

$ \mathbf{L0} $ = 3x3 Laplace operator modified for $ r = 0 $

$ \mathbf{D} $ = 3x3 derivative operator for $ r $

Note that the index $ j = 1 $ corresponds to $ r = 0 $.

Parameters
[in]MNumber of columns of input matrix (z)
[in]NNumber of rows of input matrix (r)
[in]aInput matrix (concentration, c)
[in]scale1Scaling factor #1
[in]scale2Scaling factor #2
[in]invrVector of 1/r values
[out]outOutput matrix

Definition at line 133 of file convo.c.

Here is the caller graph for this function:

double* create_array ( int  N,
char *  string 
)

Create an array of doubles of the specified size.

Also initialize the array to all 0.

Parameters
[in]NNumber of elements in array
[in]stringString containing a description of the array (for debugging purposes)
Returns
Pointer to the new array

Definition at line 105 of file extras.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void error ( char *  errorstring,
  ... 
)

Print an error message to stderr and exit with status EXIT_FAILURE.

Parameters
[in]errorstringString containing error message (variable-length argument list, like printf)

Definition at line 20 of file extras.c.

Here is the caller graph for this function:

void print_usage_fit_layer ( char *  program)

Print usage message and exit with status EXIT_FAILURE.

Parameters
[in]programString containing the name of the program

Definition at line 43 of file extras.c.

Here is the caller graph for this function: