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