From 338074cf534f8d9f252f9c8923e0f2f87e660108 Mon Sep 17 00:00:00 2001 From: sadiqebrahim Date: Thu, 20 Oct 2022 14:45:27 +0530 Subject: [PATCH 1/7] add electric conductivity algorithm --- electronics/electric_conductivity.py | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 electronics/electric_conductivity.py diff --git a/electronics/electric_conductivity.py b/electronics/electric_conductivity.py new file mode 100644 index 000000000000..d13563e1b276 --- /dev/null +++ b/electronics/electric_conductivity.py @@ -0,0 +1,68 @@ +from __future__ import annotations + +ELECTRON_CHARGE = 1.6021e-19 # units = C +5 * 2 + + +def electric_conductivity( + conductivity: float, + electron_conc: float, + mobility: float, +) -> tuple: + """ + This function can calculate any one of the three - + 1. Conductivity + 2, Conductivity + 3. Electron Mobility + given the other two. + Examples - + >>> electric_conductivity(conductivity=25, electron_conc=100, mobility=0) + ('mobility', 1.5604519068722301e+18) + >>> electric_conductivity(conductivity=0, electron_conc=1600, mobility=200) + ('conductivity', 5.12672e-14) + >>> electric_conductivity(conductivity=1000, electron_conc=0, mobility=1200) + ('electron_conc', 5.201506356240767e+18) + >>> electric_conductivity(conductivity=1000, electron_conc=400, mobility=1200) + Traceback (most recent call last): + File "", line 37, in + ValueError: You cannot supply more or less than 2 values + >>> electric_conductivity(conductivity=0, electron_conc=-400, mobility=1200) + Traceback (most recent call last): + File "", line 44, in + ValueError: Electron concentration cannot be negative + >>> electric_conductivity(conductivity=0, electron_conc=400, mobility=-1200) + Traceback (most recent call last): + File "", line 48, in + ValueError: mobility cannot be negative + """ + if (conductivity, electron_conc, mobility).count(0) != 1: + raise ValueError("You cannot supply more or less than 2 values") + elif conductivity < 0: + raise ValueError("Conductivity cannot be negative") + elif electron_conc < 0: + raise ValueError("Electron concentration cannot be negative ") + elif mobility < 0: + raise ValueError("mobility cannot be negative") + elif conductivity == 0: + return ( + "conductivity", + mobility * electron_conc * ELECTRON_CHARGE, + ) + elif electron_conc == 0: + return ( + "electron_conc", + conductivity / (mobility * ELECTRON_CHARGE), + ) + elif mobility == 0: + return ( + "mobility", + conductivity / (electron_conc * ELECTRON_CHARGE), + ) + else: + return (-1, -1) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From e4701c468f7f2e1fc4e66d6ca1e893456cb76546 Mon Sep 17 00:00:00 2001 From: sadiqebrahim <75269485+sadiqebrahim@users.noreply.github.com> Date: Thu, 20 Oct 2022 15:08:36 +0530 Subject: [PATCH 2/7] Update electric_conductivity.py --- electronics/electric_conductivity.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/electronics/electric_conductivity.py b/electronics/electric_conductivity.py index d13563e1b276..a13f8eb64056 100644 --- a/electronics/electric_conductivity.py +++ b/electronics/electric_conductivity.py @@ -22,18 +22,6 @@ def electric_conductivity( ('conductivity', 5.12672e-14) >>> electric_conductivity(conductivity=1000, electron_conc=0, mobility=1200) ('electron_conc', 5.201506356240767e+18) - >>> electric_conductivity(conductivity=1000, electron_conc=400, mobility=1200) - Traceback (most recent call last): - File "", line 37, in - ValueError: You cannot supply more or less than 2 values - >>> electric_conductivity(conductivity=0, electron_conc=-400, mobility=1200) - Traceback (most recent call last): - File "", line 44, in - ValueError: Electron concentration cannot be negative - >>> electric_conductivity(conductivity=0, electron_conc=400, mobility=-1200) - Traceback (most recent call last): - File "", line 48, in - ValueError: mobility cannot be negative """ if (conductivity, electron_conc, mobility).count(0) != 1: raise ValueError("You cannot supply more or less than 2 values") From c5d0e788fd87c5a667b76c64f06191487d9ec186 Mon Sep 17 00:00:00 2001 From: sadiqebrahim <75269485+sadiqebrahim@users.noreply.github.com> Date: Thu, 20 Oct 2022 17:57:22 +0530 Subject: [PATCH 3/7] Apply suggestions from code review Co-authored-by: Caeden Perelli-Harris --- electronics/electric_conductivity.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/electronics/electric_conductivity.py b/electronics/electric_conductivity.py index a13f8eb64056..cd47215c0c8c 100644 --- a/electronics/electric_conductivity.py +++ b/electronics/electric_conductivity.py @@ -1,20 +1,19 @@ from __future__ import annotations ELECTRON_CHARGE = 1.6021e-19 # units = C -5 * 2 def electric_conductivity( conductivity: float, electron_conc: float, mobility: float, -) -> tuple: +) -> tuple[str, float]: """ This function can calculate any one of the three - 1. Conductivity 2, Conductivity 3. Electron Mobility - given the other two. + This is calculated from the other two provided values Examples - >>> electric_conductivity(conductivity=25, electron_conc=100, mobility=0) ('mobility', 1.5604519068722301e+18) @@ -28,7 +27,7 @@ def electric_conductivity( elif conductivity < 0: raise ValueError("Conductivity cannot be negative") elif electron_conc < 0: - raise ValueError("Electron concentration cannot be negative ") + raise ValueError("Electron concentration cannot be negative") elif mobility < 0: raise ValueError("mobility cannot be negative") elif conductivity == 0: From f0952f556d01372f91f51cec5ff3c6b66b7f9c2e Mon Sep 17 00:00:00 2001 From: sadiqebrahim <75269485+sadiqebrahim@users.noreply.github.com> Date: Thu, 20 Oct 2022 17:58:45 +0530 Subject: [PATCH 4/7] Update electric_conductivity.py --- electronics/electric_conductivity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electronics/electric_conductivity.py b/electronics/electric_conductivity.py index cd47215c0c8c..259232b7eac1 100644 --- a/electronics/electric_conductivity.py +++ b/electronics/electric_conductivity.py @@ -11,7 +11,7 @@ def electric_conductivity( """ This function can calculate any one of the three - 1. Conductivity - 2, Conductivity + 2. Electron Concentration 3. Electron Mobility This is calculated from the other two provided values Examples - From e93febdfe4f0174a23cbd8e6fad1ae412cdf449a Mon Sep 17 00:00:00 2001 From: sadiqebrahim <75269485+sadiqebrahim@users.noreply.github.com> Date: Thu, 20 Oct 2022 18:03:27 +0530 Subject: [PATCH 5/7] Update electric_conductivity.py --- electronics/electric_conductivity.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/electronics/electric_conductivity.py b/electronics/electric_conductivity.py index 259232b7eac1..14d3d7cbd6b9 100644 --- a/electronics/electric_conductivity.py +++ b/electronics/electric_conductivity.py @@ -45,8 +45,6 @@ def electric_conductivity( "mobility", conductivity / (electron_conc * ELECTRON_CHARGE), ) - else: - return (-1, -1) if __name__ == "__main__": From 0a98f5db450815b87949908be5c10e89b50221b2 Mon Sep 17 00:00:00 2001 From: sadiqebrahim <75269485+sadiqebrahim@users.noreply.github.com> Date: Thu, 20 Oct 2022 18:14:52 +0530 Subject: [PATCH 6/7] Update electric_conductivity.py --- electronics/electric_conductivity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electronics/electric_conductivity.py b/electronics/electric_conductivity.py index 14d3d7cbd6b9..11f2a607d214 100644 --- a/electronics/electric_conductivity.py +++ b/electronics/electric_conductivity.py @@ -40,7 +40,7 @@ def electric_conductivity( "electron_conc", conductivity / (mobility * ELECTRON_CHARGE), ) - elif mobility == 0: + else: return ( "mobility", conductivity / (electron_conc * ELECTRON_CHARGE), From 7719a1e06b08d70253a36341b3efc1b316dd8d13 Mon Sep 17 00:00:00 2001 From: sadiqebrahim Date: Sat, 22 Oct 2022 22:01:27 +0530 Subject: [PATCH 7/7] add algorithm --- physics/sheer_stress.py | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 physics/sheer_stress.py diff --git a/physics/sheer_stress.py b/physics/sheer_stress.py new file mode 100644 index 000000000000..74a2d36b1f45 --- /dev/null +++ b/physics/sheer_stress.py @@ -0,0 +1,51 @@ +from __future__ import annotations + + +def sheer_stress( + stress: float, + tangential_force: float, + area: float, +) -> tuple[str, float]: + """ + This function can calculate any one of the three - + 1. Sheer Stress + 2. Tangential Force + 3. Cross-sectional Area + This is calculated from the other two provided values + Examples - + >>> sheer_stress(stress=25, tangential_force=100, area=0) + ('area', 4.0) + >>> sheer_stress(stress=0, tangential_force=1600, area=200) + ('stress', 8.0) + >>> sheer_stress(stress=1000, tangential_force=0, area=1200) + ('tangential_force', 1200000) + """ + if (stress, tangential_force, area).count(0) != 1: + raise ValueError("You cannot supply more or less than 2 values") + elif stress < 0: + raise ValueError("Stress cannot be negative") + elif tangential_force < 0: + raise ValueError("Tangential Force cannot be negative") + elif area < 0: + raise ValueError("Area cannot be negative") + elif stress == 0: + return ( + "stress", + tangential_force / area, + ) + elif tangential_force == 0: + return ( + "tangential_force", + stress * area, + ) + else: + return ( + "area", + tangential_force / stress, + ) + + +if __name__ == "__main__": + import doctest + + doctest.testmod()