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

Vectorized 'plot_details()'.

parent ae8ed3f7
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ TODO: Contemplate using lambdify for basis
TODO: Discuss how wavelet details should be plotted
Urgent:
TODO: Vectorize 'plot_details()'
TODO: Vectorize 'plot_details()' -> Done
TODO: Replace loops/list comprehension with vectorization if feasible
TODO: Replace loops with list comprehension if feasible
TODO: Rework ICs to allow vector input
......
......@@ -140,26 +140,22 @@ def plot_details(fine_projection: ndarray, fine_mesh: Mesh, basis: Basis,
Matrix of multiwavelet coefficients.
"""
num_coarse_mesh_cells = len(coarse_projection[0])
averaged_projection = [[coarse_projection[degree][cell]
* basis.basis[degree].subs(x, value)
for cell in range(num_coarse_mesh_cells)
for value in [-0.5, 0.5]]
basis_matrix = np.array(
[[basis.basis[degree].subs(x, point)
for point in [-0.5, 0.5]]
for degree in range(basis.polynomial_degree+1)])
projected_coarse = (basis_matrix.T @ coarse_projection).flatten('F')
wavelet_matrix = np.array(
[[basis.wavelet[degree].subs(z, 0.5) * value
for value in [(-1) ** (basis.polynomial_degree + degree + 1), 1]]
for degree in range(basis.polynomial_degree + 1)])
projected_wavelet_coeffs = (wavelet_matrix.T @
multiwavelet_coeffs[:, ::2]).flatten('F')
basis_vector = [basis.basis[degree].subs(x, 0)
for degree in range(basis.polynomial_degree + 1)]
wavelet_projection = [[multiwavelet_coeffs[degree][cell]
* basis.wavelet[degree].subs(z, 0.5) * value
for cell in range(num_coarse_mesh_cells)
for value in [(-1) ** (basis.polynomial_degree
+ degree + 1), 1]]
for degree in range(basis.polynomial_degree + 1)]
projected_coarse = np.sum(averaged_projection, axis=0)
projected_fine = np.sum([fine_projection[degree]
* basis.basis[degree].subs(x, 0)
for degree in range(basis.polynomial_degree + 1)],
axis=0)
projected_wavelet_coeffs = np.sum(wavelet_projection, axis=0)
projected_fine = basis_vector @ fine_projection
plt.figure('coeff_details')
plt.plot(fine_mesh.non_ghost_cells, projected_fine-projected_coarse, 'm-.')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment