How to run fds on python?

287 views
Skip to first unread message

Андрей Х.

unread,
Oct 21, 2021, 11:09:41 AM10/21/21
to FDS and Smokeview Discussions
Hello!

Please tell me how to edit this code to run fds on python?

import os
from subprocess import Popen, PIPE
base = (os.getcwd())
string = f"{base}/1"
os.chdir(string)
cmd = 'cmd.exe'
p = Popen(cmd, stdin=PIPE, stdout=PIPE, bufsize=0, shell=True)
p.stdin.write(rb"fdsinit\ D:\Python\Project\Repositories\Project_Clicker\Run_FDS\1")
p.stdin.write(b"fds_local -p 2 -o 1 b_1.fds")
cc = p.stdin.close()
vv = p.wait()

File.fds is located in the folder D:\Python\Project\Repositories\Project_Clicker\Run_FDS\1

Андрей Х.

unread,
Oct 22, 2021, 8:53:54 AM10/22/21
to FDS and Smokeview Discussions
Or maybe someone will offer their sample code to run fds in python?

четверг, 21 октября 2021 г. в 18:09:41 UTC+3, Андрей Х.:

王俊翔

unread,
Oct 22, 2021, 9:46:56 AM10/22/21
to fds...@googlegroups.com
Hey, buddy

Maybe you could try this for FDS 6.7, it is modified from Propti written by Lukas Arnold's group.

import os
import logging, subprocess

def generate_fds_cmd(execution_dir, model_file_name):
    root = os.path.abspath(execution_dir)[:2]
    cmd1 = 'set PATH=C:/Program Files/firemodels/FDS6/bin/mpi;%PATH% && '
    cmd2 = 'set IN_CMDFDS=1 && '
    cmd3 = '{} && cd {} && '.format(root, execution_dir)
    cmd4 = 'fds_local -p {} -o {} {}'.format(2, 1, model_file_name) # openmp and mpi
    return cmd1 + cmd2 + cmd3 + cmd4

fds_file_path = "F:/20210516-PSO-PP composite-V15/1.020_best/input.fds"
execution_dir = os.path.split(fds_file_path)[0]
fds_file_name = os.path.split(fds_file_path)[-1]
cmd = generate_fds_cmd(execution_dir, fds_file_name)
log_file = open(os.path.join(execution_dir, "execution.log"), "w")
logging.debug("executing command: {}".format(cmd))
subprocess.check_call(cmd, shell=True, stdout=log_file, stderr=log_file)
log_file.close()

Андрей Х. <i.do...@yandex.ru> 于2021年10月22日周五 下午8:53写道:
--
You received this message because you are subscribed to the Google Groups "FDS and Smokeview Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fds-smv+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fds-smv/6de723b0-43d9-4ad5-b7c2-5bc13b0bdab1n%40googlegroups.com.

Андрей Х.

unread,
Oct 22, 2021, 3:59:54 PM10/22/21
to FDS and Smokeview Discussions
Thanks, this code runs.fds and generates the execution.log file.
I couldn't figure out how to intercept and read the records that fall into the execution.log file without waiting for the end of the calculation

пятница, 22 октября 2021 г. в 16:46:56 UTC+3, Undi:

王俊翔

unread,
Oct 22, 2021, 9:17:19 PM10/22/21
to fds...@googlegroups.com
Then I don't know, this script is used for a relatively small model, the records seem to be useless most of the time.

If the model is huge, using Python might not be a good idea.


Андрей Х. <i.do...@yandex.ru> 于2021年10月23日周六 上午3:59写道:
Reply all
Reply to author
Forward
0 new messages