TRNSYSをPythonから実行する

Pythonのsubprocessモジュールを使うと、簡単に外部プログラムを実行することができます。

そして、TRNBuild, Simulation Studio, TRNSYSもコマンドラインから起動できます。で、組み合わせるとスクリプトを使って、一連の処理をまとめて実行することができます。

次の例では、一連の処理をPythonから実行しています。

  1. TRNBuildでVFM, SHM/ISMを生成
  2. Simulation StudioでDckファイルの書き出し
  3. TRNSYSで計算を実行

普段はあまりなさそうな使い方ですが、何度も計算を繰り返すようなケース(パラメトリックスタディなど)で役に立ちそうです。

例)RunTRNSYS.py

# coding: utf-8
"""
This example shows how to run TRNBuild, Simulation Studio and TRNSYS.
coded by Yuichi Yasuda @ quattro corporate design
"""

import subprocess
#from subprocess import Popen

if(__name__ == '__main__'):
    # TRNBuild
    #--------------------------------------------------------------------------------------------------------------------------------
    # Creating VFM from command line
    subprocess.call(r'"C:\TRNSYS18\Building\TRNBuild.exe" "C:\TRNSYS18\ExamplesD_Building_Step_Add_Daylight\building_ModGeo.b18" /N /vfm')
    
    # Creating SHM/ISM from command line
    subprocess.call(r'"C:\TRNSYS18\Building\TRNBuild.exe" "C:\TRNSYS18\ExamplesD_Building_Step_Add_Daylight\building_ModGeo.b18" /N /masks')

    # Simulation Studio
    #--------------------------------------------------------------------------------------------------------------------------------      
    # Creating DCK file from command line. 
    # command line options
    #   /d create deck file
    #   /r run simulation
    #   /q quit
    subprocess.call(r'"C:\TRNSYS18\Studio\Exe\Studio.exe" /d /q "C:\TRNSYS18\ExamplesD_Building_Step_Add_Daylight\Building.tpf"')

    # TRNSYS
    #--------------------------------------------------------------------------------------------------------------------------------
    # Running TRNSYS in interactive mode
    #subprocess.call(r'"C:\TRNSYS18\Exe\TrnEXE64.exe" "Building.dck"', cwd=r'C:\TRNSYS18\ExamplesD_Building_Step_Add_Daylight')

    # Running TRNSYS in batch mode
    # subprocess.call(r'"C:\TRNSYS18\Exe\TrnEXE64.exe" "Building.dck" /n', cwd=r'C:\TRNSYS18\ExamplesD_Building_Step_Add_Daylight')

    # Running TRNSYS in Hidden mode
    subprocess.call(r'"C:\TRNSYS18\Exe\TrnEXE64.exe" "Building.dck" /h', cwd=r'C:\TRNSYS18\ExamplesD_Building_Step_Add_Daylight')
  


    

動作環境

以下の環境で動作を確認しています。
Windows10 Pro(64bit)
Python:Anaconda 5.1(Python 3.6/64bit)
TRNSYS18.00.0017(64bit)

Pocket

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です