Skip to main content

Conversion of units

Physical units

Although in smartCORE all channels with physical variables, measured or calculated, have usually been assigned a physical unit in the configuration, these are not taken into account in the calculation and further processing.

It is the author's responsibility to convert and standardize the physical values himself by making appropriate corrections.

Frequently used conversions are provided by the following functions:

FunctionDescription
rad2deg(alpha)Conversion of the angle alpha from radians to degrees
deg2rad(alpha)Conversion of the angle alpha from radians to radians
kph2mph(speed)Conversion of speed from km/h to mph
mph2kph(speed)Conversion of speed from mph to km/h
C2K(temperature)Converting a temperature from °Celsius to Kelvin
K2C(temperature)Conversion of a temperature from Kelvin to °Celsius
C2F(temperature)Conversion of a temperature from °Celsius to °Fahrenheit
F2C(temperature)Conversion of a temperature from °Fahrenheit to °Celsius
F2K(temperature)Conversion of a temperature from °Fahrenheit to Kelvin
K2F(temperature)Conversion of a temperature from Kelvin to °Fahrenheit
tip

If the required conversion function is not available here, the commented definition of scaling factors at the beginning of the formula text has proved useful.

// Constants for unit conversion
uConv_Ws2kWh = 1e-3 / 3600; // Ws -> kWh
...

Example 1 shows the application in the energy calculation.

The following examples show the need:

Example: Power and energy

The electrical power is the product of current and voltage:

Pel(t)=U(t)I(t)P_{el}(t) = U(t) \cdot I(t)

and the energy from the integral over the power:

Wel(t)=0tPel(τ)dτW_{el}(t) = \int_0^t P_{el}(\tau) d\tau

The SI base units A (ampere), V (volt), W (watt) and J (joule) are assumed. If the measurement data is not available in the SI base units or if the results are not to be output in these units, correction factors must be incorporated.

If the current is measured in mA and the power is to be output in kW, it must be corrected in the form of an equation of the following dimensions:

Pel(t)=U(t)I(t)1A1000mA1kW1000WP_{el}(t)=U(t) \cdot I(t)\cdot\frac{1 \rm{A}}{1000 \rm{mA}}\cdot\frac{1 \rm{kW}}{1000 \rm{W}}

in the commented formula text:

P_el = U_el * I_el / 1000 / 1000; // I in mA, P_el in kW

To output the energy in kWh, the following equation must be formed using the relationship 1J=1Ws1 \rm{J} = 1 \rm{Ws}:

Wel(t)=1kWh1000Wh1h3600s0tPel(τ)1000W1kWdτW_{el}(t) = \frac{1 \rm{kWh}}{1000 \rm{Wh}} \cdot \frac{1 \rm{h}}{3600 \rm{s}} \int_0^t P_{el}(\tau) \frac{1000 \rm{W}}{1 \rm{kW}} d\tau

and in the commented formula text:

W_el = integrate(P_el * 1000) / 1000 / 3600; // P_el in kW, W_el in kWh

It is important to ensure that function blocks that can be provided with a persistent memory are filled in SI base units. This makes it easier to subsequently implement corrections in the source and target units. In this example, the integrand must have the SI unit W. Therefore, the factor 1000 should not be removed from the integral and shortened.

W_el = integrate(P_el * 1000, {storage:'energy_Ws'}) / 1000 / 3600;
note

In this example, the definition of constants for conversion suggested at the beginning was not implemented. You can see how the readability of the formulas deteriorates. For what and why does it say * 1000 or / 1000 ?

Example: Thermodynamics

In thermodynamic formulas, temperatures are used in the SI base unit Kelvin (K). For example, in the thermal equation of state

pV=mRTp \cdot V = m \cdot R \cdot T

The following SI base units are to be used:

  • p in Nm2=Pa\frac{\rm{N}}{\rm{m}^2} = \rm{Pa} (Pascal)

  • V in m3\rm{m}^3

  • m in kg\rm{kg}

  • R in NmkgK\frac{\rm{Nm}}{\rm{kg}\cdot \rm{K}}

  • T in K\rm{K} (Kelvin)

In addition to the scaling factors for the volume, mass or pressure, the offset of 273.15K273.15 \rm{K} must be taken into account in the formula text when converting the temperature from °Celsius to Kelvin. The conversion from °Fahrenheit to Kelvin is even "worse".

The size equation is then, for example

p105Pa1barV1m3103l=m1kg103gR(TK°C+273.15K)p \cdot \frac{10^5 \rm{Pa}}{1 \rm{bar}} \cdot V \cdot \frac{1 \rm{m^3}}{10^3 \rm{l}} = m \cdot \frac{1 \rm{kg}}{10^3\rm{g}} \cdot R \cdot \left(T \frac{\rm{K}}{\rm{°C}} +273.15\rm{K}\right)

Even if the scaling factors can be summarized well here, good documentation of the units used and expected is essential due to the complexity!