Skip to content

Wrong results with models that use time series #72

@pya

Description

@pya

Approach

I ran all models from MODFLOW 6 examples: built 02/06/2025 19:17.

Code

This code was used to run all models:

from modflowapi import Callbacks, run_simulation

def callback(sim, callback_step):
    pass

run_simulation(
    dll='path/to/libmf6.dylib',
    sim_path='path/tomodel',
    callback=callback,
)

Versions

  • modflowapi: 0.3.0.dev0
  • xmipy: 1.3.1
  • MODFLOW: 6.6.1

Results

Most model runs produce the same output compared with the standalone MODFLOW executable. But these models:

  • ex-gwf-csub-p03a
  • ex-gwf-fhb
  • ex-gwf-advtidal
  • ex-gwf-csub-p03b

produce significantly different results in the balance values as listed in each <mode-name>.lst file. All of these models use of time series.

These models also use time series:

  • ex-gwf-csub-p01
  • ex-gwf-sfr-pindersauera
  • ex-gwf-sfr-pindersauerb

but show no differences in results compared to the standalone runs.

Potential problem

The problems seems to be in the solution loop in modflowapi.extensions.runner.run_simulation().

Replacing this loop:

    for sol_id, slnobj in sorted(sim.solutions.items()):
            models = {}
            maxiter = slnobj.mxiter
            solution = {sol_id: slnobj}
            for model in sim.models:
                if sol_id == model.solution_id:
                    models[model.name.lower()] = model

            sim_grp = ApiSimulation(
                mf6, models, solution, sim._exchanges, sim.tdis, sim.ats
            )
            mf6.prepare_solve(sol_id)
            if sim.kper != kperold[sol_id - 1]:
                callback(sim_grp, Callbacks.stress_period_start)
                kperold[sol_id - 1] += 1
            elif current_time == 0:
                callback(sim_grp, Callbacks.stress_period_start)

            kiter = 0
            callback(sim_grp, Callbacks.timestep_start)

            if sim_grp.ats_period[0]:
                mindt = sim_grp.ats_period[-1]
                while sim_grp.delt > mindt:
                    sim_grp.iteration = kiter
                    callback(sim_grp, Callbacks.iteration_start)
                    has_converged = mf6.solve(sol_id)
                    callback(sim_grp, Callbacks.iteration_end)
                    kiter += 1
                    if has_converged and sim_grp.allow_convergence:
                        break

            else:
                while kiter < maxiter:
                    sim_grp.iteration = kiter
                    callback(sim_grp, Callbacks.iteration_start)
                    has_converged = mf6.solve(sol_id)
                    callback(sim_grp, Callbacks.iteration_end)
                    kiter += 1
                    if has_converged and sim_grp.allow_convergence:
                        break

            callback(sim_grp, Callbacks.timestep_end)
            mf6.finalize_solve(sol_id)

with:

mf6.do_time_step()

fixes the problem and all models produce the same results as the standalone runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions