Repository navigation
Expand file tree
/
Copy pathnode.py
More file actions
287 lines (238 loc) · 8.21 KB
/
Copy pathnode.py
File metadata and controls
287 lines (238 loc) · 8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
"""
node.py
=======
Node, Constraint, EndRelease.
These are pure data containers — no computation logic.
Node : geometric point with DOF indices assigned by DOFManager.
Constraint : boundary condition attached to a node (by ID).
EndRelease : internal hinge at an element end (by DOF name).
"""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import TYPE_CHECKING
# ---------------------------------------------------------------------------
# Node
# ---------------------------------------------------------------------------
@dataclass
class Node:
"""
Geometric node in the 2D plane.
Attributes
----------
id : user-assigned identifier
x, y : coordinates (any consistent unit system)
dofs : global DOF indices [d_ux, d_uy, d_rz], assigned by DOFManager
after model.finalize(). Empty list before finalize().
Notes
-----
- No mass stored here — see NodalMass.
- No material, section, or element references — pure geometry.
- dofs is written by DOFManager; the user should never set it directly.
"""
id: str | int
x: float
y: float
dofs: list[int] = field(default_factory=list)
def to_dict(self) -> dict:
return {
"id": self.id,
"x": self.x,
"y": self.y,
"dofs": self.dofs,
}
@classmethod
def from_dict(cls, data: dict) -> Node:
return cls(
id=data["id"],
x=data["x"],
y=data["y"],
dofs=data.get("dofs", []),
)
def __repr__(self) -> str:
return f"Node(id={self.id!r}, x={self.x}, y={self.y})"
# ---------------------------------------------------------------------------
# Constraint
# ---------------------------------------------------------------------------
@dataclass
class Constraint:
"""
Boundary condition applied to a node.
Each flag (ux, uy, rz) marks the corresponding DOF as constrained.
The ConstraintHandler translates these flags into modifications of
the global stiffness matrix.
Attributes
----------
id : user-assigned identifier
node_id : target node (reference by ID, never direct object)
ux : constrain horizontal displacement
uy : constrain vertical displacement
rz : constrain rotation
Examples
--------
Fully fixed (all DOFs constrained):
Constraint(id="fix_A", node_id="A", ux=True, uy=True, rz=True)
Pin (translations constrained, rotation free):
Constraint(id="pin_B", node_id="B", ux=True, uy=True, rz=False)
Roller (vertical reaction only):
Constraint(id="roll_C", node_id="C", ux=False, uy=True, rz=False)
"""
id: str | int
node_id: str | int
ux: bool = False
uy: bool = False
rz: bool = False
def constrained_dofs(self) -> list[str]:
"""Return list of constrained DOF names, e.g. ['ux', 'uy']."""
result = []
if self.ux:
result.append("ux")
if self.uy:
result.append("uy")
if self.rz:
result.append("rz")
return result
def is_fully_fixed(self) -> bool:
"""Return True if all three DOFs are constrained."""
return self.ux and self.uy and self.rz
def to_dict(self) -> dict:
return {
"id": self.id,
"node_id": self.node_id,
"ux": self.ux,
"uy": self.uy,
"rz": self.rz,
}
@classmethod
def from_dict(cls, data: dict) -> Constraint:
return cls(
id=data["id"],
node_id=data["node_id"],
ux=data.get("ux", False),
uy=data.get("uy", False),
rz=data.get("rz", False),
)
def __repr__(self) -> str:
flags = "".join([
"ux" if self.ux else "",
"uy" if self.uy else "",
"rz" if self.rz else "",
])
return f"Constraint(id={self.id!r}, node_id={self.node_id!r}, [{flags}])"
# ---------------------------------------------------------------------------
# EndRelease
# ---------------------------------------------------------------------------
@dataclass
class EndRelease:
"""
Internal hinge at one end of a beam element.
Implemented as a very soft spring (finite stiffness) to avoid
singularity in the global stiffness matrix. The element incorporates
the release directly in its local stiffness formulation — no extra
DOFs are needed in the DOFManager.
Attributes
----------
dof : released degree of freedom — "ux", "uy", or "rz"
stiffness : residual spring stiffness (default 1e-6).
Must be > 0 to avoid a singular K.
Choose relative to EI/L of the connected element.
end : which end of the element — "i" (start node) or "j" (end node)
law : constitutive law for nonlinear hinge (Phase 1+).
None -> linear spring with `stiffness`.
Notes
-----
The most common case is a moment release (rz) at one or both ends,
which turns a fixed-end beam into a pin-ended or simply supported one.
Example
-------
Moment release at the j-end of element "beam_1":
EndRelease(dof="rz", end="j")
"""
dof: str # "ux" | "uy" | "rz"
end: str # "i" | "j"
stiffness: float = 1e-6
law: object = None # ConstitutiveLaw | None — placeholder for Phase 1
def __post_init__(self) -> None:
valid_dofs = {"ux", "uy", "rz"}
if self.dof not in valid_dofs:
raise ValueError(
f"EndRelease: invalid dof '{self.dof}'. "
f"Must be one of {sorted(valid_dofs)}."
)
valid_ends = {"i", "j"}
if self.end not in valid_ends:
raise ValueError(
f"EndRelease: invalid end '{self.end}'. Must be 'i' or 'j'."
)
if self.stiffness <= 0:
raise ValueError(
f"EndRelease: stiffness must be positive to avoid a singular "
f"stiffness matrix (got {self.stiffness})."
)
def to_dict(self) -> dict:
return {
"dof": self.dof,
"end": self.end,
"stiffness": self.stiffness,
# law is not serialized yet — placeholder for Phase 1
}
@classmethod
def from_dict(cls, data: dict) -> EndRelease:
return cls(
dof=data["dof"],
end=data["end"],
stiffness=data.get("stiffness", 1e-6),
)
def __repr__(self) -> str:
return (
f"EndRelease(dof={self.dof!r}, end={self.end!r}, "
f"stiffness={self.stiffness})"
)
# ---------------------------------------------------------------------------
# NodalMass
# ---------------------------------------------------------------------------
@dataclass
class NodalMass:
"""
Concentrated mass applied at a node.
Used for tanks, machinery, or additional seismic masses.
Added directly to the diagonal of the global mass matrix by the Assembler.
Attributes
----------
id : user-assigned identifier
node_id : target node (reference by ID)
mx : mass in x direction
my : mass in y direction
I_theta : rotational inertia about z axis
"""
id: str | int
node_id: str | int
mx: float
my: float
I_theta: float
def __post_init__(self) -> None:
if self.mx < 0 or self.my < 0 or self.I_theta < 0:
raise ValueError(
f"NodalMass '{self.id}': mass components must be non-negative."
)
def to_dict(self) -> dict:
return {
"id": self.id,
"node_id": self.node_id,
"mx": self.mx,
"my": self.my,
"I_theta": self.I_theta,
}
@classmethod
def from_dict(cls, data: dict) -> NodalMass:
return cls(
id=data["id"],
node_id=data["node_id"],
mx=data["mx"],
my=data["my"],
I_theta=data["I_theta"],
)
def __repr__(self) -> str:
return (
f"NodalMass(id={self.id!r}, node_id={self.node_id!r}, "
f"mx={self.mx}, my={self.my}, I_theta={self.I_theta})"
)