Skip to content

Cross section files

The crosssection module provides the specific logic for accessing cross section files (location and definition) for a D-Flow FM model. Generic parsing and serializing functionality comes from the generic hydrolib.core.dflowfm.ini modules.

The cross section files are represented by the classes below.

Model

CircleCrsDef

Bases: CrossSectionDefinition

Crosssection definition with type=circle, to be included in a crossdef file. Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]

All lowercased attributes match with the circle input as described in UM Sec.C.16.1.1.

Source code in hydrolib/core/dflowfm/crosssection/models.py
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
class CircleCrsDef(CrossSectionDefinition):
    """
    Crosssection definition with `type=circle`, to be included in a crossdef file.
    Typically inside the definition list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.crossdeffile.definition[..]`

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

    class Comments(CrossSectionDefinition.Comments):
        type: Optional[str] = Field("Cross section type; must read circle")

        diameter: Optional[str] = Field("Internal diameter of the circle [m].")
        frictionid: Optional[str] = Field(
            frictionid_description,
            alias="frictionId",
        )
        frictiontype: Optional[str] = Field(
            frictiontype_description,
            alias="frictionType",
        )
        frictionvalue: Optional[str] = Field(
            frictionvalue_description,
            alias="frictionValue",
        )

    comments: Comments = Comments()

    type: Literal["circle"] = Field("circle")
    diameter: float
    frictionid: Optional[str] = Field(alias="frictionId")
    frictiontype: Optional[FrictionType] = Field(alias="frictionType")
    frictionvalue: Optional[float] = Field(alias="frictionValue")

    _friction_validator = CrossSectionDefinition._get_friction_root_validator(
        "frictionid", "frictiontype", "frictionvalue"
    )
    _frictiontype_validator = get_enum_validator("frictiontype", enum=FrictionType)

CrossDefGeneral

Bases: INIGeneral

The crosssection definition file's [General] section with file meta data.

Source code in hydrolib/core/dflowfm/crosssection/models.py
36
37
38
39
40
class CrossDefGeneral(INIGeneral):
    """The crosssection definition file's `[General]` section with file meta data."""

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

CrossDefModel

Bases: INIModel

The overall crosssection definition model that contains the contents of one crossdef file.

This model is typically referenced under a FMModel.geometry.crossdeffile.

Attributes:

Name Type Description
general CrossdefGeneral

[General] block with file metadata.

definition List[CrossSectionDefinition]

List of [Definition] blocks for all cross sections.

Source code in hydrolib/core/dflowfm/crosssection/models.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
class CrossDefModel(INIModel):
    """
    The overall crosssection definition model that contains the contents of one crossdef file.

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

    Attributes:
        general (CrossdefGeneral): `[General]` block with file metadata.
        definition (List[CrossSectionDefinition]): List of `[Definition]` blocks for all cross sections.
    """

    general: CrossDefGeneral = CrossDefGeneral()
    definition: List[CrossSectionDefinition] = []

    _make_list = make_list_validator("definition")

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

CrossLocGeneral

Bases: INIGeneral

The crosssection location file's [General] section with file meta data.

Source code in hydrolib/core/dflowfm/crosssection/models.py
43
44
45
46
47
class CrossLocGeneral(INIGeneral):
    """The crosssection location file's `[General]` section with file meta data."""

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

CrossLocModel

Bases: INIModel

The overall crosssection location model that contains the contents of one crossloc file.

This model is typically referenced under a FMModel.geometry.crosslocfile.

Attributes:

Name Type Description
general CrossLocGeneral

[General] block with file metadata.

crosssection List[CrossSection]

List of [CrossSection] blocks for all cross section locations.

Source code in hydrolib/core/dflowfm/crosssection/models.py
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
class CrossLocModel(INIModel):
    """
    The overall crosssection location model that contains the contents of one crossloc file.

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

    Attributes:
        general (CrossLocGeneral): `[General]` block with file metadata.
        crosssection (List[CrossSection]): List of `[CrossSection]` blocks for all cross section locations.
    """

    general: CrossLocGeneral = CrossLocGeneral()
    crosssection: List[CrossSection] = []

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

CrossSection

Bases: INIBasedModel

