structuralcodes 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of structuralcodes might be problematic. Click here for more details.

Files changed (24) hide show
  1. structuralcodes/__init__.py +1 -1
  2. structuralcodes/codes/ec2_2004/__init__.py +43 -11
  3. structuralcodes/codes/ec2_2004/_concrete_creep_and_shrinkage.py +529 -0
  4. structuralcodes/codes/ec2_2004/shear.py +5 -1
  5. structuralcodes/codes/mc2010/_concrete_creep_and_shrinkage.py +3 -1
  6. structuralcodes/core/base.py +16 -4
  7. structuralcodes/geometry/_geometry.py +4 -2
  8. structuralcodes/geometry/_reinforcement.py +14 -2
  9. structuralcodes/materials/constitutive_laws/__init__.py +84 -0
  10. structuralcodes/materials/constitutive_laws/_bilinearcompression.py +138 -0
  11. structuralcodes/materials/constitutive_laws/_elastic.py +114 -0
  12. structuralcodes/materials/constitutive_laws/_elasticplastic.py +172 -0
  13. structuralcodes/materials/constitutive_laws/_parabolarectangle.py +198 -0
  14. structuralcodes/materials/constitutive_laws/_popovics.py +133 -0
  15. structuralcodes/materials/constitutive_laws/_sargin.py +115 -0
  16. structuralcodes/materials/constitutive_laws/_userdefined.py +218 -0
  17. structuralcodes/sections/_generic.py +39 -9
  18. structuralcodes/sections/section_integrators/_fiber_integrator.py +1 -3
  19. structuralcodes/sections/section_integrators/_marin_integrator.py +1 -1
  20. {structuralcodes-0.1.0.dist-info → structuralcodes-0.2.0.dist-info}/METADATA +1 -1
  21. {structuralcodes-0.1.0.dist-info → structuralcodes-0.2.0.dist-info}/RECORD +22 -15
  22. structuralcodes/codes/ec2_2004/annex_b_shrink_and_creep.py +0 -257
  23. structuralcodes/materials/constitutive_laws.py +0 -981
  24. {structuralcodes-0.1.0.dist-info → structuralcodes-0.2.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,198 @@
1
+ """Parabola-Rectangle constitutive law."""
2
+
3
+ from __future__ import annotations # To have clean hints of ArrayLike in docs
4
+
5
+ import typing as t
6
+
7
+ import numpy as np
8
+ from numpy.typing import ArrayLike
9
+
10
+ from ...core.base import ConstitutiveLaw
11
+
12
+
13
+ class ParabolaRectangle(ConstitutiveLaw):
14
+ """Class for parabola rectangle constitutive law.
15
+
16
+ The stresses and strains are assumed negative in compression and positive
17
+ in tension.
18
+ """
19
+
20
+ __materials__: t.Tuple[str] = ('concrete',)
21
+
22
+ def __init__(
23
+ self,
24
+ fc: float,
25
+ eps_0: float = -0.002,
26
+ eps_u: float = -0.0035,
27
+ n: float = 2.0,
28
+ name: t.Optional[str] = None,
29
+ ) -> None:
30
+ """Initialize a Parabola-Rectangle Material.
31
+
32
+ Arguments:
33
+ fc (float): The strength of concrete in compression.
34
+
35
+ Keyword Arguments:
36
+ eps_0 (float): Peak strain of concrete in compression. Default
37
+ value = -0.002.
38
+ eps_u (float): Ultimate strain of concrete in compression. Default
39
+ value = -0.0035.
40
+ n (float): Exponent for the pre-peak branch. Default value = 2.
41
+ name (str): A name for the constitutive law.
42
+ """
43
+ name = name if name is not None else 'ParabolaRectangleLaw'
44
+ super().__init__(name=name)
45
+ self._fc = -abs(fc)
46
+ self._eps_0 = -abs(eps_0)
47
+ self._eps_u = -abs(eps_u)
48
+ self._n = n
49
+
50
+ def get_stress(
51
+ self, eps: t.Union[float, ArrayLike]
52
+ ) -> t.Union[float, ArrayLike]:
53
+ """Return the stress given strain."""
54
+ eps = eps if np.isscalar(eps) else np.atleast_1d(eps)
55
+ # Preprocess eps array in order
56
+ eps = self.preprocess_strains_with_limits(eps=eps)
57
+ # Compute stress
58
+ # If it is a scalar
59
+ if np.isscalar(eps):
60
+ sig = 0
61
+ if self._eps_0 <= eps <= 0:
62
+ sig = self._fc * (1 - (1 - eps / self._eps_0) ** self._n)
63
+ if self._eps_u <= eps < self._eps_0:
64
+ sig = self._fc
65
+ return sig
66
+ # If it is an array
67
+ sig = np.zeros_like(eps)
68
+ # Parabolic branch
69
+ sig[(eps <= 0) & (eps >= self._eps_0)] = self._fc * (
70
+ 1
71
+ - (1 - (eps[(eps <= 0) & (eps >= self._eps_0)] / self._eps_0))
72
+ ** self._n
73
+ )
74
+ # Rectangle branch
75
+ sig[eps < self._eps_0] = self._fc
76
+ # Zero elsewhere
77
+ sig[eps < self._eps_u] = 0
78
+ sig[eps > 0] = 0
79
+ return sig
80
+
81
+ def get_tangent(
82
+ self, eps: t.Union[float, ArrayLike]
83
+ ) -> t.Union[float, ArrayLike]:
84
+ """Return the tangent given strain."""
85
+ eps = eps if np.isscalar(eps) else np.atleast_1d(eps)
86
+ # If it is a scalar
87
+ if np.isscalar(eps):
88
+ tangent = 0
89
+ if self._eps_0 <= eps <= 0:
90
+ tangent = (
91
+ self._n
92
+ * self._fc
93
+ / self._eps_0
94
+ * (1 - (eps / self._eps_0)) ** (self._n - 1)
95
+ )
96
+ return tangent
97
+ # If it is an array
98
+ # parabolic branch
99
+ tangent = np.zeros_like(eps)
100
+ tangent[(eps <= 0) & (eps >= self._eps_0)] = (
101
+ self._n
102
+ * self._fc
103
+ / self._eps_0
104
+ * (1 - (eps[(eps <= 0) & (eps >= self._eps_0)] / self._eps_0))
105
+ ** (self._n - 1)
106
+ )
107
+ # Elsewhere tangent is zero
108
+ tangent[eps < self._eps_0] = 0.0
109
+ tangent[eps > 0] = 0.0
110
+ return tangent
111
+
112
+ def __marin__(
113
+ self, strain: t.Tuple[float, float]
114
+ ) -> t.Tuple[t.List[float], t.List[float]]:
115
+ """Returns coefficients and strain limits for Marin integration in a
116
+ simply formatted way.
117
+
118
+ Arguments:
119
+ strain (float, float): Tuple defining the strain profile: eps =
120
+ strain[0] + strain[1]*y.
121
+
122
+ Example:
123
+ [(0, -0.002), (-0.002, -0.003)]
124
+ [(a0, a1, a2), (a0)]
125
+ """
126
+ if self._n != 2:
127
+ # The constitutive law is not writtable as a polynomial,
128
+ # Call the generic distretizing method
129
+ return super().__marin__(strain=strain)
130
+
131
+ strains = []
132
+ coeff = []
133
+ if strain[1] == 0:
134
+ # Uniform strain equal to strain[0]
135
+ # understand in which branch are we
136
+ strain[0] = self.preprocess_strains_with_limits(strain[0])
137
+ if strain[0] > 0:
138
+ # We are in tensile branch
139
+ strains = None
140
+ coeff.append((0.0,))
141
+ elif strain[0] > self._eps_0:
142
+ # We are in the parabolic branch
143
+ strains = None
144
+ a0 = (
145
+ 2
146
+ * self._fc
147
+ * strain[0]
148
+ / self._eps_0
149
+ * (1 - 0.5 * (strain[0] / self._eps_0))
150
+ )
151
+ a1 = (
152
+ 2
153
+ * self._fc
154
+ / self._eps_0
155
+ * strain[1]
156
+ * (1 - strain[0] / self._eps_0)
157
+ )
158
+ coeff.append((a0, a1, 0.0))
159
+ elif strain[0] >= self._eps_u:
160
+ # We are in the constant branch
161
+ strains = None
162
+ coeff.append((self._fc,))
163
+ else:
164
+ # We are in a branch of non-resisting concrete
165
+ # Too much compression
166
+ strains = None
167
+ coeff.append((0.0,))
168
+ else:
169
+ # Parabolic part
170
+ strains.append((self._eps_0, 0))
171
+ a0 = (
172
+ 2
173
+ * self._fc
174
+ * strain[0]
175
+ / self._eps_0
176
+ * (1 - 0.5 * (strain[0] / self._eps_0))
177
+ )
178
+ a1 = (
179
+ 2
180
+ * self._fc
181
+ / self._eps_0
182
+ * strain[1]
183
+ * (1 - strain[0] / self._eps_0)
184
+ )
185
+ a2 = -self._fc * strain[1] ** 2 / self._eps_0**2
186
+ coeff.append((a0, a1, a2))
187
+ # Constant part
188
+ strains.append((self._eps_u, self._eps_0))
189
+ coeff.append((self._fc,))
190
+ return strains, coeff
191
+
192
+ def get_ultimate_strain(
193
+ self, yielding: bool = False
194
+ ) -> t.Tuple[float, float]:
195
+ """Return the ultimate strain (negative and positive)."""
196
+ if yielding:
197
+ return (self._eps_0, 100)
198
+ return (self._eps_u, 100)
@@ -0,0 +1,133 @@
1
+ """Popovics constitutive law."""
2
+
3
+ from __future__ import annotations # To have clean hints of ArrayLike in docs
4
+
5
+ import typing as t
6
+
7
+ import numpy as np
8
+ from numpy.typing import ArrayLike
9
+
10
+ from ...core.base import ConstitutiveLaw
11
+
12
+
13
+ class Popovics(ConstitutiveLaw):
14
+ """Class for Popovics-Mander constitutive law.
15
+
16
+ The stresses and strains are assumed negative in compression and positive
17
+ in tension.
18
+
19
+ If the relation Ec = 5000 * sqrt(fc) is used for elastic modulus, the
20
+ constitutive law is identical to the one proposed by Mander et al. (1988).
21
+
22
+ References:
23
+ Popovics, S., 1973, “A Numerical Approach to the Complete Stress-Strain
24
+ Curve of Concrete”, Cement and Concrete Research, 3(4), 583-599.
25
+
26
+ Mander, J.B., Priestley, M.J.N., Park, R., 1988, "Theoretical Stress-Strain
27
+ Model for Confined Concrete", Journal of Structural Engineering, 114(8),
28
+ 1804-1826.
29
+ """
30
+
31
+ __materials__: t.Tuple[str] = ('concrete',)
32
+
33
+ def __init__(
34
+ self,
35
+ fc: float,
36
+ eps_c: float = -0.002,
37
+ eps_cu: float = -0.0035,
38
+ Ec: t.Optional[float] = None,
39
+ name: t.Optional[str] = None,
40
+ ) -> None:
41
+ """Initialize a Popovics Material.
42
+
43
+ Arguments:
44
+ fc (float): the strength of concrete in compression
45
+
46
+ Keyword Arguments:
47
+ eps_c (float): Peak strain of concrete in compression. Default
48
+ value = -0.002.
49
+ eps_cu (float): Ultimate strain of concrete in compression. Default
50
+ value = -0.0035.
51
+ E (optional float): Elastic modulus of concrete. If None, the
52
+ equation Ec = 5000 * fc**0.5 proposed by Mander et al. (1988)
53
+ is adopted (fc in MPa). Default value = None.
54
+ name (str): A name for the constitutive law.
55
+
56
+ Raises:
57
+ ValueError: If E is less or equal to 0.
58
+
59
+ Note:
60
+ If positive values are input for fc, eps_c and eps_cu are input,
61
+ they will be assumed negative.
62
+ """
63
+ name = name if name is not None else 'PopovicsLaw'
64
+ super().__init__(name=name)
65
+ self._fc = -abs(fc)
66
+ self._eps_c = -abs(eps_c)
67
+ self._eps_cu = -abs(eps_cu)
68
+ if Ec is None:
69
+ # fc in MPa, relation of Mander et al. (1988)
70
+ Ec = 5000 * abs(fc) ** 0.5
71
+ if Ec <= 0:
72
+ raise ValueError('Elastic modulus must be a positive number.')
73
+ E_sec = self._fc / self._eps_c
74
+ self._n = Ec / (Ec - E_sec)
75
+
76
+ def get_stress(
77
+ self, eps: t.Union[float, ArrayLike]
78
+ ) -> t.Union[float, ArrayLike]:
79
+ """Return the stress given the strain."""
80
+ eps = eps if np.isscalar(eps) else np.atleast_1d(eps)
81
+ # Preprocess eps array in order
82
+ eps = self.preprocess_strains_with_limits(eps=eps)
83
+ # Compute stress
84
+ # Compression branch
85
+ eta = eps / self._eps_c
86
+
87
+ sig = self._fc * eta * self._n / (self._n - 1 + eta**self._n)
88
+
89
+ # Elsewhere stress is 0.0
90
+ if np.isscalar(eps):
91
+ if eps < self._eps_cu or eps > 0:
92
+ return 0.0
93
+ else:
94
+ sig[eps < self._eps_cu] = 0.0
95
+ sig[eps > 0] = 0.0
96
+
97
+ return sig
98
+
99
+ def get_tangent(
100
+ self, eps: t.Union[float, ArrayLike]
101
+ ) -> t.Union[float, ArrayLike]:
102
+ """Return the tangent given strain."""
103
+ eps = eps if np.isscalar(eps) else np.atleast_1d(eps)
104
+ # Preprocess eps array in order
105
+ eps = self.preprocess_strains_with_limits(eps=eps)
106
+ # Compression branch
107
+ eta = eps / self._eps_c
108
+
109
+ tangent = (
110
+ (1 - eta**self._n)
111
+ / (self._n - 1 + eta**self._n) ** 2
112
+ * self._n
113
+ * (self._n - 1)
114
+ * self._fc
115
+ / self._eps_c
116
+ )
117
+ # Elsewhere tangent is zero
118
+ if np.isscalar(eps):
119
+ if eps < self._eps_cu or eps > 0:
120
+ return 0
121
+ else:
122
+ tangent[eps < self._eps_cu] = 0.0
123
+ tangent[eps > 0] = 0.0
124
+
125
+ return tangent
126
+
127
+ def get_ultimate_strain(
128
+ self, yielding: bool = False
129
+ ) -> t.Tuple[float, float]:
130
+ """Return the ultimate strain (negative and positive)."""
131
+ if yielding:
132
+ return (self._eps_c, 100)
133
+ return (self._eps_cu, 100)
@@ -0,0 +1,115 @@
1
+ """Sargin constitutive law."""
2
+
3
+ from __future__ import annotations # To have clean hints of ArrayLike in docs
4
+
5
+ import typing as t
6
+
7
+ import numpy as np
8
+ from numpy.typing import ArrayLike
9
+
10
+ from ...core.base import ConstitutiveLaw
11
+
12
+
13
+ class Sargin(ConstitutiveLaw):
14
+ """Class for Sargin constitutive law.
15
+
16
+ The stresses and strains are assumed negative in compression and positive
17
+ in tension.
18
+
19
+ References:
20
+ Sargin, M. (1971), "Stress-strain relationship for concrete and the
21
+ analysis of structural concrete section, Study No. 4,
22
+ Solid Mechanics Division, University of Waterloo, Ontario, Canada
23
+ """
24
+
25
+ __materials__: t.Tuple[str] = ('concrete',)
26
+
27
+ def __init__(
28
+ self,
29
+ fc: float,
30
+ eps_c1: float = -0.0023,
31
+ eps_cu1: float = -0.0035,
32
+ k: float = 2.04,
33
+ name: t.Optional[str] = None,
34
+ ) -> None:
35
+ """Initialize a Sargin Material.
36
+
37
+ Arguments:
38
+ fc (float): The strength of concrete in compression
39
+
40
+ Keyword Arguments:
41
+ eps_c1 (float): Peak strain of concrete in compression. Default
42
+ value = -0.0023.
43
+ eps_u (float): Ultimate strain of concrete in compression. Default
44
+ value = -0.0035.
45
+ k (float): Plasticity number. Default value = 2.04.
46
+ name (str): A name for the constitutive law.
47
+
48
+ Raises:
49
+ ValueError: If k is less or equal to 0.
50
+
51
+ Note:
52
+ If positive values are input for fc, eps_c1 and eps_cu1 are input,
53
+ they will be assumed negative.
54
+ """
55
+ name = name if name is not None else 'SarginLaw'
56
+ super().__init__(name=name)
57
+ self._fc = -abs(fc)
58
+ self._eps_c1 = -abs(eps_c1)
59
+ self._eps_cu1 = -abs(eps_cu1)
60
+ self._k = k
61
+
62
+ def get_stress(
63
+ self, eps: t.Union[float, ArrayLike]
64
+ ) -> t.Union[float, ArrayLike]:
65
+ """Return the stress given the strain."""
66
+ eps = eps if np.isscalar(eps) else np.atleast_1d(eps)
67
+ # Preprocess eps array in order
68
+ eps = self.preprocess_strains_with_limits(eps=eps)
69
+ # Compute stress
70
+ # Polynomial branch
71
+ eta = eps / self._eps_c1
72
+
73
+ sig = self._fc * (self._k * eta - eta**2) / (1 + (self._k - 2) * eta)
74
+
75
+ # Elsewhere stress is 0.0
76
+ if np.isscalar(eps):
77
+ if eps < self._eps_cu1 or eps > 0:
78
+ return 0.0
79
+ else:
80
+ sig[eps < self._eps_cu1] = 0.0
81
+ sig[eps > 0] = 0.0
82
+
83
+ return sig
84
+
85
+ def get_tangent(
86
+ self, eps: t.Union[float, ArrayLike]
87
+ ) -> t.Union[float, ArrayLike]:
88
+ """Return the tangent given strain."""
89
+ eps = eps if np.isscalar(eps) else np.atleast_1d(eps)
90
+ # polynomial branch
91
+ eta = eps / self._eps_c1
92
+
93
+ tangent = (
94
+ self._fc
95
+ / self._eps_c1
96
+ * ((2 - self._k) * eta**2 - 2 * eta + self._k)
97
+ / (1 + (self._k - 2) * eta) ** 2
98
+ )
99
+ # Elsewhere tangent is zero
100
+ if np.isscalar(eps):
101
+ if eps < self._eps_cu1 or eps > 0:
102
+ return 0
103
+ else:
104
+ tangent[eps < self._eps_cu1] = 0.0
105
+ tangent[eps > 0] = 0.0
106
+
107
+ return tangent
108
+
109
+ def get_ultimate_strain(
110
+ self, yielding: bool = False
111
+ ) -> t.Tuple[float, float]:
112
+ """Return the ultimate strain (negative and positive)."""
113
+ if yielding:
114
+ return (self._eps_c1, 100)
115
+ return (self._eps_cu1, 100)
@@ -0,0 +1,218 @@
1
+ """User defined constitutive law."""
2
+
3
+ from __future__ import annotations # To have clean hints of ArrayLike in docs
4
+
5
+ import typing as t
6
+
7
+ import numpy as np
8
+ from numpy.typing import ArrayLike
9
+
10
+ from ...core.base import ConstitutiveLaw
11
+
12
+
13
+ class UserDefined(ConstitutiveLaw):
14
+ """Class for a user defined constitutive law.
15
+
16
+ The curve is defined with positive and optionally negative values. After
17
+ the last value, the stress can go to zero to simulate failure (default), or
18
+ be maintained constante, or the last tanget or secant values may be
19
+ maintained indefinetely. The flag parameter controls this behavior.
20
+ """
21
+
22
+ __materials__: t.Tuple[str] = ('concrete', 'steel', 'rebars')
23
+
24
+ def __init__(
25
+ self,
26
+ x: ArrayLike,
27
+ y: ArrayLike,
28
+ name: t.Optional[str] = None,
29
+ flag: int = 0,
30
+ ) -> None:
31
+ """Initialize a UserDefined constitutive law.
32
+
33
+ Arguments:
34
+ x (ArrayLike): Data for strains.
35
+ y (ArrayLike): Data for stresses. Must be of same length as x.
36
+
37
+ Keyword Arguments:
38
+ name (Optional, str): A name for the constitutive law.
39
+ flag (Optional): A flag specifying the behavior after the last
40
+ point. Admissible values: 0 (default): stress drops to zero
41
+ after ultimate strain, 1: stress is mantained constant, 2:
42
+ last tangent is used, 3: last secant is used.
43
+ """
44
+ name = name if name is not None else 'UserDefinedLaw'
45
+ super().__init__(name=name)
46
+ x = np.atleast_1d(np.asarray(x))
47
+ y = np.atleast_1d(np.asarray(y))
48
+ if len(x) != len(y):
49
+ raise ValueError('The two arrays should have the same length')
50
+ if not np.any(x < 0):
51
+ # User provided only positive part, reflect in negative
52
+ self._x = np.concatenate((-np.flip(x)[:-1], x))
53
+ self._y = np.concatenate((-np.flip(y)[:-1], y))
54
+ else:
55
+ # User gave both positive and negative parts
56
+ self._x = x
57
+ self._y = y
58
+ # Define what happens after last strain
59
+ if flag not in (0, 1, 2, 3):
60
+ raise ValueError('Flag can assume values 0, 1, 2 or 3.')
61
+ self._ultimate_strain_p = self._x[-1]
62
+ self._ultimate_strain_n = self._x[0]
63
+ if flag in (1, 2, 3):
64
+ x = np.insert(self._x, 0, self._x[0] * 100)
65
+ x = np.append(x, self._x[-1] * 100)
66
+ if flag == 1:
67
+ y = np.insert(self._y, 0, self._y[0])
68
+ y = np.append(y, self._y[-1])
69
+ elif flag == 2:
70
+ tangent_p = (self._y[-1] - self._y[-2]) / (
71
+ self._x[-1] - self._x[-2]
72
+ )
73
+ tangent_n = (self._y[1] - self._y[0]) / (
74
+ self._x[1] - self._x[0]
75
+ )
76
+ y = np.insert(
77
+ self._y, 0, (x[0] - x[1]) * tangent_n + self._y[0]
78
+ )
79
+ y = np.append(y, (x[-1] - x[-2]) * tangent_p + self._y[-1])
80
+ elif flag == 3:
81
+ secant_p = self._y[-1] / self._x[-1]
82
+ secant_n = self._y[0] / self._x[0]
83
+ y = np.insert(
84
+ self._y, 0, (x[0] - x[1]) * secant_n + self._y[0]
85
+ )
86
+ y = np.append(y, (x[-1] - x[-2]) * secant_p + self._y[-1])
87
+ self._x = x
88
+ self._y = y
89
+
90
+ # Compute slope of each segment
91
+ self._slopes = np.diff(self._y) / np.diff(self._x)
92
+
93
+ def get_stress(
94
+ self, eps: t.Union[float, ArrayLike]
95
+ ) -> t.Union[float, ArrayLike]:
96
+ """Return the stress given strain."""
97
+ eps = eps if np.isscalar(eps) else np.atleast_1d(eps)
98
+ # Preprocess eps array in order
99
+ eps = self.preprocess_strains_with_limits(eps=eps)
100
+ # Compute stress
101
+ return np.interp(eps, self._x, self._y, left=0, right=0)
102
+
103
+ def get_tangent(
104
+ self, eps: t.Union[float, ArrayLike]
105
+ ) -> t.Union[float, ArrayLike]:
106
+ """Return the tangent given strain."""
107
+ eps = eps if np.isscalar(eps) else np.atleast_1d(eps)
108
+
109
+ # Find the segment index for each x value
110
+ indices = np.searchsorted(self._x, eps) - 1
111
+
112
+ # Check that indices are within vlaid range
113
+ indices = np.clip(indices, 0, len(self._slopes) - 1)
114
+
115
+ # Get the corresponding slopes
116
+ tangent = self._slopes[indices]
117
+
118
+ # Elsewhere tangent is zero
119
+ if np.isscalar(eps):
120
+ if eps < self._x[0] or eps > self._x[-1]:
121
+ tangent = 0
122
+ else:
123
+ tangent[eps < self._x[0]] = 0.0
124
+ tangent[eps > self._x[-1]] = 0.0
125
+
126
+ return tangent
127
+
128
+ def __marin__(
129
+ self, strain: t.Tuple[float, float]
130
+ ) -> t.Tuple[t.List[t.Tuple], t.List[t.Tuple]]:
131
+ """Returns coefficients and strain limits for Marin integration in a
132
+ simply formatted way.
133
+
134
+ Arguments:
135
+ strain (float, float): Tuple defining the strain profile: eps =
136
+ strain[0] + strain[1]*y.
137
+
138
+ Example:
139
+ [(0, -0.002), (-0.002, -0.003)]
140
+ [(a0, a1, a2), (a0)]
141
+ """
142
+ strains = []
143
+ coeff = []
144
+ if strain[1] == 0:
145
+ # Uniform strain equal to strain[0]
146
+ # understand in which branch are we
147
+ strain[0] = self.preprocess_strains_with_limits(strain[0])
148
+ found = False
149
+ for i in range(len(self._x) - 1):
150
+ if self._x[i] <= strain[0] and self._x[i + 1] >= strain[0]:
151
+ strains = None
152
+ stiffness = (self._y[i + 1] - self._y[i]) / (
153
+ self._x[i + 1] - self._x[i]
154
+ )
155
+ a0 = stiffness * (strain[0] - self._x[i]) + self._y[i]
156
+ a1 = stiffness * strain[1]
157
+ coeff.append((a0, a1))
158
+ found = True
159
+ break
160
+ if not found:
161
+ strains = None
162
+ coeff.append((0.0,))
163
+ else:
164
+ for i in range(len(self._x) - 1):
165
+ # For each branch of the linear piecewise function
166
+ stiffness = (self._y[i + 1] - self._y[i]) / (
167
+ self._x[i + 1] - self._x[i]
168
+ )
169
+ strains.append((self._x[i], self._x[i + 1]))
170
+ a0 = stiffness * (strain[0] - self._x[i]) + self._y[i]
171
+ a1 = stiffness * strain[1]
172
+ coeff.append((a0, a1))
173
+
174
+ return strains, coeff
175
+
176
+ def get_ultimate_strain(self, **kwargs) -> t.Tuple[float, float]:
177
+ """Return the ultimate strain (negative and positive)."""
178
+ del kwargs
179
+ return (self._ultimate_strain_n, self._ultimate_strain_p)
180
+
181
+ def set_ultimate_strain(
182
+ self, eps_su=t.Union[float, t.Tuple[float, float]]
183
+ ) -> None:
184
+ """Set ultimate strains for Elastic Material if needed.
185
+
186
+ Arguments:
187
+ eps_su (float or (float, float)): Defining ultimate strain. If a
188
+ single value is provided the same is adopted for both negative
189
+ and positive strains. If a tuple is provided, it should be
190
+ given as (negative, positive).
191
+ """
192
+ if isinstance(eps_su, float):
193
+ self._ultimate_strain_p = abs(eps_su)
194
+ self._ultimate_strain_n = -abs(eps_su)
195
+ elif isinstance(eps_su, tuple):
196
+ if len(eps_su) < 2:
197
+ raise ValueError(
198
+ 'Two values need to be provided when setting the tuple'
199
+ )
200
+ eps_su_n = eps_su[0]
201
+ eps_su_p = eps_su[1]
202
+ if eps_su_p < eps_su_n:
203
+ eps_su_p, eps_su_n = eps_su_n, eps_su_p
204
+ if eps_su_p < 0:
205
+ raise ValueError(
206
+ 'Positive ultimate strain should be non-negative'
207
+ )
208
+ if eps_su_n > 0:
209
+ raise ValueError(
210
+ 'Negative utimate strain should be non-positive'
211
+ )
212
+ self._ultimate_strain_p = eps_su_p
213
+ self._ultimate_strain_n = eps_su_n
214
+ else:
215
+ raise ValueError(
216
+ 'set_ultimate_strain requires a single value or a tuple \
217
+ with two values'
218
+ )