Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Troubled Cell Detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Christine Kühle
Troubled Cell Detection
Commits
0ee8fc66
Commit
0ee8fc66
authored
Jan 17, 2021
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Replaced 'legendre_basis_approximation()' with 'calculate_approximate_solution()'.
parent
0b067043
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ANN_Training_Data_Generator.py
+39
-4
39 additions, 4 deletions
ANN_Training_Data_Generator.py
DG_Approximation.py
+4
-0
4 additions, 0 deletions
DG_Approximation.py
Troubled_Cell_Detector.py
+8
-8
8 additions, 8 deletions
Troubled_Cell_Detector.py
with
51 additions
and
12 deletions
ANN_Training_Data_Generator.py
+
39
−
4
View file @
0ee8fc66
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
TODO: Adjust code to fit style
TODO: Adjust code to fit style
TODO: Adapt variable names to fit style
TODO: Adapt variable names to fit style
TODO: Replace
'
legendre_basis_approximation()
'
with
'
calculate_approximate_solution()
'
-> Done
"""
"""
...
@@ -14,6 +15,7 @@ from sympy import Symbol
...
@@ -14,6 +15,7 @@ from sympy import Symbol
import
Initial_Condition
import
Initial_Condition
import
Basis_Function
import
Basis_Function
import
DG_Approximation
import
DG_Approximation
import
Quadrature
x1
=
Symbol
(
'
x
'
)
x1
=
Symbol
(
'
x
'
)
...
@@ -29,7 +31,7 @@ def cell_centers_leg_basis_coeff(num_grid_cells, polynomial_degree, initial_cond
...
@@ -29,7 +31,7 @@ def cell_centers_leg_basis_coeff(num_grid_cells, polynomial_degree, initial_cond
initial_condition
.
induce_adjustment
(
-
h
[
0
]
/
3
)
initial_condition
.
induce_adjustment
(
-
h
[
0
]
/
3
)
left_bound
,
right_bound
=
interval
left_bound
,
right_bound
=
interval
dg_scheme
=
DG_Approximation
.
DGScheme
(
'
No
Detect
ion
'
,
polynomial_degree
=
polynomial_degree
,
dg_scheme
=
DG_Approximation
.
DGScheme
(
'
Wavelet
Detect
or
'
,
polynomial_degree
=
polynomial_degree
,
num_grid_cells
=
num_grid_cells
,
left_bound
=
left_bound
,
right_bound
=
right_bound
,
num_grid_cells
=
num_grid_cells
,
left_bound
=
left_bound
,
right_bound
=
right_bound
,
quadrature
=
'
Gauss
'
,
quadrature_config
=
{
'
num_eval_points
'
:
polynomial_degree
+
1
}
quadrature
=
'
Gauss
'
,
quadrature_config
=
{
'
num_eval_points
'
:
polynomial_degree
+
1
}
)
)
...
@@ -39,7 +41,7 @@ def cell_centers_leg_basis_coeff(num_grid_cells, polynomial_degree, initial_cond
...
@@ -39,7 +41,7 @@ def cell_centers_leg_basis_coeff(num_grid_cells, polynomial_degree, initial_cond
else
:
else
:
coeffs
=
dg_scheme
.
build_training_data
(
centers
[
1
],
initial_condition
)
coeffs
=
dg_scheme
.
build_training_data
(
centers
[
1
],
initial_condition
)
return
centers
,
h
,
coeffs
return
centers
,
h
,
interval
,
coeffs
# Approximation for certain evaluation input_matrix(s) in a cell given a provided polynomial_degree
# Approximation for certain evaluation input_matrix(s) in a cell given a provided polynomial_degree
...
@@ -84,6 +86,10 @@ def generate_cell_data(num_of_samples, functions, is_smooth):
...
@@ -84,6 +86,10 @@ def generate_cell_data(num_of_samples, functions, is_smooth):
samples_per_function
=
int
(
num_of_samples
/
len
(
functions
))
samples_per_function
=
int
(
num_of_samples
/
len
(
functions
))
function_id
=
0
function_id
=
0
input_data
=
np
.
zeros
((
num_of_samples
,
5
))
input_data
=
np
.
zeros
((
num_of_samples
,
5
))
test_data
=
np
.
zeros
((
num_of_samples
,
5
))
quadrature_cell_center
=
Quadrature
.
Custom
({
'
eval_points
'
:
[
0
]})
quadrature_cell_boundary
=
Quadrature
.
Custom
({
'
eval_points
'
:
[
1
]})
for
i
in
range
(
num_of_samples
):
for
i
in
range
(
num_of_samples
):
print
(
'
Object
'
)
print
(
'
Object
'
)
...
@@ -95,18 +101,40 @@ def generate_cell_data(num_of_samples, functions, is_smooth):
...
@@ -95,18 +101,40 @@ def generate_cell_data(num_of_samples, functions, is_smooth):
# Create basis_coefficients for function mapped onto stencil
# Create basis_coefficients for function mapped onto stencil
polynomial_degree
=
np
.
random
.
randint
(
1
,
high
=
5
)
polynomial_degree
=
np
.
random
.
randint
(
1
,
high
=
5
)
centers
,
h
,
basis_coeffs
=
cell_centers_leg_basis_coeff
(
3
,
polynomial_degree
,
function
)
centers
,
h
,
interval
,
basis_coeffs
=
cell_centers_leg_basis_coeff
(
3
,
polynomial_degree
,
function
)
h
=
h
[
0
]
# L: h is always a float, why the list format???
# Calculating cell averages and evaluations at the boundary
# Calculating cell averages and evaluations at the boundary
for
j
in
range
(
3
):
for
j
in
range
(
3
):
# Cell Averages
# Cell Averages
input_data
[
i
,
2
*
j
]
=
legendre_basis_approximation
(
centers
[
j
],
centers
,
j
,
0
,
basis_coeffs
)
input_data
[
i
,
2
*
j
]
=
legendre_basis_approximation
(
centers
[
j
],
centers
,
j
,
0
,
basis_coeffs
)
# print()
# print('data', i, 2*j)
# print(input_data[i, 2*j])
# print(legendre_basis_approximation(centers[j], centers, j, polynomial_degree, basis_coeffs)[0])
# print()
# Evaluations at Boundary of Center Cell
# Evaluations at Boundary of Center Cell
if
j
==
1
:
if
j
==
1
:
input_data
[
i
,
j
]
=
legendre_basis_approximation
(
centers
[
j
]
-
h
/
2
,
centers
,
j
,
polynomial_degree
,
input_data
[
i
,
j
]
=
legendre_basis_approximation
(
centers
[
j
]
-
h
/
2
,
centers
,
j
,
polynomial_degree
,
basis_coeffs
)
basis_coeffs
)
input_data
[
i
,
2
*
j
+
1
]
=
legendre_basis_approximation
(
centers
[
j
]
+
h
/
2
,
centers
,
j
,
input_data
[
i
,
2
*
j
+
1
]
=
legendre_basis_approximation
(
centers
[
j
]
+
h
/
2
,
centers
,
j
,
polynomial_degree
,
basis_coeffs
)
polynomial_degree
,
basis_coeffs
)
# print(i, j, 2*j+1)
# print(input_data[i, j])
# print(input_data[i, 2*j+1])
left_bound
,
right_bound
=
interval
# print('Yeah')
dg_scheme
=
DG_Approximation
.
DGScheme
(
'
WaveletDetector
'
,
polynomial_degree
=
polynomial_degree
,
num_grid_cells
=
3
,
left_bound
=
left_bound
,
right_bound
=
right_bound
)
# print('test')
# print(input_data[i])
test_1
=
dg_scheme
.
check_wavelet
(
np
.
transpose
(
basis_coeffs
),
quadrature_cell_center
,
0
)
test_2
=
dg_scheme
.
check_wavelet
(
np
.
transpose
(
basis_coeffs
),
quadrature_cell_boundary
,
polynomial_degree
)
# print(test_1, test_2)
test_data
[
i
]
=
np
.
array
(
list
(
zip
(
test_1
[:,
0
],
test_2
[:,
0
],
test_1
[:,
1
],
test_2
[:,
1
],
test_1
[:,
2
])))[
0
]
# print(test_data[i])
# Update Function ID
# Update Function ID
if
(
i
%
samples_per_function
==
samples_per_function
-
1
)
and
(
function_id
!=
len
(
functions
)
-
1
):
if
(
i
%
samples_per_function
==
samples_per_function
-
1
)
and
(
function_id
!=
len
(
functions
)
-
1
):
...
@@ -115,6 +143,13 @@ def generate_cell_data(num_of_samples, functions, is_smooth):
...
@@ -115,6 +143,13 @@ def generate_cell_data(num_of_samples, functions, is_smooth):
# Shuffle Function input_matrices
# Shuffle Function input_matrices
order
=
np
.
random
.
permutation
(
num_of_samples
)
order
=
np
.
random
.
permutation
(
num_of_samples
)
input_data
=
input_data
[
order
]
input_data
=
input_data
[
order
]
test_data
=
test_data
[
order
]
for
i
in
range
(
len
(
input_data
)):
print
(
i
)
print
(
input_data
[
i
])
print
(
test_data
[
i
])
print
()
output_data
=
np
.
zeros
((
num_of_samples
,
2
))
output_data
=
np
.
zeros
((
num_of_samples
,
2
))
if
is_smooth
:
if
is_smooth
:
...
@@ -122,7 +157,7 @@ def generate_cell_data(num_of_samples, functions, is_smooth):
...
@@ -122,7 +157,7 @@ def generate_cell_data(num_of_samples, functions, is_smooth):
else
:
else
:
output_data
[:,
0
]
=
np
.
ones
(
num_of_samples
)
output_data
[:,
0
]
=
np
.
ones
(
num_of_samples
)
return
inpu
t_data
,
output_data
return
tes
t_data
,
output_data
def
normalize_data
(
input_data
):
def
normalize_data
(
input_data
):
...
...
This diff is collapsed.
Click to expand it.
DG_Approximation.py
+
4
−
0
View file @
0ee8fc66
...
@@ -188,3 +188,7 @@ class DGScheme(object):
...
@@ -188,3 +188,7 @@ class DGScheme(object):
initial_condition
=
self
.
_init_cond
initial_condition
=
self
.
_init_cond
projection
=
self
.
_do_initial_projection
(
initial_condition
,
adjustment
)
projection
=
self
.
_do_initial_projection
(
initial_condition
,
adjustment
)
return
np
.
transpose
(
projection
)[
1
:
-
1
]
return
np
.
transpose
(
projection
)[
1
:
-
1
]
def
check_wavelet
(
self
,
projection
,
quadrature
,
polynomial_degree
):
projection
=
self
.
_detector
.
calculate_approximate_solution
(
projection
,
quadrature
,
polynomial_degree
)
return
projection
This diff is collapsed.
Click to expand it.
Troubled_Cell_Detector.py
+
8
−
8
View file @
0ee8fc66
...
@@ -70,7 +70,7 @@ class TroubledCellDetector(object):
...
@@ -70,7 +70,7 @@ class TroubledCellDetector(object):
def
_plot_mesh
(
self
,
projection
):
def
_plot_mesh
(
self
,
projection
):
grid
,
exact
=
self
.
_calculate_exact_solution
(
self
.
_mesh
[
2
:
-
2
],
self
.
_cell_len
)
grid
,
exact
=
self
.
_calculate_exact_solution
(
self
.
_mesh
[
2
:
-
2
],
self
.
_cell_len
)
approx
=
self
.
_
calculate_approximate_solution
(
projection
[:,
1
:
-
1
])
approx
=
self
.
calculate_approximate_solution
(
projection
[:,
1
:
-
1
]
,
self
.
_quadrature
,
self
.
_polynomial_degree
)
pointwise_error
=
np
.
abs
(
exact
-
approx
)
pointwise_error
=
np
.
abs
(
exact
-
approx
)
max_error
=
np
.
max
(
pointwise_error
)
max_error
=
np
.
max
(
pointwise_error
)
...
@@ -130,16 +130,16 @@ class TroubledCellDetector(object):
...
@@ -130,16 +130,16 @@ class TroubledCellDetector(object):
return
grid
,
exact
return
grid
,
exact
def
_
calculate_approximate_solution
(
self
,
projection
):
def
calculate_approximate_solution
(
self
,
projection
,
quadrature
,
polynomial_degree
):
points
=
self
.
_
quadrature
.
get_eval_points
()
points
=
quadrature
.
get_eval_points
()
num_points
=
self
.
_
quadrature
.
get_num_points
()
num_points
=
quadrature
.
get_num_points
()
basis
=
self
.
_basis
.
get_basis_vector
()
basis
=
self
.
_basis
.
get_basis_vector
()
basis_matrix
=
[[
basis
[
degree
].
subs
(
x
,
points
[
point
])
for
point
in
range
(
num_points
)]
basis_matrix
=
[[
basis
[
degree
].
subs
(
x
,
points
[
point
])
for
point
in
range
(
num_points
)]
for
degree
in
range
(
self
.
_
polynomial_degree
+
1
)]
for
degree
in
range
(
polynomial_degree
+
1
)]
approx
=
[[
sum
(
projection
[
degree
][
cell
]
*
basis_matrix
[
degree
][
point
]
approx
=
[[
sum
(
projection
[
degree
][
cell
]
*
basis_matrix
[
degree
][
point
]
for
degree
in
range
(
self
.
_
polynomial_degree
+
1
))
for
degree
in
range
(
polynomial_degree
+
1
))
for
point
in
range
(
num_points
)]
for
point
in
range
(
num_points
)]
for
cell
in
range
(
len
(
projection
[
0
]))]
for
cell
in
range
(
len
(
projection
[
0
]))]
...
@@ -295,7 +295,7 @@ class WaveletDetector(TroubledCellDetector):
...
@@ -295,7 +295,7 @@ class WaveletDetector(TroubledCellDetector):
def
_plot_mesh
(
self
,
projection
):
def
_plot_mesh
(
self
,
projection
):
grid
,
exact
=
self
.
_calculate_exact_solution
(
self
.
_mesh
[
2
:
-
2
],
self
.
_cell_len
)
grid
,
exact
=
self
.
_calculate_exact_solution
(
self
.
_mesh
[
2
:
-
2
],
self
.
_cell_len
)
approx
=
self
.
_
calculate_approximate_solution
(
projection
[:,
1
:
-
1
])
approx
=
self
.
calculate_approximate_solution
(
projection
[:,
1
:
-
1
]
,
self
.
_quadrature
,
self
.
_polynomial_degree
)
pointwise_error
=
np
.
abs
(
exact
-
approx
)
pointwise_error
=
np
.
abs
(
exact
-
approx
)
max_error
=
np
.
max
(
pointwise_error
)
max_error
=
np
.
max
(
pointwise_error
)
...
@@ -327,7 +327,7 @@ class WaveletDetector(TroubledCellDetector):
...
@@ -327,7 +327,7 @@ class WaveletDetector(TroubledCellDetector):
# Plot exact and approximate solutions for coarse mesh
# Plot exact and approximate solutions for coarse mesh
grid
,
exact
=
self
.
_calculate_exact_solution
(
coarse_mesh
[
1
:
-
1
],
coarse_cell_len
)
grid
,
exact
=
self
.
_calculate_exact_solution
(
coarse_mesh
[
1
:
-
1
],
coarse_cell_len
)
approx
=
self
.
_
calculate_approximate_solution
(
coarse_projection
)
approx
=
self
.
calculate_approximate_solution
(
coarse_projection
,
self
.
_quadrature
,
self
.
_polynomial_degree
)
self
.
_plot_solution_and_approx
(
grid
,
exact
,
approx
,
self
.
_colors
[
'
coarse_exact
'
],
self
.
_colors
[
'
coarse_approx
'
])
self
.
_plot_solution_and_approx
(
grid
,
exact
,
approx
,
self
.
_colors
[
'
coarse_exact
'
],
self
.
_colors
[
'
coarse_approx
'
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment