Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/documentation/equations.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,12 @@ A thermal diffusion CFL limit (`TCFL`) is added to the adaptive time-step candid

Additional geometric source terms appear with \f$1/r\f$ factors in the continuity, momentum, and energy equations. Key modifications:

- **Radial momentum:** extra \f$p/r\f$ and \f$\tau_{\theta\theta}/r\f$ terms
- **Viscous stress:** \f$\tau_{yy}\f$ includes \f$v/r\f$ corrections:
- **Radial momentum:** extra \f$p/r\f$ and \f$-\tau_{\theta\theta}/r\f$ terms; in 3D the azimuthal momentum gets \f$+\tau_{r\theta}/r\f$
- **Viscous stress:** the divergence includes \f$v/r\f$ (and \f$(1/r)\,\partial w/\partial\theta\f$ in 3D), e.g.

\f[\tau_{yy} = \mu\left(\frac{4}{3}\frac{\partial v}{\partial r} - \frac{2}{3}\frac{\partial u}{\partial x} - \frac{2}{3}\frac{v}{r}\right)\f]

- **Azimuthal direction (3D):** \f$z\f$ is \f$\theta\f$ in radians, so every \f$\theta\f$ derivative carries \f$1/r\f$: once in the face gradient of a diffusive flux and once in its divergence, \f$(1/r)\,\partial F_\theta/\partial\theta\f$ (verified in @ref validation_coordinates)
- **Axis singularity:** axis placed at cell boundary with spectral filtering in the azimuthal direction

