HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
numa2d.h File Reference
#include <basic.h>
#include <mathfunctions.h>

Go to the source code of this file.

Data Structures

struct  Numa2D
 

Macros

#define _NUMA2D_   "numa2d"
 
#define _MODEL_NDIMS_   2
 
#define _MODEL_NVARS_   4
 
#define _XDIR_   0
 
#define _YDIR_   1
 
#define _Numa2DGetFlowVars_(u, drho, uvel, vvel, dT, rho0)
 
#define _Numa2DSetFlux_(f, dir, drho, uvel, vvel, dT, dP, rho0, T0)
 
#define _Numa2DSetLinearFlux_(f, dir, drho, uvel, vvel, dT, dP, rho0, T0)
 
#define _Numa2DSetSource_(s, param, drho)
 
#define _Numa2DComputePressure_(params, T0, dT, P0, dP)
 
#define _Numa2DComputeLinearizedPressure_(params, T0, dT, P0, dP)
 
#define _Numa2DComputeTemperature_(rho0, drho, T0, dT, temperature)
 
#define _Numa2DComputeSpeedofSound_(gamma, R, T0, dT, rho0, drho, EP, c)
 
#define _Numa2DComputeLinearizedSpeedofSound_(gamma, R, T0, rho0, EP, c)
 
#define _RUSANOV_UPWINDING_   "rusanov"
 

Functions

int Numa2DInitialize (void *, void *)
 
int Numa2DCleanup (void *)
 

Macro Definition Documentation

◆ _NUMA2D_

#define _NUMA2D_   "numa2d"

Definition at line 21 of file numa2d.h.

◆ _MODEL_NDIMS_

#define _MODEL_NDIMS_   2

Definition at line 26 of file numa2d.h.

◆ _MODEL_NVARS_

#define _MODEL_NVARS_   4

Definition at line 27 of file numa2d.h.

◆ _XDIR_

#define _XDIR_   0

Definition at line 30 of file numa2d.h.

◆ _YDIR_

#define _YDIR_   1

Definition at line 31 of file numa2d.h.

◆ _Numa2DGetFlowVars_

#define _Numa2DGetFlowVars_ (   u,
  drho,
  uvel,
  vvel,
  dT,
  rho0 
)
Value:
{ \
drho = u[0]; \
uvel = u[1]/(rho0+drho); \
vvel = u[2]/(rho0+drho); \
dT = u[3]; \
}

Definition at line 33 of file numa2d.h.

◆ _Numa2DSetFlux_

#define _Numa2DSetFlux_ (   f,
  dir,
  drho,
  uvel,
  vvel,
  dT,
  dP,
  rho0,
  T0 
)
Value:
{ \
if (dir == _XDIR_) { \
f[0] = (rho0+drho) * uvel; \
f[1] = (rho0+drho)*uvel*uvel + dP; \
f[2] = (rho0+drho)*uvel*vvel; \
f[3] = uvel*(dT+T0); \
} else if (dir == _YDIR_) { \
f[0] = (rho0+drho) * vvel; \
f[1] = (rho0+drho)*uvel*vvel; \
f[2] = (rho0+drho)*vvel*vvel + dP; \
f[3] = vvel*(dT+T0); \
} \
}
#define _XDIR_
Definition: numa2d.h:30
#define _YDIR_
Definition: numa2d.h:31

Definition at line 41 of file numa2d.h.

◆ _Numa2DSetLinearFlux_

#define _Numa2DSetLinearFlux_ (   f,
  dir,
  drho,
  uvel,
  vvel,
  dT,
  dP,
  rho0,
  T0 
)
Value:
{ \
if (dir == _XDIR_) { \
f[0] = (rho0+drho) * uvel; \
f[1] = dP; \
f[2] = 0.0; \
f[3] = (rho0+drho)*uvel*T0/rho0; \
} else if (dir == _YDIR_) { \
f[0] = (rho0+drho) * vvel; \
f[1] = 0.0; \
f[2] = dP; \
f[3] = (rho0+drho)*vvel*T0/rho0; \
} \
}
#define _XDIR_
Definition: numa2d.h:30
#define _YDIR_
Definition: numa2d.h:31

