Skip to content

Proposal for units support for real entries #678

@seanpearsonuk

Description

@seanpearsonuk

Discussed in #546

Originally posted by h-krishnan June 20, 2022
At present, real entries returned from the settings API are in SI units but the unit information is not available. There is no ready mechanism to convert the value to other units.
Suppose we define a "RealWithUnits" class:

class RealWithUnits(float):
   ...

The float value is the SI value of the setting, but the class also stores unit information.
Along with the real value, suppose we also return the units via the API.

>>> session.get_settings_service().get_var("setup/boundary-conditions/velocity-inlet/inlet2/vmag/constant")
(10.2, "m/s")

We can wrap the return value with RealWithUnits so that setup.boundary_conditions.velocity_inlet['inlet2'].vmag.constant() will return RealWithUnits(10.2, "m/s"). The __str__() method of this class will return (10.2, 'm/s').
We can support index operators so that users can get the value in desired units:

v = RealWithUnits(10.2, "m/s")
v["cm/s"]  # --> "1020 [cm/s]" ( ReaWithUnits(1020, "cm/s") )

Whenever values are set via RealWithUnits() instead of real, we could convert to SI units and then send to Fluent. We could support special "tuple" assignment:

setup.boundary_conditions.velocity_inlet['inlet2'].vmag.constant = (1.2, "ft/s")

Of course, if no units are specified, SI units are implicitly assumed.

setup.boundary_conditions.velocity_inlet['inlet2'].vmag.constant = 1.2  # m/s

Values returned from Fluent will always be in SI units. But if user creates their own RealWithUnits object and sets a setting with that value, the value will be converted to SI units before sending to Fluent. User's specification of units is not preserved in the case file.

Metadata

Metadata

Assignees

Labels

enhancementImprove any current implemented feature

Type

No type

Projects

Status

2021-2024

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions