Skip to main content

simpok

High level python API for Phase field simulation of phase-ordering kinetics.

Implemented: Dimensionless CHC, TDGL, and SDSD solvers, finite differences in space and explicit Euler in time.

Install

pip install simpok

Python 3.10+. The Mojo toolchain arrives as a dependency — there is nothing else to install, and no compiler to set up by hand.

The first import simpok takes about 20 seconds. It is compiling the Mojo sources for your machine; the result is cached and every later import is instant. It recompiles only when the package is upgraded.

Quick start

from simpok import TDGL

sim = TDGL().ic(seed=0)
snaps, meta = sim.run(steps=90000, nevery=1000)

print(snaps.shape)          # (90, 256, 256)
print(meta["backend"])      # 'gpu' or 'cpu'
print(meta["times"][-1])    # 9000.0

run returns a Result — a named tuple of snaps (a (nsnap, ny, nx) NumPy array) and meta (a dict of every parameter used, plus times, backend, device and elapsed).

Conserved dynamics works the same way:

from simpok import CHC

snaps, meta = CHC().ic(seed=0, psi0=-0.4).run(steps=50000, nevery=500)

And with a wall that prefers one component:

from simpok import SDSD

sim = SDSD(nz=256, nx=512, eps=0.041)
snaps, meta = sim.ic(seed=0, psi0=-0.4).run(steps=80000, nevery=2000)

profile = snaps.mean(axis=2)   # laterally averaged depth profile, (nsnap, nz)

Check what you're running on:

from simpok import get_device

d = get_device()
print(d)        # Device(available=True, name='NVIDIA RTX A5000', reason=None, kind='gpu')
print(d.kind)   # 'gpu' or 'cpu' — pass it straight back as device=

The models

TDGL — nonconserved scalar order parameter (Model A).

∂ψ/∂t = ψ − ψ³ + h + ∇²ψ + θ

CHC — conserved scalar order parameter (Model B).

∂ψ/∂t = −∇²(ψ − ψ³ + ∇²ψ) + ∇·θ

SDSD — surface-directed spinodal decomposition. The same conserved dynamics in contact with a wall at z = 0 that prefers one component: the bulk phase separates while the wall is wetted, and the two processes interfere. The result is a layered composition profile — wetting layer, depletion layer, then bulk — that propagates away from the wall.

∂ψ/∂t = −∇²(ψ − ψ³ + ½∇²ψ − V(z)) + ∇·θ                    z > 0

h₁ + gψ + γ ∂ψ/∂z = 0                                      at z = 0
∂/∂z(−ψ + ψ³ − ½∇²ψ + V) = 0                               at z = 0

with the long-ranged wall potential V(z) = −V₀/zⁿ (cut off at −V₀ for z ≤ 1).

API

TDGL(ny=256, nx=256, dx=1.0, dt=0.1, h=0.0, eps=0.0, dtype=np.float64, device=None)
CHC (ny=256, nx=256, dx=1.0, dt=0.01, eps=0.0, dtype=np.float64, device=None)
SDSD(nz=256, nx=256, dx=1.0, dt=0.03, h1=0.8, g=-0.4, gamma=0.4, v0=None, n=4,
     potential=None, eps=0.0, dtype=np.float64, device=None)

The wall potential does not have to be that power law. potential= takes any function of depth (or a ready-made array), evaluated once on sim.z and stored as sim.V:

SDSD(potential=lambda z: -0.8 * np.exp(-z / 3.0))        # short-ranged well
SDSD(potential=lambda z: np.where(z <= 5.0, -0.8, 0.0))  # square well
SDSD(potential=np.zeros(256))                            # no potential at all

Hardware notes

  • Supported Device — GPU (AMD, NVIDIA, APPLE) and CPU

License

MIT — see LICENSE.

Metadata

Release files for simpok 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simpok 0.2.0
File Size Uploaded
simpok-0.2.0.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simpok 0.2.0
File Interpreter ABI Platform
simpok-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.8 kB

Release files / simpok-0.2.0.tar.gz

Download URL simpok-0.2.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7f3d5b5101aa3b5ed7ce55da1e2e7d5cd4942243f7045f5f4bb598b8c05a7c7a
BLAKE2b-256 checksum
How to use checksums
df3e7c2aa105f641c2ec3966aa69d4660b9a6026d1807550e1b54004fcf706b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / simpok-0.2.0-py3-none-any.whl

Download URL simpok-0.2.0-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2751f63e01f940dd685fb903c3351d3c2d6fd701cd6e0015736601a27c63ffde
BLAKE2b-256 checksum
How to use checksums
cf93318297621a56449540cfc74f6e75a3a79ce692375eca7d58dcc9cfbe932d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

1.0.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page