# How rfx is built

Channel: release; package: 2.2.0; source: 084b5032b7d014f12b65b4b947cf61a840970bf4

Page: https://remilab.ai/rfx/project/structure/
Source: https://github.com/bk-squared/rfx/blob/084b5032b7d014f12b65b4b947cf61a840970bf4/docs/public/project/structure.mdx

This page is for readers who want to know how rfx turns a declared model into a
result: contributors, and users who want to know which part of the code a
setting reaches. You do not need it to use rfx.

[rfx 2.0 structure: a Simulation declaration is assembled into a realized model, advanced by one shared time-step order with measurements recorded at hook points, and turned into S-parameters and far field after the run. On several devices, DFT planes, flux and far field are recorded in slab records.](https://remilab.ai/rfx/gallery/assets/structure/structure.png)

## The stages

1. **Declaration.** You describe the model on a `Simulation`: the grid, the
   materials and shapes, the sources and ports, and what to measure (`add_*`
   methods; `rfx/api/`).
2. **Model assembly.** `run()` and `forward()` both start with the same front:
   the preflight checks (`rfx/preflight/`), the assembly of the realized model,
   which is the geometry and materials as they land on the grid (`rfx/model/`),
   and the choice of solver path (`rfx/api/_dispatch.py`). What the grid
   built is what `sim.realized_geometry()` and `sim.fidelity_report()` show.
3. **Time step.** One step order advances the fields: the H update, the E
   update, the boundaries and the sources, in a fixed sequence with named
   hook points between them (`rfx/stepping/sequence.py`). The uniform-mesh and
   graded-mesh paths use it on one device. On several devices, each slab of the
   grid runs the same step, and the exchanges between slabs are attached at
   its hook points (`rfx/stepping/slab_wrap_uniform.py`,
   `rfx/stepping/slab_wrap.py`).
4. **Recording.** Before the run, rfx builds a measurement plan from your
   declarations: probes, ports, DFT planes, flux monitors, the far-field box and
   current-moment monitors (`rfx/measurement/`). On one device, the step
   records each of them at its hook points from that plan.
5. **Results.** After the run, the records become results. `run()` returns
   the S-parameters and the far-field box's DFT records in a result object
   (`rfx/measurement/`, `rfx/sparams/`); `compute_far_field` turns those records into a radiation
   pattern (`rfx/measurement/farfield.py`). `forward()` returns the time
   signals as JAX arrays, so you can differentiate them (see
   [run() and forward()](https://remilab.ai/rfx/run/run-and-forward/)).

## Where the paths still differ

On several devices, the probe and port samples come through the shared step,
but DFT planes, flux, current moments, far field and snapshots are recorded
in the slab code (`rfx/runners/_distributed_records.py`), not from the
measurement plan. The figure marks this in colour. The recorded quantities are
the same; the code that records them is not yet shared.

Paths the figure leaves out:

- A graded mesh on several devices with PMC faces runs its own slab loop
  instead of the shared step.
- Subgridding (`add_refinement` on a uniform mesh) is outside the 2.0 supported
  scope and is refused by default; it has its own step loop. See
  [solver paths](https://remilab.ai/rfx/support/#solver-paths).
- ADI time stepping has been removed. A model that asks for it is refused.
