SOLPS 中间物理量导出 & 粒子平衡统计脚本(python)

2020-04-17  本文已影响0人  锅炉工的自我修养

output analysis

1. 命名格式

b2npc9_fnax003.dat

2. 涉及物理量



是否阐释导出求解公式中的某一项?Appendix G


Others


Statistic script


脚本编写

1. 产生所需数据 eirc fnax


python 调用shell

#!/user/bin/env python
import os
val=os.system('ls -al')
print(val)
echo "phys eirc fnax 'fnax_2D.last10' mprt" | b2plot;mv  b2pl.exe.dir/fnax_2D.last10 2D_data 
import sys
cwd=sys.path[0]
print(cwd)
full_path= cwd+"/b2pl.exe/fnax_2D.last10"
print(full_path)
search cmd
e: # 盘符
cd path
jupyter note


过滤含有指定字符的行

with open(test_path,'r') as f:
        for each in f:
                if "#" not in each:
                        print(each.strip())

没有anacoda不能调用numpy库

清华镜像不快
获得数据源

a=[]
with open(full_path,'r') as f:
        for each in f:
                if "#"  not in each:
                #       print(each.strip())

                        # save the first column
                        #tmp=each.strip()
                        tmp=each.split()[3]
                        a.append(tmp)
        a=np.array(a)
        a.reshape(98,38,-1)
        print(a)

查询官方文档

numpy 官方文档
numpy 详细介绍


matlab中reshape是列优先读取的,python的reshape,存在三种读取循序

image.png

anaconda in linux 不能直接显示图片,需要先保存,再打开

image.png

存在的问题,没有按照数值排序

最终框架

#!/user/bin/env python
#coding=utf-8 

import os
import sys
import numpy as np
import matplotlib.pyplot as plt

# ===================== callback the b2plot commands ============================= #
#os.system("echo \"phys eirc fnax 'fnax_2D.last10' mprt \" | b2plot")

# ====================== get current path & string join ========================== #
#cwd=os.getcwd()
#print(cwd)
cwd=sys.path[0]
#print(cwd)

full_path= cwd+"/b2pl.exe.dir/fnax_2D.last10"
a=[]
with open(full_path,'r') as f:
        for each in f:
                if "#"  not in each:
                        # save the first column
                        tmp=each.split()[3]
                        a.append(tmp)
        a=np.array(a)
        a=np.reshape(a,(98,38,-1),order='F') # correspond with matlab script
        #print(a)
        print(a.ndim)
        print(a.size)
        print(a.shape)
        #print(a[:,0,0]) # pass the test of order

# ====================== save data in a list ================== #
ix_div_in=26
f_div=a[ix_div_in-1,:,0]
print(f_div)
print(f_div.shape)

iy=np.array(range(1,39))
print(iy.shape)

# ======================== plot the flux at somewhere ========== # 

plt.plot(iy,f_div,label='$T_{e}$',color='r',linestyle='-',linewidth=1)


plt.savefig('test.eps')


上一篇 下一篇

猜你喜欢

热点阅读