Command groups¶
Groups of components that SwanConfig takes as one field (startup, inpgrid, forcing, physics, output, lockup), with checks across their commands.
SWAN Components Group Module
This module provides group components for organizing SWAN model configurations in the ROMPY framework.
PROJECT_TYPE
module-attribute
¶
COORDINATES_TYPE
module-attribute
¶
COORDINATES_TYPE = Annotated[
COORDINATES, Field(description="Coordinates component")
]
INPGRID_TYPE
module-attribute
¶
INPGRID_TYPE = Annotated[
Union[REGULAR, CURVILINEAR, UNSTRUCTURED, WIND, ICE],
Field(discriminator="model_type"),
]
NEGATINP_TYPE
module-attribute
¶
QUADRUPL_TYPE
module-attribute
¶
VEGETATION_TYPE
module-attribute
¶
VEGETATION_TYPE = Annotated[
VEGETATION, Field(description="Vegetation component")
]
TURBULENCE_TYPE
module-attribute
¶
TURBULENCE_TYPE = Annotated[
TURBULENCE, Field(description="Turbulence component")
]
LIMITER_TYPE
module-attribute
¶
OBSTACLE_TYPE
module-attribute
¶
DIFFRACTION_TYPE
module-attribute
¶
DIFFRACTION_TYPE = Annotated[
DIFFRACTION, Field(description="Diffraction component")
]
SURFBEAT_TYPE
module-attribute
¶
SCAT_TYPE
module-attribute
¶
OFF_TYPE
module-attribute
¶
GEN_TYPE
module-attribute
¶
GEN_TYPE = Annotated[
Union[GEN1, GEN2, GEN3],
Field(
description="Wave generation component",
discriminator="model_type",
),
]
SSWELL_TYPE
module-attribute
¶
SSWELL_TYPE = Annotated[
Union[SSWELL_ROGERS, SSWELL_ARDHUIN, SSWELL_ZIEGER],
Field(
description="Swell dissipation component",
discriminator="model_type",
),
]
WCAPPING_TYPE
module-attribute
¶
WCAPPING_TYPE = Annotated[
Union[WCAPPING_KOMEN, WCAPPING_AB],
Field(
description="Whitecapping component",
discriminator="model_type",
),
]
BREAKING_TYPE
module-attribute
¶
BREAKING_TYPE = Annotated[
Union[BREAKING_CONSTANT, BREAKING_BKD],
Field(
description="Wave breaking component",
discriminator="model_type",
),
]
FRICTION_TYPE
module-attribute
¶
FRICTION_TYPE = Annotated[
Union[
FRICTION_JONSWAP,
FRICTION_COLLINS,
FRICTION_MADSEN,
FRICTION_RIPPLES,
],
Field(
description="Bottom friction component",
discriminator="model_type",
),
]
TRIAD_TYPE
module-attribute
¶
TRIAD_TYPE = Annotated[
Union[TRIAD, TRIAD_DCTA, TRIAD_LTA, TRIAD_SPB],
Field(
description="Triad interactions component",
discriminator="model_type",
),
]
SICE_TYPE
module-attribute
¶
SICE_TYPE = Annotated[
Union[SICE, SICE_R19, SICE_D15, SICE_M18, SICE_R21B],
Field(
description="Sea ice component",
discriminator="model_type",
),
]
BRAGG_TYPE
module-attribute
¶
BRAGG_TYPE = Annotated[
Union[BRAGG, BRAGG_FT, BRAGG_FILE],
Field(
description="Bragg scattering component",
discriminator="model_type",
),
]
FRAME_TYPE
module-attribute
¶
GROUP_TYPE
module-attribute
¶
CURVE_TYPE
module-attribute
¶
RAY_TYPE
module-attribute
¶
ISOLINE_TYPE
module-attribute
¶
QUANTITY_TYPE
module-attribute
¶
QUANTITY_TYPE = Annotated[
QUANTITIES, Field(description="Quantity component")
]
OUTOPT_TYPE
module-attribute
¶
OUTOPT_TYPE = Annotated[
OUTPUT_OPTIONS,
Field(description="Output options component"),
]
TABLE_TYPE
module-attribute
¶
SPECOUT_TYPE
module-attribute
¶
NESTOUT_TYPE
module-attribute
¶
TEST_TYPE
module-attribute
¶
BLOCK_TYPE
module-attribute
¶
BLOCK_TYPE = Annotated[
Union[BLOCK, BLOCKS],
Field(
description="Block write component",
discriminator="model_type",
),
]
POINTS_TYPE
module-attribute
¶
POINTS_TYPE = Annotated[
Union[POINTS, POINTS_FILE],
Field(
description="Points locations component",
discriminator="model_type",
),
]
NGRID_TYPE
module-attribute
¶
NGRID_TYPE = Annotated[
Union[NGRID, NGRID_UNSTRUCTURED],
Field(
description="Ngrid locations component",
discriminator="model_type",
),
]
NEST_TYPE
module-attribute
¶
COMPUTE_TYPE
module-attribute
¶
COMPUTE_TYPE = Annotated[
Union[COMPUTE, COMPUTE_STAT, COMPUTE_NONSTAT],
Field(
description="Compute components",
discriminator="model_type",
),
]
BaseGroupComponent
pydantic-model
¶
BaseGroupComponent(**data: Any)
Bases: BaseComponent
Base group component.
Base class for SWAN group components. This base class modifies the render()
method to allow rendering of a list of components. It is not intended to be used
directly but to be subclassed by other group components.
Fields:
-
model_type(Literal['group', 'GROUP'])
STARTUP
pydantic-model
¶
STARTUP(**data: Any)
Bases: BaseGroupComponent
Startup group component.
This group component is used to group individual startup components. Only fields that are explicitly prescribed are rendered by this group component.
Examples¶
from rompy_swan.components.startup import PROJECT, SET, MODE, COORDINATES
from rompy_swan.components.group import STARTUP
proj = PROJECT(nr="01")
set = SET(level=0.5, direction_convention="nautical")
mode = MODE(kind="nonstationary", dim="twodimensional")
coords = COORDINATES(kind=dict(model_type="spherical", projection="ccm"))
startup = STARTUP(
project=proj,
set=set,
mode=mode,
coordinates=coords,
)
print(startup.render())
Fields:
-
model_type(Literal['startup', 'STARTUP']) -
project(Optional[PROJECT_TYPE]) -
set(Optional[SET_TYPE]) -
mode(Optional[MODE_TYPE]) -
coordinates(Optional[COORDINATES_TYPE])
FORCING
pydantic-model
¶
FORCING(**data: Any)
Bases: BaseGroupComponent
SWAN constant forcing group component.
This group component holds constant (non-gridded) forcing inputs. At most one WIND and one ICE instance may be provided; use the INPGRID-based components for spatially-varying inputs.
Examples¶
from rompy_swan.components.group import FORCING
forcing = FORCING(wind=dict(vel=10.0, dir=270.0))
print(forcing.render())
forcing = FORCING(
wind=dict(vel=10.0, dir=270.0),
ice=dict(aice=0.5, hice=1.5),
)
print(forcing.render())
Fields:
Validators:
INPGRIDS
pydantic-model
¶
INPGRIDS(**data: Any)
Bases: BaseGroupComponent
SWAN input grids group component.
This group component is a convenience to allow defining and rendering a list of input grid components.
Examples¶
from rompy_swan.components.inpgrid import REGULAR, ICE
from rompy_swan.components.group import INPGRIDS
inpgrid_bottom = REGULAR(
grid_type="bottom",
excval=-99.0,
xpinp=172.0,
ypinp=-41.0,
alpinp=0.0,
mxinp=99,
myinp=99,
dxinp=0.005,
dyinp=0.005,
readinp=dict(fname1="bottom.txt"),
)
inpgrid_wind = REGULAR(
grid_type="wind",
excval=-99.0,
xpinp=172.0,
ypinp=-41.0,
alpinp=0.0,
mxinp=99,
myinp=99,
dxinp=0.005,
dyinp=0.005,
readinp=dict(fname1="wind.txt"),
nonstationary=dict(
tbeg="2019-01-01T00:00:00",
tend="2019-01-07 00:00:00",
delt=3600,
dfmt="hr",
),
)
inpgrid_ice_cte = ICE(aice=0.8, hice=2.0)
inpgrids = INPGRIDS(inpgrids=[inpgrid_bottom, inpgrid_wind, inpgrid_ice_cte])
print(inpgrids.render())
INPGRID BOTTOM REGULAR xpinp=172.0 ypinp=-41.0 alpinp=0.0 mxinp=99 myinp=99 dxinp=0.005 dyinp=0.005 EXCEPTION excval=-99.0
READINP BOTTOM fac=1.0 fname1='bottom.txt' idla=1 nhedf=0 nhedt=0 nhedvec=0 FREE
INPGRID WIND REGULAR xpinp=172.0 ypinp=-41.0 alpinp=0.0 mxinp=99 myinp=99 dxinp=0.005 dyinp=0.005 EXCEPTION excval=-99.0 NONSTATIONARY tbeginp=20190101.000000 deltinp=1.0 HR &
tendinp=20190107.000000
READINP WIND fac=1.0 fname1='wind.txt' idla=1 nhedf=0 nhedt=0 nhedvec=0 FREE
ICE aice=0.8 hice=2.0
Fields:
-
model_type(Literal['inpgrids']) -
inpgrids(list[SerializeAsAny[INPGRID_TYPE]])
Validators:
inpgrids
pydantic-field
¶
inpgrids: list[SerializeAsAny[INPGRID_TYPE]]
List of input grid components
ensure_unique_grid_type
pydantic-validator
¶
ensure_unique_grid_type(
inpgrids: INPGRID_TYPE,
) -> INPGRID_TYPE
Ensure that each grid type is unique.
check_for_typos
classmethod
¶
Suggest the closest field name for an unknown input key.
A field can be given by its name or, like in pydantic, by its alias.
PHYSICS
pydantic-model
¶
PHYSICS(**data: Any)
Bases: BaseGroupComponent
Physics group component.
The physics group component is a convenience to allow specifying several individual components in a single command and check for consistency between them.
Exemples¶
from rompy_swan.components.group import PHYSICS
gen = {"model_type": "gen3", "source_terms": {"model_type": "komen"}}
phys = PHYSICS(gen=gen)
print(phys.render())
phys = PHYSICS(
gen=dict(model_type="gen3", source_terms={"model_type": "st6c1"}),
negatinp={"model_type": "negatinp", "rdcoef": 0.04},
sswell={"model_type": "zieger"},
breaking={"model_type": "constant", "alpha": 1.0, "gamma": 0.73},
friction={"model_type": "jonswap", "cfjon": 0.038},
)
print(phys.render())
GEN3 KOMEN DRAG WU
GEN3 ST6 a1sds=4.7e-07 a2sds=6.6e-06 p1sds=4.0 p2sds=4.0 UP HWANG VECTAU U10PROXY windscaling=28.0 AGROW
SSWELL ZIEGER
NEGATINP rdcoef=0.04
BREAKING CONSTANT alpha=1.0 gamma=0.73
FRICTION JONSWAP CONSTANT cfjon=0.038
Fields:
-
model_type(Literal['physics', 'PHYSICS']) -
gen(Optional[GEN_TYPE]) -
sswell(Optional[SSWELL_TYPE]) -
negatinp(Optional[NEGATINP_TYPE]) -
wcapping(Optional[WCAPPING_TYPE]) -
quadrupl(Optional[QUADRUPL_TYPE]) -
breaking(Optional[BREAKING_TYPE]) -
friction(Optional[FRICTION_TYPE]) -
triad(Optional[TRIAD_TYPE]) -
vegetation(Optional[VEGETATION_TYPE]) -
mud(Optional[MUD_TYPE]) -
sice(Optional[SICE_TYPE]) -
turbulence(Optional[TURBULENCE_TYPE]) -
bragg(Optional[BRAGG_TYPE]) -
limiter(Optional[LIMITER_TYPE]) -
obstacle(Optional[OBSTACLE_TYPE]) -
setup(Optional[SETUP_TYPE]) -
diffraction(Optional[DIFFRACTION_TYPE]) -
surfbeat(Optional[SURFBEAT_TYPE]) -
scat(Optional[SCAT_TYPE]) -
deactivate(Optional[OFF_TYPE])
Validators:
model_type
pydantic-field
¶
model_type: Literal['physics', 'PHYSICS'] = 'physics'
Model type discriminator
negatinp_only_with_zieger
pydantic-validator
¶
negatinp_only_with_zieger() -> PHYSICS
Log a warning if NEGATINP is used with a non-ZIEGER SSWELL.
check_for_typos
classmethod
¶
Suggest the closest field name for an unknown input key.
A field can be given by its name or, like in pydantic, by its alias.
OUTPUT
pydantic-model
¶
OUTPUT(**data: Any)
Bases: BaseGroupComponent
Output group component.
FRAME 'sname' ...
GROUP 'sname' ...
CURVE 'sname' ...
RAY 'rname' ...
ISOLINE 'sname' 'rname' ...
POINTS 'sname ...
NESTS (list):
- NEST 'sname':
NGRID 'sname' ...
NESTOUT 'sname' ...
- NEST 'sname':
NGRID 'sname' ...
NESTOUT 'sname' ...
QUANTITY ...
OUTPUT OPTIONS ...
BLOCK 'sname' ...
TABLE 'sname' ...
SPECOUT 'sname' ...
This group component is used to define multiple types of output locations and write components in a single model. Only fields that are explicitly prescribed are rendered by this group component.
Note
The components prescribed are validated according to some constraints as defined in the SWAN manual:
- The name
'sname'of each Locations component must be unique. - The Locations
'sname'assigned to each write component must be defined. - The BLOCK component must be associated with either a
FRAMEorGROUP. - The ISOLINE write component must be associated with a
RAYcomponent. - For nested grids, use the
nestsfield which accepts a list of NEST components. Each NEST automatically couples NGRID and NESTOUT with matching snames. - Legacy
ngridandnestoutfields are deprecated. Usenestsinstead for single or multiple nested grid definitions.
Examples:
from rompy_swan.components.output import POINTS, BLOCK, QUANTITIES, TABLE
from rompy_swan.components.group import OUTPUT
points = POINTS(sname="outpts", xp=[172.3, 172.4], yp=[-39, -39])
quantity = QUANTITIES(
quantities=[
dict(output=["depth", "hsign", "tps", "dir", "tm01"], excv=-9),
]
)
times = dict(tbeg="2012-01-01T00:00:00", delt="PT30M", tfmt=1, dfmt="min")
block = BLOCK(
model_type="block",
sname="COMPGRID",
fname="./swangrid.nc",
output=["depth", "hsign", "tps", "dir"],
times=times,
)
table = TABLE(
sname="outpts",
format="noheader",
fname="./swantable.nc",
output=["hsign", "hswell", "dir", "tps", "tm01", "watlev", "qp"],
times=times,
)
out = OUTPUT(
points=points,
quantity=quantity,
block=block,
table=table,
)
print(out.render())
POINTS sname='outpts' &
xp=172.3 yp=-39.0 &
xp=172.4 yp=-39.0
QUANTITY DEPTH HSIGN TPS DIR TM01 excv=-9.0
BLOCK sname='COMPGRID' fname='./swangrid.nc' &
DEPTH &
HSIGN &
TPS &
DIR &
OUTPUT tbegblk=20120101.000000 deltblk=30.0 MIN
TABLE sname='outpts' NOHEADER fname='./swantable.nc' &
HSIGN &
HSWELL &
DIR &
TPS &
TM01 &
WATLEV &
QP &
OUTPUT tbegtbl=20120101.000000 delttbl=30.0 MIN
Fields:
-
model_type(Literal['output', 'OUTPUT']) -
frame(Optional[FRAME_TYPE]) -
group(Optional[GROUP_TYPE]) -
curve(Optional[CURVE_TYPE]) -
ray(Optional[RAY_TYPE]) -
isoline(Optional[ISOLINE_TYPE]) -
points(Optional[POINTS_TYPE]) -
nests(Optional[list[NEST_TYPE]]) -
ngrid(Optional[NGRID_TYPE]) -
quantity(Optional[QUANTITY_TYPE]) -
output_options(Optional[OUTOPT_TYPE]) -
block(Optional[BLOCK_TYPE]) -
table(Optional[TABLE_TYPE]) -
specout(Optional[SPECOUT_TYPE]) -
nestout(Optional[NESTOUT_TYPE]) -
test(Optional[TEST_TYPE])
Validators:
-
write_locations_exists -
locations_sname_unique -
block_with_frame_or_group -
isoline_ray_defined -
migrate_legacy_ngrid_nestout -
nests_snames_unique
model_type
pydantic-field
¶
model_type: Literal['output', 'OUTPUT'] = 'output'
Model type discriminator
nests
pydantic-field
¶
List of nested grid definitions (each couples NGRID + NESTOUT)
write_locations_exists
pydantic-validator
¶
write_locations_exists() -> OUTPUT
Ensure the location component requested by a write component exists.
locations_sname_unique
pydantic-validator
¶
locations_sname_unique() -> OUTPUT
Ensure same sname isn't used in more than one set of output locations.
block_with_frame_or_group
pydantic-validator
¶
block_with_frame_or_group() -> OUTPUT
Ensure Block is only defined for FRAME or GROUP locations.
isoline_ray_defined
pydantic-validator
¶
isoline_ray_defined() -> OUTPUT
Ensure the isoline ray has been defined.
migrate_legacy_ngrid_nestout
pydantic-validator
¶
migrate_legacy_ngrid_nestout() -> OUTPUT
Convert deprecated ngrid/nestout fields to nests.
Deprecated
Use the nests field instead. This validator will be removed in a future
version once the legacy ngrid and nestout fields are dropped.
nests_snames_unique
pydantic-validator
¶
nests_snames_unique() -> OUTPUT
Ensure each nest has a unique sname.
check_for_typos
classmethod
¶
Suggest the closest field name for an unknown input key.
A field can be given by its name or, like in pydantic, by its alias.
LOCKUP
pydantic-model
¶
LOCKUP(**data: Any)
Bases: BaseComponent
Lockup group component.
This is a group component to specify SWAN "Lockup" commands including multiple
COMPUTE commands that may or may not be interleaved with HOTFILE commands,
and a final STOP command.
The computation depends on the SWAN mode (see command MODE):
- stationary mode (SWAN's default): a single computation without times,
COMPUTE. - nonstationary mode: computations at given times, either stationary
(
COMPUTE_STAT) or nonstationary (COMPUTE_NONSTAT).
Examples¶
from rompy_swan.components.group import LOCKUP
lockup = LOCKUP(compute=dict(model_type="compute"))
print(lockup.render())
lockup = LOCKUP(
compute=dict(
model_type="stat",
times=dict(
model_type="nonstationary",
tbeg="1990-01-01T00:00:00",
tend="1990-01-01T03:00:00",
delt="PT1H",
dfmt="hr",
),
hotfile=dict(fname="hotfile"),
hottimes=[-1],
),
)
print(lockup.render())
COMPUTE
STOP
COMPUTE STATIONARY time=19900101.000000
COMPUTE STATIONARY time=19900101.010000
COMPUTE STATIONARY time=19900101.020000
COMPUTE STATIONARY time=19900101.030000
HOTFILE fname='hotfile_19900101T030000'
STOP
Fields:
-
model_type(Literal['lockup', 'LOCKUP']) -
compute(COMPUTE_TYPE)