Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: fluid dynamics #958

Merged
merged 4 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
Dynamic pressure from speed
===========================

*Dynamic pressure*, sometimes called *velocity pressure*, is a physical quantity denoting the
pressure caused by a flowing fluid. It is numerically equal to the kinetic energy of the
fluid per unit volume (see :doc:`laws.quantities.quantity_is_volumetric_density_times_volume`).
**Dynamic pressure**, sometimes called **velocity pressure**, is a physical quantity denoting the
pressure caused by a flowing fluid.

**Notes:**

Expand All @@ -16,43 +15,29 @@
#. `Wikipedia <https://en.wikipedia.org/wiki/Dynamic_pressure>`__.
"""

from sympy import (Eq, solve)
from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output)
from sympy import Eq, solve
from symplyphysics import Quantity, validate_input, validate_output, symbols

dynamic_pressure = Symbol("dynamic_pressure", units.pressure)
dynamic_pressure = symbols.dynamic_pressure
"""
Dynamic pressure of the fluid.

Symbol:
:code:`q`
:symbols:`dynamic_pressure` of the fluid.
"""

density = Symbol("density", units.mass / units.volume)
r"""
Density of the fluid.

Symbol:
:code:`rho`

Latex:
:math:`\rho`
density = symbols.density
"""

flow_speed = Symbol("flow_speed", units.velocity)
:symbols:`density` of the fluid.
"""
Flow speed of the fluid.

Symbol:
:code:`u`
flow_speed = symbols.flow_speed
"""
:symbols:`flow_speed` of the fluid.
"""

law = Eq(dynamic_pressure, density * flow_speed**2 / 2)
r"""
:code:`q = 1/2 * rho * u^2`
"""
:laws:symbol::

Latex:
.. math::
q = \frac{1}{2} \rho u^2
:laws:latex::
"""


Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,71 @@
"""
Efficiency of hydraulic press from force and height
===================================================

A real hydraulic press is never :math:`100%` efficient due to friction and other energy
losses. Its efficiency is the ratio of the useful work (given by the product of output
force and the height of the output side) to the expended work (given by the product of
input force and the height of the input side).

..
TODO: find link
"""

from sympy import Eq, solve
from symplyphysics import (
clone_as_symbol,
symbols,
units,
Quantity,
Symbol,
validate_input,
validate_output,
dimensionless,
convert_to_float,
)

# Description
## Since the hydraulic press is a mechanism, its operation can be characterized by a coefficient of efficiency.
output_force = clone_as_symbol(symbols.force, subscript="2")
"""
Output :symbols:`force`.
"""

output_distance = clone_as_symbol(symbols.euclidean_distance, subscript="2")
"""
:symbols:`euclidean_distance` covered by the output piston.
"""

input_force = clone_as_symbol(symbols.force, subscript="1")
"""
Input :symbols:`force`.
"""

## Law: n = (F2 * h2) / (F1 * h1)
## Where:
## F2 is the force spent on useful work (work on lifting the load)
## h2 is the movement of load
## F1 is expended force
## h1 is expended height
## n is coefficient of efficiency
input_distance = clone_as_symbol(symbols.euclidean_distance, subscript="1")
"""
:symbols:`euclidean_distance` covered by the input piston.
"""

# TODO find link
efficiency = symbols.mechanical_efficiency
"""
:symbols:`mechanical_efficiency` of the hydraulic press.
"""

useful_force = clone_as_symbol(symbols.force, display_symbol="F_1", display_latex="F_1")
useful_height = Symbol("useful_height", units.length)
expended_force = clone_as_symbol(symbols.force, display_symbol="F_2", display_latex="F_2")
expended_height = Symbol("expended_height", units.length)
efficiency = Symbol("efficiency", dimensionless)
law = Eq(efficiency, (output_force * output_distance) / (input_force * input_distance))
"""
:laws:symbol::

law = Eq(efficiency, (useful_force * useful_height) / (expended_force * expended_height))
:laws:latex::
"""


@validate_input(useful_force_=useful_force,
useful_height_=useful_height,
expended_force_=expended_force,
expended_height_=expended_height)
@validate_input(useful_force_=output_force,
useful_height_=output_distance,
expended_force_=input_force,
expended_height_=input_distance)
@validate_output(efficiency)
def calculate_efficiency(useful_force_: Quantity, useful_height_: Quantity,
expended_force_: Quantity, expended_height_: Quantity) -> float:
result_expr = solve(law, efficiency, dict=True)[0][efficiency]
result_efficiency = result_expr.subs({
useful_force: useful_force_,
useful_height: useful_height_,
expended_force: expended_force_,
expended_height: expended_height_
output_force: useful_force_,
output_distance: useful_height_,
input_force: expended_force_,
input_distance: expended_height_
})
return convert_to_float(result_efficiency)
36 changes: 16 additions & 20 deletions symplyphysics/laws/hydro/efflux_speed_via_height.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
Efflux speed via height
=======================

The speed of a fluid flowing out from a small orifice can be expressed as a function
of the height of the fluid column. It is also known as the *Torricelli's law*.
The speed of a fluid flowing out from a small orifice can be expressed as a function of
the height of the fluid column. It is also known as the **Torricelli's law**.

**Notation:**

#. :quantity_notation:`acceleration_due_to_gravity`.

**Conditions:**

Expand All @@ -16,32 +20,24 @@
#. `Wikipedia <https://en.wikipedia.org/wiki/Torricelli%27s_law#>`__.
"""

from sympy import (Eq, solve, sqrt)
from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output)
from sympy import Eq, solve, sqrt
from symplyphysics import Quantity, validate_input, validate_output, symbols, quantities

efflux_speed = Symbol("efflux_speed", units.velocity)
efflux_speed = symbols.flow_speed
"""
Speed of the fluid flowing out of the pipe.

Symbol:
:code:`v`
:symbols:`flow_speed` of the fluid flowing out of the pipe.
"""

height = Symbol("height", units.length)
height = symbols.height
"""
Height of the fluid column above the orifice.

Symbol:
:code:`h`
:symbols:`height` of the fluid column above the orifice.
"""

law = Eq(efflux_speed, sqrt(2 * units.acceleration_due_to_gravity * height))
r"""
:code:`v = sqrt(2 * g * h)`
law = Eq(efflux_speed, sqrt(2 * quantities.acceleration_due_to_gravity * height))
"""
:laws:symbol::

Latex:
.. math::
v = \sqrt{2 g h}
:laws:latex::
"""

# TODO Derive from Bernoulli's equation and constancy of volume flux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,32 @@
TODO find link
"""

from sympy import (Eq, solve, sqrt)
from symplyphysics import (
units,
Quantity,
Symbol,
validate_input,
validate_output,
)
from sympy import Eq, solve, sqrt
from symplyphysics import Quantity, validate_input, validate_output, symbols
from symplyphysics.core.expr_comparisons import expr_equals
from symplyphysics.laws.hydro import hydrostatic_pressure_via_density_and_height as pressure_law
from symplyphysics.laws.hydro import efflux_speed_via_height as velocity_law

efflux_speed = Symbol("efflux_speed", units.velocity)
efflux_speed = symbols.flow_speed
"""
Speed of the fluid flowing out of the pipe.

Symbol:
:code:`v`
:symbols:`flow_speed` of the fluid flowing out of the pipe.
"""

hydrostatic_pressure = Symbol("hydrostatic_pressure", units.pressure)
hydrostatic_pressure = symbols.hydrostatic_pressure
"""
Hydrostatic pressure of the fluid.

Symbol:
:code:`p`
:symbols:`hydrostatic_pressure` of the fluid.
"""

density = Symbol("density", units.mass / units.volume)
r"""
Density of the fluid.

Symbol:
:code:`rho`

Latex:
:math:`\rho`
density = symbols.density
"""
:symbols:`density` of the fluid.
"""

law = Eq(efflux_speed, sqrt(2 * hydrostatic_pressure / density))
r"""
:code:`v = sqrt(2 * p / rho)`
"""
:laws:symbol::

Latex:
.. math::
v = \sqrt{\frac{2 p}{\rho}}
:laws:latex::
"""