A [CrossSection] block for use inside a crosssection location file, i.e., a CrossLocModel.

Attributes:

Name Type Description
id str

Unique cross-section location id.

branchid str

Branch on which the cross section is located.

chainage str

Chainage on the branch (m).

x str

x-coordinate of the location of the cross section.

y str

y-coordinate of the location of the cross section.

shift float

Vertical shift of the cross section definition [m]. Defined positive upwards.

definitionid str

Id of cross section definition.

Source code in hydrolib/core/dflowfm/crosssection/models.py
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
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
class CrossSection(INIBasedModel):
    """
    A `[CrossSection]` block for use inside a crosssection location file,
    i.e., a [CrossLocModel][hydrolib.core.dflowfm.crosssection.models.CrossLocModel].

    Attributes:
        id (str): Unique cross-section location id.
        branchid (str, optional): Branch on which the cross section is located.
        chainage (str, optional): Chainage on the branch (m).
        x (str, optional): x-coordinate of the location of the cross section.
        y (str, optional): y-coordinate of the location of the cross section.
        shift (float, optional): Vertical shift of the cross section definition [m]. Defined positive upwards.
        definitionid (str): Id of cross section definition.
    """

    class Comments(INIBasedModel.Comments):
        id: Optional[str] = "Unique cross-section location id."
        branchid: Optional[str] = Field(
            "Branch on which the cross section is located.", alias="branchId"
        )
        chainage: Optional[str] = "Chainage on the branch (m)."

        x: Optional[str] = Field(
            "x-coordinate of the location of the cross section.",
        )
        y: Optional[str] = Field(
            "y-coordinate of the location of the cross section.",
        )
        shift: Optional[str] = Field(
            "Vertical shift of the cross section definition [m]. Defined positive upwards.",
        )
        definitionid: Optional[str] = Field(
            "Id of cross section definition.", alias="definitionId"
        )

    comments: Comments = Comments()

    _header: Literal["CrossSection"] = "CrossSection"
    id: str = Field(alias="id")

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

    x: Optional[float] = Field(None)
    y: Optional[float] = Field(None)

    shift: Optional[float] = Field(0.0)
    definitionid: str = Field(alias="definitionId")

    @root_validator(allow_reuse=True)
    def validate_that_location_specification_is_correct(cls, values: Dict) -> Dict:
        """Validates that the correct location specification is given."""
        return validate_location_specification(
            values,
            config=LocationValidationConfiguration(
                validate_node=False,
                validate_num_coordinates=False,
                validate_location_type=False,
            ),
            fields=LocationValidationFieldNames(x_coordinates="x", y_coordinates="y"),
        )

validate_that_location_specification_is_correct(values)

Validates that the correct location specification is given.

Source code in hydrolib/core/dflowfm/crosssection/models.py
716
717
718
719
720
721
722
723
724
725
726
727
@root_validator(allow_reuse=True)
def validate_that_location_specification_is_correct(cls, values: Dict) -> Dict:
    """Validates that the correct location specification is given."""
    return validate_location_specification(
        values,
        config=LocationValidationConfiguration(
            validate_node=False,
            validate_num_coordinates=False,
            validate_location_type=False,
        ),
        fields=LocationValidationFieldNames(x_coordinates="x", y_coordinates="y"),
    )

CrossSectionDefinition

Bases: INIBasedModel

A [Definition] block for use inside a crosssection definition file, i.e., a CrossDefModel.

This class is intended as an abstract class: various subclasses should define they actual types of crosssection definitions.

Source code in hydrolib/core/dflowfm/crosssection/models.py
 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
class CrossSectionDefinition(INIBasedModel):
    """
    A `[Definition]` block for use inside a crosssection definition file,
    i.e., a [CrossDefModel][hydrolib.core.dflowfm.crosssection.models.CrossDefModel].

    This class is intended as an abstract class: various subclasses should
    define they actual types of crosssection definitions.
    """

    # TODO: would we want to load this from something externally and generate these automatically
    class Comments(INIBasedModel.Comments):
        id: Optional[str] = "Unique cross-section definition id."
        thalweg: Optional[str] = Field(
            "Transverse Y coordinate at which the cross section aligns with the branch "
            + "(Keyword used by GUI only)."
        )

    comments: Comments = Comments()

    _header: Literal["Definition"] = "Definition"

    id: str = Field(alias="id")
    type: str = Field(alias="type")
    thalweg: Optional[float]

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

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

    @classmethod
    def _duplicate_keys_as_list(cls):
        return True

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

    @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 `CrossSectionDefinition`.
        The derived model with an equal crosssection definition type will be initialized.

        Raises:
            ValueError: When the given type is not a known crosssection definition 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)

    @staticmethod
    def _get_friction_root_validator(
        frictionid_attr: str,
        frictiontype_attr: str,
        frictionvalue_attr: str,
    ):
        """
        Make a root_validator that verifies whether the crosssection definition (subclass)
        has a valid friction specification.
        Supposed to be embedded in subclasses for their friction fields.

        Args:
            frictionid_attr: name of the frictionid attribute in the subclass.
            frictiontype_attr: name of the frictiontype attribute in the subclass.
            frictionvalue_attr: name of the frictionvalue attribute in the subclass.

        Returns:
            root_validator: to be embedded in the subclass that needs it.
        """

        def validate_friction_specification(cls, values):
            """
            The actual validator function.

            Args:
            cls: The subclass for which the root_validator is called.
            values (dict): Dictionary of values to create a CrossSectionDefinition subclass.
            """
            frictionid = values.get(frictionid_attr) or ""
            frictiontype = values.get(frictiontype_attr) or ""
            frictionvalue = values.get(frictionvalue_attr) or ""

            if frictionid != "" and (frictiontype != "" or frictionvalue != ""):
                raise ValueError(
                    f"Cross section has duplicate friction specification (both {frictionid_attr} and {frictiontype_attr}/{frictionvalue_attr})."
                )

            return values

        return root_validator(allow_reuse=True)(validate_friction_specification)

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 CrossSectionDefinition. The derived model with an equal crosssection definition type will be initialized.

Raises:

Type Description
ValueError

When the given type is not a known crosssection definition type.

Source code in hydrolib/core/dflowfm/crosssection/models.py
 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
@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 `CrossSectionDefinition`.
    The derived model with an equal crosssection definition type will be initialized.

    Raises:
        ValueError: When the given type is not a known crosssection definition 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)

RectangleCrsDef

Bases: CrossSectionDefinition

Crosssection definition with type=rectangle, to be included in a crossdef file. Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]

All lowercased attributes match with the rectangle input as described in UM Sec.C.16.1.2.

Source code in hydrolib/core/dflowfm/crosssection/models.py
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
class RectangleCrsDef(CrossSectionDefinition):
    """
    Crosssection definition with `type=rectangle`, to be included in a crossdef file.
    Typically inside the definition list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.crossdeffile.definition[..]`

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

    class Comments(CrossSectionDefinition.Comments):
        type: Optional[str] = Field("Cross section type; must read rectangle")
        width: Optional[str] = Field("Width of the rectangle [m].")
        height: Optional[str] = Field("Height of the rectangle [m].")
        closed: Optional[str] = Field("no: Open channel, yes: Closed channel.")
        frictionid: Optional[str] = Field(
            frictionid_description,
            alias="frictionId",
        )
        frictiontype: Optional[str] = Field(
            frictiontype_description,
            alias="frictionType",
        )
        frictionvalue: Optional[str] = Field(
            frictionvalue_description,
            alias="frictionValue",
        )

    comments: Comments = Comments()

    type: Literal["rectangle"] = Field("rectangle")
    width: float
    height: float
    closed: bool = Field(True)
    frictionid: Optional[str] = Field(alias="frictionId")
    frictiontype: Optional[FrictionType] = Field(alias="frictionType")
    frictionvalue: Optional[float] = Field(alias="frictionValue")

    _friction_validator = CrossSectionDefinition._get_friction_root_validator(
        "frictionid", "frictiontype", "frictionvalue"
    )
    _frictiontype_validator = get_enum_validator("frictiontype", enum=FrictionType)

XYZCrsDef

Bases: YZCrsDef, CrossSectionDefinition

Crosssection definition with type=xyz, to be included in a crossdef file. Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]

All lowercased attributes match with the xyz input as described in UM Sec.C.16.1.5.

This class extends the YZCrsDef class with x-coordinates and an optional branchId field. Most other attributes are inherited, but the coordcount is overridden under the Pydantic alias "xyzCount".

Attributes:

Name Type Description
yzcount Optional[int]

dummy attribute that should not be set nor used. Only present to mask the inherited attribute from parent class YZCrsDef.

xyzcount int

Number of XYZ-coordinates. Always use this instead of yzcount.

Source code in hydrolib/core/dflowfm/crosssection/models.py
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
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
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
class XYZCrsDef(YZCrsDef, CrossSectionDefinition):
    """
    Crosssection definition with `type=xyz`, to be included in a crossdef file.
    Typically inside the definition list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.crossdeffile.definition[..]`

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

    This class extends the YZCrsDef class with x-coordinates and an optional
    branchId field. Most other attributes are inherited, but the coordcount
    is overridden under the Pydantic alias "xyzCount".

    Attributes:
        yzcount (Optional[int]): dummy attribute that should not be set nor used.
            Only present to mask the inherited attribute from parent class YZCrsDef.
        xyzcount (int): Number of XYZ-coordinates. Always use this instead of yzcount.
    """

    class Comments(YZCrsDef.Comments):
        type: Optional[str] = Field("Cross section type; must read xyz", alias="type")
        branchid: Optional[str] = Field(
            "Branch on which the cross section is located.", alias="branchId"
        )
        xyzcount: Optional[str] = Field("Number of XYZ-coordinates.", alias="xyzCount")
        xCoordinates: Optional[str] = Field(
            "Space separated list of x-coordinates [m or degrees East].",
            alias="xCoordinates",
        )
        yCoordinates: Optional[str] = Field(
            "Space separated list of y-coordinates [m or degrees North].",
            alias="yCoordinates",
        )
        zCoordinates: Optional[str] = Field(
            "Space separated list of z-coordinates [m AD].",
            alias="zCoordinates",
        )

    comments: Comments = Comments()

    type: Literal["xyz"] = Field("xyz")
    branchid: Optional[str] = Field(alias="branchId")
    yzcount: Optional[int] = Field(
        alias="yzCount"
    )  # Trick to not inherit parent's yzcount required field.
    xyzcount: int = Field(alias="xyzCount")
    xcoordinates: List[float] = Field(alias="xCoordinates")

    _split_to_list0 = get_split_string_on_delimiter_validator(
        "xcoordinates",
    )

    @validator("xyzcount")
    @classmethod
    def validate_xyzcount_without_yzcount(cls, field_value: int, values: dict) -> int:
        """
        Validates whether this XYZCrsDef does have attribute xyzcount,
        but not the parent class's yzcount.

        Args:
            field_value (Optional[Path]): Value given for xyzcount.
            values (dict): Dictionary of values already validated.

        Raises:
            ValueError: When yzcount is present.

        Returns:
            int: The value given for xyzcount.
        """
        # Retrieve the algorithm value (if not found use 0).
        yzcount_value = values.get("yzcount")
        if field_value is not None and yzcount_value is not None:
            # yzcount should not be set, when xyzcount is set.
            raise ValueError(
                f"xyz cross section definition should not contain field yzCount (rather: xyzCount), current value: {yzcount_value}."
            )
        return field_value

    @root_validator(allow_reuse=True)
    def check_list_lengths_coordinates(cls, values):
        """Validates that the length of the xcoordinates, ycoordinates and zcoordinates field are as expected."""
        return validate_correct_length(
            values,
            "xcoordinates",
            "ycoordinates",
            "zcoordinates",
            length_name="xyzcount",
        )

check_list_lengths_coordinates(values)

Validates that the length of the xcoordinates, ycoordinates and zcoordinates field are as expected.

Source code in hydrolib/core/dflowfm/crosssection/models.py
655
656
657
658
659
660
661
662
663
664
@root_validator(allow_reuse=True)
def check_list_lengths_coordinates(cls, values):
    """Validates that the length of the xcoordinates, ycoordinates and zcoordinates field are as expected."""
    return validate_correct_length(
        values,
        "xcoordinates",
        "ycoordinates",
        "zcoordinates",
        length_name="xyzcount",
    )

validate_xyzcount_without_yzcount(field_value, values) classmethod

Validates whether this XYZCrsDef does have attribute xyzcount, but not the parent class's yzcount.

Parameters:

Name Type Description Default
field_value Optional[Path]

Value given for xyzcount.

required
values dict

Dictionary of values already validated.

required

Raises:

Type Description
ValueError

When yzcount is present.

Returns:

Name Type Description
int int

The value given for xyzcount.

Source code in hydrolib/core/dflowfm/crosssection/models.py
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
@validator("xyzcount")
@classmethod
def validate_xyzcount_without_yzcount(cls, field_value: int, values: dict) -> int:
    """
    Validates whether this XYZCrsDef does have attribute xyzcount,
    but not the parent class's yzcount.

    Args:
        field_value (Optional[Path]): Value given for xyzcount.
        values (dict): Dictionary of values already validated.

    Raises:
        ValueError: When yzcount is present.

    Returns:
        int: The value given for xyzcount.
    """
    # Retrieve the algorithm value (if not found use 0).
    yzcount_value = values.get("yzcount")
    if field_value is not None and yzcount_value is not None:
        # yzcount should not be set, when xyzcount is set.
        raise ValueError(
            f"xyz cross section definition should not contain field yzCount (rather: xyzCount), current value: {yzcount_value}."
        )
    return field_value

YZCrsDef

Bases: CrossSectionDefinition

Crosssection definition with type=yz, to be included in a crossdef file. Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]

All lowercased attributes match with the yz input as described in UM Sec.C.16.1.6.

Source code in hydrolib/core/dflowfm/crosssection/models.py
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
494
495
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
class YZCrsDef(CrossSectionDefinition):
    """
    Crosssection definition with `type=yz`, to be included in a crossdef file.
    Typically inside the definition list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.crossdeffile.definition[..]`

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

    class Comments(CrossSectionDefinition.Comments):
        type: Optional[str] = Field("Cross section type; must read yz", alias="type")
        conveyance: Optional[str] = Field(
            "lumped: Lumped, segmented: Vertically segmented. Only the default lumped "
            + "option is allowed if singleValuedZ = no. In the case of lumped conveyance, "
            + "only a single uniform roughness for the whole cross section is allowed, "
            + "i.e., sectionCount must equal 1.",
        )
        yzcount: Optional[str] = Field("Number of YZ-coordinates.", alias="yzCount")
        yCoordinates: Optional[str] = Field(
            "Space separated list of monotonic increasing y-coordinates [m].",
            alias="yCoordinates",
        )
        zCoordinates: Optional[str] = Field(
            "Space separated list of single-valued z-coordinates [m AD].",
            alias="zCoordinates",
        )
        sectioncount: Optional[str] = Field(
            "Number of roughness sections. If the lumped conveyance is selected then "
            + "sectionCount must equal 1.",
            alias="sectionCount",
        )
        frictionpositions: Optional[str] = Field(
            "Locations where the roughness sections start and end. Always one location more than "
            + "sectionCount. The first value should equal 0 and the last value should equal the "
            + "cross section length. Keyword may be skipped if sectionCount = 1.",
            alias="frictionPositions",
        )
        frictionids: Optional[str] = Field(
            "Semicolon separated list of roughness variable names associated with the roughness "
            + "sections. Either this parameter or frictionTypes should be specified. If neither "
            + 'parameter is specified, the frictionIds default to "Main", "FloodPlain1" '
            + 'and "FloodPlain2".',
            alias="frictionIds",
        )
        frictiontypes: Optional[str] = Field(
            "Semicolon separated list of roughness types associated with the roughness sections. "
            + "Either this parameter or frictionIds should be specified. Can be specified as a "
            + "single value if all roughness sections use the same type.",
            alias="frictionTypes",
        )
        frictionvalues: Optional[str] = Field(
            "Space separated list of roughness values; their meaning depends on the roughness "
            + "types selected (only used if frictionTypes specified).",
            alias="frictionValues",
        )

    comments: Comments = Comments()

    type: Literal["yz"] = Field("yz")
    singlevaluedz: Optional[bool] = Field(alias="singleValuedZ")
    yzcount: int = Field(alias="yzCount")
    ycoordinates: List[float] = Field(alias="yCoordinates")
    zcoordinates: List[float] = Field(alias="zCoordinates")
    conveyance: Optional[str] = Field("segmented")
    sectioncount: Optional[int] = Field(1, alias="sectionCount")
    frictionpositions: Optional[List[float]] = Field(alias="frictionPositions")
    frictionids: Optional[List[str]] = Field(alias="frictionIds", delimiter=";")
    frictiontypes: Optional[List[FrictionType]] = Field(
        alias="frictionTypes", delimiter=";"
    )
    frictionvalues: Optional[List[float]] = Field(alias="frictionValues")

    _split_to_list = get_split_string_on_delimiter_validator(
        "ycoordinates",
        "zcoordinates",
        "frictionpositions",
        "frictionvalues",
        "frictionids",
        "frictiontypes",
    )

    @root_validator(allow_reuse=True)
    def check_list_lengths_coordinates(cls, values):
        """Validates that the length of the ycoordinates and zcoordinates fields are as expected."""
        return validate_correct_length(
            values,
            "ycoordinates",
            "zcoordinates",
            length_name="yzcount",
        )

    @root_validator(allow_reuse=True)
    def check_list_lengths_friction(cls, values):
        """Validates that the length of the frictionids, frictiontypes and frictionvalues field are as expected."""
        return validate_correct_length(
            values,
            "frictionids",
            "frictiontypes",
            "frictionvalues",
            length_name="sectioncount",
        )

    @root_validator(allow_reuse=True)
    def check_list_length_frictionpositions(cls, values):
        """Validates that the length of the frictionpositions field is as expected."""
        return validate_correct_length(
            values,
            "frictionpositions",
            length_name="sectioncount",
            length_incr=1,  # 1 extra for frictionpositions
        )

    _friction_validator = CrossSectionDefinition._get_friction_root_validator(
        "frictionids", "frictiontypes", "frictionvalues"
    )
    _frictiontype_validator = get_enum_validator("frictiontypes", enum=FrictionType)

