Skip to content

Commit

Permalink
refactor(Modpath7.create_mp7): expose porosity parameter of Modpath7B…
Browse files Browse the repository at this point in the history
…as (#2340)

This PR exposes the porosity parameter of Modpath7Bas in Modpath7's convenience method, create_mp7. This idea is raised in #2339.
  • Loading branch information
martclanor authored Oct 20, 2024
1 parent e85ecd2 commit 3a2c494
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
48 changes: 48 additions & 0 deletions autotest/test_mp7.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,54 @@ def test_mp7sim_replacement(function_tmpdir):
assert success, buff


@requires_exe("mf6", "mp7")
@pytest.mark.parametrize(
"porosity_type", ("constant", "list", "array_1d", "array")
)
@pytest.mark.slow
def test_mp7bas_porosity(ex01_mf6_model, porosity_type):
sim, function_tmpdir = ex01_mf6_model
sim.run_simulation()

mpnam = f"{ex01_mf6_model_name}_mp_forward"
gwf = sim.get_model(ex01_mf6_model_name)

if porosity_type == "constant":
porosity = 0.30
elif porosity_type == "list":
porosity = [0.35, 0.30, 0.25] # constant per layer
elif porosity_type == "array_1d":
porosity = np.array([0.35, 0.30, 0.25]) # constant per layer
elif porosity_type == "array":
# Initialize porosity array based on dim of dis.botm
# lay_1=0.35, lay_2=0.30, lay_3=0.25
porosity = np.array([[[0.35]], [[0.30]], [[0.25]]]) * np.ones(
(gwf.dis.botm.array.shape)
)
# Diversify porosity values, adjust both halves of the model
porosity[:, :, : porosity.shape[2] // 2] -= 0.05
porosity[:, :, porosity.shape[2] // 2 :] += 0.05

mp = Modpath7.create_mp7(
modelname=mpnam,
trackdir="forward",
flowmodel=gwf,
exe_name="mp7",
model_ws=function_tmpdir,
rowcelldivisions=1,
columncelldivisions=1,
layercelldivisions=1,
porosity=porosity,
)

# Check mean of assigned porosity
assert np.isclose(np.mean(mp.get_package("MPBAS").porosity.array), 0.3)

mp.write_input()
success, _ = mp.run_model()
assert success, f"mp7 model ({mp.name}) did not run"


@requires_exe("mf6", "mp7")
def test_flopy_2223(function_tmpdir):
mf6sim = Mp7Cases.mf6(function_tmpdir)
Expand Down
5 changes: 4 additions & 1 deletion flopy/modpath/mp7.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ def create_mp7(
rowcelldivisions=2,
layercelldivisions=2,
nodes=None,
porosity=0.30,
):
"""
Create a default MODPATH 7 model using a passed flowmodel with
Expand Down Expand Up @@ -447,6 +448,8 @@ def create_mp7(
direction (default is 2).
nodes : int, list of ints, tuple of ints, or np.ndarray
Nodes (zero-based) with particles. If (default is node 0).
porosity: float or array of floats (nlay, nrow, ncol)
The porosity array (the default is 0.30).
Returns
-------
Expand Down Expand Up @@ -477,7 +480,7 @@ def create_mp7(

# create MODPATH 7 basic file and add to the MODPATH 7
# model instance (mp)
Modpath7Bas(mp, defaultiface=defaultiface)
Modpath7Bas(mp, porosity=porosity, defaultiface=defaultiface)

# create particles
if nodes is None:
Expand Down

0 comments on commit 3a2c494

Please sign in to comment.