Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:fedebenelli/yaeos into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fedebenelli committed Dec 5, 2024
2 parents 56a3a96 + bc178b7 commit 0d9b014
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
39 changes: 22 additions & 17 deletions python/docs/source/tutorial/more_calculations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,8 @@
"ids = [chemicals.CAS_from_any(name) for name in components]\n",
"\n",
"Tc = [chemicals.critical.Tc(id) for id in ids]\n",
"Pc = [chemicals.critical.Pc(id)/1e5 for id in ids]\n",
"w = [chemicals.acentric.omega(id) for id in ids]\n",
"Pc = [chemicals.critical.Pc(id) / 1e5 for id in ids]\n",
"w = [chemicals.acentric.omega(id) for id in ids]\n",
"\n",
"z = [0.3, 0.7]\n",
"\n",
Expand Down Expand Up @@ -802,12 +802,12 @@
"\n",
"plt.plot(env[\"Ts\"], env[\"Ps\"], label=\"Envelope\")\n",
"plt.scatter(T, Psat)\n",
"plt.scatter(T, Psat+5)\n",
"plt.scatter(T, Psat-5)\n",
"plt.scatter(T, Psat + 5)\n",
"plt.scatter(T, Psat - 5)\n",
"plt.ylabel(\"P [bar]\")\n",
"plt.xlabel(\"T [K]\")\n",
"plt.show()\n",
"Psat\n"
"Psat"
]
},
{
Expand Down Expand Up @@ -838,7 +838,7 @@
"source": [
"ws = np.linspace(0, 1, 100)\n",
"\n",
"Ps = [Psat+5, Psat, Psat-5]\n",
"Ps = [Psat + 5, Psat, Psat - 5]\n",
"\n",
"for P in Ps:\n",
" tms = []\n",
Expand All @@ -852,11 +852,13 @@
"plt.ylabel(\"tm\")\n",
"plt.axhline(0, color=\"black\", linestyle=\"--\")\n",
"plt.legend(title=\"Pressure [bar]\")\n",
"plt.title(\"\"\"\n",
"plt.title(\n",
" \"\"\"\n",
" Comparison of tm values at different pressures. \n",
" It is clear that above the saturation pressure the composition z is stable.\n",
" But, below the saturation pressure the composition z is unstable and another phase appears.\n",
" \"\"\")\n",
" \"\"\"\n",
")\n",
"plt.show()"
]
},
Expand Down Expand Up @@ -894,8 +896,8 @@
"ids = [chemicals.CAS_from_any(name) for name in components]\n",
"\n",
"Tc = [chemicals.critical.Tc(id) for id in ids]\n",
"Pc = [chemicals.critical.Pc(id)/1e5 for id in ids]\n",
"w = [chemicals.acentric.omega(id) for id in ids]\n",
"Pc = [chemicals.critical.Pc(id) / 1e5 for id in ids]\n",
"w = [chemicals.acentric.omega(id) for id in ids]\n",
"\n",
"z = [0.2, 0.2, 0.6]\n",
"\n",
Expand Down Expand Up @@ -949,21 +951,24 @@
"for j, w1 in enumerate(w1s):\n",
" for i, w2 in enumerate(w2s):\n",
" w = [w1, w2, 1 - w1 - w2]\n",
" \n",
"\n",
" if w[-1] <= 0:\n",
" continue\n",
" \n",
"\n",
" tm = model.stability_tm(z=z, w=w, pressure=P, temperature=T)\n",
" if tm < minval: \n",
" if tm < minval:\n",
" w_min = w\n",
" minval = tm\n",
" tms[i, j] = tm\n",
"\n",
"plt.imshow(tms, extent=(0, 1, 0, 1), origin=\"lower\", aspect=\"auto\")\n",
"plt.contour(\n",
" tms, extent=(0, 1, 0, 1), \n",
" levels=[i/10 for i in range(-25, 25)], \n",
" origin=\"lower\",colors=\"black\")\n",
" tms,\n",
" extent=(0, 1, 0, 1),\n",
" levels=[i / 10 for i in range(-25, 25)],\n",
" origin=\"lower\",\n",
" colors=\"black\",\n",
")\n",
"\n",
"plt.scatter(z[0], z[1], color=\"red\", label=\"Test pahse\")\n",
"plt.scatter(w_min[0], w_min[1], color=\"blue\", label=\"New phase\")\n",
Expand Down Expand Up @@ -1041,7 +1046,7 @@
}
],
"source": [
"# Comparing the found w_min with the one obtained before by sweeping \n",
"# Comparing the found w_min with the one obtained before by sweeping\n",
"# the composition space\n",
"stab_analysis[\"w_min\"], w_min"
]
Expand Down
10 changes: 5 additions & 5 deletions python/yaeos/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,13 +1101,13 @@ def stability_analysis(self, z, pressure, temperature):
-------
dict
Stability analysis result dictionary with keys:
- w_min:
- w_min:
value of the test phase that minimizes
the :math:`tm` function
- tm_min:
- tm_min:
minimum value of the :math:`tm` function
- all_mins_w:
all values of :math:`w` that minimize the
- all_mins_w:
all values of :math:`w` that minimize the
:math:`tm` function
"""
(w_min, tm_min, all_mins_w) = yaeos_c.stability_zpt(
Expand All @@ -1128,7 +1128,7 @@ def stability_tm(self, z, w, pressure, temperature):
z : array_like
Global mole fractions
w : array_like
Test Phase mole fractions
Test Phase mole fractions
pressure : float
Pressure [bar]
temperature : float
Expand Down

0 comments on commit 0d9b014

Please sign in to comment.