Txt输出不是我期望的

时间:2019-11-21 21:24:28

标签: python

分配的目标是制作一个在不同深度(0、5和10)的土壤剖面的热流图,以下代码未引起错误,但输出文本不是所需的。

import math

kappa = 0.10e-6 # m^2 - thermal diffusivity
C = 0.58e6 # J/m^3/K - heat capacity
delta_z = 0.01 # m - grid spacing
model_depth = 1 # m
delta_t = 60 # s - time step
grid_boundaries = [x * delta_z for x in range(0, int(model_depth/delta_z))]
Flux = [x * 0 for x in range(0, int(model_depth/delta_z))]
grid_centres = []
T = []
Tsfc = []
T5 = []
T10 = []

for i in range(0, len(grid_boundaries) - 1):
    grid_centres.append( (grid_boundaries[i] + grid_boundaries[i+1]) / 2)
    T.append(20)
for i in range(1, int(86400/delta_t) * 7):
    Flux[0] = 5 * math.sin(2*math.pi * i/(86400/delta_t))
    for j in range(1, len(grid_centres)):
        Flux[j] = -kappa * C * (T[j] - T[j-1]) / delta_z
    for j in range(0, len(grid_centres)):
        DeltaT = (Flux[j+1] - Flux[j] * delta_t / C / delta_z)
    Tsfc.append(T[0])
    T5.append(T[5])
    T10.append(T[10])
T[j] = T[j] - DeltaT

with open('model_output.txt', 'w') as f:
    for i in range(1, int(86400/delta_t) * 7):
        print("%f\t%f\t%f\t%f" % (i/86400 * delta_t,
                                    Tsfc[i-1], T5[i-1], T10[i-1]), file=f)
f.close

我的输出应该是4列,(时间,Tsfc,T5和T10),但是第二,第三和第四列都显示为20.00000。有什么我想念的吗?或我可以添加的内容?抱歉,我是python的新手,正在按照实验大纲进行操作,因此在没有错误的情况下,我不确定我哪里出错了。

0 个答案:

没有答案