From fda716b6975e3e95fbcbcf4a99402fb58b90464f Mon Sep 17 00:00:00 2001 From: ZeroDayOwl <56065602+ZeroDayOwl@users.noreply.github.com> Date: Fri, 14 Oct 2022 08:22:45 +0600 Subject: [PATCH 1/9] Add algorithm for Casimir Effect --- physics/casimir_effect.py | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 physics/casimir_effect.py diff --git a/physics/casimir_effect.py b/physics/casimir_effect.py new file mode 100644 index 000000000000..9e48dff35a4f --- /dev/null +++ b/physics/casimir_effect.py @@ -0,0 +1,116 @@ +""" +Title : Finding the value of magnitude of either the Casimir force, the surface area +of one of the plates or distance between the plates provided that the other +two parameters are given. + +Description : In quantum field theory, the Casimir effect is a physical force +acting on the macroscopic boundaries of a confined space which arises from the +quantum fluctuations of the field. It is a physical force exerted between separate +objects, which is due to neither charge, gravity, nor the exchange of particles, +but instead is due to resonance of all-pervasive energy fields in the intervening +space between the objects. Since the strength of the force falls off rapidly with +distance it is only measurable when the distance between the objects is extremely +small. On a submicron scale, this force becomes so strong that it becomes the +dominant force between uncharged conductors. + +Dutch physicist Hendrik B. G. Casimir first proposed the existence of the force, +and he formulated an experiment to detect it in 1948 while participating in research +at Philips Research Labs. The classic form of his experiment used a pair of uncharged +parallel metal plates in a vacuum, and successfully demonstrated the force to within +15% of the value he had predicted according to his theory. + +The Casimir force F for idealized, perfectly conducting plates of surface area +A square meter and placed at a distance of a meter apart with vacuum between +them is expressed as - + +F = - ((Reduced Planck Constant ℏ) * c * Pi^2 * A) / (240 * a^4) + +Here, the negative sign indicates the force is attractive in nature. For the ease +of calculation, only the magnitude of the force is considered. + +Source : +- https://en.wikipedia.org/wiki/Casimir_effect +- https://www.cs.mcgill.ca/~rwest/wikispeedia/wpcd/wp/c/Casimir_effect.htm +- Casimir, H. B. ; Polder, D. (1948) "The Influence of Retardation on the + London-van der Waals Forces", Physical Review, vol. 73, Issue 4, pp. 360-372 +""" + +from __future__ import annotations + +# Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of Pi and the function +REDUCED_PLANCK_CONSTANT = 1.054571817e-34 # unit of ℏ : J * s + +SPEED_OF_LIGHT = 3e8 # unit of c : m * s^-1 + +PI = 3.14 + + +def casimir_force( + force: float, area: float, distance: float +) -> dict[str, float]: + + """ + Input Parameters + ---------------- + force -> Casimir Force : magnitude in Newtons + + area -> Surface area of each plate : magnitude in square meters + + distance -> Distance between two plates : distance in Meters + + Returns + ------- + result : dict name, value pair of the parameter having Zero as it's value + + Returns the value of one of the parameters specified as 0, provided the values of + other parameters are given. + >>> casimir_force(force = 0, area = 4, distance = 0.03) + {'force': 6.4183063499340754e-21} + + >>> casimir_force(force = 2635e-13, area = 0.0023, distance = 0) + {'distance': 1.032043900858094e-05} + + >>> casimir_force(force = 2737e-21, area = 0, distance = 0.0023746) + {'area': 0.06695625910516347} + + >>> casimir_force(force = 3457e-12, area = 0, distance = 0) + Traceback (most recent call last): + ... + ValueError: One and only one argument must be 0 + + >>> casimir_force(force = 3457e-12, area = 0, distance = -0.00344) + Traceback (most recent call last): + ... + ValueError: Distance can not be negative + + >>> casimir_force(force = -912e-12, area = 0, distance = 0.09374) + Traceback (most recent call last): + ... + ValueError: Magnitude of force can not be negative + """ + + if (force, area, distance).count(0) != 1: + raise ValueError("One and only one argument must be 0") + if force < 0: + raise ValueError("Magnitude of force can not be negative") + if distance < 0: + raise ValueError("Distance can not be negative") + if area < 0: + raise ValueError("Area can not be negative") + if force == 0: + force = (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2 * area) / (240 * (distance)**4) + return {"force": force} + elif area == 0: + area = (240 * force * (distance)**4) / (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2) + return {"area": area} + elif distance == 0: + distance = ((REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2 * area) / (240 * force) )**(1/4) + return {"distance": distance} + raise ValueError("One and only one argument must be 0") + + +# Run doctest +if __name__ == "__main__": + import doctest + + doctest.testmod() From 5bf3af771bab63105e338f4ea1dcb69dcaa50af4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Oct 2022 02:29:46 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/casimir_effect.py | 54 +++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/physics/casimir_effect.py b/physics/casimir_effect.py index 9e48dff35a4f..02b1a961561f 100644 --- a/physics/casimir_effect.py +++ b/physics/casimir_effect.py @@ -1,38 +1,38 @@ """ -Title : Finding the value of magnitude of either the Casimir force, the surface area -of one of the plates or distance between the plates provided that the other +Title : Finding the value of magnitude of either the Casimir force, the surface area +of one of the plates or distance between the plates provided that the other two parameters are given. -Description : In quantum field theory, the Casimir effect is a physical force -acting on the macroscopic boundaries of a confined space which arises from the -quantum fluctuations of the field. It is a physical force exerted between separate -objects, which is due to neither charge, gravity, nor the exchange of particles, -but instead is due to resonance of all-pervasive energy fields in the intervening -space between the objects. Since the strength of the force falls off rapidly with -distance it is only measurable when the distance between the objects is extremely -small. On a submicron scale, this force becomes so strong that it becomes the +Description : In quantum field theory, the Casimir effect is a physical force +acting on the macroscopic boundaries of a confined space which arises from the +quantum fluctuations of the field. It is a physical force exerted between separate +objects, which is due to neither charge, gravity, nor the exchange of particles, +but instead is due to resonance of all-pervasive energy fields in the intervening +space between the objects. Since the strength of the force falls off rapidly with +distance it is only measurable when the distance between the objects is extremely +small. On a submicron scale, this force becomes so strong that it becomes the dominant force between uncharged conductors. -Dutch physicist Hendrik B. G. Casimir first proposed the existence of the force, -and he formulated an experiment to detect it in 1948 while participating in research -at Philips Research Labs. The classic form of his experiment used a pair of uncharged -parallel metal plates in a vacuum, and successfully demonstrated the force to within +Dutch physicist Hendrik B. G. Casimir first proposed the existence of the force, +and he formulated an experiment to detect it in 1948 while participating in research +at Philips Research Labs. The classic form of his experiment used a pair of uncharged +parallel metal plates in a vacuum, and successfully demonstrated the force to within 15% of the value he had predicted according to his theory. The Casimir force F for idealized, perfectly conducting plates of surface area -A square meter and placed at a distance of a meter apart with vacuum between +A square meter and placed at a distance of a meter apart with vacuum between them is expressed as - F = - ((Reduced Planck Constant ℏ) * c * Pi^2 * A) / (240 * a^4) -Here, the negative sign indicates the force is attractive in nature. For the ease +Here, the negative sign indicates the force is attractive in nature. For the ease of calculation, only the magnitude of the force is considered. Source : - https://en.wikipedia.org/wiki/Casimir_effect - https://www.cs.mcgill.ca/~rwest/wikispeedia/wpcd/wp/c/Casimir_effect.htm -- Casimir, H. B. ; Polder, D. (1948) "The Influence of Retardation on the - London-van der Waals Forces", Physical Review, vol. 73, Issue 4, pp. 360-372 +- Casimir, H. B. ; Polder, D. (1948) "The Influence of Retardation on the + London-van der Waals Forces", Physical Review, vol. 73, Issue 4, pp. 360-372 """ from __future__ import annotations @@ -40,14 +40,12 @@ # Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of Pi and the function REDUCED_PLANCK_CONSTANT = 1.054571817e-34 # unit of ℏ : J * s -SPEED_OF_LIGHT = 3e8 # unit of c : m * s^-1 +SPEED_OF_LIGHT = 3e8 # unit of c : m * s^-1 PI = 3.14 -def casimir_force( - force: float, area: float, distance: float -) -> dict[str, float]: +def casimir_force(force: float, area: float, distance: float) -> dict[str, float]: """ Input Parameters @@ -98,13 +96,19 @@ def casimir_force( if area < 0: raise ValueError("Area can not be negative") if force == 0: - force = (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2 * area) / (240 * (distance)**4) + force = (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2 * area) / ( + 240 * (distance) ** 4 + ) return {"force": force} elif area == 0: - area = (240 * force * (distance)**4) / (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2) + area = (240 * force * (distance) ** 4) / ( + REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2 + ) return {"area": area} elif distance == 0: - distance = ((REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2 * area) / (240 * force) )**(1/4) + distance = ( + (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2 * area) / (240 * force) + ) ** (1 / 4) return {"distance": distance} raise ValueError("One and only one argument must be 0") From cdb1fc9d3d5c569f450a563826d4f463117acba5 Mon Sep 17 00:00:00 2001 From: ZeroDayOwl <56065602+ZeroDayOwl@users.noreply.github.com> Date: Fri, 14 Oct 2022 08:38:29 +0600 Subject: [PATCH 3/9] Fix the line length --- physics/casimir_effect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/physics/casimir_effect.py b/physics/casimir_effect.py index 9e48dff35a4f..c84b7db79d9c 100644 --- a/physics/casimir_effect.py +++ b/physics/casimir_effect.py @@ -37,7 +37,8 @@ from __future__ import annotations -# Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of Pi and the function +# Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of Pi +# and the function REDUCED_PLANCK_CONSTANT = 1.054571817e-34 # unit of ℏ : J * s SPEED_OF_LIGHT = 3e8 # unit of c : m * s^-1 From 109a3baedffca31cfe7773b5ed613fc9057afe9b Mon Sep 17 00:00:00 2001 From: ZeroDayOwl <56065602+ZeroDayOwl@users.noreply.github.com> Date: Fri, 14 Oct 2022 08:41:36 +0600 Subject: [PATCH 4/9] Fix the line length --- physics/casimir_effect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/physics/casimir_effect.py b/physics/casimir_effect.py index c84b7db79d9c..e71354d87602 100644 --- a/physics/casimir_effect.py +++ b/physics/casimir_effect.py @@ -37,8 +37,8 @@ from __future__ import annotations -# Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of Pi -# and the function +# Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of +# Pi and the function REDUCED_PLANCK_CONSTANT = 1.054571817e-34 # unit of ℏ : J * s SPEED_OF_LIGHT = 3e8 # unit of c : m * s^-1 From 7f26716af3fdb829abf10c043e51ab3da536876a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Oct 2022 02:44:01 +0000 Subject: [PATCH 5/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/casimir_effect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/casimir_effect.py b/physics/casimir_effect.py index 225c8b73d69c..d9af285cb58b 100644 --- a/physics/casimir_effect.py +++ b/physics/casimir_effect.py @@ -37,7 +37,7 @@ from __future__ import annotations -# Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of +# Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of # Pi and the function REDUCED_PLANCK_CONSTANT = 1.054571817e-34 # unit of ℏ : J * s From 5ad33e575ee73c7a63d6aee7739883123f09c96d Mon Sep 17 00:00:00 2001 From: ZeroDayOwl <56065602+ZeroDayOwl@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:23:56 +0600 Subject: [PATCH 6/9] Import math module and use Pi --- physics/casimir_effect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/physics/casimir_effect.py b/physics/casimir_effect.py index d9af285cb58b..da6b7f0227e9 100644 --- a/physics/casimir_effect.py +++ b/physics/casimir_effect.py @@ -36,6 +36,7 @@ """ from __future__ import annotations +import math # Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of # Pi and the function @@ -43,7 +44,7 @@ SPEED_OF_LIGHT = 3e8 # unit of c : m * s^-1 -PI = 3.14 +PI = math.pi def casimir_force(force: float, area: float, distance: float) -> dict[str, float]: From b0d800a510c24c28d90992092b950bb6d8bc0c2d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 15 Oct 2022 13:25:38 +0000 Subject: [PATCH 7/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/casimir_effect.py | 1 + 1 file changed, 1 insertion(+) diff --git a/physics/casimir_effect.py b/physics/casimir_effect.py index da6b7f0227e9..6488ad8f93c0 100644 --- a/physics/casimir_effect.py +++ b/physics/casimir_effect.py @@ -36,6 +36,7 @@ """ from __future__ import annotations + import math # Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of From 2f7663bb200105f5914758cdcb75876e9e36e1e6 Mon Sep 17 00:00:00 2001 From: ZeroDayOwl <56065602+ZeroDayOwl@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:52:54 +0600 Subject: [PATCH 8/9] Update doctest results --- physics/casimir_effect.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/physics/casimir_effect.py b/physics/casimir_effect.py index 6488ad8f93c0..7f4084a1570c 100644 --- a/physics/casimir_effect.py +++ b/physics/casimir_effect.py @@ -66,13 +66,13 @@ def casimir_force(force: float, area: float, distance: float) -> dict[str, float Returns the value of one of the parameters specified as 0, provided the values of other parameters are given. >>> casimir_force(force = 0, area = 4, distance = 0.03) - {'force': 6.4183063499340754e-21} + {'force': 6.4248189174864216e-21} >>> casimir_force(force = 2635e-13, area = 0.0023, distance = 0) - {'distance': 1.032043900858094e-05} + {'distance': 1.0323056015031114e-05} >>> casimir_force(force = 2737e-21, area = 0, distance = 0.0023746) - {'area': 0.06695625910516347} + {'area': 0.06688838837354052} >>> casimir_force(force = 3457e-12, area = 0, distance = 0) Traceback (most recent call last): From 9df4f719efc7914fdc17cee944ddaa248f0c42fe Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 15 Oct 2022 19:35:02 +0200 Subject: [PATCH 9/9] from math import pi --- physics/casimir_effect.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/physics/casimir_effect.py b/physics/casimir_effect.py index 7f4084a1570c..ee8a6c1eba53 100644 --- a/physics/casimir_effect.py +++ b/physics/casimir_effect.py @@ -37,7 +37,7 @@ from __future__ import annotations -import math +from math import pi # Define the Reduced Planck Constant ℏ (H bar), speed of light C, value of # Pi and the function @@ -45,8 +45,6 @@ SPEED_OF_LIGHT = 3e8 # unit of c : m * s^-1 -PI = math.pi - def casimir_force(force: float, area: float, distance: float) -> dict[str, float]: @@ -99,18 +97,18 @@ def casimir_force(force: float, area: float, distance: float) -> dict[str, float if area < 0: raise ValueError("Area can not be negative") if force == 0: - force = (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2 * area) / ( + force = (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2 * area) / ( 240 * (distance) ** 4 ) return {"force": force} elif area == 0: area = (240 * force * (distance) ** 4) / ( - REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2 + REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2 ) return {"area": area} elif distance == 0: distance = ( - (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * PI**2 * area) / (240 * force) + (REDUCED_PLANCK_CONSTANT * SPEED_OF_LIGHT * pi**2 * area) / (240 * force) ) ** (1 / 4) return {"distance": distance} raise ValueError("One and only one argument must be 0")