# Copyright (c) 2026 JSOL CORPORATION
#
# 本スクリプトはMITライセンスのもとで公開しています。
# ライセンス全文は以下を参照してください。
# https://www.jmag-international.com/jp/scriptlibrary/jmag_script_library_mit/

app = designer.GetApplication()

def createOrGetThermalModelDefinition(study):
    """熱モデル設定を作成し、既に存在する場合は既存の設定を取得する。"""
    app.ClearError()
    thermalModelDefinition = study.CreateThermalModelDefinition(u"motor")

    if app.HasError():
        app.ClearError()
        thermalModelDefinition = study.GetThermalModelDefinition()

    return thermalModelDefinition

def setThermalModelDefinition(thermalModelDefinition):
    """熱モデル設定に冷却条件、ハウジング及び周辺部品のパラメータを設定する。"""
    # 英語の引数はVer.25.1.02以降で動作。Ver.25.1.01のみ日本語で指定が必要
    thermalModelDefinition.SetCoolantPathType(u"Cooling Jacket + Hollow Shaft Spray")
    #thermalModelDefinition.SetCoolantPathType(u"クーリングジャケット + 中空シャフトスプレー")

    parameterSettings = [
        (u"ExternalTemperature", 70),
        (u"Speed", 1000),
        (u"Inlet-1CoolantVolumeFlowRate", 8e-5),
        (u"Inlet-1SprayCoolantTemperature", 70),
        (u"Inlet-1CoolantType", u"Oil"),
        (u"FromHollowShaftToOutlet", 0.4),
        (u"FromHollowShaftToFrontShaftSpray", 0.3),
        (u"FromHollowShaftToRearShaftSpray", 0.3),
        (u"HousingHeight", 300.0),
        (u"HousingThickness", 10),
        (u"MotorMountingType", u"FrontFlange"),
        (u"FlangeDiameter", 43.7),
        (u"FlangePlateHeight", 265.0),
        (u"FlangePlateWidth", 265.0),
        (u"FlangePlateTemperature", 70),
        (u"TubeWidth", 10),
        (u"TubeHeight", 7),
        (u"TubeNumber", 3),
        (u"ShaftInnerDiameter", 14.6),
        (u"CoilEndThermalConductivity", 400),
        (u"ShaftDiameterFront", 29.1),
        (u"BearingDiameterFront", 37.8),
        (u"BearingWidthFront", 10.0),
        (u"ShaftDiameterRear", 29.1),
        (u"BearingDiameterRear", 37.8),
        (u"BearingWidthRear", 10.0),
        (u"ConvectionType", u"Natural"),
    ]

    for propertyName, value in parameterSettings:
        thermalModelDefinition.SetValue(propertyName, value)

def main():
    """現在のスタディに熱モデル設定を作成し、各パラメータを設定する。"""
    study = app.GetCurrentStudy()
    thermalModelDefinition = createOrGetThermalModelDefinition(study)
    setThermalModelDefinition(thermalModelDefinition)

main()
