From 5b26530ef417560d7fe3c1209574f87fc940d22a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=BChle=2C=20Laura=20Christine=20=28lakue103=29?= <laura.kuehle@uni-duesseldorf.de> Date: Fri, 10 Mar 2023 08:45:17 +0100 Subject: [PATCH] Enforced boundary condition on Boxplot bounds with decorator. --- Snakefile | 2 +- scripts/tcd/Boundary_Condition.py | 21 ++++++++++++--------- scripts/tcd/Troubled_Cell_Detector.py | 8 ++------ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Snakefile b/Snakefile index 6cd65c6..0bf224c 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 3d5ab91..72c429a 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 69c2162..d78fec7 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 -- GitLab