check_list_length_frictionpositions(values)

Validates that the length of the frictionpositions field is as expected.

Source code in hydrolib/core/dflowfm/crosssection/models.py
562
563
564
565
566
567
568
569
570
@root_validator(allow_reuse=True)
def check_list_length_frictionpositions(cls, values):
    """Validates that the length of the frictionpositions field is as expected."""
    return validate_correct_length(
        values,
        "frictionpositions",
        length_name="sectioncount",
        length_incr=1,  # 1 extra for frictionpositions
    )

check_list_lengths_coordinates(values)

Validates that the length of the ycoordinates and zcoordinates fields are as expected.

Source code in hydrolib/core/dflowfm/crosssection/models.py
541
542
543
544
545
546
547
548
549
@root_validator(allow_reuse=True)
def check_list_lengths_coordinates(cls, values):
    """Validates that the length of the ycoordinates and zcoordinates fields are as expected."""
    return validate_correct_length(
        values,
        "ycoordinates",
        "zcoordinates",
        length_name="yzcount",
    )

check_list_lengths_friction(values)

Validates that the length of the frictionids, frictiontypes and frictionvalues field are as expected.

Source code in hydrolib/core/dflowfm/crosssection/models.py
551
552
553
554
555
556
557
558
559
560
@root_validator(allow_reuse=True)
def check_list_lengths_friction(cls, values):
    """Validates that the length of the frictionids, frictiontypes and frictionvalues field are as expected."""
    return validate_correct_length(
        values,
        "frictionids",
        "frictiontypes",
        "frictionvalues",
        length_name="sectioncount",
    )

