-
Notifications
You must be signed in to change notification settings - Fork 6
520 feature request set n decimals as abstract method to latex formula #522
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
Open
johan-tuls
wants to merge
15
commits into
main
Choose a base branch
from
520-feature-request-set-n-decimals-as-abstract-method-to-latex-formula
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
068cefd
#355 Added menard equations 2.21 and 2.22 of CUR 288
johan-tuls-bam 418df4a
#355 Feedback naming ModulusHorizontalSubgrade
johan-tuls-bam 05ee0a2
Update blueprints/codes/cur/cur_228/formula_2_22.py
johan-tuls 2cb0db1
Merge branch 'main' into 355-feature-request-menard-stiffness-cur-228
egarciamendez 31a5cfd
Merge branch 'main' into 355-feature-request-menard-stiffness-cur-228
egarciamendez 0b34943
Merge branch 'main' into 355-feature-request-menard-stiffness-cur-228
johan-tuls-bam 35f66d4
355 Added additional checks.
johan-tuls-bam 3c8652b
355 Update how to handle decimals in latex
johan-tuls-bam 7c69e78
355 Fix coverage
johan-tuls-bam 3ff74cd
355 Fix tests
johan-tuls-bam 5e5d08b
520 Latex abstract method
johan-tuls-bam 6f36d74
520 Fix test coverage
johan-tuls-bam 1ee1012
520 Fix tests menard.
johan-tuls-bam b5e472e
Merge branch 'main' into 520-feature-request-set-n-decimals-as-abstra…
GerjanDorgelo 50fe742
Merge branch 'main' into 520-feature-request-set-n-decimals-as-abstra…
GerjanDorgelo 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
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
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
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 |
---|---|---|
|
@@ -165,4 +165,5 @@ cython_debug/ | |
.vscode/ | ||
|
||
# ENV file | ||
.ENV | ||
.ENV | ||
/local/ |
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
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 @@ | ||
"""CUR guidelines.""" |
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,7 @@ | ||
"""CUR-228 package.""" | ||
|
||
from blueprints.type_alias import M | ||
|
||
CUR_228 = "CUR 228" | ||
|
||
R_0: M = 0.3 |
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,80 @@ | ||
"""Contains formula 2.21 from CUR 228.""" | ||
|
||
from blueprints.codes.cur.cur_228 import CUR_228, R_0 | ||
from blueprints.codes.formula import Formula | ||
from blueprints.codes.latex_formula import LatexFormula | ||
from blueprints.type_alias import DIMENSIONLESS, KN_M3, KPA, M | ||
from blueprints.validations import raise_if_less_or_equal_to_zero, raise_if_negative | ||
|
||
|
||
class Form2Dot21ModulusHorizontalSubgrade(Formula): | ||
"""Representation of equation 2.21 CUR 228.""" | ||
|
||
source_document = CUR_228 | ||
label = "2.21" | ||
n_decimals: int = 2 | ||
|
||
def __init__(self, r: M, e_p: KPA, alpha: DIMENSIONLESS) -> None: | ||
"""Calculates the modulus of horizontal subgrade reaction (k_h) using Menard stiffness for r >= 0.3 m. | ||
|
||
Parameters | ||
---------- | ||
r: M | ||
The radius of a foundation pile [m]: | ||
r >= 0.3 m | ||
e_p: KPA | ||
Elastic modulus of Ménard [kPa]: | ||
e_p ≈ beta * q_c | ||
beta: DIMENSIONLESS | ||
Dependent on soil type [-]: (table 2.1) | ||
q_c: KPA | ||
Cone resistance [kPa] | ||
alpha: DIMENSIONLESS | ||
Factor dependent on soil type [-]: (table 2.1) | ||
""" | ||
super().__init__() | ||
self.r = float(r) | ||
self.e_p = float(e_p) | ||
self.alpha = float(alpha) | ||
|
||
@staticmethod | ||
def _evaluate(r: M, e_p: KPA, alpha: DIMENSIONLESS) -> KN_M3: | ||
"""Evaluates the formula, for more information see the __init__ method.""" | ||
r_0 = R_0 | ||
raise_if_negative(e_p=e_p) | ||
raise_if_less_or_equal_to_zero(r=r, alpha=alpha) | ||
|
||
if r >= r_0: | ||
return 3 * e_p / (1.3 * r_0 * (2.65 * r / r_0) ** alpha + alpha * r) | ||
msg = "Radius is smaller than 0.3m, use: Eq2Dot21ModulusHorizontalSubgrade" | ||
raise ValueError(msg) | ||
|
||
def latex(self, n: int = 3) -> LatexFormula: | ||
"""Latex representation of the full equation including result. | ||
|
||
Parameters | ||
---------- | ||
n: int | ||
Number of decimals to round the result to | ||
|
||
Returns | ||
------- | ||
LatexFormula | ||
Latex representation of the equation | ||
|
||
""" | ||
n = self.n_decimals | ||
|
||
return LatexFormula( | ||
return_symbol="k_{h}", | ||
equation=r"\frac{1}{3 \cdot E_{p}} \cdot " | ||
r"\left[1.3 \cdot R_{0} " | ||
r"\left( 2.65 \frac{R}{R_0}\right)^\alpha" | ||
r" + \alpha \cdot R \right]", | ||
numeric_equation=rf"\frac{{1}}{{3 \cdot {self.e_p:.{n}}}} \cdot" | ||
rf"\left[1.3 \cdot {R_0:.{n}} " | ||
rf"\left( 2.65 \cdot \frac{{{self.r:.{n}}}}{{{R_0:.{n}}}}\right)^{{{self.alpha:.{n}f}}}" | ||
rf"+ {self.alpha:.{n}} \cdot {self.r:.{n}}\right]", | ||
result=f"{self:.{n}f}", | ||
unit="kN/m^3", | ||
) |
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,67 @@ | ||
"""Contains formula 2.22 from CUR 228.""" | ||
|
||
from blueprints.codes.cur.cur_228 import CUR_228, R_0 | ||
from blueprints.codes.formula import Formula | ||
from blueprints.codes.latex_formula import LatexFormula | ||
from blueprints.type_alias import DIMENSIONLESS, KN_M3, KPA, M | ||
from blueprints.validations import raise_if_less_or_equal_to_zero, raise_if_negative | ||
|
||
|
||
class Form2Dot22ModulusHorizontalSubgrade(Formula): | ||
"""Representation of equation 2.22 CUR 228.""" | ||
|
||
source_document = CUR_228 | ||
label = "2.22" | ||
n_decimals: int = 2 | ||
|
||
def __init__(self, r: M, e_p: KPA, alpha: DIMENSIONLESS) -> None: | ||
"""Calculates the modulus of horizontal subgrade reaction (k_h) using Menard stiffness for r < 0.3 m. | ||
|
||
Parameters | ||
---------- | ||
r: M | ||
The radius of a foundation pile [m]: | ||
r < 0.3 m | ||
e_p: KPA | ||
Elastic modulus of Ménard [kPa]: | ||
e_p ≈ beta * q_c | ||
beta: DIMENSIONLESS | ||
Dependent on soil type [-]: (table 2.1) | ||
q_c: KPA | ||
Cone resistance [kPa] | ||
alpha: DIMENSIONLESS | ||
Factor dependent on soil type [-]: (table 2.1) | ||
""" | ||
super().__init__() | ||
self.r = r | ||
self.e_p = e_p | ||
self.alpha = alpha | ||
|
||
@staticmethod | ||
def _evaluate(r: M, e_p: KPA, alpha: DIMENSIONLESS) -> KN_M3: | ||
"""Return the Menard stiffness k_h when r < 0.3 m [kN/m3].""" | ||
raise_if_negative(e_p=e_p) | ||
raise_if_less_or_equal_to_zero(r=r, alpha=alpha) | ||
if r < R_0: | ||
return e_p / 2 / r / ((4 * 2.65**alpha + 3 * alpha) / 18) | ||
msg = "Radius is equal to- or larger than 0.3m, use: Eq2Dot21ModulusHorizontalSubgrade" | ||
raise ValueError(msg) | ||
|
||
def latex(self, n: int = 3) -> LatexFormula: | ||
"""Latex representation of the full equation including result. | ||
|
||
Returns | ||
------- | ||
LatexFormula | ||
Latex representation of the equation | ||
|
||
""" | ||
n = self.n_decimals | ||
return LatexFormula( | ||
return_symbol=r"k_{h}", | ||
result=f"{self:.{n}f}", | ||
equation=r"\frac{2 \cdot R}{E_{p}} \cdot \frac{4 \cdot 2.65^{\alpha} + 3 \alpha}{18}", | ||
numeric_equation=rf"\frac{{2 \cdot {self.r:.{n}f}}}{{{self.e_p:.{n}f}}} \cdot \frac{{4 \cdot 2.65^{{{self.alpha:.{n}f}}} + 3 \cdot " | ||
rf"{self.alpha:.{n}f}}}{{18}}", | ||
unit="kN/m^3", | ||
) |
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
nothing is preventing a user from submitting a negative value. maybe its wice to always pick the larger value of 0 and n?