# This law might be derived via "hydrostatic_pressure_from_density_and_depth" law
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,73 @@
from sympy import (Eq, solve)
from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output)
from symplyphysics.core.expr_comparisons import expr_equals
"""
Excess pressure under curved surface of bubble
==============================================

from symplyphysics.laws.thermodynamics import laplace_pressure_of_spherical_shapes as laplace_law
Under the curved surface of the liquid, in addition to the internal pressure, additional
pressure is created due to the curvature of the surface. For a bubble, this pressure is
created by two surfaces: the outer and the inner.

**Links:**

#. `Physics LibreTexts, formula 20.2.4 <https://phys.libretexts.org/Bookshelves/Classical_Mechanics/Classical_Mechanics_(Tatum)/20%3A_Miscellaneous/20.02%3A_Surface_Tension/20.2.01%3A_Excess_Pressure_Inside_Drops_and_Bubbles>`__.

# Description
## Under the curved surface of the liquid, in addition to the internal pressure,
## additional pressure is created due to the curvature of the surface.
## For a bubble, this pressure is created by two surfaces: the outer and the inner.
..
TODO: fix file name
"""

from sympy import Eq, solve
from symplyphysics import Quantity, validate_input, validate_output, symbols, clone_as_symbol
from symplyphysics.core.expr_comparisons import expr_equals
from symplyphysics.laws.thermodynamics import laplace_pressure_of_spherical_shapes as laplace_law

## Law is: p = 4 * sigma / R, where
## p - excessive pressure under the curved surface of bubble,
## sigma - surface tension of the liquid,
## R - radius of bubble.
pressure_difference = clone_as_symbol(symbols.pressure, display_symbol="Delta(p)", display_latex="\\Delta p")
"""
:symbols:`pressure` difference between the surfaces of the bubble.
"""

# Links: Physics LibreTexts, formula 20.2.4 <https://phys.libretexts.org/Bookshelves/Classical_Mechanics/Classical_Mechanics_(Tatum)/20%3A_Miscellaneous/20.02%3A_Surface_Tension/20.2.01%3A_Excess_Pressure_Inside_Drops_and_Bubbles>
surface_tension = symbols.surface_tension
"""
:symbols:`surface_tension` of the bubble.
"""

excessive_pressure = Symbol("excessive_pressure", units.pressure)
radius = symbols.radius
"""
:symbols:`radius` of the bubble.
"""

surface_tension_of_the_liquid = Symbol("surface_tension_of_the_liquid", units.force / units.length)
radius_of_bubble = Symbol("radius_of_bubble", units.length)
law = Eq(pressure_difference, 4 * surface_tension / radius)
"""
:laws:symbol::

law = Eq(excessive_pressure, 4 * surface_tension_of_the_liquid / radius_of_bubble)
:laws:latex::
"""

# This law might be derived via Laplace law.

# TODO prefix all variables used in proof with underscore

laplace_law_applied = laplace_law.law.subs({
laplace_law.surface_tension: surface_tension_of_the_liquid,
laplace_law.radius_of_curvature: radius_of_bubble
_laplace_law_applied = laplace_law.law.subs({
laplace_law.surface_tension: surface_tension,
laplace_law.radius_of_curvature: radius
})

# This is an excess pressure in a spherical drop.
pressure_derived = solve(laplace_law_applied, laplace_law.laplace_pressure,
_pressure_derived = solve(_laplace_law_applied, laplace_law.laplace_pressure,
dict=True)[0][laplace_law.laplace_pressure]

# Check if derived pressure is same as declared.
# The bubble has two surfaces – an outer and an inner one, each of which creates additional pressure.
# Therefore, an additional multiplier of "2" appears.
assert expr_equals(2 * pressure_derived, law.rhs)
assert expr_equals(2 * _pressure_derived, law.rhs)


@validate_input(surface_tension_of_the_liquid_=surface_tension_of_the_liquid,
radius_of_bubble_=radius_of_bubble)
@validate_output(excessive_pressure)
@validate_input(surface_tension_of_the_liquid_=surface_tension,
radius_of_bubble_=radius)
@validate_output(pressure_difference)
def calculate_excessive_pressure(surface_tension_of_the_liquid_: Quantity,
radius_of_bubble_: Quantity) -> Quantity:
solved = solve(law, excessive_pressure, dict=True)[0][excessive_pressure]
solved = solve(law, pressure_difference, dict=True)[0][pressure_difference]
result_expr = solved.subs({
surface_tension_of_the_liquid: surface_tension_of_the_liquid_,
radius_of_bubble: radius_of_bubble_
surface_tension: surface_tension_of_the_liquid_,
radius: radius_of_bubble_
})
return Quantity(result_expr)
Loading