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

Initialize the Burgers module. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <bandedmatrix.h>
#include <physicalmodels/burgers.h>
#include <mpivars.h>
#include <hypar.h>

Go to the source code of this file.

Functions

double BurgersComputeCFL (void *, void *, double, double)
 
int BurgersAdvection (double *, double *, int, void *, double)
 
int BurgersUpwind (double *, double *, double *, double *, double *, double *, int, void *, double)
 
int BurgersInitialize (void *s, void *m)
 

Detailed Description

Initialize the Burgers module.

Author
John Loffeld

Definition in file BurgersInitialize.c.

Function Documentation

double BurgersComputeCFL ( void *  s,
void *  m,
double  dt,
double  t 
)

Computes the maximum CFL number over the domain. Note that the CFL is computed over the local domain on this processor only.

Parameters
sSolver object of type HyPar
mMPI object of type MPIVariables
dtTime step size for which to compute the CFL
tTime

Definition at line 15 of file BurgersComputeCFL.c.

20 {
21  HyPar *solver = (HyPar*) s;
22  Burgers *params = (Burgers*) solver->physics;
23 
24  int ndims = solver->ndims;
25  int nvars = solver->nvars;
26  int ghosts = solver->ghosts;
27  int *dim = solver->dim_local;
28  double *u = solver->u;
29 
30  int index[ndims], dir, v;
31 
32  double max_cfl = 0;
33  int done = 0; _ArraySetValue_(index,ndims,0);
34  while (!done) {
35  int p; _ArrayIndex1D_(ndims,dim,index,ghosts,p);
36  for (v=0; v<nvars; v++) {
37  for (dir=0; dir<ndims; dir++) {
38  double dxinv;
39  _GetCoordinate_(dir,index[dir],dim,ghosts,solver->dxinv,dxinv); /* 1/dx */
40  double local_cfl = u[nvars*p+v]*dt*dxinv;
41  if (local_cfl > max_cfl) max_cfl = local_cfl;
42  }
43  }
44  _ArrayIncrementIndex_(ndims,dim,index,done);
45  }
46 
47  return(max_cfl);
48 }
#define _ArraySetValue_(x, size, value)
double * u
Definition: hypar.h:116
#define _ArrayIncrementIndex_(N, imax, i, done)
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
#define _GetCoordinate_(dir, i, dim, ghosts, x, coord)
Definition: basic.h:31
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
int nvars
Definition: hypar.h:29
double * dxinv
Definition: hypar.h:110
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int BurgersAdvection ( double *  f,
double *  u,
int  dir,
void *  s,
double  t 
)

Compute the hyperbolic flux over the local domain.

\begin{equation} {\bf F}\left({\bf u}\right) = 0.5 {\bf u}^2 \end{equation}

Parameters
fArray to hold the computed flux (same size and layout as u)
uArray containing the conserved solution
dirSpatial dimension
sSolver object of type HyPar
tCurrent time

Definition at line 17 of file BurgersAdvection.c.

