Skip to content

Boundary and initial conditions

BOUNDSPEC, BOUNDNEST1, BOUNDNEST2, BOUNDNEST3 and INITIAL.

Boundary for SWAN.

HERE module-attribute

HERE = Path(__file__).parent

INITIAL pydantic-model

INITIAL(**data: Any)

Bases: BaseComponent

Initial conditions.

INITIAL -> DEFAULT|ZERO|PAR|HOTSTART

This command can be used to specify the initial values for a stationary (INITIAL HOTSTART only) or nonstationary computation. The initial values thus specified override the default initialization (see Section 2.6.3). Note that it is possible to obtain an initial state by carrying out a previous stationary or nonstationary computation.

Examples

from rompy_swan.components.boundary import INITIAL
init = INITIAL()
print(init.render())
init = INITIAL(
    kind=dict(model_type="hotmultiple", fname="hotstart.swn", format="free")
)
print(init.render())
INITIAL DEFAULT
INITIAL HOTSTART MULTIPLE fname='hotstart.swn' FREE

Fields:

model_type pydantic-field

model_type: Literal['initial', 'INITIAL'] = 'initial'

Model type discriminator

kind pydantic-field

Initial condition type

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.

BOUNDSPEC pydantic-model

BOUNDSPEC(**data: Any)

Bases: BaseComponent

Boundary along sides or segment.

BOUNDSPEC ->SIDE|SEGMENT CONSTANT|VARIABLE PAR|FILE

This command BOUNDSPEC defines parametric spectra at the boundary. It consists of two parts, the first part defines the boundary side or segment where the spectra will be given, the second part defines the spectral parameters of these spectra. Note that in fact only the incoming wave components of these spectra are used by SWAN. The fact that complete spectra are calculated at the model boundaries from the spectral parameters should not be misinterpreted. Only the incoming components are effective in the computation.

TODO: Add support for unstructured grid (k).

Examples

from rompy_swan.components.boundary import BOUNDSPEC
boundary = BOUNDSPEC(
    shapespec=dict(model_type="shapespec", shape=dict(model_type="pm")),
    location=dict(model_type="side", side="west", direction="ccw"),
    data=dict(model_type="constantpar", hs=2, per=8, dir=270, dd=30),
)
print(boundary.render())
boundary = BOUNDSPEC(
    shapespec=dict(model_type="shapespec", shape=dict(model_type="pm")),
    location=dict(
        model_type="segment",
        points=dict(model_type="ij", i=[0, 0], j=[0, 3])
    ),
    data=dict(model_type="constantpar", hs=2, per=8, dir=270, dd=30),
)
print(boundary.render())
BOUND SHAPESPEC PM PEAK DSPR POWER
BOUNDSPEC SIDE WEST CCW CONSTANT PAR hs=2.0 per=8.0 dir=270.0 dd=30.0
BOUND SHAPESPEC PM PEAK DSPR POWER
BOUNDSPEC SEGMENT IJ  &
    i=0 j=0 &
    i=0 j=3 &
    CONSTANT PAR hs=2.0 per=8.0 dir=270.0 dd=30.0

Fields:

model_type pydantic-field

model_type: Literal['boundspec', 'BOUNDSPEC'] = 'boundspec'

Model type discriminator

shapespec pydantic-field

shapespec: SHAPESPEC

Spectral shape specification

location pydantic-field

location: SIDE | SEGMENT

Location to apply the boundary

data pydantic-field

Spectral data

cmd

cmd() -> list

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.

BOUNDNEST1 pydantic-model

BOUNDNEST1(**data: Any)

Bases: BaseComponent

Boundary spectra from a coarser SWAN nest.

BOUNDNEST1 NEST 'fname' ->CLOSED|OPEN

With this optional command a nested SWAN run can be carried out with the boundary conditions obtained from a coarse grid SWAN run (generated in that previous SWAN run with command NESTOUT). The spectral frequencies and directions of the coarse grid run do not have to coincide with the frequencies and directions used in the nested SWAN run; SWAN will interpolate to these frequencies and directions in the nested run (see Section 2.6.3). To generate the nest boundary in the coarse grid run, use command NGRID. For the nested run, use the command CGRID with identical geographical information except the number of meshes (which will be much higher for the nested run). This BOUNDNEST1 command is not available for 1D computations; in such cases the commands SPECOUT and BOUNDSPEC can be used for the same purpose. A nested SWAN run must use the same coordinate system as the coarse grid SWAN run. For a curvilinear grid, it is advised to use the commands POINTS or CURVE and SPECOUT instead of NGRID and NESTOUT.

Examples

from rompy_swan.components.boundary import BOUNDNEST1
boundary = BOUNDNEST1(fname="boundary.swn", rectangle="closed")
print(boundary.render())
BOUNDNEST1 NEST fname='boundary.swn' CLOSED

Fields:

model_type pydantic-field

model_type: Literal["boundnest1", "BOUNDNEST1"] = (
    "boundnest1"
)

Model type discriminator

fname pydantic-field

fname: str

Name of the file containing the boundary conditions for the present run, created by the previous SWAN coarse grid run. This file is structured according to the rules given in Appendix D for 2D spectra

rectangle pydantic-field

rectangle: Literal['closed', 'open'] = 'closed'

Boundary is defined over a closed (default) or an open rectangle. Boundary generated from the NESTOUT command is aways closed

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.

BOUNDNEST2 pydantic-model

BOUNDNEST2(**data: Any)

Bases: BaseComponent

Boundary spectra from WAM.

BOUNDNEST2 WAMNEST 'fname' FREE|UNFORMATTED ->CRAY|WKSTAT [xgc] [ygc] [lwdate]

With this optional command (not fully tested) a nested SWAN run can be carried out with the boundary conditions obtained from a coarse grid WAM run (WAM Cycle 4.5, source code as distributed by the Max Planck Institute in Hamburg). The spectral frequencies and directions of the coarse grid run do not have to coincide with the frequencies and directions used in the nested SWAN run; SWAN will interpolate to these frequencies and directions in the nested run (see Section 2.6.3). Note that SWAN will accept output of a WAM output location only if the SWAN grid point on the nest boundary lies within a rectangle between two consecutive WAM output locations with a width equal to 0.1 times the distance between these output locations on either side of the line between these WAM output locations. This BOUNDNEST2 command is not available for 1D computations. Only boundary conditions generated by WAM Cycle 4.5 can be read properly by SWAN. A nested SWAN run may use either Cartesian or spherical coordinates. A curvilinear grid may be used in the nested grid but the boundaries of this nest should conform to the rectangular course grid nest boundaries. WAM output files are unformatted (binary); this usually implies that WAM and SWAN have to run on the same computer. For those cases where WAM and SWAN run on different types of machines (binary files do not transfer properly), the option FREE is available in this command. The distributed version of WAM does not support the required free format nesting output; WAM users who modify WAM such that it can make formatted output, must modify WAM such that the files made by WAM can be read in free format, i.e. with at least a blank or comma between numbers.

Note

the contents of 'fname' file could look like:

CBO9212010000
CBO9212020000
CBO9212030000

Examples:

from rompy_swan.components.boundary import BOUNDNEST2
boundary = BOUNDNEST2(fname="boundary.wam", format="cray", lwdate=12)
print(boundary.render())
BOUNDNEST2 WAMNEST fname='boundary.wam' UNFORMATTED CRAY lwdate=12

Fields:

model_type pydantic-field

model_type: Literal["boundnest2", "BOUNDNEST2"] = (
    "boundnest2"
)

Model type discriminator

fname pydantic-field

fname: str

A file name that contains all the names of WAM files containing the nested boundary conditions in time-sequence (usually one file per day)

format pydantic-field

format: Literal['cray', 'wkstat', 'free']

Format of the WAM file. cray: CRAY version of WAM, wkstat: WORKSTATION version of WAM, free: Free format (these files are not generated standard by WAM)

xgc pydantic-field

xgc: Optional[float] = None

