[S8493] Script to calculate the induced voltage constant Ke from the analysis results and register it in the response value

 

The following is an example of a script that calculates the induced voltage constant Ke from the analysis results and registers it in the response value.

※Voltage difference results are required.

import math

app = designer.GetApplication()

# Get the study being displayed

objStudy = app.GetCurrentStudy()

# Get the results table for “Voltage difference”

result_voltage_difference = objStudy.GetResultTable().GetData("VoltageDifference")

# Initialization of the sum of maximum voltage differences

total_voltage = 0

# Loop through all rows, calculate the absolute value of the maximum voltage for each row, and add them up.

for i in range(result_voltage_difference.GetRows()):

   # Initialize the maximum voltage for each rows

   max_voltage = 0    

   # Loop through each row and find the maximum value.

   for j in range(result_voltage_difference.GetCols()):

       # Get the absolute value of the columns

       temp_val = abs(result_voltage_difference.GetValue(i, j))        

       # Compare with the current maximum value and update if larger

       if max_voltage < temp_val:

           max_voltage = temp_val            

   # Add the maximum voltage of each line to the total

   total_voltage += max_voltage

# Calculate the average voltage

average_voltage = total_voltage / result_voltage_difference.GetRows()

# Convert the speed (rpm) set in the "Motion: Rotation" conditions to angular velocity (rad/s) and calculate the Ke value.

value_ke = average_voltage / (objStudy.GetCondition("Rotor").GetValue("AngularVelocity") / 60 * 2 * math.pi) 

# Set the calculated Ke value to the user response variable.

objStudy.SetUserResponseVariable("Ke", objStudy.GetCurrentCase(), value_ke)

How to use script file

Use the JMAG Script Library after reading and agreeing to the following terms of use.