{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## ADM1F SRT: single tank and two-phase anaerobic dynamic membrane bioreactor\n", "\n", "This script is used to simulate a single tank suspended anaerobic dynamic membrane digester and a novel two-phase anaerobic dynamic membrane bioreator with separated SRT and HRT. In the two-phase reactor the effluent (model output) from the first phase dynamic membrane bioreactor is converted to the influent (model input) for the second-phase anaerobic dynamic membrane bioreactor as shown in the figure." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note:** Before running the ADM1F SRT simulations see intructions on how to compile `adm1f_srt.cxx` in the User Guide.\n", "\n", "\n", "**Mass balance equation with SRT:**\n", "\n", "The ADM1 and ADM1F solve the mass balance equation (i.e. mass_change = mass_in – mass_out + reaction). ADM1F_SRT version of the model includes solid retention time ($t_{res,X}$) as shown in the equation below. \n", "\n", "$$\n", "\\frac{d\\, S_{\\text{liq,i}}}{dt} = \\frac{qS_{\\text{in,i}}}{V_{\\text{liq}}} - \\frac{qS_{\\text{liq,i}} }{V_{\\text{liq}}}+ \\sum_{j=1}^{12}\\rho_{j} v_{i,j}\n", "$$\n", "\n", "$$\n", "\\frac{d\\, X_{\\text{liq,i}}}{dt} = \\frac{qX_{\\text{in,i}}}{V_{\\text{liq}}} - \\frac{X_{\\text{liq,i}}}{t_{\\text{res,X}} + V_{\\text{liq}}/q} + \\sum_{j=13}^{24}\\rho_{j} v_{i,j}\n", "$$\n", "\n", "Authors: Wenjuan Zhang, Elchin Jafarov, Kuang Zhu" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-09-22T22:41:31.196813Z", "start_time": "2020-09-22T22:41:29.366849Z" }, "code_folding": [] }, "outputs": [], "source": [ "# Load packages\n", "import numpy as np\n", "import pandas as pd\n", "import os\n", "import seaborn as sns\n", "import adm1f_utils as adm1fu\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# navigate to simulations folder\n", "os.chdir('../simulations')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-09-22T22:41:42.100135Z", "start_time": "2020-09-22T22:41:31.231830Z" }, "code_folding": [] }, "outputs": [], "source": [ "# Grab the names and unit of all the outputs\n", "(output_name,output_unit)=adm1fu.get_output_names()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/elchin/project/ADM1F_WM/build/adm1f\r\n" ] } ], "source": [ "#check the path to the executable\n", "!echo $ADM1F_EXE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Single tank anaerobic dynamic membrane bioreactor (AnDMBR)\n", "\n", "To simulate the single tank AnDMBR that has separated SRT and HRT, We can call the function`reactor1` with different Q (flow-rate), Vliq (reactor volume), t_resx (SRT-HRT) values, the function will return the corresponding output\n", "\n", "Usage example: reactor1(Q=100, t_resx=30, Vliq=300) \n", "\n", "**(Unit)** Q: [m3/d], t_resx: [day], Vliq: [m3]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-09-22T22:43:01.349288Z", "start_time": "2020-09-22T22:43:01.343864Z" }, "code_folding": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Reactor run, phase-one:\n", "$ADM1F_EXE -ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady -Vliq 300 -t_resx 0 -influent_file influent_cur.dat\n", "indicator-228.out\n", "Reactor run, phase-one:\n", "$ADM1F_EXE -ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady -Vliq 300 -t_resx 1 -influent_file influent_cur.dat\n", "indicator-307.out\n", "Reactor run, phase-one:\n", "$ADM1F_EXE -ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady -Vliq 300 -t_resx 2 -influent_file influent_cur.dat\n", "indicator-437.out\n", "Reactor run, phase-one:\n", "$ADM1F_EXE -ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady -Vliq 300 -t_resx 3 -influent_file influent_cur.dat\n", "indicator-563.out\n", "Reactor run, phase-one:\n", "$ADM1F_EXE -ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady -Vliq 300 -t_resx 4 -influent_file influent_cur.dat\n", "indicator-521.out\n", "Reactor run, phase-one:\n", "$ADM1F_EXE -ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady -Vliq 300 -t_resx 5 -influent_file influent_cur.dat\n", "indicator-516.out\n", "Reactor run, phase-one:\n", "$ADM1F_EXE -ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady -Vliq 300 -t_resx 6 -influent_file influent_cur.dat\n", "indicator-534.out\n", "Reactor run, phase-one:\n", "$ADM1F_EXE -ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady -Vliq 300 -t_resx 7 -influent_file influent_cur.dat\n", "indicator-542.out\n", "Reactor run, phase-one:\n", "$ADM1F_EXE -ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady -Vliq 300 -t_resx 8 -influent_file influent_cur.dat\n", "indicator-556.out\n", "Reactor run, phase-one:\n", "$ADM1F_EXE -ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady -Vliq 300 -t_resx 9 -influent_file influent_cur.dat\n", "indicator-576.out\n" ] } ], "source": [ "# testing different SRTs=[0,1,2,...9] on the one-phase reactor\n", "resx_list = [i for i in range(10)]\n", "# setup the matrix with columns correspoding SRTs and rows to outputs\n", "output1_resx = np.zeros((len(resx_list), 67))\n", "# here we utilize back euler solver and adataptive time step\n", "# for more command options see \"User Guide/Running ADM1F/step 5\"\n", "options='-ts_type beuler -ts_adapt_type basic -ts_max_snes_failures -1 -steady'\n", "\n", "for i in range(len(resx_list)):\n", " output1_resx[i] = adm1fu.reactor1(opt=options, Vliq=300, Q=600, t_resx=resx_list[i])\n", " \n", "np.savetxt('output_1phase.csv',output1_resx,delimiter=',',fmt='%1.4e')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-09-22T22:43:13.547934Z", "start_time": "2020-09-22T22:43:13.481493Z" } }, "outputs": [], "source": [ "df1_resx = pd.read_csv('output_1phase.csv', sep=',', header=None)\n", "df1_resx.columns = output_name \n", "df1_resx.insert(0,\"T_resx\",resx_list)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Relation between t_resx and output when Vliq=300m3, Q=600m3/d**" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-09-22T22:43:41.970938Z", "start_time": "2020-09-22T22:43:41.906442Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " | T_resx | \n", "Ssu | \n", "Saa | \n", "Sfa | \n", "Sva | \n", "Sbu | \n", "Spro | \n", "Sac | \n", "Sh2 | \n", "Sch4 | \n", "... | \n", "Alk | \n", "NH3 | \n", "NH4 | \n", "LCFA | \n", "percentch4 | \n", "energych4 | \n", "efficiency | \n", "VFA/ALK | \n", "ACN | \n", "sampleT | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "0 | \n", "2152.800 | \n", "324.2700 | \n", "7382.70 | \n", "2381.700 | \n", "3667.300 | \n", "2542.700 | \n", "8263.5 | \n", "25.643000 | \n", "-8.963700e-82 | \n", "... | \n", "44957.0 | \n", "0.053067 | \n", "1074.00 | \n", "7382.70 | \n", "-1.133000e-81 | \n", "83.808 | \n", "3.9774 | \n", "0.351490 | \n", "-3.203400e-72 | \n", "0.5 | \n", "
1 | \n", "1 | \n", "123.060 | \n", "49.1670 | \n", "7751.20 | \n", "2574.400 | \n", "4202.900 | \n", "3244.500 | \n", "9600.7 | \n", "30.352000 | \n", "3.859800e-12 | \n", "... | \n", "59182.0 | \n", "0.047701 | \n", "1135.60 | \n", "7751.20 | \n", "1.599000e-12 | \n", "100.630 | \n", "-76.4800 | \n", "0.310840 | \n", "1.255000e-08 | \n", "0.5 | \n", "
2 | \n", "2 | \n", "63.057 | \n", "26.6380 | \n", "7839.00 | \n", "2610.000 | \n", "4268.600 | \n", "3305.000 | \n", "9742.9 | \n", "30.772000 | \n", "1.085400e-09 | \n", "... | \n", "61421.0 | \n", "0.048208 | \n", "1150.90 | \n", "7839.00 | \n", "4.422100e-10 | \n", "102.210 | \n", "-155.0200 | \n", "0.304150 | \n", "2.777100e-07 | \n", "0.5 | \n", "
3 | \n", "3 | \n", "39.313 | \n", "17.3450 | \n", "908.19 | \n", "41.129 | \n", "54.118 | \n", "53.411 | \n", "3339.7 | \n", "0.000662 | \n", "2.574900e+02 | \n", "... | \n", "16289.0 | \n", "2.513100 | \n", "963.03 | \n", "908.19 | \n", "5.579800e+01 | \n", "209.370 | \n", "-218.4400 | \n", "0.200760 | \n", "9.097200e+00 | \n", "0.5 | \n", "
4 | \n", "4 | \n", "30.634 | \n", "13.5750 | \n", "457.20 | \n", "30.592 | \n", "39.989 | \n", "35.895 | \n", "3066.6 | \n", "0.000515 | \n", "2.653300e+02 | \n", "... | \n", "18846.0 | \n", "3.157300 | \n", "963.70 | \n", "457.20 | \n", "5.623900e+01 | \n", "214.510 | \n", "-304.2100 | \n", "0.157850 | \n", "1.324200e+01 | \n", "0.5 | \n", "
5 | \n", "5 | \n", "25.261 | \n", "11.2240 | \n", "309.54 | \n", "24.543 | \n", "31.958 | \n", "27.254 | \n", "2856.4 | \n", "0.000424 | \n", "2.695900e+02 | \n", "... | \n", "21319.0 | \n", "3.693200 | \n", "966.73 | \n", "309.54 | \n", "5.648800e+01 | \n", "217.230 | \n", "-390.0200 | \n", "0.129290 | \n", "1.778600e+01 | \n", "0.5 | \n", "
6 | \n", "6 | \n", "21.606 | \n", "9.6181 | \n", "236.08 | \n", "20.615 | \n", "26.775 | \n", "22.111 | \n", "2685.8 | \n", "0.000362 | \n", "2.726300e+02 | \n", "... | \n", "23721.0 | \n", "4.147900 | \n", "970.17 | \n", "236.08 | \n", "5.666900e+01 | \n", "219.140 | \n", "-475.6200 | \n", "0.108900 | \n", "2.279000e+01 | \n", "0.5 | \n", "
7 | \n", "7 | \n", "18.960 | \n", "8.4513 | \n", "192.14 | \n", "17.859 | \n", "23.153 | \n", "18.702 | \n", "2543.7 | \n", "0.000317 | \n", "2.750200e+02 | \n", "... | \n", "26050.0 | \n", "4.540600 | \n", "973.69 | \n", "192.14 | \n", "5.681200e+01 | \n", "220.630 | \n", "-560.8900 | \n", "0.093693 | \n", "2.825000e+01 | \n", "0.5 | \n", "
8 | \n", "8 | \n", "16.955 | \n", "7.5652 | \n", "162.87 | \n", "15.818 | \n", "20.479 | \n", "16.276 | \n", "2423.2 | \n", "0.000284 | \n", "2.770000e+02 | \n", "... | \n", "28311.0 | \n", "4.885500 | \n", "977.21 | \n", "162.87 | \n", "5.692900e+01 | \n", "221.870 | \n", "-645.8400 | \n", "0.081984 | \n", "3.416600e+01 | \n", "0.5 | \n", "
9 | \n", "9 | \n", "15.383 | \n", "6.8691 | \n", "141.96 | \n", "14.244 | \n", "18.422 | \n", "14.462 | \n", "2319.3 | \n", "0.000257 | \n", "2.786900e+02 | \n", "... | \n", "30505.0 | \n", "5.192300 | \n", "980.68 | \n", "141.96 | \n", "5.702800e+01 | \n", "222.920 | \n", "-730.4900 | \n", "0.072728 | \n", "4.053400e+01 | \n", "0.5 | \n", "
10 rows × 68 columns
\n", "\n", " | Ssu | \n", "Saa | \n", "Sfa | \n", "Sva | \n", "Sbu | \n", "Spro | \n", "Sac | \n", "Sh2 | \n", "Sch4 | \n", "Sic | \n", "... | \n", "Alk | \n", "NH3 | \n", "NH4 | \n", "LCFA | \n", "percentch4 | \n", "energych4 | \n", "efficiency | \n", "VFA/ALK | \n", "ACN | \n", "sampleT | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Default Configuration | \n", "7.17674 | \n", "3.21796 | \n", "54.9446 | \n", "6.39778 | \n", "8.23228 | \n", "6.08339 | \n", "1963.6 | \n", "0.00012 | \n", "48.3303 | \n", "639.764 | \n", "... | \n", "8438.52 | \n", "9.32395 | \n", "1026.69 | \n", "54.9446 | \n", "56.905 | \n", "65.228 | \n", "53.3712 | \n", "0.220453 | \n", "109.164 | \n", "25.3731 | \n", "
1 rows × 67 columns
\n", "\n", " | Ssu | \n", "Saa | \n", "Sfa | \n", "Sva | \n", "Sbu | \n", "Spro | \n", "Sac | \n", "Sh2 | \n", "Sch4 | \n", "Sic | \n", "... | \n", "Alk | \n", "NH3 | \n", "NH4 | \n", "LCFA | \n", "percentch4 | \n", "energych4 | \n", "efficiency | \n", "VFA/ALK | \n", "ACN | \n", "sampleT | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Phase 1 Configuration | \n", "80.5616 | \n", "33.4704 | \n", "7808.75 | \n", "2598.14 | \n", "4246.87 | \n", "3285.25 | \n", "9696.05 | \n", "28.5069 | \n", "7.737870e-30 | \n", "147.214 | \n", "... | \n", "60316.4 | \n", "0.048011 | \n", "1145.6 | \n", "7808.75 | \n", "3.164870e-30 | \n", "104.203 | \n", "-104.737 | \n", "0.308161 | \n", "1.202840e-17 | \n", "0.550162 | \n", "
1 rows × 67 columns
\n", "\n", " | Ssu | \n", "Saa | \n", "Sfa | \n", "Sva | \n", "Sbu | \n", "Spro | \n", "Sac | \n", "Sh2 | \n", "Sch4 | \n", "Sic | \n", "... | \n", "Alk | \n", "NH3 | \n", "NH4 | \n", "LCFA | \n", "percentch4 | \n", "energych4 | \n", "efficiency | \n", "VFA/ALK | \n", "ACN | \n", "sampleT | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Phase 2 Configuration | \n", "2.70068 | \n", "1.20723 | \n", "19.0168 | \n", "2.34856 | \n", "3.01652 | \n", "2.16597 | \n", "1125.18 | \n", "0.000045 | \n", "75.1774 | \n", "952.376 | \n", "... | \n", "21574.7 | \n", "14.7549 | \n", "1186.64 | \n", "19.0168 | \n", "58.194 | \n", "255.569 | \n", "-899.833 | \n", "0.049221 | \n", "3302.96 | \n", "5.50162 | \n", "
1 rows × 67 columns
\n", "\n", " | Ssu | \n", "Saa | \n", "Sfa | \n", "Sva | \n", "Sbu | \n", "Spro | \n", "Sac | \n", "Sh2 | \n", "Sch4 | \n", "Sic | \n", "... | \n", "Alk | \n", "NH3 | \n", "NH4 | \n", "LCFA | \n", "percentch4 | \n", "energych4 | \n", "efficiency | \n", "VFA/ALK | \n", "ACN | \n", "sampleT | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Phase1 | \n", "80.561600 | \n", "33.470400 | \n", "7808.7500 | \n", "2598.14000 | \n", "4246.87000 | \n", "3285.25000 | \n", "9696.05 | \n", "28.506900 | \n", "7.771710e-32 | \n", "147.214 | \n", "... | \n", "60316.4 | \n", "0.048011 | \n", "1145.6 | \n", "7808.7500 | \n", "3.068330e-32 | \n", "104.203 | \n", "-104.737 | \n", "0.308161 | \n", "1.216580e-18 | \n", "0.550162 | \n", "
Phase2 | \n", "0.355681 | \n", "0.132504 | \n", "19.2757 | \n", "2.37729 | \n", "3.05196 | \n", "2.19399 | \n", "1248.96 | \n", "0.000046 | \n", "7.114040e+01 | \n", "867.356 | \n", "... | \n", "17101.8 | \n", "15.289200 | \n", "1139.4 | \n", "19.2757 | \n", "6.198330e+01 | \n", "192.277 | \n", "-590.307 | \n", "0.068884 | \n", "-2.807000e+01 | \n", "6.241160 | \n", "
2 rows × 67 columns
\n", "