HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
Euler1DInitialize.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <basic.h>
10 #include <arrayfunctions.h>
11 #include <physicalmodels/euler1d.h>
12 #include <mpivars.h>
13 #include <hypar.h>
14 
15 double Euler1DComputeCFL (void*,void*,double,double);
16 int Euler1DFlux (double*,double*,int,void*,double);
17 int Euler1DStiffFlux (double*,double*,int,void*,double);
18 int Euler1DSource (double*,double*,void*,void*,double);
19 
20 int Euler1DUpwindRoe (double*,double*,double*,double*,double*,double*,int,void*,double);
21 int Euler1DUpwinddFRoe (double*,double*,double*,double*,double*,double*,int,void*,double);
22 
23 int Euler1DUpwindRF (double*,double*,double*,double*,double*,double*,int,void*,double);
24 int Euler1DUpwinddFRF (double*,double*,double*,double*,double*,double*,int,void*,double);
25 
26 int Euler1DUpwindLLF (double*,double*,double*,double*,double*,double*,int,void*,double);
27 int Euler1DUpwinddFLLF (double*,double*,double*,double*,double*,double*,int,void*,double);
28 
29 int Euler1DUpwindSWFS (double*,double*,double*,double*,double*,double*,int,void*,double);
30 int Euler1DUpwindRusanov (double*,double*,double*,double*,double*,double*,int,void*,double);
31 
32 int Euler1DJacobian (double*,double*,void*,int,int,int);
33 int Euler1DStiffJacobian (double*,double*,void*,int,int,int);
34 
35 int Euler1DRoeAverage (double*,double*,double*,void*);
36 int Euler1DLeftEigenvectors (double*,double*,void*,int);
37 int Euler1DRightEigenvectors (double*,double*,void*,int);
38 
39 int Euler1DGravityField (void*,void*);
40 int Euler1DSourceUpwindLLF (double*,double*,double*,double*,int,void*,double);
41 int Euler1DSourceUpwindRoe (double*,double*,double*,double*,int,void*,double);
42 
43 int Euler1DModifiedSolution (double*,double*,int,void*,void*,double);
44 int Euler1DPreStep (double*,void*,void*,double);
45 
72  void *s,
73  void *m
74  )
75 {
76  HyPar *solver = (HyPar*) s;
77  MPIVariables *mpi = (MPIVariables*) m;
78  Euler1D *physics = (Euler1D*) solver->physics;
79  int ferr, d;
80 
81  static int count = 0;
82 
83  if (solver->nvars != _MODEL_NVARS_) {
84  fprintf(stderr,"Error in Euler1DInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
85  return(1);
86  }
87  if (solver->ndims != _MODEL_NDIMS_) {
88  fprintf(stderr,"Error in Euler1DInitialize(): ndims has to be %d.\n",_MODEL_NDIMS_);
89  return(1);
90  }
91 
92  /* default values */
93  physics->gamma = 1.4;
94  physics->grav = 0.0;
95  physics->grav_type = 0;
96  strcpy(physics->upw_choice,"roe");
97 
98  /* reading physical model specific inputs */
99  if (!mpi->rank) {
100  FILE *in;
101  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
102  in = fopen("physics.inp","r");
103  if (!in) printf("Warning: File \"physics.inp\" not found. Using default values.\n");
104  else {
105  char word[_MAX_STRING_SIZE_];
106  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
107  if (!strcmp(word, "begin")){
108  while (strcmp(word, "end")){
109  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
110  if (!strcmp(word, "gamma")) {
111  ferr = fscanf(in,"%lf",&physics->gamma);
112  if (ferr != 1) return(1);
113  } else if (!strcmp(word, "gravity")) {
114  ferr = fscanf(in,"%lf",&physics->grav);
115  if (ferr != 1) return(1);
116  } else if (!strcmp(word, "gravity_type")) {
117  ferr = fscanf(in,"%d",&physics->grav_type);
118  if (ferr != 1) return(1);
119  } else if (!strcmp(word,"upwinding")) {
120  ferr = fscanf(in,"%s",physics->upw_choice);
121  if (ferr != 1) return(1);
122  } else if (strcmp(word,"end")) {
123  char useless[_MAX_STRING_SIZE_];
124  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
125  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",word,useless);
126  printf("recognized or extraneous. Ignoring.\n");
127  }
128  }
129  } else {
130  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
131  return(1);
132  }
133  }
134  fclose(in);
135  }
136 
137 #ifndef serial
138  IERR MPIBroadcast_double (&physics->gamma ,1,0,&mpi->world); CHECKERR(ierr);
139  IERR MPIBroadcast_double (&physics->grav ,1,0,&mpi->world); CHECKERR(ierr);
140  IERR MPIBroadcast_integer (&physics->grav_type,1,0,&mpi->world); CHECKERR(ierr);
142 #endif
143 
144  if ((physics->grav != 0.0) && (strcmp(physics->upw_choice,_LLF_)) && (strcmp(physics->upw_choice,_ROE_))) {
145  if (!mpi->rank) {
146  fprintf(stderr,"Error in Euler1DInitialize: %s or %s upwinding is needed for flows ",_LLF_,_ROE_);
147  fprintf(stderr,"with gravitational forces.\n");
148  }
149  return(1);
150  }
151 
152  /* initializing physical model-specific functions */
153  solver->PreStep = Euler1DPreStep;
154  solver->ComputeCFL = Euler1DComputeCFL;
155  solver->FFunction = Euler1DFlux;
156  solver->SFunction = Euler1DSource;
158  if (!strcmp(physics->upw_choice,_ROE_ )) solver->Upwind = Euler1DUpwindRoe;
159  else if (!strcmp(physics->upw_choice,_RF_ )) solver->Upwind = Euler1DUpwindRF;
160  else if (!strcmp(physics->upw_choice,_LLF_ )) solver->Upwind = Euler1DUpwindLLF;
161  else if (!strcmp(physics->upw_choice,_SWFS_ )) solver->Upwind = Euler1DUpwindSWFS;
162  else if (!strcmp(physics->upw_choice,_RUSANOV_)) solver->Upwind = Euler1DUpwindRusanov;
163  else {
164  if (!mpi->rank) fprintf(stderr,"Error in Euler1DInitialize(): %s is not a valid upwinding scheme.\n",
165  physics->upw_choice);
166  return(1);
167  }
168  if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
169  solver->dFFunction = Euler1DStiffFlux;
171  if (!strcmp(physics->upw_choice,_ROE_ )) solver->UpwinddF = Euler1DUpwinddFRoe;
172  else if (!strcmp(physics->upw_choice,_RF_ )) solver->UpwinddF = Euler1DUpwinddFRF;
173  else if (!strcmp(physics->upw_choice,_LLF_ )) solver->UpwinddF = Euler1DUpwinddFLLF;
174  else {
175  if (!mpi->rank) {
176  fprintf(stderr,"Error in Euler1DInitialize(): %s is not a valid upwinding scheme ",
177  physics->upw_choice);
178  fprintf(stderr,"when split form of the hyperbolic flux is used. Use %s, %s or %s.\n",
179  _ROE_,_RF_,_LLF_);
180  }
181  return(1);
182  }
183  } else {
184  solver->dFFunction = NULL;
185  solver->UpwinddF = NULL;
186  solver->JFunction = Euler1DJacobian;
187  }
191 
192  if (!strcmp(physics->upw_choice,_LLF_ )) physics->SourceUpwind = Euler1DSourceUpwindLLF;
193  else if (!strcmp(physics->upw_choice,_ROE_ )) physics->SourceUpwind = Euler1DSourceUpwindRoe;
194 
195  /* allocate array to hold the gravity field */
196  int *dim = solver->dim_local;
197  int ghosts = solver->ghosts;
198  int size = 1; for (d=0; d<_MODEL_NDIMS_; d++) size *= (dim[d] + 2*ghosts);
199  physics->grav_field = (double*) calloc (size, sizeof(double));
200  physics->fast_jac = (double*) calloc (size*_MODEL_NVARS_*_MODEL_NVARS_, sizeof(double));
201  physics->solution = (double*) calloc (size*_MODEL_NVARS_, sizeof(double));
202  IERR Euler1DGravityField(solver,mpi); CHECKERR(ierr);
203 
204  count++;
205  return(0);
206 }
double Euler1DComputeCFL(void *, void *, double, double)
int Euler1DStiffFlux(double *, double *, int, void *, double)
Definition: Euler1DFlux.c:64
int Euler1DRoeAverage(double *, double *, double *, void *)
double gamma
Definition: euler1d.h:274
int nvars
Definition: hypar.h:29
#define IERR
Definition: basic.h:16
MPI related function definitions.
int Euler1DSourceUpwindRoe(double *, double *, double *, double *, int, void *, double)
#define CHECKERR(ierr)
Definition: basic.h:18
Structure containing variables and parameters specific to the 1D Euler equations. This structure cont...
Definition: euler1d.h:273
int Euler1DUpwinddFRF(double *, double *, double *, double *, double *, double *, int, void *, double)
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
int(* SourceUpwind)(double *, double *, double *, double *, int, void *, double)
Definition: euler1d.h:300
int Euler1DUpwindRusanov(double *, double *, double *, double *, double *, double *, int, void *, double)
int Euler1DUpwindLLF(double *, double *, double *, double *, double *, double *, int, void *, double)
int MPIBroadcast_integer(int *, int, int, void *)
Definition: MPIBroadcast.c:23
int Euler1DJacobian(double *, double *, void *, int, int, int)
double * fast_jac
Definition: euler1d.h:289
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
int Euler1DGravityField(void *, void *)
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 Euler1DUpwinddFRoe(double *, double *, double *, double *, double *, double *, int, void *, double)
int Euler1DInitialize(void *s, void *m)
int ndims
Definition: hypar.h:26
int MPIBroadcast_character(char *, int, int, void *)
Definition: MPIBroadcast.c:37
int Euler1DRightEigenvectors(double *, double *, void *, int)
Definition: Euler1DEigen.c:38
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
int Euler1DPreStep(double *, void *, void *, double)
Structure containing all solver-specific variables and functions.
Definition: hypar.h:23
int Euler1DUpwindSWFS(double *, double *, double *, double *, double *, double *, int, void *, double)
#define _MAX_STRING_SIZE_
Definition: basic.h:14
#define _ROE_
Definition: euler1d.h:62
int Euler1DUpwindRoe(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: Euler1DUpwind.c:30
#define _MODEL_NDIMS_
Definition: euler1d.h:56
int Euler1DLeftEigenvectors(double *, double *, void *, int)
Definition: Euler1DEigen.c:19
Contains structure definition for hypar.
#define _RUSANOV_
Definition: euler1d.h:70
MPI_Comm world
int(* PreStep)(double *, void *, void *, double)
Definition: hypar.h:339
double grav
Definition: euler1d.h:275
int * dim_local
Definition: hypar.h:37
int(* dFFunction)(double *, double *, int, void *, double)
Definition: hypar.h:280
void * physics
Definition: hypar.h:266
int(* JFunction)(double *, double *, void *, int, int, int)
Definition: hypar.h:326
1D Euler Equations (inviscid, compressible flows)
double * solution
Definition: euler1d.h:290
int Euler1DSource(double *, double *, void *, void *, double)
Definition: Euler1DSource.c:23
int Euler1DUpwinddFLLF(double *, double *, double *, double *, double *, double *, int, void *, double)
int(* UpwinddF)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:300
int ghosts
Definition: hypar.h:52
int Euler1DUpwindRF(double *, double *, double *, double *, double *, double *, int, void *, double)
#define _SWFS_
Definition: euler1d.h:68
Structure of MPI-related variables.
#define _MODEL_NVARS_
Definition: euler1d.h:58
int Euler1DStiffJacobian(double *, double *, void *, int, int, int)
int grav_type
Definition: euler1d.h:286
Contains macros and function definitions for common array operations.
int(* GetRightEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:359
int Euler1DModifiedSolution(double *, double *, int, void *, void *, double)
#define _RF_
Definition: euler1d.h:64
int Euler1DFlux(double *, double *, int, void *, double)
Definition: Euler1DFlux.c:16
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357
double * grav_field
Definition: euler1d.h:288
int(* UFunction)(double *, double *, int, void *, void *, double)
Definition: hypar.h:321
int Euler1DSourceUpwindLLF(double *, double *, double *, double *, int, void *, double)
#define _LLF_
Definition: euler1d.h:66
char upw_choice[_MAX_STRING_SIZE_]
Definition: euler1d.h:291