Skip to content

Commit

Permalink
Merge branch 'main' into chore/665_Fix-quality-gate-issues
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/dflowfm/test_mdu.py
  • Loading branch information
tim-vd-aardweg committed Jul 5, 2024
2 parents cbc92f2 + f22d6bd commit e1ebbee
Show file tree
Hide file tree
Showing 13 changed files with 334 additions and 124 deletions.
48 changes: 46 additions & 2 deletions hydrolib/core/dflowfm/ini/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
from enum import Enum
from math import isnan
from re import compile
from typing import Any, Callable, List, Literal, Optional, Set, Type, Union
from typing import (
Any,
Callable,
List,
Literal,
Optional,
Set,
Type,
Union,
get_args,
get_origin,
)

from pydantic.v1 import Extra, Field, root_validator
from pydantic.v1.class_validators import validator
Expand Down Expand Up @@ -206,7 +217,7 @@ def _to_section(
) -> Section:
props = []
for key, value in self:
if key in self._exclude_fields():
if not self._should_be_serialized(key, value):
continue

field_key = key
Expand All @@ -221,6 +232,39 @@ def _to_section(
props.append(prop)
return Section(header=self._header, content=props)

def _should_be_serialized(self, key: str, value: Any) -> bool:
if key in self._exclude_fields():
return False

field = self.__fields__.get(key)
if not field:
return value is not None

field_type = field.type_
if self._is_union(field_type):
return value is not None or self._union_has_filemodel(field_type)

if self._is_list(field_type):
field_type = get_args(field_type)[0]

return self._value_is_not_none_or_type_is_filemodel(field_type, value)

@staticmethod
def _is_union(field_type: type) -> bool:
return get_origin(field_type) is Union

@staticmethod
def _union_has_filemodel(field_type: type) -> bool:
return any(issubclass(arg, FileModel) for arg in get_args(field_type))

@staticmethod
def _is_list(field_type: type) -> bool:
return get_origin(field_type) is List

@staticmethod
def _value_is_not_none_or_type_is_filemodel(field_type: type, value: Any) -> bool:
return value is not None or issubclass(field_type, FileModel)


Datablock = List[List[Union[float, str]]]

Expand Down
111 changes: 84 additions & 27 deletions hydrolib/core/dflowfm/mdu/models.py

Large diffs are not rendered by default.

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",
]
146 changes: 83 additions & 63 deletions hydrolib/core/dflowfm/research/models.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ AdditionalHistoryOutputFile = # extra history
StatisticsFile = # statistics file
ThetaVertical = 0. # theta vertical for waq
DtProcesses = 0. # waq processes time step
DtMassBalance = 0. # waq mass balance output time step
ProcessFluxIntegration = 1 # Process fluxes integration option (1: WAQ, 2: D-Flow FM)
Wriwaqbot3Doutput = 0 # Write 3D water quality bottom variables (1: yes, 0: no)
VolumeDryThreshold = 1.d-3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ Jbasqbnddownwindhs = 0 # 0
cstbnd = 0 # Delft-3D type velocity treatment near boundaries for small coastal models (1) or not (0)
Maxitverticalforestersal = 100 # 0 : no vertical filter, > 0 = Max nr of iterations
Maxitverticalforestertem = 0 # 0 : no vertical filter for temp, > 0 = Max nr of iterations
Jaorgsethu = 1 # Velocity reconstruction scheme (0 : setumod, sethu, setau sequence, 1 : sethu, setau, setumod sequence (standard))
Turbulencemodel = 3 # 0=no, 1 = constant, 2 = algebraic, 3 = k-eps, 4 = k-tau
Turbulenceadvection = 3 # 0=no, 3 = hor. expl., vert. impl.
AntiCreep = 0 # Include anti-creep calculation, (0=no, 1=yes)
Expand All @@ -87,7 +86,6 @@ UnifFrictCoef = 0.1 # U
UnifFrictType = 2 # 0=Chezy, 1=Manning, 2=White Colebrook, 3=idem, WAQUA style
UnifFrictCoef1D = 2.3d-2 # Uniform friction coefficient in 1D links, 0=no friction
UnifFrictCoefLin = 0. # Uniform linear friction coefficient for ocean models (m/s), 0=no
Umodlin = 0 # Use 1 for linear friction umod, for ifrctyp=4,5,6
Vicouv = 0.0 # Uniform horizontal eddy viscosity (m2/s)
Dicouv = 0.0000000 # Uniform horizontal eddy diffusivity (m2/s)
Vicoww = 0. # Uniform vertical eddy viscosity (m2/s)
Expand Down Expand Up @@ -116,7 +114,6 @@ Secchidepth = 1. # W
Stanton = -1. # Coefficient for convective heat flux ( ) , if negative, Cd wind*abs(Stanton)
Dalton = -1. # Coefficient for evaporative heat flux ( ), if negative, Cd wind*abs(Dalton)
SecondaryFlow = 0 # Secondary flow (0=no, 1=yes)
EffectSpiral = 0. # Factor for weighing the effect of the spiral flow intensity on transport angle
BetaSpiral = 0. # Factor for weighing the effect of the spiral flow on flow dispersion stresses

