[S0068] Create a multiple face reference target and set it as the reference for the surface normal direction of a superconducting material

A multiple-face reference target can be used to specify multiple faces together as reference entities. By using the surface normal direction as the material direction, material properties whose direction varies along a curved surface can be defined. When multiple faces are specified, a local direction can be set for each element based on the referenced face.
This script obtains the face with the largest area from each part in the model, creates a multiple-face reference target and sets the reference target as the reference for the surface normal direction of a superconductor material.

Preconditions

  • One or more magnetic field transient response analysis studies have been created for a 3D model.
  • The study has a part that is assigned superconductor material and its name or ID is known.
    This script runs on the active model and study in the project tree.
    A superconductor material can be used in magnetic field transient response analysis study.
  • The multiple-face reference target and surface normal direction reference of a superconductor material are available in JMAG-Designer v25.1 and later.

Script Function

  • Obtain the face with the largest area from each part in the model.
  • Create a multiple-face reference target from the obtained faces.
  • Set the direction of the material assigned to the target part "ID1543" to the surface normal direction and set the created reference target.
# 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()
model = app.GetCurrentModel()
study = app.GetCurrentStudy()

# Reference target name
ReferenceTargetName = u"Ref1"
# Target part name or ID
TargetPartNameOrId = u"ID1543"


def getLargestFaceIds(model):
    """Obtain the face ID with the largest area from each part in the model"""
    faceIds = []
    for partIndex in range(model.NumParts()):
        part = model.GetPartByIndex(partIndex)
        largestFaceId = None
        largestFaceArea = -1.0
        for faceId in part.GetFaceIDs():
            faceArea = model.GetFaceArea(faceId)
            if faceArea > largestFaceArea:
                largestFaceArea = faceArea
                largestFaceId = faceId
        faceIds.append(largestFaceId)
    return faceIds


def createMultipleFaceReferenceTarget(model, referenceTargetName, faceIds):
    """Create a reference target that references the specified multiple faces"""
    referenceTargetList = model.GetReferenceTargetList()
    referenceTarget = referenceTargetList.CreateFaceReferenceTarget(
        referenceTargetName
    )
    # [Type]: [Multiple Faces]
    referenceTarget.SetType(u"MultipleFaces")
    selection = referenceTarget.GetSelection()
    for faceId in faceIds:
        selection.SelectFace(faceId)
    referenceTarget.AddSelected(selection)
    return referenceTarget


def setSurfaceNormalDirection(material, referenceTarget):
    """Set the material direction to the surface normal direction and specify a reference target"""
    material.SetPatternReferenceTarget(referenceTarget)
    # [Direction]: [Surface Normal Direction]
    material.SetPattern(u"SurfaceNormalDirection")
    material.SetNormalDirectionFromReferenceTarget(
        u"SurfaceNormalDirection",
        referenceTarget
    )


def main():
    faceIds = getLargestFaceIds(model)
    referenceTarget = createMultipleFaceReferenceTarget(
        model,
        ReferenceTargetName,
        faceIds
    )
    material = study.GetMaterial(TargetPartNameOrId)
    setSurfaceNormalDirection(material, referenceTarget)


main()

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