plaid.containers.managers.default_manager

DefaultManager for managing default time/base/zone selections.

Classes

FeaturesBackend

Minimal interface required by DefaultManager.

DefaultManager

Manages and resolves default time/base/zone selections.

Module Contents

class FeaturesBackend[source]

Bases: Protocol

Minimal interface required by DefaultManager.

This allows any backend implementing these methods to be used by DefaultManager.

For example, SampleFeatures already satisfies this contract.

get_all_time_values() list[float][source]

Get all available time values in the mesh.

get_base_names(*, time: float | None = None) list[str][source]

Get all available base names at a given time.

get_zone_names(base_name: str | None = None, *, time: float | None = None) list[str][source]

Get all available zone names within a base at a given time.

has_base(base_name: str, time: float | None = None) bool[source]

Check if a base exists at a given time.

has_zone(zone_name: str, base_name: str | None = None, time: float | None = None) bool[source]

Check if a zone exists within a base at a given time.

class DefaultManager[source]

Manages and resolves default time/base/zone selections.

Notes on legacy semantics: - resolve_time(None) returns the first sorted available timestamp, else 0.0. - resolve_base(None) returns None if no non-Global base exists. - resolve_zone(None) returns None if no zone exists in the resolved base.

set_default_time(time: float) None[source]

Set the default time for the system.

This function sets the default time to be used for various operations in the system.

Parameters:

time (float) – The time value to be set as the default.

Raises:

ValueError – If the specified time does not exist in the available mesh times.

Note

  • Setting the default time is important for synchronizing operations with a specific time point in the system’s data.

  • The available mesh times can be obtained using the get_all_mesh_times method.

Example

from plaid import Sample
sample = Sample("path_to_plaid_sample")
print(sample)
>>> Sample(2 scalars, 1 timestamp, 5 fields)
print(sample.show_tree(0.5))
>>> ...

# Set the default time to 0.5 seconds
sample.set_default_time(0.5)

# You can now use class functions with 0.5 as default time
print(sample.show_tree()) # show the cgns tree at the time 0.5
>>> ...
set_default_base(base_name: str, time: float | None = None) None[source]

Set the default base for the specified time (that will also be set as default if provided).

The default base is a reference point for various operations in the system.

Parameters:
  • base_name (str) – The name of the base to be set as the default.

  • time (float, optional) – The time at which the base should be set as default. If not provided, the default base and active zone will be set with the default time.

Raises:

ValueError – If the specified base does not exist at the given time.

Note

  • Setting the default base and is important for synchronizing operations with a specific base in the system’s data.

  • The available mesh base can be obtained using the get_base_names method.

Example

from plaid import Sample
sample = Sample("path_to_plaid_sample")
print(sample)
>>> Sample(2 scalars, 1 timestamp, 5 fields)
print(sample.get_physical_dim("BaseA", 0.5))
>>> 3

# Set "BaseA" as the default base for the default time
sample.set_default_base("BaseA")

# You can now use class functions with "BaseA" as default base
print(sample.get_physical_dim(0.5))
>>> 3

# Set "BaseB" as the default base for a specific time
sample.set_default_base("BaseB", 0.5)

# You can now use class functions with "BaseB" as default base and 0.5 as default time
print(sample.get_physical_dim()) # Physical dim of the base "BaseB"
>>> 3
set_default_zone_base(zone_name: str, base_name: str, time: float | None = None) None[source]

Set the default base and active zone for the specified time (that will also be set as default if provided).

The default base and active zone serve as reference points for various operations in the system.

Parameters:
  • zone_name (str) – The name of the zone to be set as the active zone.

  • base_name (str) – The name of the base to be set as the default.

  • time (float, optional) – The time at which the base and zone should be set as default. If not provided, the default base and active zone will be set with the default time.

Raises:

ValueError – If the specified base or zone does not exist at the given time

Note

  • Setting the default base and zone are important for synchronizing operations with a specific base/zone in the system’s data.

  • The available mesh bases and zones can be obtained using the get_base_names and get_base_zones methods, respectively.

Example

from plaid import Sample
sample = Sample("path_to_plaid_sample")
print(sample)
>>> Sample(2 scalars, 1 timestamp, 5 fields)
print(sample.get_zone_type("ZoneX", "BaseA", 0.5))
>>> Structured

# Set "BaseA" as the default base and "ZoneX" as the active zone for the default time
sample.set_default_zone_base("ZoneX", "BaseA")

# You can now use class functions with "BaseA" as default base with "ZoneX" as default zone
print(sample.get_zone_type(0.5)) # type of the zone "ZoneX" of base "BaseA"
>>> Structured

# Set "BaseB" as the default base and "ZoneY" as the active zone for a specific time
sample.set_default_zone_base("ZoneY", "BaseB", 0.5)

# You can now use class functions with "BaseB" as default base with "ZoneY" as default zone and 0.5 as default time
print(sample.get_zone_type()) # type of the zone "ZoneY" of base "BaseB" at 0.5
>>> Unstructured
resolve_time(time: float | None = None) float[source]

Resolve which time to use for an operation.

Resolution order: - If time is provided, return it. - Else if a default time is set, return it. - Else return the first sorted available timestamp, or 0.0 if none exist.

Parameters:

time (float, optional) – The time to resolve. Defaults to None.

Returns:

The resolved time.

Return type:

float

resolve_base(base_name: str | None = None, time: float | None = None) str | None[source]

Resolve which base name to use for an operation.

Parameters:
  • base_name (str, optional) – The base name to resolve. Defaults to None.

  • time (float, optional) – The time at which to resolve the base. Defaults to None.

Returns:

The resolved base name.

Return type:

Optional[str]

Raises:

KeyError – If multiple bases exist and no default is set.

resolve_zone(zone_name: str | None = None, base_name: str | None = None, time: float | None = None) str | None[source]

Resolve which zone name to use for an operation.

Parameters:
  • zone_name (str, optional) – The zone name to resolve. Defaults to None.

  • base_name (str, optional) – The base name in which the zone is located. Defaults to None.

  • time (float, optional) – The time at which to resolve the zone. Defaults

Returns::

Optional[str]: The resolved zone name.

Raises:

KeyError – If multiple zones exist and no default is set.