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

Cross section models for D-Flow FM.

CircleCrsDef

Bases: CrossSectionDefinition

CircleCrsDef.

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
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
class CircleCrsDef(CrossSectionDefinition):
    """CircleCrsDef.

    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):
        """Comments for the CircleCrsDef class."""

        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(None, alias="frictionId")
    frictiontype: Optional[FrictionType] = Field(None, alias="frictionType")
    frictionvalue: Optional[float] = Field(None, alias="frictionValue")

    @model_validator(mode="after")
    def check_friction(self):
        self._check_friction_fields(
            self.frictionid, self.frictiontype, self.frictionvalue, label=self.id
        )
        return self

    @field_validator("frictiontype", mode="before")
    @classmethod
    def validate_enum_frictiontype(cls, v):
        return enum_value_parser(v, FrictionType)

Comments

Bases: Comments

Comments for the CircleCrsDef class.

Source code in hydrolib/core/dflowfm/crosssection/models.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
class Comments(CrossSectionDefinition.Comments):
    """Comments for the CircleCrsDef class."""

    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",
    )

CrossDefGeneral

Bases: INIGeneral

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

Source code in hydrolib/core/dflowfm/crosssection/models.py
42
43
44
45
46
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
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
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: Annotated[
        List[CrossSectionDefinitionUnion], BeforeValidator(make_list)
    ] = []

    @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
49
50
51
52
53
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, The crosssection attribute also accepts single cross section.

Examples:

  • Create the read CrossLocModel class from file.

    >>> from hydrolib.core.dflowfm.crosssection.models import CrossLocModel
    >>> from pathlib import Path
    >>> path = Path("examples/data/crsloc.ini")
    >>> crossloc_model = CrossLocModel(path)
    >>> print(len(crossloc_model.crosssection))
    2
    >>> print(crossloc_model.crosssection[0])
    comments=Comments(id=None, branchid=None, chainage=None, x='x-coordinate of the location of the cross section.', y='y-coordinate of the location of the cross section.', shift=None, definitionid=None) id='Channel1_50.000' branchid='Channel1' chainage=50.0 x=None y=None shift=1.0 definitionid='Prof1'
    

  • Create the CrossLocModel class by providing values for the crosssection attribute.

    >>> data = {
    ...    "id": 99,
    ...    "branchId": 9,
    ...    "chainage": 403,
    ...    "shift": 0.0,
    ...    "definitionId": 99
    ... }
    >>> cross_section = CrossSection(**data)
    >>> crossloc = CrossLocModel(crosssection=cross_section)
    >>> type(crossloc.crosssection)
    <class 'list'>
    >>> len(crossloc.crosssection)
    1
    

  • Create the CrossLocModel class by providing values as a dictionary.

    >>> data = {
    ...     "crosssection": {
    ...         "id": 99,
    ...         "branchId": 9,
    ...         "chainage": 403.089709,
    ...         "shift": 0.0,
    ...         "definitionId": 99,
    ...     }
    ... }
    >>> crossloc = CrossLocModel(**data)
    >>> print(crossloc.crosssection)
    [CrossSection(comments=Comments(id='Unique cross-section location id.', branchid='Branch on which the cross section is located.', chainage='Chainage on the branch (m).', x='x-coordinate of the location of the cross section.', y='y-coordinate of the location of the cross section.', shift='Vertical shift of the cross section definition [m]. Defined positive upwards.', definitionid='Id of cross section definition.'), id='99', branchid='9', chainage=403.089709, x=None, y=None, shift=0.0, definitionid='99')]
    

Source code in hydrolib/core/dflowfm/crosssection/models.py
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
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
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, The crosssection attribute also accepts
            single cross section.

    Examples:
        - Create the read `CrossLocModel` class from file.
        ```python
        >>> from hydrolib.core.dflowfm.crosssection.models import CrossLocModel
        >>> from pathlib import Path
        >>> path = Path("examples/data/crsloc.ini")
        >>> crossloc_model = CrossLocModel(path)
        >>> print(len(crossloc_model.crosssection))
        2
        >>> print(crossloc_model.crosssection[0])
        comments=Comments(id=None, branchid=None, chainage=None, x='x-coordinate of the location of the cross section.', y='y-coordinate of the location of the cross section.', shift=None, definitionid=None) id='Channel1_50.000' branchid='Channel1' chainage=50.0 x=None y=None shift=1.0 definitionid='Prof1'

        ```

        - Create the `CrossLocModel` class by providing values for the `crosssection` attribute.
        ```python
        >>> data = {
        ...    "id": 99,
        ...    "branchId": 9,
        ...    "chainage": 403,
        ...    "shift": 0.0,
        ...    "definitionId": 99
        ... }
        >>> cross_section = CrossSection(**data)
        >>> crossloc = CrossLocModel(crosssection=cross_section)
        >>> type(crossloc.crosssection)
        <class 'list'>
        >>> len(crossloc.crosssection)
        1

        ```

        - Create the `CrossLocModel` class by providing values as a dictionary.
        ```python
        >>> data = {
        ...     "crosssection": {
        ...         "id": 99,
        ...         "branchId": 9,
        ...         "chainage": 403.089709,
        ...         "shift": 0.0,
        ...         "definitionId": 99,
        ...     }
        ... }
        >>> crossloc = CrossLocModel(**data)
        >>> print(crossloc.crosssection)
        [CrossSection(comments=Comments(id='Unique cross-section location id.', branchid='Branch on which the cross section is located.', chainage='Chainage on the branch (m).', x='x-coordinate of the location of the cross section.', y='y-coordinate of the location of the cross section.', shift='Vertical shift of the cross section definition [m]. Defined positive upwards.', definitionid='Id of cross section definition.'), id='99', branchid='9', chainage=403.089709, x=None, y=None, shift=0.0, definitionid='99')]

        ```
    """

    general: CrossLocGeneral = CrossLocGeneral()
    crosssection: List[CrossSection] = Field(default_factory=list)

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

    @field_validator("crosssection", mode="before")
    def ensure_crosssection_is_list(cls, v):
        """Converting the crosssection to a list if it is not already a list."""
        if isinstance(v, list):
            return v
        elif v is None:
            return []
        return [v]

