{ "cells": [ { "cell_type": "markdown", "id": "b532d14c", "metadata": {}, "source": [ "# Carbon dioxide gas solubility in water\n", "\n", "This tutorial demonstrates how to simulate the solubility of CO2 gas in water or, in simpler words, the effect\n", "happening when one opens the bottle with soda.\n", "\n", "First, we defined considered chemical system:" ] }, { "cell_type": "code", "execution_count": null, "id": "b1a5ad8e", "metadata": {}, "outputs": [], "source": [ "from reaktoro import *\n", "db = Database(\"supcrt98.xml\")\n", "editor = ChemicalEditor(db)\n", "editor.addAqueousPhaseWithElements(\"H O C\")\n", "editor.addGaseousPhase([\"CO2(g)\"])\n", "system = ChemicalSystem(editor)\n", "print(system)" ] }, { "cell_type": "markdown", "id": "b5c11cc6", "metadata": {}, "source": [ "Then we defined the pressure in the bottle before adn after opening (as two end states). To generates pressure values\n", "in between, we use function `linspace()` of the **numpy** library:" ] }, { "cell_type": "code", "execution_count": null, "id": "0221f9a5", "metadata": {}, "outputs": [], "source": [ "p_closed_bottle = 3.79 # in bars\n", "p_open_bottle = 1.01325 # in bars\n", "pressures = numpy.linspace(p_open_bottle, p_closed_bottle, num=100)\n", "print(pressures)" ] }, { "cell_type": "markdown", "id": "711593a5", "metadata": {}, "source": [ "Next, we run through the generated pressure list and create a chemical problem corresponding to each pressure.\n", "\n", "> **Note**: A typical carbonated soft drink contains approximately 3–4 volumes (6–8 g/L) CO2.\n", "> To obtain amount of mol of CO2 we need to add to each problem, we do the following calculations:\n", "> 8 g/L = 8 / 44.01 = 0.18$, where 44.01 g/mol is the CO2 molar mass." ] }, { "cell_type": "code", "execution_count": null, "id": "1b2c24ad", "metadata": {}, "outputs": [], "source": [ "problems = []\n", "for P in pressures:\n", " problem = EquilibriumProblem(system)\n", " problem.setTemperature(20.0, \"celsius\")\n", " problem.setPressure(P, \"bar\")\n", " problem.add(\"H2O\", 0.5, \"kg\") # add ~ half a liter of water\n", " problem.add(\"C02\", 0.18, \"mol\") # add calculated amount of gas\n", " problems.append(problem) # append the new problem into the list of problems problems" ] }, { "cell_type": "markdown", "id": "f4890daf", "metadata": {}, "source": [ "Equilibrate the list of generated chemical problems:" ] }, { "cell_type": "code", "execution_count": null, "id": "7c753e08", "metadata": {}, "outputs": [], "source": [ "solver = EquilibriumSolver(system)\n", "states = [ChemicalState(system) for _ in range(len(problems))]\n", "for i in range(len(problems)):\n", " solver.solve(states[i], problems[i])" ] }, { "cell_type": "markdown", "id": "7cb88505", "metadata": {}, "source": [ "To visualize the changes in the CO2 amount in the bottle, we export\n", "[bokeh](https://docs.bokeh.org/en/latest/docs/gallery.html#standalone-examples) python plotting package." ] }, { "cell_type": "code", "execution_count": null, "id": "0851a8ce", "metadata": { "lines_to_next_cell": 1 }, "outputs": [], "source": [ "from bokeh.plotting import figure, show\n", "from bokeh.io import output_notebook\n", "output_notebook()" ] }, { "cell_type": "code", "execution_count": null, "id": "f162e598", "metadata": { "lines_to_next_cell": 1 }, "outputs": [], "source": [ "def custom_figure(title, y_axis_label): return figure(plot_width=600, plot_height=300,\n", " title=title,\n", " x_axis_label='Pressures',\n", " y_axis_label=y_axis_label)" ] }, { "cell_type": "code", "execution_count": null, "id": "e2cc064e", "metadata": {}, "outputs": [], "source": [ "co2gas_amount = [state.speciesAmount(\"CO2(g)\") for state in states]\n", "fig = custom_figure(title=\"CO2(g)\", y_axis_label='Amount of CO2(g) [mol]')\n", "fig.line(pressures, co2gas_amount, line_width=4, line_color='teal')\n", "show(fig)" ] }, { "cell_type": "markdown", "id": "c047f1e0", "metadata": {}, "source": [ "From the plot, we see that by decreasing the pressure in the bottle, we also reduce the amount of CO2(g)." ] } ], "metadata": {}, "nbformat": 4, "nbformat_minor": 5 }