Skip to content

Apply CrankNicolson's ddtCorr as OpenFOAM does - #108

Merged
tihiera merged 2 commits into
developfrom
fix/cn-ddtcorr
Nov 28, 2026
Merged

tihiera merged 2 commits into
developfrom
fix/cn-ddtcorr

Conversation

@tihiera

@tihiera tihiera commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

pimpleFoam under CrankNicolson applies OpenFOAM's fvc::ddtCorr, which brae omitted with a notice.

OpenFOAM: CrankNicolsonDdtScheme::fvcDdtPhiCorr (.C:1262-1320) keeps two DDt0Fields of its own, ddtCorrDdt0(U) and ddtCorrDdt0(phi). The correction is

ddtCouplingCoeff*((rDtCoef*phi_o + offCentre(dphidt0)) - (Sf & interpolate(rDtCoef*U_o + offCentre(ddt0))))
  • Each field is created zero on the first step that asks for it (ddt0_, .C:102-165), and evaluated once a step after that (evaluate, .C:170-180): ddt0 = rDtCoef0*(old - oldOld) - offCentre(ddt0).
  • rDtCoef = coef/deltaT and rDtCoef0 = coef0/deltaT0. coef is 1 + ocCoeff after the start step, and coef0 after the step following it; both are 1 before that (.C:184-226).
  • offCentre multiplies by ocCoeff when ocCoeff is below 1 (.C:249-260).
  • U's old-old level exists from the first step, because fvmDdt asks for it unconditionally. phi's is created at the first evaluation as a copy of phi.oldTime(), so dphidt0 starts from zero while ddt0 does not.

brae before: under CrankNicolson the correction was omitted with a notice. On incompressible/pimpleFoam/RAS/pitzDaily from rest at CrankNicolson 0.9, p was 2.3 off OpenFOAM at step 2 and 1.0e+02 by step 5. With ddtCorr off in both codes, the same case agrees to 5e-11 (RAS and laminar), so the whole gap was this term.

Change:

  • The driver carries the two DDt0 recurrences (cells and patch values for U's, internal and boundary faces for phi's), creates them zero on their first step and evaluates them once per step. phi's old-old level is a copy at the first evaluation, as OpenFOAM creates it.
  • The scheme's bracket goes to the existing correction kernel, which applies the coupling coefficient from the single old level as before.
  • The time index the driver already receives (Apply Euler ddtCorr on backward's first step #104) dates the fields.
  • A moving mesh (OpenFOAM's fvcDdtUfCorr) and cyclic or AMI interfaces keep the notice and omit the term.
  • Control: BRAE_CONTROL_CN_NO_DDTCORR=1.

Gate: new tests/pimple_cranknicolson_vs_openfoam.sh (label slow). pitzDaily from rest at a fixed deltaT 1e-4, six steps, every solve tight, ddtCorr on. Every entry of p, U, k, epsilon and nut, and phi, at steps 1-6 within 1e-8:

Arm Before (develop 191bc2dc) After
C9 (CrankNicolson 0.9) 1.0e+02 (p at step 5), phi 9.9e-02 3.2e-09, phi 1.5e-11
C1 (CrankNicolson 1) 1.4e+02, phi 1.0e-01 3.4e-09, phi 1.5e-11
  • Premise: OpenFOAM's own ddtCorr moves C9 by 2.3 at step 2.
  • Control: red at 1.0e+02.
  • U holds 6e-12 and phi 1.5e-11 at every step. The p entry's 3.2e-09 is a floor: p's absolute difference is flat at 2-4e-7 from step 1 on (the p solves' tolerance), while its scale falls from 1.8e4 to 112 as the start-up pressure decays.

Regressions (one GH200; this branch against develop 191bc2dc, built and run on the same node, one tree at a time):

  • The new gate as registered passes on this branch. In report mode on develop's binaries, C9 reads 1.0e+02 and C1 1.4e+02; the premise and control hold on both.
  • 29 tests on each tree, all passing on both: every pimpleFoam, DES, ddt (gpu_ddt_cn included), restart, backward and CrankNicolson test, plus the registration and audit tests.

Not covered:

  • The CrankNicolson restart: brae does not write or read ddtCorrDdt0(U), ddtCorrDdt0(phi), U_0 and phi_0, which OpenFOAM does.
  • A moving mesh's fvcDdtUfCorr, and cyclic or AMI interfaces (notice, term omitted).

No tolerance was changed.

@tihiera
tihiera merged commit ecaa29e into develop Nov 28, 2026
6 checks passed
@tihiera
tihiera deleted the fix/cn-ddtcorr branch November 28, 2026 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant