Toy Example

Assorted overview of some more niche functionality.

Prelude

from importlib import reload as re
import landau as ld
import landau.interpolate as ldi
import landau.calculate as ldc
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

Toy Example

l1 = ld.TemperatureDependentLinePhase(
    "l0", fixed_concentration=0, temperatures=[1, 750, 1000], free_energies=[2, 1.80, 1.00], interpolator=ldi.PolyFit(3)
)
l2 = ld.TemperatureDependentLinePhase(
    "l1", fixed_concentration=1, temperatures=[1, 750, 1000], free_energies=[3, 2.80, 2.00], interpolator=ldi.PolyFit(3)
)
l3 = ld.TemperatureDependentLinePhase(
    "l2",
    fixed_concentration=0.5,
    temperatures=[1, 750, 1000],
    free_energies=[2.45, 2.00, 1.42],
    interpolator=ldi.PolyFit(3),
)
liq = ld.IdealSolution("liquid", l1, l2)
rliq = ld.RegularSolution("liquid", [l1, l3, l2])
s1 = ld.TemperatureDependentLinePhase(
    "s0", fixed_concentration=0, temperatures=[1, 750, 1000], free_energies=[1.9, 1.6, 1.2], interpolator=ldi.SGTE(2)
)
s2 = ld.TemperatureDependentLinePhase(
    "s1", fixed_concentration=1, temperatures=[1, 750, 1000], free_energies=[2.9, 2.6, 2.2], interpolator=ldi.SGTE(2)
)
s3 = ld.TemperatureDependentLinePhase(
    "s3",
    fixed_concentration=0.4,
    temperatures=[1, 750, 1000],
    free_energies=np.array([2.4, 1.85, 1.45]) - 0.05,
    interpolator=ldi.SGTE(3),
)
sol = ld.IdealSolution("solid", s1, s2)
Ts = np.linspace(50, 1000, 100)
s3.check_interpolation()
l3.check_interpolation()
plt.legend()
/home/ponder/science/phd/dev/landau/landau/interpolate.py:110: OptimizeWarning: Covariance of the parameters could not be estimated
  parameters, *_ = so.curve_fit(G_calphad, x, y, p0=[0] * self.nparam)
<matplotlib.legend.Legend at 0x7fabfc749250>
../_images/5701c56591fc7afd5189cae78b5fbbc0eaae617a000c2b86007b2bbe81c76921.png
c = np.linspace(0, 1, 75)[1:-1]
mu = 1 + ld.phases.kB * 4000 * np.log(c / (1 - c))
plt.plot(mu, liq.concentration(1000, mu))
plt.plot(mu, rliq.concentration(1000, mu))
[<matplotlib.lines.Line2D at 0x7fab5c928dd0>]
../_images/355cf032c5f6a5bc72c935dd6831efb634ceedd515d0e4bd2b5a2a3150751d39.png
rliq.check_interpolation(750)
../_images/71d04530eac6b8d4985fa8ce086db7c0edb75db704bdb17fb2e24446efdeb109.png
# df = ppdt.calc_phase_diagram([liq, s1, s2], np.linspace(50, 1000), mu, refine=True)
from importlib import reload as re

re(ld.phases)
re(ld)
<module 'landau' from '/home/ponder/science/phd/dev/landau/landau/__init__.py'>
df = ldc.calc_phase_diagram([rliq, sol, s3], np.linspace(500, 1000, 50), mu, refine=True)
sns.scatterplot(data=df.query("stable"), x="c", y="T", hue="phase")
<Axes: xlabel='c', ylabel='T'>
../_images/a87d5d9e09ce849f42144afedbafc14e950e81ec6ddaf936f1bc2635f4fa1196.png
sns.relplot(
    data=df.query("border"),
    x="mu",
    y="T",
    hue="phase",
    col="phase",
    style="refined",
)
<seaborn.axisgrid.FacetGrid at 0x7fab5c9bed50>
../_images/446074b3f065b1b7518e8803715e84e3218d7e5100284dc4d8643a251362b7b6.png
sns.relplot(
    data=df.query("border and 850<T<920 and c<.1"),
    x="c",
    y="T",
    hue="phase",
    # col='phase',
    style="refined",
)
<seaborn.axisgrid.FacetGrid at 0x7fab5c637c50>
../_images/5793e3e25918260b84e21da47d51e8905a015ad781b85e3d7e5e61980e7c61e5.png
sns.relplot(
    data=df.query("border and 850<T<920 and c<.1"),
    x="mu",
    y="T",
    hue="phase",
    # col='phase',
    style="refined",
)
<seaborn.axisgrid.FacetGrid at 0x7fab5c695cd0>
../_images/82501d8f39b1a171374922fc6da12891bf36d79c31eab78ce243a532e4fc763e.png
sns.relplot(
    data=df.query("border and 820<T<880 and 1.2<mu<1.4"),
    x="mu",
    y="T",
    hue="phase",
    # col='phase',
    style="refined",
)
<seaborn.axisgrid.FacetGrid at 0x7fab5c6e6d50>
../_images/074b16f088d515a4e551f2c1dc8f797749618c93726a6a25999779e17d812c48.png
ld.plot_phase_diagram(df)
plt.axhline(714.285714, zorder=10)
# plt.ylim(750, 1000)
<matplotlib.lines.Line2D at 0x7fab5c6ff7d0>
../_images/461e5f7fdfa851536fc7cf3aab75f9373cf8b8e72d8e719ea1eec04c30b46430.png
ld.plot_phase_diagram(df, poly_method='tsp', tielines=True)
plt.axhline(714.285714, zorder=10)
# plt.ylim(750, 1000)
<matplotlib.lines.Line2D at 0x7fabe2a0acd0>
../_images/c571a6e965c392f7936aee399e8763cc463123bc18f9d549621ae70ac43b2dd5.png
p = ld.InterpolatingPhase(
    "test",
    [
        ld.LinePhase("s0", 0.65, 2.50, 0.00005),
        ld.LinePhase("s0", 0.75, 2.40, 0.00010),
        ld.LinePhase("s0", 0.85, 2.50, 0.00005),
    ],
    num_coeffs=3,
    num_samples=250,
)
p.check_interpolation(750)
plt.ylim(1.8, 3)
(1.8, 3.0)
../_images/b67435753aa53d6f28031968ad65b3a4be12aae60b42ba45ca8e106840c4d9ed.png
c = np.linspace(0, 1, 50)[1:-1]
mu = 1 + ld.phases.kB * 4000 * np.log(c / (1 - c))
%%time
df = ldc.calc_phase_diagram([rliq, sol, p, s3], np.linspace(250, 1000, 50), mu, refine=True)
CPU times: user 24.3 s, sys: 72.6 ms, total: 24.3 s
Wall time: 24.6 s
sns.scatterplot(data=df.query("stable"), x="c", y="T", hue="phase")
<Axes: xlabel='c', ylabel='T'>
../_images/f3d58e0f1ac8c3d40bdf2fc95a2869f42743873e3441e6db263d3cc91a789f1a.png
%%time
ld.plot_phase_diagram(df, poly_method='tsp', tielines=True)
CPU times: user 4.43 s, sys: 191 ms, total: 4.62 s
Wall time: 4.63 s
../_images/26e972f29194b4b8a581b87ff5d9fee3774e22693c0d2150ab8caadcebb60f26.png