Re: [std-proposals] On the standardization of mp-units P3045R1

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Tue, 18 Jun 2024 14:41:59 +0100
On 18/06/2024 13:28, Tiago Freire via Std-Proposals wrote:
> Hi, I will be participating in St. Louis.
>
> And one of the papers that interested me was P3045R1, unfortunately I
> may or may not be on time to participate in this particular session.
>
> There’s this question that I would like an answer too, and I wonder if
> there is anyone who will be attending St. Louis who would be willing to
> make this question on my behalf:
>
> A lab worker puts in 40Kg of dry ice into a 1 cubic meter pressure tank
> rated for 10atm, they then vacuum the tank and seal it.
>
> As the CO2 warms up to room temperature (which at a specific date was
> 28°C) it evaporates, and eventually following the ideal gas law:
>
> PV=nRT
>
> Is this setup dangerous?
>
> Using mp-units (with the exact same design as the one being proposed for
> standardization) to solve this problem:
>
> ```
>
> quantity Volume = 1.0 * m*m*m;
>
> quantity Temperature = (28.0 * deg_C).in(K);
>
> quantity n_ = 0.04401 * kg / mol;
>
> quantity R_boltzman = 8.314 * N * m / (K * mol);
>
> quantity mass = 40.0 * kg;
>
> quantity Pressure = R_boltzman * Temperature * mass / n_ / Volume;
>
> std::cout << Pressure << std::endl;
>
> ```
>
> We get the following result:
>
> `211581 N/m2`
>
> (=211.581kPa = 2,09 atm)
>
> But the correct answer is actually: 2275.629kPa = 22.5 atm

Ouch, this does look underhanded. I am not overly familiar with mp-units
and other unit libraries, however I am a Physicist so I feel qualified
to comment about Celsius and Kelvins.

In my opinion the units and °C and K are inherently poorly handled in
Engineering and Physics as notations, and they convert differently in
different contexts. Mainly when they denote *the* temperature of an
object/system or they denote a temperature difference (which for example
can be the difference of temperatures of the same object at different
times or temperatures of distinct objects at the same).

This context can be very implicit, like specific heat is expressed in
kJ/(kg * °C) or kJ/(kg * K), which are equivalent units, as the
temperature units here denote the same temperature difference.

It looks like the syntax required for using mp-units implies a default
context here: quantities are relative by default. Absolute quantities
live in a more abstract Euclidean point space.

This might be mathematically sound, but having a default here enables
the bug that you described above.

>
> (11 time s higher than what mp-units calculated)
>
> How is this considered a design feature and not a bug? (note that other
> similar libraries don’t have this problem)

I wonder how other libraries deal with temperature differences.

There is an analogous Δp V = nRΔT equation, where Δp is pressure-change
and ΔT is temperature-change. Here the 1°C = 1K unit conversion is the
correct one.

Similarly the specific heat of water is 4184 kJ/(kg * °C) or 4184 kJ/(kg
* K), these should convert one-to-one.

I don't think that there is a nice solution that could simultaneously
solve all of these problems concisely with implicit contexts. And at
that point maybe this context should be spelled out everywhere.

I really should dig into this paper more, but I also have a lot on my
plate. In the BSI we had a discussion about these issues, but we didn't
have such a nice example, so thank you for that. I will point them to
this discussion.

>
> And how do the authors think this design choice impacts on safety and
> user-friendliness?
>
> Thanks.
>
>