23 {
24  HyPar *solver = (HyPar*) s;
25  Burgers *param = (Burgers*) solver->physics;
26  int i, v;
27 
28  int *dim = solver->dim_local;
29  int ghosts = solver->ghosts;
30  int ndims = solver->ndims;
31  int nvars = solver->nvars;
32  int index[ndims], bounds[ndims], offset[ndims];
33 
34  /* set bounds for array index to include ghost points */
35  _ArrayCopy1D_(dim,bounds,ndims);
36  for (i=0; i<ndims; i++) bounds[i] += 2*ghosts;
37 
38  /* set offset such that index is compatible with ghost point arrangement */
39  _ArraySetValue_(offset,ndims,-ghosts);
40 
41  int done = 0; _ArraySetValue_(index,ndims,0);
42  while (!done) {
43  int p; _ArrayIndex1DWO_(ndims,dim,index,offset,ghosts,p);
44  for (v = 0; v < nvars; v++) f[nvars*p+v] = 0.5 * u[nvars*p+v] * u[nvars*p+v];
45  _ArrayIncrementIndex_(ndims,bounds,index,done);
46  }
47 
48  return(0);
49 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
int ndims
Definition: hypar.h:26
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int BurgersUpwind ( double *  fI,
double *  fL,
double *  fR,
double *  uL,
double *  uR,
double *  u,
int  dir,
void *  s,
double  t 
)

Upwinding scheme for the Burgers equations

Parameters
fIComputed upwind interface flux
fLLeft-biased reconstructed interface flux
fRRight-biased reconstructed interface flux
uLLeft-biased reconstructed interface solution
uRRight-biased reconstructed interface solution
uCell-centered solution
dirSpatial dimension
sSolver object of type HyPar
tCurrent solution time

Definition at line 15 of file BurgersUpwind.c.

25 {
26  HyPar *solver = (HyPar*) s;
27  Burgers *param = (Burgers*) solver->physics;
28  int done,v;
29 
30  int ndims = solver->ndims;
31  int nvars = solver->nvars;
32  int *dim = solver->dim_local;
33  int ghosts = solver->ghosts;
34 
35  int index_outer[ndims], index_inter[ndims], bounds_outer[ndims], bounds_inter[ndims];
36  _ArrayCopy1D_(dim,bounds_outer,ndims); bounds_outer[dir] = 1;
37  _ArrayCopy1D_(dim,bounds_inter,ndims); bounds_inter[dir] += 1;
38 
39  done = 0; _ArraySetValue_(index_outer,ndims,0);
40  while (!done) {
41  _ArrayCopy1D_(index_outer,index_inter,ndims);
42  for (index_inter[dir] = 0; index_inter[dir] < bounds_inter[dir]; index_inter[dir]++) {
43 
44  int p; _ArrayIndex1D_(ndims,bounds_inter,index_inter,0,p);
45  int indexL[ndims]; _ArrayCopy1D_(index_inter,indexL,ndims); indexL[dir]--;
46  int indexR[ndims]; _ArrayCopy1D_(index_inter,indexR,ndims);
47  int pL; _ArrayIndex1D_(ndims,dim,indexL,ghosts,pL);
48  int pR; _ArrayIndex1D_(ndims,dim,indexR,ghosts,pR);
49 
50  for (v = 0; v < nvars; v++) {
51  double eigL = u[nvars*pL+v],
52  eigR = u[nvars*pR+v];
53 
54  if ((eigL > 0) && (eigR > 0)) {
55  fI[nvars*p+v] = fL[nvars*p+v];
56  } else if ((eigL < 0) && (eigR < 0)) {
57  fI[nvars*p+v] = fR[nvars*p+v];
58  } else {
59  double alpha = max(absolute(eigL), absolute(eigR));
60  fI[nvars*p+v] = 0.5 * (fL[nvars*p+v] + fR[nvars*p+v] - alpha * (uR[nvars*p+v] - uL[nvars*p+v]));
61  }
62  }
63 
64  }
65  _ArrayIncrementIndex_(ndims,bounds_outer,index_outer,done);
66 
67  }
68 
69  return(0);
70 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
void * physics
Definition: hypar.h:266
int * dim_local
Definition: hypar.h:37
int ghosts
Definition: hypar.h:52
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayCopy1D_(x, y, size)
int nvars
Definition: hypar.h:29
int ndims
Definition: hypar.h:26
#define absolute(a)
Definition: math_ops.h:32
#define max(a, b)
Definition: math_ops.h:18
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int BurgersInitialize ( void *  s,
void *  m 
)

Initialize the nonlinear Burgers physics module - allocate and set physics-related parameters, read physics-related inputs from file, and set the physics-related function pointers in HyPar

Parameters
sSolver object of type HyPar
mObject of type MPIVariables containing MPI-related info

Definition at line 25 of file BurgersInitialize.c.

28 {
29  HyPar *solver = (HyPar*) s;
30  MPIVariables *mpi = (MPIVariables*) m;
31  Burgers *physics = (Burgers*) solver->physics;
32  int i, ferr;
33 
34  static int count = 0;
35 
36  /* reading physical model specific inputs - all processes */
37  if (!mpi->rank) {
38  FILE *in;
39  in = fopen("physics.inp","r");
40  if (in) {
41  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
42  char word[_MAX_STRING_SIZE_];
43  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
44  if (!strcmp(word, "begin")){
45  while (strcmp(word, "end")){
46  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
47  if (strcmp(word,"end")) {
48  char useless[_MAX_STRING_SIZE_];
49  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
50  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",
51  word, useless);
52  printf("recognized or extraneous. Ignoring.\n");
53  }
54  }
55  } else {
56  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
57  return(1);
58  }
59  }
60  fclose(in);
61  }
62 
63  if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
64  if (!mpi->rank) {
65  fprintf(stderr,"Error in BurgersInitialize: This physical model does not have a splitting ");
66  fprintf(stderr,"of the hyperbolic term defined.\n");
67  }
68  return(1);
69  }
70 
71 #ifndef serial
72 #endif
73 
74  /* initializing physical model-specific functions */
75  solver->ComputeCFL = BurgersComputeCFL;
76  solver->FFunction = BurgersAdvection;
77  solver->Upwind = BurgersUpwind;
78 
79  count++;
80  return(0);
81 }
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
void * physics
Definition: hypar.h:266
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
#define _MAX_STRING_SIZE_
Definition: basic.h:14
double BurgersComputeCFL(void *s, void *m, double dt, double t)
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
int BurgersAdvection(double *f, double *u, int dir, void *s, double t)
int BurgersUpwind(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: BurgersUpwind.c:15
Structure of MPI-related variables.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23