Skip to content

Commit fb648a5

Browse files
committed
Switch element / facet indices to ndarray
1 parent 5a397b8 commit fb648a5

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

examples/Freefem/MMS/fem.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,13 @@ def assemble_nodal_forces(f_body, nodes, conn, element_rule):
306306
dim = nodes.shape[1]
307307
F = np.zeros((len(nodes), dim))
308308
for elem in conn:
309-
xe = nodes[elem] # (n_local, dim)
309+
# np.asarray forces row-style fancy indexing even when `elem` is a
310+
# Python tuple (which would otherwise trigger multi-axis indexing).
311+
idx = np.asarray(elem)
312+
xe = nodes[idx] # (n_local, dim)
310313
for coords, w, N, _ in element_rule(xe):
311314
f_components = f_body(*coords)
312-
for a, node in enumerate(elem):
315+
for a, node in enumerate(idx):
313316
for d in range(dim):
314317
F[node, d] += N[a] * f_components[d] * w
315318
return F
@@ -334,10 +337,11 @@ def assemble_traction(traction, nodes, facets, facet_rule):
334337
dim = nodes.shape[1]
335338
F = np.zeros((len(nodes), dim))
336339
for facet in facets:
337-
xe = nodes[facet] # (n_local, dim)
340+
idx = np.asarray(facet)
341+
xe = nodes[idx] # (n_local, dim)
338342
for coords, w, N in facet_rule(xe):
339343
T = traction(*coords)
340-
for a, node in enumerate(facet):
344+
for a, node in enumerate(idx):
341345
for d in range(dim):
342346
F[node, d] += N[a] * T[d] * w
343347
return F
@@ -391,8 +395,9 @@ def l2_error(nodes, conn, u_h, u_ex, element_rule):
391395
u = np.asarray(u_h)
392396
total = 0.0
393397
for elem in conn:
394-
xe = nodes[elem] # (n_local, dim)
395-
u_loc = u[elem] # (n_local, dim)
398+
idx = np.asarray(elem)
399+
xe = nodes[idx] # (n_local, dim)
400+
u_loc = u[idx] # (n_local, dim)
396401
for coords, w, N, _ in element_rule(xe):
397402
u_h_g = N @ u_loc # (dim,)
398403
u_ex_g = np.asarray(u_ex(*coords)) # (dim,)
@@ -417,8 +422,9 @@ def h1_semi_error(nodes, conn, u_h, grad_u_ex, element_rule):
417422
u = np.asarray(u_h)
418423
total = 0.0
419424
for elem in conn:
420-
xe = nodes[elem] # (n_local, dim)
421-
u_loc = u[elem] # (n_local, dim)
425+
idx = np.asarray(elem)
426+
xe = nodes[idx] # (n_local, dim)
427+
u_loc = u[idx] # (n_local, dim)
422428
for coords, w, _, dN_phys in element_rule(xe):
423429
# grad_uh[i, d] = sum_a u_i[a] * dN_a/dx_d
424430
grad_uh = (dN_phys @ u_loc).T # (dim, dim) [i, d]

0 commit comments

Comments
 (0)