ensure_crosssection_is_list(v)

Converting the crosssection to a list if it is not already a list.

Source code in hydrolib/core/dflowfm/crosssection/models.py
822
823
824
825
826
827
828
829
@field_validator("crosssection", mode="before")
def ensure_crosssection_is_list(cls, v):
    """Converting the crosssection to a list if it is not already a list."""
    if isinstance(v, list):
        return v
    elif v is None:
        return []
    return [v]

CrossSection

Bases: INIBasedModel

Crosssection.

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
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
class CrossSection(INIBasedModel):
    """Crosssection.

    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):
        """Comments for the CrossSection class."""

        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")

    @model_validator(mode="after")
    def validate_that_location_specification_is_correct(self):
        """Validate that the correct location specification is given."""
        validate_location_specification(
            self.model_dump(),
            config=LocationValidationConfiguration(
                validate_node=False,
                validate_num_coordinates=False,
                validate_location_type=False,
            ),
            fields=LocationValidationFieldNames(x_coordinates="x", y_coordinates="y"),
        )
        return self

Comments

Bases: Comments

Comments for the CrossSection class.

Source code in hydrolib/core/dflowfm/crosssection/models.py
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
class Comments(INIBasedModel.Comments):
    """Comments for the CrossSection class."""

    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"
    )

validate_that_location_specification_is_correct()

Validate that the correct location specification is given.

Source code in hydrolib/core/dflowfm/crosssection/models.py
738
739
740
741
742
743
744
745
746
747
748
749
750
@model_validator(mode="after")
def validate_that_location_specification_is_correct(self):
    """Validate that the correct location specification is given."""
    validate_location_specification(
        self.model_dump(),
        config=LocationValidationConfiguration(
            validate_node=False,
            validate_num_coordinates=False,
            validate_location_type=False,
        ),
        fields=LocationValidationFieldNames(x_coordinates="x", y_coordinates="y"),
    )
    return self

CrossSectionDefinition

Bases: INIBasedModel

CrossSectionDefinition.

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
 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
class CrossSectionDefinition(INIBasedModel):
    """CrossSectionDefinition.

    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.
    """

    class Comments(INIBasedModel.Comments):
        """Comments for the CrossSectionDefinition class."""

        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] = None

    @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

    @staticmethod
    def _check_friction_fields(frictionid, frictiontype, frictionvalue, label=""):
        """Check the friction specification.

        Make a model_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:
                name of the frictionid attribute in the subclass.
            frictiontype:
                name of the frictiontype attribute in the subclass.
            frictionvalue:
                name of the frictionvalue attribute in the subclass.

        Raises:
            ValueError:
                If both frictionid and frictiontype/frictionvalue are specified.
        """
        if frictionid and (frictiontype or frictionvalue):
            raise ValueError(
                f"{label} has duplicate friction specification: both frictionid and frictiontype/frictionvalue."
            )

Comments

Bases: Comments

Comments for the CrossSectionDefinition class.

Source code in hydrolib/core/dflowfm/crosssection/models.py
66
67
68
69
70
71
72
class Comments(INIBasedModel.Comments):
    """Comments for the CrossSectionDefinition class."""

    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)."
    )

RectangleCrsDef

Bases: CrossSectionDefinition

RectangleCrsDef.

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
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
class RectangleCrsDef(CrossSectionDefinition):
    """RectangleCrsDef.

    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):
        """Comments for the RectangleCrsDef class."""

        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(None, alias="frictionId")
    frictiontype: Optional[FrictionType] = Field(None, alias="frictionType")
    frictionvalue: Optional[float] = Field(None, alias="frictionValue")

    @model_validator(mode="after")
    def check_friction(self):
        self._check_friction_fields(
            self.frictionid, self.frictiontype, self.frictionvalue, label=self.id
        )
        return self

    @field_validator("frictiontype", mode="before")
    @classmethod
    def validate_enum_frictiontype(cls, v):
        return enum_value_parser(v, FrictionType)

Comments

Bases: Comments

Comments for the RectangleCrsDef class.

Source code in hydrolib/core/dflowfm/crosssection/models.py
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
class Comments(CrossSectionDefinition.Comments):
    """Comments for the RectangleCrsDef class."""

    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",
    )

XYZCrsDef

Bases: YZCrsDef, CrossSectionDefinition

XYZCrsDef.

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
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
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
class XYZCrsDef(YZCrsDef, CrossSectionDefinition):
    """XYZCrsDef.

    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):
        """Comments for the XYZCrsDef class."""

        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(None, alias="branchId")
    yzcount: Optional[int] = Field(
        None, alias="yzCount"
    )  # Trick to not inherit parent's yzcount required field.
    xyzcount: int = Field(alias="xyzCount")
    xcoordinates: List[float] = Field(alias="xCoordinates")

    @field_validator("xcoordinates", mode="before")
    def split_string_xcoordinates(cls, v, info: ValidationInfo):
        return split_string_on_delimiter(cls, v, info)

    @field_validator("xyzcount")
    @classmethod
    def validate_xyzcount_without_yzcount(
        cls, field_value: int, values: ValidationInfo
    ) -> int:
        """Validate the xyzcount field.

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

        Args:
            field_value (Optional[Path]):
                Value given for xyzcount.
            value (int):
                The validated value of xyzcount.

        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.data.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

    @model_validator(mode="after")
    def check_list_lengths_coordinates(self):
        """Validate that the length of the xcoordinates, ycoordinates and zcoordinates field are as expected."""
        validate_correct_length(
            self.model_dump(),
            "xcoordinates",
            "ycoordinates",
            "zcoordinates",
            length_name="xyzcount",
        )
        return self

Comments

Bases: Comments

Comments for the XYZCrsDef class.

Source code in hydrolib/core/dflowfm/crosssection/models.py
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
class Comments(YZCrsDef.Comments):
    """Comments for the XYZCrsDef class."""

    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",
    )

check_list_lengths_coordinates()

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

Source code in hydrolib/core/dflowfm/crosssection/models.py
674
675
676
677
678
679
680
681
682
683
684
@model_validator(mode="after")
def check_list_lengths_coordinates(self):
    """Validate that the length of the xcoordinates, ycoordinates and zcoordinates field are as expected."""
    validate_correct_length(
        self.model_dump(),
        "xcoordinates",
        "ycoordinates",
        "zcoordinates",
        length_name="xyzcount",
    )
    return self

validate_xyzcount_without_yzcount(field_value, values) classmethod

Validate the xyzcount field.

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
value int

