summaryrefslogtreecommitdiff
path: root/docs/pitheorem.rst
blob: cd37165282676a4ba9668e266bee886a22ab6f04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
.. _pitheorem:

Buckingham Pi Theorem
=====================

`Buckingham π theorem`_ states that an equation involving *n* number of
physical variables which are expressible in terms of *k* independent fundamental
physical quantities can be expressed in terms of *p = n - k* dimensionless
parameters.

.. testsetup:: *

   from pint import UnitRegistry
   ureg = UnitRegistry()
   Q_ = ureg.Quantity

To start with a very simple case, consider that you want to find a dimensionless
quantity involving the magnitudes `V`, `T` and `L` with dimensions `[length]/[time]`,
`[time]` and `[length]` respectively.

.. doctest::

    >>> from pint import pi_theorem
    >>> pi_theorem({'V': '[length]/[time]', 'T': '[time]', 'L': '[length]'})
    [{'V': 1.0, 'T': 1.0, 'L': -1.0}]

The result indicates that a dimensionless quantity can be obtained by
multiplying `V` by `T` and the inverse of `L`.

Which can be pretty printed using the `Pint` formatter:

.. doctest::

    >>> from pint import formatter
    >>> result = pi_theorem({'V': '[length]/[time]', 'T': '[time]', 'L': '[length]'})
    >>> print(formatter(result[0].items()))
    T * V / L

You can also apply the Buckingham π theorem associated to a Registry. In this case,
you can use derived dimensions such as speed:

.. doctest::

    >>> from pint import UnitRegistry
    >>> ureg = UnitRegistry()
    >>> ureg.pi_theorem({'V': '[speed]', 'T': '[time]', 'L': '[length]'})
    [{'V': 1.0, 'T': 1.0, 'L': -1.0}]

or unit names:

.. doctest::

    >>> ureg.pi_theorem({'V': 'meter/second', 'T': 'second', 'L': 'meter'})
    [{'V': 1.0, 'T': 1.0, 'L': -1.0}]

or quantities:

    >>> Q_ = ureg.Quantity
    >>> ureg.pi_theorem({'V': Q_(1, 'meter/second'),
    ...                  'T': Q_(1, 'second'),
    ...                  'L': Q_(1, 'meter')})
    [{'V': 1.0, 'T': 1.0, 'L': -1.0}]


Application to the pendulum
---------------------------

There are 3 fundamental physical units in this equation: time, mass, and length, and 4 dimensional variables, T (oscillation period), M (mass), L (the length of the string), and g (earth gravity). Thus we need only 4 − 3 = 1 dimensionless parameter.

.. doctest::

    >>> ureg.pi_theorem({'T': '[time]',
    ...                  'M': '[mass]',
    ...                  'L': '[length]',
    ...                  'g': '[acceleration]'})
    [{'T': 2.0, 'L': -1.0, 'g': 1.0}]

which means that the dimensionless quantity is:

.. math::

   \Pi = \frac{g T^2}{L}

and therefore:

.. math::

    T = constant \sqrt{\frac{L}{g}}

(In case you wonder, the constant is equal to 2 π, but this is outside the scope of this help)


Pressure loss in a pipe
-----------------------

What is the pressure loss `p` in a pipe with length `L` and diameter `D` for a fluid with density `d`, and viscosity `m` travelling with speed `v`? As pressure, mass, volume, viscosity and speed are defined as derived dimensions in the registry, we only need to explicitly write the density dimensions.

.. doctest::

    >>> ureg.pi_theorem({'p': '[pressure]',
    ...                  'L': '[length]',
    ...                  'D': '[length]',
    ...                  'd': '[mass]/[volume]',
    ...                  'm': '[viscosity]',
    ...                  'v': '[speed]'
    ...                  })                             # doctest: +SKIP
    [{'p': 1.0, 'm': -2.0, 'd': 1.0, 'L': 2.0}, {'v': 1.0, 'm': -1.0, 'd': 1.0, 'L': 1.0}, {'L': -1.0, 'D': 1.0}]

The second dimensionless quantity is the `Reynolds Number`_

.. _`Buckingham π theorem`: http://en.wikipedia.org/wiki/Buckingham_%CF%80_theorem
.. _`Reynolds Number`: http://en.wikipedia.org/wiki/Reynolds_number