Droplet Lagrangian Transient One-dimensional Reacting Code Implementation of both liquid and gas phase governing equations.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

initDropTwoPhase.py 5.3KB

7 maanden geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Wed Feb 14 14:39:59 2024
  5. @author: wangweiye
  6. """
  7. import numpy as np
  8. from numpy import power
  9. import cantera as ct
  10. import matplotlib.pyplot as plt
  11. from scipy.interpolate import CubicHermiteSpline
  12. font = {'family':'times',
  13. 'color':'darkred',
  14. 'weight':'normal',
  15. 'size':16}
  16. def calVaporPressure(T:float) ->float :
  17. # return 1e5*np.power(10,4.6543 - (1435.264/(T - 64.84))) # returns Pa, where T is in K
  18. #P = 1e3*np.exp(16.7 - (4060.0/(T - 37.0))) # returns Pa, where T is in K,FOR WATER
  19. #P = 1e5*np.power(10,4.02832-(1268.636/(T-56.199))) ; #FOR N-HEPTANE
  20. P = 0.00 #NO FUEL @ t0
  21. return P
  22. # return 1D numpy array for liquid phase mass fraction
  23. def genLiquidMassFracArr(gas,dropTemp:float,P:float,dropSpec:str) :
  24. gas.TPX = dropTemp,P,dropSpec
  25. massArr_ = gas.Y
  26. # print(gas.Y)
  27. return massArr_
  28. # return 1D numpy array for gas phase mass fraction
  29. def genGasMassFracArr(gas,gasTemp:float,P:float,gasSpec:str):
  30. gas.TPX = gasTemp,P,gasSpec
  31. massArr_ = gas.Y
  32. return massArr_
  33. # return 1D numpy array for gas phase spatial coordinate and temperature
  34. def genGasTempAndRadiusArr(Rd,L,shift,Wmix,nPts,dropTemp,gasTemp):
  35. dX = L/(nPts-1)
  36. r_ = np.zeros(nPts)
  37. r_[0] = Rd
  38. #DEBUG
  39. #print("r_[0] = %15.6e\n"%(r_[0]))
  40. for ii in range(1, nPts-1):
  41. r_[ii] = r_[ii-1] + dX
  42. r_[nPts-1] = Rd+L
  43. x = [Rd+shift, Rd+shift+Wmix] ;
  44. y = [dropTemp, gasTemp] ;
  45. m = [0,0] ;
  46. spline = CubicHermiteSpline(x, y, m)
  47. T_ = np.zeros(nPts)
  48. for i in range(nPts):
  49. if r_[i] < Rd + shift :
  50. T_[i] = dropTemp ;
  51. if r_[i] >= (Rd + shift) and (r_[i] <= Rd + shift + Wmix) :
  52. T_[i] = spline(r_[i]) ;
  53. if r_[i] > (Rd + shift +Wmix) and r_[i] <= (Rd+L) :
  54. T_[i] = gasTemp ;
  55. return r_,T_
  56. # return 2D numpy array with size of (nvar*nPts)
  57. def writeGlobalArr(Rd,L,shift,Wmix,dropTemp,gasTemp,P,dropSpec,gasSpec,gas,lnPts,gnPts,fileName):
  58. liquidMassFracArr_ = genLiquidMassFracArr(gas, dropTemp, P, dropSpec)
  59. gasMassFracArr_ = genGasMassFracArr(gas, gasTemp, P, gasSpec)
  60. # assign spatial coordinate value
  61. rG_,TG_ = genGasTempAndRadiusArr(Rd, L, shift, Wmix, gnPts, dropTemp, gasTemp)
  62. rL_ = np.zeros(lnPts)
  63. dXL = Rd/(lnPts-1)
  64. rL_[0] = 0.0
  65. for ii in range(1, lnPts-1):
  66. rL_[ii] = rL_[ii-1] + dXL
  67. rL_[lnPts-1] = Rd
  68. #DEBUG
  69. # print("last element of rL_ is :%15.6e"%(rL_[lnPts-1]))
  70. # print("first element of rG_ is :%15.6e"%(rG_[0]))
  71. r_ = np.concatenate((rL_,rG_))
  72. # assign temperature values
  73. TL_ = np.ones(lnPts)*dropTemp
  74. T_ = np.concatenate((TL_,TG_))
  75. # assign pressure values
  76. P_ = np.ones(gnPts+lnPts) * P
  77. mdot_ = np.ones(gnPts+lnPts) * 0.0
  78. # write global arr to output file
  79. out=open(fileName,"w")
  80. for i in range(lnPts):
  81. out.write("%15.6e\t%15.6e\t"%(r_[i],T_[i]))
  82. for j in range(gas.n_species):
  83. out.write("%15.6e\t"%(liquidMassFracArr_[j]))
  84. out.write("%15.6e\t"%(P_[i]))
  85. out.write("%15.6e\n"%(mdot_[i]))
  86. for i in range(lnPts,lnPts+gnPts):
  87. out.write("%15.6e\t%15.6e\t"%(r_[i],T_[i]))
  88. for j in range(gas.n_species):
  89. out.write("%15.6e\t"%(gasMassFracArr_[j]))
  90. out.write("%15.6e\t"%(P_[i]))
  91. out.write("%15.6e\n"%(mdot_[i]))
  92. out.close()
  93. # =============================================================================
  94. # Following block defines the user defined parameters
  95. # =============================================================================
  96. if __name__ == "__main__" :
  97. fileName = "initialConditionTest.dat" #This script output the initial conditions
  98. #mech='sdMechMergedVer2.cti'
  99. mech='redKaust-C3.xml' #Mechanism name
  100. #mech='chem171.cti'
  101. gas = ct.Solution(mech)
  102. Rd = 200.0e-6 #droplet radius, Unit:[m]
  103. domainLength = Rd*50.0 #domain length, Unit:[m]
  104. shift = Rd * 3.0e0 #shift of mixing region from droplet surface
  105. Wmix = Rd * 5.0e0 #thickness of mixing layer for heptane mass fraction & Temperature distribution, Unit:[m]
  106. gNpts = 5000 #Number of grid points in gas phase
  107. lNpts = 500 #Number of grid points in liquid phase
  108. Tamb = 1400.00 #Temperature of ambient air, Unit : [K]
  109. Pamb = 20.0*ct.one_atm #Pressure of ambient air, Unit :[Pa]
  110. Td = 310.00 #Temperature of droplet surface, Unit: [K]
  111. #RH = 0.0 #relative humidity
  112. dropName = "C3H8:0.20,NC7H16:0.80" #Name of droplet species
  113. # dropName ="NC7H16:1.00"
  114. gasComposition = "O2:0.21,N2:0.79"
  115. writeGlobalArr(Rd, domainLength, shift, Wmix, Td, Tamb, Pamb, dropName, gasComposition, gas, lNpts, gNpts, fileName)
  116. # writeGlobalArr(Rd, L, shift, Wmix, dropTemp, gasTemp, P, dropSpec, gasSpec, gas, lnPts, gnPts, fileName)
  117. #writeInitCond(Rd, domainLength, shift, Wmix, nGrid, Tamb, Pamb, Td, RH, gas, dropName, oxidizerName, bathName, fileName)
  118. # genTotalMassfracArr(Rd, domainLength, shift, Wmix, nGrid, Tamb, Pamb, Td, RH, gas, dropName, oxidizerName, bathName)
  119. # genTemArr(Rd, domainLength, shift, Wmix, nGrid, Tdrop, Tamb)
  120. # genMolefracArr(Rd, domainLength, shift, Wmix, nGrid, Tamb, Pamb, Td, RH)