<!-- TE10 Studio documentation: /docs/api/results -->
# Results

`Setup.solve()` returns a `Result`; `Job.results()` returns one per case. For a parametric sweep,
`result.variables` holds that case's variable values.

## Result

| Member | Returns |
|---|---|
| `s_parameters()` | [`SParameterResult`](#s-parameters): \|S\| in dB, phase in degrees, frequencies in GHz |
| `network(z0=50.0, raw=False)` | A [scikit-rf](https://scikit-rf.readthedocs.io) `Network`, with the ports' de-embedding and renormalisation applied (as the app shows them) unless `raw=True` |
| `write_touchstone(path, z0=50.0)` | Writes `.sNp` (the extension follows the port count); returns the path |
| `eigenmodes()` | `[(frequency_GHz, Q), ...]` of an eigenmode solve |
| `fields()` | [`FieldSolution`](#fields): saved field data of any solve type |
| `farfield()` | [`FarFieldResult`](#far-field): directivity, gain and realized-gain patterns |
| `rcs()` | [`RCSResult`](#radar-cross-section) of a plane-wave solve |
| `rlgc(length_m, near_ports=None, far_ports=None, z0=50.0)` | Per-metre R, L, G, C matrices of the solved line (a port at each end of each conductor; near ends first unless the port lists say otherwise, 1-based) |
| `write_rlgc_csv(path, length_m, near_ports=None, far_ports=None)` | The same, as CSV; returns the path |
| `log()` | The solver's console output, `str` |
| `folder` | The case's result folder |
| `variables` | `{name: value}` of this case (parametric sweeps) |

## S-parameters

```python
sp = result.s_parameters()
f = sp.frequencies_ghz            # numpy array, GHz
s21_db = sp.get_db(2, 1)          # numpy array, dB
s21_deg = sp.get_phase_deg(2, 1)  # numpy array, degrees
s21 = sp.get_linear_complex(2, 1) # complex numpy array
sp.available_ports()              # [(1, 1), (1, 2), (2, 1), (2, 2)]
```

Ports are numbered from 1, response first: `get_db(2, 1)` is S21. A getter returns `None` for a pair
that wasn't solved.

### As a scikit-rf network

```python
ntwk = result.network()           # skrf.Network, frequencies in Hz inside
ntwk.s_db[:, 1, 0]                # S21 in dB (0-based in scikit-rf)
ntwk.write_touchstone("filter")   # or result.write_touchstone("filter.s2p")
```

The functions in [Post-processing](/docs/api/postprocessing) take this `Network`.

## Eigenmodes

```python
for f_ghz, q in result.eigenmodes():
    print(f"{f_ghz:.4f} GHz, Q = {q:.0f}")
```

## Fields

`result.fields()` returns a `FieldSolution` for driven, eigenmode, transient or static solves.

| Member | Returns |
|---|---|
| `steps(excitation=None)` | The saved steps (frequencies, modes or times), in order |
| `nearest_step(frequency_ghz, excitation=None)` | The saved step closest to a frequency |
| `frequencies_ghz(excitation=None)` | The saved frequencies |
| `excitations()` | Excitation (port) indices with saved fields |
| `available_quantities()` | Quantity names this solution can give |
| `evaluate(quantity, step=None, phase_deg=0.0, excitation=None, boundary=None)` | A PyVista dataset with the quantity as point data named after it |
| `port_mode(port_index, step=None, phase_deg=0.0)` | The port's mode field on its own faces |
| `eigenmodes()` | `[(frequency_GHz, Q), ...]` |
| `volume(step=None)`, `boundary(step=None)` | The raw volume / boundary datasets as the solver wrote them |

Quantities include `E_magnitude` (at a phase), `E_peak`, `E_vectors`, `H_magnitude` (H = B/(μ0·μr) per
material), `H_vectors`, `Surface_current_vectors`, `Surface_charge`, `Power_flow` and energy densities;
`available_quantities()` gives the exact list for a solution.

```python
sol = result.fields()
step = sol.nearest_step(10.0)                         # 10 GHz
grid = sol.evaluate("E_magnitude", step, phase_deg=45)
print(grid.point_data["E_magnitude"].max())            # V/m
grid.save("e_10ghz.vtu")                              # open in ParaView
```

Fields are saved at the solution frequency by default; use `save_fields="all"` on the setup, or a field
monitor, for others.

## Far field

`result.farfield()` returns a `FarFieldResult` (needs a far-field setup and an open boundary).

| Member | Returns |
|---|---|
| `excitations()` | Excitation indices |
| `frequencies_ghz(excitation=None)` | Frequencies with far-field data |
| `pattern(freq_ghz=None, excitation=None)` | A `Pattern` at the nearest solved frequency (default: the first) |

`Pattern`:

| Member | Returns |
|---|---|
| `theta`, `phi` | Direction arrays (degrees) |
| `values(quantity="Directivity", component="Total")` | Linear values: `"Directivity"`, `"Gain"`, `"RealizedGain"` (dimensionless) or `"rE"` (volts); component `"Total"`, `"Theta"`, `"Phi"` |
| `peak(quantity="Directivity", component="Total")` | `(peak linear value, theta, phi)` |
| `intensity(component="Total")` | Radiation intensity U (W/sr) |
| `radiation_efficiency` | Radiated / accepted power |
| `p_rad`, `p_acc`, `p_inc` | Radiated, accepted and incident power (W) |
| `summary()` | Peak values and powers as a dict |

```python
pat = result.farfield().pattern(2.4)
d, th, ph = pat.peak("Directivity")
print(f"Peak directivity {10 * np.log10(d):.2f} dBi at theta={th:.0f}, phi={ph:.0f}")
```

## Radar cross-section

`result.rcs()` returns an `RCSResult` for plane-wave solves.

| Member | Returns |
|---|---|
| `bistatic(freq_ghz=None, wave=None, phi_cut=None)` | An `RCSCut`: `theta`, `phi`, `sigma`, `sigma_theta`, `sigma_phi` (m²) and `.dbsm`. With `phi_cut`, the θ cut at that φ (and φ + 180° as negative θ) |
| `monostatic(wave=None)` | `(frequencies_GHz, sigma_m2)` back-scatter at each wave's incidence direction |
| `frequencies_ghz(wave=None)` | |
| `wave(name_or_index=None)` | One plane wave's run |

Shielding effectiveness from E probes: `te10_studio.postprocess.rcs.shielding_effectiveness(prj.core)`.

## Monitors

`te10_studio.postprocess.monitors.results_for(prj.core, setup_name=None, excitation=None)` returns each
probe, voltage and current monitor's values against frequency. See
[Monitors and probes](/docs/api/excitations-boundaries#monitors-and-probes).

## The results folder

A project `Filter.te10` keeps solver output in `Filter.te10results/`. The `.te10` never contains results:
copying only it gives the project without them.

| Folder | Holds |
|---|---|
| `mesh/<setup>/` | `model.msh`, `adapted.mesh`, `passes/pass<n>.mesh` |
| `fields/<setup>/` | `paraview/` volume and boundary fields |
| `sparams/<setup>/` | `port-S.csv`, port voltages and currents, `terminal-*.csv` (C, L) |
| `data/<setup>/` | Other solver tables: `eig.csv`, energies, surface and far-field data |
| `logs/<setup>/` | `solve.log`, solver configurations, `convergence.json`; `failed-run/` |
| `jobs/` | Packages of jobs from `submit()` / `solve()` (one case folder each) |
