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:
- Is the IGOOD=0 / EXIT / timestep-acceptance sequence a known issue in TOUGH3 v1.1 or other versions?
- Is an official correction available, particularly for PETSc failures with MOP(17)=9?
- Should additional safeguards be implemented for MPI synchronization, state rollback, hysteresis variables, or other MOP(17) settings?
- 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
-
Following is the answer from TOUGH Agent (https://www.tough2.com/hgl)
Hi Carlos,
Yes. With the statements in the order you show,
CYCITcan accept a timestep afterLINEQreports failure withMOP(17)=9. The Newton loop has already established that the current iterate has not converged. ClearingIGOODand then executingEXITlets control reach the acceptance test withIGOOD=0andITER<=NOITE. No further residual evaluation occurs. That contradicts the TOUGH3 User’s Guide, which specifies timestep reduction after linear solver failure forMOP(17)=9.The local source has a different ordering. Its
TOUGH3.f90header identifies version 1.12, September 2022. Insrc/Main_Comp.f90,LINEQsetsIGOOD=3and returns when the solver reports failure. The relevant statements inCYCIT, at lines 490–494, are:if (IGOOD .NE. 0) then if (MOP(17) .EQ. 9) exit IGOOD=0 endifFor option 9,
IGOODtherefore retains the value3across the loop exit. The acceptance test at line 506 fails, and the rejection branch setsDELT=DELTEX/REDLTfor the retry, subject to the minimum timestep and retry limits. This ordering is present in the earliest revision available in this repository (23c7013). The bundledReadMe_V1.12.pdfmentions 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)=2observation also follows from the source. Once a step reachesCONVER, that routine commitsDXto the primary variables and advancesSUMTIMbyDELTEX. Under automatic timestep selection,ITER<=2then proposes twice the previous step size, subject to the applicable limits.CYCITsubsequently callsFGTABfor 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 observationsFor 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. TheIGOODreduction afterCALL EOScomes too late to synchronize an earlierEXIT. The localCYCITstill accumulatesRintoDXbefore checkingIGOOD. Checking first would keep a rejected correction out of the trial state. Preserve the documented behavior ofMOP(17)=0, which allows Newton iteration to continue after linear solver failure. - Rollback and hysteresis. On an ordinary retry,
CYCITcalls EOS3 withITER=0andIHLV=1. EOS3 reconstructs its state fromXwithout addingDX, andCYCITclearsDXat 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,SAVEHScan itself veto a step forIHYSTER<0, whileCONVERcommitsSNMAXIItoSNMAXforIHYSTER>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 setsIQIT=1and exits the retry loop, after which control still reachesCALL 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,
IGOODon return fromLINEQ,KCYC,ITER, the attemptedDELTEX, andSUMTIMacross 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. - Solver status and MPI. Use the final linear-solver result. The local PETSc interface can retry internally for some preconditioners before returning
