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

Added mesh as argument for '_get_point()'.

parent 0e93e230
Branches
No related tags found
No related merge requests found
...@@ -20,9 +20,23 @@ TODO: Discuss descriptions (matrices, cfl number, right-hand side, ...@@ -20,9 +20,23 @@ TODO: Discuss descriptions (matrices, cfl number, right-hand side,
limiting slope, basis, wavelet, etc.) limiting slope, basis, wavelet, etc.)
TODO: Discuss referencing info on SSPRK3 TODO: Discuss referencing info on SSPRK3
TODO: Discuss why the left_factor is not subtracted for the second
discontinuity for the two-sided Heaviside
TODO: Discuss order of addends for two-sided Heaviside
TODO: Discuss whether to enforce positive shift in the two-sided Heaviside
TODO: Discuss reasoning behind minimum mesh size of 2^5 instead of 2^3 for
training data
TODO: Discuss why basis degree can be as high as 6 if it is only defined up
to 4 so far (alternative calculation?)
TODO: Discuss whether domain other than [-1, 1] is in any way useful for
training
Urgent: Urgent:
TODO: Introduce middle_factor for two-sided Heaviside TODO: Introduce middle_factor for two-sided Heaviside -> Done
TODO: Adjust polynomial degree for ANN Data Generator TODO: Adjust mesh exponent for ANN Data Generator -> Done
TODO: Fix index issue for mesh selection during training -> Done
TODO: Add mesh as argument for _get_point() -> Done
TODO: Replace induce_adjustment() with margin
TODO: Rename 'adjustment' to 'shift' TODO: Rename 'adjustment' to 'shift'
TODO: Induce shift in IC class TODO: Induce shift in IC class
TODO: Move plot_approximation_results() into plotting script TODO: Move plot_approximation_results() into plotting script
...@@ -335,7 +349,7 @@ def do_initial_projection(initial_condition, mesh, basis, quadrature, ...@@ -335,7 +349,7 @@ def do_initial_projection(initial_condition, mesh, basis, quadrature,
for degree in range(basis.polynomial_degree + 1): for degree in range(basis.polynomial_degree + 1):
new_row.append(np.float64(sum(initial_condition.calculate( new_row.append(np.float64(sum(initial_condition.calculate(
x=eval_point + mesh.cell_len/2 x=eval_point + mesh.cell_len/2
* quadrature.nodes[point] - adjustment) * quadrature.nodes[point] - adjustment, mesh=mesh)
* basis.basis[degree].subs( * basis.basis[degree].subs(
x, quadrature.nodes[point]) x, quadrature.nodes[point])
* quadrature.weights[point] * quadrature.weights[point]
......
...@@ -98,18 +98,18 @@ class InitialCondition(ABC): ...@@ -98,18 +98,18 @@ class InitialCondition(ABC):
""" """
pass pass
def calculate(self, x, mesh=None): def calculate(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
If a mesh is given, the x-value is projected into its periodic In evaluation (not training) mode, the x-value is projected
interval before evaluating the function. into its periodic interval before evaluating the function.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh, optional mesh : Mesh
Mesh for calculation. Default: None. Mesh for calculation.
Returns Returns
------- -------
...@@ -117,22 +117,24 @@ class InitialCondition(ABC): ...@@ -117,22 +117,24 @@ class InitialCondition(ABC):
Value of function evaluates at x-value. Value of function evaluates at x-value.
""" """
if mesh is not None: if mesh.mode is 'evaluation':
left_bound, right_bound = mesh.bounds left_bound, right_bound = mesh.bounds
while x < left_bound: while x < left_bound:
x += mesh.interval_len x += mesh.interval_len
while x > right_bound: while x > right_bound:
x -= mesh.interval_len x -= mesh.interval_len
return self._get_point(x) return self._get_point(x, mesh)
@abstractmethod @abstractmethod
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
...@@ -185,13 +187,15 @@ class Sine(InitialCondition): ...@@ -185,13 +187,15 @@ class Sine(InitialCondition):
config = {'factor': factor} config = {'factor': factor}
self._reset(config) self._reset(config)
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
...@@ -215,13 +219,15 @@ class Box(InitialCondition): ...@@ -215,13 +219,15 @@ class Box(InitialCondition):
"""Returns flag that function is not smooth.""" """Returns flag that function is not smooth."""
return False return False
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
...@@ -286,13 +292,15 @@ class FourPeakWave(InitialCondition): ...@@ -286,13 +292,15 @@ class FourPeakWave(InitialCondition):
"""Returns flag that function is not smooth.""" """Returns flag that function is not smooth."""
return False return False
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
...@@ -392,13 +400,15 @@ class Linear(InitialCondition): ...@@ -392,13 +400,15 @@ class Linear(InitialCondition):
config = {'factor': factor} config = {'factor': factor}
self._reset(config) self._reset(config)
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
...@@ -456,13 +466,15 @@ class LinearAbsolute(InitialCondition): ...@@ -456,13 +466,15 @@ class LinearAbsolute(InitialCondition):
config = {'factor': factor} config = {'factor': factor}
self._reset(config) self._reset(config)
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
...@@ -511,13 +523,15 @@ class DiscontinuousConstant(InitialCondition): ...@@ -511,13 +523,15 @@ class DiscontinuousConstant(InitialCondition):
"""Returns flag that function is not smooth.""" """Returns flag that function is not smooth."""
return False return False
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
...@@ -574,13 +588,15 @@ class Polynomial(InitialCondition): ...@@ -574,13 +588,15 @@ class Polynomial(InitialCondition):
config = {'factor': factor, 'exponential': exponential} config = {'factor': factor, 'exponential': exponential}
self._reset(config) self._reset(config)
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
...@@ -632,13 +648,15 @@ class Continuous(InitialCondition): ...@@ -632,13 +648,15 @@ class Continuous(InitialCondition):
config = {'factor': factor} config = {'factor': factor}
self._reset(config) self._reset(config)
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
...@@ -702,13 +720,15 @@ class HeavisideOneSided(InitialCondition): ...@@ -702,13 +720,15 @@ class HeavisideOneSided(InitialCondition):
'discontinuity_position': self._discontinuity_position} 'discontinuity_position': self._discontinuity_position}
self._reset(config) self._reset(config)
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
...@@ -799,13 +819,15 @@ class HeavisideTwoSided(InitialCondition): ...@@ -799,13 +819,15 @@ class HeavisideTwoSided(InitialCondition):
'right_factor': right_factor, 'adjustment': adjustment} 'right_factor': right_factor, 'adjustment': adjustment}
self._reset(config) self._reset(config)
def _get_point(self, x): def _get_point(self, x, mesh):
"""Evaluates function at given x-value. """Evaluates function at given x-value.
Parameters Parameters
---------- ----------
x : float x : float
Evaluation point of function. Evaluation point of function.
mesh : Mesh
Mesh for calculation.
Returns Returns
------- -------
......
...@@ -26,6 +26,8 @@ class Mesh: ...@@ -26,6 +26,8 @@ class Mesh:
Attributes Attributes
---------- ----------
mode : str
Mode for mesh use. Either 'training' or 'evaluation'.
num_grid_cells : int num_grid_cells : int
Number of cells in the mesh (ghost cells notwithstanding). Usually Number of cells in the mesh (ghost cells notwithstanding). Usually
exponential of 2. exponential of 2.
...@@ -62,6 +64,7 @@ class Mesh: ...@@ -62,6 +64,7 @@ class Mesh:
""" """
self._num_grid_cells = num_grid_cells self._num_grid_cells = num_grid_cells
self._mode = 'training' if training_data_mode else 'evaluation'
if not training_data_mode: if not training_data_mode:
if not math.log(self._num_grid_cells, 2).is_integer(): if not math.log(self._num_grid_cells, 2).is_integer():
raise ValueError('The number of cells in the mesh has to be ' raise ValueError('The number of cells in the mesh has to be '
...@@ -70,6 +73,11 @@ class Mesh: ...@@ -70,6 +73,11 @@ class Mesh:
self._left_bound = left_bound self._left_bound = left_bound
self._right_bound = right_bound self._right_bound = right_bound
@property
def mode(self) -> str:
"""Return mode ('training' or 'evaluation')."""
return self._mode
@property @property
def num_grid_cells(self) -> int: def num_grid_cells(self) -> int:
"""Return number of grid cells.""" """Return number of grid cells."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment