鱼C论坛

 找回密码
 立即注册
查看: 1057|回复: 1

求问,CompositionReader是个python的第三方库吗?

[复制链接]
发表于 2020-8-26 00:03:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
这个是cantera的一个事例,其中用到了import CompositionReader,求问CompositionReader怎么安装下载,我用pip失败了
  1. # Clint Dunn, cdunn6754@gmail.com, 07-5-17
  2. # written in Python 3.6.1 on cantera 2.3.0

  3. ## Description
  4. # A PSR combustor. Two separate streams - one coal volatiles and the other air, both at
  5. # 300 K and 1 atm flow into an adiabatic and constant pressure
  6. # combustor where they mix and burn.

  7. # Writen so that we can write out a csv file for a particular combination of
  8. # chemical mechanism and fuel composition. It writes these to the csv directory.
  9. # The ppPsr.py script then reads these csv's and plots/ post processes them.

  10. # From the original Cantera file starter thing that I kept:
  11. # We are interested in the steady-state burning solution. Since at 300 K no
  12. # reaction will occur between fuel and air, we need to use an 'igniter' to
  13. # initiate the chemistry. A simple igniter is a pulsed flow of atomic hydrogen.
  14. # After the igniter is turned off, the system approaches the steady burning
  15. # solution.


  16. # let me get at my utility functions
  17. import sys
  18. import os
  19. sys.path.append(os.path.abspath("/home/cdunn3/Python_3.6.1/Cantera/utilities"))

  20. import math
  21. import csv
  22. import matplotlib.pyplot as plt
  23. import cantera as ct
  24. import numpy as np
  25. import CompositionReader as cr

  26. #..........................................................................#
  27. ## setup stuff

  28. # user inputs
  29. mechanism = 'drm'
  30. fuel_name = 'heavy'

  31. # Get the specified fuel compositions
  32. fuel_dict = {'light':'light_fuel.txt',
  33.              'heavy':'heavy_fuel.txt'
  34.          }
  35. composition = cr.read_compositions(fuel_dict[fuel_name])

  36. # define the mechanism and gas
  37. mech_dir = 'mechanisms/'
  38. mechanism_dict = {'reduced':'r_creck_52.cti',
  39.                   'full':'POLIMI_TOT_1412.cti',
  40.                   'drm':'DRM_22_benzene.cti'
  41.               }
  42. gas = ct.Solution(mech_dir +  mechanism_dict[mechanism])

  43. # ....................................................................#
  44. ## run the simulation

  45. # create a reservoir for the fuel inlet, and set to pure methane.
  46. gas.TPX = 300.0, ct.one_atm, composition
  47. fuel_in = ct.Reservoir(gas)
  48. fuel_mw = gas.mean_molecular_weight

  49. # use predefined function Air() for the air inlet
  50. air = ct.Solution('air.xml')
  51. air_in = ct.Reservoir(air)
  52. air_mw = air.mean_molecular_weight

  53. # to ignite the fuel/air mixture, we'll introduce a pulse of radicals. The
  54. # steady-state behavior is independent of how we do this, so we'll just use a
  55. # stream of pure atomic hydrogen.
  56. gas.TPX = 300.0, ct.one_atm, 'H:1.0'
  57. igniter = ct.Reservoir(gas)

  58. # create the combustor, and fill it in initially with N2
  59. gas.TPX = 300.0, ct.one_atm, 'N2:1.0'
  60. combustor = ct.IdealGasReactor(gas)
  61. combustor.volume = 1.0

  62. # create a reservoir for the exhaust
  63. exhaust = ct.Reservoir(gas)

  64. # adjust the ratio coming in
  65. Z  = 0.15

  66. # compute fuel and air mass flow rates (light crashes at 2.5)
  67. total_mdot = lambda t:  1 + (2.*t)**2.0
  68. air_mdot = lambda t: total_mdot(t) * (1.0 -Z)
  69. fuel_mdot = lambda t: total_mdot(t) * Z

  70. # create and install the mass flow controllers. Controllers m1 and m2 provide
  71. # constant mass flow rates, and m3 provides a short Gaussian pulse only to
  72. # ignite the mixture
  73. m1 = ct.MassFlowController(fuel_in, combustor, mdot=fuel_mdot)

  74. # note that this connects two reactors with different reaction mechanisms and
  75. # different numbers of species. Downstream and upstream species are matched by
  76. # name.
  77. m2 = ct.MassFlowController(air_in, combustor, mdot=air_mdot)

  78. # The igniter will use a Gaussian time-dependent mass flow rate.
  79. fwhm = 0.2
  80. amplitude = 0.01
  81. t0 = 0.5
  82. igniter_mdot = lambda t: amplitude * math.exp(-(t-t0)**2 * 4 * math.log(2) / fwhm**2)
  83. m3 = ct.MassFlowController(igniter, combustor, mdot=igniter_mdot)

  84. # put a valve on the exhaust line to regulate the pressure
  85. v = ct.Valve(combustor, exhaust, K=1.0)

  86. # the simulation only contains one reactor
  87. sim = ct.ReactorNet([combustor])

  88. # take single steps to 6 s, writing the results to a CSV file for later
  89. # plotting.
  90. tfinal = 40.0
  91. dt = 0.0001
  92. times = np.arange(dt,tfinal,dt)

  93. # data output arrays
  94. states = ct.SolutionArray(gas, extra=['t', 'tres', 'fuel_mdot', 'Z'])
  95. for i, time in enumerate(times):
  96.     sim.advance(time)
  97.     tres = combustor.mass/(m1.mdot(time) + m2.mdot(time))    #v.mdot(time)
  98.     states.append(gas.state, t=time, tres=tres, fuel_mdot=m1.mdot(time), Z=Z)

  99. csv_dir = 'csv_files/'
  100. states.write_csv(csv_dir + fuel_name + '_' + mechanism + '_states.csv')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-26 08:03:21 | 显示全部楼层


应该不是,是自己写的代码吧

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-10 02:53

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表