{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# States\n", "\n", "A Riemann Problem is specified by the state of the material to the left and right of the interface. In this hydrodynamic problem, the state is fully determined by an [equation of state](eos_defns.html) and the variables\n", "\n", "$$\n", " {\\bf U} = \\begin{pmatrix} \\rho_0 \\\\ v_x \\\\ v_t \\\\ \\epsilon \\end{pmatrix},\n", "$$\n", "\n", "where $\\rho_0$ is the rest-mass density, $v_x$ the velocity normal to the interface, $v_t$ the velocity tangential to the interface, and $\\epsilon$ the specific internal energy." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Defining a state" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In `r3d2` we define a state from an equation of state and the values of the key variables:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from r3d2 import eos_defns, State" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "eos = eos_defns.eos_gamma_law(5.0/3.0)\n", "U = State(1.0, 0.1, 0.0, 2.0, eos)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Inside the notebook, the state will automatically display the values of the key variables:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "\\begin{equation}\\begin{pmatrix} \\rho \\\\ v_x \\\\ v_t \\\\ \\epsilon \\end{pmatrix}= \\begin{pmatrix} 1.0000 \\\\ 0.1000 \\\\ 0.0000 \\\\ 2.0000 \\end{pmatrix}\\end{equation}" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "U" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Adding a label to the state for output purposes requires an extra keyword:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "\\begin{equation}\\begin{pmatrix} \\rho \\\\ v_x \\\\ v_t \\\\ \\epsilon \\end{pmatrix}_{L} = \\begin{pmatrix} 10.0000 \\\\ -0.3000 \\\\ 0.1000 \\\\ 5.0000 \\end{pmatrix}\\end{equation}" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "U2 = State(10.0, -0.3, 0.1, 5.0, eos, label=\"L\")\n", "U2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reactive states\n", "\n", "If the state has energy available for reactions, that information is built into the equation of state. The definition of the equation of state changes: the definition of the state itself does not:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/latex": [ "\\begin{equation}\\begin{pmatrix} \\rho \\\\ v_x \\\\ v_t \\\\ \\epsilon \\\\ q \\end{pmatrix}_{Reactive} = \\begin{pmatrix} 5.0000 \\\\ 0.1000 \\\\ 0.1000 \\\\ 2.0000 \\\\ 0.1000 \\end{pmatrix}\\end{equation}" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q_available = 0.1\n", "t_ignition = 10.0\n", "Cv = 1.0\n", "eos_reactive = eos_defns.eos_gamma_law_react(5.0/3.0, q_available, Cv, t_ignition, eos)\n", "U_reactive = State(5.0, 0.1, 0.1, 2.0, eos_reactive, label=\"Reactive\")\n", "U_reactive" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Additional functions\n", "\n", "A state knows its own wavespeeds. Given a wavenumber (the left acoustic wave is `0`, the middle contact or advective wave is `1`, and the right acoustic wave is `2`), we have:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Left wavespeed of first state is -0.6636390537799616\n", "Middle wavespeed of second state is -0.3\n", "Right wavespeed of reactive state is 0.7615771981098584\n" ] } ], "source": [ "print(\"Left wavespeed of first state is {}\".format(U.wavespeed(0)))\n", "print(\"Middle wavespeed of second state is {}\".format(U2.wavespeed(1)))\n", "print(\"Right wavespeed of reactive state is {}\".format(U.wavespeed(2)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A state will return the key *primitive* variables ($\\rho, v_x, v_t, \\epsilon$):" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Primitive variables of first state are [1. 0.1 0. 2. ]\n" ] } ], "source": [ "print(\"Primitive variables of first state are {}\".format(U.prim()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A state will return all the variables it computes, which is $\\rho, v_x, v_t, \\epsilon, p, W, h, c_s$: the primitive variables as above, the pressure $p$, Lorentz factor $W$, specific enthalpy $h$, and speed of sound $c_s$:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "All variables of second state are [1. 0.1 0. 2. 1.33333333 1.00503782\n", " 4.33333333 0.71611487]\n" ] } ], "source": [ "print(\"All variables of second state are {}\".format(U.state()))" ] } ], "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.4" } }, "nbformat": 4, "nbformat_minor": 2 }