# Fluid mechanics

Load the complete package with `\usepackage{tikzphysics}`, or just this module:

```tex
\usepackage{tikz}
\usetikzlibrary{tikzphysics.fluids}
```

These are editable teaching schematics for the supplied reference families, not a fluid solver. Heights and curvatures are inputs; the package does not infer equilibrium from density, gravity, or acceleration. No additional font package is loaded. Text and math use the document fonts; native `font=\large` also scales default arrow tips. Ordinary `draw`, `fill`, `color`, `line width`, `opacity`, `rotate`, `scale`, `xscale`, and `yscale` remain available. TikZ's usual rule applies: `scale` changes coordinates; add `transform shape` to scale node text too.

## Native nodes first

Eight individual objects support ordinary `\node`: `fluid tank`, `fluid cylinder`, `pressure element`, `meniscus`, `rotating fluid`, `flow tube`, `liquid ring`, and `u tube`.

```tex
\begin{tikzpicture}[font=\small]
  \node[fluid tank,
    fluid={width=4cm,height=3cm,left level=.85,right level=.55},
    pattern=north east lines,pattern color=gray,
    draw=black,line width=.7pt
  ] (T) {};
  \draw[->] (T.right-surface) -- ++(1,0) node[right] {$a_x$};
\end{tikzpicture}
```

Nodes have standard compass, base, and mid anchors, native `anchor`, `minimum width`, `minimum height`, `inner sep`, `outer sep`, text contents, and positioning-library support (`right=1cm of T`). Minimum sizes can enlarge the geometric frame; use `fluid width` and `fluid height` to set the primitive size. Ring nodes remain circular with diameter set by width. Automatic connections use the nominal rectangular frame (a circular frame for liquid rings); semantic anchors give precise attachment points on curved boundaries.

| Node | Additional anchors |
|---|---|
| `fluid tank`, `meniscus`, `rotating fluid`, `u tube` | `left-surface`, `right-surface`, `surface` |
| `fluid cylinder` | `surface` |
| `pressure element`, `flow tube` | `inlet`, `outlet` |
| `liquid ring` | `liquid-start`, `liquid-end` |

Node coordinates are centred on `(T.center)`. Cylinder-node `fluid level` measures along its straight wall between the end-cap centres. U-tube nodes show a single liquid; use the assembly for a second liquid and its interface. Nodes contain no automatic force labels: put text in `{...}` or use native `label` and your own paths.

## Patterns from the user's document

The default is a light dot pattern. Native choices work directly:

```tex
\node[fluid tank,pattern=dots] (A) {};
\node[fluid tank,pattern=north east lines,pattern color=gray] at (4,0) {};
\node[fluid tank,pattern=horizontal lines,dashed] at (8,0) {};
\node[fluid tank,fill=cyan!20] at (0,-4) {}; % solid liquid
\node[fluid tank,pattern=none] at (4,-4) {}; % outline only
```

A later `fill` replaces a pattern; a later `pattern` selects patterned liquid. `pattern color`, `fill opacity`, line width, and dashes remain adjustable. Stroke-based patterns can also inherit a dash setting, as in native PGF. The node-local fill/pattern handlers paint only the liquid and do not affect subsequent ordinary TikZ nodes. `examples/fluid-patterns.tex` demonstrates all of these together.

## Assemblies with pics

Fourteen pics retain complete teaching diagrams, including forces, axes, interface labels, the hydraulic press, gas manometer, capillary apparatus, and surface-tension ring. For an object that also has a node, the explicit pic name is `<name> diagram`; the original pic name is an alias:

```tex
\pic (T) {fluid tank diagram={fluid left level=.85,fluid right level=.55}};
\draw[->] (T-right-surface) -- ++(1,0);
```

Use `\physicshelp{fluid tank}` for the node and `\physicshelp{fluid tank diagram}` for the assembly. Node anchors use dots; pic component coordinates use hyphens. Geometry goes inside the pic argument after its defaults, while native placement/transforms can go outside. Per-object defaults use `every fluid tank/.append style={...}`; `every fluid node` applies only to nodes.

## Native keys and aliases

`fluid={width=4cm,height=3cm}` is a scoped shorthand for `fluid width=4cm,fluid height=3cm`. Each semantic key also has a `physics fluid ...` alias. Each node and pic has a `physics ...` alias, for example `\node[physics fluid tank] {};` and `\pic {physics fluid tank diagram={physics fluid width=4cm}};`. Native global keys such as `radius`, `angle`, `minimum width`, and `height` are never redefined. Use native keys directly for styling; use the fluid family for geometry. Lengths accept units and math expressions; bare lengths mean centimetres. Levels are unitless fractions in [0,1].

## Primitives and geometry

All pics expose `(F-origin)`, `(F-center)`, `(F-bottom)`, `(F-top)`, `(F-left)`, `(F-right)` for a pic named `F`. These describe the nominal frame; protruding arrows and labels may extend beyond it. Other coordinates are listed below. For `liquid ring`, width controls both diameters and height only places the nominal frame centre.

| Pic | Geometry keys (under `fluid`) | Additional coordinates |
|---|---|---|
| `u tube` | width, height, tube width, left level, right level, level | left-surface, right-surface, interface, upper-surface |
| `gas manometer` | width, height, tube width, left level, right level | left-surface, right-surface, gas |
| `hydraulic press` | width, height, tube width, left level, right level | large-piston, small-piston |
| `fluid cylinder` | width, height, level | surface |
| `fluid tank` | width, height, left level, right level | left-surface, right-surface, surface |
| `pressure element` | width, height | None |
| `rotating tube` | width, height, tube width, level | element-left, element-right |
| `rotating fluid` | width, height, level, bend | vertex, rim-surface |
| `buoyancy` | width, height, left level, right level | left-surface, right-surface, surface, body |
| `flow tube` | width, height, bend | inlet, outlet |
| `meniscus` | width, height, level, bend | contact-left, contact-right, surface |
| `capillary` | width, height, level, left level, bend | contact-left, contact-right, reservoir |
| `surface tension ring` | width, height | None |
| `liquid ring` | width, tube width, angle, sweep | liquid-start, liquid-end |

