Physical units handling in Python

Physical units handling in Python

On Demand

Information

Accurate handling of physical units is a key capability across the Ansys product portfolio. For example, Ansys users can choose their preferred units for the values they input and inspect in graphical user interfaces. Due to the sharing of a core library, the conversion and arithmetical combination of physical quantities with units exhibit consistent behaviour across products. Equivalent units handling capabilities are needed in the PyAnsys ecosystem. PyAnsys users should be able to obtain or specify quantities in any given units and also combine quantities together arithmetically, where all results should precisely emulate those exhibited in Ansys products. In this presentation, we detail the work we have done to achieve accurate, consistent, Ansys-compliant physical units handling in any Ansys or PyAnsys Python code. We have developed two solutions: one addresses the scenario where Python and Ansys are embedded together, while the other lends itself to use in PyAnsys client libraries that can communicate with a remote Ansys product. The two approaches are united by common abstractions, and a single, comprehensive set of unit tests. The embedded solution consists of only a very thin layer of Python code, built on top of trusted C and C++ code: the core Ansys units library. The PyAnsys solution is pure Python by default, which can be swapped to the embedded version if the required libraries are installed locally (e.g., in an Ansys installation). A simple, user-editable units configuration covers a breadth of units and unit systems. The Python code we have developed is already integrated into Fluent and PyFluent, where users can configure the code, and instantiate, convert and combine physical quantity objects based on Fluent values as well as arbitrary physical values. The code makes no assumptions, and is decoupled from either Fluent or PyFluent concepts. We propose its reuse across PyAnsys and Ansys code, which would require minimal effort.

Log in

See all the content and easy-to-use features by logging in or registering!