Skip to content

Commit 2d0d2fd

Browse files
authored
Fix numerical Schlieren for single fluid IGR + add case validation guard for schlieren_alpha (#1477)
1 parent b53fbe8 commit 2d0d2fd

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

docs/documentation/case.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ If `file_per_process` is true, then pre_process, simulation, and post_process mu
708708

709709
- ``[variable's name]_wrt`` activates the output of each specified variable into the database.
710710

711-
- `schlieren_alpha(i)` specifies the intensity of the numerical Schlieren of $i$-th component.
711+
- `schlieren_alpha(i)` specifies the intensity of the numerical Schlieren of $i$-th component. It must be specified for every fluid when `schlieren_wrt` is enabled.
712712

713713
- `fd_order` specifies the order of the finite difference scheme used to compute the vorticity from the velocity field and the numerical schlieren from the density field using an integer of 1, 2, and 4.
714714
`fd_order = 1`, `2`, and `4` correspond to the first, second, and fourth-order finite difference schemes.

src/post_process/m_derived_variables.fpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ contains
438438

439439
real(wp) :: drho_dx, drho_dy, drho_dz !< Spatial derivatives of the density in the x-, y- and z-directions
440440
real(wp), dimension(2) :: gm_rho_max !< Global (max gradient magnitude, rank) pair for density
441+
real(wp) :: alpha_last !< Volume fraction of the fluid not explicitly stored (IGR)
441442
integer :: i, j, k, l
442443

443444
do l = -offset_z%beg, p + offset_z%end
@@ -495,10 +496,24 @@ contains
495496
do j = -offset_x%beg, m + offset_x%end
496497
q_sf(j, k, l) = 0._wp
497498
498-
do i = 1, eqn_idx%adv%end - eqn_idx%E
499-
q_sf(j, k, l) = q_sf(j, k, l) - schlieren_alpha(i)*q_cons_vf(i + eqn_idx%E)%sf(j, k, l)*gm_rho_sf(j, &
500-
& k, l)/gm_rho_max(1)
501-
end do
499+
! Tracks the volume fraction of the fluid not explicitly stored (IGR reconstructs it as 1 - sum)
500+
if (igr) then
501+
! IGR stores only num_fluids-1 volume fractions; the last fluid's volume fraction is untracked.
502+
! For a single fluid this is simply 1.0 everywhere. Without this term, the entire single-fluid
503+
! Schlieren field is dropped, leaving exp(0) = 1 everywhere. Compute that term below.
504+
alpha_last = 1._wp
505+
do i = 1, eqn_idx%adv%end - eqn_idx%E
506+
q_sf(j, k, l) = q_sf(j, k, l) - schlieren_alpha(i)*q_cons_vf(i + eqn_idx%E)%sf(j, k, &
507+
& l)*gm_rho_sf(j, k, l)/gm_rho_max(1)
508+
alpha_last = alpha_last - q_cons_vf(i + eqn_idx%E)%sf(j, k, l)
509+
end do
510+
q_sf(j, k, l) = q_sf(j, k, l) - schlieren_alpha(num_fluids)*alpha_last*gm_rho_sf(j, k, l)/gm_rho_max(1)
511+
else
512+
do i = 1, eqn_idx%adv%end - eqn_idx%E
513+
q_sf(j, k, l) = q_sf(j, k, l) - schlieren_alpha(i)*q_cons_vf(i + eqn_idx%E)%sf(j, k, &
514+
& l)*gm_rho_sf(j, k, l)/gm_rho_max(1)
515+
end do
516+
end if
502517
end do
503518
end do
504519
end do

toolchain/mfc/case_validator.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,14 +1558,24 @@ def check_schlieren(self):
15581558
n = self.get("n", 0)
15591559
fd_order = self.get("fd_order")
15601560
num_fluids = self.get("num_fluids")
1561+
model_eqns = self.get("model_eqns")
15611562

15621563
self.prohibit(n is not None and n == 0 and schlieren_wrt, "schlieren_wrt requires n > 0 (at least 2D)")
15631564
self.prohibit(schlieren_wrt and fd_order is None, "fd_order must be set for schlieren_wrt")
15641565

1566+
# The volume-fraction model (model_eqns /= 1) weights the Schlieren field by schlieren_alpha(i) for every fluid; an unset
1567+
# value stays at the -1e6 sentinel and produces nonsensical output. Under IGR the last fluid's volume fraction is
1568+
# reconstructed (not stored), so schlieren_alpha must still be set for all num_fluids components, including the single
1569+
# fluid of a single-fluid IGR case. The gamma/pi_inf model (model_eqns == 1) does not use schlieren_alpha.
15651570
if num_fluids is not None:
15661571
for i in range(1, num_fluids + 1):
15671572
schlieren_alpha = self.get(f"schlieren_alpha({i})")
1568-
if schlieren_alpha is not None:
1573+
if schlieren_alpha is None:
1574+
self.prohibit(
1575+
schlieren_wrt and model_eqns is not None and model_eqns != 1,
1576+
f"schlieren_alpha({i}) must be set for every fluid when schlieren_wrt is enabled (unless model_eqns == 1)",
1577+
)
1578+
else:
15691579
self.prohibit(schlieren_alpha <= 0, f"schlieren_alpha({i}) must be greater than zero")
15701580
self.prohibit(not schlieren_wrt, f"schlieren_alpha({i}) should be set only with schlieren_wrt enabled")
15711581

0 commit comments

Comments
 (0)