Skip to content
Snippets Groups Projects
Commit 3bef3da5 authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Upload Limiter.py (as of March 17 2020)

parent 26a9a147
Branches
Tags
No related merge requests found
# -*- coding: utf-8 -*-
"""
@author: Laura C. Kühle
"""
import numpy as np
class Limiter(object):
def __init__(self, config):
pass
def get_name(self):
return self.function_name
def apply():
pass
class NoLimiter(Limiter):
def __init__(self, config):
# Set name of function
self.function_name = 'NoLimiter'
pass
def apply(self, projection, cell):
return np.transpose(self.projection)[cell]
class MinMod(Limiter):
def __init__(self, config):
# Unpack necessary parameter
self.erase_degree = config.pop('erase_degree', 0)
# Set name of function
self.function_name = 'MinMod' + str(self.erase_degree)
# Pop unncessary parameter
config.pop('cell_len')
self.projection = []
self.cell = 0
pass
def apply(self, projection, cell):
self.projection = projection
self.cell = cell
self._set_cell_slope()
is_good_cell = self._determine_modification()
if is_good_cell:
return np.transpose(self.projection)[self.cell]
adapted_projection = np.transpose(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):
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)
self.cell_slope = slope[self.cell]
def _determine_modification(self):
forward_slope = (self.projection[0][self.cell+1]
- self.projection[0][self.cell]) * (0.5**0.5)
backward_slope = (self.projection[0][self.cell]
- self.projection[0][self.cell-1]) * (0.5**0.5)
if ((forward_slope <= 0) & (backward_slope <= 0)
& (self.cell_slope <= 0)):
return True
if ((forward_slope >= 0) & (backward_slope >= 0)
& (self.cell_slope >= 0)):
return True
return False
class ModifiedMinMod(MinMod):
def __init__(self, config):
# Unpack necessary configurations
self.cell_len = config.pop('cell_len')
self.erase_degree = config.pop('erase_degree', 0)
self.mod_factor = config.pop('mod_factor', 0)
# Set name of function
self.function_name = 'ModifiedMinMod' + str(self.erase_degree)
self.projection = []
self.cell = 0
pass
def _determine_modification(self):
if (abs(self.cell_slope) <= self.mod_factor*self.cell_len**2):
return True # former: u_tilde_entry
return super()._determine_modification()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment