HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
BCSubsonicInflow.c
Go to the documentation of this file.
1 
6 #include <stdlib.h>
7 #include <basic.h>
8 #include <arrayfunctions.h>
9 #include <boundaryconditions.h>
10 
11 #include <physicalmodels/euler2d.h>
13 
21  void *b,
22  void *m,
23  int ndims,
24  int nvars,
25  int *size,
26  int ghosts,
27  double *phi,
28  double waqt
29  )
30 {
31  DomainBoundary *boundary = (DomainBoundary*) b;
32 
33  int dim = boundary->dim;
34  int face = boundary->face;
35 
36  if (ndims == 2) {
37 
38  /* create a fake physics object */
39  Euler2D physics;
40  double gamma;
41  gamma = physics.gamma = boundary->gamma;
42  double inv_gamma_m1 = 1.0/(gamma-1.0);
43 
44  if (boundary->on_this_proc) {
45  int bounds[ndims], indexb[ndims], indexi[ndims];
46  _ArraySubtract1D_(bounds,boundary->ie,boundary->is,ndims);
47  _ArraySetValue_(indexb,ndims,0);
48  int done = 0;
49  while (!done) {
50  int p1, p2;
51  _ArrayCopy1D_(indexb,indexi,ndims);
52  _ArrayAdd1D_(indexi,indexi,boundary->is,ndims);
53  if (face == 1) indexi[dim] = ghosts-1-indexb[dim];
54  else if (face == -1) indexi[dim] = size[dim]-indexb[dim]-1;
55  else return(1);
56  _ArrayIndex1DWO_(ndims,size,indexb,boundary->is,ghosts,p1);
57  _ArrayIndex1D_(ndims,size,indexi,ghosts,p2);
58 
59  /* flow variables in the interior */
60  double rho, uvel, vvel, energy, pressure;
61  double rho_gpt, uvel_gpt, vvel_gpt, energy_gpt, pressure_gpt;
62  _Euler2DGetFlowVar_((phi+nvars*p2),rho,uvel,vvel,energy,pressure,(&physics));
63  /* set the ghost point values */
64  rho_gpt = boundary->FlowDensity;
65  pressure_gpt = pressure;
66  uvel_gpt = boundary->FlowVelocity[0];
67  vvel_gpt = boundary->FlowVelocity[1];
68  energy_gpt = inv_gamma_m1*pressure_gpt
69  + 0.5 * rho_gpt * (uvel_gpt*uvel_gpt + vvel_gpt*vvel_gpt);
70 
71  phi[nvars*p1+0] = rho_gpt;
72  phi[nvars*p1+1] = rho_gpt * uvel_gpt;
73  phi[nvars*p1+2] = rho_gpt * vvel_gpt;
74  phi[nvars*p1+3] = energy_gpt;
75 
76  _ArrayIncrementIndex_(ndims,bounds,indexb,done);
77  }
78  }
79 
80  } else if (ndims == 3) {
81 
82  /* create a fake physics object */
83  double gamma;
84  gamma = boundary->gamma;
85  double inv_gamma_m1 = 1.0/(gamma-1.0);
86 
87  if (boundary->on_this_proc) {
88  int bounds[ndims], indexb[ndims], indexi[ndims];
89  _ArraySubtract1D_(bounds,boundary->ie,boundary->is,ndims);
90  _ArraySetValue_(indexb,ndims,0);
91  int done = 0;
92  while (!done) {
93  int p1, p2;
94  _ArrayCopy1D_(indexb,indexi,ndims);
95  _ArrayAdd1D_(indexi,indexi,boundary->is,ndims);
96  if (face == 1) indexi[dim] = ghosts-1-indexb[dim];
97  else if (face == -1) indexi[dim] = size[dim]-indexb[dim]-1;
98  else return(1);
99  _ArrayIndex1DWO_(ndims,size,indexb,boundary->is,ghosts,p1);
100  _ArrayIndex1D_(ndims,size,indexi,ghosts,p2);
101 
102  /* flow variables in the interior */
103  double rho, uvel, vvel, wvel, energy, pressure;
104  double rho_gpt, uvel_gpt, vvel_gpt, wvel_gpt, energy_gpt, pressure_gpt;
105  _NavierStokes3DGetFlowVar_((phi+nvars*p2),_NavierStokes3D_stride_,rho,uvel,vvel,wvel,energy,pressure,gamma);
106  /* set the ghost point values */
107  rho_gpt = boundary->FlowDensity;
108  pressure_gpt = pressure;
109  uvel_gpt = boundary->FlowVelocity[0];
110  vvel_gpt = boundary->FlowVelocity[1];
111  wvel_gpt = boundary->FlowVelocity[2];
112  energy_gpt = inv_gamma_m1*pressure_gpt
113  + 0.5 * rho_gpt
114  * (uvel_gpt*uvel_gpt + vvel_gpt*vvel_gpt + wvel_gpt*wvel_gpt);
115 
116  phi[nvars*p1+0] = rho_gpt;
117  phi[nvars*p1+1] = rho_gpt * uvel_gpt;
118  phi[nvars*p1+2] = rho_gpt * vvel_gpt;
119  phi[nvars*p1+3] = rho_gpt * wvel_gpt;
120  phi[nvars*p1+4] = energy_gpt;
121 
122  _ArrayIncrementIndex_(ndims,bounds,indexb,done);
123  }
124  }
125 
126  }
127  return(0);
128 }
Containts the structures and definitions for boundary condition implementation.
Some basic definitions and macros.
Structure containing the variables and function pointers defining a boundary.
3D Navier Stokes equations (compressible flows)
#define _Euler2DGetFlowVar_(u, rho, vx, vy, e, P, p)
Definition: euler2d.h:44
#define _ArraySubtract1D_(x, a, b, size)
#define _ArrayAdd1D_(x, a, b, size)
double gamma
Definition: euler2d.h:245
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArrayIndex1DWO_(N, imax, i, offset, ghost, index)
static const int _NavierStokes3D_stride_
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
int BCSubsonicInflowU(void *b, void *m, int ndims, int nvars, int *size, int ghosts, double *phi, double waqt)
#define _ArrayCopy1D_(x, y, size)
Contains macros and function definitions for common array operations.
#define _NavierStokes3DGetFlowVar_(u, stride, rho, vx, vy, vz, e, P, gamma)