Open giovannifi opened 2 years ago
@giovannifi, it is my understanding that a simulation with a gwf model requires a solver package (ims). That said, when I run your code flopy generates an error in step 4 (write_simulation) because the tdis package is missing. For the above code to generate a model runnable by MODFLOW-6, a tdis, ic, npf, and ims package must be added. Flopy was not designed to save/load incomplete or invalid MODFLOW-6 simulations.
If you are intentionally trying to write/load an incomplete simulation, please let me know why you would like flopy to support writing/loading incomplete simulations. My current opinion is that allowing flopy to load/save incomplete simulations is not a common use case, and allowing this complicates the testing and coding of new flopy features. However, I do think that when write_simulation is called flopy should look for an ims and tdis file, and if either are not present it should produce a human readable error stating that the required file(s) are missing. Checking for the required ims/tdis files during write_simulation should be fairly easy to implement.
@spaulins-usgs you are correct I forgot to mention that I had to create also tdis before being able to write the packages. Yes I am trying to build an incomplete simulation. The reason is very simple: in 90% of the cases, models are not built in one go and are not built by only one person. In this particular case I was involved in the development of the model grid, then I had to pass the results to a my colleague to continue with the rest of the model building. The horizontal grid was built with a third party software and I developed a script to covert the output of the third party software into a disv package. I remember that for the old versions of modflow it was possible to load directly the individual packages once a "dummy" simulation was created. I was not able to find the same method and I was forced to re-create a pseudo complete simulation (including at least the tdis and ims packages) to be able to transfer my results to my colleague. In my report I simply asked if this is the expected behavior or not. I was not sure if this was a bug or not. In any case I had to figure it out (the inclusion of tdis and ims packages) by trial and error approach as the error message I received was not very clear and the software did not alert me that the ims package has to be declared before writing the packages. In my opinion an alert should be produced by the writing module to alert the user that the simulation is not complete and it will not be possible to load it subsequently. I would say that this should be the expected behavior.
I switched this from a bug to enhancement. As @spaulins-usgs said flopy can't currently do this for MF6 simulations, and it is out of scope for the current major version as the effort to refactor would be significant.
This seems like a common use case however and we are aiming to support load/write for standalone packages in the next major version. Thanks @giovannifi for the suggestion, feedback like this is helpful as we prototype.
Describe the bug I created the grid of a model using flopy and saved it as a disv package (my model is vertically structured). Then I wrote the packages (the disv package only). I tried to re-load the model and I got the following error:
loading simulation... loading simulation name file... loading tdis package... loading model gwf6... loading package disv... WARNING: Unable to resolve dimension of ('gwf6', 'disv', 'cell2d', 'cell2d', 'icvert') based on shape "ncvert". Traceback (most recent call last): File "H:\scripts\Intera_scripts\test_load_mf.py", line 9, in <module> sim = flopy.mf6.MFSimulation.load(sim_name=name, exe_name=path_exe, sim_ws=workspace, version="mf6", File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\modflow\mfsimulation.py", line 839, in load for solution_group in solution_group_dict.values(): AttributeError: 'NoneType' object has no attribute 'values'
I have then went back to the script that created the original package and this time I also created the "ims" package. When I tried to load the model, this time everything went OK. I wonder if this is the expected behaviour of the code.
To Reproduce Steps to reproduce the behavior:
sim = flopy.mf6.MFSimulation(sim_name=mf_name, exe_name=exe_name, version="mf6", sim_ws=workspace)
gwf = flopy.mf6.ModflowGwf(sim, modelname=mf_name, save_flows=True, newtonoptions='UNDER_RELAXATION')
disv = flopy.mf6.ModflowGwfdisv(gwf, length_units='METERS', nlay=nlays, ncpl=ncpl, nvert=nvert, top=top, botm=bots, vertices=vertices, cell2d=cell2d)
sim.write_simulation()
sim = flopy.mf6.MFSimulation.load(sim_name=name, exe_name=path_exe, sim_ws=workspace, version="mf6", load_only=['disv'])
loading simulation... loading simulation name file... loading tdis package... loading model gwf6... loading package disv... WARNING: Unable to resolve dimension of ('gwf6', 'disv', 'cell2d', 'cell2d', 'icvert') based on shape "ncvert". Traceback (most recent call last): File "H:\scripts\Intera_scripts\test_load_mf.py", line 9, in <module> sim = flopy.mf6.MFSimulation.load(sim_name=name, exe_name=path_exe, sim_ws=workspace, version="mf6", File "C:\Program Files\Python39\lib\site-packages\flopy\mf6\modflow\mfsimulation.py", line 839, in load for solution_group in solution_group_dict.values(): AttributeError: 'NoneType' object has no attribute 'values'
Expected behavior I would expect no errors. As I said before if I create the IMS package and then load the model everything works fine.
Desktop (please complete the following information):