- **u tube:** Two-liquid U tube. level adds a second liquid only above left level.
- **gas manometer:** Gas reservoir connected to a U tube. body label names the gas.
- **hydraulic press:** Large piston width is 0.32 times width; tube width sets the small piston.
- **fluid cylinder:** Projected cylinder with an elliptical liquid surface. width is the diameter.
- **fluid tank:** Open vessel. Equal endpoint levels give a horizontal free surface.
- **pressure element:** Projected horizontal fluid element with inward pressure forces.
- **rotating tube:** Horizontal tube with a differential section. level locates its left face along width.
- **rotating fluid:** Parabolic surface. level is the vertex height; bend is the wall-to-vertex rise divided by height.
- **buoyancy:** Immersed body with schematic inward pressure arrows. Arrow lengths do not encode pressure magnitude.
- **flow tube:** Curved flow tube; outlet height is 0.55 times inlet height. bend controls vertical curvature.
- **meniscus:** Positive bend is concave; negative bend is convex. Contact angle is measured through the liquid.
- **capillary:** Capillary rise. level is the reservoir surface and left level is the contact-line height.
- **surface tension ring:** Projected circular contact line. width and height are the ellipse diameters.
- **liquid ring:** Annular liquid sector. width is outer diameter, tube width is radial thickness. Angles use degrees counterclockwise from right.

## Styling and labels

Pic liquid fills follow native `fill` and `pattern`. Override pic components using:

```tex
\tikzset{
  every fluid liquid/.append style={pattern=horizontal lines},
  every fluid outline/.append style={thick},
  every fluid arrow/.append style={>={Stealth[length=.7em]}},
  every fluid label/.append style={font=\footnotesize}
}
```

Other hooks are `every fluid secondary liquid` and `every fluid dimension`. All have corresponding `every physics fluid ...` aliases. Per-pic hooks follow `every <pic name>`, also with a `physics` alias. User styles run after defaults.

Generic labels: `fluid body label`, `fluid left label`, `fluid right label`, and `fluid dimension label`. The pressure element uses the first three for area and pressure forces, and the last for its length. The hydraulic press uses body label for its load. Empty text suppresses a label. All keys accept arbitrary LaTeX, including custom macros and units.

Named labels use `fluid <name> label`:

- `force` (hydraulic press), `volume` (buoyancy).
- `pressure`, `pressure increment`, `angular velocity`, `position` (rotating tube).
- `horizontal axis`, `vertical axis` (rotating fluid).
- `inlet velocity`, `outlet velocity` (flow tube).
- `contact angle` (meniscus and liquid ring), `radius` (liquid ring).
- `rise`, `tension` (capillary), `circumference force` (surface tension ring).

Body dimensions remain physical lengths when a font changes. Label padding and arrow tips use em units. For large fonts in small diagrams, enlarge geometry or shorten labels. Explicit hook styling always takes precedence.

## Geometry limits and interpretation

- U-tube and manometer: tube width < one third of both width and height; both liquid levels must lie above the semicircular bend (`min(left level,right level)*height > width/2`). The optional second liquid occupies the left arm between left level and level.
- Hydraulic press: tube width < 0.3*width and below both piston heights. The large piston width is 0.32*width.
- Rotating tube: `level*width + tube width < width`.
- Rotating vessel: bend >= 0 and level + bend <= 1. The surface is `height*(level + bend*(2*x/width-1)^2)`.
- Meniscus: level +/- abs(bend) must stay in [0,1]. Its cubic curve sets the contact tangent; the angle arc is drawn inside the liquid. It is a schematic meniscus, not a Young-Laplace solution.
- Capillary rise: bend >= 0 and left level - 0.75*bend >= level. The bore is 0.2*width. The h annotation measures to the contact line. Use ordinary paths for added force components; the composed example demonstrates this.
- Liquid ring: tube width < width/2; sweep in (0,360]. The ring is circular; use a native transform to project it.
- Buoyancy arrows indicate pressure direction only. A physical force diagram can be added at the named body coordinate.

## Discovery and examples

Inside a TikZ picture, `\physicshelp{fluid tank diagram}` shows assembly geometry defaults and coordinates. Pic coordinates are not node anchors: use `(F-surface)`, not `(F.surface)`. The generic `show anchors` overlay works on native fluid nodes, but does not apply to pics.

- `examples/fluid-mechanics-nodes.tex`: all eight native nodes.
- `examples/fluid-patterns.tex`: document-controlled patterns, fill, and positioning.
- `examples/fluid-mechanics-gallery.tex`: every primitive, one per page.
- `examples/fluid-mechanics-reference-scenes.tex`: compositions covering all thirteen supplied references, including two fluids, acceleration, contact-angle signs, and force components.
- `examples/elements-fonts.tex`: font inheritance, font-relative arrows,
  per-node overrides, and native pattern/fill variants.

The generated `output/overleaf/tikzphysics.sty` contains this module and the rest of the package. Upload that file alongside any example or your own document. No sibling library files are required. Regenerate with `python3 scripts/build_overleaf_bundle.py`; verify with `--check`.