ZWCrsDef

Bases: CrossSectionDefinition

Crosssection definition with type=zw, to be included in a crossdef file. Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]

All lowercased attributes match with the zw input as described in UM Sec.C.16.1.4.

Source code in hydrolib/core/dflowfm/crosssection/models.py
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
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
class ZWCrsDef(CrossSectionDefinition):
    """
    Crosssection definition with `type=zw`, to be included in a crossdef file.
    Typically inside the definition list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.crossdeffile.definition[..]`

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

    class Comments(CrossSectionDefinition.Comments):
        type: Optional[str] = Field("Cross section type; must read zw", alias="type")
        # NOTE: Field "template" deliberately ignored for now.
        numlevels: Optional[str] = Field(
            "Number of levels in the table.", alias="numLevels"
        )
        levels: Optional[str] = Field(
            "Space separated list of monotonic increasing heights/levels [m AD].",
            alias="levels",
        )
        flowwidths: Optional[str] = Field(
            "Space separated list of flow widths at the selected heights [m)].",
            alias="flowWidths",
        )
        totalwidths: Optional[str] = Field(
            "Space separated list of total widths at the selected heights [m]. "
            "Equal to flowWidths if not specified. If specified, the totalWidths"
            "should be larger than flowWidths.",
            alias="totalWidths",
        )
        frictionid: Optional[str] = Field(
            frictionid_description,
            alias="frictionId",
        )
        frictiontype: Optional[str] = Field(
            frictiontype_description,
            alias="frictionType",
        )
        frictionvalue: Optional[str] = Field(
            frictionvalue_description,
            alias="frictionValue",
        )

    comments: Comments = Comments()

    type: Literal["zw"] = Field("zw")
    numlevels: int = Field(alias="numLevels")
    levels: List[float]
    flowwidths: List[float] = Field(alias="flowWidths")
    totalwidths: Optional[List[float]] = Field(alias="totalWidths")
    frictionid: Optional[str] = Field(alias="frictionId")
    frictiontype: Optional[FrictionType] = Field(alias="frictionType")
    frictionvalue: Optional[float] = Field(alias="frictionValue")

    _split_to_list = get_split_string_on_delimiter_validator(
        "levels",
        "flowwidths",
        "totalwidths",
    )

    @root_validator(allow_reuse=True)
    def check_list_lengths(cls, values):
        """Validates that the length of the levels, flowwidths and totalwidths fields are as expected."""
        return validate_correct_length(
            values,
            "levels",
            "flowwidths",
            "totalwidths",
            length_name="numlevels",
        )

    _friction_validator = CrossSectionDefinition._get_friction_root_validator(
        "frictionid", "frictiontype", "frictionvalue"
    )
    _frictiontype_validator = get_enum_validator("frictiontype", enum=FrictionType)

check_list_lengths(values)

Validates that the length of the levels, flowwidths and totalwidths fields are as expected.

Source code in hydrolib/core/dflowfm/crosssection/models.py
443
444
445
446
447
448
449
450
451
452
@root_validator(allow_reuse=True)
def check_list_lengths(cls, values):
    """Validates that the length of the levels, flowwidths and totalwidths fields are as expected."""
    return validate_correct_length(
        values,
        "levels",
        "flowwidths",
        "totalwidths",
        length_name="numlevels",
    )

ZWRiverCrsDef

Bases: CrossSectionDefinition

Crosssection definition with type=zwRiver, to be included in a crossdef file. Typically inside the definition list of a FMModel.geometry.crossdeffile.definition[..]

All lowercased attributes match with the zwRiver input as described in UM Sec.C.16.1.3.

Source code in hydrolib/core/dflowfm/crosssection/models.py
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
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
353
354
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
class ZWRiverCrsDef(CrossSectionDefinition):
    """
    Crosssection definition with `type=zwRiver`, to be included in a crossdef file.
    Typically inside the definition list of a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.crossdeffile.definition[..]`

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

    class Comments(CrossSectionDefinition.Comments):
        type: Optional[str] = Field(
            "Cross section type; must read zwRiver", alias="type"
        )
        numlevels: Optional[str] = Field(
            "Number of levels in the table.", alias="numLevels"
        )
        levels: Optional[str] = Field(
            "Space separated list of monotonic increasing heights/levels [m AD].",
            alias="levels",
        )
        flowwidths: Optional[str] = Field(
            "Space separated list of flow widths at the selected heights [m)].",
            alias="flowWidths",
        )
        totalwidths: Optional[str] = Field(
            "Space separated list of total widths at the selected heights [m]. "
            "Equal to flowWidths if not specified. If specified, the totalWidths"
            "should be larger than flowWidths.",
            alias="totalWidths",
        )
        leveecrestLevel: Optional[str] = Field(
            "Crest level of levee [m AD].", alias="leveeCrestlevel"
        )
        leveebaselevel: Optional[str] = Field(
            "Base level of levee [m AD].", alias="leveeBaseLevel"
        )
        leveeflowarea: Optional[str] = Field(
            "Flow area behind levee [m2].", alias="leveeFlowArea"
        )
        leveetotalarea: Optional[str] = Field(
            "Total area behind levee [m2].", alias="leveeTotalArea"
        )
        mainwidth: Optional[str] = Field(
            "Width of main section [m]. Default value: max(flowWidths).",
            alias="mainWidth",
        )
        fp1width: Optional[str] = Field(
            "Width of floodplain 1 section [m]. Default value: max(flowWidths)-mainWidth",
            alias="fp1Width",
        )
        fp2width: Optional[str] = Field(
            "Width of floodplain 2 section [m]. Default value: max(flowWidths)-mainWidth-fp1Width",
            alias="fp2Width",
        )
        frictionids: Optional[str] = Field(
            "Semicolon separated list of roughness variable names associated with the roughness "
            "sections. Either this parameter or frictionTypes should be specified. If neither "
            'parameter is specified, the frictionIds default to "Main", "FloodPlain1" '
            'and "FloodPlain2".',
            alias="frictionIds",
        )
        frictiontypes: Optional[str] = Field(
            "Semicolon separated list of roughness types associated with the roughness sections. "
            "Either this parameter or frictionIds should be specified. Can be specified as a "
            "single value if all roughness sections use the same type.",
            alias="frictionTypes",
        )
        frictionvalues: Optional[str] = Field(
            "Space separated list of roughness values; their meaning depends on the roughness "
            "types selected (only used if frictionTypes specified).",
            alias="frictionValues",
        )

    comments: Comments = Comments()

    type: Literal["zwRiver"] = Field("zwRiver")
    numlevels: int = Field(alias="numLevels")
    levels: List[float]
    flowwidths: List[float] = Field(alias="flowWidths")
    totalwidths: Optional[List[float]] = Field(alias="totalWidths")
    leveecrestLevel: Optional[float] = Field(alias="leveeCrestlevel")
    leveebaselevel: Optional[float] = Field(alias="leveeBaseLevel")
    leveeflowarea: Optional[float] = Field(alias="leveeFlowArea")
    leveetotalrea: Optional[float] = Field(alias="leveeTotalArea")
    mainwidth: Optional[float] = Field(alias="mainWidth")
    fp1width: Optional[float] = Field(alias="fp1Width")
    fp2width: Optional[float] = Field(alias="fp2Width")
    frictionids: Optional[List[str]] = Field(alias="frictionIds", delimiter=";")
    frictiontypes: Optional[List[FrictionType]] = Field(
        alias="frictionTypes", delimiter=";"
    )
    frictionvalues: Optional[List[float]] = Field(alias="frictionValues")

    _split_to_list = get_split_string_on_delimiter_validator(
        "levels",
        "flowwidths",
        "totalwidths",
        "frictionvalues",
        "frictionids",
        "frictiontypes",
    )

    _friction_validator = CrossSectionDefinition._get_friction_root_validator(
        "frictionids", "frictiontypes", "frictionvalues"
    )
    _frictiontype_validator = get_enum_validator("frictiontypes", enum=FrictionType)

    @root_validator(allow_reuse=True)
    def check_list_lengths(cls, values):
        """Validates that the length of the levels, flowwidths and totalwidths fields are as expected."""
        return validate_correct_length(
            values,
            "levels",
            "flowwidths",
            "totalwidths",
            length_name="numlevels",
        )

check_list_lengths(values)

Validates that the length of the levels, flowwidths and totalwidths fields are as expected.

Source code in hydrolib/core/dflowfm/crosssection/models.py
372
373
374
375
376
377
378
379
380
381
@root_validator(allow_reuse=True)
def check_list_lengths(cls, values):
    """Validates that the length of the levels, flowwidths and totalwidths fields are as expected."""
    return validate_correct_length(
        values,
        "levels",
        "flowwidths",
        "totalwidths",
        length_name="numlevels",
    )