Recipes

Examples & recipes

Seven hand-checked recipes, one per physics domain plus reporting. Each recipe illustrates what the platform computes for that domain.

⚠ The cf.* code on this page illustrates the server‑side engine API. The cufemlab solver engine runs on the GPU server and is not installed in your notebook, so import cufemlab raises ModuleNotFoundError. These recipes show what the platform computes. To actually run an analysis from your Jupyter session, use the installed cufemlab_client SDK — see the runnable example in Motor workflow.

Runnable right now (zero setup)

These run as‑is in any Jupyter cell — pure Python standard library, no API key, no upload, no GPU. They reproduce the closed‑form references the platform validates against, and each returns the standard result dictionary.

Eddy‑current skin depth (electromagnetics)

# Proprietary and confidential. Copyright Secrotec / Eba Turan. All rights reserved.
import math, json

def skin_depth(freq_hz=50.0, sigma_s_per_m=2.0e6, mu_r=1000.0):
    """delta = 1 / sqrt(pi * f * mu * sigma). Jackson, Classical Electrodynamics, Ch. 8."""
    mu0 = 4.0 * math.pi * 1e-7
    delta = 1.0 / math.sqrt(math.pi * freq_hz * mu_r * mu0 * sigma_s_per_m)
    return {"ok": True, "phase": "A/J", "example": "eddy-current skin depth",
            "method": "closed-form EM skin depth",
            "reference": "Jackson, Classical Electrodynamics, Ch. 8",
            "verdict": "ANALYTICAL_CPU_OK",
            "metrics": {"freq_hz": freq_hz, "skin_depth_mm": round(delta * 1e3, 4)},
            "notes": ["pure stdlib math; no API key, no file, no GPU"]}

print(json.dumps(skin_depth(), indent=2))

Rotating‑disk burst safety factor (mechanics)

# Proprietary and confidential. Copyright Secrotec / Eba Turan. All rights reserved.
import math, json

def rotating_disk_safety(rpm=10000.0, R=0.10, rho=7700.0, nu=0.29, sigma_yield=250e6):
    """Solid spinning-disk peak hoop stress + burst-speed safety factor.
    Timoshenko and Goodier, Theory of Elasticity, Sec. 73."""
    omega = 2.0 * math.pi * rpm / 60.0
    sigma_hoop_max = (3.0 + nu) / 8.0 * rho * omega**2 * R**2
    return {"ok": True, "phase": "C", "example": "rotating-disk burst safety factor",
            "method": "closed-form solid-disk elasticity",
            "reference": "Timoshenko and Goodier, Theory of Elasticity, Sec. 73",
            "verdict": "ANALYTICAL_CPU_OK",
            "metrics": {"rpm": rpm, "sigma_hoop_max_MPa": round(sigma_hoop_max / 1e6, 3),
                        "safety_factor": round(sigma_yield / sigma_hoop_max, 2)},
            "notes": ["pure stdlib math; runs instantly"]}

print(json.dumps(rotating_disk_safety(), indent=2))

1‑D steady conduction slab (thermal)

# Proprietary and confidential. Copyright Secrotec / Eba Turan. All rights reserved.
import json

def slab_conduction(k=45.0, area_m2=0.01, thickness_m=0.02, T_hot=120.0, T_cold=40.0):
    """1-D steady Fourier conduction: q = k A (T_hot - T_cold) / L. Incropera, Ch. 3."""
    q = k * area_m2 * (T_hot - T_cold) / thickness_m
    R = thickness_m / (k * area_m2)
    return {"ok": True, "phase": "B", "example": "1-D steady slab conduction",
            "method": "Fourier law closed form",
            "reference": "Incropera, Fundamentals of Heat and Mass Transfer, Ch. 3",
            "verdict": "ANALYTICAL_CPU_OK",
            "metrics": {"heat_flow_W": round(q, 3), "thermal_resistance_K_per_W": round(R, 4)},
            "notes": ["pure stdlib; no deps"]}

print(json.dumps(slab_conduction(), indent=2))

Engine‑API recipes (illustrative)

The recipes below illustrate the server‑side engine API (see the banner above) — they are not runnable locally. To run the real platform from your notebook, use the cufemlab_client SDK with a real API key (create one under API keys in the app; the literal cfm_... placeholder raises AuthenticationError).

1. Magnetostatic 2-D on GPU

import cufemlab as cf

mesh = cf.mesh.rectangular(nx=128, ny=128, lx=0.20, ly=0.20)
mats = cf.materials.load("m19_steel.yaml")

sol = cf.solvers.Magnetostatic2D(mesh, mats)
A   = sol.solve(current_density=1e6, boundary_conditions="dirichlet_zero")
B   = sol.flux_density()

verdict = sol.benchmark(reference="wang_2018")
print(verdict)
# PASS  B_peak = 0.7833 T  err 2.1%  tol 5%  cuda_event = 3.4 ms

2. Nonlinear B-H against TEAM benchmark

sol = cf.solvers.Magnetostatic2D(mesh, mats, nonlinear=True)
sol.set_bh_curve(mats.bh_curve)

A = sol.solve_picard(tol=1e-6, max_iter=80)
verdict = sol.benchmark(reference="team_problem_x")
print(verdict.error, verdict.tolerance, verdict.passed)

3. Transient thermal — 1-D analytical match

mesh = cf.mesh.line(n=200, length=0.10)
mats = cf.materials.load("aluminium.yaml")

sol = cf.solvers.TransientThermal(mesh, mats, dt=0.005, steps=1000)
T   = sol.solve(T0=293.0, source=0.0, boundary={"left":373.0, "right":293.0})

verdict = sol.benchmark(reference="carslaw_section_2_3")
print(verdict)
# PASS  L2 error = 1.4%  tol 5%

4. Conjugate heat (solid/fluid)

sol = cf.solvers.ConjugateHeat(mesh, mats)
T   = sol.solve(
    flow_velocity = 0.02,        # m/s
    inlet_temp    = 293.0,
    wall_heat     = 5e3,         # W/m^2
)

verdict = sol.benchmark(reference="incropera_ch5")
print(verdict)
# PASS  Nusselt err 3.8%  tol 5%

5. Linear elasticity on GPU — rotor stress

mesh = cf.mesh.disc(nr=120, ntheta=120, r_inner=0.04, r_outer=0.10)
mats = cf.materials.load("m19_steel.yaml")

sol = cf.solvers.LinearElasticity(mesh, mats)
u, sigma = sol.solve(
    centrifugal_omega = 2*3.14159*100,   # rad/s -> rotor at 6000 rpm
    boundary          = {"inner": "fixed"},
    use_gpu           = True,
)

verdict = sol.benchmark(reference="timoshenko_section_73")
print("safety factor:", sol.safety_factor(mats.mechanical.yield_stress))
# safety factor: 46.16   verdict: GPU_PASS   cuda_event = 6.2 ms

6. Stokes lid-driven cavity

mesh = cf.mesh.rectangular(nx=129, ny=129, lx=1.0, ly=1.0)
mats = cf.materials.load("water_293k.yaml")

sol = cf.solvers.StokesLidCavity(mesh, mats)
psi, omega = sol.solve(lid_velocity=1.0)

verdict = sol.benchmark(reference="burggraf_1966")
print(verdict)
# PASS  psi_min err 4.2%  tol 5%

7. Sign and ship the report

motor  = cf.workflows.IntegratedMotorWorkflow(materials="materials/m19_steel.yaml")
result = motor.run(stator_od=0.20, current_a=12.0, slot_temp_k=393)

report = cf.reporting.Report(result, output_dir="reports/customer_xyz/")
report.write_pdf()
report.write_json()
report.write_markdown()

print("Signed PDF:", report.pdf_path)
print("Provenance hash:", result.provenance)
What ships in reports/. Each report carries every sub-verdict, the cited reference for each check, the declared tolerance, the measured error, the CUDA event timing (if any), and the SHA-256 provenance hash of inputs + materials + code. Audit-ready.

Run the full suite

python scripts/run_full_platform_integration.py
# OVERALL: PASS   suites: 18/18 PASS   checks: 290 PASS / 0 FAIL   gpu suites: 6   duration: 35.1 s