[grw]
Expand All @@ -135,7 +132,6 @@ Gapres = 101325.0000000 # O

[waves]
Wavemodelnr = 0 # Wave model nr, 0=no, 1=fetch/depth limited hurdlestive, 2=youngverhagen, 3 = Delft3D-WAVE, 4=wave group forcing
WaveNikuradse = 1.d-2 # Wave friction Nikuradse ks coefficient, used in Krone Swart, e.g. 0.01 m
Rouwav = # Friction model for wave induced shear stress
Gammax = 1. # Maximum wave height/water depth ratio

Expand Down Expand Up @@ -169,11 +165,9 @@ XLSInterval = # I
MapFile = # *_map.nc Map file in NetCDF format.
MapInterval = 0.0 # Map file output, given as "interval" "start period" "end period" (s)
RstInterval = 0.0 # Restart file output, given as "interval" "start period" "end period" (s)
S1incinterval = # Interval (m) in incremental file for waterlevels S1
WaqFileBase = # Basename (without extension) for all Delwaq files to be written.
WaqInterval = # Interval (in s) between Delwaq file outputs
StatsInterval = # Interval (in s) between simulation statistics output.
Writebalancefile = 0 # Write Balancefile, 1=yes, 0=no
TimingsInterval = # Timings output interval
TimeSplitInterval = 0X # Time splitting interval, after which a new output file is started. value+unit, e.g. '1 M', valid units: Y,M,D,h,m,s.
MapFormat = 4 # Map file format, 1: netCDF, 2: Tecplot, 3: netCFD and Tecplot, 4: NetCDF-UGRID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ TimeStepType = 2 #
Limtyphu = 0 # Limiter type for waterdepth in continuity eq., 0=no, 1=minmod,2=vanLeer,3=Kooren,4=Monotone Central
Limtypmom = 4 # Limiter type for cell center advection velocity, 0=no, 1=minmod,2=vanLeer,3=Kooren,4=Monotone Central
Limtypsa = 4 # Limiter type for salinity transport, 0=no, 1=minmod,2=vanLeer,3=Kooren,4=Monotone Central
TransportMethod = 1 # Transport method, 0=Herman method, 1=Sander method
Vertadvtypsal = 5 # Vertical advection type for salinity, 0=No, 1=UpwexpL, 2=Centralexpl, 3=UpwimpL, 4=CentraLimpL, 5=4 but 3 for neg. stratif., 6=higher order expl, no forester
Horadvtypzlayer = 0 # Horizontal advection treatment zlayer, 1=default, 2 = Sigma like
Icgsolver = 4 # Solver type , 1 = sobekGS_OMP, 2 = sobekGS_OMPthreadsafe, 3 = sobekGS, 4 = sobekGS + Saadilud, 5 = parallel/global Saad, 6 = parallel/Petsc, 7 = parallel/GS
Expand All @@ -72,7 +71,6 @@ Jbasqbnddownwindhs = 0 # 0
cstbnd = 0 # Delft-3D type velocity treatment near boundaries for small coastal models (1) or not (0)
Maxitverticalforestersal = 100 # 0 : no vertical filter, > 0 = Max nr of iterations
Maxitverticalforestertem = 0 # 0 : no vertical filter for temp, > 0 = Max nr of iterations
Jaorgsethu = 1 # Velocity reconstruction scheme (0 : setumod, sethu, setau sequence, 1 : sethu, setau, setumod sequence (standard))
Turbulencemodel = 3 # 0=no, 1 = constant, 2 = algebraic, 3 = k-eps, 4 = k-tau
Turbulenceadvection = 3 # 0=no, 3 = hor. expl., vert. impl.
AntiCreep = 0 # Include anti-creep calculation, (0=no, 1=yes)
Expand All @@ -85,7 +83,6 @@ UnifFrictCoef = 0.1 # U
UnifFrictType = 2 # 0=Chezy, 1=Manning, 2=White Colebrook, 3=idem, WAQUA style
UnifFrictCoef1D = 2.3d-2 # Uniform friction coefficient in 1D links, 0=no friction
UnifFrictCoefLin = 0. # Uniform linear friction coefficient for ocean models (m/s), 0=no
Umodlin = 0 # Use 1 for linear friction umod, for ifrctyp=4,5,6
Vicouv = 0.0 # Uniform horizontal eddy viscosity (m2/s)
Dicouv = 0.0000000 # Uniform horizontal eddy diffusivity (m2/s)
Vicoww = 0. # Uniform vertical eddy viscosity (m2/s)
Expand Down Expand Up @@ -114,7 +111,6 @@ Secchidepth = 1. # W
Stanton = -1. # Coefficient for convective heat flux ( ) , if negative, Cd wind*abs(Stanton)
Dalton = -1. # Coefficient for evaporative heat flux ( ), if negative, Cd wind*abs(Dalton)
SecondaryFlow = 0 # Secondary flow (0=no, 1=yes)
EffectSpiral = 0. # Factor for weighing the effect of the spiral flow intensity on transport angle
BetaSpiral = 0. # Factor for weighing the effect of the spiral flow on flow dispersion stresses

