Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Tue Apr 2 15:14:40 2019
  4.  
  5. @author: ddesantis
  6. """
  7.  
  8. from fipy import *
  9. import numpy as np
  10. import matplotlib.pyplot as plt
  11.  
  12. #%% - Mesh
  13.  
  14. nx = 50
  15. L = 0.061 #m,
  16.  
  17. L1 = 0.035 # Length of air channel
  18. t_w = 1./1000. # m, wall thickness
  19. L2 = L1+t_w # m, interface between PCM and wall
  20. L3 = L # m, Total Length
  21. mesh = Grid1D(Lx=L,nx=nx)
  22. #mesh = CylindricalGrid1D(nr=nx, dr=dx)
  23.  
  24. X = mesh.faceCenters
  25. x=mesh.cellCenters[0]
  26. #%% - Sweeps
  27. dt = 0.45 #s,time step for sweeps
  28. steps = 150
  29. #%% Universal Constants
  30. MW = 2.02 #g H2 mol^-1
  31. R = 8.314e-3 # kj mol^-1 K^-1
  32.  
  33. #%% - air Properties
  34. T_in = 600. # K
  35. P_in = 1. # bar
  36. v = 0.5 # m s^-2
  37. k_air = 44.41/1000./1000. # kJ s^-1 m^-1 K^-1 (air at ~600K)
  38. Cp_air = 1.051 # kJ kg ^-1 K^-1
  39. rho_air = 0.6 # kg m^-3, At 600K
  40.  
  41. Re = 1150. # Reynolds Number, dimensionless
  42. Pr = 0.727 # Prandlt Number, dimensionless
  43. Nu = 1.86 # Nusselt Number, dimensionless
  44.  
  45. #%% - Wall properties
  46. #I'm assuming the wall is steel
  47. rho_w = 8050. # kg m^-3
  48. Cp_w = 0.5 # kJ K^-1 kg^-1
  49. k_w = 16.3/1000. # kJ s^-1 m^-1 K^-1
  50.  
  51. T_w_initial = (T_in+293)/2
  52.  
  53. #%% PCM Properties
  54. T_init = 293. #K
  55. T_melt = 300. #K
  56. H_fus = 206. #kJ kg^-1
  57.  
  58. k_s = 0.18 #W m^-1 K^-1
  59. k_l = 0.19 #W m^-1 K^-1
  60. #k_PCM = FaceVariable(mesh=mesh,value = k_s)
  61. k_PCM = k_s
  62.  
  63. Cp_s = 1.8 #kJ kg^-1 K^-1
  64. Cp_l = 2.4 #kJ kg^-1 K^-1
  65. #Cp_PCM = FaceVariable(mesh=mesh,value = Cp_s)
  66. Cp_PCM = Cp_s
  67.  
  68. # I assume they want solid and liquid presented the same way again?
  69. rho_s = 789. # kg m^-3
  70. rho_l = 750. # kg m^-3
  71.  
  72. #%% Domains
  73.  
  74. air = x <= L1
  75. wall = (x > L1) & (x <= L2)
  76. PCM = x > L2
  77.  
  78. #%% Equation Variables
  79.  
  80. T = CellVariable(name='Temp', mesh=mesh, hasOld=True)
  81. T.setValue(T_in, where=air)
  82. T.setValue(T_w_initial, where=wall)
  83. T.setValue(T_init, where=PCM)
  84.  
  85. rho = CellVariable(name='rho', mesh=mesh)
  86. rho.setValue(rho_air, where=air)
  87. rho.setValue(rho_w, where=wall)
  88. rho.setValue(rho_s, where=PCM)
  89.  
  90. Cp = CellVariable(name='Cp', mesh=mesh)
  91. Cp.setValue(Cp_air, where=air)
  92. Cp.setValue(Cp_w, where=wall)
  93. Cp.setValue(Cp_s, where=PCM)
  94.  
  95. k = CellVariable(name='k', mesh=mesh)
  96. k.setValue(k_air, where=air)
  97. k.setValue(k_w, where=wall)
  98. k.setValue(k_s, where=PCM)
  99.  
  100. #%% Boundary Conditions
  101.  
  102. T.constrain(T_in, mesh.facesLeft)
  103.  
  104. #%% - Equations
  105.  
  106. eq = TransientTerm(coeff=rho * Cp, var=T) == DiffusionTerm(coeff=k, var=T)
  107.  
  108. #%% - Sweeps
  109. viewer = Viewer(vars=T,datamin = 50.,datamax = 700.)
  110. viewer.plot()
  111.  
  112. for step in range(steps):
  113. T.updateOld()
  114. eq.solve(dt=dt)
  115.  
  116. viewer.plot()
  117. percent_complete = float(step)/float(steps)
  118. print('percent complete: {:0.0f}%'.format(100.*percent_complete))
  119.  
  120. print('step {} of {}'.format(step, steps))
  121.  
  122. print('elapsed fill time: {:0.2f}s'.format(step*dt))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement