Skip to content

Config

Config is the XBeach model configuration. It gathers the grid, bathymetry, forcing and model settings, and writes params.txt and the input files. It subclasses rompy's BaseConfig.

XBEACH Rompy config.

logger module-attribute

logger = logging.getLogger(__name__)

HERE module-attribute

HERE = Path(__file__).parent

WBCTYPE_WAVEMODELS module-attribute

WBCTYPE_WAVEMODELS = {
    "parametric": {"surfbeat", "nonh"},
    "swan": {"surfbeat", "nonh"},
    "vardens": {"surfbeat", "nonh"},
    "reuse": {"surfbeat", "nonh"},
    "ts_1": {"surfbeat"},
    "ts_2": {"surfbeat"},
    "ts_nonh": {"nonh"},
}

WindType module-attribute

WindType = Annotated[
    Union[load_entry_points("xbeach.data", etype="wind")],
    Field(
        description="Wind input data",
        discriminator="model_type",
    ),
]

WaveType module-attribute

WaveType = Annotated[
    Union[load_entry_points("xbeach.data", etype="wave")],
    Field(
        description="Wave input data",
        discriminator="model_type",
    ),
]

TideType module-attribute

TideType = Annotated[
    Union[load_entry_points("xbeach.data", etype="tide")],
    Field(
        description="Tide input data",
        discriminator="model_type",
    ),
]

DataInterface pydantic-model

DataInterface(**data: Any)

Bases: RompyBaseModel

XBeach forcing data: waves, wind and tide.

Each field takes a data interface, which writes its forcing files into the workspace and returns the XBeach parameters that point to them.

Examples

from rompy_xbeach.config import DataInterface
from rompy_xbeach.data.boundary import BoundaryParams

print(DataInterface(wave=BoundaryParams(Hrms=1.0, Trep=10.0, dir0=270.0)))
DataInterface:
  model_type: data
  wave:
    nmax: None
    wbcevarreduce: None
    bclwonly: None
    swkhmin: None
    wbcRemoveStokes: None
    wbcScaleEnergy: None
    cyclicdiradjust: None
    taper: None
    ARC: None
    freewave: None
    thetamin: None
    thetamax: None
    dtheta: None
    dtheta_s: None
    thetanaut: None
    order: None
    id: params
    model_type: params
    Hrms: 1.0
    Trep: 10.0
    Tlong: None
    dir0: 270.0
    m: 10
  wind: None
  tide: None

Fields:

model_type pydantic-field

model_type: Literal['data'] = 'data'

Model type discriminator

wave pydantic-field

wave: Optional[WaveType] = None

wind pydantic-field

wind: Optional[WindType] = None

tide pydantic-field

tide: Optional[TideType] = None

get

get(
    staging_dir: Path, grid: RegularGrid, period: TimeRange
)

Generate each input data and return the XBeach params.

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.

Config pydantic-model

Config(**data: Any)

Bases: XBeachBaseConfig

XBeach model configuration.

Gathers the grid, bathymetry, forcing and model settings. When a ModelRun generates the workspace, the configuration writes the input files and params.txt: the data interfaces (bathy and input) write their files and return the parameters that point to them, and the components (physics, sediment, output, the boundaries, mpi and hotstart) add their parameters.

The validators reject combinations XBeach refuses, such as a wave boundary type that does not suit the wave model.

Fields:

Validators:

model_type pydantic-field

model_type: Literal['xbeach'] = 'xbeach'

Model type discriminator

template pydantic-field

template: str = str(HERE / 'templates' / 'base')

The model config template

grid pydantic-field

The XBeach grid object

bathy pydantic-field

bathy: XBeachBathy

The XBeach bathymetry object

input pydantic-field

input: Optional[DataInterface] = None

Input data including wave, wind, and tide boundary conditions

physics pydantic-field

physics: Physics

Physical processes configuration, including the required wave model

sediment pydantic-field

sediment: Optional[Sediment]

Sediment transport configuration

mpi pydantic-field

mpi: Optional[Mpi]

MPI parallelisation configuration

output pydantic-field

output: Output

Output configuration

flow_boundary pydantic-field

flow_boundary: Optional[FlowBoundaryConditions] = None

Flow boundary conditions for shallow water equations

tide_boundary pydantic-field

tide_boundary: Optional[TideBoundaryConditions] = None

Tide and surge boundary conditions

hotstart pydantic-field

hotstart: Optional[Union[bool, Hotstart]] = None

Hotstart configuration. Set to True to enable hotstart with files already in run directory, or provide a Hotstart object to specify source directory and file number.

tunits pydantic-field

tunits: Optional[str] = None

Time units in udunits format, if not provided it is constructed based on the simulation start time (XBeach default: s)

params property

params: dict

Return the XBeach configuration parameters.

checkout pydantic-field

checkout: Optional[str] = 'main'

The git branch to use if the template is a git repo

set_dtheta_if_surfbeat pydantic-validator

set_dtheta_if_surfbeat() -> Config

Placeholder validator for future dtheta logic.

check_wave_boundary_for_wavemodel pydantic-validator

check_wave_boundary_for_wavemodel() -> Config

Raise if the wave boundary type cannot be used with the wave model.

XBeach stops at start-up for these combinations, see WBCTYPE_WAVEMODELS. Bichromatic waves (wbctype=params with Tlong) require the surfbeat model.

warn_wave_direction_params_without_swave pydantic-validator

warn_wave_direction_params_without_swave() -> Config

Warn if wave directional parameters are set but swave is disabled.

The wave directional grid parameters (thetamin, thetamax, dtheta, dtheta_s, thetanaut) are only used when short waves are enabled (swave=1). Setting these when swave=0 has no effect.

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(context: dict, output_dir: Path | str) -> None

Render the configuration template to the output directory.

This method orchestrates the template rendering process. The default implementation uses cookiecutter rendering with the template and checkout defined on this config. Subclasses can override this method to implement alternative rendering strategies (e.g., direct file writing, Jinja2, custom logic).

Parameters:

Name Type Description Default
context dict

Full context dictionary. Expected to contain at least 'runtime' and 'config' keys.

required
output_dir Path | str

Target directory for rendered output.

required