databies 0.1.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.
- databies/__init__.py +65 -0
- databies/api.py +251 -0
- databies/models/__init__.py +23 -0
- databies/models/beam.py +316 -0
- databies/models/loads.py +226 -0
- databies/models/releases.py +44 -0
- databies/models/supports.py +125 -0
- databies/py.typed +0 -0
- databies/results/__init__.py +17 -0
- databies/results/diagrams.py +477 -0
- databies/results/plotter.py +273 -0
- databies/results/results.py +393 -0
- databies/solver/__init__.py +5 -0
- databies/solver/classifier.py +105 -0
- databies/solver/dispatch.py +130 -0
- databies/solver/fem.py +1352 -0
- databies/solver/integration.py +351 -0
- databies/solver/static.py +241 -0
- databies/utils/__init__.py +4 -0
- databies/utils/numerics.py +5 -0
- databies/utils/validators.py +157 -0
- databies-0.1.0.dist-info/METADATA +509 -0
- databies-0.1.0.dist-info/RECORD +25 -0
- databies-0.1.0.dist-info/WHEEL +4 -0
- databies-0.1.0.dist-info/licenses/LICENSE +21 -0
databies/__init__.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Interfaz publica del paquete databies.
|
|
2
|
+
|
|
3
|
+
Todo lo necesario para analizar una viga se importa directamente desde aqui::
|
|
4
|
+
|
|
5
|
+
from databies import Beam, Material, CrossSection, PinSupport, analyze
|
|
6
|
+
|
|
7
|
+
Los internos del solver (``solve_fem``, ``FemSolution``, ``classify_beam``, ...)
|
|
8
|
+
siguen accesibles desde sus submodulos, pero no forman parte de la API publica
|
|
9
|
+
documentada.
|
|
10
|
+
|
|
11
|
+
Ningun modulo interno importa desde esta raiz: el paquete se organiza en
|
|
12
|
+
``databies.models``, ``databies.solver``, ``databies.results`` y
|
|
13
|
+
``databies.utils``, y esta raiz solo los reexporta. Si un modulo interno
|
|
14
|
+
importara desde aqui se crearia un import circular.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
18
|
+
|
|
19
|
+
from databies.api import analyze
|
|
20
|
+
from databies.models import (
|
|
21
|
+
Beam,
|
|
22
|
+
CrossSection,
|
|
23
|
+
DistributedLoad,
|
|
24
|
+
FixedSupport,
|
|
25
|
+
InternalHinge,
|
|
26
|
+
Material,
|
|
27
|
+
MomentLoad,
|
|
28
|
+
PinSupport,
|
|
29
|
+
PointLoad,
|
|
30
|
+
RollerSupport,
|
|
31
|
+
)
|
|
32
|
+
from databies.results import (
|
|
33
|
+
DeflectionDiagram,
|
|
34
|
+
MomentDiagram,
|
|
35
|
+
Results,
|
|
36
|
+
RotationDiagram,
|
|
37
|
+
ShearDiagram,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
__version__ = version("databies")
|
|
42
|
+
except PackageNotFoundError:
|
|
43
|
+
# Codigo fuente usado sin instalar (p. ej. con PYTHONPATH): no hay metadatos
|
|
44
|
+
# de distribucion de donde leer la version, pero importar no debe fallar.
|
|
45
|
+
__version__ = "0.0.0+unknown"
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
"analyze",
|
|
49
|
+
"Results",
|
|
50
|
+
"ShearDiagram",
|
|
51
|
+
"MomentDiagram",
|
|
52
|
+
"RotationDiagram",
|
|
53
|
+
"DeflectionDiagram",
|
|
54
|
+
"Beam",
|
|
55
|
+
"Material",
|
|
56
|
+
"CrossSection",
|
|
57
|
+
"PinSupport",
|
|
58
|
+
"RollerSupport",
|
|
59
|
+
"FixedSupport",
|
|
60
|
+
"PointLoad",
|
|
61
|
+
"DistributedLoad",
|
|
62
|
+
"MomentLoad",
|
|
63
|
+
"InternalHinge",
|
|
64
|
+
"__version__",
|
|
65
|
+
]
|
databies/api.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"""API principal de Databies.
|
|
2
|
+
|
|
3
|
+
``analyze(beam)`` es el punto de entrada publico de la libreria: recibe una
|
|
4
|
+
viga ya modelada y devuelve un ``Results`` con reacciones, cortante, momento,
|
|
5
|
+
rotacion, deflexion, clasificacion y advertencias, sin que el usuario tenga que
|
|
6
|
+
clasificar la viga ni elegir el solver. Tambien puede resolver las cargas
|
|
7
|
+
mayoradas o solo las de un caso (``factored``, ``case``), sin modificar la viga.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from collections.abc import Sequence
|
|
13
|
+
from dataclasses import dataclass, replace
|
|
14
|
+
|
|
15
|
+
from databies.models.beam import Beam, Load
|
|
16
|
+
from databies.models.loads import (
|
|
17
|
+
LOAD_CASES,
|
|
18
|
+
DistributedLoad,
|
|
19
|
+
LoadCase,
|
|
20
|
+
LoadFunction,
|
|
21
|
+
)
|
|
22
|
+
from databies.results.results import Results
|
|
23
|
+
from databies.solver.dispatch import select_solver
|
|
24
|
+
from databies.solver.fem import validate_refinement
|
|
25
|
+
from databies.utils.validators import validate_beam
|
|
26
|
+
|
|
27
|
+
_MIN_SAMPLE_COUNT = 2
|
|
28
|
+
DEFAULT_ELEMENTS_PER_SPAN = 8
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def analyze(
|
|
32
|
+
beam: Beam,
|
|
33
|
+
*,
|
|
34
|
+
factored: bool = False,
|
|
35
|
+
case: LoadCase | None = None,
|
|
36
|
+
sample_count: int = 101,
|
|
37
|
+
elements_per_span: int | None = DEFAULT_ELEMENTS_PER_SPAN,
|
|
38
|
+
max_element_length: float | None = None,
|
|
39
|
+
) -> Results:
|
|
40
|
+
"""Analiza una viga y devuelve sus reacciones y diagramas.
|
|
41
|
+
|
|
42
|
+
Elige el camino con ``select_solver`` (ver sus reglas): el estatico usa
|
|
43
|
+
``Results.for_isostatic`` (equilibrio estatico, incluye ``"Rx"``) y el FEM
|
|
44
|
+
usa ``Results.for_hyperstatic``. El formato del ``Results`` devuelto es el
|
|
45
|
+
mismo en ambos casos, y las explicaciones de la eleccion (por ejemplo, por
|
|
46
|
+
que una viga isostatica se resolvio por FEM) llegan en ``warnings``.
|
|
47
|
+
|
|
48
|
+
Toda la validacion ocurre antes de resolver nada, de modo que una entrada
|
|
49
|
+
invalida nunca llega a ensamblar matrices. ``analyze`` no modifica la viga:
|
|
50
|
+
no llama a ``beam.solve()`` y acepta vigas resueltas o no.
|
|
51
|
+
|
|
52
|
+
Por defecto se resuelven las cargas con su magnitud nominal, sin mirar su
|
|
53
|
+
caso ni su factor. Con ``factored=True`` cada carga se multiplica por su
|
|
54
|
+
``factor`` (una carga sin caso entra con factor 1). Con ``case`` se
|
|
55
|
+
resuelven solo las cargas de ese caso, como si las demas no existieran.
|
|
56
|
+
Ambas opciones se combinan. Con cualquiera de las dos se resuelve una copia
|
|
57
|
+
de la viga con las cargas seleccionadas; con las opciones por defecto se
|
|
58
|
+
resuelve la viga recibida tal cual. En ningun caso la viga cambia.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
beam: Viga a analizar, con apoyos, cargas y articulaciones ya agregados.
|
|
62
|
+
factored: Si es ``True``, multiplica cada carga por su ``factor``.
|
|
63
|
+
case: ``"dead"`` o ``"live"`` para resolver solo las cargas de ese
|
|
64
|
+
caso; ``None`` (por defecto) resuelve todas.
|
|
65
|
+
sample_count: Numero minimo de puntos de muestreo de los diagramas.
|
|
66
|
+
Los diagramas pueden incluir puntos adicionales (por ejemplo, en
|
|
67
|
+
cargas o articulaciones).
|
|
68
|
+
elements_per_span: Elementos FEM por tramo obligatorio (entre apoyos,
|
|
69
|
+
cargas y articulaciones). ``None`` conserva la malla que dicta solo
|
|
70
|
+
la geometria cuando no se pide una longitud maxima.
|
|
71
|
+
max_element_length: Longitud maxima opcional de cada elemento FEM, en
|
|
72
|
+
metros.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
``Results`` de la viga, con reacciones en N (y N·m para ``"Mz"``),
|
|
76
|
+
cortante en N, momento en N·m, rotacion en rad y deflexion en m.
|
|
77
|
+
Siempre incluye ``load_basis`` (``"nominal"`` o ``"factored"``),
|
|
78
|
+
``load_cases`` (casos utilizados, en orden muerta y viva, sin repetir;
|
|
79
|
+
``()`` si no hay casos) y ``load_filter`` (el ``case`` pedido o ``None``).
|
|
80
|
+
|
|
81
|
+
Raises:
|
|
82
|
+
TypeError: si ``beam`` no es un ``Beam`` o ``factored`` no es ``bool``.
|
|
83
|
+
ValueError: si ``sample_count`` no es un entero mayor o igual a 2, si
|
|
84
|
+
``case`` no es ``"dead"``, ``"live"`` ni ``None``, si dos cargas
|
|
85
|
+
del mismo caso tienen factores distintos, si se pide un caso sin
|
|
86
|
+
cargas, si el modelo es invalido segun ``validate_beam``, si la viga es
|
|
87
|
+
inestable, si una carga axial cae en el camino FEM
|
|
88
|
+
(``UnsupportedAxialLoadError``), o si la viga es un mecanismo que
|
|
89
|
+
el conteo de GH no detecta.
|
|
90
|
+
|
|
91
|
+
Example:
|
|
92
|
+
>>> from databies import Beam, CrossSection, Material, PinSupport
|
|
93
|
+
>>> from databies import PointLoad, RollerSupport, analyze
|
|
94
|
+
>>> beam = Beam(
|
|
95
|
+
... length=6.0, material=Material(E=200e9), section=CrossSection(I=8.1e-6)
|
|
96
|
+
... )
|
|
97
|
+
>>> beam.add_support(PinSupport(position=0.0))
|
|
98
|
+
>>> beam.add_support(RollerSupport(position=6.0))
|
|
99
|
+
>>> beam.add_load(PointLoad(position=3.0, magnitude=-12_000.0))
|
|
100
|
+
>>> results = analyze(beam, sample_count=11)
|
|
101
|
+
>>> results.classification
|
|
102
|
+
'ISOSTATIC'
|
|
103
|
+
>>> round(results.reactions[beam.supports[0]]["Ry"], 3)
|
|
104
|
+
6000.0
|
|
105
|
+
>>> round(results.moment.M_max, 3) # P·L/4 con P = 12 kN y L = 6 m
|
|
106
|
+
18000.0
|
|
107
|
+
|
|
108
|
+
Con la carga marcada como viva y mayorada por 1.6:
|
|
109
|
+
|
|
110
|
+
>>> beam = Beam(6.0, Material(E=200e9), CrossSection(I=8.1e-6))
|
|
111
|
+
>>> beam.add_support(PinSupport(position=0.0))
|
|
112
|
+
>>> beam.add_support(RollerSupport(position=6.0))
|
|
113
|
+
>>> beam.add_load(PointLoad(3.0, -12_000.0, case="live", factor=1.6))
|
|
114
|
+
>>> results = analyze(beam, factored=True, case="live", sample_count=11)
|
|
115
|
+
>>> round(results.moment.M_max, 3)
|
|
116
|
+
28800.0
|
|
117
|
+
>>> results.load_basis, results.load_cases, results.load_filter
|
|
118
|
+
('factored', ('live',), 'live')
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
if not isinstance(beam, Beam):
|
|
122
|
+
msg = (
|
|
123
|
+
f"`beam` debe ser una instancia de Beam; se recibio {type(beam).__name__}."
|
|
124
|
+
)
|
|
125
|
+
raise TypeError(msg)
|
|
126
|
+
_validate_sample_count(sample_count)
|
|
127
|
+
validate_refinement(elements_per_span, max_element_length)
|
|
128
|
+
_validate_load_selection(factored, case)
|
|
129
|
+
validate_beam(beam)
|
|
130
|
+
_check_case_factors(beam.loads)
|
|
131
|
+
target = _effective_beam(beam, factored=factored, case=case)
|
|
132
|
+
|
|
133
|
+
selection = select_solver(target)
|
|
134
|
+
if selection.path == "static":
|
|
135
|
+
result = Results.for_isostatic(
|
|
136
|
+
target,
|
|
137
|
+
sample_count=sample_count,
|
|
138
|
+
elements_per_span=elements_per_span,
|
|
139
|
+
max_element_length=max_element_length,
|
|
140
|
+
)
|
|
141
|
+
else:
|
|
142
|
+
result = Results.for_hyperstatic(
|
|
143
|
+
target,
|
|
144
|
+
sample_count=sample_count,
|
|
145
|
+
elements_per_span=elements_per_span,
|
|
146
|
+
max_element_length=max_element_length,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
used_cases = {load.case for load in target.loads}
|
|
150
|
+
return replace(
|
|
151
|
+
result,
|
|
152
|
+
warnings=selection.notes + result.warnings,
|
|
153
|
+
load_basis="factored" if factored else "nominal",
|
|
154
|
+
load_cases=tuple(case for case in LOAD_CASES if case in used_cases),
|
|
155
|
+
load_filter=case,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _validate_sample_count(sample_count: int) -> None:
|
|
160
|
+
"""Valida que ``sample_count`` sea un entero (no ``bool``) mayor o igual a 2."""
|
|
161
|
+
|
|
162
|
+
if (
|
|
163
|
+
isinstance(sample_count, bool)
|
|
164
|
+
or not isinstance(sample_count, int)
|
|
165
|
+
or sample_count < _MIN_SAMPLE_COUNT
|
|
166
|
+
):
|
|
167
|
+
msg = (
|
|
168
|
+
"`sample_count` debe ser un entero mayor o igual a "
|
|
169
|
+
f"{_MIN_SAMPLE_COUNT}; se recibio {sample_count!r}."
|
|
170
|
+
)
|
|
171
|
+
raise ValueError(msg)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _validate_load_selection(factored: object, case: object) -> None:
|
|
175
|
+
"""Valida los argumentos ``factored`` y ``case`` de ``analyze``."""
|
|
176
|
+
|
|
177
|
+
if not isinstance(factored, bool):
|
|
178
|
+
msg = f"`factored` debe ser True o False; se recibio {factored!r}."
|
|
179
|
+
raise TypeError(msg)
|
|
180
|
+
if case is not None and case not in LOAD_CASES:
|
|
181
|
+
msg = f"`case` debe ser 'dead', 'live' o None; se recibio {case!r}."
|
|
182
|
+
raise ValueError(msg)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _check_case_factors(loads: Sequence[Load]) -> None:
|
|
186
|
+
"""Exige que todas las cargas de un mismo caso usen el mismo factor."""
|
|
187
|
+
|
|
188
|
+
factors: dict[str, list[float]] = {}
|
|
189
|
+
for load in loads:
|
|
190
|
+
if load.case is None:
|
|
191
|
+
continue
|
|
192
|
+
found = factors.setdefault(load.case, [])
|
|
193
|
+
if load.factor not in found:
|
|
194
|
+
found.append(load.factor)
|
|
195
|
+
for case, found in factors.items():
|
|
196
|
+
if len(found) > 1:
|
|
197
|
+
listed = ", ".join(str(factor) for factor in found)
|
|
198
|
+
msg = (
|
|
199
|
+
f"Las cargas del caso {case!r} tienen factores distintos "
|
|
200
|
+
f"({listed}); todas deben usar el mismo."
|
|
201
|
+
)
|
|
202
|
+
raise ValueError(msg)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
@dataclass(frozen=True, slots=True)
|
|
206
|
+
class _ScaledIntensity:
|
|
207
|
+
"""Intensidad de una carga distribuida multiplicada por un factor."""
|
|
208
|
+
|
|
209
|
+
func: LoadFunction
|
|
210
|
+
factor: float
|
|
211
|
+
|
|
212
|
+
def __call__(self, position: float) -> float:
|
|
213
|
+
return self.factor * self.func(position)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _scaled(load: Load) -> Load:
|
|
217
|
+
"""Devuelve ``load`` multiplicada por su factor.
|
|
218
|
+
|
|
219
|
+
Una carga con factor unidad se devuelve sin cambios (el mismo objeto); las
|
|
220
|
+
demas vuelven escaladas y con ``factor=1.0``.
|
|
221
|
+
"""
|
|
222
|
+
|
|
223
|
+
if load.factor == 1.0:
|
|
224
|
+
return load
|
|
225
|
+
if isinstance(load, DistributedLoad):
|
|
226
|
+
return replace(load, func=_ScaledIntensity(load.func, load.factor), factor=1.0)
|
|
227
|
+
return replace(load, magnitude=load.factor * load.magnitude, factor=1.0)
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def _effective_beam(beam: Beam, *, factored: bool, case: LoadCase | None) -> Beam:
|
|
231
|
+
"""Viga que se resuelve: la misma ``beam`` o una copia con otras cargas.
|
|
232
|
+
|
|
233
|
+
Con las opciones por defecto devuelve ``beam`` sin copiarla. Si no, arma una
|
|
234
|
+
viga nueva con el mismo largo, material, seccion, apoyos y articulaciones, y
|
|
235
|
+
solo las cargas seleccionadas (mayoradas si ``factored``).
|
|
236
|
+
"""
|
|
237
|
+
|
|
238
|
+
if not factored and case is None:
|
|
239
|
+
return beam
|
|
240
|
+
loads = [load for load in beam.loads if case is None or load.case == case]
|
|
241
|
+
if case is not None and not loads:
|
|
242
|
+
raise ValueError(f"La viga no tiene cargas del caso {case!r}.")
|
|
243
|
+
|
|
244
|
+
target = Beam(length=beam.length, material=beam.material, section=beam.section)
|
|
245
|
+
for support in beam.supports:
|
|
246
|
+
target.add_support(support)
|
|
247
|
+
for load in loads:
|
|
248
|
+
target.add_load(_scaled(load) if factored else load)
|
|
249
|
+
for hinge in beam.hinges:
|
|
250
|
+
target.add_hinge(hinge.position)
|
|
251
|
+
return target
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Modelos públicos de databies.
|
|
2
|
+
|
|
3
|
+
Aquí se exportan los modelos disponibles para uso externo dentro del paquete
|
|
4
|
+
``databies.models``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .beam import Beam, CrossSection, Material
|
|
8
|
+
from .loads import DistributedLoad, MomentLoad, PointLoad
|
|
9
|
+
from .releases import InternalHinge
|
|
10
|
+
from .supports import FixedSupport, PinSupport, RollerSupport
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"RollerSupport",
|
|
14
|
+
"PinSupport",
|
|
15
|
+
"FixedSupport",
|
|
16
|
+
"DistributedLoad",
|
|
17
|
+
"PointLoad",
|
|
18
|
+
"MomentLoad",
|
|
19
|
+
"InternalHinge",
|
|
20
|
+
"Material",
|
|
21
|
+
"CrossSection",
|
|
22
|
+
"Beam",
|
|
23
|
+
]
|
databies/models/beam.py
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"""Modelos para vigas y propiedades de seccion.
|
|
2
|
+
|
|
3
|
+
Aqui se definen:
|
|
4
|
+
- Material: modulo de elasticidad y propiedades del material.
|
|
5
|
+
- CrossSection: momento de inercia y propiedades geometricas de la seccion.
|
|
6
|
+
- Beam: contenedor central de apoyos, cargas y articulaciones internas.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import math
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
|
|
14
|
+
from databies.utils.validators import (
|
|
15
|
+
validate_beam,
|
|
16
|
+
validate_hinge_position,
|
|
17
|
+
validate_moment_load_position,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
from .loads import DistributedLoad, MomentLoad, PointLoad
|
|
21
|
+
from .releases import InternalHinge
|
|
22
|
+
from .supports import FixedSupport, PinSupport, RollerSupport
|
|
23
|
+
|
|
24
|
+
Support = RollerSupport | PinSupport | FixedSupport
|
|
25
|
+
Load = PointLoad | DistributedLoad | MomentLoad
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _validate_finite_positive(value: float, name: str) -> None:
|
|
29
|
+
"""Valida que ``value`` sea un número finito mayor que 0."""
|
|
30
|
+
|
|
31
|
+
if not math.isfinite(value):
|
|
32
|
+
raise ValueError(f"`{name}` debe ser un número finito.")
|
|
33
|
+
if value <= 0:
|
|
34
|
+
raise ValueError(f"`{name}` debe ser mayor que 0.")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass(frozen=True, slots=True)
|
|
38
|
+
class Material:
|
|
39
|
+
"""Propiedades del material de la viga.
|
|
40
|
+
|
|
41
|
+
``E`` es el modulo de Young en Pascales (Pa). Debe ser un número finito
|
|
42
|
+
positivo. ``G`` es el modulo de corte en Pa. Opcional; si se proporciona
|
|
43
|
+
debe ser un número finito positivo.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
E: Módulo de Young en Pascales (Pa).
|
|
47
|
+
G: Módulo de corte en Pascales (Pa). Opcional.
|
|
48
|
+
|
|
49
|
+
Raises:
|
|
50
|
+
ValueError: si ``E`` o ``G`` no son finitos o no son mayores que 0.
|
|
51
|
+
|
|
52
|
+
Example:
|
|
53
|
+
>>> from databies import Material
|
|
54
|
+
>>> Material(E=200e9)
|
|
55
|
+
Material(E=200000000000.0, G=None)
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
E: float
|
|
59
|
+
G: float | None = None
|
|
60
|
+
|
|
61
|
+
def __post_init__(self) -> None:
|
|
62
|
+
_validate_finite_positive(self.E, "E")
|
|
63
|
+
if self.G is not None:
|
|
64
|
+
_validate_finite_positive(self.G, "G")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass(frozen=True, slots=True)
|
|
68
|
+
class CrossSection:
|
|
69
|
+
"""Propiedades geometricas de la seccion transversal.
|
|
70
|
+
|
|
71
|
+
``I`` es el momento de inercia en m^4 respecto al eje de flexion. Debe
|
|
72
|
+
ser un número finito positivo. ``A`` es el area de la seccion en m^2.
|
|
73
|
+
Opcional; si se proporciona debe ser un número finito positivo.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
I: Momento de inercia respecto al eje de flexión, en m^4.
|
|
77
|
+
A: Área de la sección, en m^2. Opcional.
|
|
78
|
+
|
|
79
|
+
Raises:
|
|
80
|
+
ValueError: si ``I`` o ``A`` no son finitos o no son mayores que 0.
|
|
81
|
+
|
|
82
|
+
Example:
|
|
83
|
+
>>> from databies import CrossSection
|
|
84
|
+
>>> CrossSection(I=8.1e-6)
|
|
85
|
+
CrossSection(I=8.1e-06, A=None)
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
I: float # noqa: E741
|
|
89
|
+
A: float | None = None
|
|
90
|
+
|
|
91
|
+
@classmethod
|
|
92
|
+
def rectangular(cls, base: float, height: float) -> CrossSection:
|
|
93
|
+
"""Crea una sección rectangular a partir de sus dimensiones en metros.
|
|
94
|
+
|
|
95
|
+
La altura sigue la dirección de flexión (eje Y). La inercia se calcula
|
|
96
|
+
respecto al eje horizontal que pasa por el centroide: ``b·h³/12``;
|
|
97
|
+
el área es ``b·h``. La razón entre la inercia original y la obtenida al
|
|
98
|
+
intercambiar base y altura es ``(h/b)²``; el área no cambia.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
base: Base del rectángulo en metros, finita y mayor que 0.
|
|
102
|
+
height: Altura en la dirección de flexión, en metros, finita y
|
|
103
|
+
mayor que 0.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
Sección con inercia ``I`` en m⁴ y área ``A`` en m².
|
|
107
|
+
|
|
108
|
+
Raises:
|
|
109
|
+
ValueError: si la base o la altura no son finitas o no son mayores
|
|
110
|
+
que 0.
|
|
111
|
+
|
|
112
|
+
Example:
|
|
113
|
+
>>> from databies import CrossSection
|
|
114
|
+
>>> section = CrossSection.rectangular(base=0.3, height=0.5)
|
|
115
|
+
>>> round(section.I, 6) # m⁴
|
|
116
|
+
0.003125
|
|
117
|
+
>>> round(section.A, 2) # m²
|
|
118
|
+
0.15
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
_validate_finite_positive(base, "base")
|
|
122
|
+
_validate_finite_positive(height, "height")
|
|
123
|
+
return cls(I=base * height**3 / 12, A=base * height)
|
|
124
|
+
|
|
125
|
+
def __post_init__(self) -> None:
|
|
126
|
+
_validate_finite_positive(self.I, "I")
|
|
127
|
+
if self.A is not None:
|
|
128
|
+
_validate_finite_positive(self.A, "A")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@dataclass(slots=True)
|
|
132
|
+
class Beam:
|
|
133
|
+
"""Contenedor de una viga estructural de databies.
|
|
134
|
+
|
|
135
|
+
``Beam`` agrega material, seccion, apoyos, cargas y articulaciones internas.
|
|
136
|
+
El solver numerico queda fuera de este modelo; ``solve()`` solo valida las
|
|
137
|
+
precondiciones minimas del Sprint 01 y congela la viga para impedir nuevas
|
|
138
|
+
modificaciones. Para obtener reacciones y diagramas se usa ``analyze``.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
length: Longitud total de la viga, en metros. Debe ser finita y mayor
|
|
142
|
+
que 0.
|
|
143
|
+
material: Material de la viga.
|
|
144
|
+
section: Sección transversal de la viga.
|
|
145
|
+
|
|
146
|
+
Attributes:
|
|
147
|
+
supports: Apoyos agregados, en orden de inserción.
|
|
148
|
+
loads: Cargas agregadas, en orden de inserción.
|
|
149
|
+
hinges: Articulaciones internas agregadas, en orden de inserción.
|
|
150
|
+
is_solved: ``True`` una vez que se llamó a ``solve()``; desde entonces
|
|
151
|
+
la viga no admite más modificaciones.
|
|
152
|
+
|
|
153
|
+
Raises:
|
|
154
|
+
ValueError: si ``length`` no es finito o no es mayor que 0.
|
|
155
|
+
TypeError: si ``material`` no es un ``Material`` o ``section`` no es un
|
|
156
|
+
``CrossSection``.
|
|
157
|
+
|
|
158
|
+
Example:
|
|
159
|
+
>>> from databies import Beam, CrossSection, Material, PinSupport
|
|
160
|
+
>>> from databies import PointLoad, RollerSupport, analyze
|
|
161
|
+
>>> beam = Beam(
|
|
162
|
+
... length=6.0, material=Material(E=200e9), section=CrossSection(I=8.1e-6)
|
|
163
|
+
... )
|
|
164
|
+
>>> beam.add_support(PinSupport(position=0.0))
|
|
165
|
+
>>> beam.add_support(RollerSupport(position=6.0))
|
|
166
|
+
>>> beam.add_load(PointLoad(position=3.0, magnitude=-12_000.0))
|
|
167
|
+
>>> results = analyze(beam, sample_count=11)
|
|
168
|
+
>>> round(results.moment.M_max)
|
|
169
|
+
18000
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
length: float
|
|
173
|
+
material: Material
|
|
174
|
+
section: CrossSection
|
|
175
|
+
supports: tuple[Support, ...] = field(default_factory=tuple, init=False)
|
|
176
|
+
loads: tuple[Load, ...] = field(default_factory=tuple, init=False)
|
|
177
|
+
hinges: tuple[InternalHinge, ...] = field(default_factory=tuple, init=False)
|
|
178
|
+
is_solved: bool = field(default=False, init=False)
|
|
179
|
+
|
|
180
|
+
def __post_init__(self) -> None:
|
|
181
|
+
if not math.isfinite(self.length):
|
|
182
|
+
raise ValueError("`length` debe ser un número finito.")
|
|
183
|
+
if self.length <= 0:
|
|
184
|
+
raise ValueError("`length` debe ser mayor que 0.")
|
|
185
|
+
if not isinstance(self.material, Material):
|
|
186
|
+
raise TypeError("`material` debe ser una instancia de Material.")
|
|
187
|
+
if not isinstance(self.section, CrossSection):
|
|
188
|
+
raise TypeError("`section` debe ser una instancia de CrossSection.")
|
|
189
|
+
|
|
190
|
+
def add_support(self, support: Support) -> None:
|
|
191
|
+
"""Agrega un apoyo externo dentro del tramo de la viga.
|
|
192
|
+
|
|
193
|
+
Args:
|
|
194
|
+
support: ``RollerSupport``, ``PinSupport`` o ``FixedSupport``. Su
|
|
195
|
+
``position`` debe estar en ``[0, length]``, en metros.
|
|
196
|
+
|
|
197
|
+
Raises:
|
|
198
|
+
RuntimeError: si la viga ya fue resuelta con ``solve()``.
|
|
199
|
+
TypeError: si ``support`` no es un apoyo externo válido.
|
|
200
|
+
ValueError: si la posición es inválida o ya hay un apoyo en ella.
|
|
201
|
+
|
|
202
|
+
Example:
|
|
203
|
+
>>> from databies import Beam, CrossSection, Material, PinSupport
|
|
204
|
+
>>> beam = Beam(6.0, Material(E=200e9), CrossSection(I=8.1e-6))
|
|
205
|
+
>>> beam.add_support(PinSupport(position=0.0))
|
|
206
|
+
>>> beam.supports
|
|
207
|
+
(PinSupport(position=0.0),)
|
|
208
|
+
"""
|
|
209
|
+
|
|
210
|
+
self._ensure_mutable()
|
|
211
|
+
if not isinstance(support, (RollerSupport, PinSupport, FixedSupport)):
|
|
212
|
+
raise TypeError("`support` debe ser un apoyo externo válido.")
|
|
213
|
+
self._validate_position_in_span(support.position, "support.position")
|
|
214
|
+
if any(existing.position == support.position for existing in self.supports):
|
|
215
|
+
raise ValueError("Ya existe un apoyo en esa posición.")
|
|
216
|
+
self.supports = (*self.supports, support)
|
|
217
|
+
|
|
218
|
+
def add_load(self, load: Load) -> None:
|
|
219
|
+
"""Agrega una carga puntual, distribuida o de momento dentro del tramo.
|
|
220
|
+
|
|
221
|
+
Args:
|
|
222
|
+
load: ``PointLoad``, ``DistributedLoad`` o ``MomentLoad``. Sus
|
|
223
|
+
posiciones deben estar en ``[0, length]``, en metros. Las
|
|
224
|
+
cargas hacia abajo llevan magnitud o intensidad negativa.
|
|
225
|
+
|
|
226
|
+
Raises:
|
|
227
|
+
RuntimeError: si la viga ya fue resuelta con ``solve()``.
|
|
228
|
+
TypeError: si ``load`` no es una carga válida.
|
|
229
|
+
ValueError: si alguna posición cae fuera del tramo o no es finita.
|
|
230
|
+
|
|
231
|
+
Example:
|
|
232
|
+
>>> from databies import Beam, CrossSection, Material, PointLoad
|
|
233
|
+
>>> beam = Beam(6.0, Material(E=200e9), CrossSection(I=8.1e-6))
|
|
234
|
+
>>> beam.add_load(PointLoad(position=3.0, magnitude=-12_000.0))
|
|
235
|
+
>>> len(beam.loads)
|
|
236
|
+
1
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
self._ensure_mutable()
|
|
240
|
+
if not isinstance(load, (PointLoad, DistributedLoad, MomentLoad)):
|
|
241
|
+
raise TypeError("`load` debe ser una carga válida.")
|
|
242
|
+
if isinstance(load, DistributedLoad):
|
|
243
|
+
self._validate_position_in_span(load.start, "load.start")
|
|
244
|
+
self._validate_position_in_span(load.end, "load.end")
|
|
245
|
+
else:
|
|
246
|
+
self._validate_position_in_span(load.position, "load.position")
|
|
247
|
+
if isinstance(load, MomentLoad):
|
|
248
|
+
validate_moment_load_position(self, load.position)
|
|
249
|
+
self.loads = (*self.loads, load)
|
|
250
|
+
|
|
251
|
+
def add_hinge(self, position: float) -> None:
|
|
252
|
+
"""Registra una articulación interna en ``position``.
|
|
253
|
+
|
|
254
|
+
La articulación libera el momento flector en ese punto; se guarda como
|
|
255
|
+
un ``InternalHinge`` en ``hinges``.
|
|
256
|
+
|
|
257
|
+
Args:
|
|
258
|
+
position: Posición en metros desde el extremo izquierdo, estrictamente
|
|
259
|
+
dentro del tramo ``(0, length)``.
|
|
260
|
+
|
|
261
|
+
Raises:
|
|
262
|
+
RuntimeError: si la viga ya fue resuelta con ``solve()``.
|
|
263
|
+
ValueError: si la posición es inválida o ya hay una articulación
|
|
264
|
+
en ella.
|
|
265
|
+
|
|
266
|
+
Example:
|
|
267
|
+
>>> from databies import Beam, CrossSection, Material
|
|
268
|
+
>>> beam = Beam(6.0, Material(E=200e9), CrossSection(I=8.1e-6))
|
|
269
|
+
>>> beam.add_hinge(4.5)
|
|
270
|
+
>>> beam.hinges
|
|
271
|
+
(InternalHinge(position=4.5),)
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
self._ensure_mutable()
|
|
275
|
+
validate_hinge_position(self, position)
|
|
276
|
+
if any(existing.position == position for existing in self.hinges):
|
|
277
|
+
raise ValueError("Ya existe una articulación interna en esa posición.")
|
|
278
|
+
self.hinges = (*self.hinges, InternalHinge(position=position))
|
|
279
|
+
|
|
280
|
+
def solve(self) -> None:
|
|
281
|
+
"""Valida precondiciones y congela la viga.
|
|
282
|
+
|
|
283
|
+
No calcula reacciones ni diagramas (para eso está ``analyze``). Valida
|
|
284
|
+
que el modelo sea coherente, rechazando vigas inestables o mal
|
|
285
|
+
construidas, y luego marca ``is_solved`` para bloquear nuevas
|
|
286
|
+
modificaciones.
|
|
287
|
+
|
|
288
|
+
Raises:
|
|
289
|
+
RuntimeError: si la viga ya fue resuelta.
|
|
290
|
+
ValueError: si el modelo es inválido (por ejemplo, sin apoyos o
|
|
291
|
+
inestable).
|
|
292
|
+
|
|
293
|
+
Example:
|
|
294
|
+
>>> from databies import Beam, CrossSection, Material, PinSupport
|
|
295
|
+
>>> from databies import RollerSupport
|
|
296
|
+
>>> beam = Beam(6.0, Material(E=200e9), CrossSection(I=8.1e-6))
|
|
297
|
+
>>> beam.add_support(PinSupport(position=0.0))
|
|
298
|
+
>>> beam.add_support(RollerSupport(position=6.0))
|
|
299
|
+
>>> beam.solve()
|
|
300
|
+
>>> beam.is_solved
|
|
301
|
+
True
|
|
302
|
+
"""
|
|
303
|
+
|
|
304
|
+
self._ensure_mutable()
|
|
305
|
+
validate_beam(self)
|
|
306
|
+
self.is_solved = True
|
|
307
|
+
|
|
308
|
+
def _ensure_mutable(self) -> None:
|
|
309
|
+
if self.is_solved:
|
|
310
|
+
raise RuntimeError("La viga ya fue resuelta y no puede modificarse.")
|
|
311
|
+
|
|
312
|
+
def _validate_position_in_span(self, position: float, field_name: str) -> None:
|
|
313
|
+
if not math.isfinite(position):
|
|
314
|
+
raise ValueError(f"`{field_name}` debe ser un número finito.")
|
|
315
|
+
if position < 0 or position > self.length:
|
|
316
|
+
raise ValueError(f"`{field_name}` debe estar dentro del tramo [0, length].")
|