---
Expand Down
4 changes: 2 additions & 2 deletions docs/documentation/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ The cold run uses `--tw 270` in a copy of the directory (the output is written n

**Status:** validated. **Examples:** `examples/1D_sodHypo`, `examples/2D_hypo_shear_contact`. Hypoelastic longitudinal and shear Riemann problems against linear elastodynamics: wave speeds \f$\sqrt{(K + 4G/3)/\rho}\f$ and \f$\sqrt{G/\rho}\f$, plateau velocities and stresses. Results and limits: @ref validation_elastic_waves.

## Axisymmetric coordinates and stretched grids {#sec-validation-coordinates}
## Cylindrical coordinates and stretched grids {#sec-validation-coordinates}

**Status:** partially validated. **Examples:** `examples/2D_acoustic_support6_axisym`, `examples/1D_acoustic_gauss_sigmatime` (`--stretch`). The focal pressure of an axisymmetric focused transducer against the on-axis solution of a spherical cap, and the 1D acoustic pulse on a stretched grid against the same linear solution as on the uniform grid. Results and limits: @ref validation_coordinates.
**Status:** partially validated. **Examples:** `examples/2D_acoustic_support6_axisym`, `examples/3D_cyl_viscous_mms`, `examples/1D_acoustic_gauss_sigmatime` (`--stretch`). The focal pressure of an axisymmetric focused transducer against the on-axis solution of a spherical cap, the 3D cylindrical and 2D axisymmetric viscous operator against manufactured solutions (second order), and the 1D acoustic pulse on a stretched grid against the same linear solution as on the uniform grid. Results and limits: @ref validation_coordinates.

## Shock tubes {#sec-validation-shock-tubes}

Expand Down
34 changes: 31 additions & 3 deletions docs/documentation/validation_coordinates.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@page validation_coordinates Validation: Axisymmetric Focusing and Stretched Grids
@page validation_coordinates Validation: Cylindrical Coordinates and Stretched Grids

# Coordinates and grids: axisymmetric focusing and a stretched 1D grid
# Coordinates and grids: axisymmetric focusing, the cylindrical viscous operator and a stretched 1D grid

**Status:** partially validated. The focal pressure of an axisymmetric transducer converges to the exact on-axis solution (−0.4 % at the finest grid) and arrives on time (shift 0.01 \f$\Delta t\f$), but 4 % of the waveform differs in its tails. On a stretched grid the 1D pulse is as accurate as on the uniform grid. **Code:** `master` at 3e4c53258 with the stage-time fix of [#2462](https://github.com/MFlowCode/MFC/issues/2462). **Examples:** `examples/2D_acoustic_support6_axisym`, `examples/1D_acoustic_gauss_sigmatime`. See also @ref validation and @ref validation_acoustics.
**Status:** partially validated. The focal pressure of an axisymmetric transducer converges to the exact on-axis solution (−0.4 % at the finest grid) and arrives on time (shift 0.01 \f$\Delta t\f$), but 4 % of the waveform differs in its tails. On a stretched grid the 1D pulse is as accurate as on the uniform grid. **Code:** `master` at 3e4c53258 with the stage-time fix of [#2462](https://github.com/MFlowCode/MFC/issues/2462). The viscous operator in 3D cylindrical and 2D axisymmetric coordinates converges at second order to manufactured solutions ([#1910](https://github.com/MFlowCode/MFC/issues/1910)). **Examples:** `examples/2D_acoustic_support6_axisym`, `examples/3D_cyl_viscous_mms`, `examples/1D_acoustic_gauss_sigmatime`. See also @ref validation and @ref validation_acoustics.

## Axisymmetric focused transducer {#sec-validation-coordinates-focus}

Expand All @@ -29,6 +29,33 @@ The focal signal arrives on time: the shift falls from −0.14 to −0.01 \f$\De

Limits: one transducer geometry and one probe point on the axis; the off-axis field, the element arrays (`support = 9, 10`) and the 3D transducers are not compared.

## Cylindrical viscous operator {#sec-validation-coordinates-viscous}

| Item | Value |
| :--- | :--- |
| Equations | \f$\mathbf{f} = \nabla\cdot\boldsymbol{\tau}\f$ and \f$W = \nabla\cdot(\boldsymbol{\tau}\cdot\mathbf{u})\f$ with \f$\boldsymbol{\tau} = \mu(\nabla\mathbf{u} + \nabla\mathbf{u}^T) + (\mu_b - 2\mu/3)(\nabla\cdot\mathbf{u})\mathbf{I}\f$ in (x, r, \f$\theta\f$): \f$f_r\f$ carries \f$-\tau_{\theta\theta}/r\f$, \f$f_\theta\f$ carries \f$+\tau_{r\theta}/r\f$, every \f$\theta\f$ derivative carries \f$1/r\f$ |
| Geometry | r in [0, 2] with the axis (`bc_y%%beg = -14` in 3D, `-2` in 2D), \f$\theta\f$ periodic, x periodic with 26 cells; fields independent of x |
| Fields | (a) \f$u_x = A(r/R)^2\cos\theta\f$ (exact \f$f_x = 3\mu A\cos\theta/R^2\f$ at every r); (b) Taylor-Couette \f$u_\theta = A(r + 0.5/r)\f$ (exact \f$\mathbf{f} = 0\f$, rings with r \f$\ge\f$ 0.5); (c) \f$u_x = Ar^3\cos\theta\f$, \f$u_r = Ar^2\cos\theta\f$, \f$u_\theta = A(r^3 - r^2\sin\theta)\f$ with bulk viscosity; (d) 2D axisymmetric \f$u_x = A(r/R)^2\f$, \f$u_r = A(r/R)^3\f$ with bulk viscosity. \f$\mu\f$ = \f$\mu_b\f$ = 1, A = 0.1, \f$\rho\f$ = p = 1 |
| Measured | `run_mms.py`: one RK3 step, \f$\Delta t\f$ = 1e-8, rate = (q with viscosity - q without)/\f$\Delta t\f$ (the inviscid terms cancel) against the exact rates of `derive_rates.py` (sympy) at the cell centres; max norm over the rings away from the axis and the outer boundary, relative to the largest exact momentum rate (energy: the largest exact \f$W\f$; (b): the largest error before the fix) |

![Max-norm error of the viscous rate against N, before (dashed) and after (solid) the fix of #1910](../res/validation_cyl_viscous.png)

| Case, component | N = 32 | 64 | 128 | 256 | order | before the fix (N = 128) |
| :--- | ---: | ---: | ---: | ---: | ---: | ---: |
| (a) \f$\rho u_x\f$ | 1.07e-3 | 2.68e-4 | 6.70e-5 | | 2.0 | 0.289 |
| (a) \f$\rho E\f$ | 1.20e-3 | 2.95e-4 | 7.41e-5 | | 2.0 | 0.124 |
| (b) \f$\rho u_\theta\f$ | 1.50e-2 | 3.81e-3 | 9.63e-4 | | 2.0 | 1.00 |
| (c) \f$\rho u_x\f$ | 8.84e-4 | 3.27e-4 | 8.63e-5 | | 1.9 | 0.075 |
| (c) \f$\rho u_r\f$ | 1.32e-3 | 3.23e-4 | 8.05e-5 | | 2.0 | 0.107 |
| (c) \f$\rho u_\theta\f$ | 2.79e-3 | 7.94e-4 | 2.03e-4 | | 2.0 | 0.257 |
| (c) \f$\rho E\f$ | 1.24e-3 | 2.93e-4 | 7.30e-5 | | 2.0 | 0.078 |
| (d) \f$\rho u_r\f$ | 1.49e-3 | 5.30e-4 | 1.31e-4 | 3.27e-5 | 2.0 | 0.125 |
| (d) \f$\rho E\f$ | 8.19e-4 | 1.86e-4 | 4.60e-5 | 1.18e-5 | 2.0 | 0.038 |

GNU 13.3 on the CPU, one rank; order from the last two grids. On an NVIDIA Quadro RTX 6000 (NVHPC 25.11, OpenACC, N = 32 and 64) every entry reproduces the CPU error to three digits. Before the fix, 3D lacked the \f$1/r\f$ of the \f$\theta\f$ divergence and of both hoop terms, and 2D used the Cartesian (x, r) stress (no \f$u_r/r\f$ in \f$\nabla\cdot\mathbf{u}\f$, no \f$-\tau_{\theta\theta}/r\f$). The errors then stay O(1) and the measured rates match those of the defective operator (`MASTER` in `exact_rates.py`) to within the errors in the table: the issue's case gives \f$(4 - r)\,\mu A\cos\theta/R^2\f$ instead of \f$3\,\mu A\cos\theta/R^2\f$. Species diffusion uses the same metric (`--case S2`, `S3`). With \f$Y_{H_2} = Y_0 + 10^{-3}(r/R)^2\f$ (times \f$\cos\theta\f$ in 3D, N\f$_2\f$ compensating) at rest in h2o2 at uniform T and p with unity Lewis number, the exact rate of \f$\rho Y_{H_2}\f$ over \f$\epsilon/R^2\f$ is \f$4\rho D + 2r\,d(\rho D)/dr\f$ in 2D (\f$\rho D = k/c_p\f$ follows the local composition) and \f$3\rho D\f$ for the \f$\cos\theta\f$ coefficient in 3D, with \f$k/c_p\f$ from Cantera. The max-norm error relative to the exact mean is 6.7e-6, 1.7e-6, 5.4e-7 in 2D (N = 32, 64, 128) and 1.07e-3, 2.67e-4 in 3D (N = 32, 64), second order; these runs are GNU 12.3 on Phoenix. Before the fix the radial species diffusion was skipped with the axis boundary. Heat conduction in \f$\theta\f$ was already correct and is unchanged to round-off.

Limits: one step (the operator, not a time-accurate flow); smooth fields; the cells next to the axis and the outer boundary are excluded. Surface tension has no cylindrical metric terms in its gradients and is not covered; in 3D its theta divergence and the theta-face hoop terms (which share the momentum flux slots) now carry the \f$1/r\f$. With viscosity and species diffusion together, the axis cell's energy row misses the diffusive energy flux through its outer face ([#2513](https://github.com/MFlowCode/MFC/issues/2513)).

## Stretched grid {#sec-validation-coordinates-stretched}

The 1D Gaussian pulse of @ref validation_acoustics run on a stretched grid (`stretch_x`, `a_x` = 4, clustered on 0.3 to 0.6 mm, one loop): the same number of cells cover 0 to 1.68 mm with \f$\Delta x\f$ from 0.81 to 3.6 times the uniform spacing of 1 mm/N, and the largest change between neighbouring cells 0.8 %. The reference is the same linear solution, evaluated with the run's own cell widths, and \f$\Delta t\f$ is that of the uniform grid (c \f$\Delta t/\Delta x_\text{min}\f$ = 0.73).
Expand All @@ -49,5 +76,6 @@ Limits: one stretching and one direction; a pulse that crosses the clustered reg
./mfc.sh run examples/2D_acoustic_support6_axisym/case.py -t pre_process simulation -n 1 -- --refine 4 --probe
python3 examples/2D_acoustic_support6_axisym/check_focus.py examples/2D_acoustic_support6_axisym --case-args "--refine 4 --probe"
./mfc.sh run examples/1D_acoustic_gauss_sigmatime/case.py -t pre_process simulation post_process -n 1 -- -N 400 --stretch 4
python3 examples/3D_cyl_viscous_mms/run_mms.py --case A3 -N 32 64 128 # also B3, C3, E2, and the species cases S2, S3
python3 examples/1D_acoustic_gauss_sigmatime/check_acoustic.py examples/1D_acoustic_gauss_sigmatime --case-args "-N 400 --stretch 4"
```
Binary file added docs/res/validation_cyl_viscous.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
a constant times cos(theta), the same at every radius. The radial half of that answer,
4*k*A*T0*cos(theta)/R**2, is reproduced exactly by the discretization (T is quadratic in r on a
uniform r-grid), so subtracting it isolates the azimuthal half, -k*A*T0*cos(theta)/R**2, which is
what the (1/r**2) metric in m_conduction has to produce. Dropping either metric factor multiplies
what the two 1/r factors (the face gradient in m_conduction, the divergence in m_rhs) have to produce. Dropping either metric factor multiplies
that half by r**2 -- an r-dependent error that no refinement removes -- so the table reports the
azimuthal half ring by ring as well as in aggregate.

Expand Down
28 changes: 28 additions & 0 deletions examples/3D_cyl_viscous_mms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Cylindrical viscous operator and species diffusion: manufactured solutions

One RK3 step of a manufactured velocity field in cylindrical coordinates (x axial, y = r with the axis at r = 0,
z = theta in radians), uniform density and pressure, mu = 1. The viscous rate is measured as
`(q(dt) with viscosity - q(dt) without) / dt`, so every inviscid term cancels, and compared with the exact rate
of the field (`exact_rates.py`, generated by `derive_rates.py` with sympy).

| `--case` | field | checks |
| --- | --- | --- |
| `A3` | `u_x = A (r/R)^2 cos(theta)` | theta divergence; exact `d(rho u_x)/dt = 3 mu A cos(theta)/R^2` at every r (issue #1910) |
| `B3` | `u_theta = A (r + 0.5/r)` (Taylor-Couette) | hoop term `tau_r_theta / r`; exact viscous force zero (rings with r >= 0.5) |
| `C3` | `u_x = A r^3 cos(theta)`, `u_r = A r^2 cos(theta)`, `u_theta = A (r^3 - r^2 sin(theta))` | all components, shear and bulk viscosity, both hoop terms, viscous work |
| `E2` | `u_x = A (r/R)^2`, `u_r = A (r/R)^3` (2D axisymmetric) | radial flow: `u_r/r` in div u and the hoop term `-tau_theta_theta / r` |
| `S2`, `S3` | h2o2 at rest, uniform T and p, unity Lewis: `Y_H2 = Y0 + eps (r/R)^2` (times `cos(theta)` in `S3`), N2 compensating | species diffusion: radial term and axis cell (`S2`), theta divergence and face gradient (`S3`); exact rate of `rho Y_H2` is `4 rho D eps/R^2` (`3 rho D eps cos(theta)/R^2`) at every r |

```
python3 examples/3D_cyl_viscous_mms/run_mms.py --case A3 -N 32 64 128 -- --no-build
```

The trailing flags are passed to `./mfc.sh run` (use the build flags of your build). The script writes its runs
to `examples/3D_cyl_viscous_mms/runs/` and prints, per grid and component, the max-norm error relative to the
largest exact rate and the distance to the rates of the operator before the fix (`MASTER` in `exact_rates.py`).
For `S2`/`S3` the toggle is species diffusion (`chem_params%diffusion`), the state is set with Cantera, and the
script prints the max-norm error of `c(r)`, the rate (3D: its `cos(theta)` coefficient) over `eps/R^2`, against its
exact value with `rho D = k/cp` from Cantera (in 2D `4 rho D + 2 r d(rho D)/dr`, since `rho D` follows the local
composition), relative to the exact mean. It includes the difference between Cantera's and MFC's transport fits.
The species cases need a chemistry build (`h2o2.yaml`).
Results: `docs/documentation/validation_coordinates.md`.
127 changes: 127 additions & 0 deletions examples/3D_cyl_viscous_mms/case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env python3
# Manufactured-solution check of the cylindrical viscous operator and species diffusion (3D cylindrical and 2D
# axisymmetric). The patch is uniform at rest; run_mms.py overwrites the initial state with the manufactured field
# between pre_process and simulation (no analytic patch, so no per-case compile), runs one step with and without
# viscosity (species cases: diffusion), and compares (q_on - q_off)/dt with the exact rates.
# Coordinates: x axial, y = r (axis at 0), z = theta in radians.
import argparse
import json
import math

# Species-diffusion cases S2/S3 (SI units): h2o2 at rest, uniform T and p, unity Lewis number
SPECIES = {"mech": "h2o2.yaml", "T": 300.0, "p": 101325.0, "Y0": "H2:0.02, O2:0.22, N2:0.76", "eps": 1.0e-3, "R": 2.0e-3, "dt": 1.0e-9}


def species_case(args, d3):
import cantera as ct

gas = ct.Solution(SPECIES["mech"])
gas.TPY = SPECIES["T"], SPECIES["p"], SPECIES["Y0"]
c = {
"chemistry": "T",
"chem_params%diffusion": args.viscous,
"chem_params%reactions": "F",
"chem_params%transport_model": 2,
"cantera_file": SPECIES["mech"],
"viscous": "F",
"dt": SPECIES["dt"],
"x_domain%end": 1.0e-3,
"y_domain%end": SPECIES["R"],
"patch_icpp(1)%pres": SPECIES["p"],
"patch_icpp(1)%alpha_rho(1)": gas.density,
"fluid_pp(1)%gamma": 1.0 / 0.4,
"fluid_pp(1)%eos": "ideal_gas",
}
c.update({f"patch_icpp(1)%Y({k + 1})": y for k, y in enumerate(gas.Y)})
return c


def main():
parser = argparse.ArgumentParser(prog="3D_cyl_viscous_mms", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--mfc", type=json.loads, default="{}", metavar="DICT", help="MFC's toolchain's internal state.")
parser.add_argument("--case", default="A3", choices=["A3", "B3", "C3", "E2", "S2", "S3"], help="manufactured field; trailing digit = dimension")
parser.add_argument("-N", type=int, default=32, help="cells in r (and theta in 3D)")
parser.add_argument("--viscous", default="T", choices=["T", "F"], help="viscosity (species cases: diffusion) on or off")
args = parser.parse_args()

d3 = args.case.endswith("3")
NX, R = 26, 2.0 # fields do not depend on x; WENO5 needs m + 1 >= 26
case = {
"run_time_info": "F",
"x_domain%beg": 0.0,
"x_domain%end": 1.0,
"y_domain%beg": 0.0,
"y_domain%end": R,
"cyl_coord": "T",
"m": NX - 1,
"n": args.N - 1,
"p": args.N - 1 if d3 else 0,
"dt": 1.0e-8,
"t_step_start": 0,
"t_step_stop": 1,
"t_step_save": 1,
"num_patches": 1,
"model_eqns": 2,
"num_fluids": 1,
"time_stepper": 3,
"weno_order": 5,
"weno_eps": 1.0e-16,
"weno_Re_flux": "F",
"weno_avg": "F",
"mapped_weno": "T",
"riemann_solver": 2,
"wave_speeds": 1,
"avg_state": 2,
"viscous": args.viscous,
"bc_x%beg": -1,
"bc_x%end": -1,
"bc_y%beg": -14 if d3 else -2,
"bc_y%end": -3,
"patch_icpp(1)%vel(1)": 0.0,
"patch_icpp(1)%vel(2)": 0.0,
"patch_icpp(1)%pres": 1.0,
"patch_icpp(1)%alpha_rho(1)": 1.0,
"patch_icpp(1)%alpha(1)": 1.0,
"fluid_pp(1)%gamma": 1.0 / 0.4,
"fluid_pp(1)%pi_inf": 0.0,
"parallel_io": "T",
"format": 1,
"precision": 2,
"prim_vars_wrt": "F",
}
if args.viscous == "T" and not args.case.startswith("S"):
case["fluid_pp(1)%Re(1)"] = 1.0 # mu = 1
if args.case in ("C3", "E2"):
case["fluid_pp(1)%Re(2)"] = 1.0 # bulk viscosity 1
if d3:
case.update(
{
"z_domain%beg": 0.0,
"z_domain%end": 2.0 * math.pi,
"bc_z%beg": -1,
"bc_z%end": -1,
"patch_icpp(1)%geometry": 10,
"patch_icpp(1)%x_centroid": 0.5,
"patch_icpp(1)%y_centroid": 0.0,
"patch_icpp(1)%z_centroid": 0.0,
"patch_icpp(1)%length_x": 1.0,
"patch_icpp(1)%radius": 2.0 * R,
"patch_icpp(1)%vel(3)": 0.0,
}
)
else:
case.update({"patch_icpp(1)%geometry": 3, "patch_icpp(1)%x_centroid": 0.5, "patch_icpp(1)%y_centroid": 0.5 * R, "patch_icpp(1)%length_x": 1.0, "patch_icpp(1)%length_y": 2.0 * R})

if args.case.startswith("S"):
case.update(species_case(args, d3))
del case["fluid_pp(1)%pi_inf"] # ideal gas
if d3:
case["patch_icpp(1)%radius"] = 2.0 * SPECIES["R"]
else:
case.update({"patch_icpp(1)%y_centroid": 0.5 * SPECIES["R"], "patch_icpp(1)%length_y": 2.0 * SPECIES["R"]})
case.update({"patch_icpp(1)%x_centroid": 0.5e-3, "patch_icpp(1)%length_x": 1.0e-3})
print(json.dumps(case))


if __name__ == "__main__":
main()
Loading
Loading