diff --git a/DG_Approximation.py b/DG_Approximation.py index bb8d8affb81e85ccc029a3a5dc2dcb34f7fd1cf7..babce4bd72e0766f3e81964d9ea9b3a0060124e4 100644 --- a/DG_Approximation.py +++ b/DG_Approximation.py @@ -16,6 +16,10 @@ TODO: Contemplate saving training data for each IC separately TODO: Contemplate removing TrainingDataGenerator class TODO: Ask why no fine mesh is used for calculate_coarse_projection() +TODO: Ask the meaning of the shifted bounds in Boxplot (Modified script) +TODO: Ask whether the indices for the wavelet calculation are i or i+1 +TODO: Ask why wavelet matrix has unset ghost cells + Urgent: TODO: Enforce mesh with 2^n cells TODO: Change heaviside random to uniform(-100, 100) diff --git a/Troubled_Cell_Detector.py b/Troubled_Cell_Detector.py index becf16977da432623ef27b487782ba3c40414068..3cb1ce1fdabcd878dbde889ff2c02a176f7d6208 100644 --- a/Troubled_Cell_Detector.py +++ b/Troubled_Cell_Detector.py @@ -8,12 +8,10 @@ TODO: Change method of calculating quartiles -> Done TODO: Include overlapping cells in quartile calculation (if needed) -> Done TODO: Determine max_value for Theoretical only over highest degree -> Done (now optional) -TODO: Check if indexing in wavelets is correct -TODO: Combine get_cells() and _get_cells() -TODO: Add TC condition to only flag cell if left-adjacent one is flagged as - well (remove this condition) -TODO: Check coarse_projection calculation for indexing errors -TODO: Adjust Boxplot approach (adjacent cells, outer fence, etc.) +TODO: Check if indexing in wavelets is correct -> Done +TODO: Combine get_cells() and _get_cells() -> Done +TODO: Check coarse_projection calculation for indexing errors -> Done +TODO: Adjust Boxplot approach (adjacent cells, outer fence, etc.) -> Done TODO: Give detailed description of wavelet detection """ @@ -237,24 +235,6 @@ class WaveletDetector(TroubledCellDetector): self._wavelet_projection_left, self._wavelet_projection_right \ = self._basis.multiwavelet_projection - def get_cells(self, projection): - """Calculates troubled cells in a given projection. - - Parameters - ---------- - projection : ndarray - Matrix of projection for each polynomial degree. - - Returns - ------- - list - List of indices for all detected troubled cells. - - """ - multiwavelet_coeffs = self._calculate_wavelet_coeffs(projection) - multiwavelet_coeffs = self._select_degree(multiwavelet_coeffs) - return self._get_cells(multiwavelet_coeffs, projection) - def _calculate_wavelet_coeffs(self, projection): """Calculates wavelet coefficients used for projection to coarser grid. @@ -303,25 +283,6 @@ class WaveletDetector(TroubledCellDetector): min_values = np.min(wavelet_matrix, axis=0) return np.where(-min_values > max_values, min_values, max_values) - @abstractmethod - def _get_cells(self, multiwavelet_coeffs, projection): - """Calculates troubled cells using multiwavelet coefficients. - - Parameters - ---------- - multiwavelet_coeffs : ndarray - Matrix of multiwavelet coefficients. - projection : ndarray - Matrix of projection for each polynomial degree. - - Returns - ------- - list - List of indices for all detected troubled cells. - - """ - pass - def _calculate_coarse_projection(self, projection): """Calculates coarse projection. @@ -419,23 +380,23 @@ class Boxplot(WaveletDetector): fold * self._fold_len - num_overlapping_cells, (fold+1) * self._fold_len + num_overlapping_cells)]) - def _get_cells(self, coeffs, projection): - """Calculate troubled cells using multiwavelet coefficients. + def get_cells(self, projection): + """Calculate troubled cells in a given projection. Parameters ---------- - coeffs : ndarray - Matrix of multiwavelet coefficients. projection : ndarray Matrix of projection for each polynomial degree. Returns ------- list - List of indices of all detected troubled cells. + List of indices for all detected troubled cells. """ # Determine quartiles of folds + coeffs = self._select_degree(self._calculate_wavelet_coeffs( + projection)) folds = coeffs[self._fold_indices] first_quartiles = np.quantile(folds, 0.25, axis=1, method=self._quantile_method) @@ -508,13 +469,11 @@ class Theoretical(WaveletDetector): np.sqrt(2) * self._mesh.cell_len) # comment to line above: or 2 or 3 - def _get_cells(self, coeffs, projection): - """Calculates troubled cells using multiwavelet coefficients. + def get_cells(self, projection): + """Calculate troubled cells in a given projection. Parameters ---------- - coeffs : ndarray - Matrix of multiwavelet coefficients. projection : ndarray Matrix of projection for each polynomial degree. @@ -524,6 +483,8 @@ class Theoretical(WaveletDetector): List of indices for all detected troubled cells. """ + coeffs = self._select_degree(self._calculate_wavelet_coeffs( + projection)) troubled_cells = [] max_avg = np.sqrt(0.5) \ * max(1, max(abs(projection[0][cell+1])