Skip to content

Commit 278d2ef

Browse files
committed
Merge remote-tracking branch 'origin/models/euler' into model/shallow-water-2d
2 parents 30b1ff3 + f5b477d commit 278d2ef

File tree

87 files changed

+2607
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2607
-483
lines changed

.github/workflows/main-docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ jobs:
1919

2020
- name: Install docs dependencies
2121
run: |
22+
apt install python3-pydot graphviz
2223
python -m pip install --upgrade pip
23-
pip install -r docs/requirements.txt
24+
python -m pip install -r docs/requirements.txt
2425
2526
- name: Generate API docs
2627
run: |

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ lcov.info
4242
.vscode/
4343
util/
4444
*.info
45+
*.egg-info
46+
results.db
47+
results.json
48+
results.stats.csv
49+
results.csv
50+
results.sysinfo.txt

docs/Models/burgers-equation-model.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type(Mesh1D),target :: mesh
7171
! Create a mesh using the built-in
7272
! uniform mesh generator.
7373
! The domain is set to x in [0,1] with 10 elements
74-
call mesh%UniformBlockMesh(nGeo=1, &
74+
call mesh%StructuredMesh(nGeo=1, &
7575
nElem=10, &
7676
x=(/0.0_prec,1.0_prec/))
7777
@@ -147,8 +147,8 @@ implicit none
147147
type(Mesh1D),target :: mesh
148148
type(Geometry1D),target :: geometry
149149
150-
call mesh % UniformBlockMesh(nElem=10, &
151-
x=(/0.0_prec,1.0_prec/))
150+
call mesh % StructuredMesh(nElem=10, &
151+
x=(/0.0_prec,1.0_prec/))
152152
153153
! Set the left and right boundary conditions to prescribed
154154
call mesh % ResetBoundaryConditionType(SELF_BC_PRESCRIBED,SELF_BC_PRESCRIBED)

docs/Models/linear-euler-2d-model.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Linear Euler (2D)
2+
3+
## Definition
4+
The [`SELF_LinearEuler2D_t` module](../ford/module/self_lineareuler2d_t.html) defines the [`LinearEuler2D_t` class](ford/type/lineareuler2d_t.html). In SELF, models are posed in the form of a generic conservation law
5+
6+
$$
7+
\vec{s}_t + \nabla \cdot \overleftrightarrow{f} = \vec{q}
8+
$$
9+
10+
where $\vec{s}$ is a vector of solution variables, $\overleftrightarrow{f}$ is the conservative flux, and $\vec{q}$ are non-conservative source terms.
11+
12+
For the Linear Euler equations in 2-D
13+
14+
15+
16+
$$
17+
\vec{s} =
18+
\begin{pmatrix}
19+
\rho \\
20+
u \\
21+
v \\
22+
p
23+
\end{pmatrix}
24+
$$
25+
26+
where $\rho$ is a density anomaly, referenced to the density $\rho_0$, $u$ and $v$ are the $x$ and $y$ components of the fluid velocity (respectively), and $p$ is the pressure. When we assume an ideal gas, and a motionless background state, the conservative fluxes are
27+
28+
$$
29+
\overleftrightarrow{f} =
30+
\begin{pmatrix}
31+
\rho_0(u \hat{x} + v \hat{y}) \\
32+
p \hat{x} \\
33+
p \hat{y} \\
34+
\rho_0c^2(u \hat{x} + v \hat{y})
35+
\end{pmatrix}
36+
$$
37+
38+
where $c$ is the (constant) speed of sound. The source term is set to zero.
39+
40+
$$
41+
\vec{q} = \vec{0}
42+
$$
43+
44+
To track stability of the Euler equation, the total entropy function is
45+
46+
$$
47+
e = \frac{1}{2} \int_V u^2 + v^2 + \frac{p}{\rho_0 c^2} \hspace{1mm} dV
48+
$$
49+
50+
## Implementation
51+
The Linear Euler 2D model is implemented as a type extension of the [`DGModel2D` class](../ford/type/dgmodel2d_t.html). The [`LinearEuler2D_t` class](../ford/type/lineareuler2d_t.html) adds parameters for the reference density and the speed speed of sound and overrides the `SetMetadata`, `entropy_func`, `flux2d`, and `riemannflux2d` type-bound procedures.
52+
53+
### Riemann Solver
54+
The `LinearEuler2D` class is defined using the conservative form of the conservation law. The Riemman solver for the hyperbolic part of Euler equation is the local Lax Friedrichs upwind riemann solver
55+
56+
$$
57+
\overleftrightarrow{f}_h^* \cdot \hat{n} = \frac{1}{2}( \overleftrightarrow{f}_L \cdot \hat{n} + \overleftrightarrow{f}_R \cdot \hat{n} + c (\vec{s}_L - \vec{s}_R))
58+
$$
59+
60+
where
61+
62+
$$
63+
\overleftrightarrow{f}_L \cdot \hat{n} =
64+
\begin{pmatrix}
65+
\rho_0(u_L n_x + v_L n_y) \\
66+
p_L n_x \\
67+
p_L n_y \\
68+
\rho_0c^2(u_L n_x + v_L n_y)
69+
\end{pmatrix}
70+
$$
71+
72+
$$
73+
\overleftrightarrow{f}_R \cdot \hat{n} =
74+
\begin{pmatrix}
75+
\rho_0(u_R n_x + v_R n_y) \\
76+
p_R n_x \\
77+
p_R n_y \\
78+
\rho_0c^2(u_R n_x + v_R n_y)
79+
\end{pmatrix}
80+
$$
81+
82+
The details for this implementation can be found in [`self_lineareuler2d_t.f90`](../ford/sourcefile/self_lineareuler2d_t.f90.html)
83+
84+
### Boundary conditions
85+
When initializing the mesh for your Euler 2D equation solver, you can change the boundary conditions to
86+
87+
* `SELF_BC_Radiation` to set the external state on model boundaries to 0 in the Riemann solver
88+
* `SELF_BC_NoNormalFlow` to set the external normal velocity to the negative of the interior normal velocity and prolong the density, pressure, and tangential velocity (free slip). This effectively creates a reflecting boundary condition.
89+
* `SELF_BC_Prescribed` to set a prescribed external state.
90+
91+
92+
As an example, when using the built-in structured mesh generator, you can do the following
93+
94+
```fortran
95+
96+
type(Mesh2D),target :: mesh
97+
integer :: bcids(1:4)
98+
99+
bcids(1:4) = (/&
100+
SELF_NONORMALFLOW,& ! South boundary condition
101+
SELF_RADIATION,& ! East boundary condition
102+
SELF_PRESCRIBED,& ! North boundary condition
103+
SELF_RADIATION & ! West boundary condition
104+
/)
105+
call mesh%StructuredMesh(nxPerTile=5,nyPerTile=5,&
106+
nTileX=2,nTileY=2,&
107+
dx=0.1_prec,dy=0.1_prec,bcids)
108+
109+
```
110+
111+
!!! note
112+
See the [Structured Mesh documentation](../MeshGeneration/StructuredMesh.md) for details on using the `structuredmesh` procedure
113+
114+
!!! note
115+
To set a prescribed state as a function of position and time, you can create a type-extension of the `LinearEuler2D` class and override the [`hbc2d_Prescribed`](../ford/proc/hbc2d_prescribed_model.html)
116+
117+
118+
## GPU Acceleration
119+
When building SELF with GPU acceleration enabled, the Linear Euler (2-D) model overrides the following `DGModel2D` type-bound procedures
120+
121+
* `BoundaryFlux`
122+
* `FluxMethod`
123+
* `SourceMethod`
124+
* `SetBoundaryCondition`
125+
* `SetGradientBoundaryCondition`
126+
127+
These methods are one-level above the usual `pure function` type-bound procedures used to define the riemann solver, flux, source terms, and boundary conditions. These procedures need to be overridden with calls to GPU accelerated kernels to make the solver fully resident on the GPU.
128+
129+
Out-of-the-box, the no-normal-flow and radiation boundary conditions are GPU accelerated. However, prescribed boundary conditions are CPU-only. We have opted to keep the prescribed boundary conditions CPU-only so that their implementation remains easy-to-use. This implies that some data is copied between host and device every iteration when prescribed boundary conditions are enabled.
130+
131+
!!! note
132+
In simulations where no prescribed boundaries are used, or your prescribed boundaries are time independent, you can disable prescribed boundary conditions by explicitly setting `modelobj % prescribed_bcs_enabled = .false.`. This can improve the time-to-solution for your simulation by avoiding unnecessary host-device memory movement. An example of this feature is shown in [`examples/lineareuler2d_spherical_soundwave_closeddomain.f90`](https://github.com/FluidNumerics/SELF/blob/main/examples/linear_euler2d_spherical_soundwave_closeddomain.f90)
133+
134+
135+
## Example usage
136+
137+
For examples, see any of the following
138+
139+
* [`examples/lineareuler2d_spherical_soundwave_closeddomain.f90`](https://github.com/FluidNumerics/SELF/blob/main/examples/linear_euler2d_spherical_soundwave_closeddomain.f90) - Implements a simulation with a gaussian pressure and density anomaly as an initial condition in a domain with no normal flow boundary conditions on all sides.
140+
* [`examples/linear_euler2d_planewave_propagation.f90`](https://github.com/FluidNumerics/SELF/blob/main/examples/linear_euler2d_planewave_propagation.f90) - Implements a simulation with a gaussian plane wave that propagates at a $45^\circ$ angle through a square domain. The initial and boundary conditions are all taken as an exact plane wave solution to the Linear Euler equations in 2D. This provides an example for using prescribed boundary conditions.
141+
* [`examples/linear_euler2d_planewave_reflection.f90`](https://github.com/FluidNumerics/SELF/blob/main/examples/linear_euler2d_planewave_reflection.f90) - Implements a simulation with a gaussian plane wave that propagates at a $45^\circ$ angle through a square domain and reflects off a wall at x=1 (eastern domain boundary). The initial and boundary conditions are all taken as an exact plane wave solution to the Linear Euler equations in 2D derived using the method of images. This provides an example for using prescribed boundary conditions in combination with the no-normal-flow boundary conditions.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Visualization with PySELF
2+
3+
SELF comes with a python post-processing toolkit called `pyself` that provides the ability to read in SELF's HDF5 pickup files and map the ouput into [`pyvista`](https://pyvista.org/) objects for visualization. This documentation will walk through getting started with `pyself` and visualizing model output.
4+
5+
## Installing PySELF
6+
7+
## Visualizing 2-D data
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Linear Euler 2D - Plane Wave Propagation Tutorial
2+
This tutorial will walk you through using an example program that uses the `LinearEuler2D` class to run a simulation with the linear Euler equations for an ideal gas in 2-D. This example is configured using the built in structured mesh generator with prescribed boundary conditions on all domain boundaries.
3+
4+
## Problem statement
5+
6+
### Equations Solved
7+
In this example, we are solving the linear Euler equations in 2-D for an ideal gas, given by
8+
9+
$$
10+
\vec{s}_t + \nabla \cdot \overleftrightarrow{f} = \vec{q}
11+
$$
12+
13+
where
14+
15+
16+
$$
17+
\vec{s} =
18+
\begin{pmatrix}
19+
\rho \\
20+
u \\
21+
v \\
22+
p
23+
\end{pmatrix}
24+
$$
25+
26+
and
27+
28+
$$
29+
\overleftrightarrow{f} =
30+
\begin{pmatrix}
31+
\rho_0(u \hat{x} + v \hat{y}) \\
32+
p \hat{x} \\
33+
p \hat{y} \\
34+
\rho_0c^2(u \hat{x} + v \hat{y})
35+
\end{pmatrix}
36+
$$
37+
38+
$$
39+
\vec{q} = \vec{0}
40+
$$
41+
42+
43+
44+
The variables are defined as follows
45+
46+
* $\rho$ is a density anomaly referenced to the density $\rho_0$
47+
* $u$ and $v$ are the $x$ and $y$ components of the fluid velocity (respectively)
48+
* $p$ is the pressure
49+
* $c$ is the (constant) speed of sound.
50+
51+
### Model Domain
52+
The physical domain is defined by $\vec{x} \in [0, 1]\times[0,1]$. We use the `StructuredMesh` routine to create a domain with 20 × 20 elements that are dimensioned 0.05 × 0.05 . Model boundaries are all tagged with the `SELF_BC_PRESCRIBED` flag to implement prescribed boundary conditions.
53+
54+
Within each element, all variables are approximated by a Lagrange interpolating polynomial of degree 7. The interpolation knots are the Legendre-Gauss points.
55+
56+
57+
### Initial and Boundary Conditions
58+
The initial and boundary conditions are set using an exact solution,
59+
60+
$$
61+
\begin{pmatrix}
62+
ρ \\
63+
u \\
64+
v \\
65+
P
66+
\end{pmatrix} =
67+
\begin{pmatrix}
68+
\frac{1}{c^2} \\
69+
\frac{k_x}{c} \\
70+
\frac{k_y}{c} \\
71+
1
72+
\end{pmatrix} \bar{p} e^{-\left( \frac{(k_x(x-x_0) + k_y(y-y_0) - ct)^2}{L^2} \right)}
73+
$$
74+
75+
where
76+
77+
* $\bar{p} = 10^{-4}$ is the amplitude of the sound wave
78+
* $x_0 = y_0 = 0.2$ defines the center of the initial sound wave
79+
* $L = \frac{0.2}{2\sqrt{\ln{2}}}$ is the half-width of the sound wave
80+
* $k_x = k_y = \frac{\sqrt{2}}{2}$ are the $x$ and $y$ components of the wave number
81+
82+
The model domain
83+
<figure markdown>
84+
![Plane wave initial condition](./img/planewave_p_init.png){ align=left }
85+
<figcaption>Pressure field for the initial condition, showing a plane wave with a front oriented at 45 degrees</figcaption>
86+
</figure>
87+
88+
<figure markdown>
89+
![Plane wave at the end of the simulation](./img/planewave_p_t05.png){ align=left }
90+
<figcaption>Pressure field at t=0.5 computed with SELF</figcaption>
91+
</figure>
92+
93+
## How we implement this
94+
You can find the example file for this demo in the `examples/linear_euler2d_planewave_propagation.f90` file. This file defines the `lineareuler2d_planewave_model` module in addition to a program that runs the propagating plane wave simulation.
95+
96+
97+
The `lineareuler2d_planewave_model` module defines the `lineareuler2d_planewave` class, which is a type extension of the `lineareuler2d` class that is provided by SELF. We make this type extension so that we can
98+
99+
* add attributes ( `kx` and `ky` ) for the x and y components of the plane-wave wave number
100+
* add attributes ( `x0` and `y0` ) for the initial center position of the plane-wave
101+
* add an attribute ( `p` ) for the pressure amplitude of the wave
102+
* add an attribute ( `L` ) for the half-width of the plane wave
103+
* override the `hbc1d_Prescribed` type-bound procedure to set the boundary condition to the exact solution
104+
105+
## Running this example
106+
107+
!!! note
108+
To run this example, you must first [install SELF](../../GettingStarted/install.md) . We assume that SELF is installed in path referenced by the `SELF_ROOT` environment variable.
109+
110+
111+
To run this example, simply execute
112+
113+
```shell
114+
${SELF_ROOT}/examples/linear_euler2d_planewave_propagation
115+
```
116+
117+
This will run the simulation from $t=0$ to $t=1.0$ and write model output at intervals of $Δ t_{io} = 0.05$.
118+
119+
During the simulation, tecplot (`solution.*.tec`) files are generated which can easily be visualized with paraview.

0 commit comments

Comments
 (0)