# 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)