Skip to content

Commit c66240f

Browse files
committed
fix typos, incorrect ref to data, use of super, docs warnings, ...
1 parent fb60a56 commit c66240f

File tree

17 files changed

+106
-79
lines changed

17 files changed

+106
-79
lines changed

src/compas_fea2/job/input_file.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class InputFile(FEAData):
2727
"""
2828

2929
def __init__(self, problem, **kwargs):
30-
super(InputFile, self).__init__(**kwargs)
30+
super().__init__(**kwargs)
3131
self._registration = problem
3232
self._extension = None
3333
self.path = None
@@ -47,6 +47,7 @@ def model(self):
4747
# ==============================================================================
4848
# General methods
4949
# ==============================================================================
50+
5051
def write_to_file(self, path=None):
5152
"""Writes the InputFile to a file in a specified location.
5253
@@ -76,5 +77,5 @@ class ParametersFile(InputFile):
7677
"""Input file object for Optimizations."""
7778

7879
def __init__(self, **kwargs):
79-
super(ParametersFile, self).__init__(**kwargs)
80-
raise NotImplementedError()
80+
super().__init__(**kwargs)
81+
raise NotImplementedError

src/compas_fea2/model/bcs.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
class _BoundaryCondition(FEAData):
4646
"""Base class for all zero-valued boundary conditions."""
4747

48-
__doc__ += docs
48+
__doc__ += docs # type: ignore
4949

5050
def __init__(self, axes: str = "global", **kwargs):
5151
super().__init__(**kwargs)
@@ -94,7 +94,7 @@ def components(self) -> Dict[str, bool]:
9494
return {c: getattr(self, c) for c in ["x", "y", "z", "xx", "yy", "zz"]}
9595

9696
@property
97-
def __data__(self) -> Dict[str, any]:
97+
def __data__(self) -> dict:
9898
return {
9999
"class": self.__class__.__base__.__name__,
100100
"axes": self._axes,
@@ -107,7 +107,7 @@ def __data__(self) -> Dict[str, any]:
107107
}
108108

109109
@classmethod
110-
def __from_data__(cls, data: Dict[str, any]):
110+
def __from_data__(cls, data: dict):
111111
return cls(
112112
axes=data.get("axes", "global"),
113113
x=data.get("x", False),
@@ -122,7 +122,8 @@ def __from_data__(cls, data: Dict[str, any]):
122122
class GeneralBC(_BoundaryCondition):
123123
"""Customized boundary condition."""
124124

125-
__doc__ += docs
125+
__doc__ += docs # type: ignore
126+
126127
__doc__ += """
127128
Additional Parameters
128129
---------------------
@@ -153,7 +154,7 @@ def __init__(self, x: bool = False, y: bool = False, z: bool = False, xx: bool =
153154
class FixedBC(_BoundaryCondition):
154155
"""A fixed nodal displacement boundary condition."""
155156

156-
__doc__ += docs
157+
__doc__ += docs # type: ignore
157158

158159
def __init__(self, **kwargs):
159160
super().__init__(**kwargs)
@@ -168,7 +169,7 @@ def __init__(self, **kwargs):
168169
class FixedBCX(_BoundaryCondition):
169170
"""A fixed nodal displacement boundary condition along and around X."""
170171

171-
__doc__ += docs
172+
__doc__ += docs # type: ignore
172173

173174
def __init__(self, **kwargs):
174175
super().__init__(**kwargs)
@@ -179,7 +180,7 @@ def __init__(self, **kwargs):
179180
class FixedBCY(_BoundaryCondition):
180181
"""A fixed nodal displacement boundary condition along and around Y."""
181182

182-
__doc__ += docs
183+
__doc__ += docs # type: ignore
183184

184185
def __init__(self, **kwargs):
185186
super().__init__(**kwargs)
@@ -190,7 +191,7 @@ def __init__(self, **kwargs):
190191
class FixedBCZ(_BoundaryCondition):
191192
"""A fixed nodal displacement boundary condition along and around Z."""
192193

193-
__doc__ += docs
194+
__doc__ += docs # type: ignore
194195

195196
def __init__(self, **kwargs):
196197
super().__init__(**kwargs)
@@ -201,7 +202,7 @@ def __init__(self, **kwargs):
201202
class PinnedBC(_BoundaryCondition):
202203
"""A pinned nodal displacement boundary condition."""
203204

204-
__doc__ += docs
205+
__doc__ += docs # type: ignore
205206

206207
def __init__(self, **kwargs):
207208
super().__init__(**kwargs)
@@ -213,7 +214,7 @@ def __init__(self, **kwargs):
213214
class ClampBCXX(PinnedBC):
214215
"""A pinned nodal displacement boundary condition clamped in XX."""
215216

216-
__doc__ += docs
217+
__doc__ += docs # type: ignore
217218

218219
def __init__(self, **kwargs):
219220
super().__init__(**kwargs)
@@ -223,7 +224,7 @@ def __init__(self, **kwargs):
223224
class ClampBCYY(PinnedBC):
224225
"""A pinned nodal displacement boundary condition clamped in YY."""
225226

226-
__doc__ += docs
227+
__doc__ += docs # type: ignore
227228

228229
def __init__(self, **kwargs):
229230
super().__init__(**kwargs)
@@ -233,7 +234,7 @@ def __init__(self, **kwargs):
233234
class ClampBCZZ(PinnedBC):
234235
"""A pinned nodal displacement boundary condition clamped in ZZ."""
235236

236-
__doc__ += docs
237+
__doc__ += docs # type: ignore
237238

238239
def __init__(self, **kwargs):
239240
super().__init__(**kwargs)
@@ -243,7 +244,7 @@ def __init__(self, **kwargs):
243244
class RollerBCX(PinnedBC):
244245
"""A pinned nodal displacement boundary condition released in X."""
245246

246-
__doc__ += docs
247+
__doc__ += docs # type: ignore
247248

248249
def __init__(self, **kwargs):
249250
super().__init__(**kwargs)
@@ -253,7 +254,7 @@ def __init__(self, **kwargs):
253254
class RollerBCY(PinnedBC):
254255
"""A pinned nodal displacement boundary condition released in Y."""
255256

256-
__doc__ += docs
257+
__doc__ += docs # type: ignore
257258

258259
def __init__(self, **kwargs):
259260
super().__init__(**kwargs)
@@ -263,7 +264,7 @@ def __init__(self, **kwargs):
263264
class RollerBCZ(PinnedBC):
264265
"""A pinned nodal displacement boundary condition released in Z."""
265266

266-
__doc__ += docs
267+
__doc__ += docs # type: ignore
267268

268269
def __init__(self, **kwargs):
269270
super().__init__(**kwargs)
@@ -273,7 +274,7 @@ def __init__(self, **kwargs):
273274
class RollerBCXY(PinnedBC):
274275
"""A pinned nodal displacement boundary condition released in X and Y."""
275276

276-
__doc__ += docs
277+
__doc__ += docs # type: ignore
277278

278279
def __init__(self, **kwargs):
279280
super().__init__(**kwargs)
@@ -284,7 +285,7 @@ def __init__(self, **kwargs):
284285
class RollerBCYZ(PinnedBC):
285286
"""A pinned nodal displacement boundary condition released in Y and Z."""
286287

287-
__doc__ += docs
288+
__doc__ += docs # type: ignore
288289

289290
def __init__(self, **kwargs):
290291
super().__init__(**kwargs)
@@ -295,7 +296,7 @@ def __init__(self, **kwargs):
295296
class RollerBCXZ(PinnedBC):
296297
"""A pinned nodal displacement boundary condition released in X and Z."""
297298

298-
__doc__ += docs
299+
__doc__ += docs # type: ignore
299300

300301
def __init__(self, **kwargs):
301302
super().__init__(**kwargs)

src/compas_fea2/model/ics.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, **kwargs):
1515
super(_InitialCondition, self).__init__(**kwargs)
1616

1717
@property
18-
def __data__(self):
18+
def __data__(self) -> dict:
1919
return {
2020
"type": self.__class__.__base__.__name__,
2121
}
@@ -111,11 +111,7 @@ def stress(self, value):
111111
@property
112112
def __data__(self):
113113
data = super().__data__
114-
data.update(
115-
{
116-
"stress": self._s,
117-
}
118-
)
114+
data.update({"stress": self._s})
119115
return data
120116

121117
@classmethod

src/compas_fea2/model/materials/concrete.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Concrete(_Material):
4545
"""
4646

4747
def __init__(self, *, fck, E=None, v=None, density=None, fr=None, units=None, **kwargs):
48-
super(Concrete, self).__init__(density=density, **kwargs)
48+
super().__init__(density=density, **kwargs)
4949

5050
# Ensure small increment for stress-strain curve
5151
de = 0.0001
@@ -107,9 +107,7 @@ def __str__(self):
107107
G : {}
108108
fck : {}
109109
fr : {}
110-
""".format(
111-
self.name, self.density, self.E, self.v, self.G, self.fck, self.fr
112-
)
110+
""".format(self.name, self.density, self.E, self.v, self.G, self.fck, self.fr)
113111

114112
@property
115113
def __data__(self):
@@ -140,9 +138,9 @@ def __from_data__(cls, data):
140138
@classmethod
141139
def C20_25(cls, units, **kwargs):
142140
if not units:
143-
units = u.get_default_units()
141+
units = u(system="SI_mm")
144142
elif not isinstance(units, UnitRegistry):
145-
units = u.get_units(units)
143+
units = u(units)
146144

147145
return cls(fck=25 * units.MPa, E=30 * units.GPa, v=0.17, density=2400 * units("kg/m**3"), name="C20/25", **kwargs)
148146

@@ -196,7 +194,7 @@ class ConcreteSmearedCrack(_Material):
196194
"""
197195

198196
def __init__(self, *, E, v, density, fc, ec, ft, et, fr=[1.16, 0.0836], **kwargs):
199-
super(ConcreteSmearedCrack, self).__init__(density=density, **kwargs)
197+
super().__init__(density=density, **kwargs)
200198

201199
self.E = E
202200
self.v = v
@@ -228,9 +226,7 @@ def __str__(self):
228226
ft : {}
229227
et : {}
230228
fr : {}
231-
""".format(
232-
self.name, self.density, self.E, self.v, self.G, self.fc, self.ec, self.ft, self.et, self.fr
233-
)
229+
""".format(self.name, self.density, self.E, self.v, self.G, self.fc, self.ec, self.ft, self.et, self.fr)
234230

235231
@property
236232
def __data__(self):
@@ -303,7 +299,7 @@ class ConcreteDamagedPlasticity(_Material):
303299
"""
304300

305301
def __init__(self, *, E, v, density, damage, hardening, stiffening, **kwargs):
306-
super(ConcreteDamagedPlasticity, self).__init__(density=density, **kwargs)
302+
super().__init__(density=density, **kwargs)
307303

308304
self.E = E
309305
self.v = v

src/compas_fea2/model/materials/material.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
from compas_fea2.base import FEAData
24

35

@@ -37,15 +39,11 @@ class _Material(FEAData):
3739
3840
"""
3941

40-
def __init__(self, density: float, expansion: float = None, **kwargs):
42+
def __init__(self, density: Optional[float] = None, expansion: Optional[float] = None, **kwargs):
4143
super().__init__(**kwargs)
4244
self.density = density
4345
self.expansion = expansion
4446

45-
@property
46-
def key(self) -> int:
47-
return self._key
48-
4947
@property
5048
def model(self):
5149
return self._registration
@@ -77,9 +75,7 @@ def __str__(self) -> str:
7775
name : {}
7876
density : {}
7977
expansion : {}
80-
""".format(
81-
self.__class__.__name__, len(self.__class__.__name__) * "-", self.name, self.density, self.expansion
82-
)
78+
""".format(self.__class__.__name__, len(self.__class__.__name__) * "-", self.name, self.density, self.expansion)
8379

8480
def __html__(self) -> str:
8581
return """<html>
@@ -138,7 +134,21 @@ class ElasticOrthotropic(_Material):
138134
Shear modulus Gzx in z-x directions.
139135
"""
140136

141-
def __init__(self, Ex: float, Ey: float, Ez: float, vxy: float, vyz: float, vzx: float, Gxy: float, Gyz: float, Gzx: float, density: float, expansion: float = None, **kwargs):
137+
def __init__(
138+
self,
139+
Ex: float,
140+
Ey: float,
141+
Ez: float,
142+
vxy: float,
143+
vyz: float,
144+
vzx: float,
145+
Gxy: float,
146+
Gyz: float,
147+
Gzx: float,
148+
density: float,
149+
expansion: Optional[float] = None,
150+
**kwargs,
151+
):
142152
super().__init__(density=density, expansion=expansion, **kwargs)
143153
self.Ex = Ex
144154
self.Ey = Ey
@@ -152,7 +162,7 @@ def __init__(self, Ex: float, Ey: float, Ez: float, vxy: float, vyz: float, vzx:
152162

153163
@property
154164
def __data__(self):
155-
data = super().__data__()
165+
data = super().__data__
156166
data.update(
157167
{
158168
"Ex": self.Ex,
@@ -241,7 +251,7 @@ class ElasticIsotropic(_Material):
241251
242252
"""
243253

244-
def __init__(self, E: float, v: float, density: float, expansion: float = None, **kwargs):
254+
def __init__(self, E: float, v: float, density: float, expansion: Optional[float] = None, **kwargs):
245255
super().__init__(density=density, expansion=expansion, **kwargs)
246256
self.E = E
247257
self.v = v
@@ -272,9 +282,7 @@ def __str__(self) -> str:
272282
E : {}
273283
v : {}
274284
G : {}
275-
""".format(
276-
self.name, self.density, self.expansion, self.E, self.v, self.G
277-
)
285+
""".format(self.name, self.density, self.expansion, self.E, self.v, self.G)
278286

279287
@property
280288
def G(self) -> float:
@@ -284,7 +292,7 @@ def G(self) -> float:
284292
class Stiff(_Material):
285293
"""Elastic, very stiff and massless material."""
286294

287-
def __init__(self, *, density: float, expansion: float = None, name: str = None, **kwargs):
295+
def __init__(self, *, density: float, expansion: Optional[float] = None, name: Optional[str] = None, **kwargs):
288296
raise NotImplementedError()
289297

290298

@@ -318,13 +326,13 @@ class ElasticPlastic(ElasticIsotropic):
318326
in the form of strain/stress value pairs.
319327
"""
320328

321-
def __init__(self, *, E: float, v: float, density: float, strain_stress: list[tuple[float, float]], expansion: float = None, **kwargs):
329+
def __init__(self, *, E: float, v: float, density: float, strain_stress: list[tuple[float, float]], expansion: Optional[float] = None, **kwargs):
322330
super().__init__(E=E, v=v, density=density, expansion=expansion, **kwargs)
323331
self.strain_stress = strain_stress
324332

325333
@property
326334
def __data__(self):
327-
data = super().__data__()
335+
data = super().__data__
328336
data.update(
329337
{
330338
"strain_stress": self.strain_stress,
@@ -355,9 +363,7 @@ def __str__(self) -> str:
355363
G : {}
356364
357365
strain_stress : {}
358-
""".format(
359-
self.name, self.density, self.expansion, self.E, self.v, self.G, self.strain_stress
360-
)
366+
""".format(self.name, self.density, self.expansion, self.E, self.v, self.G, self.strain_stress)
361367

362368

363369
# ==============================================================================

0 commit comments

Comments
 (0)