Skip to content

Commit 740092a

Browse files
Mortara  AlessandroMortara  Alessandro
authored andcommitted
chore: update methods for inductance evaluation
Modified functions: *__inductance_analytical_calculation *added check on the new mode (value = 0) *added keyword SELF_INDUCTANCE_MODE_0=0 in self_inductance_switch __inductance_approximate_calculation *added check on the new mode (value = 0) *added keyword SELF_INDUCTANCE_MODE_0=0 in self_inductance_switch __build_electric_mass_matrix *added check on the new mode (value = 0) *added keyword CONSTANT_INDUCTANCE=0 in inductance_switch NEED REFACTORING!!! Class: Conductor modified: conductor.py
1 parent b1aad2f commit 740092a

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

source_code/conductor.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# import classes
1515
from component_collection import ComponentCollection
1616
from conductor_flags import (
17+
CONSTANT_INDUCTANCE,
1718
ANALYTICAL_INDUCTANCE,
1819
APPROXIMATE_INDUCTANCE,
1920
ELECTRIC_CONDUCTANCE_UNIT_LENGTH,
@@ -22,6 +23,7 @@
2223
IOP_CONSTANT,
2324
IOP_FROM_EXT_FUNCTION,
2425
IOP_FROM_FILE,
26+
SELF_INDUCTANCE_MODE_0,
2527
SELF_INDUCTANCE_MODE_1,
2628
SELF_INDUCTANCE_MODE_2,
2729
STATIC_ELECTRIC_SOLVER,
@@ -3753,9 +3755,9 @@ def __inductance_analytical_calculation(self, mode: int = 2):
37533755
mode (int,optional): flag to select the equation for the analytical evaluation of self inductance. 1: mode 1; 2: mode 2. Defaults to 2.
37543756
"""
37553757

3756-
if mode != 1 and mode != 2:
3758+
if mode!= SELF_INDUCTANCE_MODE_0 and mode != SELF_INDUCTANCE_MODE_1 and mode != SELF_INDUCTANCE_MODE_2:
37573759
raise ValueError(
3758-
f"{self.identifier}\nArgument 'mode' must be equal to {SELF_INDUCTANCE_MODE_1 = } or to {SELF_INDUCTANCE_MODE_2 = }. Current value {mode = } is not allowed. Please check sheet {self.workbook_sheet_name[2]} in file {self.workbook_name}.\n"
3760+
f"{self.identifier}\nArgument 'mode' must be equal to {SELF_INDUCTANCE_MODE_0 = } or to {SELF_INDUCTANCE_MODE_1 = } or to {SELF_INDUCTANCE_MODE_2 = }. Current value {mode = } is not allowed. Please check sheet {self.workbook_sheet_name[2]} in file {self.workbook_name}.\n"
37593761
)
37603762
ABSTOL = 1e-6
37613763
lmod = (
@@ -3799,6 +3801,7 @@ def __inductance_analytical_calculation(self, mode: int = 2):
37993801

38003802
# Switch to evalutae self inductance.
38013803
self_inductance_switch = {
3804+
SELF_INDUCTANCE_MODE_0: self.__constant_self_inductance_evaluation,
38023805
SELF_INDUCTANCE_MODE_1: self.__self_inductance_mode1,
38033806
SELF_INDUCTANCE_MODE_2: self.__self_inductance_mode2,
38043807
}
@@ -4053,8 +4056,13 @@ def __self_inductance_mode2(self, lmod: np.ndarray) -> np.ndarray:
40534056

40544057
# START: INDUCTANCE APPROXIMATE EVALUATION
40554058

4056-
def __inductance_approximate_calculation(self):
4059+
def __inductance_approximate_calculation(self, mode : int = 2):
40574060
"""Private method that approximate the inductance of the system. For an analytical evaluation of the inductance use private method __inductance_analytical_calculation."""
4061+
4062+
if mode!= SELF_INDUCTANCE_MODE_0 and mode != SELF_INDUCTANCE_MODE_1 and mode != SELF_INDUCTANCE_MODE_2:
4063+
raise ValueError(
4064+
f"{self.identifier}\nArgument 'mode' must be equal to {SELF_INDUCTANCE_MODE_0 = } or to {SELF_INDUCTANCE_MODE_1 = } or to {SELF_INDUCTANCE_MODE_2 = }. Current value {mode = } is not allowed. Please check sheet {self.workbook_sheet_name[2]} in file {self.workbook_name}.\n"
4065+
)
40584066

40594067
ll = (
40604068
self.nodal_coordinates.iloc[
@@ -4088,8 +4096,13 @@ def __inductance_approximate_calculation(self):
40884096
ll, mutual_inductance
40894097
)
40904098

4091-
# Evaluate self inductance
4092-
self_inductance = self.__self_inductance_approximate(lmod)
4099+
self_inductance_switch = {
4100+
SELF_INDUCTANCE_MODE_0: self.__constant_self_inductance_evaluation,
4101+
SELF_INDUCTANCE_MODE_1: self.__self_inductance_mode1,
4102+
SELF_INDUCTANCE_MODE_2: self.__self_inductance_mode2,
4103+
}
4104+
self_inductance = self_inductance_switch[mode](lmod)
4105+
40934106
# Evaluate internal inductance
40944107
internal_inductance = lmod.to_numpy() / 2.0
40954108

@@ -4214,19 +4227,21 @@ def __build_electric_mass_matrix(self):
42144227
"""
42154228

42164229
if (
4217-
self.operations["INDUCTANCE_MODE"] != 0
4218-
and self.operations["INDUCTANCE_MODE"] != 1
4230+
self.operations["INDUCTANCE_MODE"] != CONSTANT_INDUCTANCE
4231+
and self.operations["INDUCTANCE_MODE"] != ANALYTICAL_INDUCTANCE
4232+
and self.operations["INDUCTANCE_MODE"] != APPROXIMATE_INDUCTANCE
42194233
):
42204234
raise ValueError(
4221-
f"{self.identifier = }\nArgument self.operations['INDUCTANCE_MODE'] should be equal to {APPROXIMATE_INDUCTANCE = } or {ANALYTICAL_INDUCTANCE = }. Current value ({self.operations['INDUCTANCE_MODE'] = }) is not allowed. Please check {self.workbook_sheet_name[2]} in file {self.workbook_name}.\n"
4235+
f"{self.identifier = }\nArgument self.operations['INDUCTANCE_MODE'] should be equal to {CONSTANT_INDUCTANCE = } or {APPROXIMATE_INDUCTANCE = } or {ANALYTICAL_INDUCTANCE = }. Current value ({self.operations['INDUCTANCE_MODE'] = }) is not allowed. Please check {self.workbook_sheet_name[2]} in file {self.workbook_name}.\n"
42224236
)
42234237

42244238
inductance_switch = {
4239+
CONSTANT_INDUCTANCE: self.__constant_inductance,
42254240
ANALYTICAL_INDUCTANCE: self.__inductance_analytical_calculation,
42264241
APPROXIMATE_INDUCTANCE: self.__inductance_approximate_calculation,
42274242
}
42284243

4229-
inductance_switch[self.operations["INDUCTANCE_MODE"]]()
4244+
inductance_switch[self.operations["INDUCTANCE_MODE"]](self.operations["SELF_INDUCTANCE_MODE"])
42304245

42314246
self.electric_mass_matrix[
42324247
: self.total_elements_current_carriers,

0 commit comments

Comments
 (0)