HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Numa3DInitialize.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 Numa3DComputeCFL (void*,void*,double,double);
14 int Numa3DFlux (double*,double*,int,void*,double);
15 int Numa3DStiffFlux (double*,double*,int,void*,double);
16 int Numa3DSource (double*,double*,void*,void*,double);
17 
18 int Numa3DRusanovFlux (double*,double*,double*,double*,double*,double*,int,void*,double);
19 int Numa3DRusanovLinearFlux(double*,double*,double*,double*,double*,double*,int,void*,double);
20 
21 void Numa3DCalculateStandardAtmosphere_1(void*,double,double*,double*,double*,double*);
22 void Numa3DCalculateStandardAtmosphere_2(void*,double,double*,double*,double*,double*);
23 
24 int Numa3DInitialize(void *s,void *m)
25 {
26  HyPar *solver = (HyPar*) s;
27  MPIVariables *mpi = (MPIVariables*) m;
28  Numa3D *physics = (Numa3D*) solver->physics;
29  int ferr = 0;
30 
31  static int count = 0;
32 
33  if (solver->nvars != _MODEL_NVARS_) {
34  fprintf(stderr,"Error in Numa3DInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
35  return(1);
36  }
37  if (solver->ndims != _MODEL_NDIMS_) {
38  fprintf(stderr,"Error in Numa3DInitialize(): ndims has to be %d.\n",_MODEL_NDIMS_);
39  return(1);
40  }
41 
42  /* default values */
43  physics->gamma = 1.4;
44  physics->R = 287.058; /* J kg^{-1} K^{-1} */
45  physics->Omega = 7.2921150E-05; /* rad s^{-1} */
46  physics->g = 9.8; /* m s^{-2} */
47 
48  physics->Pref = 101327.0; /* N m^{-2} */
49  physics->Tref = 288.15; /* Kelvin */
50 
51  strcpy(physics->upwind,_RUSANOV_UPWINDING_);
52 
53  /* default choice of initial atmosphere */
54  physics->init_atmos = 1;
55 
56  /* reading physical model specific inputs - all processes */
57  if (!mpi->rank) {
58  FILE *in;
59  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
60  in = fopen("physics.inp","r");
61  if (!in) printf("Warning: File \"physics.inp\" not found. Using default values.\n");
62  else {
63  char word[_MAX_STRING_SIZE_];
64  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
65  if (!strcmp(word, "begin")){
66  while (strcmp(word, "end")){
67  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
68  if (!strcmp(word, "gamma")) {
69  ferr = fscanf(in,"%lf",&physics->gamma); if (ferr != 1) return(1);
70  } else if (!strcmp(word,"R")) {
71  ferr = fscanf(in,"%lf",&physics->R); if (ferr != 1) return(1);
72  } else if (!strcmp(word,"g")) {
73  ferr = fscanf(in,"%lf",&physics->g); if (ferr != 1) return(1);
74  } else if (!strcmp(word,"Omega")) {
75  ferr = fscanf(in,"%lf",&physics->Omega); if (ferr != 1) return(1);
76  } else if (!strcmp(word,"Pref")) {
77  ferr = fscanf(in,"%lf",&physics->Pref); if (ferr != 1) return(1);
78  } else if (!strcmp(word,"Tref")) {
79  ferr = fscanf(in,"%lf",&physics->Tref); if (ferr != 1) return(1);
80  } else if (!strcmp(word,"init_atmos")) {
81  ferr = fscanf(in,"%d",&physics->init_atmos); if (ferr != 1) return(1);
82  } else if (!strcmp(word,"upwinding")) {
83  ferr = fscanf(in,"%s",physics->upwind); if (ferr != 1) return(1);
84  } else if (strcmp(word,"end")) {
85  char useless[_MAX_STRING_SIZE_];
86  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
87  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",word,useless);
88  printf("recognized or extraneous. Ignoring.\n");
89  }
90  }
91  } else {
92  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
93  return(1);
94  }
95  }
96  fclose(in);
97  }
98 
99 #ifndef serial
100  IERR MPIBroadcast_double (&physics->gamma ,1 ,0,&mpi->world); CHECKERR(ierr);
101  IERR MPIBroadcast_double (&physics->R ,1 ,0,&mpi->world); CHECKERR(ierr);
102  IERR MPIBroadcast_double (&physics->g ,1 ,0,&mpi->world); CHECKERR(ierr);
103  IERR MPIBroadcast_double (&physics->Omega ,1 ,0,&mpi->world); CHECKERR(ierr);
104  IERR MPIBroadcast_double (&physics->Pref ,1 ,0,&mpi->world); CHECKERR(ierr);
105  IERR MPIBroadcast_double (&physics->Tref ,1 ,0,&mpi->world); CHECKERR(ierr);
106  IERR MPIBroadcast_integer (&physics->init_atmos ,1 ,0,&mpi->world); CHECKERR(ierr);
108 #endif
109 
110  /* calculate the mean hydrostatic atmosphere as a function of altitude */
111  if (physics->init_atmos == 1) {
113  } else if (physics->init_atmos == 2) {
115  } else {
116  if (!mpi->rank) {
117  fprintf(stderr,"Error in Numa3DInitialize(): invalid choice of initial atmosphere (init_atmos).\n");
118  return(1);
119  }
120  }
121  CHECKERR(ierr);
122 
123  /* initializing physical model-specific functions */
124  if (!strcmp(solver->SplitHyperbolicFlux,"yes"))
125  solver->dFFunction = Numa3DStiffFlux;
126  else solver->dFFunction = NULL;
127  solver->FFunction = Numa3DFlux;
128  solver->ComputeCFL = Numa3DComputeCFL;
129  solver->SFunction = Numa3DSource;
130  if (!strcmp(physics->upwind,_RUSANOV_UPWINDING_)) {
131  solver->Upwind = Numa3DRusanovFlux;
132  if (!strcmp(solver->SplitHyperbolicFlux,"yes"))
134  else solver->UpwinddF = NULL;
135  } else {
136  if (!mpi->rank) fprintf(stderr,"Error in Numa3DInitialize(): Invalid choice of upwinding scheme.\n");
137  return(1);
138  }
139 
140  /* set the value of gamma in all the boundary objects */
141  int n;
142  DomainBoundary *boundary = (DomainBoundary*) solver->boundary;
143  for (n = 0; n < solver->nBoundaryZones; n++) boundary[n].gamma = physics->gamma;
144 
145  count++;
146  return(0);
147 }
int(* dFFunction)(double *, double *, int, void *, double)
Definition: hypar.h:280
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
int Numa3DSource(double *, double *, void *, void *, double)
Definition: Numa3DSource.c:7
int MPIBroadcast_double(double *, int, int, void *)
Definition: MPIBroadcast.c:9
#define _MODEL_NVARS_
Definition: euler1d.h:58
double Tref
Definition: numa3d.h:136
int Numa3DRusanovLinearFlux(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: Numa3DUpwind.c:71
Containts the structures and definitions for boundary condition implementation.
void * physics
Definition: hypar.h:266
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
int(* UpwinddF)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:300
double R
Definition: numa3d.h:130
MPI related function definitions.
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
#define _MODEL_NDIMS_
Definition: euler1d.h:56
MPI_Comm world
double Pref
Definition: numa3d.h:136
#define _MAX_STRING_SIZE_
Definition: basic.h:14
int Numa3DFlux(double *f, double *u, int dir, void *s, double t)
Definition: Numa3DFlux.c:7
int Numa3DCalculateStandardAtmosphere_2(void *p, double z, double *ExnerP, double *P, double *rho, double *T)
Definition: numa3d.h:128
int Numa3DRusanovFlux(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: Numa3DUpwind.c:9
void * boundary
Definition: hypar.h:159
Structure containing the variables and function pointers defining a boundary.
int Numa3DStiffFlux(double *f, double *u, int dir, void *s, double t)
Definition: Numa3DFlux.c:43
Contains function definitions for common mathematical functions.
int nBoundaryZones
Definition: hypar.h:157
double Numa3DComputeCFL(void *s, void *m, double dt, double t)
double Omega
Definition: numa3d.h:131
void(* StandardAtmosphere)(void *, double, double *, double *, double *, double *)
Definition: numa3d.h:139
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
double gamma
Definition: numa3d.h:129
int nvars
Definition: hypar.h:29
char upwind[_MAX_STRING_SIZE_]
Definition: numa3d.h:142
#define CHECKERR(ierr)
Definition: basic.h:18
Contains structure definition for hypar.
int Numa3DInitialize(void *, void *)
double g
Definition: numa3d.h:132
int MPIBroadcast_character(char *, int, int, void *)
Definition: MPIBroadcast.c:37
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
Some basic definitions and macros.
int ndims
Definition: hypar.h:26
Contains macros and function definitions for common array operations.
#define IERR
Definition: basic.h:16
int Numa3DCalculateStandardAtmosphere_1(void *p, double z, double *ExnerP, double *P, double *rho, double *T)
Structure of MPI-related variables.
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
#define _RUSANOV_UPWINDING_
Definition: numa2d.h:130
int MPIBroadcast_integer(int *, int, int, void *)
Definition: MPIBroadcast.c:23
int init_atmos
Definition: numa3d.h:133