{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Computing standard thermodynamic properties of species\n", "\n", "
Written by Allan Leal (ETH Zurich) on Jan 20th, 2022
\n", "\n", "```{attention}\n", "Always make sure you are using the [latest version of Reaktoro](https://anaconda.org/conda-forge/reaktoro). Otherwise, some new features documented on this website will not work on your machine and you may receive unintuitive errors. Follow these [update instructions](updating_reaktoro_via_conda) to get the latest version of Reaktoro!\n", "```\n", "\n", "This tutorial demonstrates the use of Reaktoro for the computation of standard thermodynamic properties of chemical species such as:\n", "\n", "* the standard molar Gibbs energy, $G_i^\\circ$\n", "* the standard molar Helmholtz energy, $A_i^\\circ$\n", "* the standard molar enthalpy, $H_i^\\circ$\n", "* the standard molar internal energy, $U_i^\\circ$\n", "* the standard molar entropy, $S_i^\\circ$\n", "* the standard molar volume, $V_i^\\circ$\n", "* the standard molar heat capacity (constant pressure), $C_{P,i}^\\circ$\n", "* the standard molar heat capacity (constant volume), $C_{V,i}^\\circ$\n", "\n", "Let's start with the use of the SUPCRTBL database {cite}`Zimmer2016a` to compute the standard thermodynamic properties of the following chemical species:\n", "\n", "* CO{{_2}}(aq)\n", "* CO{{_2}}(g)\n", "* Calcite" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from reaktoro import *\n", "\n", "db = SupcrtDatabase(\"supcrtbl\")\n", "\n", "CO2g = db.species(\"CO2(g)\")\n", "CO2aq = db.species(\"CO2(aq)\")\n", "calcite = db.species(\"Calcite\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can now use method `props` in the {{Species}} class to compute the standard thermodynamic properties of these species at 60 °C and 100 bar:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "STANDARD THERMODYNAMIC PROPERTIES OF CO2(G) AT 60 °C AND 100 BAR\n", "+------------------------------------------+---------+-------------+\n", "| Property | Value | Unit |\n", "+------------------------------------------+---------+-------------+\n", "| Temperature | 333.15 | K |\n", "| Pressure | 1e+07 | Pa |\n", "| Standard Gibbs Energy | -401904 | J/mol |\n", "| Standard Enthalpy | -392186 | J/mol |\n", "| Standard Volume | 0 | m3/mol |\n", "| Standard Volume (Temperature Derivative) | 0 | m3/(mol*K) |\n", "| Standard Volume (Pressure Derivative) | 0 | m3/(mol*Pa) |\n", "| Standard Isobaric Heat Capacity | 38.5567 | J/(mol*K) |\n", "| Standard Isochoric Heat Capacity | 38.5567 | J/(mol*K) |\n", "| Standard Internal Energy | -392186 | J/mol |\n", "| Standard Entropy | 29.1699 | J/(mol*K) |\n", "| Standard Helmholtz Energy | -401904 | J/mol |\n", "+------------------------------------------+---------+-------------+\n", "STANDARD THERMODYNAMIC PROPERTIES OF CO2(AQ) AT 60 °C AND 100 BAR\n", "+------------------------------------------+--------------+-------------+\n", "| Property | Value | Unit |\n", "+------------------------------------------+--------------+-------------+\n", "| Temperature | 333.15 | K |\n", "| Pressure | 1e+07 | Pa |\n", "| Standard Gibbs Energy | -390193 | J/mol |\n", "| Standard Enthalpy | -405930 | J/mol |\n", "| Standard Volume | 3.43478e-05 | m3/mol |\n", "| Standard Volume (Temperature Derivative) | 3.31002e-08 | m3/(mol*K) |\n", "| Standard Volume (Pressure Derivative) | -2.62559e-14 | m3/(mol*Pa) |\n", "| Standard Isobaric Heat Capacity | 203.77 | J/(mol*K) |\n", "| Standard Isochoric Heat Capacity | 189.868 | J/(mol*K) |\n", "| Standard Internal Energy | -406274 | J/mol |\n", "| Standard Entropy | -47.2375 | J/(mol*K) |\n", "| Standard Helmholtz Energy | -390537 | J/mol |\n", "+------------------------------------------+--------------+-------------+\n", "STANDARD THERMODYNAMIC PROPERTIES OF CALCITE AT 60 °C AND 100 BAR\n", "+------------------------------------------+--------------+-------------+\n", "| Property | Value | Unit |\n", "+------------------------------------------+--------------+-------------+\n", "| Temperature | 333.15 | K |\n", "| Pressure | 1e+07 | Pa |\n", "| Standard Gibbs Energy | -1.13263e+06 | J/mol |\n", "| Standard Enthalpy | -1.20455e+06 | J/mol |\n", "| Standard Volume | 3.69181e-05 | m3/mol |\n", "| Standard Volume (Temperature Derivative) | 0 | m3/(mol*K) |\n", "| Standard Volume (Pressure Derivative) | 0 | m3/(mol*Pa) |\n", "| Standard Isobaric Heat Capacity | 86.9803 | J/(mol*K) |\n", "| Standard Isochoric Heat Capacity | 86.9803 | J/(mol*K) |\n", "| Standard Internal Energy | -1.20492e+06 | J/mol |\n", "| Standard Entropy | -215.868 | J/(mol*K) |\n", "| Standard Helmholtz Energy | -1.133e+06 | J/mol |\n", "+------------------------------------------+--------------+-------------+\n" ] } ], "source": [ "print(\"STANDARD THERMODYNAMIC PROPERTIES OF CO2(G) AT 60 °C AND 100 BAR\")\n", "print(CO2g.props(60, \"C\", 100, \"bar\"))\n", "\n", "print(\"STANDARD THERMODYNAMIC PROPERTIES OF CO2(AQ) AT 60 °C AND 100 BAR\")\n", "print(CO2aq.props(60, \"C\", 100, \"bar\"))\n", "\n", "print(\"STANDARD THERMODYNAMIC PROPERTIES OF CALCITE AT 60 °C AND 100 BAR\")\n", "print(calcite.props(60, \"C\", 100, \"bar\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's calculate the standard thermodynamic properties of CO{{_2}}(aq) from 25 to 300 °C along the saturation pressure of water. The code block below will build a Python dictionary containing data that we will plot later (i.e., the standard molar Gibbs energy and standard molar enthalpy of the species CO{{_2}}(aq) and the temperatures used to calculate these properties):" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "temperatures = np.linspace(25.0, 300.0, 100) + 273.15 # in K\n", "\n", "data = { \"T\": [], \"G0\": [], \"H0\": [] }\n", "\n", "for T in temperatures:\n", " P = waterSaturationPressureWagnerPruss(T) # in Pa\n", " props = CO2aq.props(T, P)\n", " data[\"T\" ].append(float(T - 273.15)) # in °C\n", " data[\"G0\"].append(float(props.G0 * 0.001)) # in kJ/mol\n", " data[\"H0\"].append(float(props.H0 * 0.001)) # in kJ/mol" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```{tip}\n", "You might also be interested in other methods for calculating the thermodynamic properties of water besides `waterSaturationPressureWagnerPruss`, which implements the water saturation pressure equation in {cite:t}`Wagner2002`. Below are other methods available in Reaktoro:\n", "\n", "* `waterDensityHGK`\n", "* `waterDensityWagnerPruss`\n", "* `waterLiquidDensityHGK`\n", "* `waterLiquidDensityWagnerPruss`\n", "* `waterVaporDensityHGK`\n", "* `waterVaporDensityWagnerPruss`\n", "* `waterPressureHGK`\n", "* `waterPressureWagnerPruss`\n", "* `waterSaturationPressureWagnerPruss`\n", "* `waterSaturationLiquidDensityWagnerPruss`\n", "* `waterSaturationVapourDensityWagnerPruss`\n", "* `waterThermoPropsHGK`\n", "* `waterThermoPropsWagnerPruss`\n", "\n", "Search for these method names in [Reaktoro's API Reference](https://reaktoro.org/api/) to learn more about how to use them.\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We'll use the [bokeh](https://bokeh.org/) plotting library next. First, we need to import it and initialize it to work with Jupyter Notebooks:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": "\n(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n const JS_MIME_TYPE = 'application/javascript';\n const HTML_MIME_TYPE = 'text/html';\n const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n const CLASS_NAME = 'output_bokeh rendered_html';\n\n /**\n * Render data to the DOM node\n */\n function render(props, node) {\n const script = document.createElement(\"script\");\n node.appendChild(script);\n }\n\n /**\n * Handle when an output is cleared or removed\n */\n function handleClearOutput(event, handle) {\n const cell = handle.cell;\n\n const id = cell.output_area._bokeh_element_id;\n const server_id = cell.output_area._bokeh_server_id;\n // Clean up Bokeh references\n if (id != null && id in Bokeh.index) {\n Bokeh.index[id].model.document.clear();\n delete Bokeh.index[id];\n }\n\n if (server_id !== undefined) {\n // Clean up Bokeh references\n const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n cell.notebook.kernel.execute(cmd_clean, {\n iopub: {\n output: function(msg) {\n const id = msg.content.text.trim();\n if (id in Bokeh.index) {\n Bokeh.index[id].model.document.clear();\n delete Bokeh.index[id];\n }\n }\n }\n });\n // Destroy server and session\n const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n cell.notebook.kernel.execute(cmd_destroy);\n }\n }\n\n /**\n * Handle when a new output is added\n */\n function handleAddOutput(event, handle) {\n const output_area = handle.output_area;\n const output = handle.output;\n\n // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n return\n }\n\n const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n\n if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n // store reference to embed id on output_area\n output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n }\n if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n const bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n const script_attrs = bk_div.children[0].attributes;\n for (let i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n }\n\n function register_renderer(events, OutputArea) {\n\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n const toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[toinsert.length - 1]);\n element.append(toinsert);\n return toinsert\n }\n\n /* Handle when an output is cleared or removed */\n events.on('clear_output.CodeCell', handleClearOutput);\n events.on('delete.Cell', handleClearOutput);\n\n /* Handle when a new output is added */\n events.on('output_added.OutputArea', handleAddOutput);\n\n /**\n * Register the mime type and append_mime function with output_area\n */\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n /* Is output safe? */\n safe: true,\n /* Index of renderer in `output_area.display_order` */\n index: 0\n });\n }\n\n // register the mime type if in Jupyter Notebook environment and previously unregistered\n if (root.Jupyter !== undefined) {\n const events = require('base/js/events');\n const OutputArea = require('notebook/js/outputarea').OutputArea;\n\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n }\n\n \n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n const NB_LOAD_WARNING = {'data': {'text/html':\n \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"
\\n\"+\n \"