From d6a25f5df6798d0e2a29f10cf669a8b0f718417c Mon Sep 17 00:00:00 2001 From: Jeremy Lore Date: Tue, 8 Sep 2026 08:52:28 -0400 Subject: [PATCH] Preserve face orientation in intflux Use the signed fcQalf projection in the primal and differentiated intflux routines so face orientation is retained across topology cuts. --- src/differentiation/adjoint/intflux_b.F90 | 11 ++--------- src/differentiation/hessian_tgt/intflux_dv_dv.F90 | 11 ++--------- src/differentiation/tangent/intflux_dv.F90 | 11 ++--------- src/utility/intflux.F | 6 ++++-- 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/differentiation/adjoint/intflux_b.F90 b/src/differentiation/adjoint/intflux_b.F90 index ae57880d3..ac4d4b456 100644 --- a/src/differentiation/adjoint/intflux_b.F90 +++ b/src/differentiation/adjoint/intflux_b.F90 @@ -53,8 +53,6 @@ SUBROUTINE INTFLUX_NODIFF(nfc, ncv, mpg, geo, faceflux, density, cvflux) ! INTEGER :: idir, ifc REAL(kind=r8) :: qf(nfc), wrkf(nfc, 0:1), wrkc(ncv, 0:1) - INTRINSIC ABS - REAL(kind=r8) :: abs0 ! ! ..interpolate the quantity to cell faces CALL INTFACE(ncv, nfc, mpg%fccv, geo%fcvol, density, qf) @@ -64,13 +62,8 @@ SUBROUTINE INTFLUX_NODIFF(nfc, ncv, mpg, geo, faceflux, density, cvflux) DO ifc=1,nfc IF (geo%fcqalf(ifc, idir) .NE. 0.0_R8 .AND. qf(ifc) .NE. 0.0_R8) & & THEN - IF (geo%fcqalf(ifc, idir) .GE. 0.) THEN - abs0 = geo%fcqalf(ifc, idir) - ELSE - abs0 = -geo%fcqalf(ifc, idir) - END IF - wrkf(ifc, idir) = faceflux(ifc, idir)/qf(ifc)/(geo%fcs(ifc)*abs0& -& ) + wrkf(ifc, idir) = faceflux(ifc, idir)/qf(ifc)/(geo%fcs(ifc)*geo%& +& fcqalf(ifc, idir)) ELSE wrkf(ifc, idir) = 0.0_R8 END IF diff --git a/src/differentiation/hessian_tgt/intflux_dv_dv.F90 b/src/differentiation/hessian_tgt/intflux_dv_dv.F90 index bd49a96e5..3cfe2d693 100644 --- a/src/differentiation/hessian_tgt/intflux_dv_dv.F90 +++ b/src/differentiation/hessian_tgt/intflux_dv_dv.F90 @@ -59,8 +59,6 @@ SUBROUTINE INTFLUX_NODIFF_NODIFF(nfc, ncv, mpg, geo, faceflux, density, & ! INTEGER :: idir, ifc REAL(kind=r8) :: qf(nfc), wrkf(nfc, 0:1), wrkc(ncv, 0:1) - INTRINSIC ABS - REAL(kind=r8) :: abs0 ! ! ..interpolate the quantity to cell faces CALL INTFACE(ncv, nfc, mpg%fccv, geo%fcvol, density, qf) @@ -70,13 +68,8 @@ SUBROUTINE INTFLUX_NODIFF_NODIFF(nfc, ncv, mpg, geo, faceflux, density, & DO ifc=1,nfc IF (geo%fcqalf(ifc, idir) .NE. 0.0_R8 .AND. qf(ifc) .NE. 0.0_R8) & & THEN - IF (geo%fcqalf(ifc, idir) .GE. 0.) THEN - abs0 = geo%fcqalf(ifc, idir) - ELSE - abs0 = -geo%fcqalf(ifc, idir) - END IF - wrkf(ifc, idir) = faceflux(ifc, idir)/qf(ifc)/(geo%fcs(ifc)*abs0& -& ) + wrkf(ifc, idir) = faceflux(ifc, idir)/qf(ifc)/(geo%fcs(ifc)*geo%& +& fcqalf(ifc, idir)) ELSE wrkf(ifc, idir) = 0.0_R8 END IF diff --git a/src/differentiation/tangent/intflux_dv.F90 b/src/differentiation/tangent/intflux_dv.F90 index ea839d1ac..7f7fa20d7 100644 --- a/src/differentiation/tangent/intflux_dv.F90 +++ b/src/differentiation/tangent/intflux_dv.F90 @@ -55,8 +55,6 @@ SUBROUTINE INTFLUX_NODIFF(nfc, ncv, mpg, geo, faceflux, density, cvflux) ! INTEGER :: idir, ifc REAL(kind=r8) :: qf(nfc), wrkf(nfc, 0:1), wrkc(ncv, 0:1) - INTRINSIC ABS - REAL(kind=r8) :: abs0 ! ! ..interpolate the quantity to cell faces CALL INTFACE(ncv, nfc, mpg%fccv, geo%fcvol, density, qf) @@ -66,13 +64,8 @@ SUBROUTINE INTFLUX_NODIFF(nfc, ncv, mpg, geo, faceflux, density, cvflux) DO ifc=1,nfc IF (geo%fcqalf(ifc, idir) .NE. 0.0_R8 .AND. qf(ifc) .NE. 0.0_R8) & & THEN - IF (geo%fcqalf(ifc, idir) .GE. 0.) THEN - abs0 = geo%fcqalf(ifc, idir) - ELSE - abs0 = -geo%fcqalf(ifc, idir) - END IF - wrkf(ifc, idir) = faceflux(ifc, idir)/qf(ifc)/(geo%fcs(ifc)*abs0& -& ) + wrkf(ifc, idir) = faceflux(ifc, idir)/qf(ifc)/(geo%fcs(ifc)*geo%& +& fcqalf(ifc, idir)) ELSE wrkf(ifc, idir) = 0.0_R8 END IF diff --git a/src/utility/intflux.F b/src/utility/intflux.F index 8c2933d12..862775912 100644 --- a/src/utility/intflux.F +++ b/src/utility/intflux.F @@ -22,7 +22,9 @@ subroutine intflux(nFc,nCv,mpg,geo,faceflux,density,cvflux) c Provides an interpolation of face flux quantities to cell centers c The flux carries the cell-centered density of the quantity being transported c We first interpolate the density to cell faces -c We then compute an effective velocity at cell faces +c We then compute an effective velocity at cell faces. The projected area +c retains the sign of fcQalf because face orientation can reverse across +c topology cuts. C We interpolate this velocity to cell centers c We multiply the interpolated velocity by the density and the projected area use b2mod_types @@ -47,7 +49,7 @@ subroutine intflux(nFc,nCv,mpg,geo,faceflux,density,cvflux) do iFc = 1, nFc if (geo%fcQalf(iFc,idir).ne.0.0_R8.and.qf(iFc).ne.0.0_R8) then wrkf(iFc,idir) = faceflux(iFc,idir)/qf(iFc)/ - . (geo%fcS(iFc)*abs(geo%fcQalf(iFc,idir))) + . (geo%fcS(iFc)*geo%fcQalf(iFc,idir)) else wrkf(iFc,idir) = 0.0_R8 end if