Skip to content

cable_builder

Module responsible for building FDCable objects based on given cable specifications.

CableBuilder

Utility class responsible for constructing FDCable objects based on various input specifications.

build_cable_from_cable_id classmethod

build_cable_from_cable_id(
    cable_id: str,
    fd_cable_class: type[CableT],
    grid_points_per_layer: int = 10,
    pipe: PipeInputSchema | None = None,
    cable_source_file_path: Path = __PROJECT_ROOT
    / "data"
    / "example_cables.csv",
) -> CableT

Builds a new FDCable instance based on a cable_id.

Parameters:

Name Type Description Default
cable_id str

The name of a cable mentioned in the file specified by cable_source_file_path.

required
grid_points_per_layer int

The number of points per cable layer.

10
pipe PipeInputSchema | None

A pipe instance to be added around the cable.

None
fd_cable_class type[FDCable]

The FDCable class to instantiate.

required
cable_source_file_path Path

The path to the cable source file. Defaults to "data/example_cables.csv". The file can be either a CSV or an Excel file.

__PROJECT_ROOT / 'data' / 'example_cables.csv'

Returns:

Name Type Description
TFDCable CableT

A new FDCable instance (based on a Cable instance).

Source code in cable_thermal_model/cable/cable_builder.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
@classmethod
def build_cable_from_cable_id(
    cls,
    cable_id: str,
    fd_cable_class: type[CableT],
    grid_points_per_layer: int = 10,
    pipe: PipeInputSchema | None = None,
    cable_source_file_path: Path = __PROJECT_ROOT / "data" / "example_cables.csv",
) -> CableT:
    """Builds a new FDCable instance based on a cable_id.

    Args:
        cable_id (str): The name of a cable mentioned in the file specified by `cable_source_file_path`.
        grid_points_per_layer (int): The number of points per cable layer.
        pipe (PipeInputSchema | None): A pipe instance to be added around the cable.
        fd_cable_class (type[FDCable]): The FDCable class to instantiate.
        cable_source_file_path (Path): The path to the cable source file.
            Defaults to "data/example_cables.csv". The file can be either
            a CSV or an Excel file.

    Returns:
            TFDCable: A new FDCable instance (based on a Cable instance).

    """
    if (
        fd_cable_class in [FDCableTrefoilCircuitInSinglePipe, FDCableTrefoilCircuitInSinglePipeInAir]
        and pipe is None
    ):
        raise ValueError(f"When using FDCable class '{fd_cable_class.__name__}', a pipe must be provided.")

    # load the cable data from the specified file
    cable_specs = cls._load_cable_data_from_file(cable_source_file_path, cable_id)

    # build the cable based on the loaded data
    return cls.build_cable_from_cable_specs(
        cable_specs=cable_specs,
        fd_cable_class=fd_cable_class,
        grid_points_per_layer=grid_points_per_layer,
        pipe=pipe,
    )

build_cable_from_cable_specs classmethod

build_cable_from_cable_specs(
    cable_specs: Series,
    fd_cable_class: type[CableT],
    grid_points_per_layer: int = 10,
    pipe: PipeInputSchema | None = None,
) -> CableT

Builds a new FDCable instance based on a given set of cable specifications.

Parameters:

Name Type Description Default
cable_specs Series

A Pandas Series holding the cable specification.

required
grid_points_per_layer int | None

The number of points per layer to use in FD grids

10
pipe PipeInputSchema | None

A pipe instance to be added around the cable.

None
fd_cable_class type[FDCable]

The FDCable class to instantiate.

required

Returns:

Name Type Description
TFDCable CableT

A new FDCable instance (based on a Cable instance).

Source code in cable_thermal_model/cable/cable_builder.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@classmethod
def build_cable_from_cable_specs(
    cls,
    cable_specs: pd.Series,
    fd_cable_class: type[CableT],
    grid_points_per_layer: int = 10,
    pipe: PipeInputSchema | None = None,
) -> CableT:
    """Builds a new FDCable instance based on a given set of cable specifications.

    Args:
        cable_specs (pd.Series): A Pandas Series holding the cable specification.
        grid_points_per_layer (int | None): The number of points per layer to use in FD grids
        pipe (PipeInputSchema | None): A pipe instance to be added around the cable.
        fd_cable_class (type[FDCable]): The FDCable class to instantiate.

    Returns:
            TFDCable: A new FDCable instance (based on a Cable instance).

    """
    cable_spec_parser = SpecParserFactory.get_spec_parser(cable_specs)
    cable_constructional_input: CableConstructionalInputSchema = cable_spec_parser.get_cable_constructional_input()

    # build the cable based on the parsed specifications
    return cls.build_cable(
        cable_constructional_input=cable_constructional_input,
        fd_cable_class=fd_cable_class,
        grid_points_per_layer=grid_points_per_layer,
        pipe=pipe,
    )

build_cable classmethod

build_cable(
    cable_constructional_input: CableConstructionalInputSchema,
    fd_cable_class: type[CableT],
    grid_points_per_layer: int = 10,
    pipe: PipeInputSchema | None = None,
) -> CableT

Build FD cable object.

Parameters:

Name Type Description Default
cable_constructional_input CableConstructionalInputSchema

A CableConstructionalInputSchema object holding the cable specification.

required
grid_points_per_layer int

The number of points per layer to use in FD grids

10
fd_cable_class type[FDCable]

The FDCable class to instantiate.

required
pipe PipeInputSchema | None

A pipe instance to be added around the cable.

None

Returns:

Name Type Description
CableT CableT

A finite-difference cable object.

Source code in cable_thermal_model/cable/cable_builder.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
@classmethod
def build_cable(
    cls,
    cable_constructional_input: CableConstructionalInputSchema,
    fd_cable_class: type[CableT],
    grid_points_per_layer: int = 10,
    pipe: PipeInputSchema | None = None,
) -> CableT:
    """Build FD cable object.

    Args:
        cable_constructional_input (CableConstructionalInputSchema):
            A CableConstructionalInputSchema object holding the cable
            specification.
        grid_points_per_layer (int): The number of points per layer to use in FD grids
        fd_cable_class (type[FDCable]): The FDCable class to instantiate.
        pipe (PipeInputSchema | None): A pipe instance to be added around the cable.

    Returns:
        CableT: A finite-difference cable object.

    """
    # retrieve the cable's conductor properties
    cable_conductor_properties: CableConductorProperties = cls._get_cable_conductor_properties(
        cable_constructional_input
    )

    # retrieve the cable's layer properties
    cable_layer_properties_by_layer: dict[CableLayer, CableLayerProperties] = cls._get_cable_layer_properties(
        cable_constructional_input
    )

    # retrieve the cable's layer metrics
    cable_layer_metrics: CableLayerMetrics = cls._get_cable_layer_metrics(cable_constructional_input)

    # instantiate the cable
    fd_cable = fd_cable_class(
        conductor=cable_conductor_properties,
        layer_properties=cable_layer_properties_by_layer,
        layer_metrics=cable_layer_metrics,
        cable_type=cable_constructional_input.cable_type,
        grid_counts=dict.fromkeys(cable_layer_properties_by_layer.keys(), grid_points_per_layer),
    )

    # add a pipe around the cable if specified
    if pipe is not None:
        fd_cable = fd_cable.get_cable_copy_with_pipe(
            Pipe(
                pipe_input=pipe,
                outer_radius_cable=fd_cable.layer_metrics.cable_radius,
            )
        )

    return fd_cable