diff --git a/Snakefile b/Snakefile index 6cd65c6fb45372d8c5d22eed0e1f118ad47dd44c..0bf224cc6fec0a832acf5c950b5b224bf804e1ff 100644 --- a/Snakefile +++ b/Snakefile @@ -25,7 +25,7 @@ TODO: Discuss how wavelet details should be plotted Urgent: TODO: Refactor Boxplot class -> Done TODO: Enforce periodic boundary condition for projection with decorator -> Done -TODO: Enforce Boxplot bounds with decorator +TODO: Enforce Boxplot bounds with decorator -> Done TODO: Enforce Boxplot folds with decorator TODO: Enforce boundary for initial condition in exact solution only TODO: Adapt number of ghost cells based on ANN stencil diff --git a/scripts/tcd/Boundary_Condition.py b/scripts/tcd/Boundary_Condition.py index 3d5ab91bcaaaa4c1960b3118e99cd0fc10b5cfb6..72c429a686120840266cdb0fc0fee2e660ef542a 100644 --- a/scripts/tcd/Boundary_Condition.py +++ b/scripts/tcd/Boundary_Condition.py @@ -3,17 +3,9 @@ @author: Laura C. Kühle """ -# from typing import Tuple -# from abc import ABC, abstractmethod -# import numpy as np +import numpy as np from numpy import ndarray -# from .Basis_Function import Basis -# from .Initial_Condition import InitialCondition -# from .Mesh import Mesh -# from .projection_utils import do_initial_projection -# from .Quadrature import Quadrature - def periodic_boundary(projection: ndarray, num_ghost_cells: int) -> ndarray: """Enforce boundary condition. @@ -74,3 +66,14 @@ def enforce_boundary(num_ghost_cells=None): raise Exception('Not implemented!') return boundary return _enforce_boundary + + +def enforce_boxplot_boundaries(func): + def boxplot_boundary(self, *args, **kwargs): + bounds = np.array(func(self, *args, **kwargs)) + if self._mesh.boundary == 'periodic': + return tuple(periodic_boundary(projection=bounds, + num_ghost_cells=1)) + else: + raise Exception('Not implemented!') + return boxplot_boundary diff --git a/scripts/tcd/Troubled_Cell_Detector.py b/scripts/tcd/Troubled_Cell_Detector.py index 69c216224539a8463df8b4cf3aa7b62e4bd6ea40..d78fec7bb4758e622eb62812de2c3166de876b77 100644 --- a/scripts/tcd/Troubled_Cell_Detector.py +++ b/scripts/tcd/Troubled_Cell_Detector.py @@ -10,6 +10,7 @@ from numpy import ndarray import torch from . import ANN_Model +from .Boundary_Condition import enforce_boxplot_boundaries from .Mesh import Mesh @@ -423,6 +424,7 @@ class Boxplot(WaveletDetector): return troubled_cells + @enforce_boxplot_boundaries def _compute_bounds(self, coeffs: ndarray) -> Tuple[ndarray, ndarray]: """Compute lower and upper bound for Boxplot outliers. @@ -455,12 +457,6 @@ class Boxplot(WaveletDetector): upper_bounds[1:-1] = third_quartiles + self._whisker_len * ( third_quartiles-first_quartiles) - # Adjust bounds to capture periodic boundary - lower_bounds[0] = lower_bounds[-2] - lower_bounds[-1] = lower_bounds[1] - upper_bounds[0] = upper_bounds[-2] - upper_bounds[-1] = upper_bounds[1] - return lower_bounds, upper_bounds