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

Replaced calculation in 'cell_centers_leg_basis_coeff()' with '_do_initial_projection()'.

parent 5b4d71cb
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,8 @@ TODO: Fix might be referenced before assignment error for "discontinuous_functio
TODO: Extract initial conditions from "generate_[...]_cell_data()" -> Done
TODO: Combine "generate_smooth_cell_data()" and "generate_troubled_cell_data()" to "generate_cell_data()" -> Done
TODO: Adapt variable names to fit style
TODO: Replace "num_of_eval_pts" with polynomial_degree + 1
TODO: Replace "num_of_eval_pts" with polynomial_degree + 1 -> Done (no need as deleted)
TODO: Replace calculation in "cell_centers_leg_basis_coeff()" with "_do_initial_projection()" -> Done
"""
......@@ -21,6 +22,7 @@ from sympy import Symbol
import Initial_Condition
import Basis_Function
import DG_Approximation
x1 = Symbol('x')
......@@ -31,34 +33,22 @@ def cell_centers_leg_basis_coeff(num_grid_cells, polynomial_degree, initial_cond
# Create stencil and basis_coefficients for smooth_function mapped onto stencil
interval, centers, h = create_3_point_stencil()
# print(interval, centers, h)
initial_condition.induce_adjustment(-h[0]/3)
if initial_condition.is_smooth():
centers = np.array([[0] for _ in centers])
left_bound, right_bound = interval
cell_len = (right_bound - left_bound) / num_grid_cells # assumes uniform mesh
# Gauss-Legendre Quadrature: Evaluation
num_of_eval_pts = polynomial_degree + 1
xi_eval, weights_eval = np.polynomial.legendre.leggauss(num_of_eval_pts)
cell_centers = np.zeros(num_grid_cells)
basis_coeff = np.zeros((num_grid_cells, polynomial_degree + 1))
basis = Basis_Function.OrthonormalLegendre(polynomial_degree)
basis_vector = basis.get_basis_vector()
dg_scheme = DG_Approximation.DGScheme('NoDetection', polynomial_degree=polynomial_degree,
num_grid_cells=num_grid_cells, left_bound=left_bound, right_bound=right_bound,
quadrature='Gauss', quadrature_config={'num_eval_points': polynomial_degree+1}
)
# print("Objects?")
for degree in range(polynomial_degree + 1):
for cell in range(num_grid_cells):
cell_centers[cell] = left_bound + (cell + 0.5) * cell_len
# In-Cell [-1,1] coordinates:
nodes_eval = (cell_len / 2) * xi_eval + cell_centers[cell] * np.ones(num_of_eval_pts)
# Projections calculation
init_node = [initial_condition.calculate(node) for node in nodes_eval-centers[1]]
integrand = init_node * np.array([basis_vector[degree].subs(x1, entry) for entry in xi_eval])
basis_coeff[cell][degree] = sum(integrand * weights_eval)
if initial_condition.is_smooth():
coeffs = dg_scheme.build_training_data(0, initial_condition)
else:
coeffs = dg_scheme.build_training_data(centers[1], initial_condition)
return cell_centers, h, basis_coeff
centers = [center[0] for center in centers]
return centers, h, coeffs
# Approximation for certain evaluation input_matrix(s) in a cell given a provided polynomial_degree
......@@ -115,16 +105,6 @@ def generate_cell_data(num_of_samples, functions, is_smooth):
# Create basis_coefficients for function mapped onto stencil
polynomial_degree = np.random.randint(1, high=5)
centers, h, basis_coeffs = cell_centers_leg_basis_coeff(3, polynomial_degree, function)
# print()
# print("Centers")
# print(centers)
# # print(centers_1)
# centers = [[entry] for entry in centers]
# centers = np.array(centers)
# # print(centers == centers_2)
# # print(type(centers_2), type(centers_1), type(centers))
# print(centers)
# print()
# Calculating cell averages and evaluations at the boundary
for j in range(3):
......
......@@ -90,7 +90,7 @@ class DGScheme(object):
Here come some parameter.
"""
projection = self._do_initial_projection()
projection = self._do_initial_projection(self._init_cond)
time_step = abs(self._cfl_number * self._cell_len / self._wave_speed)
......@@ -155,7 +155,7 @@ class DGScheme(object):
mass_matrix.append(new_row)
self._inv_mass = np.array(mass_matrix)
def _do_initial_projection(self):
def _do_initial_projection(self, initial_condition, adjustment=0):
# Initialize matrix and set first entry to accommodate for ghost cell
output_matrix = [0]
basis_vector = self._basis.get_basis_vector()
......@@ -166,7 +166,8 @@ class DGScheme(object):
for degree in range(self._polynomial_degree + 1):
new_entry = sum(
self._init_cond.calculate(eval_point + self._cell_len/2 * self._quadrature.get_eval_points()[point])
initial_condition.calculate(
eval_point + self._cell_len/2 * self._quadrature.get_eval_points()[point] - adjustment)
* basis_vector[degree].subs(x, self._quadrature.get_eval_points()[point])
* self._quadrature.get_weights()[point]
for point in range(self._quadrature.get_num_points()))
......@@ -181,3 +182,9 @@ class DGScheme(object):
print(np.array(output_matrix).shape)
return np.transpose(np.array(output_matrix))
def build_training_data(self, adjustment, initial_condition=None):
if initial_condition is None:
initial_condition = self._init_cond
projection = self._do_initial_projection(initial_condition, adjustment)
return np.transpose(projection)[1:-1]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment