Creating empty packages results in unguided errors
I have a modelscript up and running for a specific model extent.
However, when I change the model extent so that several boundary condition definitions completely fall outside the model extent. The packages that configure those boundary conditions should not be added to the MF6 simulation.
For example I am configuring the well package and depending on the extent I select, wells need to be configured or not. In the current implementation and all wells fall outside the extent, nlmod gladly configures via flopy a well-package with stress-period-data of length 0. No problem so far. However when we write and run the simulation results in the following error:
Resources Software User Rights Notice for complete use, copyright,
and distribution information.
Run start date and time (yyyy/mm/dd hh:mm:ss): 2024/04/08 10:58:44
Writing simulation list file: mfsim.lst
Using Simulation name file: mfsim.nam
ERROR REPORT:
1. Required block "DIMENSIONS" not found. Found end of file instead.
UNIT ERROR REPORT:
1. Error occurred while reading file
'/workspaces/NHFLO/models/modelscripts/09pwnmodel2/model_ws/pwn_gwt.cnc'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/workspaces/nlmod/build/__editable__.nlmod-0.7.2-py3-none-any/nlmod/sim/sim.py", line 63, in write_and_run
assert sim.run_simulation(silent=silent)[0], "Modflow run not succeeded"
AssertionError: Modflow run not succeeded
The same error message comes from zero-length stress-period-data for the CNC package.
Desired behavior Zero-length stress-period-data does not result in the crashing of MF6.
Solution
- ~~Should we replace a zero-length stree-period-data with
Nonein all the package creation routines? Would that solve our problem?~~ (results incnc.stress_period_data.data is None) - Alternatively, if the length of the stress-period-data is zero, don't create the flopy package.
- Or, in the
nlmod.sim.write_and_run(sim, ds)function, remove packages from the simulation that have zero-length stress-period-data.
The error message given by mf6 is not so helpfull..
Currently, I have in my modelscripts the following code. It works, is not pretty and not intuitively implented by the end-user.
if cnc.stress_period_data.data is None:
gwt.remove_package(cnc.name[0])
Checking for zero length stress_period_data makes sense to me. The least we should do is log a warning, but I think it also makes sense to prevent the package from being added/created in that situation.
Thus using the example of the initiation of the CNC package:
cnc = nlmod.gwt.cnc(
ds,
gwt,
da_mask=(ds["northsea"] == 1).expand_dims({"layer": [ds.layer.data[0]]}),
da_conc=ds["chloride"].isel(layer=slice(0, 1)),
)
this code produce a zero-length stress_period_data because idomain, stored in ds, is false for all relevant cells.
Running this line of code should:
- Not raise an error
- Add a warning to the log that the package will not be added to the simulation because there is no stress_period_data
- Do not add the package to
gwt - Return
None