Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Separate input and out files in different directories #2462

Open
pya opened this issue Mar 2, 2025 · 4 comments
Open

feature: Separate input and out files in different directories #2462

pya opened this issue Mar 2, 2025 · 4 comments
Milestone

Comments

@pya
Copy link
Contributor

pya commented Mar 2, 2025

Is your feature request related to a problem? Please describe.

Models tend to get big with many input and output files. Therefore, distributing files in directories and sub-directories can be helpful to organize a project. All examples I found so far use a flat directory structure, i.e. all input and output files are in one directory.

This is my attempt to separate input and output files.

This is the directory structure after running mf6:

├── input
│   ├── rivercond.chd
│   ├── rivercond.dis
│   ├── rivercond.dis.grb
│   ├── rivercond.ic
│   ├── rivercond.ims
│   ├── rivercond.nam
│   ├── rivercond.npf
│   ├── rivercond.oc
│   ├── rivercond.riv
│   └── rivercond.tdis
├── mfsim.lst
├── mfsim.nam
└── output
    ├── rivercond.cbc
    └── rivercond.hds

The content of mfsim.nam:

BEGIN options
  MEMORY_PRINT_OPTION  all
END options

BEGIN timing
  TDIS6  input/rivercond.tdis
END timing

BEGIN models
  gwf6  input/rivercond.nam  rivercond
END models

BEGIN exchanges
END exchanges

BEGIN solutiongroup  1
  ims6  input/rivercond.ims  rivercond
END solutiongroup  1             

rivercond.oc:

BEGIN options
  BUDGET  FILEOUT  output/rivercond.cbc
  HEAD  FILEOUT  output/rivercond.hds
END options

BEGIN period  1
  SAVE  head  all
  SAVE  budget  all
  PRINT  budget  all
END period  1                  

rivercond.nam:

BEGIN options
  PRINT_INPUT
  SAVE_FLOWS
END options

BEGIN packages
  DIS6  input/rivercond.dis  dis
  NPF6  input/rivercond.npf  npf
  IC6  input/rivercond.ic  ic
  RIV6  input/rivercond.riv  river
  CHD6  input/rivercond.chd  chd_0
  OC6  input/rivercond.oc  oc
END packages

This works. I guess this could be extend into a deeper structure that would allow to use the same input files for multiple models. For example, these models could share files for the model geometry and use specific files for some boundary conditions that are different for each model (variant).

Looking at the source of flopy, it seems that it always assumes a flat structure (i.e. all files in one directory) for model post processing such as plotting. I this correct?

Describe the solution you'd like

A flexible directory structure, that allows to distribute input and output files to specified directories would help to organize large models and scenario runs that modify only small parts of the input. Maybe this already possible but I don't know how to do it.

Describe alternatives you've considered

See problem description above.

Additional context

Test runs done with MF 6.6.

@pya pya added the enhancement label Mar 2, 2025
@wpbonelli wpbonelli added this to the 4.0 milestone Mar 2, 2025
@mwtoews
Copy link
Contributor

mwtoews commented Mar 2, 2025

Further to this idea is to use consistent filenames regardless of model name. For instance, a model with a groundwater-flow simulation could look like this:

Part of mfsim.nam:

BEGIN models
  gwf6  input/gwf.nam  rivercond
END models

Part of input/gwf.nam:

BEGIN packages
  DIS6  input/gwf.dis  dis
  NPF6  input/gwf.npf  npf
  IC6   input/gwf.ic   ic
  RIV6  input/gwf.riv  river
  CHD6  input/gwf.chd  chd_0
  OC6   input/gwf.oc   oc
END packages

and if there were a groundwater-transport component, the gwt.nam, gwt.dis, etc. files would be in the input directory.

However, there are many exceptions where there is more than one package per model (e.g. two WEL packages wells1.wel and wells2.wel), or nested groundwater-flow models (e.g. parent.nam and child.nam). So this simple approach is sometime too simple to use broadly.


One side observation is that input/rivercond.dis.grb is an output file that can only be suppressed with NOGRB. I'm not sure how to convince mf6 to output it separately.

@pya
Copy link
Contributor Author

pya commented Mar 3, 2025

Thanks for your suggestion. I tend to use the naming pattern gwf_modelname_suffix.*´, gwt_modelname_suffix.*, gwe_modelname_suffix.*´ etc. modelname is also the name of the base directory. Once parameterized with flopy, this should have the same benefits as using the same name stems for all model files across models. I realized that the *.dis.rgb file appears in the input directory. My approach would be a post-run cleanup step, moving to output. But flopy doesn't know this and would not find this file. :(

@christianlangevin
Copy link

Just an FYI that it is possible now to organize individual models of a simulation into folders, and do this with flopy. There is an example of this for two flow models and two transport models located here. The example makes use of the flopy model method set_model_relative_path(). The result of that test is to create a folder structure like the following:

Image

In this case, the mfsim.nam file has relative paths to the individual model name files:

# File generated by Flopy version 3.10.0.dev1 on 03/03/2025 at 09:31:21.
BEGIN options
END options

BEGIN timing
  TDIS6  test_mf6model_0-adv01a_gwtgwt_0.tdis
END timing

BEGIN models
  gwf6  flow1/flow1.nam  flow1
  gwf6  flow2/flow2.nam  flow2
  gwt6  transport1/transport1.nam  transport1
  gwt6  transport2/transport2.nam  transport2
END models

BEGIN exchanges
  GWF6-GWF6  flow1_flow2.gwfgwf  flow1  flow2
  GWT6-GWT6  transport1_transport2.gwtgwt  transport1  transport2
  GWF6-GWT6  flow1_transport1.gwfgwt  flow1  transport1
  GWF6-GWT6  flow2_transport2.gwfgwt  flow2  transport2
END exchanges

BEGIN solutiongroup  1
  ims6  flow.ims  flow1  flow2
  ims6  transport.ims  transport1  transport2
END solutiongroup  1

One thing to keep in mind here is that all file names should be specified relative to the directory where mf6 was run. So this results in a model name file that looks like:

# File generated by Flopy version 3.10.0.dev1 on 03/03/2025 at 09:31:21.
BEGIN options
  SAVE_FLOWS
END options

BEGIN packages
  DIS6  flow1/flow1.dis  dis
  IC6  flow1/flow1.ic  ic
  NPF6  flow1/flow1.npf  npf
  WEL6  flow1/flow1.wel  wel-1
  OC6  flow1/flow1.oc  oc
END packages

I like @mwtoews idea to have a simple and straightforward way to have all files named and organized in an intuitive manner. I also can see benefit to organizing input and output into separate folders as suggested by @pya. File management has been tricky and error prone with flopy in the past. I think there may be some things we could do on the MODFLOW side to help with some of this, perhaps along the line of MODFLOW issue #157.

wpbonelli added a commit to MODFLOW-ORG/modflow6 that referenced this issue Mar 4, 2025
Add option to all discretization packages to configure the grb output file path, usage GRB6 OUTFILE <filepath>. Motivated by modflowpy/flopy#2462.
@pya
Copy link
Contributor Author

pya commented Mar 4, 2025

@christianlangevin Thanks for your comment. I was not aware of set_model_relative_path(). This seems the way to go. Much better than writing your own pre- and post-file-moving tools.

@wpbonelli wpbonelli marked this as a duplicate of #2156 Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants