1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! The [`Grid`] trait: topology, blocks, and block views.
//!
//! **Design decisions:**
//!
//! - **Dimension is an associated fact, not a trait parameter.** Concrete grids
//! carry `const D: usize`; the trait exposes dimension through `DIM` and
//! through associated `Point`/`Index` types (`[f64; D]`, `[isize; D]` for
//! Cartesian). Generic solver code never needs `D`; only concrete stencils
//! do, and they are written per grid family anyway.
//!
//! - **The grid is a collection of blocks**. Block identity is a flat
//! [`BlockId`]; refinement level and geometry are queried per block so a
//! uniform grid (one level) and an adaptive grid (many levels) present the
//! same execution surface.
//!
//! - **Views are grid-associated types (GATs).** Storage hands the grid a raw
//! `&[T]` slab for one block; the grid wraps it in a typed view that knows
//! the block's interior extent and ghost width. This is what makes "storage
//! separate from views" zero-cost: the view is a slice + a few integers,
//! constructed inline, and index arithmetic monomorphizes into the stencil
//! loop. Stencils are written against `G::View<'_, T>`, so an AMR grid can
//! hand out views that transparently handle coarse–fine interpolation later
//! without any stencil signature changing.
//!
//! - **Grids own no field data.** They translate (block, index) into offsets
//! and coordinates; storage lives in [`crate::core::state::State`].
use crateScalar;
use Debug;
/// Flat identifier of a block.
///
/// Stable for the lifetime of a grid; an AMR regrid produces a *new* grid
/// (and a state migration), never mutates one in place — which is what
/// keeps `Grid: Sync` trivially sound.
;
/// Spatial topology and block-structured layout.