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

Adapted 'randomize()' to take an input configuration. Allowed adjustment in x-direction.

parent c40e57bb
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,10 @@ class InitialCondition(object):
def is_smooth(self):
return True
def randomize(self):
def induce_adjustment(self, value):
pass
def randomize(self, config):
pass
def calculate(self, x):
......@@ -43,8 +46,9 @@ class Sine(InitialCondition):
# Unpack necessary configurations
self._factor = config.pop('factor', 2)
def randomize(self):
config = {'factor': 2}
def randomize(self, config):
factor = config.pop('factor', np.random.uniform(low=-100, high=100))
config = {'factor': factor}
self._reset(config)
def _get_point(self, x):
......@@ -109,9 +113,9 @@ class Linear(InitialCondition):
# Unpack necessary configurations
self._factor = config.pop('factor', 1)
def randomize(self):
a = np.random.uniform(low=-100, high=100)
config = {'factor': a}
def randomize(self, config):
factor = config.pop('factor', np.random.uniform(low=-100, high=100))
config = {'factor': factor}
self._reset(config)
def _get_point(self, x):
......@@ -128,9 +132,9 @@ class LinearAbsolut(InitialCondition):
def is_smooth(self):
return False
def randomize(self):
a = np.random.uniform(low=-100, high=100)
config = {'factor': a}
def randomize(self, config):
factor = config.pop('factor', np.random.uniform(low=-100, high=100))
config = {'factor': factor}
self._reset(config)
def _get_point(self, x):
......@@ -158,10 +162,10 @@ class Polynomial(InitialCondition):
self._factor = config.pop('factor', 1)
self._exponential = config.pop('exponential', 2)
def randomize(self):
a = np.random.uniform(low=-100, high=100)
k = np.random.randint(2, high=6)
config = {'factor': a, 'exponential': k}
def randomize(self, config):
factor = config.pop('factor', np.random.uniform(low=-100, high=100))
exponential = config.pop('exponential', np.random.randint(2, high=6))
config = {'factor': factor, 'exponential': exponential}
self._reset(config)
def _get_point(self, x):
......@@ -175,9 +179,9 @@ class Continuous(InitialCondition):
# Unpack necessary configurations
self._factor = config.pop('factor', 1)
def randomize(self):
a = np.random.uniform(low=-100, high=100)
config = {'factor': a}
def randomize(self, config):
factor = config.pop('factor', np.random.uniform(low=-100, high=100))
config = {'factor': factor}
self._reset(config)
def _get_point(self, x):
......@@ -194,9 +198,9 @@ class HeavisideOneSided(InitialCondition):
def is_smooth(self):
return False
def randomize(self):
a = np.random.choice([-1, 1])
config = {'factor': a}
def randomize(self, config):
factor = config.pop('factor', np.random.uniform(low=-100, high=100))
config = {'factor': factor}
self._reset(config)
def _get_point(self, x):
......@@ -210,15 +214,22 @@ class HeavisideTwoSided(InitialCondition):
# Unpack necessary configurations
self._left_factor = config.pop('left_factor', 1)
self._right_factor = config.pop('right_factor', 2)
self._adjustment = config.pop('adjustment', 0)
def is_smooth(self):
return False
def randomize(self):
a = np.random.choice([-1, 1])
b = np.random.choice([-1, 1])
config = {'left_factor': a, 'right_factor': b}
def induce_adjustment(self, value):
self._adjustment = value
def randomize(self, config):
left_factor = config.pop('left_factor', np.random.choice([-1, 1]))
right_factor = config.pop('right_factor', np.random.choice([-1, 1]))
adjustment = config.pop('adjustment', np.random.uniform(low=-1, high=1))
config = {'left_factor': left_factor, 'right_factor': right_factor, 'adjustment': adjustment}
self._reset(config)
def _get_point(self, x):
return self._left_factor - self._left_factor * np.heaviside(x, 0) - self._right_factor * np.heaviside(x, 0)
return self._left_factor\
- self._left_factor * np.heaviside(x - self._adjustment, 0)\
- self._right_factor * np.heaviside(x + self._adjustment, 0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment