<!-- TE10 Studio documentation: /docs/api/rftools-materials -->
# RF tools and material library

The app's **Tools › Macros** are plain functions. **All values are SI here** (metres, hertz, ohms), not
project units.

```python
from te10_studio.rftools import tlines, builders, ports, catalog
```

## Calculators: `tlines`

| Function | Returns |
|---|---|
| `microstrip(w, h, er, t=0.0, f=None)` | `LineResult` (Hammerstad–Jensen with strip thickness; Kirschning–Jansen dispersion at `f`) |
| `microstrip_width(z0, h, er, t=0.0)` | Width for an impedance, m |
| `stripline(w, b, er)` | `LineResult` of a centred zero-thickness strip (Cohn) |
| `stripline_width(z0, b, er)` | m |
| `cpw(w, s, h, er, grounded=False)` | `LineResult` of coplanar waveguide (conformal mapping) |
| `cpw_width(z0, s, h, er, grounded=False)` | m |
| `coax(d_inner, d_outer, er=1.0)` | `LineResult` |
| `coax_outer_diameter(z0, d_inner, er=1.0)` | m |
| `coax_cutoff_te11(d_inner, d_outer, er=1.0)` | Hz |
| `rect_waveguide_modes(a, b, er=1.0, count=8)` | `list[Mode]` (`name`, `fc` in Hz), lowest first |
| `circ_waveguide_modes(d, er=1.0, count=8)` | `list[Mode]` |
| `waveguide_mode(fc, f, er=1.0)` | `(beta_rad_per_m, guided_wavelength_m, te_wave_impedance_ohm)`; `ValueError` below cutoff |
| `skin_depth(f, sigma, mu_r=1.0)`, `surface_resistance(f, sigma, mu_r=1.0)` | m, Ω/sq |
| `wavelength(f, er=1.0, mu_r=1.0)` | m |

`LineResult` has `z0` (Ω), `eps_eff`, `wavelength(f)` and `electrical_length_deg(length, f)`.

```python
w = tlines.microstrip_width(50, h=1.6e-3, er=4.4)          # 0.00306 m
line = tlines.microstrip(w, 1.6e-3, 4.4, t=35e-6, f=2.4e9)
print(line.z0, line.eps_eff, line.wavelength(2.4e9))
```

## Builders: `builders`

Each builds into a project (`em.Project`), adds wave ports and a frequency sweep around its design
frequency, makes that setup active, and returns a `BuildResult` (`summary`, `objects`, `ports`,
`values`).

| Function | Builds |
|---|---|
| `microstrip_line(prj, z0=50.0, er=4.4, h=1.6e-3, length=0.03, f0=5e9, tand=0.0, board_width=None)` | A straight line on its board, ports at both ends |
| `quarter_wave_transformer(prj, z_source=50.0, z_load=100.0, f0=2.4e9, er=4.4, h=1.6e-3, tand=0.0)` | Source line, √(Zs·ZL) λg/4 section, load line |
| `tapered_line(prj, z1=50.0, z2=100.0, length=0.04, kind="exponential", er=4.4, h=1.6e-3, f0=3e9, segments=40, tand=0.0, gamma_max=0.02)` | `kind`: `"linear"`, `"exponential"` or `"klopfenstein"` |
| `branchline_coupler(prj, f0=2.4e9, z0=50.0, er=4.4, h=1.6e-3, tand=0.0, feed_length=None)` | 3 dB 90° hybrid, four ports |
| `patch_antenna(prj, f0=2.4e9, er=4.4, h=1.6e-3, tand=0.02, z0=50.0)` | Inset-fed patch, ground, radiation box, wave port |
| `waveguide_section(prj, size="WR-90", length=0.05, a=None, b=None, er=1.0)` | A standard or custom rectangular guide |
| `coax_section(prj, z0=50.0, d_inner=1.27e-3, er=2.1, length=0.02)` | A coax sized for an impedance |
| `design_patch(f0, er, h, z0=50.0)` | `PatchDesign` (`W`, `L`, `eps_eff`, `dL`, `r_edge`, `inset`, `feed_w`), nothing built |

```python
prj = em.Project("coupler", units="mm")
res = builders.branchline_coupler(prj, f0=2.4e9, er=3.66, h=0.508e-3)
print(res.summary, res.ports)            # ['Port1', 'Port2', 'Port3', 'Port4']
print(prj.setups.names())                # ['CouplerSweep']: the sweep the builder added
result = prj.setups["CouplerSweep"].solve(cores=4)
```

## Ports on your own traces: `ports`

| Function | |
|---|---|
| `add_line_port(prj, trace, kind="microstrip", name=None, **kw)` | Plans and adds a port on a trace's end; returns `(port, plan)` |
| `plan_line_port(prj, trace, kind="microstrip", end="auto", port_type="wave", ...)` | Works out the port without changing anything; returns a `PortPlan`. Lengths read from the model unless given (`w`, `t`, `h`, `er`, `s`, `b`, `width`, `height`, metres) |
| `apply_port_plan(prj, plan, name=None, modes=1, resistance=50.0)` | Builds a plan: the air box if needed, the port sheet and the port |
| `describe(plan)` | A readable summary |
| `port_size(kind, w, h, er, s=None, b=None)` | `(width, height above the reference, depth below it)` by the usual sizing rules |

`kind` is `"microstrip"`, `"stripline"`, `"cpw"` or `"gcpw"`; `port_type` `"wave"` or `"lumped"`. Sizing
rules are in the user guide's [RF tools](/docs/app/rf-tools#ports) page.

## The tool catalogue: `catalog`

`catalog.run(tool_id, prj, values=None, build=False) -> str` runs any menu tool by id with SI `values`
overriding its defaults, and returns its text output. `build=True` also builds it.
`catalog.defaults(catalog.TOOLS_BY_ID[tool_id])` gives the defaults.

| Ids | |
|---|---|
| `calc.microstrip`, `calc.stripline`, `calc.cpw`, `calc.coax`, `calc.waveguide`, `calc.skin`, `calc.patch` | Calculators |
| `port.wave`, `port.lumped` | Port wizards |
| `build.microstrip`, `build.qwt`, `build.taper`, `build.branchline`, `build.patch`, `build.waveguide`, `build.coax` | Builders |

## Material library

```python
from te10_studio.core import material_library as lib
```

| Function | Returns |
|---|---|
| `lib.search(text="", category="", conductors=None)` | Entries whose name, category, vendor or construction contain every word of `text` |
| `lib.get(name)` | One entry (case-insensitive), or `None` |
| `entry.values_at(freq_hz)` | `(eps_r, tan_delta, sigma)` at a frequency (tables interpolated linearly in log f) |
| `lib.make_material(entry, freq_hz=10e9, dispersive=False, name=None)` | A project material with the entry's values at that frequency; `dispersive=True` for a Djordjevic–Sarkar model anchored there |

```python
e = lib.get("Panasonic MEGTRON 6 R-5775(N) 2x1078 RC59 5.0mil core")
print(e.values_at(28e9))
mat = lib.make_material(e, 28e9)
prj.core.materials[mat.name] = mat         # add it to the project
```

What the library holds is listed in the user guide's [Materials](/docs/app/materials#the-material-library)
page.
