Skip to content

Config

The SwanConfig class is the main entry point for configuring SWAN simulations.

SwanConfig

Bases: BaseConfig

SWAN config class.

TODO: Combine boundary and inpgrid into a single input type.

Note

The cgrid is the only required field since it is used to define the swan grid object which is passed to other components.

Time Control

When calling the config with a runtime TimeRange object (e.g., from ModelRun.period), the temporal parameters are set as follows:

COMPUTE Components (LOCKUP): - Time values (tbeg, tend, delt) are always from the runtime TimeRange - Time and interval formatting (tfmt, dfmt) can be specified in the component's times field - The runtime interval defines the computational timestep (deltc)

OUTPUT Components (BLOCK, TABLE, SPECOUT, NESTOUT): - Start time (tbeg) is always from runtime start - Time interval (delt) can be specified in the component's times field to override runtime interval - Time and interval formatting (tfmt, dfmt) can be specified in the component's times field - If no times field is specified, the component uses runtime interval for delt

This allows fine-grained control over: - COMPUTE: Time and interval formatting - OUTPUT: Time interval and formatting

All components start at the same time from ModelRun.period.start.

Examples

.. code-block:: python

from datetime import datetime, timedelta
from rompy.core.time import TimeRange

# Runtime with 1-hour interval
runtime = TimeRange(
    start=datetime(2024, 1, 1, 0, 0, 0),
    end=datetime(2024, 1, 2, 0, 0, 0),
    interval=timedelta(hours=1),
)

config = SwanConfig(
    cgrid=dict(...),
    output=dict(
        # Custom 30-minute output interval
        block=dict(
            sname="COMPGRID",
            fname="output.nc",
            output=["hsign"],
            times=dict(delt=timedelta(minutes=30), tfmt=1, dfmt="min"),
        ),
        # Uses runtime interval (1 hour)
        table=dict(
            sname="COMPGRID",
            fname="table.nc",
            output=["dir"],
        ),
    ),
)

# Result:
# - COMPUTE: deltc = 1 HR (from runtime)
# - BLOCK: deltblk = 30 MIN (from component times)
# - TABLE: delttbl = 1 HR (from runtime)
rendered = config(runtime)

Attributes

cgrid instance-attribute

cgrid: CGRID_TYPES

startup class-attribute instance-attribute

startup: Optional[STARTUP_TYPE] = Field(default=None)

inpgrid class-attribute instance-attribute

inpgrid: Optional[INPGRID_TYPES] = Field(default=None)

boundary class-attribute instance-attribute

boundary: Optional[BOUNDARY_TYPES] = Field(default=None)

initial class-attribute instance-attribute

initial: Optional[INITIAL_TYPE] = Field(default=None)

physics class-attribute instance-attribute

physics: Optional[PHYSICS_TYPE] = Field(default=None)

prop class-attribute instance-attribute

prop: Optional[PROP_TYPE] = Field(default=None)

numeric class-attribute instance-attribute

numeric: Optional[NUMERIC_TYPE] = Field(default=None)

output class-attribute instance-attribute

output: Optional[OUTPUT_TYPE] = Field(default=None)

lockup class-attribute instance-attribute

lockup: Optional[LOCKUP_TYPE] = Field(default=None)

grid property

grid

Define a SwanGrid from the cgrid field.