Search code examples
maximawxmaxima

ezunits not so ez -- ideal gas


I'm having lots of problems with ezunits, can't seem to get the units and their conversions right. One should calculate the volume of 2 tanks at 20°C which are filled with 6kg H_2 at 700bar relative pressure.

The total volume should be 0.103 m^3 and the volume for one tank should be 51.5 l.

That's what I get in Wxmaxima: https://ibb.co/6P91kYk

My code:

/* [ Created with wxMaxima version 20.06.6 ] */
/* [wxMaxima: input   start ] */
kill(all); load(ezunits);
/* [wxMaxima: input   end   ] */

/* [wxMaxima: section start ]
Brennstoffzellenfahrzeug H_2, 2 Tanks, T=20°C, p_rel=700bar, m=6kg. Welches Volumen hat ein Tank?
   [wxMaxima: section end   ] */


/* [wxMaxima: input   start ] */
T: 273.15`K+20`deg; p_rel: 700`bar; RR:8.314`J/(mol*K); m: 6`kg;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
p: p_rel+1`bar;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
p: p``N/m^2;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
M_H_2:2*1.01`g/mol;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
R: RR/M_H_2;
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
kill(V); dimensionally(solve(p*V=m*R*T,V)); V: rhs(%[1]);
/* [wxMaxima: input   end   ] */


/* [wxMaxima: input   start ] */
V_tank: V/2;
/* [wxMaxima: input   end   ] */


/* Old versions of Maxima abort on loading files that end in a comment. */
"Created with wxMaxima 20.06.6"$

Solution

  • Some things I see that you can try.

    (1) bar isn't a built-in unit. Try: declare_unit_conversion(1 ` bar = 101325 ` Pa)

    (2) To convert 20 degrees Celsius, try: T: 20 ` degC `` K.

    (3) Here m appears as a variable, and also the unit m. Rename the variable m to m_tank or something.

    (4) Units aren't automatically reduced to basic units. Try: fundamental_units(V_tank); and then V_tank `` fundamental_units(V_tank);

    Here's what I get after those changes:

    (%i3) load(ezunits)
    (%o3) /usr/local/Cellar/maxima/5.44.0/share/maxima/5.44.0/share/\
    ezunits/ezunits.mac
    (%i4) declare_unit_conversion(1 ` bar = 101325 ` Pa)
    (%o4)                         done
    (%i5) T:20 ` degC `` K
                                5863
    (%o5)                       ---- ` K
                                 20
    (%i6) p_rel:700 ` bar
    (%o6)                       700 ` bar
    (%i7) RR:8.314 ` J/(mol*K)
                                        J
    (%o7)                     8.314 ` -----
                                      K mol
    (%i8) m_tank:6 ` kg
    (%o8)                        6 ` kg
    (%i9) p:p_rel+1 ` bar
    (%o9)                       701 ` bar
    (%i10) p:p `` N/m^2
                                         N
    (%o10)                    71028825 ` --
                                          2
                                         m
    (%i11) M_H_2:2*1.01 ` g/mol
                                       g
    (%o11)                     2.02 ` ---
                                      mol
    (%i12) R:RR/M_H_2
                                              J
    (%o12)               4.115841584158416 ` ---
                                             K g
    (%i13) kill(V)
    (%o13)                        done
    (%i14) dimensionally(solve(p*V = m_tank*R*T,V))
    
    rat: replaced -7239.353762376237 by -73117473/10100 = -7239.353762376238
                                                2
                             24372491     J kg m
    (%o14)            [V = ------------ ` -------]
                           239130377500     N g
    (%i15) V:rhs(%[1])
                                              2
                           24372491     J kg m
    (%o15)               ------------ ` -------
                         239130377500     N g
    (%i16) V_tank:V/2
                                              2
                           24372491     J kg m
    (%o16)               ------------ ` -------
                         478260755000     N g
    (%i17) fundamental_units(V_tank)
                                    3
    (%o17)                         m
    (%i18) V_tank `` fundamental_units(V_tank)
                             24372491     3
    (%o18)                   --------- ` m
                             478260755
    (%i19) float(%)
                                               3
    (%o19)              0.05096067520739811 ` m