Deltares / imod-python

🐍🧰 Make massive MODFLOW models
https://deltares.github.io/imod-python/
MIT License
19 stars 3 forks source link

Add converter for iMOD5 Discretization package #964

Closed JoerivanEngelen closed 6 months ago

JoerivanEngelen commented 6 months ago

If architecture as described in #961 is agreed on, we can create a converter for the DIS package. For the Structured Discretization, the target grid is the smallest grid in the package. Therefore the method from_imod5_package needs to be overloaded:

class StructuredDiscretization:
...
    @classmethod
    def from_imod5_package(cls, **data):
        # Find smallest grid in data to regrid to
        target = find_smallest_grid(data)
        # Regrid to one consistent dataset
        dataset = cls._regrid_like(target, **data)

        # Add logic to prepare the dataset in the following way here:
        # IBOUND -1  -> IDOMAIN = 1
        # IBOUND -1 cells will be converted to CHD cells
        dataset["idomain"] = dataset["idomain"].where(dataset["idomain"] > 0, 0)
        # Thickness <= 0 -> IDOMAIN = -1
        thickness = dataset["top"] - dataset["bottom"]
        dataset["idomain"] = dataset["idomain"].where(thickness > 0, -1)
        # TOP 3D -> TOP 2D
        dataset["top"] = dataset["top"].sel(layer=1, drop=True)

        return cls(**dataset)
JoerivanEngelen commented 6 months ago

Merged into feature branch: https://github.com/Deltares/imod-python/tree/imod5_converter_feature_branch