HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
ShallowWater2DInitialize.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 ShallowWater2DComputeCFL (void*,void*,double,double);
16 int ShallowWater2DFlux (double*,double*,int,void*,double);
17 int ShallowWater2DSource (double*,double*,void*,void*,double);
18 int ShallowWater2DUpwindRoe (double*,double*,double*,double*,double*,double*,int,void*,double);
19 int ShallowWater2DUpwindLLF (double*,double*,double*,double*,double*,double*,int,void*,double);
20 
21 int ShallowWater2DJacobian (double*,double*,void*,int,int,int);
22 int ShallowWater2DRoeAverage (double*,double*,double*,void*);
23 int ShallowWater2DLeftEigenvectors (double*,double*,void*,int);
24 int ShallowWater2DRightEigenvectors (double*,double*,void*,int);
25 
26 int ShallowWater2DTopography (void*,void*,int,int, int*);
27 int ShallowWater2DSourceUpwindLLF (double*,double*,double*,double*,int,void*,double);
28 int ShallowWater2DSourceUpwindRoe (double*,double*,double*,double*,int,void*,double);
29 
30 int ShallowWater2DModifiedSolution (double*,double*,int,void*,void*,double);
31 int ShallowWater2DWriteTopography (void*,void*,double);
32 
38  void *s,
39  void *m
40  )
41 {
42  HyPar *solver = (HyPar*) s;
43  MPIVariables *mpi = (MPIVariables*) m;
44  ShallowWater2D *physics = (ShallowWater2D*) solver->physics;
45  int ferr, d;
46 
47  static int count = 0;
48 
49  if (solver->nvars != _MODEL_NVARS_) {
50  fprintf(stderr,"Error in ShallowWater2DInitialize(): nvars has to be %d.\n",_MODEL_NVARS_);
51  return(1);
52  }
53  if (solver->ndims != _MODEL_NDIMS_) {
54  fprintf(stderr,"Error in ShallowWater2DInitialize(): 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  physics->fhat = 0.0;
62  physics->beta = 0.0;
63  physics->D = 0.0;
64  strcpy(physics->upw_choice,"roe");
65 
66  /* reading physical model specific inputs */
67  if (!mpi->rank) {
68  FILE *in;
69  if (!count) printf("Reading physical model inputs from file \"physics.inp\".\n");
70  in = fopen("physics.inp","r");
71  if (!in) printf("Warning: File \"physics.inp\" not found. Using default values.\n");
72  else {
73  char word[_MAX_STRING_SIZE_];
74  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
75  if (!strcmp(word, "begin")){
76  while (strcmp(word, "end")){
77  ferr = fscanf(in,"%s",word); if (ferr != 1) return(1);
78  if (!strcmp(word, "gravity")) {
79  ferr = fscanf(in,"%lf",&physics->g);
80  if (ferr != 1) return(1);
81  } else if (!strcmp(word, "topography_type")) {
82  ferr = fscanf(in,"%d",&physics->bt_type);
83  if (ferr != 1) return(1);
84  } else if (!strcmp(word, "coriolis_fhat")) {
85  ferr = fscanf(in,"%lf",&physics->fhat);
86  if (ferr != 1) return(1);
87  } else if (!strcmp(word, "coriolis_beta")) {
88  ferr = fscanf(in,"%lf",&physics->beta);
89  if (ferr != 1) return(1);
90  } else if (!strcmp(word, "coriolis_D")) {
91  ferr = fscanf(in,"%lf",&physics->D);
92  if (ferr != 1) return(1);
93  } else if (!strcmp(word,"upwinding")) {
94  ferr = fscanf(in,"%s",physics->upw_choice);
95  if (ferr != 1) return(1);
96  } else if (strcmp(word,"end")) {
97  char useless[_MAX_STRING_SIZE_];
98  ferr = fscanf(in,"%s",useless); if (ferr != 1) return(ferr);
99  printf("Warning: keyword %s in file \"physics.inp\" with value %s not ",word,useless);
100  printf("recognized or extraneous. Ignoring.\n");
101  }
102  }
103  } else {
104  fprintf(stderr,"Error: Illegal format in file \"physics.inp\".\n");
105  return(1);
106  }
107  }
108  fclose(in);
109  }
110 
111 #ifndef serial
112  IERR MPIBroadcast_double (&physics->g ,1,0,&mpi->world); CHECKERR(ierr);
113  IERR MPIBroadcast_integer (&physics->bt_type ,1,0,&mpi->world); CHECKERR(ierr);
114  IERR MPIBroadcast_double (&physics->fhat ,1,0,&mpi->world); CHECKERR(ierr);
115  IERR MPIBroadcast_double (&physics->beta ,1,0,&mpi->world); CHECKERR(ierr);
116  IERR MPIBroadcast_double (&physics->D ,1,0,&mpi->world); CHECKERR(ierr);
118 #endif
119 
120  /* initializing physical model-specific functions */
122  solver->FFunction = ShallowWater2DFlux;
126  if (!strcmp(physics->upw_choice,_ROE_ )) solver->Upwind = ShallowWater2DUpwindRoe;
127  else if (!strcmp(physics->upw_choice,_LLF_ )) solver->Upwind = ShallowWater2DUpwindLLF;
128  else {
129  if (!mpi->rank) fprintf(stderr,"Error in ShallowWater2DInitialize(): %s is not a valid upwinding scheme.\n",
130  physics->upw_choice);
131  return(1);
132  }
137 
138  if (!strcmp(physics->upw_choice,_LLF_ )) physics->SourceUpwind = ShallowWater2DSourceUpwindLLF;
139  else if (!strcmp(physics->upw_choice,_ROE_ )) physics->SourceUpwind = ShallowWater2DSourceUpwindRoe;
140 
141  /* allocate array to hold the bottom topography field */
142  physics->b = (double*) calloc (solver->npoints_local_wghosts, sizeof(double));
144 
145  count++;
146  return(0);
147 }
int(* PhysicsOutput)(void *, void *, double)
Definition: hypar.h:347
int nvars
Definition: hypar.h:29
#define IERR
Definition: basic.h:16
MPI related function definitions.
int ShallowWater2DLeftEigenvectors(double *, double *, void *, int)
#define CHECKERR(ierr)
Definition: basic.h:18
char upw_choice[_MAX_STRING_SIZE_]
int(* SourceUpwind)(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.
double ShallowWater2DComputeCFL(void *, void *, double, double)
int ShallowWater2DTopography(void *, void *, int, int, int *)
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
2D Shallow Water Equations
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 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 ShallowWater2DModifiedSolution(double *, double *, int, void *, void *, double)
int ShallowWater2DSource(double *, double *, void *, void *, double)
int MPIBroadcast_double(double *, int, int, void *)
Definition: MPIBroadcast.c:9
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
Structure containing variables and parameters specific to the 2D Shallow Water equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D ShallowWater equations.
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 ShallowWater2DFlux(double *, double *, int, void *, double)
int ShallowWater2DJacobian(double *, double *, void *, int, int, int)
#define _MODEL_NDIMS_
Definition: euler1d.h:56
Contains structure definition for hypar.
int ShallowWater2DRightEigenvectors(double *, double *, void *, int)
MPI_Comm world
int ShallowWater2DUpwindLLF(double *, double *, double *, double *, double *, double *, int, void *, double)
int ShallowWater2DWriteTopography(void *, void *, double)
void * physics
Definition: hypar.h:266
int(* JFunction)(double *, double *, void *, int, int, int)
Definition: hypar.h:326
int ShallowWater2DSourceUpwindLLF(double *, double *, double *, double *, int, void *, double)
int ShallowWater2DSourceUpwindRoe(double *, double *, double *, double *, int, void *, double)
Structure of MPI-related variables.
#define _MODEL_NVARS_
Definition: euler1d.h:58
int npoints_local_wghosts
Definition: hypar.h:42
Contains macros and function definitions for common array operations.
int(* GetRightEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:359
int ShallowWater2DInitialize(void *s, void *m)
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357
int ShallowWater2DRoeAverage(double *, double *, double *, void *)
int(* UFunction)(double *, double *, int, void *, void *, double)
Definition: hypar.h:321
int ShallowWater2DUpwindRoe(double *, double *, double *, double *, double *, double *, int, void *, double)
#define _LLF_
Definition: euler1d.h:66