{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import math\n", "from collections import defaultdict\n", "from chempy import ReactionSystem\n", "from chempy.units import (\n", " default_units as u,\n", " SI_base_registry as ureg\n", ")\n", "from chempy.kinetics.ode import get_odesys\n", "from chempy.kinetics.rates import SinTemp\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rsys = ReactionSystem.from_string(\"\"\"\n", "2 HNO2 -> H2O + NO + NO2; EyringParam(dH=85e3*J/mol, dS=10*J/K/mol)\n", "2 NO2 -> N2O4; EyringParam(dH=70e3*J/mol, dS=20*J/K/mol)\n", "\"\"\"\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "st = SinTemp(unique_keys='Tbase Tamp Tangvel Tphase'.split())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "odesys, extra = get_odesys(rsys, include_params=False, substitutions={\n", " 'temperature': st}, unit_registry=ureg)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "init_conc = defaultdict(lambda: 0*u.M, HNO2=1*u.M, H2O=55*u.M)\n", "params = dict(\n", " Tbase=300*u.K,\n", " Tamp=10*u.K,\n", " Tangvel=2*math.pi/(10*u.s),\n", " Tphase=-math.pi/2\n", ")\n", "duration = 60*u.s" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def integrate_and_plot(system):\n", " result = system.integrate(duration, init_conc, params, integrator='cvode', nsteps=2000)\n", " result.plot(names='NO HNO2 N2O4 NO2'.split())\n", " print({k: v for k, v in sorted(result.info.items()) if not k.startswith('internal')})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "integrate_and_plot(odesys)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "autsys = odesys.as_autonomous()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "autsys.exprs" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "integrate_and_plot(autsys)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }