Skip to content

Structure .ini files

Structure .ini files contain the definition of hydraulic structures for a D-Flow FM model.

Generic parsing and serializing functionality comes from the generic hydrolib.core.dflowfm.ini modules.

A structures.ini file is described by the classes below.

Models

structure namespace for storing the contents of an FMModel's structure file.

Bridge

Bases: Structure

Hydraulic structure with type=bridge, to be included in a structure file. Typically inside the structure list of a FMModel.geometry.structurefile[0].structure[..]

All lowercased attributes match with the bridge input as described in UM Sec.C.12.5.

Source code in hydrolib/core/dflowfm/structure/models.py
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
class Bridge(Structure):
    """
    Hydraulic structure with `type=bridge`, to be included in a structure file.
    Typically inside the structure list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.structurefile[0].structure[..]`

    All lowercased attributes match with the bridge input as described in
    [UM Sec.C.12.5](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.C.12.5).
    """

    class Comments(Structure.Comments):
        type: Optional[str] = Field("Structure type; must read bridge", alias="type")
        allowedflowdir: Optional[str] = Field(
            FlowDirection.allowedvaluestext, alias="allowedFlowdir"
        )

        csdefid: Optional[str] = Field(
            "Id of Cross-Section Definition.", alias="csDefId"
        )
        shift: Optional[str] = Field(
            "Vertical shift of the cross section definition [m]. Defined positive upwards."
        )
        inletlosscoeff: Optional[str] = Field(
            "Inlet loss coefficient [-], ξ_i.",
            alias="inletLossCoeff",
        )
        outletlosscoeff: Optional[str] = Field(
            "Outlet loss coefficient [-], k.",
            alias="outletLossCoeff",
        )
        frictiontype: Optional[str] = Field(
            "Friction type, possible values are: Chezy, Manning, wallLawNikuradse, WhiteColebrook, StricklerNikuradse, Strickler, deBosBijkerk.",
            alias="frictionType",
        )
        friction: Optional[str] = Field(
            "Friction value, used in friction loss.",
            alias="friction",
        )
        length: Optional[str] = Field("Length [m], L.")

    comments: Comments = Comments()

    type: Literal["bridge"] = Field("bridge", alias="type")
    allowedflowdir: FlowDirection = Field(alias="allowedFlowdir")

    csdefid: str = Field(alias="csDefId")
    shift: float
    inletlosscoeff: float = Field(alias="inletLossCoeff")
    outletlosscoeff: float = Field(alias="outletLossCoeff")
    frictiontype: FrictionType = Field(alias="frictionType")
    friction: float
    length: float

    _frictiontype_validator = get_enum_validator("frictiontype", enum=FrictionType)

Compound

Bases: Structure

Hydraulic structure with type=compound, to be included in a structure file. Typically inside the structure list of a FMModel.geometry.structurefile[0].structure[..]

All lowercased attributes match with the compound input as described in UM Sec.C.12.11.

Source code in hydrolib/core/dflowfm/structure/models.py
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
class Compound(Structure):
    """
    Hydraulic structure with `type=compound`, to be included in a structure file.
    Typically inside the structure list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.structurefile[0].structure[..]`

    All lowercased attributes match with the compound input as described in
    [UM Sec.C.12.11](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.C.12.11).
    """

    type: Literal["compound"] = Field("compound", alias="type")
    numstructures: int = Field(alias="numStructures")
    structureids: List[str] = Field(alias="structureIds", delimiter=";")

    _split_to_list = get_split_string_on_delimiter_validator(
        "structureids",
    )

Culvert

Bases: Structure

Hydraulic structure with type=culvert, to be included in a structure file. Typically inside the structure list of a FMModel.geometry.structurefile[0].structure[..]

All lowercased attributes match with the culvert input as described in UM Sec.C.12.3.

Source code in hydrolib/core/dflowfm/structure/models.py
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
class Culvert(Structure):
    """
    Hydraulic structure with `type=culvert`, to be included in a structure file.
    Typically inside the structure list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.structurefile[0].structure[..]`

    All lowercased attributes match with the culvert input as described in
    [UM Sec.C.12.3](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.C.12.3).
    """

    type: Literal["culvert"] = Field("culvert", alias="type")
    allowedflowdir: FlowDirection = Field(alias="allowedFlowDir")

    leftlevel: float = Field(alias="leftLevel")
    rightlevel: float = Field(alias="rightLevel")
    csdefid: str = Field(alias="csDefId")
    length: float = Field(alias="length")
    inletlosscoeff: float = Field(alias="inletLossCoeff")
    outletlosscoeff: float = Field(alias="outletLossCoeff")
    valveonoff: bool = Field(alias="valveOnOff")
    valveopeningheight: Optional[ForcingData] = Field(alias="valveOpeningHeight")
    numlosscoeff: Optional[int] = Field(alias="numLossCoeff")
    relopening: Optional[List[float]] = Field(alias="relOpening")
    losscoeff: Optional[List[float]] = Field(alias="lossCoeff")
    bedfrictiontype: Optional[FrictionType] = Field(alias="bedFrictionType")
    bedfriction: Optional[float] = Field(alias="bedFriction")
    subtype: Optional[CulvertSubType] = Field(
        CulvertSubType.culvert.value, alias="subType"
    )
    bendlosscoeff: Optional[float] = Field(alias="bendLossCoeff")

    _split_to_list = get_split_string_on_delimiter_validator("relopening", "losscoeff")
    _flowdirection_validator = get_enum_validator("allowedflowdir", enum=FlowDirection)
    _subtype_validator = get_enum_validator("subtype", enum=CulvertSubType)
    _frictiontype_validator = get_enum_validator("bedfrictiontype", enum=FrictionType)

    @root_validator(allow_reuse=True)
    def validate_that_valve_related_fields_are_present_for_culverts_with_valves(
        cls, values: Dict
    ) -> Dict:
        """Validates that valve-related fields are present when there is a valve present."""
        return validate_required_fields(
            values,
            "valveopeningheight",
            "numlosscoeff",
            "relopening",
            "losscoeff",
            conditional_field_name="valveonoff",
            conditional_value=True,
        )

    @root_validator(allow_reuse=True)
    def validate_that_bendlosscoeff_field_is_present_for_invertedsyphons(
        cls, values: Dict
    ) -> Dict:
        """Validates that the bendlosscoeff value is present when dealing with inverted syphons."""
        return validate_required_fields(
            values,
            "bendlosscoeff",
            conditional_field_name="subtype",
            conditional_value=CulvertSubType.invertedSiphon,
        )

    @root_validator(allow_reuse=True)
    def check_list_lengths(cls, values):
        """Validates that the length of the relopening and losscoeff fields are as expected."""
        return validate_correct_length(
            values,
            "relopening",
            "losscoeff",
            length_name="numlosscoeff",
            list_required_with_length=True,
        )

    @root_validator(allow_reuse=True)
    def validate_that_bendlosscoeff_is_not_provided_for_culverts(
        cls, values: Dict
    ) -> Dict:
        """Validates that the bendlosscoeff field is not provided when the subtype is a culvert."""
        return validate_forbidden_fields(
            values,
            "bendlosscoeff",
            conditional_field_name="subtype",
            conditional_value=CulvertSubType.culvert,
        )

check_list_lengths(values)

Validates that the length of the relopening and losscoeff fields are as expected.

Source code in hydrolib/core/dflowfm/structure/models.py
472
473
474
475
476
477
478
479
480
481
@root_validator(allow_reuse=True)
def check_list_lengths(cls, values):
    """Validates that the length of the relopening and losscoeff fields are as expected."""
    return validate_correct_length(
        values,
        "relopening",
        "losscoeff",
        length_name="numlosscoeff",
        list_required_with_length=True,
    )

validate_that_bendlosscoeff_field_is_present_for_invertedsyphons(values)

Validates that the bendlosscoeff value is present when dealing with inverted syphons.

