[S0057] Define a user component and create the result item using it

User component function provides defining original output result items by applying arbitrary expressions to the distribution analysis results.
User components only support scalar operations.
The created user component result can be displayed as contour plots, probes, etc.
This script creates an expression for the user component and defines a probe using the created user component.

Preconditions

  • One or more studies have been created.
    This script runs on the active magnetic field frequency analysis study in the project tree.

Script Function

  • Create a user component.
    The analysis type is magnetic analysis
    Set "abs(Fn0x)" to the expression that is using a x-component of the nodal force(zero-order)
    The component name is "UCMagFn0xAbs"
  • Create a probe with the result type as user component.
    Set the created user component "UCMagFn0xAbs" to the result type
# 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 createUserComponent(param):
    """Create a user component."""
    usrCompoList = app.GetUserComponentList()
    usrCompo = usrCompoList.CreateUserComponent(param[u"title"])
    # Analysis type
    # 0 : Magnetic field analysis
    # 1 : Thermal analysis
    # 2 : Structural analysis
    # 3 : Electric field analysis
    # 4 : Iron loss analysis
    usrCompo.SetAnalysisType(param[u"anType"])
    usrCompo.SetDescription(param[u"desc"])
    usrCompo.SetExpression(param[u"expr"])

def createProbeByUserComponent(study, userCompoTitle):
    """Create a probe using the created user component as the result type."""
    probeDef = study.CreateProbe(u"probeUserCompo")
    probeDef.SetResultType(u"User")
    probeDef.SetUserComponentType(userCompoTitle)
    # The 1st argumet of SetResultCoordinate
    # Name or index
    # The name of the preset coordinate system is fixed according to the language setting.
    # The index is specified in a 0-based from the coordinate system definition list order under Project - Model - Coordinate Systems
    probeDef.SetResultCoordinate(0)
    probeDef.SetLocationCoordinate(0)
    probeDef.SetProbeType(u"Coordinate")
    probeDef.SetLocation(0, u"0", u"0", u"1")
    probeDef.RenamePoint(0, u"PointAlpha")
    probeDef.SetUseElementValue(False)
    probeDef.SetMoveWithPart(True)

userCompoTitle = u"UCMagFn0xAbs"
param = {
    u"title" : userCompoTitle,
    u"anType" : 0,
    u"desc" : u"Absolute value of the zero-order nodal force x component",
    u"expr" : u"abs(Fn0x)",
}
createUserComponent(param)
study = app.GetCurrentStudy()
createProbeByUserComponent(study, userCompoTitle)

Download Python source code

How to use script file

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

Search Filter
  • All Categories

An engineer's diary
JMAG-Express Online