HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
linearadr.h File Reference

Linear Advection-Diffusion-Reaction model. More...

#include <basic.h>

Go to the source code of this file.

Data Structures

struct  LinearADR
 Structure containing variables and parameters specific to the linear advection-diffusion-reaction model. More...
 

Macros

#define _LINEAR_ADVECTION_DIFFUSION_REACTION_   "linear-advection-diffusion-reaction"
 

Functions

int LinearADRInitialize (void *, void *)
 
int LinearADRCleanup (void *)
 

Detailed Description

Linear Advection-Diffusion-Reaction model.

Author
Debojyoti Ghosh

Linear Advection-Diffusion-Reachtion

\begin{equation} \frac {\partial u} {\partial t} + \sum_d \frac {\partial} {\partial x_d} \left( a_d d \right) = \sum_d \nu_d \frac {\partial^2 u} {\partial x_d^2} + k u \end{equation}

where \(a_d\) are the advection speeds, \(\nu_d\) are the diffusion coefficients, and \(k\) is the reaction rate.

Definition in file linearadr.h.


Data Structure Documentation

struct LinearADR

Structure containing variables and parameters specific to the linear advection-diffusion-reaction model.

This structure contains the physical parameters, variables, and function pointers specific to the linear advection-diffusion-reaction equation.

Definition at line 37 of file linearadr.h.

Data Fields
int constant_advection

Is the advection field constant (1) or spatially-varying (0)

char adv_filename[_MAX_STRING_SIZE_]

Filename of file to read in spatially-varying advection field from

int adv_arr_size

Size of the advection array: depends on whether advection coeff is constant or spatially-varying

double * a

advection speed for each variable along each dimension

double * d

diffusion coefficient for each variable along each dimension

char centered_flux[_MAX_STRING_SIZE_]

turn off upwinding and just take arithmetic average of left and right biased fluxes?

Macro Definition Documentation

#define _LINEAR_ADVECTION_DIFFUSION_REACTION_   "linear-advection-diffusion-reaction"

Linear advection-diffusion-reaction model

Definition at line 21 of file linearadr.h.

Function Documentation

int LinearADRInitialize ( void *  s,
void *  m 
)

Initialize the linear advection-diffusion-reaction model

Initialize the linear advection-diffusion-reaction physics module - allocate and set physics-related parameters, read physics-related inputs from file, and set the physics-related function pointers in HyPar

This file reads the file "physics.inp" that must have the following format:

begin
    <keyword>   <value>
    <keyword>   <value>
    <keyword>   <value>
    ...
    <keyword>   <value>
end

where the list of keywords are:

Keyword name Type Variable Default value
advection_filename char[] LinearADR::adv_filename "none"
advection double[] LinearADR::a 0
diffusion double[] LinearADR::d 0
centered_flux char[] LinearADR::centered_flux "no"

Note:

  • "physics.inp" is optional; if absent, default values will be used.
  • Please do not specify both "advection" and "advection_filename"!
Parameters
sSolver object of type HyPar
mObject of type MPIVariables containing MPI-related info

Definition at line 59 of file LinearADRInitialize.c.

