Skip to content

Commit 98e6643

Browse files
authored
Merge pull request #1080 from CEED/ade/riemann-bcs
HLL Flux for Riemann BCs
2 parents fa8c78e + c9e00a2 commit 98e6643

16 files changed

+1018
-338
lines changed

doc/sphinx/source/references.bib

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,14 @@ @article{shurSTG2014
202202
doi = {10.1007/s10494-014-9534-8},
203203
langid = {english},
204204
}
205+
206+
@inproceedings{mengaldoCompressibleBC2014,
207+
title = {A Guide to the Implementation of Boundary Conditions in Compact High-Order Methods for Compressible Aerodynamics},
208+
booktitle = {{{AIAA Aviation}} 2014},
209+
author = {Mengaldo, Gianmarco and De Grazia, Daniele and Peiro, Joaquim and Farrington, Antony and Witherden, Freddie and Vincent, Peter and Sherwin, Spencer},
210+
year = {2014},
211+
month = jun,
212+
publisher = {{AIAA}},
213+
address = {{Atlanta}},
214+
doi = {10.2514/6.2014-2923},
215+
}

examples/fluids/README.md

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ The following options are common among all problem types:
108108
- Use outflow boundary conditions on this list of faces
109109
-
110110

111+
* - `-bc_freestream`
112+
- Use freestream boundary conditions on this list of faces
113+
-
114+
111115
* - `-snes_view`
112116
- View PETSc `SNES` nonlinear solver configuration
113117
-
@@ -121,7 +125,7 @@ The following options are common among all problem types:
121125
-
122126
:::
123127

124-
For the case of a square/cubic mesh, the list of face indices to be used with `-bc_wall`, `bc_inflow`, `bc_outflow` and/or `-bc_slip_x`, `-bc_slip_y`, and `-bc_slip_z` are:
128+
For the case of a square/cubic mesh, the list of face indices to be used with `-bc_wall`, `bc_inflow`, `bc_outflow`, `bc_freestream` and/or `-bc_slip_x`, `-bc_slip_y`, and `-bc_slip_z` are:
125129

126130
:::{list-table} 2D Face ID Labels
127131
:header-rows: 1
@@ -541,10 +545,63 @@ For the Density Current, Channel, and Blasius problems, the following common com
541545
- string
542546
:::
543547

548+
#### Newtonian Wave
549+
550+
The newtonian wave problem has the following command-line options in addition to the Newtonian Ideal Gas options:
551+
552+
:::{list-table} Newtonian Wave Runtime Options
553+
:header-rows: 1
554+
555+
* - Option
556+
- Description
557+
- Default value
558+
- Unit
559+
560+
* - `-velocity_freestream`
561+
- Freestream velocity vector
562+
- `0,0,0`
563+
- `m/s`
564+
565+
* - `-temperature_freestream`
566+
- Freestream temperature
567+
- `288`
568+
- `K`
569+
570+
* - `-pressure_freestream`
571+
- Freestream pressure
572+
- `1.01e5`
573+
- `Pa`
574+
575+
* - `-epicenter`
576+
- Coordinates of center of perturbation
577+
- `0,0,0`
578+
- `m`
579+
580+
* - `-amplitude`
581+
- Amplitude of the perturbation
582+
- `0.1`
583+
-
584+
585+
* - `-width`
586+
- Width parameter of the perturbation
587+
- `0.002`
588+
- `m`
589+
590+
:::
591+
592+
This problem can be run with the `newtonianwave.yaml` file via:
593+
594+
```
595+
./navierstokes -options_file newtonianwave.yaml
596+
```
597+
598+
```{literalinclude} ../../../../../examples/fluids/newtonianwave.yaml
599+
:language: yaml
600+
```
544601

545602
#### Density current
546603

547-
The Density Current problem the following command-line options are available in addition to the Newtonian Ideal Gas options:
604+
The Density Current problem has the following command-line options in addition to the Newtonian Ideal Gas options:
548605

549606
:::{list-table} Density Current Runtime Options
550607
:header-rows: 1
@@ -598,7 +655,7 @@ This problem can be run with:
598655

599656
#### Channel flow
600657

