Skip to content

Commit

Permalink
fix(modelgrid): fix missing coord info if disv (#2284)
Browse files Browse the repository at this point in the history
Closes #2283

---------

Co-authored-by: wpbonelli <[email protected]>
  • Loading branch information
martclanor and wpbonelli authored Aug 7, 2024
1 parent 4321b0b commit b64f2bd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
52 changes: 52 additions & 0 deletions autotest/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -2420,3 +2420,55 @@ def test_remove_model(function_tmpdir, example_data_path):
elif exg_index > 0:
assert "end exchanges" in l
break


def test_flopy_2283(function_tmpdir):
# create triangular grid
triangle_ws = function_tmpdir / "triangle"
triangle_ws.mkdir()

active_area = [(0, 0), (0, 1000), (1000, 1000), (1000, 0)]
tri = Triangle(model_ws=triangle_ws, angle=30)
tri.add_polygon(active_area)
tri.add_region((1, 1), maximum_area=50**2)

tri.build()

# build vertex grid object
vgrid = flopy.discretization.VertexGrid(
vertices=tri.get_vertices(),
cell2d=tri.get_cell2d(),
xoff=199000,
yoff=215500,
crs=31370,
angrot=30,
)

# coord info is set (also correct when using vgrid.set_coord_info()
print(vgrid)

# create MODFLOW 6 model
ws = function_tmpdir / "model"
ws.mkdir()
sim = flopy.mf6.MFSimulation(sim_name="prj-test", sim_ws=ws)
tdis = flopy.mf6.ModflowTdis(sim)
ims = flopy.mf6.ModflowIms(sim)

gwf = flopy.mf6.ModflowGwf(sim, modelname="gwf")
disv = flopy.mf6.ModflowGwfdisv(
gwf,
xorigin=vgrid.xoffset,
yorigin=vgrid.yoffset,
angrot=vgrid.angrot, # no CRS info can be set in DISV
nlay=1,
top=0.0,
botm=-10.0,
ncpl=vgrid.ncpl,
nvert=vgrid.nvert,
cell2d=vgrid.cell2d,
vertices=tri.get_vertices(), # this is not stored in the Vertex grid object?
)

assert gwf.modelgrid.xoffset == disv.xorigin.get_data()
assert gwf.modelgrid.yoffset == disv.yorigin.get_data()
assert gwf.modelgrid.angrot == disv.angrot.get_data()
13 changes: 4 additions & 9 deletions flopy/mf6/mfmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,15 +572,10 @@ def modelgrid(self):
else:
return self._modelgrid

if self.get_grid_type() != DiscretizationType.DISV:
# get coordinate data from dis file
xorig = dis.xorigin.get_data()
yorig = dis.yorigin.get_data()
angrot = dis.angrot.get_data()
else:
xorig = self._modelgrid.xoffset
yorig = self._modelgrid.yoffset
angrot = self._modelgrid.angrot
# get coordinate data from dis file
xorig = dis.xorigin.get_data()
yorig = dis.yorigin.get_data()
angrot = dis.angrot.get_data()

# resolve offsets
if xorig is None:
Expand Down

0 comments on commit b64f2bd

Please sign in to comment.