0

I need some help with a quiete simple problem in FiPy. My goal is to simulate a fluid flowing through a concrete block while phase change. But first of all I tried to do a simple 1D simulation assumed a fluid massflow and a constant wall temperature without any phase change.

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()

I would expect a constant fluid outlet temperature because of the constant wall temperature and constant fluid inlet temperature. I have not defined the wall temperature as a boundary condition because some day I would like to analyse heat conduction and variable temperature gradients too. Running my mwe you can see that the fluid temperature at the outlet declines. Could someone please help at this case? Thanks in advance!

TThe
  • 69
  • 1
  • 7
  • The script as written doesn't seem to work. It gives `NameError: name 'nx' is not defined`. – wd15 Jun 19 '18 at 18:42
  • Yes, you are right, I changed two lines for as I thought clarity. Now it should work. Sorry for that. – TThe Jun 21 '18 at 06:39

1 Answers1

0

I changed the script around and it seem to give a constant temperature of 371.0. See this link.

  • The sourceWF term has been removed. I was unsure what this was for, but I think it would take time for the wall temperature to adjust to this.

  • The equation declaration has been moved outside the loop. This is the correct way to use FiPy, but shouldn't impact the results in this case.

wd15
  • 1,068
  • 5
  • 8
  • Thanks for the help! My problem is that I need the source term. One day this should be a simulation of a pipe with a convection through the pipe over the whole length. Furthermore the term will change every timestep so that the declaration has to be inside the loop. Do you have any other suggestions? – TThe Jun 25 '18 at 06:05
  • Can you clarify what your expect to see when the source term is present? Do you expect the wall value of `tWF` to be 371 and not to fall back to ~350? What do you expect the plot to show? – wd15 Jun 25 '18 at 18:11