Skip to content

Startup

The commands at the start of the command file: PROJECT, SET, MODE and COORDINATES.

SWAN Startup Components

This module contains components for initializing and configuring SWAN model runs, including project settings, coordinate systems, and run modes.

logger module-attribute

logger = get_logger(__name__)

PROJECT pydantic-model

PROJECT(**data: Any)

Bases: BaseComponent

SWAN Project.

PROJECT 'name' 'nr' 'title' 'title2 'title3'

With this required command the user defines a number of strings to identify the SWAN run (project name e.g., an engineering project) in the print and plot file.

Examples

from rompy_swan.components.startup import PROJECT
proj = PROJECT(nr="01")
print(proj.render())
proj = PROJECT(
    name="waus",
    nr="001",
    title1="Western Australia",
    title2="Perth Nest"
)
print(proj.render())
PROJECT nr='01'
PROJECT name='waus' nr='001' title1='Western Australia' title2='Perth Nest'

Config:

  • extra: forbid

Fields:

model_type pydantic-field

model_type: Literal['project', 'PROJECT'] = 'project'

Model type discriminator

name pydantic-field

name: Optional[str] = None

Is the name of the project, at most 16 characters long

nr pydantic-field

nr: str

Is the run identification (to be provided as a character string; e.g. the run number) to distinguish this run among other runs for the same project; it is at most 4 characters long. It is the only required information in this command.

title1 pydantic-field

title1: Optional[str] = None

A string of at most 72 characters provided by the user to appear in the output of the program for the user's convenience (SWAN default: blanks)

title2 pydantic-field

title2: Optional[str] = None

Same as 'title1'

title3 pydantic-field

title3: Optional[str] = None

Same as 'title1'

cmd

cmd() -> str

check_for_typos classmethod

check_for_typos(data: Any) -> Any

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.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

render

render(cmd: Optional[str | list] = None) -> str

Render the component to a string.

Parameters:

Name Type Description Default
cmd Optional[str | list]

Command string or list of command strings to render, by default self.cmd().

None

Returns:

Name Type Description
cdmstr str

The rendered command file component.

SET pydantic-model

SET(**data: Any)

Bases: BaseComponent

SWAN setting commands.

SET [level] [nor] [depmin] [maxmes] [maxerr] [grav] [rho] [cdcap] &
    [inrhog] [hsrerr] NAUTICAL|->CARTESIAN [pwtail] [froudmax] [icewind]

With this optional command the user assigns values to various general parameters.

Notes

The error level maxerr is coded as follows:

  • 1: warnings
  • 2: errors (possibly automatically repaired or repairable by SWAN)
  • 3: severe errors

Default values for pwtail depend on formulations of physics:

  • command GEN1: pwtail = 5
  • command GEN2: pwtail = 5
  • command GEN3 KOMEN: pwtail = 4
  • command GEN3 WESTH: pwtail = 4
  • command GEN3 JANSSEN: pwtail = 5

Examples

from rompy_swan.components.startup import SET
set = SET(level=0.5, direction_convention="nautical")
print(set.render())
set = SET(
    level=-1.0,
    nor=90,
    depmin=0.01,
    maxerr=3,
    grav=9.81,
    rho=1025,
    cdcap=2.5e-3,
    inrhog=0,
    hsrerr=0.1,
    direction_convention="nautical",
)
print(set.render())
SET level=0.5 NAUTICAL
SET level=-1.0 nor=90.0 depmin=0.01 maxerr=3 grav=9.81 rho=1025.0 cdcap=0.0025 inrhog=0 hsrerr=0.1 NAUTICAL

Fields:

Validators:

model_type pydantic-field

model_type: Literal['set', 'SET'] = 'set'

Model type discriminator

level pydantic-field

level: Optional[float] = None

Increase in water level that is constant in space and time can be given with this option, level is the value of this increase (in m). For a variable water level reference is made to the commands INPGRID and READINP (SWAN default: 0)

nor pydantic-field

nor: Optional[float] = None

Direction of North with respect to the x-axis (measured counterclockwise); default nor = 90, i.e. x-axis of the problem coordinate system points East. When spherical coordinates are used (see command COORD) the value of nor may not be modified

depmin pydantic-field

depmin: Optional[float] = None

Threshold depth (in m). In the computation any positive depth smaller than depmin is made equal to depmin (SWAN default: 0.05)

maxmes pydantic-field

maxmes: Optional[int] = None

Maximum number of error messages during the computation at which the computation is terminated. During the computational process messages are written to the print file (SWAN default: 200)

maxerr pydantic-field

maxerr: Optional[Literal[1, 2, 3]] = None

During pre-processing SWAN checks input data. Depending on the severity of the errors encountered during this pre-processing, SWAN does not start computations. The user can influence the error level above which SWAN will not start computations (at the level indicated the computations will continue) (SWAN default: 1)

grav pydantic-field

grav: Optional[float] = None

The gravitational acceleration (in m/s2) (SWAN default: 9.81)

rho pydantic-field

rho: Optional[float] = None

The water density (in kg/m3) (SWAN default: 1025)

cdcap pydantic-field

cdcap: Optional[float] = None

The maximum value for the wind drag coefficient. A value of 99999 meansno cutting off the drag coefficient. A suggestion for this parameter is cdcap = 2.5x 10-3 (SWAN default: 99999)

inrhog pydantic-field

inrhog: Optional[Literal[0, 1]] = None

To indicate whether the user requires output based on variance or based on true energy (see Section 2.5). inrhog = 0: output based on variance, inrhog = 1: output based on true energy (SWAN default: 0)

hsrerr pydantic-field

hsrerr: Optional[float] = None

