Skip to content

Tortilla #7201

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

Closed
wants to merge 7 commits into from
Closed
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
Empty file added physics/Bernoullis_equation.py
Empty file.
41 changes: 41 additions & 0 deletions physics/Torricelli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Calculates velocity of fluid from Potential Gravitational Energy

Equation for finding velocity
V = sqrt(2 * gravity * Δy)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
V = sqrt(2 * gravity * Δy)
Velocity = sqrt(2 * Acceleration due to gravity * Height)


Source:
- https://en.wikipedia.org/wiki/Archimedes%27_principle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- https://en.wikipedia.org/wiki/Archimedes%27_principle
- https://en.wikipedia.org/wiki/Torricelli%27s_law

"""


# Acceleration Constant on Earth (unit m/s^2)
g = 9.80665


def torricelli_theorem(height: float, gravity: float = g) -> float:
"""
Args:
height: The change in height between initial and point of flow (where,
velocity is being measured)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention the unit of height used.

gravity: Acceleration from gravity. Gravitational force on system,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gravity: Acceleration from gravity. Gravitational force on system,
gravity: Acceleration due to gravity. Gravitational force on system,

Default is Earth Gravity
returns:
velocity of exiting fluid.

>>> torricelli_theorem(height=5)
9.90285312422637
>>> torricelli_theorem(height=3, gravity=9.8)
7.6681158050723255
"""
if gravity <= 0:
raise ValueError("Impossible Gravity")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ValueError("Impossible Gravity")
raise ValueError("The value of g cannot be equal or smaller than 0.")


return (2 * height * gravity) ** 0.5


if __name__ == "__main__":
import doctest

# run doctest
doctest.testmod()
49 changes: 49 additions & 0 deletions physics/archimedes_principle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Calculates buoyant force on object submerged within static fluid.
Discovered by greek mathematician, Archimedes. The principle is named after him.

Equation for calculating buoyant force:
Fb = ρ * V * g

Source:
- https://en.wikipedia.org/wiki/Archimedes%27_principle
"""


# Acceleration Constant on Earth (unit m/s^2)
g = 9.80665


def archimedes_principle(
fluid_density: float, volume: float, gravity: float = g
) -> float:
"""
Args:
fluid_density: density of fluid (kg/m^3)
volume: volume of object / liquid being displaced by object
gravity: Acceleration from gravity. Gravitational force on system,
Default is Earth Gravity
returns:
buoyant force on object in Newtons

>>> archimedes_principle(fluid_density=997, volume=0.5, gravity=9.8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default value of g is 9.8, you can add a new test case for value of g different than 9.8; otherwise, it seems redundant.

4885.3
>>> archimedes_principle(fluid_density=997, volume=0.7)
6844.061035
"""

if fluid_density <= 0:
raise ValueError("Impossible fluid density")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ValueError("Impossible fluid density")
raise ValueError("Fluid density cannot be equal or smaller than 0.")

if volume < 0:
raise ValueError("Impossible Object volume")
if gravity <= 0:
raise ValueError("Impossible Gravity")
Comment on lines +38 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise ValueError("Impossible Object volume")
if gravity <= 0:
raise ValueError("Impossible Gravity")
raise ValueError("Object volume cannot smaller than 0")
if gravity <= 0:
raise ValueError("Acceleration due to gravity cannot be equal or smaller than 0.")


return fluid_density * gravity * volume


if __name__ == "__main__":
import doctest

# run doctest
doctest.testmod()