[S0009] Add result calculation of parts, faces, or edges for mesh groups

 

The result calculation function can calculate the total, maximum values or etc. ​​of distributed result quantities for specified parts, faces, and edges. A summary of distributed result quantities for a certain spatial range can be evaluated, but specifying a mesh group allows for greater flexibility in the range. This script creates result calculation definitions for each mesh group (a collection of elements, element faces, and element edges).

Preconditions

  • One or more analysis studies have been created to calculate the distributed results in a 3D model.
    This script is run for the active study in the project tree.
  • Mesh groups for elements, element faces, and element edges have been created and their titles are known.

Script Function

  • Add parts calculation definition for the element mesh group “Element_Stator.”
  • Set parameters to calculate the maximum x-component of magnetic flux density.
  • Add face calculation definition for the element face mesh groups “Face_Stator2” and “Face_Stator3.”
  • Set parameters to calculate the magnetic field surface integral.
  • Set the reverse of the normal direction for each selected face.
  • Add edge calculation definition for the element edge mesh groups “Edge_Magnet1” and “Edge_Magnet2.”
  • Set parameters to calculate the magnetization line integral.
  • Set the reverse of the reference direction for each selected edge.
# 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 getMeshGroupListInStudy(study, groupNameList):
    """Retrieve the mesh group with the specified name as an argument."""
    meshGroupList = []
    for groupName in groupNameList:
        meshGroupList.append(study.GetMeshGroupList().GetMeshGroup(groupName))
    return meshGroupList

def createPartsCalculationWithMeshGroup(study, resultType, meshGroupList):
    """Added setting to calculate the maximum value of the result type (physical quantity) in the mesh group of parts"""
    calculationType = u"max"
    component = u"X"
    title = "_".join([resultType, calculationType, component])

    calculationDefinition = study.CreateCalculationDefinition(title)
    calculationDefinition.SetResultType(resultType)
    # 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
    calculationDefinition.SetResultCoordinate(0)
    #calculationDefinition.SetResultCoordinate(u"Global Rectangular")
    calculationDefinition.SetComponent(component)
    calculationDefinition.SetCalculationType(calculationType)
    calculationDefinition.ClearParts()
    # Add the mesh group passed as an argument to the calculation target.
    for meshGroup in meshGroupList:
        calculationDefinition.AddGroup(meshGroup, 0)

def createSurfaceCalculationWithMeshGroup(study, resultType, meshGroupList):
    """Added setting to calculate the area integral of the result type (physical quantity) in the mesh group of the surface."""
    calculationType = u"surface_integral"
    title = "_".join([resultType, calculationType])

    surfaceCalculationDefinition = study.CreateSurfaceCalculationDefinition(title)
    surfaceCalculationDefinition.SetResultType(resultType)
    # 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
    surfaceCalculationDefinition.SetResultCoordinate(0)
    #surfaceCalculationDefinition.SetResultCoordinate(u"Global Rectangular")
    surfaceCalculationDefinition.SetCalculationType(calculationType)
    surfaceCalculationDefinition.SetDirectionReverse(True)
    surfaceCalculationDefinition.ClearParts()
    # Add the mesh group passed as an argument to the calculation target.
    for meshGroup in meshGroupList:
        surfaceCalculationDefinition.AddGroup(meshGroup, 1)

def createEdgeCalculationWithMeshGroup(study, resultType, meshGroupList):
    """Added setting to calculate line integrals of result types (physical quantities) in edge mesh groups"""
    calculationType = u"line_integral"
    title = "_".join([resultType, calculationType])

    edgeCalculationDefinition = study.CreateEdgeCalculationDefinition(title)
    edgeCalculationDefinition.SetResultType(resultType)
    # 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
    edgeCalculationDefinition.SetResultCoordinate(0)
    #edgeCalculationDefinition.SetResultCoordinate(u"Global Rectangular")
    edgeCalculationDefinition.SetCalculationType(calculationType)
    edgeCalculationDefinition.SetDirectionReverse(True)
    edgeCalculationDefinition.ClearParts()
    # Add the mesh group passed as an argument to the calculation target.
    for meshGroup in meshGroupList:
        edgeCalculationDefinition.AddGroup(meshGroup, 2)

app = designer.GetApplication()
study = app.GetCurrentStudy()

resultType = u"MagneticFluxDensity"
groupNameList = [u"Element_Stator"]
meshGroupList = getMeshGroupListInStudy(study, groupNameList)
createPartsCalculationWithMeshGroup(study, resultType, meshGroupList)

resultType = u"MagneticFieldStrength"
groupNameList = [u"Face_Stator2", u"Face_Stator3"]
meshGroupList = getMeshGroupListInStudy(study, groupNameList)
createSurfaceCalculationWithMeshGroup(study, resultType, meshGroupList)

resultType = u"Magnetization"
groupNameList = [u"Edge_Magnet1", u"Edge_Magnet2"]
meshGroupList = getMeshGroupListInStudy(study, groupNameList)
createEdgeCalculationWithMeshGroup(study, resultType, meshGroupList)

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