The validated value of xyzcount.

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
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
@field_validator("xyzcount")
@classmethod
def validate_xyzcount_without_yzcount(
    cls, field_value: int, values: ValidationInfo
) -> int:
    """Validate the xyzcount field.

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

    Args:
        field_value (Optional[Path]):
            Value given for xyzcount.
        value (int):
            The validated value of xyzcount.

    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.data.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

YZCrsDef.

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
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
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
576
577
578
579
580
581
582
583
584
class YZCrsDef(CrossSectionDefinition):
    """YZCrsDef.

    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):
        """Comments for the YZCrsDef class."""

        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(None, 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(None, alias="frictionPositions")
    frictionids: Optional[List[str]] = Field(
        None, alias="frictionIds", json_schema_extra={"delimiter": ";"}
    )
    frictiontypes: Optional[List[FrictionType]] = Field(
        None, alias="frictionTypes", json_schema_extra={"delimiter": ";"}
    )
    frictionvalues: Optional[List[float]] = Field(None, alias="frictionValues")

    @field_validator(
        "ycoordinates",
        "zcoordinates",
        "frictionpositions",
        "frictionvalues",
        "frictionids",
        "frictiontypes",
        mode="before",
    )
    @classmethod
    def split_string_list(cls, v, info: ValidationInfo):
        return split_string_on_delimiter(cls, v, info)

    @model_validator(mode="after")
    def check_friction(self):
        self._check_friction_fields(
            self.frictionids, self.frictiontypes, self.frictionvalues, label=self.id
        )
        return self

    @field_validator("frictiontypes", mode="before")
    @classmethod
    def validate_enum_frictiontype(cls, v):
        return enum_value_parser(v, FrictionType)

    @model_validator(mode="after")
    def check_list_lengths_coordinates(self):
        """Validate that the length of the ycoordinates and zcoordinates fields are as expected."""
        validate_correct_length(
            self.model_dump(),
            "ycoordinates",
            "zcoordinates",
            length_name="yzcount",
        )
        return self

    @model_validator(mode="after")
    def check_list_lengths_friction(self):
        """Validate that the length of the frictionids, frictiontypes and frictionvalues field are as expected."""
        validate_correct_length(
            self.model_dump(),
            "frictionids",
            "frictiontypes",
            "frictionvalues",
            length_name="sectioncount",
        )
        return self

    @model_validator(mode="after")
    def check_list_length_frictionpositions(self):
        """Validate that the length of the frictionpositions field is as expected."""
        validate_correct_length(
            self.model_dump(),
            "frictionpositions",
            length_name="sectioncount",
            length_incr=1,  # 1 extra for frictionpositions
        )
        return self

Comments

Bases: Comments

Comments for the YZCrsDef class.

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
class Comments(CrossSectionDefinition.Comments):
    """Comments for the YZCrsDef class."""

    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",
    )

check_list_length_frictionpositions()

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

Source code in hydrolib/core/dflowfm/crosssection/models.py
575
576
577
578
579
580
581
582
583
584
@model_validator(mode="after")
def check_list_length_frictionpositions(self):
    """Validate that the length of the frictionpositions field is as expected."""
    validate_correct_length(
        self.model_dump(),
        "frictionpositions",
        length_name="sectioncount",
        length_incr=1,  # 1 extra for frictionpositions
    )
    return self

check_list_lengths_coordinates()

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

Source code in hydrolib/core/dflowfm/crosssection/models.py
552
553
554
555
556
557
558
559
560
561
@model_validator(mode="after")
def check_list_lengths_coordinates(self):
    """Validate that the length of the ycoordinates and zcoordinates fields are as expected."""
    validate_correct_length(
        self.model_dump(),
        "ycoordinates",
        "zcoordinates",
        length_name="yzcount",
    )
    return self

check_list_lengths_friction()

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

Source code in hydrolib/core/dflowfm/crosssection/models.py
563
564
565
566
567
568
569
570
571
572
573
@model_validator(mode="after")
def check_list_lengths_friction(self):
    """Validate that the length of the frictionids, frictiontypes and frictionvalues field are as expected."""
    validate_correct_length(
        self.model_dump(),
        "frictionids",
        "frictiontypes",
        "frictionvalues",
        length_name="sectioncount",
    )
    return self

ZWCrsDef

Bases: CrossSectionDefinition