The relative difference between the user imposed significant wave height and the significant wave height computed by SWAN (anywhere along the computational grid boundary) above which a warning will be given. This relative difference is the difference normalized with the user provided significant wave height. This warning will be given for each boundary grid point where the problem occurs (with its x- and y-index number of the computational grid). The cause of the difference is explained in Section 2.6.3. To suppress these warnings (in particular for nonstationary computations), set hsrerr at a very high value or use command OFF BNDCHK (SWAN default: 0.10) (ONLY MEANT FOR STRUCTURED GRIDS)

direction_convention pydantic-field

direction_convention: Literal['nautical', 'cartesian']

Direction convention: nautical indicates that the Nautical convention for wind and wave direction (SWAN input and output) will be used, cartesian indicates that the Cartesian convention for wind and wave direction will be used. For definition, see Section 2.5 or Appendix A (SWAN default: cartesian)

pwtail pydantic-field

pwtail: Optional[int] = None

Power of high frequency tail; defines the shape of the spectral tail above the highest prognostic frequency fhigh (see command CGRID). The energy density is assumed to be proportional to frequency to the power pwtail. If the user wishes to use another value, then this SET command should be located in the command file after GEN1, GEN2 or GEN3 command (these will override the SET command with respect to pwtail)

froudmax pydantic-field

froudmax: Optional[float] = None

Is the maximum Froude number (U/√gd with U the current and d the water depth). The currents taken from a circulation model may mismatch with given water depth d in the sense that the Froude number becomes larger than 1. For this, the current velocities will be maximized by Froude number times sqrt(gh) (SWAN default: 0.8)

icewind pydantic-field

icewind: Optional[Literal[0, 1]] = None

Controls the scaling of wind input by open water fraction. Default value of zero corresponds to the case where wind input is scaled by the open water fraction. If icewind = 1 then sea ice does not affect wind input directly. (Though there is still indirect effect via the sea ice sink term; see command SICE) (SWAN default: 0)

pwtail_after_gen pydantic-validator

pwtail_after_gen(v)

cmd

cmd() -> str

check_for_typos classmethod

check_for_typos(data: Any) -> Any

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.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

render

render(cmd: Optional[str | list] = None) -> str

Render the component to a string.

Parameters:

Name Type Description Default
cmd Optional[str | list]

Command string or list of command strings to render, by default self.cmd().

None

Returns:

Name Type Description
cdmstr str

The rendered command file component.

MODE pydantic-model

MODE(**data: Any)

Bases: BaseComponent

SWAN Mode.

MODE ->STATIONARY|NONSTATIONARY ->TWODIMENSIONAL|ONEDIMENSIONAL

With this optional command the user indicates that the run will be either stationary or nonstationary and one-dimensional (1D-mode) or two-dimensional (2D-mode). Nonstationary means either (see command COMPUTE):

  • (a) one nonstationary computations or
  • (b) a sequence of stationary computations or
  • (c) a mix of (a) and (b)

Examples

from rompy_swan.components.startup import MODE
mode = MODE()
print(mode.render())
mode = MODE(kind="nonstationary", dim="twodimensional")
print(mode.render())
MODE STATIONARY TWODIMENSIONAL
MODE NONSTATIONARY TWODIMENSIONAL

Fields:

model_type pydantic-field

model_type: Literal['mode', 'MODE'] = 'mode'

Model type discriminator.

kind pydantic-field

kind: Literal['stationary', 'nonstationary'] = 'stationary'

Indicates if run will be stationary or nonstationary

dim pydantic-field

dim: Literal["onedimensional", "twodimensional"] = (
    "twodimensional"
)

Indicates that the run will be either one-dimensional (1D-mode) or two-dimensional (2D-mode)

cmd

cmd() -> str

check_for_typos classmethod

check_for_typos(data: Any) -> Any

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.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

render

render(cmd: Optional[str | list] = None) -> str

Render the component to a string.

Parameters:

Name Type Description Default
cmd Optional[str | list]

Command string or list of command strings to render, by default self.cmd().

None

Returns:

Name Type Description
cdmstr str

The rendered command file component.

COORDINATES pydantic-model

COORDINATES(**data: Any)

Bases: BaseComponent

SWAN Coordinates.

COORDINATES ->CARTESIAN|SPHERICAL REPEATING

Command to choose between Cartesian and spherical coordinates (see Section 2.5). A nested SWAN run must use the same coordinate system as the coarse grid SWAN run.

Examples

from rompy_swan.components.startup import COORDINATES
coords = COORDINATES()
print(coords.render())
coords = COORDINATES(
    kind=dict(model_type="spherical", projection="ccm"),
    reapeating=True,
)
print(coords.render())
COORDINATES CARTESIAN
COORDINATES SPHERICAL CCM REPEATING

Fields:

model_type pydantic-field

model_type: Literal["coordinates", "COORDINATES"] = (
    "coordinates"
)

Model type discriminator

kind pydantic-field

Coordinates kind

reapeating pydantic-field

reapeating: bool = False

This option is only for academic cases. It means that wave energy leaving at one end of the domain (in computational x-direction) enter at the other side; it is as if the wave field repeats itself in x-direction with the length of the domain in x-direction. This option cannot be used in combination with computation of set-up (see command SETUP). This option is available only with regular grids

cmd

cmd() -> str

check_for_typos classmethod

check_for_typos(data: Any) -> Any

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.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

render

render(cmd: Optional[str | list] = None) -> str

Render the component to a string.

Parameters:

Name Type Description Default
cmd Optional[str | list]

Command string or list of command strings to render, by default self.cmd().

None

Returns:

Name Type Description
cdmstr str

The rendered command file component.