Lockup¶
COMPUTE, HOTFILE and STOP: the computations and the end of the command file.
SWAN Lockup Components
This module contains components for controlling SWAN model execution flow, including computation, hotfile output, and program termination.
HOTFILE
pydantic-model
¶
HOTFILE(**data: Any)
Bases: BaseComponent
Write intermediate results.
This command can be used to write the entire wave field at the end of a computation
to a so-called hotfile, to be used as initial condition in a subsequent SWAN run
(see command INITIAL HOTSTART). This command must be entered immediately after a
COMPUTE command.
The user may choose the format of the hotfile to be written either as free or
unformatted. If the free format is chosen, then this format is identical to the
format of the files written by the SPECOUT command (option SPEC2D). This
hotfile is therefore an ASCII file which is human readable.
An unformatted (or binary) file usually requires less space on your computer than an ASCII file. Moreover, it can be readed by a subsequent SWAN run much faster than an ASCII file. Especially, when the hotfile might become a big file, the choice for unformatted is preferable. Note that your compiler and OS should follow the same ABI (Application Binary Interface) conventions (e.g. word size, endianness), so that unformatted hotfiles may transfer properly between different OS or platforms. This implies that the present and subsequent SWAN runs do not have to be carried out on the same operating system (e.g. Windows, Linux) or on the same computer, provided that distinct ABI conventions have been followed.
Note
For parallel MPI runs, more than one hotfile will be generated depending on the
number of processors (fname-001, fname-002, etc).
Examples:
from rompy_swan.components.lockup import HOTFILE
hotfile = HOTFILE(fname="hotfile.swn")
print(hotfile.render())
hotfile = HOTFILE(fname="hotfile.dat", format="unformatted")
print(hotfile.render())
Fields:
-
model_type(Literal['hotfile', 'HOTFILE']) -
fname(Path) -
format(Optional[Literal['free', 'unformatted']])
Validators:
model_type
pydantic-field
¶
model_type: Literal['hotfile', 'HOTFILE'] = 'hotfile'
Model type discriminator
format
pydantic-field
¶
Choose between free (SWAN ASCII) or unformatted (binary) format
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.
render
¶
COMPUTE
pydantic-model
¶
COMPUTE(**data: Any)
Bases: BaseComponent
Single SWAN computation in stationary mode.
If the SWAN mode is stationary (see command MODE, stationary is SWAN's default),
then SWAN makes a single computation, started by a COMPUTE command without
times. The wave field at the end of the computation can be written to a hotfile.
If the SWAN mode is nonstationary, computations are made at given times, either
stationary (COMPUTE_STAT) or nonstationary (COMPUTE_NONSTAT).
To verify input to SWAN (e.g., all input fields such as water depth, wind fields,
etc), SWAN can be run without computations (that is: zero iterations by using
command NUM ACCUR MXITST=0).
For small domains, i.e. less than 100 km or 1 deg, a stationary computation is recommended. Otherwise, a nonstationary computation is advised.
Examples¶
from rompy_swan.components.lockup import COMPUTE
comp = COMPUTE()
print(comp.render())
comp = COMPUTE(hotfile=dict(fname="hotfile.swn"))
print(comp.render())
Fields:
-
model_type(Literal['compute', 'COMPUTE']) -
hotfile(Optional[HOTFILE])
model_type
pydantic-field
¶
model_type: Literal['compute', 'COMPUTE'] = 'compute'
Model type discriminator
hotfile
pydantic-field
¶
Write the wave field at the end of the computation to a hotfile
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.
render
¶
COMPUTE_STAT
pydantic-model
¶
COMPUTE_STAT(**data: Any)
Bases: BaseComponent
Multiple SWAN stationary computations.
COMPUTE STATIONARY [time]
HOTFILE 'fname' ->FREE|UNFORMATTED
COMPUTE STATIONARY [time]
COMPUTE STATIONARY [time]
HOTFILE 'fname' ->FREE|UNFORMATTED
.
.
This component can be used to define multiple stationary compute commands and write intermediate results as hotfiles between then.
Note
The field times is optional to allow for the case where the user wants to set
times dynamically after instantiating this component.
Examples:
from rompy_swan.subcomponents.time import STATIONARY, NONSTATIONARY
from rompy_swan.components.lockup import COMPUTE_STAT
time = STATIONARY(time="1990-01-01T00:00:00")
comp = COMPUTE_STAT(times=time)
print(comp.render())
times = NONSTATIONARY(
tbeg="1990-01-01T00:00:00",
tend="1990-01-01T03:00:00",
delt="PT1H",
)
comp = COMPUTE_STAT(times=times)
print(comp.render())
hotfile = dict(fname="./hotfile.swn")
hottimes=["1990-01-01T03:00:00"]
comp = COMPUTE_STAT(times=times, hotfile=hotfile, hottimes=hottimes)
print(comp.render())
comp = COMPUTE_STAT(times=times, hotfile=hotfile, hottimes=[2, -1])
print(comp.render())
COMPUTE STATIONARY time=19900101.000000
COMPUTE STATIONARY time=19900101.000000
COMPUTE STATIONARY time=19900101.010000
COMPUTE STATIONARY time=19900101.020000
COMPUTE STATIONARY time=19900101.030000
COMPUTE STATIONARY time=19900101.000000
COMPUTE STATIONARY time=19900101.010000
COMPUTE STATIONARY time=19900101.020000
COMPUTE STATIONARY time=19900101.030000
HOTFILE fname='hotfile_19900101T030000.swn'
COMPUTE STATIONARY time=19900101.000000
COMPUTE STATIONARY time=19900101.010000
COMPUTE STATIONARY time=19900101.020000
HOTFILE fname='hotfile_19900101T020000.swn'
COMPUTE STATIONARY time=19900101.030000
HOTFILE fname='hotfile_19900101T030000.swn'
Fields:
-
model_type(Literal['stat', 'STAT']) -
times(TIMES_TYPE) -
hotfile(Optional[HOTFILE]) -
hottimes(HOTTIMES_TYPE) -
suffix(str)
Validators:
hottimes
pydantic-field
¶
hottimes: HOTTIMES_TYPE = []
Times to write hotfiles, can be a list of datetimes or times indices
timestamp_to_datetime
pydantic-validator
¶
timestamp_to_datetime(hottimes: TIMES_TYPE) -> TIMES_TYPE
Ensure pandas.Timestamp entries are coerced into datatime.
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.
render
¶
COMPUTE_NONSTAT
pydantic-model
¶
COMPUTE_NONSTAT(**data: Any)
Bases: COMPUTE_STAT
Multiple SWAN nonstationary computations.
COMPUTE NONSTATIONARY [tbegc] [deltc] SEC|MIN|HR|DAY [tendc]
HOTFILE 'fname' ->FREE|UNFORMATTED
COMPUTE NONSTATIONARY [tbegc] [deltc] SEC|MIN|HR|DAY [tendc]
HOTFILE 'fname' ->FREE|UNFORMATTED
.
.
This component can be used to define multiple nonstationary compute commands and write intermediate results as hotfiles between then.
In the case MODE NONSTATIONARY several commands COMPUTE can appear, where the
wave state at the end of one computation is used as initial state for the next one,
unless a command INIT appears in between the two COMPUTE commands. This enables
the user to make a stationary computation to obtain the initial state for a
nonstationary computation and/or to change the computational time step during a
computation, to change a boundary condition etc. This also has the advantage of not
using a hotfile since, it can be very large in size.
For a nonstationary computation, a time step of at most 10 minutes is advised (when
you are choosing a time step larger than 10 minutes, the action density limiter
(see command NUM) becomes probably a part of the physics).
Also, the time step should be chosen such that the Courant number is smaller than
10 for the fastest (or dominant) wave. Otherwise, a first order upwind scheme is
recommended in that case; see command PROP BSBT. If you want to run a high
resolution model with a very large time step, e.g. 1 hour, you may apply multiple
COMPUT STAT commands. For a small time step (<= 10 minutes), no more than 1
iteration per time step is recommended (see command NUM ... NONSTAT mxitns).
Note
The field times is optional to allow for the case where the user wants to set
times dynamically after instantiating this component.
Examples:
from rompy_swan.subcomponents.time import NONSTATIONARY
from rompy_swan.components.lockup import COMPUTE_NONSTAT
times = NONSTATIONARY(
tbeg="1990-01-01T00:00:00",
tend="1990-02-01T00:00:00",
delt="PT1H",
dfmt="hr",
)
comp = COMPUTE_NONSTAT(times=times)
print(comp.render())
comp = COMPUTE_NONSTAT(
times=times,
hotfile=dict(fname="hotfile.swn", format="free"),
hottimes=["1990-02-01T00:00:00"],
)
print(comp.render())
comp = COMPUTE_NONSTAT(
times=times,
initstat=True,
hotfile=dict(fname="hotfile", format="free"),
hottimes=[6, 12, 18, -1],
)
print(comp.render())
COMPUTE NONSTATIONARY tbegc=19900101.000000 deltc=1.0 HR tendc=19900201.000000
COMPUTE NONSTATIONARY tbegc=19900101.000000 deltc=1.0 HR tendc=19900201.000000
HOTFILE fname='hotfile_19900201T000000.swn' FREE
COMPUTE STATIONARY time=19900101.000000
COMPUTE NONSTATIONARY tbegc=19900101.000000 deltc=1.0 HR tendc=19900101.060000
HOTFILE fname='hotfile_19900101T060000' FREE
COMPUTE NONSTATIONARY tbegc=19900101.060000 deltc=1.0 HR tendc=19900101.120000
HOTFILE fname='hotfile_19900101T120000' FREE
COMPUTE NONSTATIONARY tbegc=19900101.120000 deltc=1.0 HR tendc=19900101.180000
HOTFILE fname='hotfile_19900101T180000' FREE
COMPUTE NONSTATIONARY tbegc=19900101.180000 deltc=1.0 HR tendc=19900201.000000
HOTFILE fname='hotfile_19900201T000000' FREE
Fields:
-
hotfile(Optional[HOTFILE]) -
hottimes(HOTTIMES_TYPE) -
suffix(str) -
model_type(Literal['nonstat', 'NONSTAT']) -
times(NONSTATIONARY) -
initstat(bool)
Validators:
model_type
pydantic-field
¶
model_type: Literal['nonstat', 'NONSTAT'] = 'nonstat'
Model type discriminator
initstat
pydantic-field
¶
initstat: bool = False
Run a STATIONARY computation at the initial time prior to the NONSTATIONARY computation(s) to prescribe initial conditions
hottimes
pydantic-field
¶
hottimes: HOTTIMES_TYPE = []
Times to write hotfiles, can be a list of datetimes or times indices
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.
render
¶
timestamp_to_datetime
pydantic-validator
¶
timestamp_to_datetime(hottimes: TIMES_TYPE) -> TIMES_TYPE
Ensure pandas.Timestamp entries are coerced into datatime.
STOP
pydantic-model
¶
STOP(**data: Any)
Bases: BaseComponent
End of commands.
This required command marks the end of the commands in the command file. Note that
the command STOP may be the last command in the input file; any information in
the input file beyond this command is ignored.
Examples¶
Fields:
-
model_type(Literal['stop', 'STOP'])