61 {
62  HyPar *solver = (HyPar*) s;
63  MPIVariables *mpi = (MPIVariables*) m;
64  LinearADR *physics = (LinearADR*) solver->physics;
65  int i,ferr;
66 
67  static int count = 0;
68 
69  /* default values */
70  physics->constant_advection = -1;
71  strcpy(physics->adv_filename,"none");
72  physics->a = NULL;
73  physics->adv_arr_size = -1;
74  strcpy(physics->centered_flux,"no");
75 
76  physics->d = (double*) calloc (solver->ndims*solver->nvars,sizeof(double));
77  _ArraySetValue_(physics->d,solver->ndims*solver->nvars,0.0);
78 
79  /* reading physical model specific inputs - all processes */
80  if (!mpi->rank) {
81 
82  FILE *in;
83  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
84  in = fopen("physics.inp","r");
85 
86  if (!in) {
87 
88  fprintf(stderr,"Error: File \"physics.inp\" not found.\n");
89  return(1);
90 
91  } else {
92 
93  char word[_MAX_STRING_SIZE_];
94  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
95  if (!strcmp(word, "begin")) {
96  while (strcmp(word, "end")) {
97 
98  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
99 
100  if (!strcmp(word, "advection_filename")) {
101  if (physics->constant_advection != -1) {
102  fprintf(stderr,"Error in LinearADRInitialize():\n");
103  fprintf(stderr,"Maybe advection_filename and advection are both specified.\n");
104  return 1;
105  } else {
106  /* read filename for spatially-varying advection field */
107  physics->constant_advection = 0;
108  physics->adv_arr_size = solver->npoints_local_wghosts*solver->ndims*solver->nvars;
109  physics->a = (double*) calloc ( physics->adv_arr_size, sizeof(double) );
110  _ArraySetValue_(physics->a, physics->adv_arr_size, 0.0);
111  ferr = fscanf(in,"%s",physics->adv_filename); if (ferr != 1) return(ferr);
112  }
113  } else if (!strcmp(word, "advection")) {
114  if (physics->constant_advection != -1) {
115  fprintf(stderr,"Error in LinearADRInitialize():\n");
116  fprintf(stderr,"Maybe advection_filename and advection are both specified.\n");
117  return 1;
118  } else {
119  /* read advection coefficients */
120  physics->constant_advection = 1;
121  physics->adv_arr_size = solver->ndims*solver->nvars;
122  physics->a = (double*) calloc ( physics->adv_arr_size, sizeof(double) );
123  for (i=0; i<solver->ndims*solver->nvars; i++) ferr = fscanf(in,"%lf",&physics->a[i]);
124  if (ferr != 1) return(1);
125  }
126  } else if (!strcmp(word, "diffusion")) {
127  /* read diffusion coefficients */
128  for (i=0; i<solver->ndims*solver->nvars; i++) ferr = fscanf(in,"%lf",&physics->d[i]);
129  if (ferr != 1) return(1);
130  } else if (!strcmp(word, "centered_flux")) {
131  ferr = fscanf(in, "%s", physics->centered_flux);
132  if (ferr != 1) return(ferr);
133  } else if (strcmp(word,"end")) {
134  char useless[_MAX_STRING_SIZE_];
135  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
136  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",word,useless);
137  printf("recognized or extraneous. Ignoring.\n");
138  }
139  }
140 
141  } else {
142 
143  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
144  return(1);
145 
146  }
147  }
148 
149  fclose(in);
150 
151  }
152 
153 #ifndef serial
154  MPIBroadcast_integer(&physics->constant_advection,1,0,&mpi->world);
155  MPIBroadcast_integer(&physics->adv_arr_size,1,0,&mpi->world);
156 #endif
157 
158  if (mpi->rank) {
159  physics->a = (double*) calloc (physics->adv_arr_size,sizeof(double));
160  _ArraySetValue_(physics->a, physics->adv_arr_size, 0.0);
161  }
162 
163  if (physics->constant_advection == 1) {
164 #ifndef serial
165  MPIBroadcast_double(physics->a,physics->adv_arr_size,0,&mpi->world);
166 #endif
167  } else if (physics->constant_advection == 0) {
168 #ifndef serial
170 #endif
171  }
172 
173 #ifndef serial
174  MPIBroadcast_double(physics->d,solver->ndims*solver->nvars,0,&mpi->world);
176 #endif
177 
178  if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
179  if (!mpi->rank) {
180  fprintf(stderr,"Error in LinearADRInitialize: This physical model does not have a splitting ");
181  fprintf(stderr,"of the hyperbolic term defined.\n");
182  }
183  return(1);
184  }
185 
186  /* initializing physical model-specific functions */
189  solver->FFunction = LinearADRAdvection;
190  solver->GFunction = LinearADRDiffusionG;
191  solver->HFunction = LinearADRDiffusionH;
192  solver->SFunction = LinearADRReaction;
195 
196  if (!strcmp(physics->centered_flux,"no")) {
197  solver->Upwind = LinearADRUpwind;
198  } else {
199  solver->Upwind = LinearADRCenteredFlux;
200  }
201 
202  if (physics->constant_advection == 0) {
205  } else {
206  solver->PhysicsInput = NULL;
207  solver->PhysicsOutput = NULL;
208  }
209 
210  count++;
211  return(0);
212 }
int npoints_local_wghosts
Definition: hypar.h:42
#define _ArraySetValue_(x, size, value)
int(* JFunction)(double *, double *, void *, int, int, int)
Definition: hypar.h:326
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
char adv_filename[_MAX_STRING_SIZE_]
Definition: linearadr.h:43
double * d
Definition: linearadr.h:53
int MPIBroadcast_double(double *, int, int, void *)
Definition: MPIBroadcast.c:9
int adv_arr_size
Definition: linearadr.h:47
int(* HFunction)(double *, double *, int, int, void *, double)
Definition: hypar.h:313
void * physics
Definition: hypar.h:266
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
Structure containing variables and parameters specific to the linear advection-diffusion-reaction mod...
Definition: linearadr.h:37
int(* PhysicsOutput)(void *, void *, double)
Definition: hypar.h:347
double * a
Definition: linearadr.h:50
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
int(* PhysicsInput)(void *, void *, int, int, int *)
Definition: hypar.h:351
int LinearADRWriteAdvField(void *, void *, double)
int LinearADRCenteredFlux(double *, double *, double *, double *, double *, double *, int, void *, double)
MPI_Comm world
#define _MAX_STRING_SIZE_
Definition: basic.h:14
double LinearADRComputeCFL(void *s, void *m, double dt, double t)
int LinearADRDiffusionG(double *f, double *u, int dir, void *s, double t)
double(* ComputeDiffNumber)(void *, void *, double, double)
Definition: hypar.h:272
int LinearADRDiffusionJacobian(double *, double *, void *, int, int)
int LinearADRAdvection(double *f, double *u, int dir, void *s, double t)
int LinearADRDiffusionH(double *f, double *u, int dir1, int dir2, void *s, double t)
int LinearADRAdvectionField(void *s, void *m, int idx, int nsims, int *dim_adv)
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
int(* KFunction)(double *, double *, void *, int, int)
Definition: hypar.h:331
int nvars
Definition: hypar.h:29
char centered_flux[_MAX_STRING_SIZE_]
Definition: linearadr.h:57
int MPIBroadcast_character(char *, int, int, void *)
Definition: MPIBroadcast.c:37
int constant_advection
Definition: linearadr.h:40
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
int ndims
Definition: hypar.h:26
int LinearADRReaction()
int LinearADRAdvectionJacobian(double *, double *, void *, int, int, int)
double LinearADRComputeDiffNumber(void *s, void *m, double dt, double t)
Structure of MPI-related variables.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int LinearADRUpwind(double *, double *, double *, double *, double *, double *, int, void *, double)
int(* GFunction)(double *, double *, int, void *, double)
Definition: hypar.h:310
int MPIBroadcast_integer(int *, int, int, void *)
Definition: MPIBroadcast.c:23
int LinearADRCleanup ( void *  s)

Clean up the linear advection-diffusion-reaction model

Parameters
sSolver object of type HyPar

Definition at line 10 of file LinearADRCleanup.c.

11 {
12  LinearADR *physics = (LinearADR*) s;
13  if (physics->a) free(physics->a);
14  if (physics->d) free(physics->d);
15 
16  return(0);
17 }
double * d
Definition: linearadr.h:53
Structure containing variables and parameters specific to the linear advection-diffusion-reaction mod...
Definition: linearadr.h:37
double * a
Definition: linearadr.h:50