tud_lbm.config.adapter_toml
TOML configuration file adapter.
Reads and writes .toml config files.
Requires Python ≥ 3.11 (tomllib in stdlib) or the tomli
back-port on Python 3.10:
pip install tomli
Example usage:
from config.adapter_toml import TomlAdapter
adapter = TomlAdapter()
config = adapter.load("example_for_test/config_simple.toml")
adapter.save(config, "output/config.toml")
Attributes
Classes
Adapter that reads and writes TOML configuration files. |
Module Contents
- class tud_lbm.config.adapter_toml.TomlAdapter[source]
Bases:
tud_lbm.config.adapter_base.ConfigAdapterAdapter that reads and writes TOML configuration files.
Supported top-level tables
[simulation_type]Required. Contains the simulation type (
type), grid shape, physics parameters, and runner/IO fields.[multiphase]Optional. Extra physics parameters when
type = "multiphase".[gravity_force]/[electric_force]/ …Optional. One top-level table per force model.
[boundary_conditions]Optional. Boundary condition configuration (including nested
wetting_paramsandhysteresis_params).[output]Optional. Output/saving overrides (
results_dir,fields).
- load_raw(path: str) dict[str, Any][source]
Parse path and return raw configuration dict.
Unlike
load(), this returns the raw config dict without instantiatingSimulationConfig. Useful for detecting array fields before expansion.- Parameters:
path – Filesystem path to a
.tomlfile.- Returns:
Raw config dictionary (may contain array values for physics parameters, plus output overrides from
[output]).- Raises:
FileNotFoundError – If path does not exist.
ValueError – If required sections/keys are missing.
- load(path: str) tud_lbm.config.simulation_config.SimulationConfig[source]
Parse path and return a
SimulationConfig.Supports both scalar and array-valued parameters. For array parameters, use
load_raw()followed byexpand_config()to generate multiple configs.- Parameters:
path – Filesystem path to a
.tomlfile.- Returns:
A validated
SimulationConfig.- Raises:
FileNotFoundError – If path does not exist.
ValueError – If required sections/keys are missing or invalid.
- save(config: tud_lbm.config.simulation_config.SimulationConfig, path: str) None[source]
Serialise config to a
.tomlfile at path.Delegates the field → section bucketing to
build_sections()(shared by all adapters) and writes the result withtomli_w.- Parameters:
config – A validated
SimulationConfig.path – Destination file path.
- Raises:
OSError – If the file cannot be written.
ImportError – If tomli_w is not installed.