HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
ShallowWater1DInitialize.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>
12 #include <mpivars.h>
13 #include <hypar.h>
14 
15 double ShallowWater1DComputeCFL (void*,void*,double,double);
16 int ShallowWater1DFlux (double*,double*,int,void*,double);
17 int ShallowWater1DSource (double*,double*,void*,void*,double);
18 int ShallowWater1DUpwindRoe (double*,double*,double*,double*,double*,double*,int,void*,double);
19 int ShallowWater1DUpwindLLF (double*,double*,double*,double*,double*,double*,int,void*,double);
20 
21 int ShallowWater1DJacobian (double*,double*,void*,int,int,int);
22 int ShallowWater1DRoeAverage (double*,double*,double*,void*);
23 int ShallowWater1DLeftEigenvectors (double*,double*,void*,int);
24 int ShallowWater1DRightEigenvectors (double*,double*,void*,int);
25 
26 int ShallowWater1DTopography (void*,void*,int,int, int*);
27 int ShallowWater1DSourceUpwindLLF (double*,double*,double*,double*,int,void*,double);
28 int ShallowWater1DSourceUpwindRoe (double*,double*,double*,double*,int,void*,double);
29 
30 int ShallowWater1DModifiedSolution (double*,double*,int,void*,void*,double);
31 int ShallowWater1DWriteTopography (void*,void*,double);
32 
38  void *s,
39  void *m
40  )
41 {
42  HyPar *solver = (HyPar*) s;
43  MPIVariables *mpi = (MPIVariables*) m;
44  ShallowWater1D *physics = (ShallowWater1D*) solver->physics;
45  int ferr, d;
46 
47  static int count = 0;
48 
49  if (solver->nvars != _MODEL_NVARS_) {
50  fprintf(stderr,"Error in ShallowWater1DInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
51  return(1);
52  }
53  if (solver->ndims != _MODEL_NDIMS_) {
54  fprintf(stderr,"Error in ShallowWater1DInitialize(): ndims has to be %d.\n",_MODEL_NDIMS_);
55  return(1);
56  }
57 
58  /* default values */
59  physics->g = 1.0;
60  physics->bt_type = 0;
61  strcpy(physics->upw_choice,"roe");
62 
63  /* reading physical model specific inputs */
64  if (!mpi->rank) {
65  FILE *in;
66  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
67  in = fopen("physics.inp","r");
68  if (!in) printf("Warning: File \"physics.inp\" not found. Using default values.\n");
69  else {
70  char word[_MAX_STRING_SIZE_];
71  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
72  if (!strcmp(word, "begin")){
73  while (strcmp(word, "end")){
74  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
75  if (!strcmp(word, "gravity")) {
76  ferr = fscanf(in,"%lf",&physics->g);
77  if (ferr != 1) return(1);
78  } else if (!strcmp(word, "topography_type")) {
79  ferr = fscanf(in,"%d",&physics->bt_type);
80  if (ferr != 1) return(1);
81  } else if (!strcmp(word,"upwinding")) {
82  ferr = fscanf(in,"%s",physics->upw_choice);
83  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->g ,1,0,&mpi->world); CHECKERR(ierr);
101  IERR MPIBroadcast_integer (&physics->bt_type ,1,0,&mpi->world); CHECKERR(ierr);
103 #endif
104 
105  /* initializing physical model-specific functions */
107  solver->FFunction = ShallowWater1DFlux;
111  if (!strcmp(physics->upw_choice,_ROE_ )) solver->Upwind = ShallowWater1DUpwindRoe;
112  else if (!strcmp(physics->upw_choice,_LLF_ )) solver->Upwind = ShallowWater1DUpwindLLF;
113  else {
114  if (!mpi->rank) fprintf(stderr,"Error in ShallowWater1DInitialize(): %s is not a valid upwinding scheme.\n",
115  physics->upw_choice);
116  return(1);
117  }
122 
123  if (!strcmp(physics->upw_choice,_LLF_ )) physics->SourceUpwind = ShallowWater1DSourceUpwindLLF;
124  else if (!strcmp(physics->upw_choice,_ROE_ )) physics->SourceUpwind = ShallowWater1DSourceUpwindRoe;
125 
126  /* allocate array to hold the bottom topography field */
127  physics->b = (double*) calloc (solver->npoints_local_wghosts, sizeof(double));
128  /* set function pointer to read this topography */
130 
131  count++;
132  return(0);
133 }
Structure containing variables and parameters specific to the 1D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 1D ShallowWater equations.
int(* PhysicsOutput)(void *, void *, double)
Definition: hypar.h:347
int ShallowWater1DInitialize(void *s, void *m)
int ShallowWater1DSource(double *, double *, void *, void *, double)
int nvars
Definition: hypar.h:29
1D Shallow Water Equations
#define IERR
Definition: basic.h:16
MPI related function definitions.
#define CHECKERR(ierr)
Definition: basic.h:18
int ShallowWater1DRoeAverage(double *, double *, double *, void *)
int ShallowWater1DUpwindLLF(double *, double *, double *, double *, double *, double *, int, void *, double)
int MPIBroadcast_integer(int *, int, int, void *)
Definition: MPIBroadcast.c:23
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
Some basic definitions and macros.
int(* SourceUpwind)(double *, double *, double *, double *, int, void *, double)
int ShallowWater1DJacobian(double *, double *, void *, int, int, int)
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
int(* PhysicsInput)(void *, void *, int, int, int *)
Definition: hypar.h:351
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
int ShallowWater1DTopography(void *, void *, int, int, int *)
int ndims
Definition: hypar.h:26
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
#define _MAX_STRING_SIZE_
Definition: basic.h:14
#define _ROE_
Definition: euler1d.h:62
int ShallowWater1DModifiedSolution(double *, double *, int, void *, void *, double)
#define _MODEL_NDIMS_
Definition: euler1d.h:56
Contains structure definition for hypar.
MPI_Comm world
int ShallowWater1DSourceUpwindRoe(double *, double *, double *, double *, int, void *, double)
int ShallowWater1DRightEigenvectors(double *, double *, void *, int)
void * physics
Definition: hypar.h:266
int ShallowWater1DFlux(double *, double *, int, void *, double)
int(* JFunction)(double *, double *, void *, int, int, int)
Definition: hypar.h:326
char upw_choice[_MAX_STRING_SIZE_]
double ShallowWater1DComputeCFL(void *, void *, double, double)
Structure of MPI-related variables.
#define _MODEL_NVARS_
Definition: euler1d.h:58
int npoints_local_wghosts
Definition: hypar.h:42
int ShallowWater1DUpwindRoe(double *, double *, double *, double *, double *, double *, int, void *, double)
int ShallowWater1DLeftEigenvectors(double *, double *, void *, int)
Contains macros and function definitions for common array operations.
int(* GetRightEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:359
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357
int(* UFunction)(double *, double *, int, void *, void *, double)
Definition: hypar.h:321
int ShallowWater1DSourceUpwindLLF(double *, double *, double *, double *, int, void *, double)
int ShallowWater1DWriteTopography(void *, void *, double)
#define _LLF_
Definition: euler1d.h:66