As a means of comparing and evaluating the results of multiple cases, there are response values that are defined using a calculation method appropriate to the purpose.
There are also use cases where response values are defined before analysis and used as the objective function in optimization.
This script creates a response value that calculates the simple average of joule loss.
Preconditions
- One or more studies must have been created.
This script runs for the active magnetic field analysis study in the project tree.
Script Function
- Create a response value to calculate the simple average of joule loss.
Set the reference data to joule loss, the calculation method to simple average, the lines to Total, and the variable name to JLAve.
Specify the reference data by its display name in the table results.
Set the range unit to seconds, and the calculation range by specifying the interval before last step for all cases. Set the interval from the last step to 0.05 seconds.
# Copyright (c) 2026 JSOL CORPORATION
#
# This script is released under the MIT License.
# See the full license text at:
# https://www.jmag-international.com/scriptlibrary/jmag_script_library_mit/
def createResponseDataParameterByInterval(study, referenceData, calculationType, variableName, rangeType, numLastPeriods = 0.0):
"""Generate the response value using the specified calculation method"""
parameter = app.CreateResponseDataParameter(referenceData)
parameter.SetCalculationType(calculationType)
parameter.SetUnit(u"s")
parameter.SetAllLine(False)
parameter.SetLine(u"Total")
parameter.SetVariable(variableName)
# The 1st argumet of SetCaseRangeType
# 0:Uses all steps in all cases
# 1:Uses same value for all cases
# 2:Specifies values for each case
# 3:interval specified from the final step for all cases
parameter.SetCaseRangeType(rangeType)
if rangeType == 3:
parameter.SetRangeFromLastStep(numLastPeriods)
study.CreateParametricDataFromTable(referenceData, parameter)
app = designer.GetApplication()
study = app.GetCurrentStudy()
referenceData = u"Joule Loss"
calculationType = u"SimpleAverage"
variableName = u"JLAve"
rangeType = 3
createResponseDataParameterByInterval(study, referenceData, calculationType, variableName, rangeType, 0.05)


