HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Euler2DInitialize.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <basic.h>
5 #include <arrayfunctions.h>
6 #include <boundaryconditions.h>
8 #include <mpivars.h>
9 #include <hypar.h>
10 
11 double Euler2DComputeCFL (void*,void*,double,double);
12 int Euler2DFlux (double*,double*,int,void*,double);
13 int Euler2DUpwindRoe (double*,double*,double*,double*,double*,double*,int,void*,double);
14 int Euler2DUpwindRF (double*,double*,double*,double*,double*,double*,int,void*,double);
15 int Euler2DUpwindLLF (double*,double*,double*,double*,double*,double*,int,void*,double);
16 int Euler2DUpwindSWFS (double*,double*,double*,double*,double*,double*,int,void*,double);
17 int Euler2DRoeAverage (double*,double*,double*,void*);
18 int Euler2DLeftEigenvectors (double*,double*,void*,int);
19 int Euler2DRightEigenvectors (double*,double*,void*,int);
20 
21 int Euler2DInitialize(void *s,void *m)
22 {
23  HyPar *solver = (HyPar*) s;
24  MPIVariables *mpi = (MPIVariables*) m;
25  Euler2D *physics = (Euler2D*) solver->physics;
26  int ferr = 0;
27 
28  static int count = 0;
29 
30  if (solver->nvars != _MODEL_NVARS_) {
31  fprintf(stderr,"Error in Euler2DInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
32  return(1);
33  }
34  if (solver->ndims != _MODEL_NDIMS_) {
35  fprintf(stderr,"Error in Euler2DInitialize(): ndims has to be %d.\n",_MODEL_NDIMS_);
36  return(1);
37  }
38 
39  /* default values */
40  physics->gamma = 1.4;
41  strcpy(physics->upw_choice,"roe");
42 
43  /* reading physical model specific inputs - all processes */
44  if (!mpi->rank) {
45  FILE *in;
46  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
47  in = fopen("physics.inp","r");
48  if (!in) printf("Warning: File \"physics.inp\" not found. Using default values.\n");
49  else {
50  char word[_MAX_STRING_SIZE_];
51  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
52  if (!strcmp(word, "begin")){
53  while (strcmp(word, "end")){
54  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
55  if (!strcmp(word, "gamma")) {
56  ferr = fscanf(in,"%lf",&physics->gamma); if (ferr != 1) return(1);
57  } else if (!strcmp(word,"upwinding")) {
58  ferr = fscanf(in,"%s",physics->upw_choice); if (ferr != 1) return(1);
59  } else if (strcmp(word,"end")) {
60  char useless[_MAX_STRING_SIZE_];
61  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
62  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",word,useless);
63  printf("recognized or extraneous. Ignoring.\n");
64  }
65  }
66  } else {
67  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
68  return(1);
69  }
70  }
71  fclose(in);
72  }
73 
74 #ifndef serial
75  IERR MPIBroadcast_double (&physics->gamma,1,0,&mpi->world); CHECKERR(ierr);
77 #endif
78 
79  if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
80  if (!mpi->rank) {
81  fprintf(stderr,"Error in Euler2DInitialize: This physical model does not have a splitting ");
82  fprintf(stderr,"of the hyperbolic term defined.\n");
83  }
84  return(1);
85  }
86 
87  /* initializing physical model-specific functions */
88  solver->ComputeCFL = Euler2DComputeCFL;
89  solver->FFunction = Euler2DFlux;
90  if (!strcmp(physics->upw_choice,_ROE_ )) solver->Upwind = Euler2DUpwindRoe;
91  else if (!strcmp(physics->upw_choice,_RF_ )) solver->Upwind = Euler2DUpwindRF;
92  else if (!strcmp(physics->upw_choice,_LLF_ )) solver->Upwind = Euler2DUpwindLLF;
93  else if (!strcmp(physics->upw_choice,_SWFS_)) solver->Upwind = Euler2DUpwindSWFS;
94  else {
95  fprintf(stderr,"Error in Euler2DInitialize(): %s is not a valid upwinding scheme.\n",
96  physics->upw_choice);
97  return(1);
98  }
102 
103  /* set the value of gamma in all the boundary objects */
104  int n;
105  DomainBoundary *boundary = (DomainBoundary*) solver->boundary;
106  for (n = 0; n < solver->nBoundaryZones; n++) boundary[n].gamma = physics->gamma;
107 
108  count++;
109  return(0);
110 }
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
int Euler2DUpwindLLF(double *, double *, double *, double *, double *, double *, int, void *, double)
int MPIBroadcast_double(double *, int, int, void *)
Definition: MPIBroadcast.c:9
#define _MODEL_NVARS_
Definition: euler1d.h:58
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(* GetRightEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:359
#define _LLF_
Definition: euler1d.h:66
MPI related function definitions.
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
#define _MODEL_NDIMS_
Definition: euler1d.h:56
#define _SWFS_
Definition: euler1d.h:68
MPI_Comm world
int Euler2DLeftEigenvectors(double *u, double *L, void *p, int dir)
Definition: Euler2DEigen.c:16
#define _MAX_STRING_SIZE_
Definition: basic.h:14
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
void * boundary
Definition: hypar.h:159
Structure containing the variables and function pointers defining a boundary.
double Euler2DComputeCFL(void *s, void *m, double dt, double t)
int Euler2DUpwindSWFS(double *, double *, double *, double *, double *, double *, int, void *, double)
int Euler2DRightEigenvectors(double *u, double *R, void *p, int dir)
Definition: Euler2DEigen.c:23
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357
#define _ROE_
Definition: euler1d.h:62
int nBoundaryZones
Definition: hypar.h:157
int nvars
Definition: hypar.h:29
int Euler2DUpwindRoe(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: Euler2DUpwind.c:10
#define CHECKERR(ierr)
Definition: basic.h:18
int Euler2DRoeAverage(double *uavg, double *uL, double *uR, void *p)
Contains structure definition for hypar.
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 _RF_
Definition: euler1d.h:64
#define IERR
Definition: basic.h:16
int Euler2DInitialize(void *, void *)
int Euler2DUpwindRF(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: Euler2DUpwind.c:68
Structure of MPI-related variables.
char upw_choice[_MAX_STRING_SIZE_]
Definition: euler2d.h:246
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int Euler2DFlux(double *f, double *u, int dir, void *s, double t)
Definition: Euler2DFlux.c:7
double gamma
Definition: euler2d.h:245