-
-
Notifications
You must be signed in to change notification settings - Fork 47k
add electric conductivity algorithm #7449
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
338074c
add electric conductivity algorithm
sadiqebrahim e4701c4
Update electric_conductivity.py
sadiqebrahim c5d0e78
Apply suggestions from code review
sadiqebrahim f0952f5
Update electric_conductivity.py
sadiqebrahim e93febd
Update electric_conductivity.py
sadiqebrahim 0a98f5d
Update electric_conductivity.py
sadiqebrahim 9e87037
Merge branch 'TheAlgorithms:master' into master
sadiqebrahim 7719a1e
add algorithm
sadiqebrahim e7b67c7
Merge branch 'TheAlgorithms:master' into master
sadiqebrahim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from __future__ import annotations | ||
|
||
ELECTRON_CHARGE = 1.6021e-19 # units = C | ||
|
||
|
||
def electric_conductivity( | ||
conductivity: float, | ||
electron_conc: float, | ||
mobility: float, | ||
) -> tuple[str, float]: | ||
""" | ||
This function can calculate any one of the three - | ||
1. Conductivity | ||
2. Electron Concentration | ||
3. Electron Mobility | ||
This is calculated from the other two provided values | ||
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) | ||
""" | ||
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), | ||
) | ||
else: | ||
return ( | ||
"mobility", | ||
conductivity / (electron_conc * ELECTRON_CHARGE), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does
conc
stand for?