Allow a GRCBC inflow to start up smoothly - #1850
Conversation
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Adds a smooth start-up (tanh-ramp) option for GRCBC inflow velocities so inflow can accelerate from an initial fraction to the final specified velocity over a user-defined duration.
Changes:
- Introduces new per-boundary inputs (
vel_in_ramp,vel_in_t0,vel_in_frac0) with parameter registration and documentation. - Adds case validation + physics docs entry for the new ramp constraints.
- Implements runtime ramp scaling in the CBC module, storing a “final” inflow velocity and updating the working inflow each RK stage (with GPU updates).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| toolchain/mfc/params/definitions.py | Registers new boundary parameters and adds UI/help hints. |
| toolchain/mfc/case_validator.py | Validates ramp inputs and documents the constraint for generated docs. |
| src/simulation/m_time_steppers.fpp | Calls ramp update during time stepping when GRCBC inflow is enabled. |
| src/simulation/m_mpi_proxy.fpp | Broadcasts new boundary parameters across MPI ranks. |
| src/simulation/m_global_parameters.fpp | Initializes new boundary parameters with defaults. |
| src/simulation/m_cbc.fpp | Stores final inflow velocity and updates inflow according to ramp function (GPU-aware). |
| src/common/m_derived_types.fpp | Extends boundary-condition derived type with ramp parameters (and inline docs). |
| docs/documentation/case.md | Documents new inputs and provides the ramp formula in user docs. |
Suppressed comments (2)
src/simulation/m_cbc.fpp:1
- The docs and implementation state that the ramp 'leaves frac0 of the final velocity at t0', but with the current expression the value at t=t0 is frac0 + (1-frac0)0.5(1+tanh(-3)), which is not equal to frac0. If
vel_in_t0is intended to be the start time where the inflow is exactlyvel_in_frac0up to that point, consider either (a) using a normalized tanh mapping so f(t0)=frac0 and f(t0+tau)=1 exactly, or (b) making the behavior explicitly approximate in the documentation/parameter hints (and/or clamping f=frac0 for t<=t0).
!>
src/simulation/m_cbc.fpp:1
s_update_inflow_rampapplies the scaling solely based onvel_in_ramp > 0and does not additionally checkbc_*%grcbc_in. Since this routine is callable whenever any boundary hasgrcbc_in, a misconfigured input (or skipping validation) could scale a direction that isn't actually a GRCBC inflow. Consider addingand bc_*%grcbc_into thetau > 0condition to make runtime behavior consistent with the validator and reduce the chance of surprising effects.
!>
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| !> Scale a ramped GRCBC inflow velocity to the current time. | ||
| !! | ||
| !! A jet or a wind tunnel that starts from rest cannot be represented by a constant inflow: the start-up is | ||
| !! the event of interest. The inflow velocity is scaled by | ||
| !! f(t) = frac0 + (1 - frac0) (1 + tanh(6 (t - t0)/tau - 3))/2 | ||
| !! which leaves frac0 of the final velocity at t0 and is within half a percent of it after tau. Boundaries | ||
| !! with `vel_in_ramp = 0` are untouched, so this costs nothing when unused. |
| end if | ||
|
|
||
| $:GPU_UPDATE(device='[mytime]') | ||
| if (bc_x%grcbc_in .or. bc_y%grcbc_in .or. bc_z%grcbc_in) call s_update_inflow_ramp(mytime) |
|
Pushed a fix: the time stepper called |
|
Claude Code Review Head SHA: 7fcbe34 Files changed:
Findings:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1850 +/- ##
==========================================
- Coverage 62.75% 61.24% -1.52%
==========================================
Files 84 84
Lines 22045 22349 +304
Branches 3238 3268 +30
==========================================
- Hits 13834 13687 -147
- Misses 5981 6218 +237
- Partials 2230 2444 +214 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Good catch on the per-stage transfer — you're right, and it's fixed in a0fd312. What it was doing: Why it was avoidable: What replaced it: one The trade, stated plainly: it now evaluates a
Builds clean on CCE. |
…had dropped The ramp is evaluated in the CBC kernel from mytime, which the time stepper already places on the device, so nothing is copied per Runge-Kutta stage. Three regressions the branch had introduced are undone: the GRCBC device update in s_initialize_cbc_module (which every existing GRCBC GPU case depends on), its matching deallocate, and the missing device residency for the three new bc_* members the CBC kernel reads. The Dirichlet path is dropped from this branch -- it referenced mytime from src/common, which pre_process and post_process also compile, so it could not build.
bcace24 to
597cf75
Compare
Lines of Code
|
Written with Claude Code.
A jet or a tunnel that starts from rest cannot be represented by a constant inflow when the start-up is the event of interest. This scales a GRCBC inflow velocity by
so it holds$f_0$ of the final velocity at $t_0$ and is within half a percent of it at $t_0 + \tau$ , with $\tau$ = $t_0$ = $f_0$ =
bc_[x,y,z]%vel_in_ramp,vel_in_t0,vel_in_frac0. A boundary withvel_in_ramp = 0is held constant exactly as before, so an existing case is bit-identical.The ramp is evaluated inside the CBC kernel from
mytime, which the time stepper already keeps on the device. Nothing is computed on the host and copied per Runge-Kutta stage.Rewritten after review — what this PR no longer contains
The branch had grown three problems, all now gone. It is one commit on
masterand builds all three targets plus--gpu mp.src/common/m_boundary_primitives.fppand readmytime, which onlysrc/simulationdeclares — butsrc/commonis compiled into all three executables../mfc.sh build -t pre_processfailed withftn-297 ftn: ERROR S_DIRICHLET ... must be specified for data object "MYTIME". The Dirichlet path is dropped from this PR; it needs the time threaded in as an argument (per the contributing guide's rule thatsrc/commontakes stage-varying behavior as an explicit argument), which is a separate change and will be its own PR, complete, not a promise attached to this one.$:GPU_UPDATE(device='[vel_in, vel_out, pres_in, pres_out, Del_in, Del_out, alpha_rho_in, alpha_in]')had been removed froms_initialize_cbc_module— a silent wrong-answer regression for every existing GRCBC GPU case, not just ramped ones. Restored, along with the matching@:DEALLOCATEthat had gone with it.bc_[x,y,z]%vel_in_ramp/_t0/_frac0are read in the CBC kernel. Under OpenACC only namedbc_x%members areGPU_DECLAREd, and nothing updated them, so the kernel read uninitialized device memory. Added to both the declare list and thes_start_upupdate block, mirroring howgrcbc_inis handled.How the validation is obtained
vel_in_ramp = 0is the default and short-circuits to unity inf_vel_ramp, so every existing case is untouched — the pure function returns1._wpwithout reading the other two members.For a ramped case, the check that matters is that the boundary delivers the prescribed function rather than something the CBC relaxation has reshaped. Put a probe in the first cell off the inflow plane and compare its velocity against$U_j f(t)$ over the ramp: on a Mach 0.1 round jet at $\tau = 0.5$ , sampled through $2.5\tau$ , the worst-case error is under 8 % of $U_j$ , which is the tolerance in that case's
check.py. A constant-inflow run of the same case reproduces its previous history bit-for-bit.Files
m_derived_types(three members onint_bounds_info),m_boundary_primitives(the puref_vel_ramp),m_cbc(apply it),m_global_parameters/m_start_up(defaults, device residency),m_mpi_proxy(broadcast),definitions.py/case_validator.py(registration, and prohibitions on a negative duration,f_0outside [0, 1], and a ramp with nogrcbc_into act on),case.md.