Repository: PlasmaPy/PlasmaPy
Pull request #815 (2020-05-21 22:52:50)

Reynolds
<!--
Thank you for contributing to PlasmaPy! Here's a bunch of pointers to
make things easier for all of us:

* If this PR will solve an issue tracked by GitHub, please add a phrase like
  "Closes #404." to automatically close the issue once the pull request is
  merged.  If your PR will not completely solve the issue, please still
  reference the issue. For an overview of this functionality, see
  https://help.github.com/articles/closing-issues-using-keywords/

* Remember to add some description of your changes in this text box.

* Tests and docstrings are required for new or changed functionality.
  Please make sure tests are passing before requesting a review - they
  will pop up at the bottom, in the Checks box. If you're unsure why
  they're failing, ask!
  
* If your pull request is not yet ready for review, submit it as a draft.
  Remember to change its' status once it's ready.

* If this is your first contribution, please add your name to the author
  list in `docs/about/credits.rst`.
  
* Feel free to chat with other developers on our Matrix channel at:
   https://riot.im/app/#/room/#plasmapy:openastronomy.org
  
* We have a developer's guide, where some answers to your questions may
  possibly be found, at
  http://docs.plasmapy.org/en/master/development/index.html

Many thanks in advance for following these pointers and for being willing to contribute!

When submitting a pull request, please ensure that you can (eventually,
sometime before it is merged) check the following basic requirements:

-->

- [x] I have added a changelog entry for this pull request (please see
  `changelog/README.rst` for instructions, and if you need help with picking the PR type, ask!)
- [x] If adding new functionality, I have added (passing) tests and
      docstrings. (Tests pop up at the bottom, in the checks box).
