Skip to content

model_factory

ModelFactory

Factory class for creating model instances based on the environment.

create_model staticmethod

create_model(static_env: StaticEnvAir) -> ModelAir
create_model(static_env: StaticEnvSoil) -> ModelSoil
create_model(static_env: StaticEnv) -> Model
create_model(static_env: StaticEnvT) -> Model

Create a model instance based on the environment type.

Parameters:

Name Type Description Default
static_env StaticEnvT

Static environment configuration for the model.

required

Returns:

Name Type Description
Model Model

An instance of ModelAir or ModelSoil, depending on the type of static_env.

Raises:

Type Description
ValueError

If static_env is not a supported environment type.

Source code in cable_thermal_model/model/model_factory.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
@staticmethod
def create_model(
    static_env: StaticEnvT,
) -> Model:
    """Create a model instance based on the environment type.

    Args:
        static_env (StaticEnvT): Static environment configuration for the model.

    Returns:
        Model: An instance of ModelAir or ModelSoil, depending on the type of static_env.

    Raises:
        ValueError: If static_env is not a supported environment type.
    """
    if isinstance(static_env, StaticEnvAir):
        return ModelAir(static_env=static_env)
    elif isinstance(static_env, StaticEnvSoil):
        return ModelSoil(static_env=static_env)
    else:
        raise ValueError(
            f"Unsupported static environment type: {type(static_env).__name__}. "
            f"Expected {StaticEnvAir.__name__} or {StaticEnvSoil.__name__}."
        )