Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ipython show case #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 116 additions & 44 deletions Ipython/pyrms example.ipynb
Original file line number Diff line number Diff line change
@@ -1,123 +1,195 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"## 0. Package Loading"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from diffeqpy import de\n",
"from pyrms import rms\n",
"from matplotlib import pyplot as plt\n",
"%matplotlib inline"
]
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## 1. Read input file\n",
"\n",
"An example of H2 combustion is included."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"phaseDict = rms.readinput(\"../pyrms/testing/superminimal.rms\")"
]
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"spcs = phaseDict[\"gas\"][\"Species\"]\n",
"rxns = phaseDict[\"gas\"][\"Reactions\"]"
]
"spcs = phaseDict[\"phase\"][\"Species\"]\n",
"rxns = phaseDict[\"phase\"][\"Reactions\"]"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"ig = rms.IdealGas(spcs, rxns, name=\"phase\")"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"ig = rms.IdealGas(spcs,rxns,name=\"gas\")"
]
"## 2. Define initial condition and domain\n",
"An example of constant TP domain is shown, where initial T, p, and composition is required."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"initialconds = {\"T\":1000.0,\"P\":10.0e5,\"H2\":2.0,\"O2\":1.0}"
]
"initialconds = {\"T\": 1000.0, \"P\": 10.0e5, \"H2\": 2.0, \"O2\": 1.0}"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"domain, y0, p = rms.ConstantTPDomain(phase=ig, initialconds=initialconds)"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"domain,y0 = rms.ConstantTPDomain(phase=ig,initialconds=initialconds)"
]
"## 3. Construct the reactor instance and simulate the system\n",
"input"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"react = rms.Reactor(domain,y0,(0.0,10.001))"
]
"tf = 10.001\n",
"solver = de.CVODE_BDF()\n",
"abstol=1e-20\n",
"reltol=1e-8"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"react = rms.Reactor(domain, y0, (0.0, tf))"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"sol = de.solve(react.ode,de.CVODE_BDF(),abstol=1e-20,reltol=1e-8)"
]
"sol = de.solve(react.ode, solver, abstol=abstol, reltol=reltol)"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"sim = rms.Simulation(sol, domain)"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"sim = rms.Simulation(sol,domain)"
]
"## 4. Results"
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"Mole fraction"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"rms.plotmolefractions(sim, 10.0)"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"rms.plotmolefractions(sim,10.0)"
]
"ROP"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"rms.plotrops(sim, \"OH\", 1.0, N=10)"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"rms.plotrops(sim,\"OH(D)\",1.0,N=10)"
]
"Flux Diagram"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"rms.getfluxdiagram(sim,1.0)"
]
"rms.getfluxdiagram(sim, 1.0)"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [],
"outputs": [],
"source": []
"metadata": {}
}
],
"metadata": {
Expand All @@ -141,4 +213,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
Loading