Skip to content

Commit

Permalink
feat: Add support for optional [sedtrails] research section. (#651)
Browse files Browse the repository at this point in the history
refs: #620
  • Loading branch information
tim-vd-aardweg authored Jul 5, 2024
1 parent aa0af4c commit f22d6bd
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
2 changes: 2 additions & 0 deletions hydrolib/core/dflowfm/research/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ResearchProcesses,
ResearchRestart,
ResearchSediment,
ResearchSedtrails,
ResearchTime,
ResearchTrachytopes,
ResearchWaves,
Expand All @@ -28,4 +29,5 @@
"ResearchTrachytopes",
"ResearchWaves",
"ResearchWind",
"ResearchSedtrails",
]
46 changes: 45 additions & 1 deletion hydrolib/core/dflowfm/research/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import List, Literal, Optional

from pydantic.v1 import Field

Expand All @@ -19,6 +19,8 @@
Waves,
Wind,
)
from hydrolib.core.dflowfm.ini.models import INIBasedModel
from hydrolib.core.dflowfm.ini.util import get_split_string_on_delimiter_validator


class ResearchGeneral(General):
Expand Down Expand Up @@ -863,6 +865,47 @@ class Comments(Processes.Comments):
)


class ResearchSedtrails(INIBasedModel):
"""The `[Sedtrails]` section in an MDU file."""

class Comments(INIBasedModel.Comments):
research_sedtrailsgrid: Optional[str] = Field(
"Grid file for sedtrails output locations on corners.",
alias="sedtrailsgrid",
)
research_sedtrailsanalysis: Optional[str] = Field(
"Sedtrails analysis. Should be all, transport, flowvelocity or soulsby.",
alias="sedtrailsanalysis",
)
research_sedtrailsinterval: Optional[str] = Field(
"Sedtrails output times (s), interval, starttime, stoptime (s), if starttime, stoptime are left blank, use whole simulation period.",
alias="sedtrailsinterval",
)
research_sedtrailsoutputfile: Optional[str] = Field(
"Sedtrails time-avgd output file.", alias="sedtrailsoutputfile"
)

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

research_sedtrailsgrid: Optional[DiskOnlyFileModel] = Field(
None, alias="sedtrailsgrid"
)
research_sedtrailsanalysis: Optional[
Literal["all", "transport", "flowvelocity", "soulsby"]
] = Field(None, alias="sedtrailsanalysis")
research_sedtrailsinterval: Optional[List[float]] = Field(
None, alias="sedtrailsinterval"
)
research_sedtrailsoutputfile: Optional[DiskOnlyFileModel] = Field(
None, alias="sedtrailsoutputfile"
)

_split_to_list = get_split_string_on_delimiter_validator(
"research_sedtrailsinterval",
)


class ResearchFMModel(FMModel):
"""
An extended FMModel that includes highly experimental research sections and keywords.
Expand All @@ -880,3 +923,4 @@ class ResearchFMModel(FMModel):
trachytopes: ResearchTrachytopes = Field(default_factory=ResearchTrachytopes)
output: ResearchOutput = Field(default_factory=ResearchOutput)
processes: Optional[ResearchProcesses] = Field(None)
sedtrails: Optional[ResearchSedtrails] = Field(None)
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,10 @@ ProcessFluxIntegration = 1 # Process fluxes
Wriwaqbot3Doutput = 0 # Write 3D water quality bottom variables (1: yes, 0: no)
VolumeDryThreshold = 1.d-3 # Volume below which segments are marked as dry. (m3)
DepthDryThreshold = 1.d-3 # Water depth below which segments are marked as dry. (m)
SubstanceDensityCoupling = 0 # Substance density coupling (1: yes, 0: no). It only functions correctly when all substances are sediments.
SubstanceDensityCoupling = 0 # Substance density coupling (1: yes, 0: no). It only functions correctly when all substances are sediments.

[sedtrails]
SedtrailsGrid = c:\test.txt # Grid file for sedtrails output locations on corners
SedtrailsAnalysis = all # Sedtrails analysis. Should be all, transport, flowvelocity or soulsby.
SedtrailsInterval = 3600. 1.1 2.2 # Sedtrails output times (s), interval, starttime, stoptime (s), if starttime, stoptime are left blank, use whole simulation period
SedtrailsOutputFile = d:\test2.txt # Sedtrails time-avgd output file
24 changes: 24 additions & 0 deletions tests/dflowfm/test_research.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ResearchOutput,
ResearchPhysics,
ResearchSediment,
ResearchSedtrails,
ResearchTime,
ResearchTrachytopes,
ResearchWaves,
Expand Down Expand Up @@ -85,3 +86,26 @@ def test_can_save_and_load_research_model_from_scratch_without_errors(self):
mdu = ResearchFMModel()
mdu.save(file_mdu)
_ = ResearchFMModel(file_mdu)

def test_sedtrails_fromscratch(self):
model = ResearchFMModel()
model.sedtrails = ResearchSedtrails()

model.sedtrails.research_sedtrailsgrid = r"c:\random.txt"
model.sedtrails.research_sedtrailsanalysis = "all"
model.sedtrails.research_sedtrailsinterval = [1.0, 2.0, 3.0]
model.sedtrails.research_sedtrailsoutputfile = r"c:\random2.txt"

def test_sedtrails_can_be_loaded_from_mdu(self):
input_mdu = (
test_input_dir
/ "research"
/ "mdu_with_research_keywords_from_dia_file_2024.03_release.mdu"
)

model = ResearchFMModel(filepath=input_mdu)

assert str(model.sedtrails.research_sedtrailsgrid) == r"c:\test.txt"
assert model.sedtrails.research_sedtrailsanalysis == "all"
assert model.sedtrails.research_sedtrailsinterval == [3600.0, 1.1, 2.2]
assert str(model.sedtrails.research_sedtrailsoutputfile) == r"d:\test2.txt"

0 comments on commit f22d6bd

Please sign in to comment.