ZWCrsDef.

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
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
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
class ZWCrsDef(CrossSectionDefinition):
    """ZWCrsDef.

    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):
        """Comments for the ZWCrsDef class."""

        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(None, alias="totalWidths")
    frictionid: Optional[str] = Field(None, alias="frictionId")
    frictiontype: Optional[FrictionType] = Field(None, alias="frictionType")
    frictionvalue: Optional[float] = Field(None, alias="frictionValue")

    @field_validator(
        "levels",
        "flowwidths",
        "totalwidths",
        mode="before",
    )
    @classmethod
    def split_string_list(cls, v, info: ValidationInfo):
        return split_string_on_delimiter(cls, v, info)

    @model_validator(mode="after")
    def check_list_lengths(self):
        """Validate that the length of the levels, flowwidths and totalwidths fields are as expected."""
        validate_correct_length(
            self.model_dump(),
            "levels",
            "flowwidths",
            "totalwidths",
            length_name="numlevels",
        )
        return self

    @model_validator(mode="after")
    def check_friction(self):
        self._check_friction_fields(
            self.frictionid, self.frictiontype, self.frictionvalue, label=self.id
        )
        return self

    @field_validator("frictiontype", mode="before")
    @classmethod
    def validate_enum_frictiontype(cls, v):
        return enum_value_parser(v, FrictionType)

Comments

Bases: Comments

Comments for the ZWCrsDef class.

Source code in hydrolib/core/dflowfm/crosssection/models.py
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
401
402
class Comments(CrossSectionDefinition.Comments):
    """Comments for the ZWCrsDef class."""

    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",
    )

check_list_lengths()

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

Source code in hydrolib/core/dflowfm/crosssection/models.py
425
426
427
428
429
430
431
432
433
434
435
@model_validator(mode="after")
def check_list_lengths(self):
    """Validate that the length of the levels, flowwidths and totalwidths fields are as expected."""
    validate_correct_length(
        self.model_dump(),
        "levels",
        "flowwidths",
        "totalwidths",
        length_name="numlevels",
    )
    return self

ZWRiverCrsDef

Bases: CrossSectionDefinition

ZWRiverCrsDef.

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
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
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
class ZWRiverCrsDef(CrossSectionDefinition):
    """ZWRiverCrsDef.

    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):
        """Comments for the ZWRiverCrsDef class."""

        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(None, alias="totalWidths")
    leveecrestLevel: Optional[float] = Field(None, alias="leveeCrestlevel")
    leveebaselevel: Optional[float] = Field(None, alias="leveeBaseLevel")
    leveeflowarea: Optional[float] = Field(None, alias="leveeFlowArea")
    leveetotalrea: Optional[float] = Field(None, alias="leveeTotalArea")
    mainwidth: Optional[float] = Field(None, alias="mainWidth")
    fp1width: Optional[float] = Field(None, alias="fp1Width")
    fp2width: Optional[float] = Field(None, alias="fp2Width")
    frictionids: Optional[List[str]] = Field(
        None, alias="frictionIds", json_schema_extra={"delimiter": ";"}
    )
    frictiontypes: Optional[List[FrictionType]] = Field(
        None, alias="frictionTypes", json_schema_extra={"delimiter": ";"}
    )
    frictionvalues: Optional[List[float]] = Field(None, alias="frictionValues")

    @field_validator(
        "levels",
        "flowwidths",
        "totalwidths",
        "frictionvalues",
        "frictionids",
        "frictiontypes",
        mode="before",
    )
    @classmethod
    def split_string_list(cls, v, info: ValidationInfo):
        return split_string_on_delimiter(cls, v, info)

    @model_validator(mode="after")
    def check_friction(self):
        self._check_friction_fields(
            self.frictionids, self.frictiontypes, self.frictionvalues, label=self.id
        )
        return self

    @field_validator("frictiontypes", mode="before")
    @classmethod
    def validate_enum_frictiontype(cls, v):
        return enum_value_parser(v, FrictionType)

    @model_validator(mode="after")
    def check_list_lengths(self):
        """Validate that the length of the levels, flowwidths and totalwidths fields are as expected."""
        validate_correct_length(
            self.model_dump(),
            "levels",
            "flowwidths",
            "totalwidths",
            length_name="numlevels",
        )
        return self

Comments

Bases: Comments

Comments for the ZWRiverCrsDef class.

Source code in hydrolib/core/dflowfm/crosssection/models.py
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
287
288
289
290
291
292
293
294
295
296
297
class Comments(CrossSectionDefinition.Comments):
    """Comments for the ZWRiverCrsDef class."""

    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",
    )

check_list_lengths()

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

Source code in hydrolib/core/dflowfm/crosssection/models.py
346
347
348
349
350
351
352
353
354
355
356
@model_validator(mode="after")
def check_list_lengths(self):
    """Validate that the length of the levels, flowwidths and totalwidths fields are as expected."""
    validate_correct_length(
        self.model_dump(),
        "levels",
        "flowwidths",
        "totalwidths",
        length_name="numlevels",
    )
    return self