CyFlex Math and the temperature “GOTCHA”

Units Independence in CyFlex computations:

CyFlex supports “units-independence”. Internally, applications such as “compvar”, mass flow rate, etc. perform computations using SI (metric) base units. Inputs and outputs to these programs involve a units conversion process so that the inputs and outputs can be in other units. A simple example of this is the computation of horsepower from engine speed and torque. The speed may be in “rpm”, the torque in “lb-ft” and the desired result to be in “hp”. The internal process is as follows.

1. Convert the speed input value from “rpm” to “radians/sec”
2. Convert the torque input value from “lb-ft” to “newton-meters”
3. Multiply speed by torque, producing a power value in “watts”
4. Convert the power from “watts” to “hp”
5. Store the power in “hp” in the output variable
In a CyFlex computed expression, this is simply “eng_spd * eng_torque” and it doesn’t matter if eng_spd and eng_torque are in English or Metric units. The result will still be computed properly. Likewise, the output target could be “hp” or “kw” and the appropriate conversion from “watts” will be performed.

See Section 7 of the “CyFlex Variables, Units, Computed Expressions” user manual for details of the rules for writing computed expressions.

The Temperature “GOTCHA”:

The description above also describes how conversion takes place for temperature values, but the normal Celsius and Fahrenheit units have a characteristic that is different from other units. They have an offset (bias). Units of pressure, speed, torque, etc., do not have an offset, so 0[psi] = 0[kpa] = 0[in_hg] = 0[in_h20] and so on. However,

0[deg_c] = 273.15[K] (Kelvin is the SI base units)

0[deg_f] = 255.372[K]

So, now take an example of a simple addition expression:

“100[deg_f] + 1[deg_f]”

You expect the result to be 101[deg_f], but here is how the math works:

100[deg_f] converts to 310.928[K]

1[deg_f] converts to 255.928[K]

Summing these values yields a result of 566.855[K]

Converting the result to “deg_f” yields 560.67[deg_f] ????

What if we just try to subtract 1[deg_f] “100[deg_f] – 1[deg_f]”

The subtraction (310.92 – 255.928] yields 55[K] which converts to -360.67[deg_f] ???

That demonstrates the problem. But what is the solution. CyFlex has some special temperature units referred to as “temperature differential” units, “dt_f”, “dt_c”, “dt_k”, and “dt_r”. These units have the bias removed from the units conversion factors.

So, the 100+1 math works as follows when the differential units are specified:

“100[deg_f] + 1[dt_f]”

100[deg_f] converts to 310.928[K]

1[dt_f] converts to 0.5555[K]

Summing these values yields a result of 311.483[K]

Converting the result to “deg_f” yields 101[deg_f] (ta da!)

Likewise, for subtraction.

Testing expressions from the command line:

You can experiment with any computed expression using the “get_comp” application. Type “use get_comp” for help.

get_comp “expression” [u=units]

If u=units are not included, the result is always reported in base SI units. Example:

get_comp “100[deg_f] + 1[dt_f]”
311.48

get_comp “100[deg_f] + 1[dt_f]” u=deg_f
101.00[f]

This units-independence feature is why numeric values in CyFlex expressions include units of measure.
Other benefits of units-independence are that it allows a measurement in one set of units to be displayed, logged, or monitored in different units.