Source code in hydrolib/core/dflowfm/structure/models.py
460
461
462
463
464
465
466
467
468
469
470
@root_validator(allow_reuse=True)
def validate_that_bendlosscoeff_field_is_present_for_invertedsyphons(
    cls, values: Dict
) -> Dict:
    """Validates that the bendlosscoeff value is present when dealing with inverted syphons."""
    return validate_required_fields(
        values,
        "bendlosscoeff",
        conditional_field_name="subtype",
        conditional_value=CulvertSubType.invertedSiphon,
    )

validate_that_bendlosscoeff_is_not_provided_for_culverts(values)

Validates that the bendlosscoeff field is not provided when the subtype is a culvert.

Source code in hydrolib/core/dflowfm/structure/models.py
483
484
485
486
487
488
489
490
491
492
493
@root_validator(allow_reuse=True)
def validate_that_bendlosscoeff_is_not_provided_for_culverts(
    cls, values: Dict
) -> Dict:
    """Validates that the bendlosscoeff field is not provided when the subtype is a culvert."""
    return validate_forbidden_fields(
        values,
        "bendlosscoeff",
        conditional_field_name="subtype",
        conditional_value=CulvertSubType.culvert,
    )

Validates that valve-related fields are present when there is a valve present.

Source code in hydrolib/core/dflowfm/structure/models.py
445
446
447
448
449
450
451
452
453
454
455
456
457
458
@root_validator(allow_reuse=True)
def validate_that_valve_related_fields_are_present_for_culverts_with_valves(
    cls, values: Dict
) -> Dict:
    """Validates that valve-related fields are present when there is a valve present."""
    return validate_required_fields(
        values,
        "valveopeningheight",
        "numlosscoeff",
        "relopening",
        "losscoeff",
        conditional_field_name="valveonoff",
        conditional_value=True,
    )

CulvertSubType

Bases: StrEnum

Enum class to store a Culvert's subType.

Source code in hydrolib/core/dflowfm/structure/models.py
403
404
405
406
407
class CulvertSubType(StrEnum):
    """Enum class to store a [Culvert][hydrolib.core.dflowfm.structure.models.Culvert]'s subType."""

    culvert = "culvert"
    invertedSiphon = "invertedSiphon"

Dambreak

Bases: Structure

Hydraulic structure with type=dambreak, to be included in a structure file. Typically inside the structure list of a FMModel.geometry.structurefile[0].structure[..]

All lowercased attributes match with the dambreak input as described in UM Sec.C.12.10.

Source code in hydrolib/core/dflowfm/structure/models.py
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
class Dambreak(Structure):
    """
    Hydraulic structure with `type=dambreak`, to be included in a structure file.
    Typically inside the structure list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.structurefile[0].structure[..]`

    All lowercased attributes match with the dambreak input as described in
    [UM Sec.C.12.10](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.C.12.10).
    """

    class Comments(Structure.Comments):
        type: Optional[str] = Field("Structure type; must read dambreak", alias="type")
        startlocationx: Optional[str] = Field(
            "x-coordinate of breach starting point.", alias="startLocationX"
        )
        startlocationy: Optional[str] = Field(
            "y-coordinate of breach starting point.", alias="startLocationY"
        )
        algorithm: Optional[str] = Field(
            "Breach growth algorithm. Possible values are: 1 (van der Knaap (2000)), 2 (Verheij–van der Knaap (2002)), 3: Predefined time series, see dambreakLevelsAndWidths",
            alias="algorithm",
        )
        crestlevelini: Optional[str] = Field(
            "Initial breach level zcrest level [m AD].", alias="crestLevelIni"
        )
        breachwidthini: Optional[str] = Field(
            "Initial breach width B0 [m].", alias="breachWidthIni"
        )
        crestlevelmin: Optional[str] = Field(
            "Minimal breach level zmin [m AD].", alias="crestLevelMin"
        )
        t0: Optional[str] = Field("Breach start time Tstart [s].", alias="t0")
        timetobreachtomaximumdepth: Optional[str] = Field(
            "tPhase 1 [s].", alias="timeToBreachToMaximumDepth"
        )
        f1: Optional[str] = Field("Factor f1 [-]", alias="f1")
        f2: Optional[str] = Field("Factor f2 [-]", alias="f2")
        ucrit: Optional[str] = Field(
            "Critical flow velocity uc for erosion [m/s].", alias="uCrit"
        )
        waterlevelupstreamlocationx: Optional[str] = Field(
            "(optional) x-coordinate of custom upstream water level point.",
            alias="waterLevelUpstreamLocationX",
        )
        waterlevelupstreamlocationy: Optional[str] = Field(
            "(optional) y-coordinate of custom upstream water level point.",
            alias="waterLevelUpstreamLocationY",
        )
        waterleveldownstreamlocationx: Optional[str] = Field(
            "(optional) x-coordinate of custom downstream water level point.",
            alias="waterLevelDownstreamLocationX",
        )
        waterleveldownstreamlocationy: Optional[str] = Field(
            "(optional) y-coordinate of custom downstream water level point.",
            alias="waterLevelDownstreamLocationY",
        )
        waterlevelupstreamnodeid: Optional[str] = Field(
            "(optional) Node Id of custom upstream water level point.",
            alias="waterLevelUpstreamNodeId",
        )
        waterleveldownstreamnodeid: Optional[str] = Field(
            "(optional) Node Id of custom downstream water level point.",
            alias="waterLevelDownstreamNodeId",
        )
        dambreaklevelsandwidths: Optional[str] = Field(
            "(only when algorithm=3) Filename of <*.tim> file (Section C.4) containing the breach levels and widths.",
            alias="dambreakLevelsAndWidths",
        )

    comments: Comments = Comments()
    type: Literal["dambreak"] = Field("dambreak", alias="type")
    startlocationx: float = Field(alias="startLocationX")
    startlocationy: float = Field(alias="startLocationY")
    algorithm: DambreakAlgorithm = Field(alias="algorithm")

    crestlevelini: float = Field(alias="crestLevelIni")
    breachwidthini: float = Field(alias="breachWidthIni")
    crestlevelmin: float = Field(alias="crestLevelMin")
    t0: float = Field(alias="t0")
    timetobreachtomaximumdepth: float = Field(alias="timeToBreachToMaximumDepth")
    f1: float = Field(alias="f1")
    f2: float = Field(alias="f2")
    ucrit: float = Field(alias="uCrit")
    waterlevelupstreamlocationx: Optional[float] = Field(
        alias="waterLevelUpstreamLocationX"
    )
    waterlevelupstreamlocationy: Optional[float] = Field(
        alias="waterLevelUpstreamLocationY"
    )
    waterleveldownstreamlocationx: Optional[float] = Field(
        alias="waterLevelDownstreamLocationX"
    )
    waterleveldownstreamlocationy: Optional[float] = Field(
        alias="waterLevelDownstreamLocationY"
    )
    waterlevelupstreamnodeid: Optional[str] = Field(alias="waterLevelUpstreamNodeId")
    waterleveldownstreamnodeid: Optional[str] = Field(
        alias="waterLevelDownstreamNodeId"
    )
    dambreaklevelsandwidths: Optional[Union[TimModel, ForcingModel]] = Field(
        alias="dambreakLevelsAndWidths"
    )

    @validator("algorithm", pre=True)
    @classmethod
    def validate_algorithm(cls, value: str) -> DambreakAlgorithm:
        """
        Validates the algorithm parameter for the dambreak structure.

        Args:
            value (int): algorithm value read from the user's input.

        Raises:
            ValueError: When the value given is not of type int.
            ValueError: When the value given is not in the range [1,3]

        Returns:
            int: Validated value.
        """
        int_value = -1
        try:
            int_value = int(value)
        except Exception:
            raise ValueError("Dambreak algorithm value should be of type int.")
        if 0 < int_value <= 3:
            return DambreakAlgorithm(int_value)
        raise ValueError("Dambreak algorithm value should be 1, 2 or 3.")

    @validator("dambreaklevelsandwidths")
    @classmethod
    def validate_dambreak_levels_and_widths(
        cls, field_value: Optional[Union[TimModel, ForcingModel]], values: dict
    ) -> Optional[Union[TimModel, ForcingModel]]:
        """
        Validates whether a dambreak can be created with the given dambreakLevelsAndWidths
        property. This property should be given when the algorithm value is 3.

        Args:
            field_value (Optional[Union[TimModel, ForcingModel]]): Value given for dambreakLevelsAndWidths.
            values (dict): Dictionary of values already validated (assuming algorithm is in it).

        Raises:
            ValueError: When algorithm value is not 3 and field_value has a value.

        Returns:
            Optional[Union[TimModel, ForcingModel]]: The value given for dambreakLevelsAndwidths.
        """
        # Retrieve the algorithm value (if not found use 0).
        algorithm_value = values.get("algorithm", 0)
        if field_value is not None and algorithm_value != 3:
            # dambreakLevelsAndWidths can only be set when algorithm = 3
            raise ValueError(
                f"Dambreak field dambreakLevelsAndWidths can only be set when algorithm = 3, current value: {algorithm_value}."
            )
        return field_value

    @root_validator
    @classmethod
    def check_location_dambreak(cls, values: dict) -> dict:
        """
        Verifies whether the location for this structure contains valid values for
        numCoordinates, xCoordinates and yCoordinates or instead is using a polyline file.
        Verifies whether de water level location specifications are valid.

        Args:
            values (dict): Dictionary of validated values to create a Dambreak.

        Raises:
            ValueError: When the values dictionary does not contain valid coordinates or polyline file or when the water level location specifications are not valid.

        Returns:
            dict: Dictionary of validated values.
        """

        def _validate_waterlevel_location(x_key: str, y_key: str, node_key: str):
            x_is_given = values.get(x_key.lower()) is not None
            y_is_given = values.get(y_key.lower()) is not None
            node_is_given = values.get(node_key.lower()) is not None

            if (x_is_given and y_is_given and not node_is_given) or (
                node_is_given and not x_is_given and not y_is_given
            ):
                return

            raise ValueError(
                f"Either `{node_key}` should be specified or `{x_key}` and `{y_key}`."
            )

        _validate_waterlevel_location(
            "waterLevelUpstreamLocationX",
            "waterLevelUpstreamLocationY",
            "waterLevelUpstreamNodeId",
        )
        _validate_waterlevel_location(
            "waterLevelDownstreamLocationX",
            "waterLevelDownstreamLocationY",
            "waterLevelDownstreamNodeId",
        )

        return values