601-
The Channel problem the following command-line options are available in addition to the Newtonian Ideal Gas options:
658+
The Channel problem has the following command-line options in addition to the Newtonian Ideal Gas options:
602659

603660
:::{list-table} Channel Runtime Options
604661
:header-rows: 1
@@ -640,7 +697,7 @@ This problem can be run with the `channel.yaml` file via:
640697

641698
#### Blasius boundary layer
642699

643-
The Blasius problem the following command-line options are available in addition to the Newtonian Ideal Gas options:
700+
The Blasius problem has the following command-line options in addition to the Newtonian Ideal Gas options:
644701

645702
:::{list-table} Blasius Runtime Options
646703
:header-rows: 1

examples/fluids/index.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ $$
385385
\int_{\Omega} \nu_{SHOCK} \nabla \bm v \!:\! \nabla \bm q dV
386386
$$
387387
388-
The shock capturing viscosity is implemented following the first formulation described in {cite} `tezduyar2007yzb`. The characteristic velocity $u_{cha}$ is taken to be the acoustic speed while the reference density $\rho_{ref}$ is just the local density. Shock capturing viscosity is defined by the following
388+
The shock capturing viscosity is implemented following the first formulation described in {cite}`tezduyar2007yzb`. The characteristic velocity $u_{cha}$ is taken to be the acoustic speed while the reference density $\rho_{ref}$ is just the local density. Shock capturing viscosity is defined by the following
389389
390390
$$
391391
\nu_{SHOCK} = \tau_{SHOCK} u_{cha}^2
@@ -413,6 +413,23 @@ The constant $C_{YZB}$ is set to 0.1 for piecewise linear elements in the curren
413413
414414
(problem-density-current)=
415415
416+
## Newtonian Wave
417+
This test case is taken/inspired by that presented in {cite}`mengaldoCompressibleBC2014`. It is intended to test non-reflecting/Riemann boundary conditions. It's primarily intended for Euler equations, but has been implemented for the Navier-Stokes equations here for flexibility.
418+
419+
The problem has a perturbed initial condition and lets it evolve in time. The initial condition contains a Gaussian perturbation in the pressure field:
420+
421+
$$
422+
\begin{aligned}
423+
\rho &= \rho_\infty\left(1+A\exp\left(\frac{-(\bar{x}^2 + \bar{y}^2)}{2\sigma^2}\right)\right) \\
424+
\bm{U} &= \bm U_\infty \\
425+
E &= \frac{p_\infty}{\gamma -1}\left(1+A\exp\left(\frac{-(\bar{x}^2 + \bar{y}^2)}{2\sigma^2}\right)\right) + \frac{\bm U_\infty \cdot \bm U_\infty}{2\rho_\infty},
426+
\end{aligned}
427+
$$
428+
429+
where $A$ and $\sigma$ are the amplitude and width of the perturbation, respectively, and $(\bar{x}, \bar{y}) = (x-x_e, y-y_e)$ is the distance to the epicenter of the perturbation, $(x_e, y_e)$.
430+
431+
Currently, a HLL (Harten, Lax, van Leer) Riemann solver is implemented under the freestream boundary condition. The formulation for the HLL solver is given in {cite}`toro2009`.
432+
416433
## Density Current
417434
418435
For this test problem (from {cite}`straka1993numerical`), we solve the full Navier-Stokes equations {eq}`eq-ns`, for which a cold air bubble (of radius $r_c$) drops by convection in a neutrally stratified atmosphere.

examples/fluids/navierstokes.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ struct CeedData_private {
134134
CeedQFunction qf_setup_vol, qf_ics, qf_rhs_vol, qf_ifunction_vol,
135135
qf_setup_sur,
136136
qf_apply_inflow, qf_apply_inflow_jacobian,
137-
qf_apply_outflow, qf_apply_outflow_jacobian;
137+
qf_apply_outflow, qf_apply_outflow_jacobian,
138+
qf_apply_freestream, qf_apply_freestream_jacobian;
138139
CeedBasis basis_x, basis_xc, basis_q, basis_x_sur, basis_q_sur,
139140
basis_xc_sur;
140141
CeedElemRestriction elem_restr_x, elem_restr_q, elem_restr_qd_i;
@@ -182,8 +183,9 @@ struct SimpleBC_private {
182183
num_comps,
183184
num_slip[3], // Number of faces with slip BCs
184185
num_inflow,
185-
num_outflow;
186-
PetscInt walls[16], slips[3][16], inflows[16], outflows[16];
186+
num_outflow,
187+
num_freestream;
188+
PetscInt walls[16], slips[3][16], inflows[16], outflows[16], freestreams[16];
187189
PetscBool user_bc;
188190
};
189191

@@ -218,8 +220,8 @@ struct ProblemData_private {
218220
CeedInt dim, q_data_size_vol, q_data_size_sur, jac_data_size_sur;
219221
CeedScalar dm_scale;
220222
ProblemQFunctionSpec setup_vol, setup_sur, ics, apply_vol_rhs, apply_vol_ifunction,
221-
apply_vol_ijacobian, apply_inflow, apply_outflow,
222-
apply_inflow_jacobian, apply_outflow_jacobian;
223+
apply_vol_ijacobian, apply_inflow, apply_outflow, apply_freestream,
224+
apply_inflow_jacobian, apply_outflow_jacobian, apply_freestream_jacobian;
223225
bool non_zero_time;
224226
PetscErrorCode (*bc)(PetscInt, PetscReal, const PetscReal[], PetscInt,
225227
PetscScalar[], void *);
@@ -235,6 +237,8 @@ extern int FreeContextPetsc(void *);
235237
// Set up problems
236238
// -----------------------------------------------------------------------------
237239
// Set up function for each problem
240+
extern PetscErrorCode NS_NEWTONIAN_WAVE(ProblemData *problem, DM dm,
241+
void *ctx);
238242
extern PetscErrorCode NS_CHANNEL(ProblemData *problem, DM dm,
239243
void *ctx);
240244
extern PetscErrorCode NS_BLASIUS(ProblemData *problem, DM dm,
@@ -380,4 +384,5 @@ PetscErrorCode SetupStrongBC_Ceed(Ceed ceed, CeedData ceed_data, DM dm,
380384
User user, AppCtx app_ctx, ProblemData *problem,
381385
SimpleBC bc, CeedInt Q_sur, CeedInt q_data_size_sur);
382386

387+
PetscErrorCode FreestreamBCSetup(ProblemData *problem, DM dm, void *ctx);
383388
#endif // libceed_fluids_examples_navier_stokes_h

examples/fluids/newtonianwave.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
problem: 'newtonian_wave'
2+
mu: 0 # Effectively solving Euler momentum equations
3+
4+
dm_plex_box_faces: 40,40,1
5+
dm_plex_box_upper: 1,1,0.1
6+
dm_plex_box_lower: 0,0,0
7+
dm_plex_dim: 3
8+
bc_freestream: 4,6,3,5
9+
bc_slip_z: 1,2
10+
11+
velocity_freestream: 1,1,0
12+
temperature_freestream: 0.25
13+
pressure_freestream: 71.75
14+
15+
epicenter: 0.33,0.75,0
16+
amplitude: 2
17+
width: 0.05
18+
19+
ts:
20+
adapt_type: 'none'
21+
max_steps: 400
22+
dt: 3.6e-4
23+
type: alpha
24+
alpha_radius: 0.5
25+
26+
implicit: true
27+
stab: supg
28+
state_var: primitive
29+
30+
snes_rtol: 1e-4
31+
ksp_rtol: 1e-2
32+
snes_lag_jacobian: 20
33+
snes_lag_jacobian_persists:
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2+
// All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3+
//
4+
// SPDX-License-Identifier: BSD-2-Clause
5+
//
6+
// This file is part of CEED: http://github.com/ceed
7+
8+
/// @file
9+
/// Utility functions for setting up Freestream boundary condition
10+
11+
#include "../navierstokes.h"
12+
#include "../qfunctions/freestream_bc.h"
13+
14+
PetscErrorCode FreestreamBCSetup(ProblemData *problem, DM dm, void *ctx) {
15+
User user = *(User *)ctx;
16+
MPI_Comm comm = PETSC_COMM_WORLD;
17+
FreestreamContext freestream_ctx;
18+
NewtonianIdealGasContext newtonian_ig_ctx;
19+
CeedQFunctionContext freestream_context;
20+
PetscFunctionBeginUser;
21+
22+
// *INDENT-OFF*
23+
switch (user->phys->state_var) {
24+
case STATEVAR_CONSERVATIVE:
25+
problem->apply_freestream.qfunction = Freestream_Conserv;
26+
problem->apply_freestream.qfunction_loc = Freestream_Conserv_loc;
27+
problem->apply_freestream_jacobian.qfunction = Freestream_Jacobian_Conserv;
28+
problem->apply_freestream_jacobian.qfunction_loc = Freestream_Jacobian_Conserv_loc;
29+
case STATEVAR_PRIMITIVE:
30+
problem->apply_freestream.qfunction = Freestream_Prim;
31+
problem->apply_freestream.qfunction_loc = Freestream_Prim_loc;
32+
problem->apply_freestream_jacobian.qfunction = Freestream_Jacobian_Prim;
33+
problem->apply_freestream_jacobian.qfunction_loc = Freestream_Jacobian_Prim_loc;
34+
}
35+
// *INDENT-ON*
36+
37+
// -- Option Defaults
38+
CeedScalar U_inf[3] = {0.}; // m/s
39+
CeedScalar T_inf = 288.; // K
40+
CeedScalar P_inf = 1.01e5; // Pa
41+
42+
PetscOptionsBegin(comm, NULL, "Options for Freestream boundary condition",
43+
NULL);
44+
PetscInt narray=3;
45+
PetscCall(PetscOptionsScalarArray("-velocity_freestream",
46+
"Velocity at freestream condition",
47+
NULL, U_inf, &narray, NULL));
48+
PetscCheck(narray == 3, comm, PETSC_ERR_ARG_SIZ,
49+
"-velocity_freestream should recieve array of size 3, instead recieved size %"
50+
PetscInt_FMT".", narray);
51+
52+
PetscCall(PetscOptionsScalar("-temperature_freestream",
53+
"Temperature at freestream condition",
54+
NULL, T_inf, &T_inf, NULL));
55+
PetscCall(PetscOptionsScalar("-pressure_freestream",
56+
"Pressure at freestream condition",
57+
NULL, P_inf, &P_inf, NULL));
58+
PetscOptionsEnd();
59+
60+
PetscScalar meter = user->units->meter;
61+
PetscScalar second = user->units->second;
62+
PetscScalar Kelvin = user->units->Kelvin;
63+
PetscScalar Pascal = user->units->Pascal;
64+
65+
T_inf *= Kelvin;
66+
P_inf *= Pascal;
67+
for (int i=0; i<3; i++) U_inf[i] *= meter / second;
68+
69+
CeedQFunctionContextGetData(problem->apply_vol_rhs.qfunction_context,
70+
CEED_MEM_HOST, &newtonian_ig_ctx);
71+
State S_infty;
72+
{
73+
CeedScalar Y[5] = {P_inf, U_inf[0], U_inf[1], U_inf[2], T_inf};
74+
CeedScalar x[3] = {0.};
75+
S_infty = StateFromY(newtonian_ig_ctx, Y, x);
76+
}
77+
78+
// -- Set freestream_ctx struct values
79+
PetscCall(PetscCalloc1(1, &freestream_ctx));
80+
freestream_ctx->newtonian_ctx = *newtonian_ig_ctx;
81+
freestream_ctx->S_infty = S_infty;
82+
83+
CeedQFunctionContextRestoreData(problem->apply_vol_rhs.qfunction_context,
84+
&newtonian_ig_ctx);
85+
86+
CeedQFunctionContextCreate(user->ceed, &freestream_context);
87+
CeedQFunctionContextSetData(freestream_context, CEED_MEM_HOST, CEED_USE_POINTER,
88+
sizeof(*freestream_ctx), freestream_ctx);
89+
CeedQFunctionContextSetDataDestroy(freestream_context, CEED_MEM_HOST,
90+
FreeContextPetsc);
91+
problem->apply_freestream.qfunction_context = freestream_context;
92+
problem->apply_freestream_jacobian.qfunction_context = freestream_context;
93+
94+
PetscFunctionReturn(0);
95+
};

0 commit comments

Comments
 (0)