Skip to content

1D field INI files

The 1D field INI files contain the spatial input data for 1D network initial conditions for a D-Flow FM model.

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

The 1D field INI file is represented by the classes below.

Model

One-dimensional field model definitions for D-Flow FM.

OneDFieldBranch

Bases: INIBasedModel

A [Branch] block for use inside a 1D field file.

Each block can define value(s) on a particular branch.

Source code in hydrolib/core/dflowfm/onedfield/models.py
 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
class OneDFieldBranch(INIBasedModel):
    """
    A `[Branch]` block for use inside a 1D field file.

    Each block can define value(s) on a particular branch.
    """

    class Comments(INIBasedModel.Comments):
        """Comments for the OneDFieldBranch section fields."""

        branchid: Optional[str] = Field("The name of the branch", alias="branchId")
        numlocations: Optional[str] = Field(
            "Number of locations on branch. The default 0 value implies branch uniform values.",
            alias="numLocations",
        )
        chainage: Optional[str] = Field(
            "Space separated list of locations on the branch (m). Locations sorted by increasing chainage. The keyword must be specified if numLocations >0.",
            alias="chainage",
        )
        values: Optional[str] = Field(
            "Space separated list of numLocations values; one for each chainage specified. One value required if numLocations =0",
            alias="values",
        )

    comments: Comments = Comments()
    _header: Literal["Branch"] = "Branch"

    branchid: str = Field(alias="branchId")
    numlocations: Optional[NonNegativeInt] = Field(0, alias="numLocations")
    chainage: Optional[List[float]] = Field(None, alias="chainage")
    values: List[float] = Field(alias="values")

    @field_validator("chainage", "values", mode="before")
    @classmethod
    def _split_to_list(cls, v, info: ValidationInfo):
        return split_string_on_delimiter(cls, v, info)

    @model_validator(mode="after")
    def check_list_length_values(self) -> "OneDFieldBranch":
        """Validates that the length of the values field is as expected."""
        validate_correct_length(
            self.model_dump(),
            "values",
            length_name="numlocations",
            list_required_with_length=True,
            min_length=1,
        )
        return self

    @model_validator(mode="after")
    def check_list_length_chainage(self) -> "OneDFieldBranch":
        """Validates that the length of the chainage field is as expected."""
        validate_correct_length(
            self.model_dump(),
            "chainage",
            length_name="numlocations",
            list_required_with_length=True,
        )
        return self

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

Comments

Bases: Comments

Comments for the OneDFieldBranch section fields.

Source code in hydrolib/core/dflowfm/onedfield/models.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class Comments(INIBasedModel.Comments):
    """Comments for the OneDFieldBranch section fields."""

    branchid: Optional[str] = Field("The name of the branch", alias="branchId")
    numlocations: Optional[str] = Field(
        "Number of locations on branch. The default 0 value implies branch uniform values.",
        alias="numLocations",
    )
    chainage: Optional[str] = Field(
        "Space separated list of locations on the branch (m). Locations sorted by increasing chainage. The keyword must be specified if numLocations >0.",
        alias="chainage",
    )
    values: Optional[str] = Field(
        "Space separated list of numLocations values; one for each chainage specified. One value required if numLocations =0",
        alias="values",
    )

check_list_length_chainage()

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

Source code in hydrolib/core/dflowfm/onedfield/models.py
115
116
117
118
119
120
121
122
123
124
@model_validator(mode="after")
def check_list_length_chainage(self) -> "OneDFieldBranch":
    """Validates that the length of the chainage field is as expected."""
    validate_correct_length(
        self.model_dump(),
        "chainage",
        length_name="numlocations",
        list_required_with_length=True,
    )
    return self

check_list_length_values()

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

Source code in hydrolib/core/dflowfm/onedfield/models.py
103
104
105
106
107
108
109
110
111
112
113
@model_validator(mode="after")
def check_list_length_values(self) -> "OneDFieldBranch":
    """Validates that the length of the values field is as expected."""
    validate_correct_length(
        self.model_dump(),
        "values",
        length_name="numlocations",
        list_required_with_length=True,
        min_length=1,
    )
    return self

OneDFieldGeneral

