我正在研究飛機幾何形狀的優化器,在優化程序中,需要在AVL(開源,Fortran)中運行模擬,它將幾何形狀作為輸入并輸出有用的資料。目前,程式的 AVL 部分是這樣作業的:
def resultados_avl(aircraft, command):
process = subprocess.Popen(['avl'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
path = create_file(aircraft, False)
if command[0] == 'alpha':
out = process.communicate(bytes('load %s\noper\na a %.3f\nx\nst\n\nquit\n' % (path, command[1]), 'utf-8'))[0]
if command[0] == 'trim':
out = process.communicate(bytes('load %s\noper\na pm %.3f\nx\nst\n\nquit\n' % (path, 0), 'utf-8'))[0]
process.terminate()
output = out.decode('utf-8')
results = dict()
# Proceeds to do some RegEx "fun" in AVL's output
這種方法的問題是需要創建一個檔案供 AVL 讀取。這是一個帶有幾何描述的簡單文本檔案,但如您所知,讀取和寫入檔案很慢,而且性能在優化器中非常重要。
我的問題:有沒有辦法在不寫入驅動器的情況下獲取 AVL 的輸入?
我想過修改 Fortran 源代碼以從 stdin 獲取輸入緩沖區,但我什至不知道從哪里開始。
uj5u.com熱心網友回復:
正如Vladimir F指出的那樣,這可以通過洗掉open()andclose()陳述句并更改用于read()陳述句的單位來完成。
在 AVL 源代碼中,幾何輸入在ainput.f檔案中進行處理。我所做的更改是注釋open()和close()陳述句所在的第 72 和 1096 行,并將第 1152 行中的單位更改為*,如下所示:
20 READ (*,1000,END=80,ERR=90) LINE
現在,AVL 不是從指定檔案讀取,而是從標準輸入讀取。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/348464.html