Definition at line 56 of file numa2d.h.

◆ _Numa2DSetSource_

#define _Numa2DSetSource_ (   s,
  param,
  drho 
)
Value:
{ \
s[0] = 0.0; \
s[1] = 0.0; \
s[2] = -param->g*drho; \
s[3] = 0.0; \
}

Definition at line 71 of file numa2d.h.

◆ _Numa2DComputePressure_

#define _Numa2DComputePressure_ (   params,
  T0,
  dT,
  P0,
  dP 
)
Value:
{ \
double gamma = params->gamma; \
double Pref = params->Pref; \
double R = params->R; \
double P_total = Pref * raiseto((R*(T0+dT)/Pref),gamma); \
dP = P_total - P0; \
}
#define raiseto(x, a)
Definition: math_ops.h:37

Definition at line 79 of file numa2d.h.

◆ _Numa2DComputeLinearizedPressure_

#define _Numa2DComputeLinearizedPressure_ (   params,
  T0,
  dT,
  P0,
  dP 
)
Value:
{ \
double gamma = params->gamma; \
dP = (gamma*P0/T0) * dT; \
}

Definition at line 88 of file numa2d.h.

◆ _Numa2DComputeTemperature_

#define _Numa2DComputeTemperature_ (   rho0,
  drho,
  T0,
  dT,
  temperature 
)
Value:
{ \
temperature = (T0+dT)*EP/(rho0+drho); \
}

Definition at line 94 of file numa2d.h.

◆ _Numa2DComputeSpeedofSound_

#define _Numa2DComputeSpeedofSound_ (   gamma,
  R,
  T0,
  dT,
  rho0,
  drho,
  EP,
 
)
Value:
{ \
c = sqrt(gamma*R*(T0+dT)*EP/(rho0+drho)); \
}

Definition at line 99 of file numa2d.h.

◆ _Numa2DComputeLinearizedSpeedofSound_

#define _Numa2DComputeLinearizedSpeedofSound_ (   gamma,
  R,
  T0,
  rho0,
  EP,
 
)
Value:
{ \
c = sqrt(gamma*R*T0*EP/rho0); \
}

Definition at line 104 of file numa2d.h.

◆ _RUSANOV_UPWINDING_

#define _RUSANOV_UPWINDING_   "rusanov"

Definition at line 130 of file numa2d.h.

Function Documentation

◆ Numa2DInitialize()

int Numa2DInitialize ( void *  ,
void *   
)

Definition at line 25 of file Numa2DInitialize.c.

26 {
27  HyPar *solver = (HyPar*) s;
28  MPIVariables *mpi = (MPIVariables*) m;
29  Numa2D *physics = (Numa2D*) solver->physics;
30  int ferr = 0;
31 
32  static int count = 0;
33 
34  if (solver->nvars != _MODEL_NVARS_) {
35  fprintf(stderr,"Error in Numa2DInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
36  return(1);
37  }
38  if (solver->ndims != _MODEL_NDIMS_) {
39  fprintf(stderr,"Error in Numa2DInitialize(): ndims has to be %d.\n",_MODEL_NDIMS_);
40  return(1);
41  }
42 
43  /* default values */
44  physics->gamma = 1.4;
45  physics->R = 287.058; /* J kg^{-1} K^{-1} */
46  physics->g = 9.8; /* m s^{-2} */
47  physics->mu = 0.0; /* m^2 s^{-1} */
48 
49  physics->Pref = 101327.0; /* N m^{-2} */
50  physics->Tref = 288.15; /* Kelvin */
51 
52  strcpy(physics->upwind,_RUSANOV_UPWINDING_);
53 
54  /* default choice of initial atmosphere */
55  physics->init_atmos = 1;
56 
57  /* reading physical model specific inputs - rank 0 */
58  if (!mpi->rank) {
59  FILE *in;
60  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
61  in = fopen("physics.inp","r");
62  if (!in) printf("Warning: File \"physics.inp\" not found. Using default values.\n");
63  else {
64  char word[_MAX_STRING_SIZE_];
65  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
66  if (!strcmp(word, "begin")){
67  while (strcmp(word, "end")){
68  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
69  if (!strcmp(word, "gamma")) {
70  ferr = fscanf(in,"%lf",&physics->gamma); if (ferr != 1) return(1);
71  } else if (!strcmp(word,"R")) {
72  ferr = fscanf(in,"%lf",&physics->R); if (ferr != 1) return(1);
73  } else if (!strcmp(word,"g")) {
74  ferr = fscanf(in,"%lf",&physics->g); if (ferr != 1) return(1);
75  } else if (!strcmp(word,"mu")) {
76  ferr = fscanf(in,"%lf",&physics->mu); if (ferr != 1) return(1);
77  } else if (!strcmp(word,"Pref")) {
78  ferr = fscanf(in,"%lf",&physics->Pref); if (ferr != 1) return(1);
79  } else if (!strcmp(word,"Tref")) {
80  ferr = fscanf(in,"%lf",&physics->Tref); if (ferr != 1) return(1);
81  } else if (!strcmp(word,"init_atmos")) {
82  ferr = fscanf(in,"%d",&physics->init_atmos); if (ferr != 1) return(1);
83  } else if (!strcmp(word,"upwinding")) {
84  ferr = fscanf(in,"%s",physics->upwind); if (ferr != 1) return(1);
85  } else if (strcmp(word,"end")) {
86  char useless[_MAX_STRING_SIZE_];
87  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
88  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",word,useless);
89  printf("recognized or extraneous. Ignoring.\n");
90  }
91  }
92  } else {
93  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
94  return(1);
95  }
96  }
97  fclose(in);
98  }
99 
100 #ifndef serial
101  IERR MPIBroadcast_double (&physics->gamma ,1 ,0,&mpi->world);CHECKERR(ierr);
102  IERR MPIBroadcast_double (&physics->R ,1 ,0,&mpi->world);CHECKERR(ierr);
103  IERR MPIBroadcast_double (&physics->g ,1 ,0,&mpi->world);CHECKERR(ierr);
104  IERR MPIBroadcast_double (&physics->mu ,1 ,0,&mpi->world);CHECKERR(ierr);
105  IERR MPIBroadcast_double (&physics->Pref ,1 ,0,&mpi->world);CHECKERR(ierr);
106  IERR MPIBroadcast_double (&physics->Tref ,1 ,0,&mpi->world);CHECKERR(ierr);
107  IERR MPIBroadcast_integer (&physics->init_atmos,1 ,0,&mpi->world);CHECKERR(ierr);
109 #endif
110 
111  /* calculate the mean hydrostatic atmosphere as a function of altitude */
112  if (physics->init_atmos == 1) {
114  } else if (physics->init_atmos == 2) {
116  } else {
117  if (!mpi->rank) {
118  fprintf(stderr,"Error in Numa2DInitialize(): invalid choice of initial atmosphere (init_atmos).\n");
119  return(1);
120  }
121  }
122  CHECKERR(ierr);
123 
124  /* initializing physical model-specific functions */
125  if (!strcmp(solver->SplitHyperbolicFlux,"yes"))
126  solver->dFFunction = Numa2DStiffFlux;
127  else solver->dFFunction = NULL;
128  solver->FFunction = Numa2DFlux;
129  solver->ComputeCFL = Numa2DComputeCFL;
130  solver->SFunction = Numa2DSource;
131  if (!strcmp(physics->upwind,_RUSANOV_UPWINDING_)) {
132  solver->Upwind = Numa2DRusanovFlux;
133  if (!strcmp(solver->SplitHyperbolicFlux,"yes"))
135  else solver->UpwinddF = NULL;
136  } else {
137  if (!mpi->rank) fprintf(stderr,"Error in Numa2DInitialize(): Invalid choice of upwinding scheme.\n");
138  return(1);
139  }
140 
141  /* set the value of gamma in all the boundary objects */
142  int n;
143  DomainBoundary *boundary = (DomainBoundary*) solver->boundary;
144  for (n = 0; n < solver->nBoundaryZones; n++) boundary[n].gamma = physics->gamma;
145 
146  /* finally, hijack the main solver's dissipation function pointer
147  * to this model's own function, since it's difficult to express
148  * the dissipation terms in the general form */
150 
151  /* check that solver has the correct choice of diffusion formulation */
152  if (strcmp(solver->spatial_type_par,_NC_2STAGE_)) {
153  if (!mpi->rank) {
154  fprintf(stderr,"Error in Numa2DInitialize(): Parabolic term spatial discretization must be \"%s\"\n",_NC_2STAGE_);
155  }
156  return(1);
157  }
158 
159  count++;
160  return(0);
161 }
int Numa2DRusanovLinearFlux(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: Numa2DUpwind.c:69
int init_atmos
Definition: numa2d.h:113
int nvars
Definition: hypar.h:29
void Numa2DCalculateStandardAtmosphere_2(void *, double, double *, double *, double *, double *)
double Tref
Definition: numa2d.h:117
#define IERR
Definition: basic.h:16
#define CHECKERR(ierr)
Definition: basic.h:18
int(* ParabolicFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:256
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
void * boundary
Definition: hypar.h:159
double mu
Definition: numa2d.h:114
int MPIBroadcast_integer(int *, int, int, void *)
Definition: MPIBroadcast.c:23
#define _RUSANOV_UPWINDING_
Definition: numa2d.h:130
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
int Numa2DParabolicFunction(double *, double *, void *, void *, double)
double R
Definition: numa2d.h:111
Structure containing the variables and function pointers defining a boundary.
int ndims
Definition: hypar.h:26
void Numa2DCalculateStandardAtmosphere_1(void *, double, double *, double *, double *, double *)
int MPIBroadcast_character(char *, int, int, void *)
Definition: MPIBroadcast.c:37
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
int MPIBroadcast_double(double *, int, int, void *)
Definition: MPIBroadcast.c:9
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
double g
Definition: numa2d.h:112
#define _MAX_STRING_SIZE_
Definition: basic.h:14
Definition: numa2d.h:109
double Pref
Definition: numa2d.h:117
#define _MODEL_NDIMS_
Definition: euler1d.h:56
double gamma
Definition: numa2d.h:110
MPI_Comm world
char spatial_type_par[_MAX_STRING_SIZE_]
Definition: hypar.h:96
int(* dFFunction)(double *, double *, int, void *, double)
Definition: hypar.h:280
void * physics
Definition: hypar.h:266
int(* UpwinddF)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:300
int Numa2DStiffFlux(double *, double *, int, void *, double)
Definition: Numa2DFlux.c:43
Structure of MPI-related variables.
#define _MODEL_NVARS_
Definition: euler1d.h:58
int nBoundaryZones
Definition: hypar.h:157
void(* StandardAtmosphere)(void *, double, double *, double *, double *, double *)
Definition: numa2d.h:120
int Numa2DRusanovFlux(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: Numa2DUpwind.c:9
int Numa2DFlux(double *, double *, int, void *, double)
Definition: Numa2DFlux.c:7
int Numa2DSource(double *, double *, void *, void *, double)
Definition: Numa2DSource.c:7
char upwind[_MAX_STRING_SIZE_]
Definition: numa2d.h:123
#define _NC_2STAGE_
Definition: hypar.h:477
double Numa2DComputeCFL(void *, void *, double, double)

◆ Numa2DCleanup()

int Numa2DCleanup ( void *  )

Definition at line 5 of file Numa2DCleanup.c.

6 {
7  return(0);
8 }