Skip to content

Proposal for units support for real entries #529

@h-krishnan

Description

@h-krishnan

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions