Skip to content

Commit a4c434c

Browse files
authored
FEAT: Custom electric period range plot (#426)
1 parent 44ebcb3 commit a4c434c

File tree

1 file changed

+77
-25
lines changed

1 file changed

+77
-25
lines changed

examples/low_frequency/motor/aedt_motor/pm_synchronous.py

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
from operator import attrgetter
1818

1919
import ansys.aedt.core
20+
import matplotlib.pyplot as plt
2021
from ansys.aedt.core.examples.downloads import download_leaf
22+
from ansys.aedt.core.generic.constants import unit_converter
23+
from ansys.aedt.core.generic.numbers import Quantity
24+
2125
# -
2226

2327
# Define constants.
@@ -147,9 +151,7 @@
147151
# Define the path for non-linear material properties.
148152
# Materials are stored in text files.
149153

150-
filename_lam, filename_PM = download_leaf(
151-
local_path=temp_folder.name
152-
)
154+
filename_lam, filename_PM = download_leaf(local_path=temp_folder.name)
153155

154156
# ## Create first material
155157
#
@@ -160,31 +162,28 @@
160162
mat_coils.conductivity = "49288048.9198"
161163
mat_coils.permeability = "1"
162164

163-
# ## Create second material
165+
# ## Create materials with a non-linear permeability
164166
#
165-
# Create the material ``"Arnold_Magnetics_N30UH_80C"``.
166-
# The BH curve is read from a tabbed CSV file. A list named ``BH_List_PM``
167-
# is created. This list is passed to the ``mat_PM.permeability.value``
168-
# variable.
167+
# Below there are two examples of how to create materials with a non-linear permeability.
168+
# The first example imports the BH curve as a 1d dataset in the project.
169+
# The second example reads the BH curve from a tabbed CSV file.
170+
171+
# Create second material ``"Arnold_Magnetics_N30UH_80C"``.
172+
# The BH curve is imported as a 1d dataset in the project.
173+
# It means that the BH curve is available in ``Project > Datasets`` in AEDT.
174+
# Once the dataset is imported, it can be assigned to the permeability value.
169175

170176
mat_PM = m2d.materials.add_material(name="Arnold_Magnetics_N30UH_80C_new")
171177
mat_PM.update()
172178
mat_PM.conductivity = "555555.5556"
173179
mat_PM.set_magnetic_coercivity(value=-800146.66287534, x=1, y=0, z=0)
174180
mat_PM.mass_density = "7500"
175-
BH_List_PM = []
176-
with open(filename_PM) as f:
177-
reader = csv.reader(f, delimiter="\t")
178-
next(reader)
179-
for row in reader:
180-
BH_List_PM.append([float(row[0]), float(row[1])])
181-
mat_PM.permeability.value = BH_List_PM
181+
BH_List_PM = m2d.import_dataset1d(filename_PM, name="Arnold_Magnetics_N30UH_80C")
182+
mat_PM.permeability.value = [[a, b] for a, b in zip(BH_List_PM.x, BH_List_PM.y)]
182183

183-
# ## Create third material
184-
#
185-
# Create the laminated material ``30DH_20C_smooth``.
186-
# This material has a BH curve and a core loss model,
187-
# which is set to electrical steel.
184+
# Create the third material laminated ``30DH_20C_smooth``.
185+
# The BH curve is read from a tabbed CSV file. A list named ``BH_List_lam``
186+
# is created. This list is passed to the ``mat_lam.permeability.value`` variable.
188187

189188
mat_lam = m2d.materials.add_material("30DH_20C_smooth")
190189
mat_lam.update()
@@ -300,7 +299,7 @@
300299
# In Maxwell 2D, you assign magnetization via the coordinate system.
301300
# The inputs are the object name, coordinate system name, and inner or outer magnetization.
302301

303-
# +
302+
304303
def create_cs_magnets(pm_id, cs_name, point_direction):
305304
edges = sorted(pm_id.edges, key=attrgetter("length"), reverse=True)
306305

@@ -320,8 +319,6 @@ def create_cs_magnets(pm_id, cs_name, point_direction):
320319
m2d.modeler.set_working_coordinate_system("Global")
321320

322321

323-
# -
324-
325322
# ## Create coordinate system for PMs in face center
326323
#
327324
# Create the coordinate system for PMs in the face center.
@@ -889,9 +886,11 @@ def create_cs_magnets(pm_id, cs_name, point_direction):
889886
# Plot the desired expression by using the Matplotlib ``plot()`` function.
890887

891888
solutions = m2d.post.get_solution_data(
892-
expressions="Moving1.Torque", primary_sweep_variable="Time", domain="Sweep"
889+
expressions="Moving1.Torque",
890+
setup_sweep_name=m2d.nominal_sweep,
891+
primary_sweep_variable="Time",
892+
domain="Sweep",
893893
)
894-
# solutions.plot()
895894

896895
# ## Retrieve the data magnitude of an expression
897896
#
@@ -908,6 +907,59 @@ def create_cs_magnets(pm_id, cs_name, point_direction):
908907
output_dir=temp_folder.name, plot_name="TorquePlots", extension=".csv"
909908
)
910909

910+
# ## Retrieve the data values of Torque within a time range
911+
#
912+
# Retrieve the data values of Torque within a specific time range of the electric period.
913+
# Since the example analyzes only one period, the time range is from ``ElectricPeriod/4`` to ``ElectricPeriod/2``.
914+
915+
time_interval = solutions.intrinsics["Time"]
916+
917+
# Convert the start and stop time of the electric period range to nanoseconds
918+
919+
start_time = Quantity(
920+
unit_converter(
921+
values=m2d.variable_manager.design_variables["ElectricPeriod"].numeric_value
922+
/ 4,
923+
unit_system="Time",
924+
input_units="s",
925+
output_units="ns",
926+
),
927+
"ns",
928+
)
929+
stop_time = Quantity(2 * start_time.value, "ns")
930+
931+
# Find the indices corresponding to the start and stop times
932+
933+
index_start_time = time_interval.index(start_time)
934+
index_stop_time = time_interval.index(stop_time)
935+
936+
# ## Extract the torque values within the specified time range
937+
938+
torque_values = solutions.data_real()
939+
time_electric_period = time_interval[index_start_time:index_stop_time]
940+
torque_electric_period = torque_values[index_start_time:index_stop_time]
941+
942+
# Plot the torque values within the specified time range with matplotlib
943+
#
944+
# Plot the graph
945+
946+
plt.plot(time_electric_period, torque_electric_period, marker="o")
947+
948+
# Labels
949+
950+
plt.xlabel("Time (ns)")
951+
plt.ylabel("Torque (Nm)")
952+
953+
# Title
954+
955+
plt.title("Torque vs Time for Half Electric Period")
956+
957+
# Uncomment the following line to display the matplotlib plot
958+
959+
# +
960+
# plt.show()
961+
# -
962+
911963
# ## Release AEDT
912964

913965
m2d.save_project()

0 commit comments

Comments
 (0)