electrostatics._mesh_plan — automatic mesh planning
tempura/electrostatics/_mesh_plan.py turns a finalized device into a
mesh plan: the master lattice, the effective per-layer spacings, the outer
simulation box, the realized stack bounding box, and an ordered list of
refinement zones. It is internal — build_problem(...) calls it — but it is
where every commensurability rule that governs the mesh lives.
The master lattice
All mesh spacings are anchored to one finest lattice, the master lattice, taken from the quantum region's resolution. A spacing \(\mathbf r = [d_x, d_y, d_z]\) is admissible only if it is an integer multiple of the master \(\mathbf m\) component-wise:
The quantum region must be the finest mesh, so any non-quantum layer requesting a finer spacing is rejected, and coarser requests are rounded up to the next master multiple (with a warning) so the lattices stay nested.
Two more rules keep the geometry commensurate with the master lattice:
- Layer thickness vs. the Z lattice. Every layer thickness must be an
integer multiple of the master \(d_z\) (validated in
Device.finalize()), so layer interfaces land exactly on mesh planes \(z = k\,d_z\) instead of drifting between them. A non-conforming thickness fails early, naming the layer, rather than producing an empty refinement zone deep insidebuild_problem(). - Device span vs. coarse spacing. Each layer's in-plane \(d_x, d_y\) must
evenly tile the device
length/width(_validate_span_divides_layer_resolutions), so an aligned box never clips a partial cell at the high \(+x/+y\) edge.
One globally anchored lattice
Every box used for the simulation domain, the refinement zones, and the device
halo is snapped to a lattice anchored at the device corner \((-L/2, -W/2, 0)\),
and every mesh pattern shares one point anchor — global_point_anchor(...),
half a master cell above that corner. Because each zone spacing is an integer
multiple of the master and every pattern is anchored at the same point, each
coarse lattice is a structural sublattice of the master: its points are a
subset of the master's. This has three consequences the old per-zone phase
search had to fight for:
- there is no phase to choose — the fine grid is fixed by the master lattice
alone, so it is independent of
vacuum_scaleand the exported plane coordinates are reproducible across domain settings; - zones of different spacing meet without hanging nodes; and
pescado'srefine_mesh(region, pattern=...)fills each zone directly from the anchored pattern, so Tempura never enumerates candidate offsets.
The outer vacuum lattice
The simulation box extends into vacuum so the grounded boundary sits far from the device. Its spacing must stay commensurate with every resolved layer, so it is built from the per-axis least common multiple of the layer multiples,
then scaled up by vacuum_resolution_scale to coarsen the far field. The vacuum
extent itself is a multiple of the device size set by vacuum_scale.
Refinement zones
Zones are emitted in a deterministic order (_zone_sort_key) so meshes are
reproducible: a coarse device halo around the whole stack first, then the
finer quantum-region slab. Each zone records the region to refine, its target
resolution, and whether it defines the protected interior that the grounded
outer shell must not overlap.
Two domain modes exist. With vacuum_scale > 0 the planner builds an outer
vacuum box plus a device halo (outer_vacuum mode); with vacuum_scale == 0
it wraps the stack tightly and meshes only the stack (tight_stack_bbox mode).
API
_mesh_plan
Automatic mesh planning for Tempura's active electrostatics pipeline.
global_point_anchor(device, master)
Return the single mesh-point anchor shared by every pattern.
Every automatic pattern is a Rectangular.constant lattice whose spacing
is an integer multiple of master. Anchoring all of them at this one
point makes each coarse lattice a structural sublattice of the master
lattice: refinement zones cannot land on incommensurate phases, so the
realized fine grid is independent of vacuum_scale and no hanging nodes
appear where zones of different spacing meet.
The anchor is offset half a master cell from the box-aligned corner origin so that mesh points sit inside the simulation box rather than exactly on its faces, matching the master lattice's own half-cell inset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Device
|
Finalized device whose XY span fixes the corner origin. |
required |
master
|
ndarray
|
Finest global |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The shared |
Source code in tempura/electrostatics/_mesh_plan.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
interface_eps(master)
Return the shared-interface exclusion band, relative to the Z lattice.
Layer thicknesses are required to be integer multiples of master[2]
(see :meth:Device.finalize), so every shared interface lands exactly on a
mesh plane z = k * master[2]. The exclusion band only needs to be a tiny
fraction of that spacing to drop points sitting on the plane while keeping
the next plane up. Scaling with master keeps the band meaningful
regardless of the (unspecified) physical unit of device.grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
master
|
ndarray
|
Finest global |
required |
Returns:
| Type | Description |
|---|---|
float
|
Absolute exclusion band in the same units as the mesh coordinates. |
Source code in tempura/electrostatics/_mesh_plan.py
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
protected_inner_bbox(mesh_plan)
Return the bbox the outer Dirichlet shell must leave untouched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh_plan
|
MeshPlan
|
Mapping returned by :func: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Bounding box for the finest protected interior region when one exists, |
ndarray
|
otherwise the full realized stack bounding box. |
Source code in tempura/electrostatics/_mesh_plan.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
resolve_auto_vacuum_resolution(layer_resolutions, master, *, resolution_scale=1.0)
Choose one outer-vacuum lattice commensurate with every layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_resolutions
|
Sequence[ndarray]
|
Effective per-layer |
required |
master
|
ndarray
|
Finest global master lattice. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Coarse outer-vacuum spacing that remains an integer multiple of every |
ndarray
|
resolved layer spacing. |
Source code in tempura/electrostatics/_mesh_plan.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
resolve_master_lattice(device, layers)
Resolve the finest global lattice from the quantum region layer resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Device
|
Finalized device whose XY lattice defines the in-plane master spacing. |
required |
layers
|
Sequence[Layer]
|
Finalized device layers in stack order. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Finest commensurate |
ndarray
|
anchor. |
Source code in tempura/electrostatics/_mesh_plan.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
resolve_mesh_plan(device, layers, *, vacuum_scale, vacuum_resolution_scale=8.0, dirichlet_boundary=True)
Resolve the active automatic mesh plan for one finalized device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
Device
|
Finalized device whose geometry should be meshed. |
required |
layers
|
Sequence[Layer]
|
Finalized layers in stacking order. |
required |
vacuum_scale
|
float
|
Outer vacuum size multiplier relative to device size. |
required |
vacuum_resolution_scale
|
float
|
Coarsening factor applied to the automatic outer-vacuum lattice spacing. |
8.0
|
dirichlet_boundary
|
bool
|
Whether build_problem() will add the optional grounded Boundary region. |
True
|
Returns:
| Type | Description |
|---|---|
MeshPlan
|
Plain mapping with the resolved master lattice, effective per-layer |
MeshPlan
|
resolutions, simulation box, realized stack bbox, and ordered |
MeshPlan
|
automatic refinement zones. |
Source code in tempura/electrostatics/_mesh_plan.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 | |