使用pytecplot脚本在tecplot中执行方程式

问题描述 投票:0回答:1

我对tecplot和python都是新手。通过对它们进行重复计算,我有很多.dat文件要处理。因此,我写了一个小脚本。

我所遇到的问题是通过以下方式出现的:对于每个.dat文件(我以XY绘图方式绘制),我想通过将变量V5除以每个.dat文件不同的常量IMax来更改变量V5,然后覆盖旧的V5。

问题是我找不到一种方法来遍历每个.dat文件并执行此操作。

抱歉,如果不清楚,我将根据需要进行编辑。预先谢谢你

编辑:这是我编写的脚本的一部分

#!/usr/bin/env python
import tecplot as tp
import tecplot
import os
import re
from tecplot.constant import *
from tecplot.exception import *
from tecplot.tecutil import _tecutil
from tecplot.constant import ValueLocation


tecplot.session.connect()

working_dir = os.getcwd()
for filename in os.listdir(working_dir):
    if filename.endswith("Cl.dat"):

    datafile = os.path.join(working_dir, filename)
    dataset = tecplot.data.load_tecplot(datafile)
    frame = tecplot.active_frame() 



    #get IMax from data set information and divide V5 with c=IMax

    zone = dataset.zone(1)
    current_dataset = tecplot.active_frame().dataset

    c = int(zone.dimensions[0])
    tecplot.data.operate.execute_equation("{V5}=V5/c", zones= [current_dataset.zone(1)])

    tp.save_layout(os.path.splitext(filename)[0]  + "_plot_fft.lay",
               include_data=True,
               include_preview=False)

    tecplot.export.save_png(os.path.splitext(filename)[0] + "_plot_fft.png",
     width=1162,
     region=ExportRegion.AllFrames,
     supersample=1,
     convert_to_256_colors=False)
    tecplot.new_layout()

问题是我需要在执行方程式内部更改c

python numpy scripting macros
1个回答
0
投票

我在搜索时找到了答案。我将其发布,因为我认为这对于在使用tecplot的python脚本时希望在execute equation命令中包含可变数量的其他人很有用。最后,我在python脚本中定义了一个函数,该函数在每个时间步都被调用。替换上面编写的脚本的以下行:

c = int(zone.dimensions[0])
tecplot.data.operate.execute_equation("{V5}=V5/c", zones=[current_dataset.zone(1)])

带有以下内容:

IMax = zone.dimensions[0]      
def normalize(vname, c, source_zone):
        equation = "{%s} = {%s}/%d"%(vname, vname, zone.dimensions[0])
        tp.data.operate.execute_equation(equation, zones=[current_dataset.zone(1)])
        return current_dataset.zone(1)

normalized_variable = normalize('Amplitude (V2)', IMax, 1)
© www.soinside.com 2019 - 2024. All rights reserved.