HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
Numa2DInitialize.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <math.h>
5 #include <basic.h>
6 #include <arrayfunctions.h>
7 #include <mathfunctions.h>
8 #include <boundaryconditions.h>
10 #include <mpivars.h>
11 #include <hypar.h>
12 
13 double Numa2DComputeCFL (void*,void*,double,double);
14 int Numa2DFlux (double*,double*,int,void*,double);
15 int Numa2DStiffFlux (double*,double*,int,void*,double);
16 int Numa2DSource (double*,double*,void*,void*,double);
17 int Numa2DParabolicFunction (double*,double*,void*,void*,double);
18 
19 int Numa2DRusanovFlux (double*,double*,double*,double*,double*,double*,int,void*,double);
20 int Numa2DRusanovLinearFlux(double*,double*,double*,double*,double*,double*,int,void*,double);
21 
22 void Numa2DCalculateStandardAtmosphere_1(void*,double,double*,double*,double*,double*);
23 void Numa2DCalculateStandardAtmosphere_2(void*,double,double*,double*,double*,double*);
24 
25 int Numa2DInitialize(void *s,void *m)
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 *)
Containts the structures and definitions for boundary condition implementation.
double Tref
Definition: numa2d.h:117
#define IERR
Definition: basic.h:16
MPI related function definitions.
#define CHECKERR(ierr)
Definition: basic.h:18
Contains function definitions for common mathematical functions.
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
Some basic definitions and macros.
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
Contains structure definition for hypar.
double gamma
Definition: numa2d.h:110
MPI_Comm world
int Numa2DInitialize(void *s, void *m)
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
Contains macros and function definitions for common array operations.
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)