Bases: INIGeneral

The 1D field file's [General] section with file meta data.

Source code in hydrolib/core/dflowfm/onedfield/models.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class OneDFieldGeneral(INIGeneral):
    """The 1D field file's `[General]` section with file meta data."""

    class Comments(INIBasedModel.Comments):
        """Comments for the OneDFieldGeneral section fields."""

        fileversion: Optional[str] = Field(
            "File version. Do not edit this.", alias="fileVersion"
        )
        filetype: Optional[str] = Field(
            "File type. Should be '1dField'. Do not edit this.",
            alias="fileType",
        )

    comments: Comments = Comments()
    _header: Literal["General"] = "General"

    fileversion: str = Field("2.00", alias="fileVersion")
    filetype: Literal["1dField"] = Field("1dField", alias="fileType")

Comments

Bases: Comments

Comments for the OneDFieldGeneral section fields.

Source code in hydrolib/core/dflowfm/onedfield/models.py
28
29
30
31
32
33
34
35
36
37
class Comments(INIBasedModel.Comments):
    """Comments for the OneDFieldGeneral section fields."""

    fileversion: Optional[str] = Field(
        "File version. Do not edit this.", alias="fileVersion"
    )
    filetype: Optional[str] = Field(
        "File type. Should be '1dField'. Do not edit this.",
        alias="fileType",
    )

OneDFieldGlobal

Bases: INIBasedModel

The [Global] block with a uniform value for use inside a 1D field file.

Source code in hydrolib/core/dflowfm/onedfield/models.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class OneDFieldGlobal(INIBasedModel):
    """The `[Global]` block with a uniform value for use inside a 1D field file."""

    class Comments(INIBasedModel.Comments):
        """Comments for the OneDFieldGlobal section fields."""

        quantity: Optional[str] = Field("The name of the quantity", alias="quantity")
        unit: Optional[str] = Field("The unit of the quantity", alias="unit")
        value: Optional[str] = Field(
            "The global default value for this quantity", alias="value"
        )

    comments: Comments = Comments()
    _header: Literal["Global"] = "Global"

    quantity: str = Field(alias="quantity")
    unit: str = Field(alias="unit")
    value: float = Field(alias="value")

Comments

Bases: Comments

Comments for the OneDFieldGlobal section fields.

Source code in hydrolib/core/dflowfm/onedfield/models.py
49
50
51
52
53
54
55
56
class Comments(INIBasedModel.Comments):
    """Comments for the OneDFieldGlobal section fields."""

    quantity: Optional[str] = Field("The name of the quantity", alias="quantity")
    unit: Optional[str] = Field("The unit of the quantity", alias="unit")
    value: Optional[str] = Field(
        "The global default value for this quantity", alias="value"
    )

OneDFieldModel

Bases: INIModel

The overall 1D field model that contains the contents of a 1D field file.

This model is typically used when a FMModel.geometry.inifieldfile[..].initial[..].datafiletype==DataFileType.onedfield.

Attributes:

Name Type Description
general OneDFieldGeneral

[General] block with file metadata.

global_ Optional[OneDFieldGlobal]

Optional [Global] block with uniform value.

branch List[OneDFieldBranch]

Definitions of [Branch] field values.

Source code in hydrolib/core/dflowfm/onedfield/models.py
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
class OneDFieldModel(INIModel):
    """
    The overall 1D field model that contains the contents of a 1D field file.

    This model is typically used when a [FMModel][hydrolib.core.dflowfm.mdu.models.FMModel]`.geometry.inifieldfile[..].initial[..].datafiletype==DataFileType.onedfield`.

    Attributes:
        general (OneDFieldGeneral): `[General]` block with file metadata.
        global_ (Optional[OneDFieldGlobal]): Optional `[Global]` block with uniform value.
        branch (List[OneDFieldBranch]): Definitions of `[Branch]` field values.
    """

    general: OneDFieldGeneral = OneDFieldGeneral()
    global_: Optional[OneDFieldGlobal] = Field(
        None, alias="global"
    )  # to circumvent built-in kw
    branch: Annotated[List[OneDFieldBranch], BeforeValidator(make_list)] = []

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

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