The optimization function searches for a design solution that optimizes the objective function using an algorithm in the specified ranges defined by min and max limits for each design variables such as CAD parameters or condition parameters.
For CAD parameter optimization, a "range finder" function is available to explore the design space while ensuring the geometry remains valid, thereby modifying ranges of the CAD parameters.
This script sets initial values of parametric variable ranges and configures it to modify the range using the range finder.
Preconditions
- One or more studies have been created.
This script runs on the active study in the project tree. - Optimization design variables must have been selected and at least one CAD parameter must be included.
- The name of the parameters to configure the range is known.
Script Function
- Configure the following optimization options of the study:
Optimization engine: Multi-Objective Genetic Algorithm
Update CAD parameter ranges to avoid broken geometry and set geometry for initial generation: ON
Set parameters automatically: ON
Expand search range for variables that have reached their minimum or maximum variable range: ON - Set the min and max values for the specified parameter variable range.
- Set the auto range modification On or Off to min and max for the specified parameter variable range.
# 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/
app = designer.GetApplication()
def paramItemModifyMinMaxValRange(optTbl, paramDataArray):
"""Setting parameter variable ranges in optimization, and selecting dimension variables whose ranges to modify."""
optTbl.SetParameter(u"engine", u"jsol_moga")
optTbl.SetParameter(u"jsol_moga_use_range_optimization", True)
optTbl.SetParameter(u"jsol_moga_use_automatic_parameters_in_range_optimization", True)
optTbl.SetParameter(u"jsol_moga_expand_range_search", True)
for paramName, minVal, maxVal, minFlag, maxFlag in paramDataArray:
optTbl.SetCheckOn(paramName, True)
paramItem = optTbl.GetParametricItem(paramName)
paramItem.SetMin(minVal)
paramItem.SetMax(maxVal)
# Select the dimension variable to modify the range.
if minFlag: paramItem.SetModifyMinValueRange(minFlag)
if maxFlag: paramItem.SetModifyMaxValueRange(maxFlag)
study = app.GetCurrentStudy()
optTbl = study.GetOptimizationTable()
paramDataArray = [
# Parameter name, parameter minimum value, parameter maximum value, whether to search the dimension range for the minimum value, whether to search the dimension range for the maximum value.
[u"CS1 (3PhaseCurrentSource): PhaseU", 0, 70, None, None],
[u"CAD parameters: FBCenterWidth0@Variables", 0.5, 6, True, False],
[u"CAD parameters: Flux_In2_deg@Variables", 40, 120, False, True],
[u"CAD parameters: Flux_Out1_deg@Variables", 55, 115, False, False],
[u"CAD parameters: Flux_Out2_deg@Variables", 45, 125, True, True],
]
paramItemModifyMinMaxValRange(optTbl, paramDataArray)


