Lock-up
SWAN lock-up commands
COMPUTE
Bases: BaseComponent
Start SWAN computation.
.. code-block:: text
COMPUTE STATIONARY|NONSTATIONARY
If the SWAN mode is stationary (see command MODE), then only the command
COMPUTE should be given here.
If the SWAN mode is nonstationary (see command MODE), then the computation can
be:
- stationary (at the specified time: option STATIONARY here).
- nonstationary (over the specified period of time.
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).
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 small domains, i.e. less than 100 km or 1 deg, a stationary computation is recommended. Otherwise, a nonstationary computation is advised.
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).
Examples
.. ipython:: python :okwarning:
from rompy_swan.components.lockup import COMPUTE
comp = COMPUTE()
print(comp.render())
comp = COMPUTE(
times=dict(model_type="stationary", time="1990-01-01T00:00:00", tfmt=2)
)
print(comp.render())
comp = COMPUTE(
times=dict(
model_type="nonstationary",
tbeg="1990-01-01T00:00:00",
tend="1990-02-01T00:00:00",
delt="PT1H",
tfmt=1,
dfmt="hr",
),
)
print(comp.render())
Source code in rompy_swan/components/lockup.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
Attributes
model_type
class-attribute
instance-attribute
model_type: Literal['compute', 'COMPUTE'] = Field(default='compute', description='Model type discriminator')
times
class-attribute
instance-attribute
times: Optional[TIMES_TYPE] = Field(default=None, description='Times for the stationary or nonstationary computation', discriminator='model_type')
i0
class-attribute
instance-attribute
i1
class-attribute
instance-attribute
Functions
times_suffix
classmethod
HOTFILE
Bases: BaseComponent
Write intermediate results.
.. code-block:: text
HOTFILE 'fname' ->FREE|UNFORMATTED
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
.. ipython:: python :okwarning:
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())
Source code in rompy_swan/components/lockup.py
Attributes
model_type
class-attribute
instance-attribute
model_type: Literal['hotfile', 'HOTFILE'] = Field(default='hotfile', description='Model type discriminator')
fname
class-attribute
instance-attribute
format
class-attribute
instance-attribute
format: Optional[Literal['free', 'unformatted']] = Field(default=None, description='Choose between free (SWAN ASCII) or unformatted (binary) format')
Functions
max_length
classmethod
cmd
COMPUTE_STAT
Bases: BaseComponent
Multiple SWAN stationary computations.
.. code-block:: text
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
.. ipython:: python :okwarning:
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())
Source code in rompy_swan/components/lockup.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
Attributes
model_type
class-attribute
instance-attribute
times
class-attribute
instance-attribute
times: TIMES_TYPE = Field(default_factory=STATIONARY, description='Compute times', discriminator='model_type')
hotfile
class-attribute
instance-attribute
hotfile: Optional[HOTFILE] = Field(default=None, description='Write results to restart files')
hottimes
class-attribute
instance-attribute
hottimes: HOTTIMES_TYPE = Field(default=[], description='Times to write hotfiles, can be a list of datetimes or times indices')
suffix
class-attribute
instance-attribute
suffix: str = Field(default='_%Y%m%dT%H%M%S', description='Time-template suffix to add to hotfile fname')
Functions
timestamp_to_datetime
classmethod
Ensure pandas.Timestamp entries are coerced into datatime.
Source code in rompy_swan/components/lockup.py
hotfile_with_hottimes
hotfile_with_hottimes() -> COMPUTE_NONSTAT
Source code in rompy_swan/components/lockup.py
cmd
Command file string for this component.
Source code in rompy_swan/components/lockup.py
COMPUTE_NONSTAT
Bases: COMPUTE_STAT
Multiple SWAN nonstationary computations.
.. code-block:: text
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.
Note
The field times is optional to allow for the case where the user wants to set
times dynamically after instantiating this component.
Examples
.. ipython:: python :okwarning:
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())
Source code in rompy_swan/components/lockup.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
Attributes
model_type
class-attribute
instance-attribute
model_type: Literal['nonstat', 'NONSTAT'] = Field(default='nonstat', description='Model type discriminator')
times
class-attribute
instance-attribute
times: NONSTATIONARY = Field(default_factory=NONSTATIONARY, description='Compute times')
initstat
class-attribute
instance-attribute
initstat: bool = Field(default=False, description='Run a STATIONARY computation at the initial time prior to the NONSTATIONARY computation(s) to prescribe initial conditions')
Functions
times_suffix
classmethod
times_suffix(times: NONSTATIONARY) -> NONSTATIONARY
cmd
Command file string for this component.
Source code in rompy_swan/components/lockup.py
STOP
Bases: BaseComponent
End of commands.
.. code-block:: text
STOP
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
.. ipython:: python :okwarning:
from rompy_swan.components.lockup import STOP
stop = STOP()
print(stop.render())