Skip to content

Commit fccfa56

Browse files
Merge pull request #148 from upb-lea/ito
Change logging behavior
2 parents 2a4b8d9 + 1bf30a7 commit fccfa56

61 files changed

Lines changed: 1164 additions & 1180 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/python-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Set up Python
2828
uses: actions/setup-python@v3
2929
with:
30-
python-version: '3.x'
30+
python-version: '3.12'
3131
- name: Install dependencies
3232
run: |
3333
python -m pip install --upgrade pip

.github/workflows/sphinx_render_docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup Python
1919
uses: actions/setup-python@v5
2020
with:
21-
python-version: '3.10'
21+
python-version: '3.12'
2222
- uses: actions/checkout@v4
2323
- name: install femmt package
2424
run: |

femmt/component.py

Lines changed: 218 additions & 246 deletions
Large diffs are not rendered by default.

femmt/data.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
"""Contains information about the file structure."""
22
# Python standard libraries
33
import os
4-
4+
import logging
55
import numpy as np
6-
from typing import List
76

87
# Local libraries
98
from femmt.enumerations import ConductorType
109
from femmt.model import Conductor
11-
from typing import Optional
1210

11+
logger = logging.getLogger(__name__)
1312

1413
class FileData:
1514
"""Contains paths to every folder and file needed in femmt."""
1615

1716
def __init__(self, working_directory: str, electro_magnetic_folder_path: str = None, strands_coefficients_folder_path: str = None):
1817
if working_directory is not None:
1918
self.update_paths(working_directory, electro_magnetic_folder_path, strands_coefficients_folder_path)
20-
self.onelab_folder_path: Optional[str] = None
19+
self.onelab_folder_path: str | None = None
2120

2221
@staticmethod
2322
def create_folders(*args: str) -> None:
@@ -57,10 +56,9 @@ def clean_folder_structure(folder_path: str):
5756
for file in files:
5857
file_path = os.path.join(root, file)
5958
os.remove(file_path)
60-
# print(f"remove {file_path}")
61-
# print("All simulation results from previous simulations have been deleted successfully.")
59+
# logger.info("All simulation results from previous simulations have been deleted successfully.")
6260
except OSError:
63-
print("Error occurred while deleting files and subdirectories.")
61+
logger.warning("Error occurred while deleting files and subdirectories.")
6462

