{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Free Flame Example\n", "\n", "This example uses `ctwrap` for one-dimensional adiabatic premixed flame simulations defined by the simulation module `freeflame` (`ctwrap.modules.freeflame`)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Function/Class Definitions" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import cantera as ct\n", "import ctwrap as cw\n", "import json" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simulations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create Simulation Object\n", "\n", "Uses a module in the `modules` folder. Modules do not have to depend on `ctwrap`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sim = cw.Simulation.from_module(cw.modules.freeflame)\n", "sim" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create Simulation Handler" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fname = 'freeflame.yaml'\n", "s = cw.SimulationHandler.from_yaml(fname, strategy='matrix', verbosity=1)\n", "s" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Run Simulation Tasks in Parallel" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%time\n", "s.run_parallel(sim, verbosity=0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create Graphical Output" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import h5py\n", "import matplotlib.pyplot as plt\n", "import matplotlib as mpl\n", "col = mpl.rcParams['axes.prop_cycle'].by_key()['color']\n", "n_col = len(col)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load Data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = h5py.File(s.output_name, 'r')\n", "data.keys()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data.attrs.keys()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "var = json.loads(data.attrs['strategy'])\n", "var" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "default = json.loads(data.attrs['defaults'])\n", "default" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "up = default.get('upstream')\n", "up" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cases = json.loads(data.attrs['cases'])\n", "cases" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "phi = [t['upstream.phi'] for t in cases.values() \n", " if t['model.transport'] == 'mix']\n", "phi" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mix = {k: dict(data[k]['flame']) for k, v in cases.items() \n", " if v['model.transport'] == 'mix'}\n", "mlt = {k: dict(data[k]['flame']) for k, v in cases.items() \n", " if v['model.transport'] == 'multi'}\n", "sor = {k: dict(data[k]['flame']) for k, v in cases.items() \n", " if v['model.transport'] == 'soret'}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mix.keys()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Plot\n", "\n", "Plot flame speeds and temperature profiles" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# create figure\n", "fig, ax = plt.subplots(1)\n", "fig.set_size_inches(8.,6.)\n", "\n", "# plot results\n", "u_mix = [ mix[t]['velocity'][0] for t in mix]\n", "u_mlt = [ mlt[t]['velocity'][0] for t in mlt]\n", "u_sor = [ sor[t]['velocity'][0] for t in sor]\n", "\n", "ax.plot(phi, u_mix, marker='o', \n", " linestyle='none', label='mixture-averaged') \n", "ax.plot(phi, u_mlt, marker='s', \n", " markerfacecolor='none',\n", " linestyle='none', label='multi-component') \n", "ax.plot(phi, u_sor, marker='x', \n", " markerfacecolor='none',\n", " linestyle='none', label='soret enabled') \n", "\n", "# add title/axis labels\n", "ax.set_xlabel('Equivalence ratio (-)')\n", "ax.set_ylabel('Flame speed (m/s)')\n", "\n", "ax.set_title('Free premixed flame simulation for {} with {}'.format(up['fuel'],up['oxidizer']))\n", "\n", "# add legend\n", "leg = ax.legend(loc='lower right',#prop={'size':11},\n", " title='Transport Model') # % mech)\n", "_ = leg.draw_frame(False) " ] }, { "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.7.8" } }, "nbformat": 4, "nbformat_minor": 2 }