HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
InitializePhysics.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 <bandedmatrix.h>
11 #include <interpolation.h>
12 #include <mpivars.h>
13 #include <simulation_object.h>
14 
15 /* include header files for each physical model */
17 #include <physicalmodels/burgers.h>
22 #include <physicalmodels/euler1d.h>
23 #include <physicalmodels/euler2d.h>
26 #include <physicalmodels/numa2d.h>
27 #include <physicalmodels/numa3d.h>
30 #include <physicalmodels/vlasov.h>
31 
38 int InitializePhysics( void *s,
39  int nsims
40  )
41 {
43  int ns;
45 
46  if (nsims == 0) return 0;
47 
48  if (!sim[0].mpi.rank) {
49  printf("Initializing physics. Model = \"%s\"\n",sim[0].solver.model);
50  }
51 
52  for (ns = 0; ns < nsims; ns++) {
53 
54  HyPar *solver = &(sim[ns].solver);
55  MPIVariables *mpi = &(sim[ns].mpi);
56 
57  /* Initialize physics-specific functions to NULL */
58  solver->ComputeCFL = NULL;
59  solver->ComputeDiffNumber = NULL;
60  solver->FFunction = NULL;
61  solver->dFFunction = NULL;
62  solver->FdFFunction = NULL;
63  solver->GFunction = NULL;
64  solver->HFunction = NULL;
65  solver->SFunction = NULL;
66  solver->UFunction = NULL;
67  solver->JFunction = NULL;
68  solver->KFunction = NULL;
69  solver->Upwind = NULL;
70  solver->UpwinddF = NULL;
71  solver->UpwindFdF = NULL;
72  solver->PreStage = NULL;
73  solver->PostStage = NULL;
74  solver->PreStep = NULL;
75  solver->PostStep = NULL;
76  solver->PrintStep = NULL;
77  solver->PhysicsOutput = NULL;
78  solver->PhysicsInput = NULL;
79  solver->AveragingFunction = NULL;
80  solver->GetLeftEigenvectors = NULL;
81  solver->GetRightEigenvectors = NULL;
82  solver->IBFunction = NULL;
83 
84  if (!strcmp(solver->model,_LINEAR_ADVECTION_DIFFUSION_REACTION_)) {
85 
86  solver->physics = (LinearADR*) calloc (1,sizeof(LinearADR));
87  IERR LinearADRInitialize(solver,mpi); CHECKERR(ierr);
88 
89  } else if (!strcmp(solver->model,_BURGERS_)) {
90 
91  solver->physics = (Burgers*) calloc (1,sizeof(Burgers));
92  IERR BurgersInitialize(solver,mpi); CHECKERR(ierr);
93 
94  } else if (!strcmp(solver->model,_FP_DOUBLE_WELL_)) {
95 
96  solver->physics = (FPDoubleWell*) calloc (1,sizeof(FPDoubleWell));
97  IERR FPDoubleWellInitialize(solver,mpi); CHECKERR(ierr);
98 
99  } else if (!strcmp(solver->model,_FP_POWER_SYSTEM_)) {
100 
101  solver->physics = (FPPowerSystem*) calloc (1,sizeof(FPPowerSystem));
102  IERR FPPowerSystemInitialize(solver,mpi); CHECKERR(ierr);
103 
104  } else if (!strcmp(solver->model,_FP_POWER_SYSTEM_1BUS_)) {
105 
106  solver->physics = (FPPowerSystem1Bus*) calloc (1,sizeof(FPPowerSystem1Bus));
107  IERR FPPowerSystem1BusInitialize(solver,mpi); CHECKERR(ierr);
108 
109  } else if (!strcmp(solver->model,_FP_POWER_SYSTEM_3BUS_)) {
110 
111  solver->physics = (FPPowerSystem3Bus*) calloc (1,sizeof(FPPowerSystem3Bus));
112  IERR FPPowerSystem3BusInitialize(solver,mpi); CHECKERR(ierr);
113 
114  } else if (!strcmp(solver->model,_EULER_1D_)) {
115 
116  solver->physics = (Euler1D*) calloc (1,sizeof(Euler1D));
117  IERR Euler1DInitialize(solver,mpi); CHECKERR(ierr);
118 
119  } else if (!strcmp(solver->model,_EULER_2D_)) {
120 
121  solver->physics = (Euler2D*) calloc (1,sizeof(Euler2D));
122  IERR Euler2DInitialize(solver,mpi); CHECKERR(ierr);
123 
124  } else if (!strcmp(solver->model,_NAVIER_STOKES_2D_)) {
125 
126  solver->physics = (NavierStokes2D*) calloc (1,sizeof(NavierStokes2D));
127  IERR NavierStokes2DInitialize(solver,mpi); CHECKERR(ierr);
128 
129  } else if (!strcmp(solver->model,_NAVIER_STOKES_3D_)) {
130 
131  solver->physics = (NavierStokes3D*) calloc (1,sizeof(NavierStokes3D));
132  IERR NavierStokes3DInitialize(solver,mpi); CHECKERR(ierr);
133 
134  } else if (!strcmp(solver->model,_NUMA2D_)) {
135 
136  solver->physics = (Numa2D*) calloc (1,sizeof(Numa2D));
137  IERR Numa2DInitialize(solver,mpi); CHECKERR(ierr);
138 
139  } else if (!strcmp(solver->model,_NUMA3D_)) {
140 
141  solver->physics = (Numa3D*) calloc (1,sizeof(Numa3D));
142  IERR Numa3DInitialize(solver,mpi); CHECKERR(ierr);
143 
144  } else if (!strcmp(solver->model,_SHALLOW_WATER_1D_)) {
145 
146  solver->physics = (ShallowWater1D*) calloc (1,sizeof(ShallowWater1D));
147  IERR ShallowWater1DInitialize(solver,mpi); CHECKERR(ierr);
148 
149  } else if (!strcmp(solver->model,_SHALLOW_WATER_2D_)) {
150 
151  solver->physics = (ShallowWater2D*) calloc (1,sizeof(ShallowWater2D));
152  IERR ShallowWater2DInitialize(solver,mpi); CHECKERR(ierr);
153 
154  } else if (!strcmp(solver->model,_VLASOV_)) {
155 
156  solver->physics = (Vlasov*) calloc (1,sizeof(Vlasov));
157  IERR VlasovInitialize(solver,mpi); CHECKERR(ierr);
158 
159  }else {
160 
161  fprintf(stderr,"Error (domain %d): %s is not a supported physical model.\n",
162  ns, solver->model);
163  return(1);
164 
165  }
166 
167  /* some checks */
168  if ( ( (solver->GetLeftEigenvectors == NULL) || (solver->GetRightEigenvectors == NULL) )
169  && (!strcmp(solver->interp_type,_CHARACTERISTIC_)) && (solver->nvars > 1) ) {
170  if (!mpi->rank) {
171  fprintf(stderr,"Error (domain %d): Interpolation type is defined as characteristic ", ns);
172  fprintf(stderr,"but physics initializations returned NULL pointers for ");
173  fprintf(stderr,"Get(Left,Right)Eigenvectors needed for characteristic-based ");
174  fprintf(stderr,"reconstruction.\n");
175  }
176  return(1);
177  }
178 
179  if (!strcmp(solver->SplitHyperbolicFlux,"yes")) {
180  if ((!solver->dFFunction) || (!solver->UpwinddF)) {
181  if (!mpi->rank) {
182  fprintf(stderr,"Error (domain %d): Splitting of hyperbolic flux requires a dFFunction ", ns);
183  fprintf(stderr,"and its upwinding function UpwinddF.\n");
184  fprintf(stderr,"Error: f(u) = [f(u) - df(u)] + df(u).\n");
185  fprintf(stderr,"Error: dFFunction or UpwinddF (or both) is (are) NULL.\n");
186  }
187  return(1);
188  }
189  if (solver->FdFFunction && solver->UpwindFdF) solver->flag_fdf_specified = 1;
190  else solver->flag_fdf_specified = 0;
191  }
192 
193  if ((solver->IBFunction == NULL) && (solver->flag_ib)) {
194  if (!mpi->rank) {
195  fprintf(stderr,"Error in InitializePhysics() (domain %d): Physical model %s does not yet have an immersed boundary treatment.\n",
196  ns, solver->model);
197  }
198  return(1);
199  }
200 
201  }
202 
203  return(0);
204 }
#define _CHARACTERISTIC_
Definition: interpolation.h:33
int(* JFunction)(double *, double *, void *, int, int, int)
Definition: hypar.h:326
int(* PreStage)(int, double **, void *, void *, double)
Definition: hypar.h:334
int NavierStokes2DInitialize(void *, void *)
int(* dFFunction)(double *, double *, int, void *, double)
Definition: hypar.h:280
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
3D Navier Stokes equations (compressible flows)
Definitions for the functions computing the interpolated value of the primitive at the cell interface...
int VlasovInitialize(void *, void *)
#define _EULER_1D_
Definition: euler1d.h:50
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 NavierStokes3DInitialize(void *, void *)
int FPPowerSystem3BusInitialize(void *, void *)
3-Bus Power System model
int(* HFunction)(double *, double *, int, int, void *, double)
Definition: hypar.h:313
int Numa2DInitialize(void *, void *)
void * physics
Definition: hypar.h:266
int(* Upwind)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:295
char model[_MAX_STRING_SIZE_]
Definition: hypar.h:263
int(* GetRightEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:359
#define _LINEAR_ADVECTION_DIFFUSION_REACTION_
Definition: linearadr.h:21
int flag_fdf_specified
Definition: hypar.h:290
int flag_ib
Definition: hypar.h:441
int(* UpwinddF)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:300
Structure containing variables and parameters specific to the linear advection-diffusion-reaction mod...
Definition: linearadr.h:37
MPI related function definitions.
int(* UpwindFdF)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:307
int(* PhysicsOutput)(void *, void *, double)
Definition: hypar.h:347
int(* FdFFunction)(double *, double *, int, void *, double)
Definition: hypar.h:286
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
int(* PhysicsInput)(void *, void *, int, int, int *)
Definition: hypar.h:351
int LinearADRInitialize(void *, void *)
Linear Advection-Diffusion-Reaction model.
#define _FP_POWER_SYSTEM_1BUS_
#define _NAVIER_STOKES_3D_
#define _EULER_2D_
Definition: euler2d.h:25
2D Navier Stokes equations (compressible flows)
int(* PostStage)(double *, void *, void *, double)
Definition: hypar.h:336
Data structure and some function declarations for banded block matrices.
#define _FP_POWER_SYSTEM_3BUS_
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
double(* ComputeDiffNumber)(void *, void *, double, double)
Definition: hypar.h:272
Definition: numa3d.h:128
2D Shallow Water Equations
#define _NUMA2D_
Definition: numa2d.h:21
int BurgersInitialize(void *, void *)
#define _FP_DOUBLE_WELL_
Definition: fpdoublewell.h:18
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357
int FPPowerSystem1BusInitialize(void *, void *)
Simulation object.
Definition: vlasov.h:57
int InitializePhysics(void *, int)
int ShallowWater1DInitialize(void *, void *)
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
int(* KFunction)(double *, double *, void *, int, int)
Definition: hypar.h:331
#define _FP_POWER_SYSTEM_
Definition: fppowersystem.h:44
#define _BURGERS_
Definition: burgers.h:14
int nvars
Definition: hypar.h:29
#define _VLASOV_
Definition: vlasov.h:37
Vlasov Equation.
#define CHECKERR(ierr)
Definition: basic.h:18
Structure containing variable and parameters specific to the 3-bus power system model. This structure contains the physical parameters and variables for the Fokker-Planck model for a 3-bus power system.
char interp_type[_MAX_STRING_SIZE_]
Definition: hypar.h:88
Definition: numa2d.h:109
int Numa3DInitialize(void *, void *)
int(* UFunction)(double *, double *, int, void *, void *, double)
Definition: hypar.h:321
int ShallowWater2DInitialize(void *, void *)
1D Shallow Water Equations
#define _SHALLOW_WATER_2D_
Structure containing variables and parameters specific to the 3D Navier Stokes equations. This structure contains the physical parameters, variables, and function pointers specific to the 3D Navier-Stokes equations.
Structure defining a simulation.
int FPPowerSystemInitialize(void *, void *)
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
Some basic definitions and macros.
int(* PrintStep)(void *, void *, double)
Definition: hypar.h:344
Structure containing variables and parameters specific to the 2D Navier Stokes equations. This structure contains the physical parameters, variables, and function pointers specific to the 2D Navier-Stokes equations.
#define _NUMA3D_
Definition: numa3d.h:26
#define IERR
Definition: basic.h:16
int Euler2DInitialize(void *, void *)
int(* IBFunction)(void *, void *, double *, double)
Definition: hypar.h:446
int FPDoubleWellInitialize(void *, void *)
int(* PreStep)(double *, void *, void *, double)
Definition: hypar.h:339
int Euler1DInitialize(void *, void *)
1D Euler Equations (inviscid, compressible flows)
Structure of MPI-related variables.
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
Structure containing variables and parameters specific to the 1D Euler equations. This structure cont...
Definition: euler1d.h:273
Fokker-Planck Model for 1-Bus Power System.
int(* GFunction)(double *, double *, int, void *, double)
Definition: hypar.h:310
#define _NAVIER_STOKES_2D_
int(* PostStep)(double *, void *, void *, double, int)
Definition: hypar.h:341
#define _DECLARE_IERR_
Definition: basic.h:17
#define _SHALLOW_WATER_1D_