check_location_dambreak(values) classmethod

Verifies whether the location for this structure contains valid values for numCoordinates, xCoordinates and yCoordinates or instead is using a polyline file. Verifies whether de water level location specifications are valid.

Parameters:

Name Type Description Default
values dict

Dictionary of validated values to create a Dambreak.

required

Raises:

Type Description
ValueError

When the values dictionary does not contain valid coordinates or polyline file or when the water level location specifications are not valid.

Returns:

Name Type Description
dict dict

Dictionary of validated values.

Source code in hydrolib/core/dflowfm/structure/models.py
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
@root_validator
@classmethod
def check_location_dambreak(cls, values: dict) -> dict:
    """
    Verifies whether the location for this structure contains valid values for
    numCoordinates, xCoordinates and yCoordinates or instead is using a polyline file.
    Verifies whether de water level location specifications are valid.

    Args:
        values (dict): Dictionary of validated values to create a Dambreak.

    Raises:
        ValueError: When the values dictionary does not contain valid coordinates or polyline file or when the water level location specifications are not valid.

    Returns:
        dict: Dictionary of validated values.
    """

    def _validate_waterlevel_location(x_key: str, y_key: str, node_key: str):
        x_is_given = values.get(x_key.lower()) is not None
        y_is_given = values.get(y_key.lower()) is not None
        node_is_given = values.get(node_key.lower()) is not None

        if (x_is_given and y_is_given and not node_is_given) or (
            node_is_given and not x_is_given and not y_is_given
        ):
            return

        raise ValueError(
            f"Either `{node_key}` should be specified or `{x_key}` and `{y_key}`."
        )

    _validate_waterlevel_location(
        "waterLevelUpstreamLocationX",
        "waterLevelUpstreamLocationY",
        "waterLevelUpstreamNodeId",
    )
    _validate_waterlevel_location(
        "waterLevelDownstreamLocationX",
        "waterLevelDownstreamLocationY",
        "waterLevelDownstreamNodeId",
    )

    return values

validate_algorithm(value) classmethod

Validates the algorithm parameter for the dambreak structure.

Parameters:

Name Type Description Default
value int

algorithm value read from the user's input.

required

Raises:

Type Description
ValueError

When the value given is not of type int.

ValueError

When the value given is not in the range [1,3]

Returns:

Name Type Description
int DambreakAlgorithm

Validated value.

Source code in hydrolib/core/dflowfm/structure/models.py
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
@validator("algorithm", pre=True)
@classmethod
def validate_algorithm(cls, value: str) -> DambreakAlgorithm:
    """
    Validates the algorithm parameter for the dambreak structure.

    Args:
        value (int): algorithm value read from the user's input.

    Raises:
        ValueError: When the value given is not of type int.
        ValueError: When the value given is not in the range [1,3]

    Returns:
        int: Validated value.
    """
    int_value = -1
    try:
        int_value = int(value)
    except Exception:
        raise ValueError("Dambreak algorithm value should be of type int.")
    if 0 < int_value <= 3:
        return DambreakAlgorithm(int_value)
    raise ValueError("Dambreak algorithm value should be 1, 2 or 3.")

validate_dambreak_levels_and_widths(field_value, values) classmethod

Validates whether a dambreak can be created with the given dambreakLevelsAndWidths property. This property should be given when the algorithm value is 3.

Parameters:

Name Type Description Default
field_value Optional[Union[TimModel, ForcingModel]]

Value given for dambreakLevelsAndWidths.

required
values dict

Dictionary of values already validated (assuming algorithm is in it).

required

Raises:

Type Description
ValueError

When algorithm value is not 3 and field_value has a value.

Returns:

Type Description
Optional[Union[TimModel, ForcingModel]]

Optional[Union[TimModel, ForcingModel]]: The value given for dambreakLevelsAndwidths.

Source code in hydrolib/core/dflowfm/structure/models.py
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
@validator("dambreaklevelsandwidths")
@classmethod
def validate_dambreak_levels_and_widths(
    cls, field_value: Optional[Union[TimModel, ForcingModel]], values: dict
) -> Optional[Union[TimModel, ForcingModel]]:
    """
    Validates whether a dambreak can be created with the given dambreakLevelsAndWidths
    property. This property should be given when the algorithm value is 3.

    Args:
        field_value (Optional[Union[TimModel, ForcingModel]]): Value given for dambreakLevelsAndWidths.
        values (dict): Dictionary of values already validated (assuming algorithm is in it).

    Raises:
        ValueError: When algorithm value is not 3 and field_value has a value.

    Returns:
        Optional[Union[TimModel, ForcingModel]]: The value given for dambreakLevelsAndwidths.
    """
    # Retrieve the algorithm value (if not found use 0).
    algorithm_value = values.get("algorithm", 0)
    if field_value is not None and algorithm_value != 3:
        # dambreakLevelsAndWidths can only be set when algorithm = 3
        raise ValueError(
            f"Dambreak field dambreakLevelsAndWidths can only be set when algorithm = 3, current value: {algorithm_value}."
        )
    return field_value

DambreakAlgorithm

Bases: int, Enum

