Skip to content

Commit

Permalink
Optimize performance of gradient_3D for simplex elements
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Maier <[email protected]>
  • Loading branch information
maierbn committed Oct 16, 2023
1 parent d0f6f11 commit 0c35efd
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/pylife/mesh/gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,27 +311,27 @@ def _compute_gradient_simplex(self, df):

nodal_values = df.iloc[:4,3]
self._initialize_ansatz_function_derivative_simplex()

# compute jacobian matrix of the mapping from reference space [0,1]^3 to world space
J11 = -x11 + x21
J21 = -x12 + x22
J31 = -x13 + x23
J12 = -x11 + x31
J22 = -x12 + x32
J32 = -x13 + x33
J13 = -x11 + x41
J23 = -x12 + x42
J33 = -x13 + x43
J = np.array([[J11,J12,J13],[J21,J22,J23],[J31,J32,J33]])

# invert jacobian to map from world space to reference domain
try:
Jinv = np.linalg.inv(J)
except np.linalg.LinAlgError:
return df

for node_index in range(4):

# compute jacobian matrix of the mapping from reference space [0,1]^3 to world space
J11 = -x11 + x21
J21 = -x12 + x22
J31 = -x13 + x23
J12 = -x11 + x31
J22 = -x12 + x32
J32 = -x13 + x33
J13 = -x11 + x41
J23 = -x12 + x42
J33 = -x13 + x43
J = np.array([[J11,J12,J13],[J21,J22,J23],[J31,J32,J33]])

# invert jacobian to map from world space to reference domain
try:
Jinv = np.linalg.inv(J)
except np.linalg.LinAlgError:
continue

# loop over derivative index d/dx_k
df.iloc[node_index,4:7] \
= self._compute_gradient_simplex_single_node(node_index, nodal_values, Jinv)
Expand Down

0 comments on commit 0c35efd

Please sign in to comment.