6563
def update_paths(self, working_directory: str, electro_magnetic_folder_path: str = None, strands_coefficients_folder_path: str = None) -> None:
6664
"""Set the local path based on the given working directory.
@@ -123,16 +121,16 @@ class MeshData:
123121
skin_mesh_factor: float
124122
c_core: float
125123
c_window: float
126-
c_conductor = List[float]
127-
c_center_conductor = List[float]
124+
c_conductor = list[float]
125+
c_center_conductor = list[float]
128126
c_air_gaps: float
129127

130128
center_factor: float
131129

132130
mu0: float
133131
core_w: float
134132
window_w: float
135-
windings: List["Conductor"] # This is written as string because it is a forward import
133+
windings: list["Conductor"] # This is written as string because it is a forward import
136134

137135
frequency: float
138136

@@ -153,7 +151,7 @@ def __init__(self, mesh_accuracy_core: float,
153151
# The value 4 has good impact on the runtime and does not affect the simulation results too much.
154152
self.center_factor = 4
155153

156-
def update_spatial_data(self, core_w: float, window_w: float, windings: List["Conductor"]):
154+
def update_spatial_data(self, core_w: float, window_w: float, windings: list["Conductor"]):
157155
"""
158156
Update geometry data of the core of the magnetic component.
159157
@@ -162,7 +160,7 @@ def update_spatial_data(self, core_w: float, window_w: float, windings: List["Co
162160
:param window_w: window width
163161
:type window_w: float
164162
:param windings: list of windings
165-
:type windings: List["Conductor"]
163+
:type windings: list["Conductor"]
166164
"""
167165
self.core_w = core_w
168166
self.window_w = window_w

femmt/drawing.py

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""Draw structures inside Onelab."""
22
# Python standard libraries
33
import numpy as np
4-
from logging import Logger
5-
from typing import List
4+
import logging
65

76
# Local libraries
87
from femmt.enumerations import *
98
from femmt.data import MeshData
109
from femmt.model import Core, WindingWindow, AirGaps, StrayPath, Insulation
1110

11+
logger = logging.getLogger(__name__)
1212

1313
class TwoDaxiSymmetric:
1414
"""
@@ -18,28 +18,27 @@ class TwoDaxiSymmetric:
1818
"""
1919

2020
core: Core
21-
winding_windows: List[WindingWindow]
21+
winding_windows: list[WindingWindow]
2222
air_gaps: AirGaps
2323
stray_path: StrayPath
2424
insulation: Insulation
2525
component_type: ComponentType
2626
mesh_data: MeshData
2727
number_of_windings: int
2828
verbosity: Verbosity
29-
logger: Logger
3029

3130
# List of points which represent the model
3231
# Every List is a List of 4 Points: x, y, z, mesh_factor
3332
p_outer: np.ndarray
3433
p_region_bound: np.ndarray
3534
p_window: np.ndarray
3635
p_air_gaps: np.ndarray
37-
# p_conductor: List[List[float]]
38-
p_iso_core: List[List[float]]
39-
p_iso_pri_sec: List[List[float]]
36+
# p_conductor: list[list[float]]
37+
p_iso_core: list[list[float]]
38+
p_iso_pri_sec: list[list[float]]
4039

41-
def __init__(self, core: Core, mesh_data: MeshData, air_gaps: AirGaps, winding_windows: List[WindingWindow],
42-
stray_path: StrayPath, insulation: Insulation, component_type: ComponentType, number_of_windings: int, verbosity: Verbosity, logger: Logger):
40+
def __init__(self, core: Core, mesh_data: MeshData, air_gaps: AirGaps, winding_windows: list[WindingWindow],
41+
stray_path: StrayPath, insulation: Insulation, component_type: ComponentType, number_of_windings: int, verbosity: Verbosity):
4342
self.core = core
4443
self.mesh_data = mesh_data
4544
self.winding_windows = winding_windows
@@ -49,7 +48,6 @@ def __init__(self, core: Core, mesh_data: MeshData, air_gaps: AirGaps, winding_w
4948
self.insulation = insulation
5049
self.number_of_windings = number_of_windings
5150
self.verbosity = verbosity
52-
self.logger = logger
5351

5452
# -- Arrays for geometry data --
5553
# TODO Is the zero initialization necessary?
@@ -71,16 +69,6 @@ def __init__(self, core: Core, mesh_data: MeshData, air_gaps: AirGaps, winding_w
7169
self.r_inner = core.r_inner
7270
self.r_outer = core.r_outer
7371

74-
def femmt_print(self, text: str):
75-
"""
76-
Print text to terminal or to log-file, dependent on the current verbosity.
77-
78-
:param text: text to print
79-
:type text: str
80-
"""
81-
if not self.verbosity == Verbosity.Silent:
82-
self.logger.info(text)
83-
8472
def draw_outer(self):
8573
"""Draws the outer points of the main core (single core)."""
8674
# Outer Core
@@ -96,7 +84,6 @@ def draw_outer(self):
9684
def draw_single_window(self):
9785
"""Draw a single window."""
9886
# At this point both windows (in a cut) are modeled
99-
# print(f"win: c_window: {self.component.mesh.c_window}")
10087
self.p_window[0] = [-self.r_inner,
10188
-self.core.window_h / 2,
10289
0,
@@ -277,9 +264,6 @@ def draw_conductors(self, draw_top_down: bool = True):
277264
right_bound = virtual_winding_window.right_bound
278265

279266
# Check, if virtual winding window fits in physical window
280-
# print(f"{bot_bound = }\n", f"{top_bound = }\n", f"{left_bound = }\n", f"{right_bound = }\n")
281-
# print(f"{winding_window.max_bot_bound = }\n", f"{winding_window.max_top_bound = }\n", f"{winding_window.max_left_bound = }\n",
282-
# f"{winding_window.max_right_bound = }\n")
283267
if bot_bound < winding_window.max_bot_bound or top_bound > winding_window.max_top_bound or \
284268
left_bound < winding_window.max_left_bound or right_bound > winding_window.max_right_bound:
285269
# Set valid to False, so that geometry is to be neglected in geometry sweep
@@ -309,9 +293,9 @@ def draw_conductors(self, draw_top_down: bool = True):
309293
310294
"""
311295
if winding0.conductor_radius != winding1.conductor_radius:
312-
print("For bifilar winding scheme both conductors must be of the same radius!")
296+
logger.warning("For bifilar winding scheme both conductors must be of the same radius!")
313297
else:
314-
print("Bifilar winding scheme is applied")
298+
logger.info("Bifilar winding scheme is applied")
315299

316300
raise Exception("Bifilar winding scheme is not implemented yet.")
317301

@@ -1304,8 +1288,8 @@ def check_number_of_drawn_conductors(self):
13041288
drawn_number_of_turns += int(self.p_conductor[winding.winding_number].shape[0] / 5) # rectangular conductors
13051289

13061290
if drawn_number_of_turns != needed_number_of_turns:
1307-
self.femmt_print(f"{drawn_number_of_turns=}")
1308-
self.femmt_print(f"{needed_number_of_turns=}")
1291+
logger.info(f"{drawn_number_of_turns=}")
1292+
logger.info(f"{needed_number_of_turns=}")
13091293
raise Exception("Winding mismatch. Probably too many turns that do not fit in the winding window")
13101294

13111295
def draw_region_single(self):
@@ -1347,7 +1331,7 @@ def draw_insulations(self):
13471331
if self.component_type == ComponentType.IntegratedTransformer:
13481332
# TODO: insulations implement for integrated_transformers
13491333
# TODO Change back to warnings?
1350-
self.femmt_print("Insulations are not set because they are not implemented for integrated transformers.")
1334+
logger.info("Insulations are not set because they are not implemented for integrated transformers.")
13511335
else:
13521336
window_h = self.core.window_h
13531337
iso = self.insulation
@@ -1587,18 +1571,18 @@ def draw_model(self):
15871571
# self.draw_region_stacked()
15881572

15891573
@staticmethod
1590-
def get_center_of_rect(p1: List[float], p2: List[float], p3: List[float], p4: List[float]):
1574+
def get_center_of_rect(p1: list[float], p2: list[float], p3: list[float], p4: list[float]):
15911575
"""
15921576
Get center point of a rectangular conductor.
15931577
15941578
:param p1: Point 1 as a x,y-List
1595-
:type p1: List[float]
1579+
:type p1: list[float]
15961580
:param p2: Point 1 as a x,y-List
1597-
:type p2: List[float]
1581+
:type p2: list[float]
15981582
:param p3: Point 1 as a x,y-List
1599-
:type p3: List[float]
1583+
:type p3: list[float]
16001584
:param p4: Point 1 as a x,y-List
1601-
:type p4: List[float]
1585+
:type p4: list[float]
16021586
"""
16031587
x_list = [p1[0], p2[0], p3[0], p4[0]]
16041588
y_list = [p1[1], p2[1], p3[1], p4[1]]

femmt/dtos.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Data transfer objects (DTOs) used by this toolbox."""
22
from dataclasses import dataclass
33
from femmt.enumerations import WindingTag
4-
from typing import Optional, List
54

65

76
@dataclass
@@ -29,10 +28,10 @@ class ConductorRow:
2928
"""Defines the conductors in one row."""
3029

3130
number_of_conds_per_winding: int
32-
number_of_conds_per_row: Optional[int]
33-
row_height: Optional[float]
31+
number_of_conds_per_row: int | None
32+
row_height: float | None
3433
winding_tag: WindingTag
35-
number_of_rows: Optional[int]
34+
number_of_rows: int | None
3635
additional_bobbin: float
3736

3837

@@ -55,20 +54,20 @@ class ThreeWindingIsolation:
5554
class CenterTappedGroup:
5655
"""Definitions for the center tapped group. A group is made of several primary and secondary rows."""
5756

58-
primary_number_of_rows: Optional[int]
59-
secondary_number_of_rows: Optional[int]
60-
primary_rest: Optional[int]
61-
secondary_rest: Optional[int]
62-
stack: List[WindingTag]
57+
primary_number_of_rows: int | None
58+
secondary_number_of_rows: int | None
59+
primary_rest: int | None
60+
secondary_rest: int | None
61+
stack: list[WindingTag]
6362

6463

6564
@dataclass
6665
class ConductorStack:
6766
"""Definitions for the conductor stack."""
6867

6968
number_of_groups: int
70-
number_of_single_rows: Optional[int]
71-
order: List[int]
69+
number_of_single_rows: int | None
70+
order: list[int]
7271

7372

7473
@dataclass
@@ -106,16 +105,16 @@ class TransformerInductance:
106105
class ThreeWindingTransformerInductance:
107106
"""Inductance definitions for a three-winding transformer."""
108107

109-
M_12: Optional[float]
110-
M_13: Optional[float]
111-
M_23: Optional[float]
112-
L_s1: Optional[float]
113-
L_s2: Optional[float]
114-
L_s3: Optional[float]
115-
L_h: Optional[float]
116-
n_12: Optional[float]
117-
n_13: Optional[float]
118-
n_23: Optional[float]
119-
L_s12: Optional[float]
120-
L_s13: Optional[float]
121-
L_s23: Optional[float]
108+
M_12: float | None
109+
M_13: float | None
110+
M_23: float | None
111+
L_s1: float | None
112+
L_s2: float | None
113+
L_s3: float | None
114+
L_h: float | None
115+
n_12: float | None
116+
n_13: float | None
117+
n_23: float | None
118+
L_s12: float | None
119+
L_s13: float | None
120+
L_s23: float | None

femmt/examples/advanced_inductor_air_gap_sweep.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import matplotlib.pyplot as plt
33
import femmt as fmt
44
import os
5-
from typing import Optional
65

7-
def basic_example_sweep(onelab_folder: Optional[str] = None, show_visual_outputs: bool = True, is_test: bool = False):
6+
def basic_example_sweep(onelab_folder: str | None = None, show_visual_outputs: bool = True, is_test: bool = False):
87
"""
98
Advanced example to demonstrate an air gap sweep for an inductor.
109
@@ -39,7 +38,7 @@ def basic_example_sweep(onelab_folder: Optional[str] = None, show_visual_outputs
3938

4039
working_directories.append(directory)
4140

42-
geo = fmt.MagneticComponent(component_type=fmt.ComponentType.Inductor, working_directory=directory, verbosity=fmt.Verbosity.Silent, is_gui=is_test)
41+
geo = fmt.MagneticComponent(component_type=fmt.ComponentType.Inductor, working_directory=directory, is_gui=is_test)
4342

4443
# This line is for automated pytest running on GitHub only. Please ignore this line!
4544
if onelab_folder is not None:

femmt/examples/advanced_inductor_sweep.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def advanced_example_inductor_sweep(onelab_folder: str = None, show_visual_outpu
2727
os.mkdir(working_directory)
2828

2929
# 1. chose simulation type
30-
geo = fmt.MagneticComponent(component_type=fmt.ComponentType.Inductor, working_directory=working_directory,
31-
verbosity=fmt.Verbosity.Silent, is_gui=is_test)
30+
geo = fmt.MagneticComponent(component_type=fmt.ComponentType.Inductor, working_directory=working_directory, is_gui=is_test)
3231

3332
# This line is for automated pytest running on GitHub only. Please ignore this line!
3433
if onelab_folder is not None:

femmt/examples/basic_inductor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
"""
1111
import femmt as fmt
1212
import os
13+
import logging
1314

15+
# configure logging to show femmt terminal output
16+
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
1417

15-
def basic_example_inductor(onelab_folder: str = None, show_visual_outputs: bool = True, is_test: bool = False):
18+
def basic_example_inductor(onelab_folder: str = None, show_visual_outputs: bool = False, is_test: bool = False):
1619
"""
1720
Run the example code for the inductor.
1821
@@ -100,7 +103,7 @@ def example_thermal_simulation(show_thermal_visual_outputs: bool = True, flag_in
100103

101104
# 1. chose simulation type
102105
geo = fmt.MagneticComponent(simulation_type=fmt.SimulationType.FreqDomain, component_type=fmt.ComponentType.Inductor, working_directory=working_directory,
103-
verbosity=fmt.Verbosity.ToConsole, is_gui=is_test)
106+
is_gui=is_test)
104107

105108
# This line is for automated pytest running on GitHub only. Please ignore this line!
106109
if onelab_folder is not None:

femmt/examples/basic_inductor_excitation_sweep.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
"""
1313
import femmt as fmt
1414
import os
15+
import logging
1516

17+
# configure logging to show femmt terminal output
18+
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
1619

1720
example_results_folder = os.path.join(os.path.dirname(__file__), "example_results")
1821
if not os.path.exists(example_results_folder):
@@ -42,7 +45,7 @@ def basic_example_inductor_excitation_sweep(onelab_folder: str = None, show_visu
4245

4346
# 1. chose simulation type
4447
geo = fmt.MagneticComponent(component_type=fmt.ComponentType.Inductor, working_directory=working_directory,
45-
verbosity=fmt.Verbosity.Silent, is_gui=is_test)
48+
is_gui=is_test)
4649

4750
# This line is for automated pytest running on GitHub only. Please ignore this line!
4851
if onelab_folder is not None:

0 commit comments

Comments
 (0)