From 83a45cda55e925f7fd8029fc6032212b6a0e9130 Mon Sep 17 00:00:00 2001
From: lakue103 <laura.kuehle@uni-duesseldorf.de>
Date: Wed, 9 Sep 2020 15:00:30 +0200
Subject: [PATCH] Started replacing transposing with vectorized access. Removed
 completed TODOs.

---
 DG_Approximation.py  |  9 +++------
 Initial_Condition.py |  2 --
 Limiter.py           | 22 +++++++++++++++++++---
 Main.py              |  5 +++++
 4 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/DG_Approximation.py b/DG_Approximation.py
index ed405c5..4a1b763 100644
--- a/DG_Approximation.py
+++ b/DG_Approximation.py
@@ -25,11 +25,8 @@ 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
-TODO: Check whether current and original projection in Update_Scheme are identical -> Done (No)
-TODO: Adjust line breaks to standard -> Done
-TODO: Remove redundant passes -> Done
-TODO: Shorten returns for True/False and redundant variables -> Done
+TODO: Make projection local variable -> Done (not for Limiter and Troubled_Cell_Detector)
+TODO: Vector faster than Trans for longer processes, therefore replace ->
 
 """
 import numpy as np
@@ -336,7 +333,7 @@ class DGScheme(object):
         toc = timeit.default_timer()
         print('Vecto:', toc-tic)
 
-        print(coarse_projection == coarse_projection1)
+        # print(coarse_projection == coarse_projection1)
 
         # Plot exact and approximate solutions for coarse mesh
         grid, exact = self._calculate_exact_solution(coarse_mesh[1:-1], coarse_cell_len)
diff --git a/Initial_Condition.py b/Initial_Condition.py
index 5c22b45..305268a 100644
--- a/Initial_Condition.py
+++ b/Initial_Condition.py
@@ -2,8 +2,6 @@
 """
 @author: Laura C. Kühle
 
-TODO: Rename initial conditions -> Done
-
 """
 import numpy as np
 
diff --git a/Limiter.py b/Limiter.py
index 34adfb3..bafa24c 100644
--- a/Limiter.py
+++ b/Limiter.py
@@ -4,6 +4,7 @@
 
 """
 import numpy as np
+import timeit
 
 
 class Limiter(object):
@@ -23,7 +24,7 @@ class NoLimiter(Limiter):
         self.function_name = 'NoLimiter'
 
     def apply(self, projection, cell):
-        return np.transpose(projection)[cell]
+        return projection[:, cell]
 
 
 class MinMod(Limiter):
@@ -47,21 +48,36 @@ class MinMod(Limiter):
         is_good_cell = self._determine_modification()
 
         if is_good_cell:
-            return np.transpose(self.projection)[self.cell]
+            return self.projection[:, self.cell]
 
-        adapted_projection = np.transpose(self.projection)[self.cell].copy()
+        adapted_projection = self.projection[:, self.cell].copy()
         for i in range(len(adapted_projection)):
             if i > self.erase_degree:
                 adapted_projection[i] = 0
         return adapted_projection
 
     def _set_cell_slope(self):
+        tic = timeit.default_timer()
         slope = []
         transposed_projection = np.transpose(self.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(self.projection)))
             slope.append(new_entry)
+        toc = timeit.default_timer()
+        print('Trans:', toc-tic)
+
+        tic = timeit.default_timer()
+        slope1 = []
+        transposed_projection = self.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(self.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):
diff --git a/Main.py b/Main.py
index ffabceb..ccced51 100644
--- a/Main.py
+++ b/Main.py
@@ -7,7 +7,9 @@ Docstring-Style: D200, D400
 
 """
 from DG_Approximation import DGScheme
+import timeit
 
+tic = timeit.default_timer()
 
 alpha = 1
 p = 2
@@ -49,6 +51,9 @@ dg_scheme = DGScheme(detector, detector_config=detector_config, init_cond=init_c
 # __, __, troubled_cells, __ =
 dg_scheme.approximate()
 dg_scheme.save_plots()
+
+toc = timeit.default_timer()
+print("Time:", toc-tic)
 # =============================================================================
 #
 # print(troubled_cells)
-- 
GitLab