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

Added Mesh class.

parent 8552c898
Branches
Tags
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
""" """
from functools import cache
from typing import Tuple from typing import Tuple
import numpy as np import numpy as np
from numpy import ndarray from numpy import ndarray
...@@ -16,6 +17,78 @@ from Initial_Condition import InitialCondition ...@@ -16,6 +17,78 @@ from Initial_Condition import InitialCondition
x = Symbol('x') x = Symbol('x')
class Mesh:
"""Class for mesh/grid.
Each cell is characterized by its center.
Attributes
----------
num_grid_cells : int
Number of cells in the mesh (ghost cells notwithstanding). Usually
exponential of 2.
bounds : Tuple[float, float]
Left and right boundary of the mesh interval.
interval_len : float
Length of the mesh interval.
cell_len : float
Length of a mesh cell.
cells : ndarray
Array of cell centers in mesh.
"""
def __init__(self, num_grid_cells: int, num_ghost_cells: int,
left_bound: float, right_bound: float) -> None:
"""Initialize Mesh.
Parameters
----------
num_grid_cells : int
Number of cells in the mesh (ghost cells notwithstanding). Usually
exponential of 2.
num_ghost_cells : int
Number of ghost cells on each side of the mesh.
left_bound : float
Left boundary of the mesh interval.
right_bound : float
Right boundary of the mesh interval.
"""
self._num_grid_cells = num_grid_cells
self._num_ghost_cells = num_ghost_cells
self._left_bound = left_bound
self._right_bound = right_bound
@property
def num_grid_cells(self) -> int:
"""Return number of grid cells."""
return self._num_grid_cells
@property
def bounds(self) -> Tuple[float, float]:
"""Return left and right boundary of the mesh interval."""
return self._left_bound, self._right_bound
@property
def interval_len(self) -> float:
"""Return the length of the mesh interval."""
return self._right_bound - self._left_bound
@property
def cell_len(self) -> float:
"""Return the length of a mesh cell."""
return self.interval_len/self.num_grid_cells
@property
@cache
def cells(self) -> ndarray:
"""Return the cell centers of the mesh (including ghost cells)."""
return np.arange(
self._left_bound - (self._num_ghost_cells*2-1)/2*self.cell_len,
self._right_bound + (self._num_ghost_cells*2+1)/2*self.cell_len,
self.cell_len)
def calculate_approximate_solution( def calculate_approximate_solution(
projection: ndarray, points: ndarray, polynomial_degree: int, projection: ndarray, points: ndarray, polynomial_degree: int,
basis: ndarray) -> ndarray: basis: ndarray) -> ndarray:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment