[S0027] ユーザー定義の応答値を登録する

 

多ケースの結果を比較評価する手段として、目的に適した計算方法で定義する応答値があります。
JMAGでは多様な計算結果と応答値算出手法がありますが、スクリプトを利用してユーザー定義の応答値を登録し、最適化等で利用することも可能です。
最適化でこの応答値を参照させたい場合は、ポスト計算スクリプトに登録します。
このスクリプトではトルクが最大となる回転角度をユーザー定義応答値として登録します。

前提条件

  • スタディが1つ以上作成されていること
    このスクリプト例では、プロジェクトツリー上でアクティブな磁界過渡応答スタディに対して実行している
  • ユーザー定義の応答値はスタディの種類を問わず使用であるが、この例はトルクが最大となる回転角度を取得するため、回転運動を伴う磁界過渡応答解析が対象となる

スクリプトにおける設定内容

  • トルクのテーブル結果のオブジェクトを取得する
  • トルク:節点力条件のタイプ名"Torque"を指定して、付与されているトルク:節点力条件の1番目のタイトルを取得し、テーブル結果の参照する列番号を取得する
  • 各行のトルク値を比較し、最大となる行番号を取得する
  • 取得した行番号での回転角度を取得し、ユーザー定義応答値として登録する。
    ユーザー定義応答値は、応答値名がある場合は、指定されたケースの値として登録され、ない場合は応答値を作成の上登録される
# Copyright (c) 2026 JSOL CORPORATION
#
# 本スクリプトはMITライセンスのもとで公開しています。
# ライセンス全文は以下を参照してください。
# https://www.jmag-international.com/jp/scriptlibrary/jmag_script_library_mit/


def getConditionsSpecifiedType(targetStudy, typeName):
    """スタディに付与されている指定されたタイプの条件を取得する"""
    matches = []
    numConds = targetStudy.NumConditions()

    for i in range(numConds):
        condition = targetStudy.GetCondition(i)
        CondType = condition.GetScriptTypeName()
        if CondType == typeName:
            matches.append(condition)
    return matches

def findTargetColumnByConditionName(targetStudy, targetResultTableData, referenceCondTypeName):
    """解析条件のタイトルによって列名が決まるテーブル形式結果にて、目的の列番号を取得する"""
    ret = -1
    conditions = getConditionsSpecifiedType(targetStudy, referenceCondTypeName)
    if len(conditions) <= 0:
        print(u"Reference condition is not found.")
    else:
        # 最初に見つかった条件のタイトルで列を探す
        nameToFind = conditions[0].GetName()
        for col in range(0, targetResultTableData.GetCols()):
            if targetResultTableData.GetColName(col) == nameToFind:
                ret = col
                break
    return ret

def setOriginalResponseValue(varName, targetStudy, targetCaseNo):
    """トルクが最大となるステップの回転角度をユーザー定義の応答値として登録する"""
    torqueData = targetStudy.GetResultTable().GetData(u"Torque")
    if not torqueData.IsValid():
        print(u"Torque result doesn't exist.")
        return
    # トルク:節点力条件のタイトルを探し、参照する列番号を取得する
    targetColNo = findTargetColumnByConditionName(targetStudy, torqueData, u"Torque")
    if targetColNo <= -1:
        print(u"Column is not found.")
        return
    maxTorque = torqueData.GetValue(0, targetColNo)
    maxRow = 0
    # トルクが最大になっている行番号を探す
    for row in range(1, torqueData.GetRows()):
        if maxTorque < torqueData.GetValue(row, targetColNo):
            maxTorque = torqueData.GetValue(row, targetColNo)
            maxRow = row
    # 得られた行番号の回転角度を取得する
    angleAtMaxTorque = torqueData.GetAngle(maxRow)
    print(varName, angleAtMaxTorque)

    targetStudy.SetUserResponseVariable(varName, targetCaseNo, angleAtMaxTorque)

app = designer.GetApplication()
responseVarName = u"Angle_atMaxTorque"
study = app.GetCurrentStudy()
caseNo = study.GetCurrentCase()
setOriginalResponseValue(responseVarName, study, caseNo)

Download Python source code

ファイルご利用の注意点

JMAGスクリプトライブラリをご利用されるに際し、以下をよくお読みいただき、ご同意の上ご利用くださるようお願い申し上げます。

絞込み検索

  • カテゴリー 一覧

JMAG-Express Online
An engineer's diary