[grw]
Expand All @@ -133,7 +129,6 @@ Gapres = 101325.0000000 # O

[waves]
Wavemodelnr = 0 # Wave model nr, 0=no, 1=fetch/depth limited hurdlestive, 2=youngverhagen, 3 = Delft3D-WAVE, 4=wave group forcing
WaveNikuradse = 1.d-2 # Wave friction Nikuradse ks coefficient, used in Krone Swart, e.g. 0.01 m
Rouwav = # Friction model for wave induced shear stress
Gammax = 1. # Maximum wave height/water depth ratio

Expand Down Expand Up @@ -167,7 +162,6 @@ XLSInterval = # I
MapFile = # *_map.nc Map file in NetCDF format.
MapInterval = 0.0 # Map file output, given as "interval" "start period" "end period" (s)
RstInterval = 0.0 # Restart file output, given as "interval" "start period" "end period" (s)
S1incinterval = # Interval (m) in incremental file for waterlevels S1
WaqFileBase = # Basename (without extension) for all Delwaq files to be written.
WaqInterval = # Interval (in s) between Delwaq file outputs
StatsInterval = # Interval (in s) between simulation statistics output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ PathsRelativeToParent = 0 # Whether or not (1/0) t

[geometry]
NetFile = moergestels_broek_net.nc# Unstructured grid file *_net.nc
BathymetryFile =
OneDNetworkFile = # 1d networkfile
BedlevelFile = # street_level.xyz , Bedlevels points file e.g. *.xyz, only needed for bedlevtype not equal 3
BathymetryFile =
DryPointsFile = # Dry points file *.xyz (third column dummy z values), or dry areas polygon file *.pol (third column 1/-1: inside/outside)
WaterLevIniFile = # Initial water levels sample file *.xyz
LandBoundaryFile = structures.ldb # Land boundaries file *.ldb, used for visualization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ UnifFrictCoef1D = 2.3d-2 # Uniform fricti
UnifFrictCoef1D2D = 2.3d-2 # Uniform friction coefficient in 1D links (0: no friction)
UnifFrictCoefLin = 0. # Uniform linear friction coefficient (0: no friction)
UnifFrictCoef1DgrLay = 5.d-2 # Uniform ground layer friction coefficient for ocean models (m/s) (0: no friction)
Umodlin = 0. # Linear friction umod, for ifrctyp=4,5,6
Vicouv = 1. # Uniform horizontal eddy viscosity (m2/s)
Dicouv = 1. # Uniform horizontal eddy diffusivity (m2/s)
Vicoww = 5.d-5 # Uniform vertical eddy viscosity (m2/s)
Expand Down Expand Up @@ -350,7 +349,7 @@ AutoTimestepNoQout = 1 # 0 = no, 1 = ye
Tunit = S # Time unit for start/stop times (D, H, M or S)
TStart = 410227200. # Start time w.r.t. RefDate (in TUnit)
TStop = 410270400. # Stop time w.r.t. RefDate (in TUnit)
TStartTlfsmo = 0. # Start time of smoothing of boundary conditions (Tlfsmo) w.r.t. RefDate (in TUnit)
TStartTlfsmo = 1.1 # Start time of smoothing of boundary conditions (Tlfsmo) w.r.t. RefDate (in TUnit)
Startdatetime = 20140101000000 # Computation Startdatetime (yyyymmddhhmmss), when specified, overrides Tstart
Stopdatetime = 20140101120000 # Computation Stopdatetime (yyyymmddhhmmss), when specified, overrides Tstop
UpdateRoughnessInterval = 86400. # Update interval for time dependent roughness parameters (in s)
Expand Down Expand Up @@ -543,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
Loading

0 comments on commit e1ebbee

Please sign in to comment.