Repository navigation
Origin and rotation info is lost when creating a DISV grid from GRIDGEN following the examples #2850
|
I believe this may be intended behavior, but it is not easy to identify from the current GRIDGEN example (https://flopy.readthedocs.io/en/latest/Notebooks/gridgen_example.html). A related coordinate-transformation issue was previously discussed in #1474.
get_gridprops_disv() returns: I understand that the coordinates returned in vertices and cell2d therefore are already expressed in the transformed, real-world coordinate system. It does not return xorigin, yorigin, or angrot. Consequently, when the returned dictionary is passed directly to ModflowGwfdisv, those three DISV options retain their default values of zero. The resulting DISV grid is spatially located correctly, but origin and rotation metadata are lost to the DISV package and are therefore written as zero values to the MODFLOW 6 binary grid file. I also understand that passing the original transformation directly to the DISV constructor would result in an incorrect grid, because FloPy applies the transformation to coordinates that have already been transformed by GRIDGEN, so the in-memory VertexGrid is shifted and/or rotated a second time. The apparent workaround is to inverse-transform the info in disv_gridprops back to local coordinates before constructing the DISV package plus passing xorigin, yorigin, and angrot when calling the constructor. Proposals:
|
Replies: 1 comment
|
That's right: in 3.11.0, import numpy as np
import flopy
mg = g.modelgrid # the structured base grid passed to Gridgen
props = g.get_gridprops_disv()
vx, vy = mg.get_local_coords(
np.array([v[1] for v in props["vertices"]]),
np.array([v[2] for v in props["vertices"]]),
)
props["vertices"] = [[v[0], x, y] for v, x, y in zip(props["vertices"], vx, vy)]
cx, cy = mg.get_local_coords(
np.array([c[1] for c in props["cell2d"]]),
np.array([c[2] for c in props["cell2d"]]),
)
props["cell2d"] = [[c[0], x, y, *c[3:]] for c, x, y in zip(props["cell2d"], cx, cy)]
disv = flopy.mf6.ModflowGwfdisv(
gwf, **props,
xorigin=mg.xoffset, yorigin=mg.yoffset, angrot=mg.angrot,
)
An opt-in flag on |
That's right: in 3.11.0,
get_gridprops_disv()has no option to return local coordinates or the transform, and there's no dedicated helper for it. The base grid you passed toGridgenalready has the inverse transform, though, so the workaround is short: