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

Fix(_mg_resync): Added checks to reset the modelgrid resync #1258

Merged
merged 2 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions autotest/t007_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,11 @@ def test_sr():
if mm.modelgrid.proj4 != "test test test":
raise AssertionError()

mm.dis.top = 5000

if not np.allclose(mm.dis.top.array, mm.modelgrid.top):
raise AssertionError("modelgrid failed dynamic update test")


def test_dis_sr():

Expand Down Expand Up @@ -683,6 +688,42 @@ def test_dis_sr():
np.testing.assert_almost_equal(y, yul)


def test_mf6_modelgrid_update():
base_dir = os.path.join("..", "examples", "data", "mf6")
# dis
model_ws = os.path.join(base_dir, "test001a_Tharmonic")
sim = flopy.mf6.MFSimulation.load(sim_ws=model_ws)
gwf = sim.get_model("flow15")

mg = gwf.modelgrid
gwf.dis.top = 12

if not np.allclose(gwf.dis.top.array, gwf.modelgrid.top):
raise AssertionError("StructuredGrid failed dynamic update test")

# disv
model_ws = os.path.join(base_dir, "test003_gwfs_disv")
sim = flopy.mf6.MFSimulation.load(sim_ws=model_ws)
gwf = sim.get_model("gwf_1")

mg = gwf.modelgrid
gwf.disv.top = 6.12

if not np.allclose(gwf.disv.top.array, gwf.modelgrid.top):
raise AssertionError("VertexGrid failed dynamic update test")

# disu
model_ws = os.path.join(base_dir, "test006_gwf3")
sim = flopy.mf6.MFSimulation.load(sim_ws=model_ws)
gwf = sim.get_model("gwf_1")

mg = gwf.modelgrid
gwf.disu.top = 101

if not np.allclose(gwf.disu.top.array, gwf.modelgrid.top):
raise AssertionError("UnstructuredGrid failed dynamic update test")


def test_twri_mg():
name = "twri.nam"
ml = flopy.modflow.Modflow.load(name, model_ws=pth, check=False)
Expand Down Expand Up @@ -1666,6 +1707,7 @@ def main():
# test_tricontour_NaN()
# test_export_contourf()
test_sr()
# test_mf6_modelgrid_update()
# test_shapefile_polygon_closed()
# test_mapview_plot_bc()
# test_crosssection_plot_bc()
Expand Down
8 changes: 8 additions & 0 deletions flopy/mf6/mfpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,14 @@ def __setattr__(self, name, value):
package=self._get_pname(),
)
return

if all(
hasattr(self, attr) for attr in ["model_or_sim", "_package_type"]
):
if hasattr(self.model_or_sim, "_mg_resync"):
if not self.model_or_sim._mg_resync:
self.model_or_sim._mg_resync = self._mg_resync

super().__setattr__(name, value)

def __repr__(self):
Expand Down
10 changes: 10 additions & 0 deletions flopy/pakbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def plottable(self):
def has_stress_period_data(self):
return self.__dict__.get("stress_period_data", None) is not None

@property
def _mg_resync(self):
if self.package_type.lower()[:4] in ("dis", "bas"):
return True
return False

@staticmethod
def _check_thresholds(chk, array, active, thresholds, name):
"""Checks array against min and max threshold values."""
Expand Down Expand Up @@ -605,6 +611,10 @@ def __setattr__(self, key, value):
)
value = new_list

if all(hasattr(self, attr) for attr in ["parent", "_name"]):
if not self.parent._mg_resync:
self.parent._mg_resync = self._mg_resync

super().__setattr__(key, value)

@property
Expand Down