-
Notifications
You must be signed in to change notification settings - Fork 52
feat: add ElasticPlastic2D material class with tests #243
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
saraschei
wants to merge
11
commits into
fib-international:implement-shell-section
Choose a base branch
from
krkris:add-elasticplastic-2d
base: implement-shell-section
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
11 commits
Select commit
Hold shift + click to select a range
a7ffe7f
Add ElasticElastic2D material class with tests
saraschei 0a7b769
Removed redundant lines inherited from the parent class
saraschei 68cc997
Removed redundant lines inherited from the parent class and changed n…
saraschei f413a2e
Merge branch 'add-elasticplastic-2d' of https://github.com/krkris/str…
saraschei a5f6be7
Change from secant to tangent
saraschei 47e4151
Added tests
saraschei 5322332
Added docstring
saraschei 2a960cd
Add strain parameter to get_tangent function
saraschei 3362924
Removed ParabolaRectangle2D from __init__
saraschei 4d89973
Merge remote-tracking branch 'origin/implement-shell-section' into ad…
saraschei 5cf1f0d
Removed eps from get_tangent
saraschei 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
68 changes: 68 additions & 0 deletions
68
structuralcodes/materials/constitutive_laws/_elasticplastic_2d.py
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,68 @@ | ||
| """Elastic-plastic constitutive law.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import typing as t | ||
|
|
||
| import numpy as np | ||
| from numpy.typing import ArrayLike | ||
|
|
||
| from structuralcodes.materials.constitutive_laws._elasticplastic import ( | ||
| ElasticPlastic, | ||
| ) | ||
|
|
||
|
|
||
| class ElasticPlastic2D(ElasticPlastic): | ||
| """Class for elastic-plastic Constitutive Law in 2D.""" | ||
|
|
||
| __materials__: t.Tuple[str] = ( | ||
| 'steel', | ||
| 'rebars', | ||
| ) | ||
|
|
||
| def __init__( | ||
| self, | ||
| E: float, | ||
| fy: float, | ||
| Eh: float = 0.0, | ||
| eps_su: t.Optional[float] = None, | ||
| name: t.Optional[str] = None, | ||
| ) -> None: | ||
| """Initialize an Elastic-Plastic 2D Material. | ||
|
|
||
| Arguments: | ||
| E (float): The elastic modulus. | ||
| fy (float): The yield strength. | ||
|
|
||
| Keyword Arguments: | ||
| Eh (float): The hardening modulus. | ||
| eps_su (float): The ultimate strain. | ||
| name (str): A descriptive name for the constitutive law. | ||
| """ | ||
| name = name if name is not None else 'ElasticPlasticLaw2D' | ||
| super().__init__(E=E, fy=fy, Eh=Eh, eps_su=eps_su, name=name) | ||
|
|
||
| @property | ||
| def E(self) -> float: | ||
| """Return the elastic modulus.""" | ||
| return self._E | ||
|
|
||
| @property | ||
| def C_s(self) -> np.ndarray: | ||
| """Return the 2D constitutive matrix.""" | ||
| return self.E * np.array( | ||
| [ | ||
| [1.0, 0.0, 0.0], | ||
| [0.0, 1.0, 0.0], | ||
| [0.0, 0.0, 0.0], | ||
| ] | ||
| ) | ||
|
|
||
| def get_stress(self, eps: ArrayLike) -> np.ndarray: | ||
| """Return the stress given strain.""" | ||
| sig_s = super().get_stress(eps) | ||
| return sig_s @ self.C_s / self.E | ||
|
|
||
| def get_tangent(self) -> np.ndarray: | ||
| """Compute the 3x3 tangent stiffness matrix C.""" | ||
| return self.C_s |
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,63 @@ | ||
| """Tests for the ElasticPlastic2D class.""" | ||
|
|
||
| import numpy as np | ||
mortenengen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import pytest | ||
|
|
||
| from structuralcodes.materials.constitutive_laws import ElasticPlastic2D | ||
|
|
||
|
|
||
| def test_elasticplastic_2d_init(): | ||
| """Test elasticplastic 2D material.""" | ||
| mat = ElasticPlastic2D(210000, 410) | ||
| assert mat.E == 210000 | ||
| assert mat._fy == 410 | ||
| assert mat._Eh == 0.0 | ||
| assert mat._eps_su is None | ||
| assert mat.name == 'ElasticPlasticLaw2D' | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'E, fy, strain', | ||
| [ | ||
| (210000, 410, np.array([0.001, 0.0, 0.0])), | ||
| (210000, 410, np.array([-0.002, -0.1, -0.002])), | ||
| (200000, 450, np.array([0.003, 0.005, 0.010])), | ||
| ], | ||
| ) | ||
| def test_elasticplastic_2d_get_stress(E, fy, strain): | ||
| """Test elasticplastic 2D material.""" | ||
| mat = ElasticPlastic2D(E, fy) | ||
| actual = mat.get_stress(strain) | ||
|
|
||
| expected = np.array( | ||
| [ | ||
| np.clip(E * strain[0], -fy, +fy), | ||
| np.clip(E * strain[1], -fy, +fy), | ||
| 0.0, | ||
| ] | ||
| ) | ||
|
|
||
| assert np.allclose(actual, expected, atol=1e-8) | ||
|
|
||
|
|
||
| def test_elasticplastic_2d_input_correct(): | ||
| """Test invalid input values for ElasticPlastic2D.""" | ||
| with pytest.raises(ValueError) as excinfo: | ||
| ElasticPlastic2D(-210000, 500) | ||
| assert str(excinfo.value) == 'Elastic modulus E must be greater than zero' | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| 'E, fy', | ||
| [ | ||
| (210000, 500), | ||
| (200000, 500), | ||
| (195000, 500), | ||
| ], | ||
| ) | ||
| def test_elasticplastic_get_tangent(E, fy): | ||
| """Test the elasticPlastic2D tangent matrix.""" | ||
| assert np.allclose( | ||
| ElasticPlastic2D(E, fy).get_tangent(), | ||
| np.array([[E, 0, 0], [0, E, 0], [0, 0, 0]]), | ||
| ) | ||
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.
Note that the tests are failing because we are trying to import
ParabolaRectangle2D, but this is not available, since it is being implemented in #242. Please remove this for now, and we will make sure it exists after merging #242.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.
Removed in commit 3362924