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

Replaced transposing with vectorized access when feasible.

parent 6acd9c49
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ TODO: Contemplate erasing inv_mass-matrix as it is identity -> Discuss
TODO: Investigate why we need inverse mass matrix for initial projection, \
but not A and B
TODO: Investigate why there are no weights in approx calc
TODO: Change transposing to vectorized access if feasible
TODO: Change transposing to vectorized access if feasible -> Done
TODO: Implement argument check for unpacking of all configs
TODO: Contemplate verbose = show_plot?
TODO: Change order of methods -> Done for Stability_Method
......@@ -25,8 +25,9 @@ TODO: Write documentation for all methods
TODO: Add a verbose option
TODO: Check whether consistency is given/possible for each class instance
TODO: Make projection local variable -> Done (not for Limiter and Troubled_Cell_Detector)
TODO: Vector faster than Trans for longer processes, therefore replace ->
TODO: Make projection local variable -> Done
TODO: Vector faster than Trans for longer processes, therefore replace -> Done
TODO: Make sure time is changed to current_time everywhere
"""
import numpy as np
......
......@@ -3,8 +3,6 @@
@author: Laura C. Kühle
"""
import numpy as np
import timeit
class Limiter(object):
......@@ -55,27 +53,10 @@ class MinMod(Limiter):
return adapted_projection
def _set_cell_slope(self, projection):
tic = timeit.default_timer()
slope = []
transposed_projection = np.transpose(projection)
for cell in range(len(transposed_projection)):
new_entry = sum(transposed_projection[cell][degree] * (degree+0.5)**0.5
for degree in range(1, len(projection)))
for cell in range(len(projection[0])):
new_entry = sum(projection[degree][cell] * (degree+0.5)**0.5 for degree in range(1, len(projection)))
slope.append(new_entry)
toc = timeit.default_timer()
# print('Trans:', toc-tic)
tic = timeit.default_timer()
slope1 = []
transposed_projection = projection
for cell in range(len(transposed_projection[0])):
new_entry = sum(transposed_projection[degree][cell] * (degree+0.5)**0.5
for degree in range(1, len(projection)))
slope1.append(new_entry)
toc = timeit.default_timer()
# print('Vecto:', toc-tic)
#
# print(slope == slope1)
self.cell_slope = slope[self.cell]
def _determine_modification(self, projection):
......
......@@ -62,10 +62,9 @@ class WaveletDetector(TroubledCellDetector):
return matrix
def _calculate_wavelet_coeffs(self, projection):
transposed_vector = np.transpose(projection)
output_matrix = []
for i in range(int(len(projection[0])/2)):
new_entry = 0.5*(transposed_vector[2*i] @ self.M1 + transposed_vector[2*i+1] @ self.M2)
new_entry = 0.5*(projection[:, 2*i] @ self.M1 + projection[:, 2*i+1] @ self.M2)
output_matrix.append(new_entry)
return np.transpose(np.array(output_matrix))
......
......@@ -13,6 +13,7 @@ TODO: Find better names for A, B, M1, and M2
"""
import numpy as np
import timeit
class UpdateScheme(object):
......@@ -105,17 +106,13 @@ class UpdateScheme(object):
new_projection = self.current_projection.copy()
for cell in self.troubled_cells:
np.transpose(new_projection)[cell] = self.limiter.apply(self.current_projection, cell)
new_projection[:, cell] = self.limiter.apply(self.current_projection, cell)
self.current_projection = new_projection
def _enforce_boundary_condition(self):
transposed_projection = np.transpose(self.current_projection)
transposed_projection[0] = transposed_projection[self.num_grid_cells]
transposed_projection[self.num_grid_cells+1] = transposed_projection[1]
self.current_projection = np.transpose(transposed_projection)
self.current_projection[:, 0] = self.current_projection[:, self.num_grid_cells]
self.current_projection[:, self.num_grid_cells+1] = self.current_projection[:, 1]
class SSPRK3(UpdateScheme):
......@@ -142,16 +139,12 @@ class SSPRK3(UpdateScheme):
self._enforce_boundary_condition()
def _update_right_hand_side(self):
# Transpose projection for easier calculation
transposed_projection = np.transpose(self.current_projection)
# Initialize vector and set first entry to accommodate for ghost cell
right_hand_side = [0]
for j in range(self.num_grid_cells):
right_hand_side.append(
2*(self.A @ transposed_projection[j+1]
+ self.B @ transposed_projection[j]))
right_hand_side.append(2*(self.A @ self.current_projection[:, j+1]
+ self.B @ self.current_projection[:, j]))
# Set ghost cells to respective value
right_hand_side[0] = right_hand_side[self.num_grid_cells]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment