Showcase · examples/potential_vortex_surface.lms
Double-well free-energy surface
Condensed Matter / Surfaces: 3D Ginzburg–Landau double-well free-energy landscape F(qx, qy) (pm3d depthorder), base contour projection and minimum-energy transition pathway
Loading the WebAssembly host…
What runs
The page fetches examples/potential_vortex_surface.bin, 5,182 bytes of lmcode bytecode
(sha256 829c7819acb3…), and hands it to the same lmplot.wasm every example uses.
The bytecode calls the host's Plot functions (plot.cmd, plot.data, plot.num,
plot.png …); gnuplot draws into an in-memory file system and the page shows the files the program wrote.
In SVG mode plot.png("x.png", w, h) writes x.svg with gnuplot's svg terminal; PNG mode uses lmplot's
own rasterizer and fonts, the same bytes as the native binary.
The program was compiled ahead of time from the source on the right with lmscript; the lmscript lines around the
_lmcode_ block (data generation, ${...} values, run_lmcode) ran at compile time.
# Ginzburg-Landau double-well free-energy surface F(qx, qy) with symmetry-breaking
# tilt, saddle-point transition path, and projected contours.
# Writes images/potential_vortex_surface.png (900x600).
mkdir("images");
mkdir("build");
p = _lmcode_ cli="lmplot" install="github:lmctl-ai/lmplot@v0.3.1";
# Landau free energy: F(x, y) = 0.25*(x^2 - 1.44)^2 + 0.55*y^2 - 0.12*x + 0.08*x*y^2 + 0.85
# Sample the minimum-energy transition path along y = 0 for x in [-1.35, 1.35]
let path_rows = "";
for (i in range(0, 61)) {
let x = -1.35 + 2.70 * float(i) / 60.0;
let y = 0.0;
let d = x * x - 1.44;
let fval = 0.25 * d * d + 0.55 * y * y - 0.12 * x + 0.85;
path_rows = path_rows + str(x) + " " + str(y) + " " + str(fval) + "\n";
}
plot.data("PATH", path_rows);
plot.cmd("set terminal unknown");
plot.cmd("stats $PATH using 1:3 nooutput");
let f_min = plot.num("STATS_min_y");
# Saddle on y = 0: dF/dx = x (x^2 - 1.44) - 0.12 = 0 near x = 0, solved by Newton iterations.
let xs = 0.0;
for (k in range(0, 8)) {
let g = xs * (xs * xs - 1.44) - 0.12;
let dg = 3.0 * xs * xs - 1.44;
xs = xs - g / dg;
}
let ds = xs * xs - 1.44;
let f_saddle = 0.25 * ds * ds - 0.12 * xs + 0.85;
let barrier = f_saddle - f_min;
plot.echo("global minimum F_min = " + str(f_min) + " k_B T");
plot.echo("saddle at q_x = " + str(xs) + ", barrier dF = " + str(barrier) + " k_B T");
plot.png("images/potential_vortex_surface.png", 900, 600);
plot.cmd("set encoding utf8");
plot.cmd("set label 2 'Ginzburg-Landau Free-Energy Landscape F(q_x, q_y) — Bistable Phase-Transition Barrier' at screen 0.5, 0.955 center front font ',12'");
plot.cmd("set xlabel 'Order Parameter q_x' offset -2,-1.3");
plot.cmd("set ylabel 'Transverse Mode q_y' offset 3,-1.3");
plot.cmd("set zlabel 'Free Energy F / k_B T' rotate by 90 offset -1.5,0");
plot.cmd("set xrange [-1.85:1.85]");
plot.cmd("set yrange [-1.65:1.65]");
plot.cmd("set zrange [0:2.6]");
plot.cmd("set cbrange [0.5:2.4]");
plot.cmd("set cblabel 'F(q_x, q_y) [k_B T]' offset -0.5,0");
plot.cmd("set view 40, 30, 0.98, 1.0");
plot.cmd("set size 0.9, 0.9");
plot.cmd("set origin 0.1, 0.0");
plot.cmd("set xyplane at 0.0");
plot.cmd("set samples 42, 42");
plot.cmd("set isosamples 34, 34");
plot.cmd("set pm3d at bs depthorder border lc rgb '#1e293b' lw 0.2");
plot.cmd("set contour base");
plot.cmd("set cntrparam levels incremental 0.65, 0.20, 2.25");
plot.cmd("unset clabel");
plot.cmd("set palette defined (0 '#0f172a', 0.22 '#1d4ed8', 0.48 '#06b6d4', 0.72 '#f59e0b', 1 '#dc2626')");
plot.cmd("unset key");
let info = plot.str("sprintf('Global minimum: q_x = +1.22 (F = %.2f k_B T)\nMetastable well: q_x = -1.18 (ΔF = +0.29 k_B T)\nBarrier from the global minimum: ΔF‡ = %.2f k_B T\nat the saddle q = (%.3f, 0)\nRed: minimum-energy path along q_y = 0', " + str(f_min) + ", " + str(barrier) + ", " + str(xs) + ")");
plot.cmd("set label 1 '" + info + "' at screen 0.015, 0.89 left front boxed noenhanced font ',9'");
plot.cmd("F(x,y) = 0.25*(x**2 - 1.44)**2 + 0.55*y**2 - 0.12*x + 0.08*x*y**2 + 0.85");
plot.cmd("set multiplot");
plot.cmd("splot F(x,y) with pm3d notitle");
# pm3d is drawn after lines, so the path goes in a second layer with the same view and ranges.
plot.cmd("unset border; unset xtics; unset ytics; unset ztics; unset colorbox; unset pm3d; unset contour; unset label; unset title; unset xlabel; unset ylabel; unset zlabel");
plot.cmd("splot $PATH using 1:2:($3+0.03) with lines lw 4.4 lc rgb '#ffffff' notitle, $PATH using 1:2:($3+0.03) with lines lw 2.6 lc rgb '#e11d48' notitle, $PATH using 1:2:(0) with lines lw 2.0 dt 2 lc rgb '#e11d48' notitle");
plot.cmd("unset multiplot");
plot.close();
end _lmcode_
r = run_lmcode(p);
assert(r.ok, json_stringify(r));
println("wrote images/potential_vortex_surface.png");