The units.py module#
Summary#
A parsed numeric value with its unit and CFD quantity classification. |
Extract every |
|
Client-friendly serialization of every quantity in |
|
Return a generator of every |
Description#
Unit- and quantity-aware parsing for free-text Fluent values.
PyFluent settings parameters generally accept either a bare numeric in
the Fluent active unit-system or a (value, unit) tuple. Host-generated
code that ignores units is a major source of silently-wrong
boundary conditions (“set inlet to 50 C” landing as 50 K because the
solver is in SI). This module extracts {value, unit, quantity}
hints from a free-form prompt so the orchestrator can pass them to the
authoring host as structured context. The grounding pass can then rewrite plain
numeric literals into (value, unit) tuples when the target API
supports it.
This module is intentionally lightweight with no pint dependency. It only handle the
units that actually show up in CFD prompts. Anything ambiguous returns
None, and the caller must fall back to asking the user.
Module detail#
- units.parse_quantities(text: str) list[Quantity]#
Extract every
pair fromtext.Order is preserved. Overlapping matches are not produced. (Regex consumes left to right). The returned list may be empty.
- units.quantity_hints(text: str) list[dict[str, object]]#
Client-friendly serialization of every quantity in
text.Each hint contains the original literal, canonical unit, quantity classification, and value converted to Fluent’s default SI unit so callers can plug it straight into PyFluent.
- units.iter_quantities(text: str) Iterator[Quantity]#
Return a generator of every
pair fromtext.Generator equivalent of
parse_quantities().- Parameters:
- text
str Text value to parse, normalize, or write.
- text
- Returns:
Iterator[Quantity]Result produced by the function.