Skip to content

Commit 20df30e

Browse files
committed
optional f, l, ... for DR
1 parent 6e9dfd1 commit 20df30e

File tree

1 file changed

+25
-7
lines changed
  • src/compas/numerical/dr

1 file changed

+25
-7
lines changed

src/compas/numerical/dr/dr.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ def adjacency_from_edges(edges):
9090
return adj
9191

9292

93-
def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
93+
def dr(vertices, edges, fixed, loads, qpre,
94+
fpre=None, lpre=None,
95+
linit=None, E=None, radius=None,
9496
kmax=100, dt=1.0, tol1=1e-3, tol2=1e-6, c=0.1, callback=None, callback_args=None):
9597
"""Implementation of dynamic relaxation with RK integration scheme in pure Python.
9698
@@ -106,15 +108,15 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
106108
XYZ components of the loads on the vertices.
107109
qpre : list
108110
Prescribed force densities in the edges.
109-
fpre : list
111+
fpre : list, optional
110112
Prescribed forces in the edges.
111-
lpre : list
113+
lpre : list, optional
112114
Prescribed lengths of the edges.
113-
linit : list
115+
linit : list, optoional
114116
Initial length of the edges.
115-
E : list
117+
E : list, optional
116118
Stiffness of the edges.
117-
radius : list
119+
radius : list, optional
118120
Radius of the edges.
119121
kmax : int, optional
120122
Maximum number of iterations.
@@ -128,6 +130,10 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
128130
Damping factor for viscous damping.
129131
callback : callable, optional
130132
A user-defined callback that is called after every iteration.
133+
The callback will be called with ``k`` the current iteration,
134+
``X`` the coordinates at iteration ``k``,
135+
``crit1, crit2`` the values of the stoppage criteria at iteration ``k``,
136+
and ``callback_args`` the optional additional arguments.
131137
callback_args : tuple, optional
132138
Additional arguments to be passed to the callback.
133139
@@ -155,6 +161,7 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
155161
# preprocess
156162
# --------------------------------------------------------------------------
157163
n = len(vertices)
164+
e = len(edges)
158165

159166
# i_nbrs = {i: [ij[1] if ij[0] == i else ij[0] for ij in edges if i in ij] for i in range(n)}
160167

@@ -172,10 +179,15 @@ def dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius,
172179
# --------------------------------------------------------------------------
173180
X = vertices
174181
P = loads
175-
Q = qpre
182+
Qpre = qpre or [0.0 for _ in range(e)]
183+
Fpre = fpre or [0.0 for _ in range(e)]
184+
Lpre = lpre or [0.0 for _ in range(e)]
176185
# --------------------------------------------------------------------------
177186
# initial values
178187
# --------------------------------------------------------------------------
188+
Q = [1.0 for _ in range(e)]
189+
L = [sum((X[i][axis] - X[j][axis]) ** 2 for axis in (0, 1, 2)) ** 0.5 for i, j in iter(edges)]
190+
F = [q * l for q, l in zip(Q, L)]
179191
M = [sum(0.5 * dt ** 2 * Q[ij_e[(i, j)]] for j in i_nbrs[i]) for i in range(n)]
180192
V = [[0.0, 0.0, 0.0] for _ in range(n)]
181193
R = [[0.0, 0.0, 0.0] for _ in range(n)]
@@ -234,6 +246,12 @@ def a(t, V):
234246
# start iterating
235247
# --------------------------------------------------------------------------
236248
for k in range(kmax):
249+
Qfpre = [a / b if b else 0 for a, b in zip(Fpre, L)]
250+
Qlpre = [a / b if b else 0 for a, b in zip(F, Lpre)]
251+
252+
Q = [a + b + c for a, b, c in zip(Qpre, Qfpre, Qlpre)]
253+
M = [sum(0.5 * dt ** 2 * Q[ij_e[(i, j)]] for j in i_nbrs[i]) for i in range(n)]
254+
237255
X0 = deepcopy(X)
238256
V0 = [[ca * V[i][axis] for axis in (0, 1, 2)] for i in range(n)]
239257

0 commit comments

Comments
 (0)