FiPy以正确的方式设置流出条件

时间:2018-06-15 19:42:21

标签: python-3.x fipy

我需要一些关于FiPy中一个安静的简单问题的帮助。我的目标是在相变时模拟流过混凝土块的流体。 但首先,我尝试进行简单的一维模拟,假设流体质量流量和恒定的壁温,没有任何相变。

from fipy import *
from fipy.meshes import CylindricalGrid2D, Grid1D
import matplotlib.pyplot as plt
import numpy as np

#%%


L = 1.5 #length transfer surface
bS = 0.75 #wide
AV = L * bS #transfer surface

tS0 = 350. #tWall

rhoWF = 880. #density fluid
mWF = 0.036 #mass flow
u = 5e-4 #Fluid speed
hWF = mWF / AV / rhoWF / u #height "fluid block"
nx = 50
VWF = hWF * L * bS/nx #fluid volumen
lambdaWF = 0.6 # thermal conductivity
alpha = 500. #heat transfer coefficient 
tWF0 = 371.



mesh = Grid1D(dx=L/nx, nx=nx)


tWF = CellVariable(name="Fluid", 
                   mesh=mesh, 
                   value= tWF0,
                   hasOld=True)

tS = CellVariable(name="storage", 
                  mesh=mesh, 
                  value=tS0, 
                  hasOld=True)


sourceWF=CellVariable(name="source Fluid",  #Variable der Konvektion
                       mesh=mesh,
                       value=0.)

cvrho = CellVariable(name = 'cprho',#Fluid
                     mesh = mesh,
                     value = rhoWF *  4215.2,
                     hasOld = True) 

tWF.constrain(tWF0, mesh.facesLeft()) #constant inlet temperature

t = 6*3600. #time
timeStepDuration = 1e2

#outflow boundary condition
outlet = mesh.facesRight
ConvCoeff = FaceVariable(mesh,value=u,rank=1)
exteriorCoeff = FaceVariable(mesh,value=0.,rank=1)
exteriorCoeff.setValue(value=ConvCoeff, where=outlet)
ConvCoeff.setValue(0., where=outlet)

residual1 = 1.
elapsedTime = 0.

tWFall = np.zeros(nx)[None,:]

while elapsedTime < t:
    tWF.updateOld()   
    it = 0 #iterations
    while residual1> 1e-2:      

        sourceWF.value = - AV / nx * alpha*(tWF - tS)/ cvrho / VWF #this will be a variable convection source

        eq1 = HybridConvectionTerm(coeff=ConvCoeff) +  TransientTerm(coeff=1.) == \
        + sourceWF\
        - ImplicitSourceTerm(exteriorCoeff.divergence) \
        #+ DiffusionTerm(coeff= lambdaWF / cvrho) #not necessary(?)

        residual1 = eq1.sweep(dt = timeStepDuration, var = tWF)
        print('res1: ' + str(residual1) )
        it += 1
        if it > 10:
            raise ValueError (r'MaxIter reached')  
    elapsedTime += timeStepDuration ; print('t= ' + str(round(elapsedTime,2)))
    residual1 = 1.
    tWFall = np.r_[tWFall, tWF.value[None,:]] #value collection

#%% outlet fluid temperature and storage temperature

plt.plot(np.linspace(0,t/3600.,int(t/timeStepDuration)), tWFall[1:,-1], label=r'$\vartheta_{WF}$')

plt.legend()

由于恒定的壁温和恒定的流体入口温度,我期望流体出口温度恒定。我没有将壁温定义为边界条件,因为有一天我想分析热传导和可变温度梯度。运行我的mwe,您可以看到出口处的流体温度下降。 有人可以帮忙吗? 提前谢谢!

1 个答案:

答案 0 :(得分:0)

我更改了脚本,它似乎提供了371.0的恒定温度。参见this link

  • sourceWF一词已被删除。我不确定这是干什么的,但是我认为需要一段时间才能适应壁温。

  • 方程式声明已移至循环之外。这是使用FiPy的正确方法,但在这种情况下不应影响结果。