0

TOUGH3 CYCIT: failed PETSc solve can be accepted as a timestep when MOP(17)=9

Hi,

I would like to report a suspected timestep-acceptance bug in CYCIT (src/Main_Comp.f90) when a PETSc linear solve fails and MOP(17)=9 requests timestep reduction.

In my tests using TOUGH3–FLAC3D (EOS3), an unsuccessful linear solve was followed by an apparently accepted timestep, advancing simulation time and writing FOFT/GOFT records without updating the monitored temperature and pressure values. A local source-level modification corrected this behavior in my test case.

I also identified the same relevant control flow in the Main_Comp.f90 source file from TOUGH3 v1.1.

In the CYCIT routine, the return status of the linear equation solver (called through the internal LINEQ routine) is checked only after the computed correction has been accumulated into DX.

The relevant error-handling section is:

if (IGOOD .NE. 0) then
    IGOOD = 0
    if (MOP(17) .EQ. 9) exit
endif

When LINEQ fails and MOP(17)=9, this resets IGOOD to zero and exits the Newton iteration loop.

However, the subsequent timestep-acceptance condition is:

IF (IGOOD.EQ.0 .AND. ITER .LE. NOITE) THEN
    timestep_is_good = .true.
    ...
ENDIF

Consequently, a failed linear solve can satisfy the timestep-acceptance condition even though nonlinear_converged remains .false.

As a result, the simulation may bypass the intended timestep reduction and incorrectly advance the simulation time while writing FOFT/GOFT records, even though the linear solver has not converged.

With MOP(16)=2, the timestep-selection logic can additionally increase the next timestep, exacerbating the behavior.

Verification: In the original simulation, nine PETSc failures were associated with additional FOFT/GOFT records and an extended period of unchanged temperature and pressure. After modifying the timestep-acceptance logic, a diagnostic simulation completed 755 accepted timesteps, with 755 FOFT records. All 12 PETSc failures triggered timestep reduction, and the temperature and pressure fields continued evolving.

This appears to be a timestep-control issue in TOUGH3 exposed by linear-solver nonconvergence, rather than a defect in PETSc itself.

I would appreciate clarification on the following:

  1. Is the IGOOD=0 / EXIT / timestep-acceptance sequence a known issue in TOUGH3 v1.1 or other versions?
  2. Is an official correction available, particularly for PETSc failures with MOP(17)=9?
  3. Should additional safeguards be implemented for MPI synchronization, state rollback, hysteresis variables, or other MOP(17) settings?
  4. Has this issue already been addressed in newer TOUGH3 releases?

I can provide before/after diagnostic log excerpts and a source-code diff.

My current numerical reproducer is a large coupled model. I have not yet developed a small-grid standalone reproducer, as recommended in the forum guidelines.

Thank you for your feedback.

1 reply

null
    • kenny
    • 5 hrs ago
    • Reported - view

    Following is the answer from TOUGH Agent (https://www.tough2.com/hgl)

    Hi Carlos,

    Yes. With the statements in the order you show, CYCIT can accept a timestep after LINEQ reports failure with MOP(17)=9. The Newton loop has already established that the current iterate has not converged. Clearing IGOOD and then executing EXIT lets control reach the acceptance test with IGOOD=0 and ITER<=NOITE. No further residual evaluation occurs. That contradicts the TOUGH3 User’s Guide, which specifies timestep reduction after linear solver failure for MOP(17)=9.

    The local source has a different ordering. Its TOUGH3.f90 header identifies version 1.12, September 2022. In src/Main_Comp.f90, LINEQ sets IGOOD=3 and returns when the solver reports failure. The relevant statements in CYCIT, at lines 490–494, are:

    if (IGOOD .NE. 0) then
        if (MOP(17) .EQ. 9) exit
        IGOOD=0
    endif

    For option 9, IGOOD therefore retains the value 3 across the loop exit. The acceptance test at line 506 fails, and the rejection branch sets DELT=DELTEX/REDLT for the retry, subject to the minimum timestep and retry limits. This ordering is present in the earliest revision available in this repository (23c7013). The bundled ReadMe_V1.12.pdf mentions bug fixes generally, without identifying this issue. The local source addresses the specific flag-ordering defect. The available history does not establish an official patch number, the first corrected distribution, or which v1.1 or TOUGH3–FLAC3D builds contain either ordering.

    Your MOP(16)=2 observation also follows from the source. Once a step reaches CONVER, that routine commits DX to the primary variables and advances SUMTIM by DELTEX. Under automatic timestep selection, ITER<=2 then proposes twice the previous step size, subject to the applicable limits. CYCIT subsequently calls FGTAB for enabled history output. A new FOFT or GOFT timestamp is therefore consistent with the erroneous acceptance. The source does not require pressure and temperature to stay constant during such an event. That was the symptom in your coupled case. Reported before-and-after observations

    For a correction in the coupled branch, I would check three things:

    • Solver status and MPI. Use the final linear-solver result. The local PETSc interface can retry internally for some preconditioners before returning succeed=.false.. With option 9, all ranks should agree on that result before any rank applies the correction or leaves the Newton loop. The IGOOD reduction after CALL EOS comes too late to synchronize an earlier EXIT. The local CYCIT still accumulates R into DX before checking IGOOD. Checking first would keep a rejected correction out of the trial state. Preserve the documented behavior of MOP(17)=0, which allows Newton iteration to continue after linear solver failure.
    • Rollback and hysteresis. On an ordinary retry, CYCIT calls EOS3 with ITER=0 and IHLV=1. EOS3 reconstructs its state from X without adding DX, and CYCIT clears DX at the start of the next Newton attempt. In a coupled build, also verify that FLAC3D history advances only on acceptance or is restored on rejection. If hysteresis is active, SAVEHS can itself veto a step for IHYSTER<0, while CONVER commits SNMAXII to SNMAX for IHYSTER>0. Both paths belong in a rollback check.
    • Acceptance and termination. Make successful nonlinear convergence an explicit prerequisite for committing state or writing accepted-step history. Include retry exhaustion in that review. In the local CYCIT, the minimum-step or retry-limit branch sets IQIT=1 and exits the retry loop, after which control still reaches CALL CONVER. That is a separate exit path worth testing.

    Please post the source diff and one paired log excerpt, even while the small standalone case is pending. The most diagnostic sequence would show the final PETSc convergence reason, IGOOD on return from LINEQ, KCYC, ITER, the attempted DELTEX, and SUMTIM across the rejection and retry. Showing the same start time, a smaller retry step, and the next history record only after nonlinear convergence would make the correction assessable independently of the size of the coupled model.

Content aside

  • 5 hrs agoLast active
  • 1Replies
  • 15Views
  • 2 Following