The pattern.py module#

Summary#

is_pattern

Return True when name contains any wildcard metacharacter.

expand_pattern

Return every entry in candidates matching pattern.

Description#

Wildcard/pattern helpers for named-object selection.

PyFluent accepts glob-style patterns on string indexers and string-list properties (such as cell_zone_conditions.copy(from_="cell_1", to="cell_*") and zone_assignment.passive_zone = "*bar*|*tabzone*"). The solver itself expands these patterns at runtime. This module mirrors that contract on the client side to do the following:

  • Recognize a pattern in user- or host-supplied identifiers.

  • Validate a pattern by checking that it matches at least one live name.

  • Enumerate matching names for batched (multi-edit) plan steps.

The pattern grammar is a subset of PyFluent’s:

  • *: Match any run of characters (fnmatch semantics).

  • ?: Match a single character.

  • [abc]: Character class.

  • |: Alternation between sub-patterns. For example, "wall-*|inlet-?" matches either branch.

Plain identifiers (no wildcard metacharacters) are returned by expand_pattern() unchanged when they appear in candidates, so a literal name behaves as a direct lookup.

Module detail#

pattern.is_pattern(name: str | None) bool#

Return True when name contains any wildcard metacharacter.

Parameters:
namestr | None

Name of the object, module, or setting being processed.

Returns:
bool

Boolean result produced by the function.

pattern.expand_pattern(pattern: str, candidates: Iterable[str]) list[str]#

Return every entry in candidates matching pattern.

The result preserves the order in which candidates first match, so callers get a stable enumeration that mirrors the underlying live name list. Duplicate matches (possible across alternation branches) are collapsed.

Plain (non-pattern) pattern values fall through to a literal membership check, returning [pattern] if present and [] otherwise.

Parameters:
patternstr

Selection pattern for matching object names.

candidatesIterable[str]

Candidates to supply to the function.

Returns:
list[str]

Collection containing the operation results.