Skip to content
Snippets Groups Projects
Commit abc8e917 authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Vectorized '_reset()' for update scheme.

parent 8981d4b4
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ TODO: Discuss name for quadrature mesh (now: grid) ...@@ -23,7 +23,7 @@ TODO: Discuss name for quadrature mesh (now: grid)
TODO: Contemplate using lambdify for basis TODO: Contemplate using lambdify for basis
Urgent: Urgent:
TODO: Vectorize '_reset()' for update scheme TODO: Vectorize '_reset()' for update scheme -> Done
TODO: Vectorize 'plot_details()' TODO: Vectorize 'plot_details()'
TODO: Replace loops/list comprehension with vectorization if feasible TODO: Replace loops/list comprehension with vectorization if feasible
TODO: Replace loops with list comprehension if feasible TODO: Replace loops with list comprehension if feasible
......
...@@ -55,36 +55,27 @@ class UpdateScheme(ABC): ...@@ -55,36 +55,27 @@ class UpdateScheme(ABC):
def _reset(self): def _reset(self):
"""Resets instance variables.""" """Resets instance variables."""
matrix_shape = (self._polynomial_degree+1, self._polynomial_degree+1)
root_vector = np.array([np.sqrt(degree+0.5) for degree in range(
self._polynomial_degree+1)])
degree_matrix = np.matmul(root_vector[:, np.newaxis],
root_vector[:, np.newaxis].T)
# Set stiffness matrix # Set stiffness matrix
matrix = [] matrix = np.ones(matrix_shape)
for i in range(self._polynomial_degree+1):
new_row = []
for j in range(self._polynomial_degree+1):
if self._wave_speed > 0: if self._wave_speed > 0:
new_entry = -1.0 matrix[np.fromfunction(
if (j < i) & ((i+j) % 2 == 1): lambda i, j: (j >= i) | ((i+j) % 2 == 0), matrix_shape)] = -1.0
new_entry = 1.0
else: else:
new_entry = 1.0 matrix[np.fromfunction(
if (j > i) & ((i+j) % 2 == 1): lambda i, j: (j > i) & ((i+j) % 2 == 1), matrix_shape)] = -1.0
new_entry = -1.0 self._stiffness_matrix = matrix * degree_matrix
new_row.append(new_entry*np.sqrt((i+0.5) * (j+0.5)))
matrix.append(new_row)
self._stiffness_matrix = np.array(matrix)
# former: inv_mass @ np.array(matrix)
# Set boundary matrix # Set boundary matrix
matrix = [] matrix = np.fromfunction(lambda i, j: (-1.0)**i, matrix_shape) \
for i in range(self._polynomial_degree+1):
new_row = []
for j in range(self._polynomial_degree+1):
new_entry = np.sqrt((i+0.5) * (j+0.5)) * (-1.0)**i \
if self._wave_speed > 0 \ if self._wave_speed > 0 \
else np.sqrt((i+0.5) * (j+0.5)) * (-1.0)**j else np.fromfunction(lambda i, j: (-1.0)**j, matrix_shape)
new_row.append(new_entry) self._boundary_matrix = matrix * degree_matrix
matrix.append(new_row)
self._boundary_matrix = np.array(matrix)
# former: inv_mass @ np.array(matrix)
def get_name(self): def get_name(self):
"""Returns string of class name.""" """Returns string of class name."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment