# Copyright (c) 2026 JSOL CORPORATION
#
# 本スクリプトはMITライセンスのもとで公開しています。
# ライセンス全文は以下を参照してください。
# https://www.jmag-international.com/jp/scriptlibrary/jmag_script_library_mit/

app = designer.GetApplication()

def createEfficiencyMap(study, effMapName, pointArray):
    """走行モード:車速の効率マップ定義オブジェクトの作成"""
    effMap = study.CreateEfficiencyMapDefinition(effMapName)
    effMap.SetMaxVoltage(600)
    effMap.SetMaxCurrent(250)
    effMap.SetVoltageLimitType(u"fundamental")
    effMap.SetTorqueType(u"electromagnetic")
    effMap.SetMotorMode(u"generation")
    effMap.SetClusterPoints(6)
    effMap.SetDriveCycleUseVehicleParameters(True)
    effMap.SetDriveCycleTireDiameter(700)
    effMap.SetDriveCycleGearRatio(5)
    effMap.SetDriveCycleAirDensity(1.3)
    effMap.SetDriveCycleDragCoefficient(0.5)
    effMap.SetDriveCycleCrossSectionalArea(3.2)
    effMap.SetDriveCycleRollingResistance(0.001)
    effMap.SetDriveCycleTotalWeight(1800)
    effMap.SetDriveCycleGravity(9.9)
    effMap.SetDriveCycleUseVehicleSpeedTable(True)
    effMap.SetDriveCycleVehicleSpeedTable(pointArray)
    effMap.SetMechancialLossFactor(20)
    effMap.SetYAxisDivisions(40)

def getDriveCycleVehicleSpeedTableArray():
    """車速の点列データ(2次元配列)取得"""
    pointArray = [[0 for i in range(2)] for j in range(5)]
    pointArray[0][0] = 0
    pointArray[0][1] = 0
    pointArray[1][0] = 10
    pointArray[1][1] = 20
    pointArray[2][0] = 20
    pointArray[2][1] = 50
    pointArray[3][0] = 30
    pointArray[3][1] = 30
    pointArray[4][0] = 40
    pointArray[4][1] = 20
    return pointArray

study = app.GetCurrentStudy()
effMapName = u"EM3-1"
pointArray = getDriveCycleVehicleSpeedTableArray()
createEfficiencyMap(study, effMapName, pointArray)
