zsh-workers
 help / color / mirror / code / Atom feed
* zsh functions, bicycle tire and gas law (PV = nRT)
@ 2020-04-24 17:31 Emanuel Berg
  2020-04-24 21:26 ` Emanuel Berg
  0 siblings, 1 reply; 2+ messages in thread
From: Emanuel Berg @ 2020-04-24 17:31 UTC (permalink / raw)
  To: zsh-workers

Hello guys, what do you think of this? After the code
are some notes I wrote on IRC while I wrote it.
There are some general zsh questions there, as well. TIA

#! /bin/zsh
#
# this file:
#   http://user.it.uu.se/~embe8573/conf/.zsh/air
#   https://dataswamp.org/~incal/conf/.zsh/air
#
# Let's model an inflated bicycle tube/tire in the form
# of a torus, as in this figure: [1]
#
# We use the ISO ETRTO notation for bicycle tire sizes.
# For example, a typical "twenty-niner" MTB tire is
# a 54-622 tire, where 54 is the tire width and 622 the
# rim Bead Seat Diameter. See [2]. We denote these (w)
# and (b).
#
# Comparing [1] and [2], we understand that
#
#   r = w/2
#
# and
#
#   R = b/2 + r
#
#   R = b/2 + w/2
#
# with the volume of a torus being
#
#   V = 2 * pi^2 * R * r^2
#
#   V = 2 * pi^2 * (b/2 + w/2) * (w/2)^2
#
#   V = pi^2w(b+w^2)/4

bike-tire-volume () {
    local width=$1
    local bsd=$2
    local pi=3.1415
    local vmm=$(( $pi**2 * $width * ($bsd + $width**2) / 4 ))
    local vcm=$(units -t "$vmm mm3" cm3)
    local rvcm=$(( rint($vcm) ))
    printf "V = %d cm3\n" $rvcm
    return $rvcm
}

# Assuming air behaves like a gas at the intended
# preassure, we use the ideal gas law, PV = nRT. We just
# have to change the units a bit and then compute.

bike-tire-air () {
    local width=$1
    local bsd=$2
    local psi=$3
    bike-tire-volume $width $bsd
    local vcm=$?

    local p=$(units -t "$psi psi" atm)
    local v=$(units -t "$vcm cm3" liters)
    local t=290.45 # [*]
    local r=0.0821

    local n=$(( ($p * $v) / ($r * $t) ))

    printf "%f moles of air gas\n" $n

    # [*] 290.45K = 17.3C, the average temperature in Liège in July,
    #     the hottest month of the year. Seems like good for cycling.
    # <https://en.climate-data.org/europe/belgium/wallonia/liege-6396>
}

# Example invocations:

# $ bike-tire-volume 57 622
# $ V = 544 cm3

# $ bike-tire-air 57 622 65
# $ V = 544 cm3
# $ 0.100902 moles of air gas


# [1] https://www.mathsisfun.com/geometry/torus.html
#
# [2] https://dataswamp.org/~incal/bike/tire-size.png


IRC notes:

<incal> if my calculations are correct, the volume of/in
        an inflated bicycle tube/tire is pi^2w(b+w^2)/4
        where b is the rim BSD and w the tire width
        <https://dataswamp.org/~incal/bike/tire-size.png>
        if one has the volume, as well as the preassure
        (written on the tire), one can use the ideal gas
        law (or general gas equation) which is PV = nRT,
        solve n to get the number of moles! in the
        cycling press they like to say that the width of
        the tire isn't what
            
<incal> determines the level of comfort, it is the
        quality of the tire and the amount of air in it.
        the scientific definition of quality is TPI
        (threads per inch) but if that is understood in
        the mundane sense and can be ignored it means
        they are wrong, the amount of air is actually
        determined by two components, one of which is
        derived from the tire width, and both of which
        are actually readily available, stated on the
        tire! (preassure in

<incal> PSI/kPa/bar tho, in PV = nRT in atm; volume in
        liter) ... _I think_! I'm not so strong in
        science ...

<incal> it seems you can't do ^ in zsh, maybe
        that's XOR, ** seems to work tho: $pi**2 * $w *
        ($b + $w**2) / 4

<incal> how is it with shell programming, is it OK to
        return data or should you just return if the
        program successfully finished or not?

<incal> units(1) seem to have special rules for
        temperature, $ units -t "tempC(17.3)" # 290.45
        K # +17.3C, the average temperature in Liège in
        July, the hottest month of the year
        <https://en.climate-data.org/europe/belgium/wallonia/liege-6396/>

<incal> https://dataswamp.org/~incal/conf/.zsh/air # but
        I should verify that air really behaves like
        a gas at the intended preassure before I send it
        to the snobbish bike magazine and try to own
        them

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: zsh functions, bicycle tire and gas law (PV = nRT)
  2020-04-24 17:31 zsh functions, bicycle tire and gas law (PV = nRT) Emanuel Berg
@ 2020-04-24 21:26 ` Emanuel Berg
  0 siblings, 0 replies; 2+ messages in thread
From: Emanuel Berg @ 2020-04-24 21:26 UTC (permalink / raw)
  To: zsh-workers

Some interesting data from this program [1], especially
the meagre improvements from switching from 23 to 25 -
not even 3% more air!

# MTB twenty-niner, 57-622 65 PSI
# $ bike-tire-air 57 622 65
# $ V = 544 cm3
# $ 0.100902 moles of air gas

# road bike, maximum PSI, 23-622 145 PSI
# $ bike-tire-air 23 622 145
# $ V = 65 cm3
# $ 0.026895 moles of air gas
# (/ 0.026895 0.100902) ; 26% of MTB tire air

# road bike, realistic PSI for ~80 kg rider, 23-622 115 PSI
# $ bike-tire-air 23 622 115
# V = 65 cm3
# 0.021330 moles of air gas
# (/ 0.021330 0.100902) ; 21%

# road bike: is it worth upgrading from 23 mm to 25 mm?
# $ bike-tire-air 23 622 115
# V = 65 cm3
# 0.021330 moles of air gas
# $ bike-tire-air 25 622 100
# V = 77 cm3
# 0.021972 moles of air gas
# (- 100 (* 100 (/ 0.021330 0.021972))) ; 2.9% improvement! :O

# budget tires
# $ bike-tire-air 28 622 85
# V = 97 cm3
# 0.023528 moles of air gas
# (/ 0.023528 0.100902) ; 23%


[1] https://dataswamp.org/~incal/conf/.zsh/air

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-24 21:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-24 17:31 zsh functions, bicycle tire and gas law (PV = nRT) Emanuel Berg
2020-04-24 21:26 ` Emanuel Berg

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).