neofoam.framework.initialization.config_context

Configuration Context

Central context for inter-model configuration exchange during initialization.

class neofoam.framework.initialization.config_context.ConfigContext(current_region: str = 'default')[source]

Bases: object

Context for inter-model configuration exchange during RESOLVE_DEPENDENCIES stage.

Models are registered by name and can be retrieved by other models during the RESOLVE_DEPENDENCIES stage to establish dependencies and exchange configuration.

Supports both intra-region (same region) and inter-region (cross-region) model access via dot notation: - “model_name” → model in current region - “region.model_name” → model in specified region

all(region: str | None = None) dict[str, Any][source]

Get all registered models in a region.

Args:

region: Region name (defaults to current_region)

Returns:

Dictionary mapping model names to model instances

contains(path: str) bool[source]

Check if a model is registered.

Supports both intra-region and inter-region paths.

Args:

path: Model path (name or region.name)

Returns:

True if the model is registered, False otherwise

get(path: str) Any[source]

Get a registered model by path.

Supports both intra-region and inter-region access: - “model_name” → model in current region - “region.model_name” → model in specified region

Args:

path: Model path (name or region.name)

Returns:

The model instance, or None if not found

Example:

# Same region access velocity = config.get(“velocity”) transport = config.get(“transport”)

# Cross-region access fluid_temp = config.get(“fluid.temperature”) solid_temp = config.get(“solid.temperature”)

get_by_prefix(prefix: str, region: str | None = None) dict[str, Any][source]

Get all models with names starting with a prefix in a region.

Useful for finding related model instances that follow a naming convention (e.g., “heat_source_1”, “heat_source_2”).

Args:

prefix: The prefix to match against model names region: Region name (defaults to current_region)

Returns:

Dictionary of models with matching names

Example:

sources = config.get_by_prefix(”heat_source_”) for name, source in sources.items():

print(f”{name}: {source.power}W”)

get_by_type(model_type: type, region: str | None = None) list[Any][source]

Get all registered models of a specific type in a region.

Useful for working with multiple instances of the same model type (e.g., multiple heat sources, multiple porous zones).

Args:

model_type: The type/class to filter by region: Region name (defaults to current_region)

Returns:

List of all model instances of the specified type

Example:

heat_sources = config.get_by_type(HeatSource) for source in heat_sources:

source.enabled = False

get_configurable_fields(path: str) dict[str, Any][source]

Get all configurable fields and their current values from a model.

Scans a model’s field definitions for fields marked with Configurable[T] type annotation and returns their current values.

Args:

path: Model path (name or region.name)

Returns:

Dictionary mapping configurable field names to their current values, or empty dict if model not found or has no configurable fields

Example:

configurable = config.get_configurable_fields(“pressure_algorithm”) # Returns: {“use_buoyancy”: False, “algorithm”: “SIMPLE”}

# Can check what’s configurable before modifying if “use_buoyancy” in configurable:

pressure.use_buoyancy = True

property regions: list[str]

Get list of all registered region names.

Returns:

List of region names

register(name: str, model: Any, region: str | None = None) None[source]

Register a model by name in a region.

Args:

name: Unique identifier for the model within the region model: The model instance to register region: Region name (defaults to current_region)

neofoam.framework.initialization.config_context.is_configurable_field(field_info: Any) bool[source]

Check if a field is marked as Configurable.