安装cantera并且运行一个官方示例
说明
cantera是一个
开源化学反应动力学分析软件
是chemkin的替代品之一
chemkin最早也是开源的,但是现在被ANSYS收购了,所以商业化了。
cantera类似一个库。这个软件没有GUI。但是可以在python中运行,作为Python的一个模块。也可以作为MATLAB的一个库来运行。
因为Python是开源的,本文就用Python。
安装
可以通过conda安装
安装好conda后在终端输入
conda create -n cantera -c cantera cantera ipython matplotlib
然后就是自动下载的过程。
这就创建了一个名为cantera的conda环境,使用时激活该环境就行了。
参考
https://jingyan.baidu.com/article/a3761b2be079961576f9aad9.html
官网安装地址,还有其他安装方式
https://cantera.org/install/index.html
运行官方示例
这里演示一个机理缩减的例子
官方示例源代码如下
https://cantera.org/examples/python/kinetics/mechanism_reduction.py.html
import cantera as ct
import numpy as np
import matplotlib.pyplot as pltgas = ct.Solution('gri30.yaml')
initial_state = 1200, 5 * ct.one_atm, 'CH4:0.35, O2:1.0, N2:3.76'# Run a simulation with the full mechanism
gas.TPX = initial_state
r = ct.IdealGasConstPressureReactor(gas)
sim = ct.ReactorNet([r])tt = []
TT = []
t = 0.0
# Rmax is the maximum relative reaction rate at any timestep
Rmax = np.zeros(gas.n_reactions)
while t < 0.02:t = sim.step()tt.append(1000 * t)TT.append(r.T)rnet = abs(gas.net_rates_of_progress)rnet /= max(rnet)Rmax = np.maximum(Rmax, rnet)plt.plot(tt, TT, label='K=53, R=325', color='k', lw=3, zorder=100)# Get the reaction objects, and sort them so the most active reactions are firstR = sorted(zip(Rmax, gas.reactions()), key=lambda x: -x[0])# Test reduced mechanisms with different numbers of reactions
C = plt.cm.winter(np.linspace(0, 1, 5))
for i, N in enumerate([40, 50, 60, 70, 80]):# Get the N most active reactionsreactions = [r[1] for r in R[:N]]# find the species involved in these reactions. At a minimum, include all# species in the reactant mixturespecies_names = {'N2', 'CH4', 'O2'}for reaction in reactions:species_names.update(reaction.reactants)species_names.update(reaction.products)# Get the species objectsspecies = [gas.species(name) for name in species_names]# create the new reduced mechanismgas2 = ct.Solution(thermo='IdealGas', kinetics='GasKinetics',species=species, reactions=reactions)# Re-run the ignition problem with the reduced mechanismgas2.TPX = initial_stater = ct.IdealGasConstPressureReactor(gas2)sim = ct.ReactorNet([r])t = 0.0tt = []TT = []while t < 0.02:t = sim.step()tt.append(1000 * t)TT.append(r.T)plt.plot(tt, TT, lw=2, color=C[i],label='K={0}, R={1}'.format(gas2.n_species, N))plt.xlabel('Time (ms)')plt.ylabel('Temperature (K)')plt.legend(loc='upper left')plt.title('Reduced mechanism ignition delay times\n''K: number of species; R: number of reactions')plt.xlim(0, 20)plt.tight_layout()plt.show()
复制到一个Python文件里,然后运行
得到结果
安装cantera并且运行一个官方示例相关推荐
- Python 安装 uWSGI并运行一个入门示例
Python 安装 uWSGI 1.通过 pip 命令: pip install uwsgi 2.下载安装脚本: curl http://uwsgi.it/install | bash -s defa ...
- 【Android 插件化】DroidPlugin 编译运行 ( DroidPlugin 简介 | 编译 DroidPlugin 官方示例 | 运行 DroidPlugin 官方示例 )
文章目录 一.DroidPlugin 简介 二.DroidPlugin 编译运行 1.编译 DroidPlugin 官方示例 2.运行 DroidPlugin 官方示例 一.DroidPlugin 简 ...
- 【Android 插件化】VirtualApp 编译运行 ( VirtualApp 简介 | 配置 VirtualApp 编译环境 | 编译运行 VirtualApp 官方示例 )
文章目录 一.VirtualApp 简介 二.配置 VirtualApp 编译环境 1.Android Studio 3.0 2.NDK 版本 ( Android NDK r10e ) 3.配置远程仓 ...
- 【Android 热修复】运行 Tinker 官方示例 ( 处理 TINKER_ID 问题 | 编译 debug 包 | 修改 Gradle 脚本 | 生成 patch 包 | 热修复 )
文章目录 一.下载官方示例源码 二.处理 TINKER_ID 问题 三.编译 debug 包 四.安装 APK 并运行 五.修改 Gradle 构建脚本中的文件名称 六.修改程序逻辑代码 七.生成 p ...
- WRF示例运行(官方示例)
[目的]该博客文用于备忘,有兴趣者可以照例实现,有疑问或需求在评论区留言即可: [内容]WRF的单层粗域实现: [参考]WRF实例运行系列(1)_钢筋火龙果的博客-CSDN博客_wrf运行实例 [气象 ...
- ANTLR4(一) VsCode Win10 Java 安装+环境配置+官方示例
ANTLR4 VsCode Win10 Java 安装及环境配置 vscode上实现官方示例 预期效果 编写批处理文件 编写.g4格式的语法文件 运行ANTLR4工具 测试生成的语法分析器 将语法分析 ...
- 微信小程序官方示例 Demo 代码
以前只知道小程序有一个UI组件库, 不知道小程序还有一个官方示例Demo,今天用了一下大大的提高了我的编程速度,界面截图如下: 具体的你们自己打开吧,我给你们整好了拦截,微信小程序官方示例Demo代码 ...
- pybullet机器人仿真环境搭建 1.安装pybullet,测试官方示例,基础环境搭建
pybullet机器人仿真环境搭建 1.安装pybullet 前言 安装 测试官方示例 基础环境搭建 导入pybullet 创建服务端 (可选)配置图形GUI 添加资源路径 设置重力 加载模型 迭代运 ...
- php 需要已安装且正在运行的邮件系统_php如何发送邮件?一个函数轻松搞定
中国邮箱网讯 10月12日消息 大家都知道,我们可以通过php直接发送邮件.那么php是如何发送邮件的呢?其实很简单,那就是通过邮件发送神器mail()函数. 发送邮件 01mail()函数介绍 ph ...
最新文章
- 避免资源死锁:识别已打开的事务
- 离线轻量级大数据平台Spark之MLib机器学习库聚类算法KMeans实例
- linux常用命令(2)常用系统工作命令
- shell模拟php多进程从redis获取数据(多个redis实例)
- JEPLUS平台首页规划简单介绍——JEPLUS软件快速开发平台
- add git 指定类型文件夹_UE4 使用git配合远程仓库
- 专转本计算机第一章试题,江苏专转本 计算机第一章自测题(含答案).doc
- android滑动菜单图标,Android实现简单底部导航栏 Android仿微信滑动切换效果
- (61)FPGA面试题-使用Verilog语言编写异步复位同步释放代码
- 3rd,Python登录模拟
- 中国内置扬声器市场趋势报告、技术动态创新及市场预测
- 三相同步电机怎么接线图_三相异步电机的正反转原理图解
- 安装程序无法创建新的系统分区也无法定位现有系统分区_不要再给硬盘胡乱分区了,这里有最方便安全的分区方法。...
- mysql忘记密码怎样重置
- opensuse 安装网易云音乐(tumbleweed)(leap)
- 获取input选择文件的本地地址
- LVDS display 应用
- 从http协议看百度360大战
- 【Active Learning - 13】总结与展望 参考文献的整理与分享(The End...)
- JAVA社招,让老板心动的简历原来是这样