Flow fields and QRAM data¶
oracq.applications.flow_data
Classical Roe Riemann local updates and a queryable QRAM data structure; no matrix element table is stored.
- class oracq.applications.flow_data.MemoryPatch(version, changes, recomputed_faces=(), recomputed_cells=())[source]¶
Bases:
objectImmutable write record returned by an update.
- Variables:
version (int) – Storage version after applying the writes; unchanged when nothing is actually written.
changes (dict[str, dict[int, int]]) – Storage items that actually changed, mapping addresses to integer values by bank name.
recomputed_faces (tuple[int, ...]) – Face indices whose Riemann fluxes were recomputed by this update; empty for direct storage-layer writes.
recomputed_cells (tuple[int, ...]) – Cell indices whose residuals were recomputed by this update; empty for direct storage-layer writes.
- version¶
- changes¶
- recomputed_faces = ()¶
- recomputed_cells = ()¶
- class oracq.applications.flow_data.QRAMStore[source]¶
Bases:
objectVersioned multi-bank classical integer storage serving as the data source of a queryable QRAM.
- Variables:
banks – Storage contents organized by bank name; each bank maps addresses to integer values.
version – The version number; incremented once per apply call that produces actual writes.
- banks¶
- version¶
- apply(changes)[source]¶
Apply a batch of updates and return the record of writes that actually happened.
Items equal to the current stored value (unwritten addresses count as zero) are not recorded in the result; the version increments when actual writes exist.
- Parameters:
changes – Writes to apply, mapping addresses to integer values by bank name.
- Returns:
The post-write version and actual writes, excluding recomputation ranges.
- Return type:
- snapshot()[source]¶
Return an independent copy of all bank contents.
- Returns:
A copy of each bank’s address-to-value mapping; modifying the snapshot does not affect the store.
- Return type:
dict
- materialize_changed(patch, factory)[source]¶
PySparQ currently exposes no write interface: only the bank objects that changed are rebuilt, with no claim of physical in-place writes.
- Parameters:
patch – The incremental write record; only banks touched by its
changesare rebuilt.factory – Factory that builds a host-side bank object from a bank name and its address-to-value mapping.
- Returns:
Mapping of rebuilt bank names to new bank objects; unchanged banks are absent.
- Return type:
dict[str, object]
- oracq.applications.flow_data.riemann_flux(left, right, *, gamma=1.4, entropy_delta=0.125)[source]¶
Compute the classical Roe approximate Riemann flux on a single face.
The eigenvector matrix
Ris built from the Roe average of the left and right conserved states; the eigenvaluesu-c,uandu+ctake entropy-fixed absolute values, and|A| = R*diag(|lambda|)*R**-1is assembled into the flux formula.- Parameters:
left – The conserved variable triple of the left cell: density, momentum then energy.
right – The conserved variable triple of the right cell, ordered as in
left.gamma – Ratio of specific heats.
entropy_delta – Harten entropy fix threshold; eigenvalues with smaller absolute value use the smoothed value instead.
- Returns:
The numerical flux of the three conserved components
0.5*(f_l+f_r) - 0.5*|A|*(u_r-u_l).- Return type:
tuple
- Raises:
ValidationError – Density non-positive on either side, or the Roe-averaged squared sound speed non-positive.
- class oracq.applications.flow_data.RoeFlowData(states, *, fmt=None, gamma=1.4, entropy_delta=0.125, angle_width=10, dx=1.0)[source]¶
Bases:
objectPeriodic one-dimensional grid; three components padded to four; sign leaves plus a squared-norm and angle binary tree.
- states¶
- fmt¶
- gamma¶
- delta¶
- angle_width¶
- dx¶
- n¶
- store¶
- fluxes¶
- residuals¶
- tree¶
- last_patch¶
- update(changed, *, initialize=False)[source]¶
Perform one local update with the given new cell values and write it into the QRAM store.
Only the Riemann fluxes on affected faces (including periodic neighbors) and the residuals of their adjacent cells are recomputed; the conserved-variable, sign, right-hand-side squared-norm tree and angle banks are maintained in sync.
- Parameters:
changed – Mapping of cell indices to new conserved variable triples.
initialize – When True, residuals are recomputed for all cells; used only for the initial fill at construction.
- Returns:
The actual writes and recomputation ranges of this call, also saved as
last_patch.- Return type:
- Raises:
ValidationError – Cell index out of range or component count not equal to three.
- property rhs_norm¶
L2 norm of the residual field, i.e. the square root of the squared-sum tree root.