If SWAN is used with Cartesian coordinates: longitude of south-west corner of SWAN computational grid (in degrees); if the south-west corner of the nest in the WAM computation is on land this value is required. If SWAN is used with spherical coordinates then xgc is ignored by SWAN (SWAN default: the location of the first spectrum encountered in the nest file

ygc pydantic-field

ygc: Optional[float] = None

If SWAN is used with Cartesian coordinates: latitude of south-west corner of SWAN computational grid (in degrees); if the south-west corner of the nest in the WAM computation is on land this value is required. If SWAN is used with spherical coordinates then ygc is ignored by SWAN (SWAN default: the location of the first spectrum encountered in the nest file

lwdate pydantic-field

lwdate: Literal[10, 12, 14] = 12

Length of character string for date-time as used in the WAM files. Possible values are: 10 (i.e. YYMMDDHHMM), 12 (i.e. YYMMDDHHMMSS) or 14 (i.e. YYYYMMDDHHMMSS) (SWAN default: lwdate = 12)

format_str property

format_str

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.

BOUNDNEST3 pydantic-model

BOUNDNEST3(**data: Any)

Bases: BaseComponent

Boundary spectra from WAVEWATCHIII.

BOUNDNEST3 WW3 'fname' FREE|UNFORMATTED ->CLOSED|OPEN [xgc] [ygc]

With this optional command a nested SWAN run can be carried out with the boundary conditions obtained from a coarse grid WAVEWATCH III run. The spectral frequencies and directions of the coarse grid run do not have to coincide with the frequencies and directions used in the nested SWAN run; SWAN will interpolate to these frequencies and directions in the nested run (see Section 2.6.3). The output files of WAVEWATCH III have to be created with the post-processor of WAVEWATCH III as output transfer files (formatted or unformatted) with WW_3 OUTP (output type 1 sub type 3) at the locations along the nest boundary (i.e. computational grid points in WAVEWATCH III). These locations are equal to the corner points of the SWAN nested grid and optionally also distributed between the corner points of the SWAN nested grid (the boundary of the WAVEWATCH III nested grid need not be closed and may cover land). The locations should be output by WAVEWATCH III in sequence (going along the nest boundary, clockwise or counterclockwise). Note that SWAN will accept output of a WAVEWATCH III output location only if the SWAN grid point on the nest boundary lies within a rectangle between two consecutive WAVEWATCH III output locations with a width equal to 0.1 times the distance between these output locations on either side of the line between these WAVEWATCH III output locations. This BOUNDNEST3 command is not available for 1D computations. A nested SWAN run may use either Cartesian or spherical coordinates. A curvilinear grid may be used in the nested grid but the boundaries of this nest should conform to the rectangular course grid nest boundaries.

Examples

from rompy_swan.components.boundary import BOUNDNEST3
boundary = BOUNDNEST3(
    fname="boundary.ww3",
    format="free",
    rectangle="closed",
)
print(boundary.render())
BOUNDNEST3 WW3 fname='boundary.ww3' FREE CLOSED

Fields:

model_type pydantic-field

model_type: Literal["boundnest3", "BOUNDNEST3"] = (
    "boundnest3"
)

Model type discriminator

fname pydantic-field

fname: str

The name of the file that contains the spectra computed by WAVEWATCH III

format pydantic-field

format: Literal['unformatted', 'free']

Format of the WW3 file. unformatted: The input WW3 files are binary, free: The input WW3 files are formatted

rectangle pydantic-field

rectangle: Literal['closed', 'open'] = 'closed'

Boundary is defined over a closed (default) or an open rectangle. Boundary generated from the NESTOUT command is aways closed

xgc pydantic-field

xgc: Optional[float] = None

If SWAN is used with Cartesian coordinates: longitude of south-west corner of SWAN computational grid (in degrees); if the south-west corner of the nest in the WAM computation is on land this value is required. If SWAN is used with spherical coordinates then xgc is ignored by SWAN (SWAN default: the location of the first spectrum encountered in the nest file.

ygc pydantic-field

ygc: Optional[float] = None

If SWAN is used with Cartesian coordinates: latitude of south-west corner of SWAN computational grid (in degrees); if the south-west corner of the nest in the WAM computation is on land this value is required. If SWAN is used with spherical coordinates then ygc is ignored by SWAN (SWAN default: the location of the first spectrum encountered in the nest file.

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.