HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
InitializePhysics.c File Reference

Initialize the physical model. More...

Go to the source code of this file.

Functions

int InitializePhysics (void *s, int nsims)
 

Detailed Description

Initialize the physical model.

Author
Debojyoti Ghosh

Definition in file InitializePhysics.c.

Function Documentation

◆ InitializePhysics()

int InitializePhysics ( void *  s,
int  nsims 
)

Initialize the physical model for a simulation: Depending on the physical model specified, this function calls the initialization function for that physical model. The latter is responsible for setting all the physics-specific functions that are required by the model.

Parameters
sArray of simulation objects of type SimulationObject
nsimsnumber of simulation objects

Definition at line 38 of file InitializePhysics.c.

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 }
int Euler2DInitialize(void *, void *)
Definition: vlasov.h:57
int FPPowerSystemInitialize(void *, void *)
#define _FP_DOUBLE_WELL_
Definition: fpdoublewell.h:18
int(* PrintStep)(void *, void *, double)
Definition: hypar.h:344
#define _FP_POWER_SYSTEM_3BUS_
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.
#define _LINEAR_ADVECTION_DIFFUSION_REACTION_
Definition: linearadr.h:21
int NavierStokes3DInitialize(void *, void *)
int(* PhysicsOutput)(void *, void *, double)
Definition: hypar.h:347
int(* GFunction)(double *, double *, int, void *, double)
Definition: hypar.h:310
int nvars
Definition: hypar.h:29
#define IERR
Definition: basic.h:16
#define CHECKERR(ierr)
Definition: basic.h:18
Structure defining a simulation.
Structure containing variables and parameters specific to the 1D Euler equations. This structure cont...
Definition: euler1d.h:273
char SplitHyperbolicFlux[_MAX_STRING_SIZE_]
Definition: hypar.h:92
#define _NAVIER_STOKES_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.
int VlasovInitialize(void *, void *)
#define _CHARACTERISTIC_
Definition: interpolation.h:33
#define _BURGERS_
Definition: burgers.h:14
int ShallowWater2DInitialize(void *, void *)
int(* KFunction)(double *, double *, void *, int, int)
Definition: hypar.h:331
int(* HFunction)(double *, double *, int, int, void *, double)
Definition: hypar.h:313
int(* AveragingFunction)(double *, double *, double *, void *)
Definition: hypar.h:354
#define _VLASOV_
Definition: vlasov.h:37
int flag_ib
Definition: hypar.h:441
int(* FdFFunction)(double *, double *, int, void *, double)
Definition: hypar.h:286
int(* SFunction)(double *, double *, void *, void *, double)
Definition: hypar.h:317
int(* IBFunction)(void *, void *, double *, double)
Definition: hypar.h:446
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
Definition: numa3d.h:128
Structure containing variables and parameters specific to the linear advection-diffusion-reaction mod...
Definition: linearadr.h:37
int(* FFunction)(double *, double *, int, void *, double)
Definition: hypar.h:276
#define _FP_POWER_SYSTEM_1BUS_
#define _FP_POWER_SYSTEM_
Definition: fppowersystem.h:44
double(* ComputeCFL)(void *, void *, double, double)
Definition: hypar.h:269
int FPPowerSystem1BusInitialize(void *, void *)
int ShallowWater1DInitialize(void *, void *)
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
Definition: numa2d.h:109
int Euler1DInitialize(void *, void *)
#define _SHALLOW_WATER_1D_
int(* PreStage)(int, double **, void *, void *, double)
Definition: hypar.h:334
int FPDoubleWellInitialize(void *, void *)
char interp_type[_MAX_STRING_SIZE_]
Definition: hypar.h:88
#define _SHALLOW_WATER_2D_
#define _EULER_1D_
Definition: euler1d.h:50
int(* PreStep)(double *, void *, void *, double)
Definition: hypar.h:339
int(* UpwindFdF)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:307
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.
double(* ComputeDiffNumber)(void *, void *, double, double)
Definition: hypar.h:272
int flag_fdf_specified
Definition: hypar.h:290
int LinearADRInitialize(void *, void *)
int(* PostStep)(double *, void *, void *, double, int)
Definition: hypar.h:341
#define _NUMA3D_
Definition: numa3d.h:26
int(* dFFunction)(double *, double *, int, void *, double)
Definition: hypar.h:280
void * physics
Definition: hypar.h:266
int NavierStokes2DInitialize(void *, void *)
char model[_MAX_STRING_SIZE_]
Definition: hypar.h:263
int(* JFunction)(double *, double *, void *, int, int, int)
Definition: hypar.h:326
int BurgersInitialize(void *, void *)
int(* PostStage)(double *, void *, void *, double)
Definition: hypar.h:336
int(* UpwinddF)(double *, double *, double *, double *, double *, double *, int, void *, double)
Definition: hypar.h:300
#define _NUMA2D_
Definition: numa2d.h:21
#define _EULER_2D_
Definition: euler2d.h:25
Structure of MPI-related variables.
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.
#define _DECLARE_IERR_
Definition: basic.h:17
#define _NAVIER_STOKES_3D_
int(* GetRightEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:359
int(* GetLeftEigenvectors)(double *, double *, void *, int)
Definition: hypar.h:357
int FPPowerSystem3BusInitialize(void *, void *)
int(* UFunction)(double *, double *, int, void *, void *, double)
Definition: hypar.h:321
int Numa3DInitialize(void *, void *)
int Numa2DInitialize(void *, void *)