Skip to content

Commit

Permalink
Account for whether or not the file is saved in working_folder
Browse files Browse the repository at this point in the history
and get the number of torque points per cycle from the JSON file.
  • Loading branch information
JackB-Ansys committed Dec 24, 2024
1 parent 12d550a commit ffb74e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/links/ece_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"machine_temp" : 75,
"Id_max" : 250,
"current_step" : 50,
"torque_points_per_cycle" : 30,
"map_name" : "ECE_e8_map.mat",
"txt_file" : "ECE_e8_txt_file.txt",
"sml_file" : "ECE_e8_sml_file.sml"
Expand Down
29 changes: 20 additions & 9 deletions examples/links/ece_export_for_twinbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ def read_parameters(json_file):
# The necessary data is extracted from the ``in_data`` dictionary. The JSON configuration file
# contains:
#
# * The filename to be used for the Motor-CAD MOT file.
# * The Motor-CAD MOT filename to be used for the ECE export. If the file does not exist in the
# ``working_folder`` location, this script opens the e8 Motor-CAD template by default.
#
# * Operating parameters for the electric machine (shaft speed, DC bus voltage, temperature, maximum
# current, current resolution).
# current, current resolution and number of points per cycle for the torque calculation). If using
# an input file, the file in the ``working_folder`` will be modified by setting the operating
# parameter input settings.
#
# * The filenames to be used for the results files that are exported (map, text file and SML file).
# Exported files are saved to the working directory, in a subfolder named ``Results``.
Expand All @@ -130,6 +133,7 @@ def read_parameters(json_file):
machine_temp = float(in_data["machine_temp"])
Id_max = float(in_data["Id_max"])
current_step = float(in_data["current_step"])
points_per_cycle = float(in_data["torque_points_per_cycle"])

results_folder = os.path.join(working_folder, "Results")
try:
Expand All @@ -142,11 +146,20 @@ def read_parameters(json_file):
sml_file = os.path.join(results_folder, in_data["sml_file"])

# %%
# Load the e8 IPM motor template and save the file to the working directory. Use the ``mot_file``
# filename that was taken from the JSON configuration file.
# Load the Motor-CAD file. If the ``mot_file`` specified in the JSON configuration file exists, open
# the MOT file. The file in the ``working_folder`` will be modified by setting the operating
# parameter input settings. Ensure this file is backed up if necessary.
#
# If the file does not exist, load the e8 IPM motor template and save the file to the
# working directory. Use the ``mot_file`` filename that was taken from the JSON configuration file.
# Save input settings to a Motor-CAD MOT file.
mc.load_template("e8")
mc.save_to_file(mot_file)
if os.path.isfile(mot_file):
mc.load_from_file(mot_file)
print("Opening " + mot_file)
else:
mc.load_template("e8")
mc.save_to_file(mot_file)
print("Opening Motor-CAD e8 template and saving to file " + mot_file)

# %%
# Determine alignment angle
Expand All @@ -157,9 +170,7 @@ def read_parameters(json_file):
# the drive offset angle can be determined. Define the calculation settings as taken from the JSON
# configuration file.
#
# * Define the number of points per cycle for the torque calculation as 30 and set this in
# Motor-CAD.
points_per_cycle = 30
# * Set the number of points per cycle for the torque calculation in Motor-CAD.
mc.set_variable("TorquePointsPerCycle", points_per_cycle)

# %%
Expand Down

0 comments on commit ffb74e4

Please sign in to comment.