ctg.config#

Configuration system for CTG wave equation solver.

This module provides Pydantic-based configuration classes that support: - Loading from YAML files - Automatic validation of types and values - Resolution of string paths to callable functions - Handling of arbitrary types (MPI communicators, callables)

Example

Load configuration from YAML file:

from pathlib import Path
from ctg.config import load_config

config = load_config(Path("config.yaml"))
print(config.numerics.n_cells_space)  # 100

Create configuration with string references to functions:

config = AppConfig(
    physics={
        "initial_data_u": "data.data_functions_pwe:initial_u",
        "rhs_0": "data.data_functions_pwe:rhs_0"
    }
)

Functions

load_config(source)

Load configuration from a YAML file path or YAML string content.

Classes

AppConfig(*args, **kwargs)

Main application configuration container.

numericsCfg(*args, **kwargs)

Numerical discretization and solver configuration.

physicsCfg(*args, **kwargs)

Physics configuration for wave equation problem.

postCfg(*args, **kwargs)

Post-processing configuration.

class ctg.config.AppConfig(*args, **kwargs)[source]#

Bases: BaseModel

Main application configuration container.

Aggregates all configuration sections for the CTG wave equation solver: physics setup and numerical parameters.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

physics#

Physics configuration (initial/boundary conditions, forcing).

numerics#

Numerical discretization configuration.

Example:

# Create with defaults
config = AppConfig()

# Load from YAML
config = load_config(Path("config.yaml"))

# Create programmatically
config = AppConfig(
    physics={"initial_data_u": "data.funcs:my_initial_u"},
    numerics={"n_cells_space": 200, "end_time": 2.0},
)
ctg.config.load_config(source)[source]#

Load configuration from a YAML file path or YAML string content.

Accepts either a Path to a YAML file or a string containing YAML content. Creates a validated AppConfig instance and automatically resolves string references to callable functions.

Parameters:

source (Union[Path, str]) – Either a Path object pointing to a YAML configuration file, or a string containing YAML content.

Returns:

Validated configuration object with all settings loaded

and callables resolved.

Return type:

AppConfig

Raises:
  • FileNotFoundError – If source is a Path and the file doesn’t exist.

  • yaml.YAMLError – If the YAML content is malformed.

  • pydantic.ValidationError – If the configuration doesn’t match the schema.

Example

>>> from pathlib import Path
>>> # Load from file path
>>> config = load_config(Path("configs/wave_eq.yaml"))
>>> print(config.numerics.n_cells_space)
100
>>> # Load from YAML string
>>> yaml_str = '''
... physics:
...   initial_data_u: "data.data_functions_pwe:initial_u"
... numerics:
...   n_cells_space: 100
... '''
>>> config = load_config(yaml_str)
class ctg.config.numericsCfg(*args, **kwargs)[source]#

Bases: BaseModel

Numerical discretization and solver configuration.

Defines spatial and temporal discretization parameters, random seed, and MPI communicator for parallel execution.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

seed#

Random seed for reproducibility. Default: 0.

comm#

MPI communicator for parallel execution. Default: MPI.COMM_SELF. Can be specified as a string path like “module:attribute”.

n_cells_space#

Number of spatial mesh cells. Default: 100.

order_x#

Polynomial degree for spatial finite elements. Default: 1.

t_slab_size#

Time slab size for space-time discretization. Default: 0.01.

order_t#

Polynomial degree for temporal finite elements. Default: 1.

verbose#

Print output from CTGSolver during run. Default: False.

Example

>>> numerics = numericsCfg(
...     n_cells_space=200,
...     t_slab_size=0.05,
...     comm="data.data_pwe_functions:comm"
... )
resolve_comm()#

Resolve an MPI communicator from a string path or return it.

class ctg.config.physicsCfg(*args, **kwargs)[source]#

Bases: BaseModel

Physics configuration for wave equation problem.

Stores callable functions defining the physics of the wave equation: initial conditions, boundary conditions, and right-hand side forcing terms. All functions should accept X with shape (n_points, 2) where columns are [t, x].

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

exact_sol_u#

Exact solution for displacement.

exact_sol_v#

Exact solution for verlocity.

initial_data_u#

Initial condition for displacement u(x, t=0). Default returns zeros.

initial_data_v#

Initial condition for velocity v(x, t=0). Default returns zeros.

boundary_data_u#

Boundary condition for displacement u on domain boundary. Default returns zeros.

boundary_data_v#

Boundary condition for velocity v on domain boundary. Default returns zeros.

boundary_D#

Dirichlet boundary condition specification. Default returns zeros.

rhs_0#

Right-hand side forcing term for first equation. Default returns zeros.

rhs_1#

Right-hand side forcing term for second equation. Default returns zeros.

start_time#

Start time for the physics simulation. Default: 0.0.

end_time#

End time for the physics simulation. Default: 1.0.

Note

Functions can be specified as: - Direct callables: lambda X: np.sin(X[:, 1]) - String paths: “module.submodule:function_name” - Dicts with params: {“path”: “module:func”, “params”: {“a”: 1}} - exact_sol_u and exact_sol_v are optional

Example

>>> physics = physicsCfg(
...     initial_data_u="data.data_functions_pwe:initial_u",
...     rhs_0=lambda X: np.zeros(X.shape[0]),
...     start_time=0.0,
...     end_time=2.0
... )
resolve_callables()#

Resolve a callable specified as a callable, string, or dict.

class ctg.config.postCfg(*args, **kwargs)[source]#

Bases: BaseModel

Post-processing configuration.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

dir_save: str = Ellipsis#