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
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
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 | 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):
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(alias="chainage")
values: List[float] = Field(alias="values")
_split_to_list = get_split_string_on_delimiter_validator(
"chainage",
"values",
)
@root_validator(allow_reuse=True)
def check_list_length_values(cls, values):
"""Validates that the length of the values field is as expected."""
return validate_correct_length(
values,
"values",
length_name="numlocations",
list_required_with_length=True,
min_length=1,
)
@root_validator(allow_reuse=True)
def check_list_length_chainage(cls, values):
"""Validates that the length of the chainage field is as expected."""
return validate_correct_length(
values,
"chainage",
length_name="numlocations",
list_required_with_length=True,
)
def _get_identifier(self, data: dict) -> Optional[str]:
return data.get("branchid")
|
check_list_length_chainage(values)
Validates that the length of the chainage field is as expected.
Source code in hydrolib/core/dflowfm/onedfield/models.py
101
102
103
104
105
106
107
108
109 | @root_validator(allow_reuse=True)
def check_list_length_chainage(cls, values):
"""Validates that the length of the chainage field is as expected."""
return validate_correct_length(
values,
"chainage",
length_name="numlocations",
list_required_with_length=True,
)
|
check_list_length_values(values)
Validates that the length of the values field is as expected.
Source code in hydrolib/core/dflowfm/onedfield/models.py
90
91
92
93
94
95
96
97
98
99 | @root_validator(allow_reuse=True)
def check_list_length_values(cls, values):
"""Validates that the length of the values field is as expected."""
return validate_correct_length(
values,
"values",
length_name="numlocations",
list_required_with_length=True,
min_length=1,
)
|
OneDFieldGeneral
Bases: INIGeneral
The 1D field file's [General]
section with file meta data.
Source code in hydrolib/core/dflowfm/onedfield/models.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 | class OneDFieldGeneral(INIGeneral):
"""The 1D field file's `[General]` section with file meta data."""
class Comments(INIBasedModel.Comments):
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")
|
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 | class OneDFieldGlobal(INIBasedModel):
"""The `[Global]` block with a uniform value for use inside a 1D field file."""
class Comments(INIBasedModel.Comments):
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")
|
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:
Source code in hydrolib/core/dflowfm/onedfield/models.py
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 | 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(
alias="global"
) # to circumvent built-in kw
branch: List[OneDFieldBranch] = []
_split_to_list = make_list_validator(
"branch",
)
@classmethod
def _ext(cls) -> str:
return ".ini"
@classmethod
def _filename(cls) -> str:
return "1dfield"
|