Proposal for units support for real entries #546
Replies: 5 comments 2 replies
-
@h-krishnan thanks for raising this topic. This looks good. To instantiate a |
Beta Was this translation helpful? Give feedback.
-
Generally I think this is a great idea. To have units attached to real values would be useful. I think it would be good if the library supported mathematics. eg: you can multiply two instances of |
Beta Was this translation helpful? Give feedback.
-
Created #678, which references this, and can be tracked on the kanban board. |
Beta Was this translation helpful? Give feedback.
-
@h-krishnan We are thinking about how compute commands etc should work. Do you already have a fixed idea about this? Taking report definition as an example, whereas the value is currently a float, i.e., |
Beta Was this translation helpful? Give feedback.
-
@h-krishnan @dnwillia-work @hpohekar @gyeole @mkundu1 @ajain-work @prmukherj Metadata attributesunits-quantity In the current version (2023R1) this is currently simply a string in the settings API, e.g., "pressure", where the name is specifically a Fluent name*, which encompasses many things, all with that Fluent-specific naming. For a client to use this information, it needs to know how these names translate to names that it understands, or at least into correct units. For instance, the units code in PyFluent uses names inherited from the Ansys/CFX units library. The names do not match, and inevitably the two sets of quantities are different, such that one-to-one translation of names is impracticable. The internal data structures that map those Fluent names to corresponding SI units can easily be translated to Python, such that any client could at least extract the units from the Fluent name. Alternatively, we could also provide such information directly as attributes via the API (see units and dimensions below). The current representation of units-quantity as string is seen as too limiting. For instance, the API returns an area-integral of pressure, where the quantity information could be preserved as the product of pressure and area rather than force. The proposed format is {"pressure":1, "area":1} for the present example, and {"pressure": 1} for the first example. The client can use the detailed quantity information not only to select the most appropriate units, but may also propagate that information in subsequent client-side operations (e.g., units In the current version, there is no units attribute. The client code has the responsibility of always computing the units from the units-quantity attribute, but as mentioned above, that might not always be practical. Hence, a units string attribute could be added. The provided units string would be of some specific format, and would also contain some idiosyncrasies. The issues caused by those idiosyncrasies should not be underestimated. For instance C stands for coulomb, but we are using it to stand for degrees celsius. These two facts (the specific format and the wrong use of some symbols) means that any client would have to be careful when using the data in its own code. dimensions The safest way to label the data is with its dimensions. The representation could be a fixed-length list/tuple of floats with the meaning of each element clearly documented (shorter lists could be returned, implying a tail of all zeros). Given that it is also documented that all data is SI, this attribute allows suitable units of all data to be robustly computed without having either to deal with arcane quantity names or to parse units strings of specific formats or containing idiosyncratic symbols. The only drawback is in the case that a client wants to recover the "most" appropriate units. *Q: are we definitely using the Fluent names in the units-quantity attribute? |
Beta Was this translation helpful? Give feedback.
-
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:
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.
We can wrap the return value with
RealWithUnits
so thatsetup.boundary_conditions.velocity_inlet['inlet2'].vmag.constant()
will returnRealWithUnits(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:
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:
Of course, if no units are specified, SI units are implicitly assumed.
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.
Beta Was this translation helpful? Give feedback.
All reactions