Source code in hydrolib/core/dflowfm/structure/models.py
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
class DambreakAlgorithm(int, Enum):
    van_der_knaap = 1  # "van der Knaap, 2000"
    verheij_van_der_knaap = 2  # "Verheij-van der Knaap, 2002"
    timeseries = 3  # "Predefined time series, dambreakLevelsAndWidths."

    @property
    def description(self) -> str:
        """
        Property to return the description of the enums defined above.
        Useful for comments in output files.

        Returns:
            str: Description for the current enum.
        """
        description_dict = dict(
            van_der_knaap="van der Knaap, 2000",
            verheij_van_der_knaap="Verheij-van der Knaap, 2002",
            timeseries="Predefined time series, dambreakLevelsAndWidths",
        )
        return description_dict[self.name]

description property

Property to return the description of the enums defined above. Useful for comments in output files.

Returns:

Name Type Description
str str

Description for the current enum.

FlowDirection

Bases: StrEnum

Enum class containing the valid values for the allowedFlowDirection attribute in several subclasses of Structure.

Source code in hydrolib/core/dflowfm/structure/models.py
289
290
291
292
293
294
295
296
297
298
299
class FlowDirection(StrEnum):
    """
    Enum class containing the valid values for the allowedFlowDirection
    attribute in several subclasses of Structure.
    """

    none = "none"
    positive = "positive"
    negative = "negative"
    both = "both"
    allowedvaluestext = "Possible values: both, positive, negative, none."

GateOpeningHorizontalDirection

Bases: StrEnum

Horizontal opening direction of gate door[s].

Source code in hydrolib/core/dflowfm/structure/models.py
676
677
678
679
680
681
682
class GateOpeningHorizontalDirection(StrEnum):
    """Horizontal opening direction of gate door[s]."""

    symmetric = "symmetric"
    from_left = "fromLeft"
    from_right = "fromRight"
    allowedvaluestext = "Possible values: symmetric, fromLeft, fromRight."

GeneralStructure

Bases: Structure

Hydraulic structure with type=generalStructure, to be included in a structure file. Typically inside the structure list of a FMModel.geometry.structurefile[0].structure[..]

All lowercased attributes match with the orifice input as described in UM Sec.C.12.9.

Source code in hydrolib/core/dflowfm/structure/models.py
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
class GeneralStructure(Structure):
    """
    Hydraulic structure with `type=generalStructure`, to be included in a structure file.
    Typically inside the structure list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.structurefile[0].structure[..]`

    All lowercased attributes match with the orifice input as described in
    [UM Sec.C.12.9](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.C.12.9).
    """

    class Comments(Structure.Comments):
        type: Optional[str] = Field(
            "Structure type; must read generalStructure", alias="type"
        )
        allowedflowdir: Optional[str] = Field(
            FlowDirection.allowedvaluestext, alias="allowedFlowDir"
        )

        upstream1width: Optional[str] = Field("w_u1 [m]", alias="upstream1Width")
        upstream1level: Optional[str] = Field("z_u1 [m AD]", alias="upstream1Level")
        upstream2width: Optional[str] = Field("w_u2 [m]", alias="upstream2Width")
        upstream2level: Optional[str] = Field("z_u2 [m D]", alias="upstream2Level")

        crestwidth: Optional[str] = Field("w_s [m]", alias="crestWidth")
        crestlevel: Optional[str] = Field("z_s [m AD]", alias="crestLevel")
        crestlength: Optional[str] = Field(
            "The crest length across the general structure [m]. When the crest length > 0, the extra resistance for this structure will be ls * g/(C2 * waterdepth)",
            alias="crestLength",
        )

        downstream1width: Optional[str] = Field("w_d1 [m]", alias="downstream1Width")
        downstream1level: Optional[str] = Field("z_d1 [m AD]", alias="downstream1Level")
        downstream2width: Optional[str] = Field("w_d2 [m]", alias="downstream2Width")
        downstream2level: Optional[str] = Field("z_d2 [m AD]", alias="downstream2Level")

        gateloweredgelevel: Optional[str] = Field(
            "Position of gate door’s lower edge [m AD]", alias="gateLowerEdgeLevel"
        )
        posfreegateflowcoeff: Optional[str] = Field(
            "Positive free gate flow corr.coeff. cgf [-]", alias="posFreeGateFlowCoeff"
        )
        posdrowngateflowcoeff: Optional[str] = Field(
            "Positive drowned gate flow corr.coeff. cgd [-]",
            alias="posDrownGateFlowCoeff",
        )
        posfreeweirflowcoeff: Optional[str] = Field(
            "Positive free weir flow corr.coeff. cwf [-]", alias="posFreeWeirFlowCoeff"
        )
        posdrownweirflowcoeff: Optional[str] = Field(
            "Positive drowned weir flow corr.coeff. cwd [-]",
            alias="posDrownWeirFlowCoeff",
        )
        poscontrcoeffreegate: Optional[str] = Field(
            "Positive gate flow contraction coefficient µgf [-]",
            alias="posContrCoefFreeGate",
        )
        negfreegateflowcoeff: Optional[str] = Field(
            "Negative free gate flow corr.coeff. cgf [-]", alias="negFreeGateFlowCoeff"
        )
        negdrowngateflowcoeff: Optional[str] = Field(
            "Negative drowned gate flow corr.coeff. cgd [-]",
            alias="negDrownGateFlowCoeff",
        )
        negfreeweirflowcoeff: Optional[str] = Field(
            "Negative free weir flow corr.coeff. cwf [-]", alias="negFreeWeirFlowCoeff"
        )
        negdrownweirflowcoeff: Optional[str] = Field(
            "Negative drowned weir flow corr.coeff. cwd [-]",
            alias="negDrownWeirFlowCoeff",
        )
        negcontrcoeffreegate: Optional[str] = Field(
            "Negative gate flow contraction coefficient mu gf [-]",
            alias="negContrCoefFreeGate",
        )
        extraresistance: Optional[str] = Field(
            "Extra resistance [-]", alias="extraResistance"
        )
        gateheight: Optional[str] = Field(None, alias="gateHeight")
        gateopeningwidth: Optional[str] = Field(
            "Opening width between gate doors [m], should be smaller than (or equal to) crestWidth",
            alias="gateOpeningWidth",
        )
        gateopeninghorizontaldirection: Optional[str] = Field(
            "Horizontal opening direction of gate door[s]. Possible values are: symmetric, fromLeft, fromRight",
            alias="gateOpeningHorizontalDirection",
        )
        usevelocityheight: Optional[str] = Field(
            "Flag indicates whether the velocity height is to be calculated or not",
            alias="useVelocityHeight",
        )

    comments: Optional[Comments] = Comments()

    type: Literal["generalStructure"] = Field("generalStructure", alias="type")
    allowedflowdir: Optional[FlowDirection] = Field(
        FlowDirection.both.value, alias="allowedFlowDir"
    )

    upstream1width: Optional[float] = Field(10.0, alias="upstream1Width")
    upstream1level: Optional[float] = Field(0.0, alias="upstream1Level")
    upstream2width: Optional[float] = Field(10.0, alias="upstream2Width")
    upstream2level: Optional[float] = Field(0.0, alias="upstream2Level")

    crestwidth: Optional[float] = Field(10.0, alias="crestWidth")
    crestlevel: Optional[ForcingData] = Field(0.0, alias="crestLevel")
    crestlength: Optional[float] = Field(0.0, alias="crestLength")

    downstream1width: Optional[float] = Field(10.0, alias="downstream1Width")
    downstream1level: Optional[float] = Field(0.0, alias="downstream1Level")
    downstream2width: Optional[float] = Field(10.0, alias="downstream2Width")
    downstream2level: Optional[float] = Field(0.0, alias="downstream2Level")

    gateloweredgelevel: Optional[ForcingData] = Field(11.0, alias="gateLowerEdgeLevel")
    posfreegateflowcoeff: Optional[float] = Field(1.0, alias="posFreeGateFlowCoeff")
    posdrowngateflowcoeff: Optional[float] = Field(1.0, alias="posDrownGateFlowCoeff")
    posfreeweirflowcoeff: Optional[float] = Field(1.0, alias="posFreeWeirFlowCoeff")
    posdrownweirflowcoeff: Optional[float] = Field(1.0, alias="posDrownWeirFlowCoeff")
    poscontrcoeffreegate: Optional[float] = Field(1.0, alias="posContrCoefFreeGate")
    negfreegateflowcoeff: Optional[float] = Field(1.0, alias="negFreeGateFlowCoeff")
    negdrowngateflowcoeff: Optional[float] = Field(1.0, alias="negDrownGateFlowCoeff")
    negfreeweirflowcoeff: Optional[float] = Field(1.0, alias="negFreeWeirFlowCoeff")
    negdrownweirflowcoeff: Optional[float] = Field(1.0, alias="negDrownWeirFlowCoeff")
    negcontrcoeffreegate: Optional[float] = Field(1.0, alias="negContrCoefFreeGate")
    extraresistance: Optional[float] = Field(0.0, alias="extraResistance")
    gateheight: Optional[float] = Field(1e10, alias="gateHeight")
    gateopeningwidth: Optional[ForcingData] = Field(0.0, alias="gateOpeningWidth")
    gateopeninghorizontaldirection: Optional[GateOpeningHorizontalDirection] = Field(
        GateOpeningHorizontalDirection.symmetric.value,
        alias="gateOpeningHorizontalDirection",
    )
    usevelocityheight: Optional[bool] = Field(True, alias="useVelocityHeight")

Orientation

Bases: StrEnum

Enum class containing the valid values for the orientation attribute in several subclasses of Structure.

Source code in hydrolib/core/dflowfm/structure/models.py
302
303
304
305
306
307
308
309
310
class Orientation(StrEnum):
    """
    Enum class containing the valid values for the orientation
    attribute in several subclasses of Structure.
    """

    positive = "positive"
    negative = "negative"
    allowedvaluestext = "Possible values: positive, negative."

Orifice

Bases: Structure

Hydraulic structure with type=orifice, to be included in a structure file. Typically inside the structure list of a FMModel.geometry.structurefile[0].structure[..]

All lowercased attributes match with the orifice input as described in UM Sec.C.12.7.

Source code in hydrolib/core/dflowfm/structure/models.py
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
class Orifice(Structure):
    """
    Hydraulic structure with `type=orifice`, to be included in a structure file.
    Typically inside the structure list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.structurefile[0].structure[..]`

    All lowercased attributes match with the orifice input as described in
    [UM Sec.C.12.7](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.C.12.7).
    """

    type: Literal["orifice"] = Field("orifice", alias="type")
    allowedflowdir: Optional[FlowDirection] = Field(
        FlowDirection.both.value, alias="allowedFlowDir"
    )

    crestlevel: ForcingData = Field(alias="crestLevel")
    crestwidth: Optional[float] = Field(None, alias="crestWidth")
    gateloweredgelevel: ForcingData = Field(alias="gateLowerEdgeLevel")
    corrcoeff: float = Field(1.0, alias="corrCoeff")
    usevelocityheight: bool = Field(True, alias="useVelocityHeight")

    # TODO Use a validator here to check the optionals related to the bool field
    uselimitflowpos: Optional[bool] = Field(False, alias="useLimitFlowPos")
    limitflowpos: Optional[float] = Field(alias="limitFlowPos")

    uselimitflowneg: Optional[bool] = Field(False, alias="useLimitFlowNeg")
    limitflowneg: Optional[float] = Field(alias="limitFlowNeg")

    _flowdirection_validator = get_enum_validator("allowedflowdir", enum=FlowDirection)

    @validator("limitflowpos", always=True)
    @classmethod
    def _validate_limitflowpos(cls, v, values):
        return cls._validate_limitflow(v, values, "limitFlowPos", "useLimitFlowPos")

    @validator("limitflowneg", always=True)
    @classmethod
    def _validate_limitflowneg(cls, v, values):
        return cls._validate_limitflow(v, values, "limitFlowNeg", "useLimitFlowNeg")

    @classmethod
    def _validate_limitflow(cls, v, values, limitflow: str, uselimitflow: str):
        if v is None and values[uselimitflow.lower()] == True:
            raise ValueError(
                f"{limitflow} should be defined when {uselimitflow} is true"
            )

        return v

Pump

Bases: Structure

Hydraulic structure with type=pump, to be included in a structure file. Typically inside the structure list of a FMModel.geometry.structurefile[0].structure[..]

All lowercased attributes match with the pump input as described in UM Sec.C.12.6.

Source code in hydrolib/core/dflowfm/structure/models.py
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
class Pump(Structure):
    """
    Hydraulic structure with `type=pump`, to be included in a structure file.
    Typically inside the structure list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.structurefile[0].structure[..]`

    All lowercased attributes match with the pump input as described in
    [UM Sec.C.12.6](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.C.12.6).
    """

    type: Literal["pump"] = Field("pump", alias="type")

    orientation: Optional[Orientation] = Field(alias="orientation")
    controlside: Optional[str] = Field(alias="controlSide")  # TODO Enum
    numstages: Optional[int] = Field(alias="numStages")
    capacity: ForcingData = Field(alias="capacity")

    startlevelsuctionside: Optional[List[float]] = Field(alias="startLevelSuctionSide")
    stoplevelsuctionside: Optional[List[float]] = Field(alias="stopLevelSuctionSide")
    startleveldeliveryside: Optional[List[float]] = Field(
        alias="startLevelDeliverySide"
    )
    stopleveldeliveryside: Optional[List[float]] = Field(alias="stopLevelDeliverySide")
    numreductionlevels: Optional[int] = Field(alias="numReductionLevels")
    head: Optional[List[float]] = Field(alias="head")
    reductionfactor: Optional[List[float]] = Field(alias="reductionFactor")

    _split_to_list = get_split_string_on_delimiter_validator(
        "startlevelsuctionside",
        "stoplevelsuctionside",
        "startleveldeliveryside",
        "stopleveldeliveryside",
        "head",
        "reductionfactor",
    )

    _orientation_validator = get_enum_validator("orientation", enum=Orientation)

    @root_validator(allow_reuse=True)
    def validate_that_controlside_is_provided_when_numstages_is_provided(
        cls, values: Dict
    ) -> Dict:
        return validate_required_fields(
            values,
            "controlside",
            conditional_field_name="numstages",
            conditional_value=0,
            comparison_func=gt,
        )

    @classmethod
    def _check_list_lengths_suctionside(cls, values: Dict) -> Dict:
        """Validates that the length of the startlevelsuctionside and stoplevelsuctionside fields are as expected."""
        return validate_correct_length(
            values,
            "startlevelsuctionside",
            "stoplevelsuctionside",
            length_name="numstages",
            list_required_with_length=True,
        )

    @root_validator(allow_reuse=True)
    def conditionally_check_list_lengths_suctionside(cls, values: Dict) -> Dict:
        """
        Validates the length of the suction side fields, but only if there is a controlside value
        present in the values and the controlside is not equal to the deliverySide.
        """
        return validate_conditionally(
            cls,
            values,
            Pump._check_list_lengths_suctionside,
            "controlside",
            "deliverySide",
            ne,
        )

    @classmethod
    def _check_list_lengths_deliveryside(cls, values: Dict) -> Dict:
        """Validates that the length of the startleveldeliveryside and stopleveldeliveryside fields are as expected."""
        return validate_correct_length(
            values,
            "startleveldeliveryside",
            "stopleveldeliveryside",
            length_name="numstages",
            list_required_with_length=True,
        )

    @root_validator(allow_reuse=True)
    def conditionally_check_list_lengths_deliveryside(cls, values: Dict) -> Dict:
        """
        Validates the length of the delivery side fields, but only if there is a controlside value
        present in the values and the controlside is not equal to the suctionSide.
        """
        return validate_conditionally(
            cls,
            values,
            Pump._check_list_lengths_deliveryside,
            "controlside",
            "suctionSide",
            ne,
        )

    @root_validator(allow_reuse=True)
    def check_list_lengths_head_and_reductionfactor(cls, values):
        """Validates that the lengths of the head and reductionfactor fields are as expected."""
        return validate_correct_length(
            values,
            "head",
            "reductionfactor",
            length_name="numreductionlevels",
            list_required_with_length=True,
        )

check_list_lengths_head_and_reductionfactor(values)

Validates that the lengths of the head and reductionfactor fields are as expected.

Source code in hydrolib/core/dflowfm/structure/models.py
597
598
599
600
601
602
603
604
605
606
@root_validator(allow_reuse=True)
def check_list_lengths_head_and_reductionfactor(cls, values):
    """Validates that the lengths of the head and reductionfactor fields are as expected."""
    return validate_correct_length(
        values,
        "head",
        "reductionfactor",
        length_name="numreductionlevels",
        list_required_with_length=True,
    )

conditionally_check_list_lengths_deliveryside(values)

Validates the length of the delivery side fields, but only if there is a controlside value present in the values and the controlside is not equal to the suctionSide.

Source code in hydrolib/core/dflowfm/structure/models.py
582
583
584
585
586
587
588
589
590
591
592
593
594
595
@root_validator(allow_reuse=True)
def conditionally_check_list_lengths_deliveryside(cls, values: Dict) -> Dict:
    """
    Validates the length of the delivery side fields, but only if there is a controlside value
    present in the values and the controlside is not equal to the suctionSide.
    """
    return validate_conditionally(
        cls,
        values,
        Pump._check_list_lengths_deliveryside,
        "controlside",
        "suctionSide",
        ne,
    )

conditionally_check_list_lengths_suctionside(values)

Validates the length of the suction side fields, but only if there is a controlside value present in the values and the controlside is not equal to the deliverySide.

Source code in hydrolib/core/dflowfm/structure/models.py
556
557
558
559
560
561
562
563
564
565
566
567
568
569
@root_validator(allow_reuse=True)
def conditionally_check_list_lengths_suctionside(cls, values: Dict) -> Dict:
    """
    Validates the length of the suction side fields, but only if there is a controlside value
    present in the values and the controlside is not equal to the deliverySide.
    """
    return validate_conditionally(
        cls,
        values,
        Pump._check_list_lengths_suctionside,
        "controlside",
        "deliverySide",
        ne,
    )

Structure

Bases: INIBasedModel

Source code in hydrolib/core/dflowfm/structure/models.py
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
class Structure(INIBasedModel):
    # TODO: would we want to load this from something externally and generate these automatically
    class Comments(INIBasedModel.Comments):
        id: Optional[str] = "Unique structure id (max. 256 characters)."
        name: Optional[str] = "Given name in the user interface."
        polylinefile: Optional[str] = Field(
            "*.pli; Polyline geometry definition for 2D structure.",
            alias="polylinefile",
        )
        branchid: Optional[str] = Field(
            "Branch on which the structure is located.", alias="branchId"
        )
        chainage: Optional[str] = "Chainage on the branch (m)."

        numcoordinates: Optional[str] = Field(
            "Number of values in xCoordinates and yCoordinates", alias="numCoordinates"
        )
        xcoordinates: Optional[str] = Field(
            "x-coordinates of the location of the structure. (number of values = numCoordinates)",
            alias="xCoordinates",
        )
        ycoordinates: Optional[str] = Field(
            "y-coordinates of the location of the structure. (number of values = numCoordinates)",
            alias="yCoordinates",
        )

    comments: Comments = Comments()

    _header: Literal["Structure"] = "Structure"

    id: str = Field("id", max_length=256, alias="id")
    name: str = Field("id", alias="name")
    type: str = Field(alias="type")

    polylinefile: Optional[DiskOnlyFileModel] = Field(None, alias="polylinefile")

    branchid: Optional[str] = Field(None, alias="branchId")
    chainage: Optional[float] = Field(None, alias="chainage")

    numcoordinates: Optional[int] = Field(None, alias="numCoordinates")
    xcoordinates: Optional[List[float]] = Field(None, alias="xCoordinates")
    ycoordinates: Optional[List[float]] = Field(None, alias="yCoordinates")

    _loc_coord_fields = {"numcoordinates", "xcoordinates", "ycoordinates"}
    _loc_branch_fields = {"branchid", "chainage"}
    _loc_all_fields = _loc_coord_fields | _loc_branch_fields

    @classmethod
    def _get_unknown_keyword_error_manager(cls) -> Optional[UnknownKeywordErrorManager]:
        """
        The Structure does not currently support raising an error on unknown keywords.
        """
        return None

    _split_to_list = get_split_string_on_delimiter_validator(
        "xcoordinates", "ycoordinates"
    )

    @validator("type", pre=True)
    def _validate_type(cls, value):
        return get_from_subclass_defaults(Structure, "type", value)

    @root_validator
    @classmethod
    def check_location(cls, values: dict) -> dict:
        """
        Validates the location of the structure based on the given parameters.
        For instance, if a branchid is given, then it is expected also the chainage,
        otherwise numcoordinates xcoordinates and ycoordinates shall be expected.

        Args:
            values (dict): Dictionary of values validated for the new structure.

        Raises:
            ValueError: When branchid or chainage values are not valid (empty strings).
            ValueError: When the number of xcoordinates and ycoordinates do not match numcoordinates.

        Returns:
            dict: Dictionary of values validated for the new structure.
        """
        filtered_values = {k: v for k, v in values.items() if v is not None}
        structype = filtered_values.get("type", "").lower()

        if structype == "compound" or issubclass(cls, (Compound)):
            # Compound structure does not require a location specification.
            return values

        # Backwards compatibility for old-style polylinefile input field (instead of num/x/yCoordinates):
        polyline_compatible_structures = dict(
            pump="Pump",
            dambreak="Dambreak",
            gate="Gate",
            weir="Weir",
            generalstructure="GeneralStructure",
        )
        polylinefile_in_model = (
            structype in polyline_compatible_structures.keys()
            and filtered_values.get("polylinefile") is not None
        )

        # No branchId+chainage for some structures:
        only_coordinates_structures = dict(
            longculvert="LongCulvert", dambreak="Dambreak"
        )
        coordinates_in_model = Structure.validate_coordinates_in_model(filtered_values)

        # Error: do not allow both x/y and polyline file:
        assert not (
            polylinefile_in_model and coordinates_in_model
        ), f"`Specify location either by `num/x/yCoordinates` or `polylinefile`, but not both."

        # Error: require x/y or polyline file:
        if (
            structype in polyline_compatible_structures.keys()
            and structype in only_coordinates_structures.keys()
        ):
            assert (
                coordinates_in_model or polylinefile_in_model
            ), f"Specify location either by setting `num/x/yCoordinates` or `polylinefile` fields for a {polyline_compatible_structures[structype]} structure."

        # Error: Some structures require coordinates_in_model, but not branchId and chainage.
        if (
            not polylinefile_in_model
            and structype in only_coordinates_structures.keys()
        ):
            assert (
                coordinates_in_model
            ), f"Specify location by setting `num/x/yCoordinates` for a {only_coordinates_structures[structype]} structure."

        # Error: final check: at least one of x/y, branchId+chainage or polyline file must be given
        branch_and_chainage_in_model = Structure.validate_branch_and_chainage_in_model(
            filtered_values
        )
        assert (
            branch_and_chainage_in_model
            or coordinates_in_model
            or polylinefile_in_model
        ), "Specify location either by setting `branchId` and `chainage` or `num/x/yCoordinates` or `polylinefile` fields."

        return values

    @staticmethod
    def validate_branch_and_chainage_in_model(values: dict) -> bool:
        """
        Static method to validate whether the given branchid and chainage values
        match the expectation of a new structure.

        Args:
            values (dict): Dictionary of values to be used to generate a structure.

        Raises:
            ValueError: When the value for branchid or chainage are not valid.

        Returns:
            bool: Result of valid branchid / chainage in dictionary.
        """
        branchid = values.get("branchid", None)
        if branchid is None:
            return False

        chainage = values.get("chainage", None)
        if str_is_empty_or_none(branchid) or chainage is None:
            raise ValueError(
                "A valid value for branchId and chainage is required when branchId key is specified."
            )
        return True

    @staticmethod
    def validate_coordinates_in_model(values: dict) -> bool:
        """
        Static method to validate whether the given values match the expectations
        of a structure to define its coordinates.

        Args:
            values (dict): Dictionary of values to be used to generate a structure.

        Raises:
            ValueError: When the given coordinates is less than 2.
            ValueError: When the given coordinates do not match in expected size.

        Returns:
            bool: Result of valid coordinates in dictionary.
        """
        searched_keys = ["numcoordinates", "xcoordinates", "ycoordinates"]
        if any(values.get(k, None) is None for k in searched_keys):
            return False

        n_coords = values["numcoordinates"]
        if n_coords < 2:
            raise ValueError(
                f"Expected at least 2 coordinates, but only {n_coords} declared."
            )

        def get_coord_len(coord: str) -> int:
            if values[coord] is None:
                return 0
            return len(values[coord])

        len_x_coords = get_coord_len("xcoordinates")
        len_y_coords = get_coord_len("ycoordinates")
        if n_coords == len_x_coords == len_y_coords:
            return True
        raise ValueError(
            f"Expected {n_coords} coordinates, given {len_x_coords} for xCoordinates and {len_y_coords} for yCoordinates."
        )

    @classmethod
    def validate(cls, v):
        """Try to initialize subclass based on the `type` field.
        This field is compared to each `type` field of the derived models of `Structure`.
        The derived model with an equal structure type will be initialized.

        Raises:
            ValueError: When the given type is not a known structure type.
        """

        # should be replaced by discriminated unions once merged
        # https://github.com/samuelcolvin/pydantic/pull/2336
        if isinstance(v, dict):
            for c in cls.__subclasses__():
                if (
                    c.__fields__.get("type").default.lower()
                    == v.get("type", "").lower()
                ):
                    v = c(**v)
                    break
            else:
                raise ValueError(
                    f"Type of {cls.__name__} with id={v.get('id', '')} and type={v.get('type', '')} is not recognized."
                )
        return super().validate(v)

    def _exclude_fields(self) -> Set:
        # exclude the non-applicable, or unset props like coordinates or branches
        if self.type == "compound":
            exclude_set = self._loc_all_fields
        elif self.branchid is not None:
            exclude_set = self._loc_coord_fields
        else:
            exclude_set = self._loc_branch_fields
        exclude_set = super()._exclude_fields().union(exclude_set)
        return exclude_set

    def _get_identifier(self, data: dict) -> Optional[str]:
        return data.get("id") or data.get("name")

check_location(values) classmethod

Validates the location of the structure based on the given parameters. For instance, if a branchid is given, then it is expected also the chainage, otherwise numcoordinates xcoordinates and ycoordinates shall be expected.

Parameters:

Name Type Description Default
values dict

Dictionary of values validated for the new structure.

required

Raises:

Type Description
ValueError

When branchid or chainage values are not valid (empty strings).

ValueError

When the number of xcoordinates and ycoordinates do not match numcoordinates.

Returns:

Name Type Description
dict dict

Dictionary of values validated for the new structure.

Source code in hydrolib/core/dflowfm/structure/models.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
@root_validator
@classmethod
def check_location(cls, values: dict) -> dict:
    """
    Validates the location of the structure based on the given parameters.
    For instance, if a branchid is given, then it is expected also the chainage,
    otherwise numcoordinates xcoordinates and ycoordinates shall be expected.

    Args:
        values (dict): Dictionary of values validated for the new structure.

    Raises:
        ValueError: When branchid or chainage values are not valid (empty strings).
        ValueError: When the number of xcoordinates and ycoordinates do not match numcoordinates.

    Returns:
        dict: Dictionary of values validated for the new structure.
    """
    filtered_values = {k: v for k, v in values.items() if v is not None}
    structype = filtered_values.get("type", "").lower()

    if structype == "compound" or issubclass(cls, (Compound)):
        # Compound structure does not require a location specification.
        return values

    # Backwards compatibility for old-style polylinefile input field (instead of num/x/yCoordinates):
    polyline_compatible_structures = dict(
        pump="Pump",
        dambreak="Dambreak",
        gate="Gate",
        weir="Weir",
        generalstructure="GeneralStructure",
    )
    polylinefile_in_model = (
        structype in polyline_compatible_structures.keys()
        and filtered_values.get("polylinefile") is not None
    )

    # No branchId+chainage for some structures:
    only_coordinates_structures = dict(
        longculvert="LongCulvert", dambreak="Dambreak"
    )
    coordinates_in_model = Structure.validate_coordinates_in_model(filtered_values)

    # Error: do not allow both x/y and polyline file:
    assert not (
        polylinefile_in_model and coordinates_in_model
    ), f"`Specify location either by `num/x/yCoordinates` or `polylinefile`, but not both."

    # Error: require x/y or polyline file:
    if (
        structype in polyline_compatible_structures.keys()
        and structype in only_coordinates_structures.keys()
    ):
        assert (
            coordinates_in_model or polylinefile_in_model
        ), f"Specify location either by setting `num/x/yCoordinates` or `polylinefile` fields for a {polyline_compatible_structures[structype]} structure."

    # Error: Some structures require coordinates_in_model, but not branchId and chainage.
    if (
        not polylinefile_in_model
        and structype in only_coordinates_structures.keys()
    ):
        assert (
            coordinates_in_model
        ), f"Specify location by setting `num/x/yCoordinates` for a {only_coordinates_structures[structype]} structure."

    # Error: final check: at least one of x/y, branchId+chainage or polyline file must be given
    branch_and_chainage_in_model = Structure.validate_branch_and_chainage_in_model(
        filtered_values
    )
    assert (
        branch_and_chainage_in_model
        or coordinates_in_model
        or polylinefile_in_model
    ), "Specify location either by setting `branchId` and `chainage` or `num/x/yCoordinates` or `polylinefile` fields."

    return values

validate(v) classmethod

Try to initialize subclass based on the type field. This field is compared to each type field of the derived models of Structure. The derived model with an equal structure type will be initialized.

Raises:

Type Description
ValueError

When the given type is not a known structure type.

Source code in hydrolib/core/dflowfm/structure/models.py
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
@classmethod
def validate(cls, v):
    """Try to initialize subclass based on the `type` field.
    This field is compared to each `type` field of the derived models of `Structure`.
    The derived model with an equal structure type will be initialized.

    Raises:
        ValueError: When the given type is not a known structure type.
    """

    # should be replaced by discriminated unions once merged
    # https://github.com/samuelcolvin/pydantic/pull/2336
    if isinstance(v, dict):
        for c in cls.__subclasses__():
            if (
                c.__fields__.get("type").default.lower()
                == v.get("type", "").lower()
            ):
                v = c(**v)
                break
        else:
            raise ValueError(
                f"Type of {cls.__name__} with id={v.get('id', '')} and type={v.get('type', '')} is not recognized."
            )
    return super().validate(v)

validate_branch_and_chainage_in_model(values) staticmethod

Static method to validate whether the given branchid and chainage values match the expectation of a new structure.

Parameters:

Name Type Description Default
values dict

Dictionary of values to be used to generate a structure.

required

Raises:

Type Description
ValueError

When the value for branchid or chainage are not valid.

Returns:

Name Type Description
bool bool

Result of valid branchid / chainage in dictionary.

Source code in hydrolib/core/dflowfm/structure/models.py
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
@staticmethod
def validate_branch_and_chainage_in_model(values: dict) -> bool:
    """
    Static method to validate whether the given branchid and chainage values
    match the expectation of a new structure.

    Args:
        values (dict): Dictionary of values to be used to generate a structure.

    Raises:
        ValueError: When the value for branchid or chainage are not valid.

    Returns:
        bool: Result of valid branchid / chainage in dictionary.
    """
    branchid = values.get("branchid", None)
    if branchid is None:
        return False

    chainage = values.get("chainage", None)
    if str_is_empty_or_none(branchid) or chainage is None:
        raise ValueError(
            "A valid value for branchId and chainage is required when branchId key is specified."
        )
    return True

validate_coordinates_in_model(values) staticmethod

Static method to validate whether the given values match the expectations of a structure to define its coordinates.

Parameters:

Name Type Description Default
values dict

Dictionary of values to be used to generate a structure.

required

Raises:

Type Description
ValueError

When the given coordinates is less than 2.

ValueError

When the given coordinates do not match in expected size.

Returns:

Name Type Description
bool bool

Result of valid coordinates in dictionary.

Source code in hydrolib/core/dflowfm/structure/models.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
@staticmethod
def validate_coordinates_in_model(values: dict) -> bool:
    """
    Static method to validate whether the given values match the expectations
    of a structure to define its coordinates.

    Args:
        values (dict): Dictionary of values to be used to generate a structure.

    Raises:
        ValueError: When the given coordinates is less than 2.
        ValueError: When the given coordinates do not match in expected size.

    Returns:
        bool: Result of valid coordinates in dictionary.
    """
    searched_keys = ["numcoordinates", "xcoordinates", "ycoordinates"]
    if any(values.get(k, None) is None for k in searched_keys):
        return False

    n_coords = values["numcoordinates"]
    if n_coords < 2:
        raise ValueError(
            f"Expected at least 2 coordinates, but only {n_coords} declared."
        )

    def get_coord_len(coord: str) -> int:
        if values[coord] is None:
            return 0
        return len(values[coord])

    len_x_coords = get_coord_len("xcoordinates")
    len_y_coords = get_coord_len("ycoordinates")
    if n_coords == len_x_coords == len_y_coords:
        return True
    raise ValueError(
        f"Expected {n_coords} coordinates, given {len_x_coords} for xCoordinates and {len_y_coords} for yCoordinates."
    )

StructureGeneral

Bases: INIGeneral

[General] section with structure file metadata.

Source code in hydrolib/core/dflowfm/structure/models.py
1095
1096
1097
1098
1099
1100
class StructureGeneral(INIGeneral):
    """`[General]` section with structure file metadata."""

    _header: Literal["General"] = "General"
    fileversion: str = Field("3.00", alias="fileVersion")
    filetype: Literal["structure"] = Field("structure", alias="fileType")

StructureModel

Bases: INIModel

The overall structure model that contains the contents of one structure file.

This model is typically referenced under a FMModel.geometry.structurefile[..].

Attributes:

Name Type Description
general StructureGeneral

[General] block with file metadata.

branch List[Structure]

List of [Structure] blocks for all hydraulic structures.

Source code in hydrolib/core/dflowfm/structure/models.py
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
class StructureModel(INIModel):
    """
    The overall structure model that contains the contents of one structure file.

    This model is typically referenced under a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.structurefile[..]`.

    Attributes:
        general (StructureGeneral): `[General]` block with file metadata.
        branch (List[Structure]): List of `[Structure]` blocks for all hydraulic structures.
    """

    general: StructureGeneral = StructureGeneral()
    structure: List[Structure] = []

    @classmethod
    def _ext(cls) -> str:
        return ".ini"

    @classmethod
    def _filename(cls) -> str:
        return "structures"

    _split_to_list = make_list_validator("structure")

UniversalWeir

Bases: Structure

Hydraulic structure with type=universalWeir, to be included in a structure file. Typically inside the structure list of a FMModel.geometry.structurefile[0].structure[..]

All lowercased attributes match with the universal weir input as described in UM Sec.C.12.2.

Source code in hydrolib/core/dflowfm/structure/models.py
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
class UniversalWeir(Structure):
    """
    Hydraulic structure with `type=universalWeir`, to be included in a structure file.
    Typically inside the structure list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.structurefile[0].structure[..]`

    All lowercased attributes match with the universal weir input as described in
    [UM Sec.C.12.2](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.C.12.2).
    """

    class Comments(Structure.Comments):
        type: Optional[str] = Field(
            "Structure type; must read universalWeir", alias="type"
        )
        allowedflowdir: Optional[str] = Field(
            FlowDirection.allowedvaluestext, alias="allowedFlowdir"
        )

        numlevels: Optional[str] = Field("Number of yz-Values.", alias="numLevels")
        yvalues: Optional[str] = Field(
            "y-values of the cross section (m). (number of values = numLevels)",
            alias="yValues",
        )
        zvalues: Optional[str] = Field(
            "z-values of the cross section (m). (number of values = numLevels)",
            alias="zValues",
        )
        crestlevel: Optional[str] = Field(
            "Crest level of weir (m AD).", alias="crestLevel"
        )
        dischargecoeff: Optional[str] = Field(
            "Discharge coefficient c_e (-).", alias="dischargeCoeff"
        )

    comments: Comments = Comments()

    type: Literal["universalWeir"] = Field("universalWeir", alias="type")
    allowedflowdir: FlowDirection = Field(alias="allowedFlowDir")

    numlevels: int = Field(alias="numLevels")
    yvalues: List[float] = Field(alias="yValues")
    zvalues: List[float] = Field(alias="zValues")
    crestlevel: float = Field(alias="crestLevel")
    dischargecoeff: float = Field(alias="dischargeCoeff")

    _split_to_list = get_split_string_on_delimiter_validator("yvalues", "zvalues")
    _flowdirection_validator = get_enum_validator("allowedflowdir", enum=FlowDirection)

Weir

Bases: Structure

Hydraulic structure with type=weir, to be included in a structure file. Typically inside the structure list of a FMModel.geometry.structurefile[0].structure[..]

All lowercased attributes match with the weir input as described in UM Sec.C.12.1.

Source code in hydrolib/core/dflowfm/structure/models.py
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
class Weir(Structure):
    """
    Hydraulic structure with `type=weir`, to be included in a structure file.
    Typically inside the structure list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.structurefile[0].structure[..]`

    All lowercased attributes match with the weir input as described in
    [UM Sec.C.12.1](https://content.oss.deltares.nl/delft3dfm1d2d/D-Flow_FM_User_Manual_1D2D.pdf#subsection.C.12.1).
    """

    class Comments(Structure.Comments):
        type: Optional[str] = Field("Structure type; must read weir", alias="type")
        allowedflowdir: Optional[str] = Field(
            FlowDirection.allowedvaluestext, alias="allowedFlowdir"
        )

        crestlevel: Optional[str] = Field(
            "Crest level of weir (m AD).", alias="crestLevel"
        )
        crestwidth: Optional[str] = Field("Width of the weir (m).", alias="crestWidth")
        corrcoeff: Optional[str] = Field(
            "Correction coefficient (-).", alias="corrCoeff"
        )
        usevelocityheight: Optional[str] = Field(
            "Flag indicating whether the velocity height is to be calculated or not.",
            alias="useVelocityHeight",
        )

    comments: Comments = Comments()

    type: Literal["weir"] = Field("weir", alias="type")
    allowedflowdir: Optional[FlowDirection] = Field(
        FlowDirection.both.value, alias="allowedFlowDir"
    )

    crestlevel: ForcingData = Field(alias="crestLevel")
    crestwidth: Optional[float] = Field(None, alias="crestWidth")
    corrcoeff: float = Field(1.0, alias="corrCoeff")
    usevelocityheight: bool = Field(True, alias="useVelocityHeight")

    _flowdirection_validator = get_enum_validator("allowedflowdir", enum=FlowDirection)