modflowpy / flopy

A Python package to create, run, and post-process MODFLOW-based models.
https://flopy.readthedocs.io
Other
522 stars 314 forks source link

feature: Pass model to Iterative Model solver #2355

Open mbakker7 opened 2 weeks ago

mbakker7 commented 2 weeks ago

Problem description In simulations with multiple models (e.g, a flow model and a transport model), separate iterative model solvers need to be created and then registered. This registration step is confusing, as it is not what has to be done with just one model (e.g., only a flow model). For more discussion see https://github.com/modflowpy/flopy/discussions/2354

Describe the solution you'd like Add a model keyword argument to ModflowIms to pass one model. Registration is done automatically. For example, the current code would be (sim is simulation instance and gwf is groundwater flow model instance)

# iterative model solver
gwf_ims  = fp.mf6.ModflowIms(simulation=sim, # add to simulation called sim
                             filename=gwf.name + '.ims', # file name to store ims
                             complexity='SIMPLE',
                            )                                                                                                
# register solver
sim.register_ims_package(solution_file=gwf_ims, # name of iterative model solver instance
                         model_list=[gwf.name], # list with name of groundwater flow model
                        )  

In the new implementation, this would be something like this (the filename and registration is taken care of by flopy in the ModflowIms code):

# iterative model solver
gwf_ims  = fp.mf6.ModflowIms(simulation=sim, # add to simulation called sim
                             model=gwf, # iterative solver for gwf model
                             complexity='SIMPLE',
                            )                                                                                                 

Alternatives It may even be considered whether both the simulation and the groundwater flow model need to be passed. To stay in line with all the other classes, simply adding it to the gwf should be enough, so that the code becomes even simpler. This is actually my preferred solution:

# iterative model solver
gwf_ims  = fp.mf6.ModflowIms(model=gwf, # iterative solver for gwf model
                             complexity='SIMPLE',
                            )                                                                                                 

Backwards compatibility should not be a problem, as the model keyword would be new.

langevin-usgs commented 2 weeks ago

Thanks, @mbakker7. We will keep this in mind for ongoing work to refactor the mf6 support in flopy.