- [x] I have fixed any new failing tests (if you're unsure why
  they're failing, ask!).

This Pull request partially solves #49 and covers part of #769 

pep8speaks: Hello @KhalilBryant! Thanks for submitting your pull request.

* In the file [`plasmapy/formulary/dimensionless.py`](https://github.com/PlasmaPy/PlasmaPy/blob/f69deb7c605adfba528013f201762e7d019c7867/plasmapy/formulary/dimensionless.py):

> [Line 94:23](https://github.com/PlasmaPy/PlasmaPy/blob/f69deb7c605adfba528013f201762e7d019c7867/plasmapy/formulary/dimensionless.py#L94): [E251](https://duckduckgo.com/?q=pep8%20E251) unexpected spaces around keyword / parameter equals
> [Line 94:25](https://github.com/PlasmaPy/PlasmaPy/blob/f69deb7c605adfba528013f201762e7d019c7867/plasmapy/formulary/dimensionless.py#L94): [E251](https://duckduckgo.com/?q=pep8%20E251) unexpected spaces around keyword / parameter equals
> [Line 95:100](https://github.com/PlasmaPy/PlasmaPy/blob/f69deb7c605adfba528013f201762e7d019c7867/plasmapy/formulary/dimensionless.py#L95): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (116 > 99 characters)
> [Line 97:100](https://github.com/PlasmaPy/PlasmaPy/blob/f69deb7c605adfba528013f201762e7d019c7867/plasmapy/formulary/dimensionless.py#L97): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (101 > 99 characters)
> [Line 99:100](https://github.com/PlasmaPy/PlasmaPy/blob/f69deb7c605adfba528013f201762e7d019c7867/plasmapy/formulary/dimensionless.py#L99): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (119 > 99 characters)





PlasmaPy follows the [PEP8 style guide](https://www.python.org/dev/peps/pep-0008/), which may be checked locally using [pycodestyle](http://pycodestyle.pycqa.org/en/latest/intro.html)
codecov[bot]: # [Codecov](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815?src=pr&el=h1) Report
> Merging [#815](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815?src=pr&el=desc) into [master](https://codecov.io/gh/PlasmaPy/PlasmaPy/commit/b20e47b631b403242e56569ef69c4bf785e479b9&el=desc) will **decrease** coverage by `0.06%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/graphs/tree.svg?width=650&height=150&src=pr&token=LzZ5mnXVad)](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #815      +/-   ##
==========================================
- Coverage   95.87%   95.80%   -0.07%     
==========================================
  Files          56       56              
  Lines        5113     5080      -33     
==========================================
- Hits         4902     4867      -35     
- Misses        211      213       +2     
```


| [Impacted Files](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [plasmapy/formulary/relativity.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree#diff-cGxhc21hcHkvZm9ybXVsYXJ5L3JlbGF0aXZpdHkucHk=) | `100.00% <ø> (ø)` | |
| [plasmapy/formulary/dimensionless.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree#diff-cGxhc21hcHkvZm9ybXVsYXJ5L2RpbWVuc2lvbmxlc3MucHk=) | `100.00% <100.00%> (ø)` | |
| [plasmapy/classes/plasma\_base.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree#diff-cGxhc21hcHkvY2xhc3Nlcy9wbGFzbWFfYmFzZS5weQ==) | `67.74% <0.00%> (-4.49%)` | :arrow_down: |
| [plasmapy/simulation/abstractions.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree#diff-cGxhc21hcHkvc2ltdWxhdGlvbi9hYnN0cmFjdGlvbnMucHk=) | `75.00% <0.00%> (-2.78%)` | :arrow_down: |
| [plasmapy/classes/sources/openpmd\_hdf5.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree#diff-cGxhc21hcHkvY2xhc3Nlcy9zb3VyY2VzL29wZW5wbWRfaGRmNS5weQ==) | `78.40% <0.00%> (-1.17%)` | :arrow_down: |
| [plasmapy/utils/decorators/checks.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree#diff-cGxhc21hcHkvdXRpbHMvZGVjb3JhdG9ycy9jaGVja3MucHk=) | `99.40% <0.00%> (-0.60%)` | :arrow_down: |
| [plasmapy/simulation/particletracker.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree#diff-cGxhc21hcHkvc2ltdWxhdGlvbi9wYXJ0aWNsZXRyYWNrZXIucHk=) | `98.27% <0.00%> (-0.03%)` | :arrow_down: |
| [plasmapy/particles/ionization\_state.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree#diff-cGxhc21hcHkvcGFydGljbGVzL2lvbml6YXRpb25fc3RhdGUucHk=) | `92.91% <0.00%> (-0.03%)` | :arrow_down: |
| [plasmapy/utils/pytest\_helpers/pytest\_helpers.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree#diff-cGxhc21hcHkvdXRpbHMvcHl0ZXN0X2hlbHBlcnMvcHl0ZXN0X2hlbHBlcnMucHk=) | `93.38% <0.00%> (-0.03%)` | :arrow_down: |
| [plasmapy/particles/particle\_class.py](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree#diff-cGxhc21hcHkvcGFydGljbGVzL3BhcnRpY2xlX2NsYXNzLnB5) | `95.73% <0.00%> (-0.01%)` | :arrow_down: |
| ... and [6 more](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815?src=pr&el=footer). Last update [b20e47b...8572aec](https://codecov.io/gh/PlasmaPy/PlasmaPy/pull/815?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/changelog/815.feature.rst b/changelog/815.feature.rst
new file mode 100644
index 00000000..43640175
--- /dev/null
+++ b/changelog/815.feature.rst
@@ -0,0 +1,1 @@
+Create :func:`~plasmapy.formulary.dimensionless.Reynolds_number` function.
diff --git a/plasmapy/formulary/dimensionless.py b/plasmapy/formulary/dimensionless.py
index 1ec7a040..8ccb96b1 100644
--- a/plasmapy/formulary/dimensionless.py
+++ b/plasmapy/formulary/dimensionless.py
@@ -8,11 +8,11 @@
 highly turbulent, while turbulence is negligible at low Reynolds
 numbers.
 """
-__all__ = ["beta", "quantum_theta"]
+__all__ = ["beta", "quantum_theta", "Reynolds_number"]
 
 from astropy import constants
 from astropy import units as u
-from plasmapy.formulary import quantum, parameters
+from plasmapy.formulary import quantum, parameters, electron_viscosity
 from plasmapy.utils.decorators import validate_quantities
 
 
@@ -89,3 +89,71 @@ def beta(T: u.K, n: u.m ** -3, B: u.T) -> u.dimensionless_unscaled:
     thermal_pressure = parameters.thermal_pressure(T, n)
     magnetic_pressure = parameters.magnetic_pressure(B)
     return thermal_pressure / magnetic_pressure
+
+
+@validate_quantities(v={"can_be_negative": True})
+def Reynolds_number(rho: u.kg / u.m ** 3, v: u.m / u.s, L: u.m,
+                    mu: u.kg / (u.m * u.s)) -> u.dimensionless_unscaled:
+    r"""
+    The Reynold's Number is a dimensionless quantity
+    that is used to predict flow patterns in fluids.
+    The Reynold's Number is defined as the ratio of inertial forces to viscous forces.
+    A low Reynold's Number describes smooth, laminar flow
+    while a high Reynold's Number describes rough, turbulent flow.
+
+    .. math::
+
+        Re = \frac{\rho v L }{\mu}
+
+    Parameters
+    ----------
+    rho : `~astropy.units.Quantity`
+        The density of the plasma.
+    v : `~astropy.units.Quantity`
+        The flow velocity of the plasma.
+    L : `~astropy.units.Quantity`
+        The characteristic length scale.
+    mu : `~astropy.units.Quantity`
+        The dynamic viscosity of the plasma.
+
+     Warns
+    -----
+    ~astropy.units.UnitsWarning
+        If units are not provided, SI units are assumed.
+
+    Raises
+    ------
+    TypeError
+        The `v` is not a `~astropy.units.Quantity` and cannot be
+        converted into a ~astropy.units.Quantity.
+
+    ~astropy.units.UnitConversionError
+        If the `v` is not in appropriate units.
+
+    :exc:`~plasmapy.utils.exceptions.RelativityError`
+        If the velocity `v` is greater than the speed of light.
+
+    Examples
+    --------
+    >>> import astropy.units as u
+    >>> rho = 1000 * u.kg / u.m ** 3
+    >>> v = 10 * u.m / u.s
+    >>> L = 1 * u.m
+    >>> mu = 8.9e-4 * u.kg / (u.m * u.s)
+    >>> Reynolds_number(rho, v, L, mu)
+    <Quantity 11235955.05617978>
+    >>> rho = 1490 * u.kg / u.m ** 3
+    >>> v = 0.1 * u.m / u.s
+    >>> L = 0.05 * u.m
+    >>> mu = 10 * u.kg / (u.m * u.s)
+    >>> Reynolds_number(rho, v, L, mu)
+    <Quantity 0.745>
+
+    Returns
+    -------
+    Re: `~astropy.Quantity`
+        Dimensionless quantity.
+
+    """
+    Re = abs(rho * v * L / mu)
+    return Re
diff --git a/plasmapy/formulary/relativity.py b/plasmapy/formulary/relativity.py
index 1bc83527..163087ec 100644
--- a/plasmapy/formulary/relativity.py
+++ b/plasmapy/formulary/relativity.py
@@ -16,6 +16,7 @@ def Lorentz_factor(V: u.m / u.s):
 
     Parameters
     ----------
+
     V : ~astropy.units.Quantity
         The velocity in units convertible to meters per second.
 


Test patch:
diff --git a/plasmapy/formulary/tests/test_dielectric.py b/plasmapy/formulary/tests/test_dielectric.py
index a99bf662..ed034e62 100644
--- a/plasmapy/formulary/tests/test_dielectric.py
+++ b/plasmapy/formulary/tests/test_dielectric.py
@@ -1,3 +1,4 @@
+
 """Tests for functions that calculate plasma dielectric parameters in
 dielectry.py"""
 
diff --git a/plasmapy/formulary/tests/test_dimensionless.py b/plasmapy/formulary/tests/test_dimensionless.py
index e8acc283..742c448a 100644
--- a/plasmapy/formulary/tests/test_dimensionless.py
+++ b/plasmapy/formulary/tests/test_dimensionless.py
@@ -1,8 +1,13 @@
-from plasmapy.formulary.dimensionless import beta, quantum_theta
+import pytest
+from astropy.constants import c
+
+from plasmapy.formulary.dimensionless import beta, quantum_theta, Reynolds_number
 
 import astropy.units as u
 import numpy as np
 
+from plasmapy.utils import RelativityError
+
 B = 1.0 * u.T
 n = 5e19 * u.m ** -3
 T = 1e6 * u.K
@@ -26,3 +31,21 @@ def test_beta_nan():
     out = beta(T, n, B)
     assert np.isnan(out[1])
     assert out[1].unit == u.dimensionless_unscaled
+
+
+def test_Reynolds_number():
+    r"""Test Reynolds_number in dimensionless.py"""
+    rho = 1490 * u.kg / u.m ** 3
+    v = 0.1 * u.m / u.s
+    L = 0.05 * u.m
+    mu = 10 * u.kg / (u.m * u.s)
+
+    assert (
+        Reynolds_number(rho, v, L, mu) * u.dimensionless_unscaled
+           ).unit == u.dimensionless_unscaled
+
+    with pytest.warns(u.UnitsWarning):
+        Reynolds_number(rho, 2.2, L, mu)
+
+    with pytest.raises(u.UnitTypeError):
+        Reynolds_number(rho, 4 * u.kg, L, mu)