The units.py module#

Summary#

Quantity

A parsed numeric value with its unit and CFD quantity classification.

parse_quantities

Extract every pair from text.

quantity_hints

Client-friendly serialization of every quantity in text.

iter_quantities

Return a generator of every pair from text.

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 from text.

Order is preserved. Overlapping matches are not produced. (Regex consumes left to right). The returned list may be empty.

Parameters:
textstr

Text value to parse, normalize, or write.

Returns:
list[Quantity]

Collection containing the operation results.

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.

Parameters:
textstr

Text value to parse, normalize, or write.

Returns:
list[dict[str, object]]

Mapping containing the operation result.

units.iter_quantities(text: str) Iterator[Quantity]#

Return a generator of every pair from text.

Generator equivalent of parse_quantities().

Parameters:
textstr

Text value to parse, normalize, or write.

Returns:
Iterator[Quantity]

Result produced by the function.