PLUTO
init.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Viscous compressible flow past a cylinder.
5 
6  Set initial and boundary conditions for a flow past a cylinder in 2D
7  cylindrical polar coordinates \f$(r,\phi)\f$.
8  The cylinder has radius 1 and the domain is initially filled with
9  constant-density and pressure gas with value \f$\rho = 1,\, p = 1/\Gamma\f$.
10 
11  The velocity field is initialized using the potential flow solution
12  for an inviscid incompressible flow around a cylinder,
13  \f[
14  V_r = U\left(1 - \frac{1}{r^2}\right)\cos\theta \,,\qquad
15  V_\phi = -U\left(1 + \frac{1}{r^2}\right)\sin\theta
16  \f]
17  where \c U, the far-field velocity, is given by the Mach number.
18  The boundary conditions in \c phi are periodic while the outer radial
19  boundary is set to inflow for negative values of x while outflow
20  for positive values.
21  A no-slip boundary condition is used at the fluid-solid interface.
22 
23  The flow past the cylinder, no matter how small the viscosity, will
24  acquire vorticity in a thin boundary layer adjacent to the cylinder.
25  Boundary layer separation may occur leading to the formation of a trailing
26  wake behind the cylinder.
27 
28  The input parameters are:
29  - \c g_inputParam[MACH]: sets the upstream Mach number
30  - \c g_inputParam[NU_VISC]: sets the viscosity
31 
32  \image html hd_flow_past_cylinder.01.jpg "Density map for configuration #01"
33  \image html hd_flow_past_cylinder.04.jpg "Entropy distribution for configuration #04 using 3 levels of refinement."
34 
35  \author A. Mignone (mignone@ph.unito.it)
36  \date Aug 18, 2014
37 */
38 /* ///////////////////////////////////////////////////////////////////// */
39 #include "pluto.h"
40 
41 /* ********************************************************************* */
42 void Init (double *v, double x1, double x2, double x3)
43 /*
44  *
45  *
46  *********************************************************************** */
47 {
48  double x, y;
49  double U = g_inputParam[MACH];
50 
51  v[RHO] = 1.0 + 0.05*sin(x2)*cos(x2);
52  v[PRS] = 1.0/g_gamma;
53  v[TRC] = 0.0;
54 
55  v[VX1] = U*(1.0 - 1.0/(x1*x1))*cos(x2);
56  v[VX2] = -U*(1.0 + 1.0/(x1*x1))*sin(x2);
57 }
58 /* ********************************************************************* */
59 void Analysis (const Data *d, Grid *grid)
60 /*
61  *
62  *********************************************************************** */
63 {}
64 
65 /* ********************************************************************* */
66 void UserDefBoundary (const Data *d, RBox *box, int side, Grid *grid)
67 /*
68  *
69  *
70  *********************************************************************** */
71 {
72  int i, j, k, nv;
73  double *x1, *x2, *x3;
74  double x, y, r, rnd, Mach;
75  double c, s;
76 
77  x1 = grid[IDIR].x;
78  x2 = grid[JDIR].x;
79  x3 = grid[KDIR].x;
80 
81  if (side == 0) { /* -- check solution inside domain -- */
82  TOT_LOOP(k,j,i){
83  }
84  }
85 
86  if (side == X1_BEG){ /* -- X1_BEG boundary -- */
87  if (box->vpos == CENTER) {
88  BOX_LOOP(box,k,j,i){
89  d->Vc[RHO][k][j][i] = d->Vc[RHO][k][j][2*IBEG - i - 1];
90  d->Vc[PRS][k][j][i] = d->Vc[PRS][k][j][2*IBEG - i - 1];
91  d->Vc[VX1][k][j][i] = -d->Vc[VX1][k][j][2*IBEG - i - 1];
92  d->Vc[VX2][k][j][i] = -d->Vc[VX2][k][j][2*IBEG - i - 1];
93  }
94  }else if (box->vpos == X1FACE){
95  BOX_LOOP(box,k,j,i){ }
96  }else if (box->vpos == X2FACE){
97  BOX_LOOP(box,k,j,i){ }
98  }else if (box->vpos == X3FACE){
99  BOX_LOOP(box,k,j,i){ }
100  }
101  }
102 
103  if (side == X1_END){ /* -- X1_END boundary -- */
104  if (box->vpos == CENTER) {
105  BOX_LOOP(box,k,j,i){
106  c = cos(x2[j]);
107  s = sin(x2[j]);
108  x = x1[i]*c;
109  y = x1[i]*s;
110  if (x < 0.0){
111 /* rnd = RandomNumber(-1.0, 1.0); */
112  rnd = 0.0;
113  Mach = g_inputParam[MACH]*(1.0 + 0.1*rnd);
114  d->Vc[RHO][k][j][i] = 1.0;
115  d->Vc[PRS][k][j][i] = 1.0/g_gamma;
116  d->Vc[VX1][k][j][i] = Mach*c;
117  d->Vc[VX2][k][j][i] = -Mach*s;
118  }else{
119  d->Vc[RHO][k][j][i] = d->Vc[RHO][k][j][IEND];
120  d->Vc[PRS][k][j][i] = d->Vc[PRS][k][j][IEND];
121  d->Vc[VX1][k][j][i] = d->Vc[VX1][k][j][IEND];
122  d->Vc[VX2][k][j][i] = d->Vc[VX2][k][j][IEND];
123  }
124 
125  }
126  }else if (box->vpos == X1FACE){
127  BOX_LOOP(box,k,j,i){ }
128  }else if (box->vpos == X2FACE){
129  BOX_LOOP(box,k,j,i){ }
130  }else if (box->vpos == X3FACE){
131  BOX_LOOP(box,k,j,i){ }
132  }
133  }
134 }
135 
136 #if BODY_FORCE != NO
137 /* ********************************************************************* */
138 void BodyForceVector(double *v, double *g, double x1, double x2, double x3)
139 /*
140  *
141  *
142  *********************************************************************** */
143 {
144  g[IDIR] = 0.0;
145  g[JDIR] = 0.0;
146  g[KDIR] = 0.0;
147 }
148 /* ********************************************************************* */
149 double BodyForcePotential(double x1, double x2, double x3)
150 /*
151  *
152  *
153  *********************************************************************** */
154 {
155  return 0.0;
156 }
157 #endif
#define X1_BEG
Boundary region at X1 beg.
Definition: pluto.h:146
double g_gamma
Definition: globals.h:112
#define MACH
void UserDefBoundary(const Data *d, RBox *box, int side, Grid *grid)
Definition: init.c:98
#define VX2
Definition: mod_defs.h:29
#define CENTER
Definition: pluto.h:200
int vpos
Location of the variable inside the cell.
Definition: structs.h:359
#define RHO
Definition: mod_defs.h:19
#define X3FACE
Definition: pluto.h:203
#define BOX_LOOP(B, k, j, i)
Definition: macros.h:70
double **** Vc
The main four-index data array used for cell-centered primitive variables.
Definition: structs.h:31
#define TRC
Definition: pluto.h:581
#define X1_END
Boundary region at X1 end.
Definition: pluto.h:147
#define VX1
Definition: mod_defs.h:28
#define KDIR
Definition: pluto.h:195
#define X1FACE
Definition: pluto.h:201
#define TOT_LOOP(k, j, i)
Definition: macros.h:44
#define IDIR
Definition: pluto.h:193
Definition: structs.h:78
double g_inputParam[32]
Array containing the user-defined parameters.
Definition: globals.h:131
int j
Definition: analysis.c:2
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:37
int k
Definition: analysis.c:2
double * x
Definition: structs.h:80
tuple c
Definition: menu.py:375
#define s
PLUTO main header file.
Definition: structs.h:30
int i
Definition: analysis.c:2
double BodyForcePotential(double x, double y, double z)
Definition: init.c:479
#define JDIR
Definition: pluto.h:194
Definition: structs.h:346
#define X2FACE
Definition: pluto.h:202
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
Definition: globals.h:35
void Analysis(const Data *d, Grid *grid)
Definition: init.c:66
void Init(double *v, double x1, double x2, double x3)
Definition: init.c:17
void BodyForceVector(double *v, double *g, double x, double y, double z)
Definition: init.c:441