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
af5c6294
Commit
af5c6294
authored
Oct 18, 2020
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Extended color options.
parent
cc96e216
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
DG_Approximation.py
+3
-3
3 additions, 3 deletions
DG_Approximation.py
Troubled_Cell_Detector.py
+24
-12
24 additions, 12 deletions
Troubled_Cell_Detector.py
with
27 additions
and
15 deletions
DG_Approximation.py
+
3
−
3
View file @
af5c6294
...
@@ -14,9 +14,9 @@ TODO: Contemplate moving basis/wavelet matrices to Vectors_of_Polynomials
...
@@ -14,9 +14,9 @@ TODO: Contemplate moving basis/wavelet matrices to Vectors_of_Polynomials
TODO: Contemplate how to make shock tubes comparable
TODO: Contemplate how to make shock tubes comparable
TODO: Improve saving of plots -> Done (moved to Troubled_Cell_Detector)
TODO: Improve saving of plots -> Done (moved to Troubled_Cell_Detector)
TODO: Added option to set plot directory -> Done
TODO: Added option to set plot directory -> Done
TODO: Extend color options
TODO: Extend color options
-> Done
TODO: Implement type check for all kwargs and configs
TODO: Implement type check for all kwargs and configs
TODO: Add option to not save plots
TODO: Add option to not save plots
-> Done (not call function in Main)
"""
"""
import
numpy
as
np
import
numpy
as
np
...
@@ -123,7 +123,7 @@ class DGScheme(object):
...
@@ -123,7 +123,7 @@ class DGScheme(object):
current_time
+=
time_step
current_time
+=
time_step
# Plot exact/approximate results, errors, shock tubes and any detector-dependant plots
# Plot exact/approximate results, errors, shock tubes and any detector-dependant plots
self
.
_detector
.
plot_results
(
projection
,
troubled_cell_history
,
time_history
,
'
k-
'
,
'
y
'
)
self
.
_detector
.
plot_results
(
projection
,
troubled_cell_history
,
time_history
)
if
self
.
_verbose
:
if
self
.
_verbose
:
plt
.
show
()
plt
.
show
()
...
...
This diff is collapsed.
Click to expand it.
Troubled_Cell_Detector.py
+
24
−
12
View file @
af5c6294
...
@@ -33,11 +33,17 @@ class TroubledCellDetector(object):
...
@@ -33,11 +33,17 @@ class TroubledCellDetector(object):
self
.
_init_cond
=
init_cond
self
.
_init_cond
=
init_cond
self
.
_quadrature
=
quadrature
self
.
_quadrature
=
quadrature
# Set p
lot directory
from config if existing
# Set p
arameters
from config if existing
self
.
_plot_dir
=
config
.
pop
(
'
plot_dir
'
,
'
fig
'
)
self
.
_plot_dir
=
config
.
pop
(
'
plot_dir
'
,
'
fig
'
)
self
.
_colors
=
config
.
pop
(
'
colors
'
,
{})
self
.
_check_colors
()
self
.
_reset
(
config
)
self
.
_reset
(
config
)
def
_check_colors
(
self
):
self
.
_colors
[
'
exact
'
]
=
self
.
_colors
.
get
(
'
exact
'
,
'
k-
'
)
self
.
_colors
[
'
approx
'
]
=
self
.
_colors
.
get
(
'
approx
'
,
'
y
'
)
def
_reset
(
self
,
config
):
def
_reset
(
self
,
config
):
pass
pass
...
@@ -47,9 +53,9 @@ class TroubledCellDetector(object):
...
@@ -47,9 +53,9 @@ class TroubledCellDetector(object):
def
get_cells
(
self
,
projection
):
def
get_cells
(
self
,
projection
):
pass
pass
def
plot_results
(
self
,
projection
,
troubled_cell_history
,
time_history
,
color_exact
,
color_approx
):
def
plot_results
(
self
,
projection
,
troubled_cell_history
,
time_history
):
self
.
_plot_shock_tube
(
troubled_cell_history
,
time_history
)
self
.
_plot_shock_tube
(
troubled_cell_history
,
time_history
)
max_error
=
self
.
_plot_mesh
(
projection
,
color_exact
,
color_approx
)
max_error
=
self
.
_plot_mesh
(
projection
)
print
(
"
p =
"
,
self
.
_polynom_degree
)
print
(
"
p =
"
,
self
.
_polynom_degree
)
print
(
"
N =
"
,
self
.
_num_grid_cells
)
print
(
"
N =
"
,
self
.
_num_grid_cells
)
...
@@ -66,14 +72,14 @@ class TroubledCellDetector(object):
...
@@ -66,14 +72,14 @@ class TroubledCellDetector(object):
plt
.
ylabel
(
'
Time
'
)
plt
.
ylabel
(
'
Time
'
)
plt
.
title
(
'
Shock Tubes
'
)
plt
.
title
(
'
Shock Tubes
'
)
def
_plot_mesh
(
self
,
projection
,
color_exact
,
color_approx
):
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
])
pointwise_error
=
np
.
abs
(
exact
-
approx
)
pointwise_error
=
np
.
abs
(
exact
-
approx
)
max_error
=
np
.
max
(
pointwise_error
)
max_error
=
np
.
max
(
pointwise_error
)
self
.
_plot_solution_and_approx
(
grid
,
exact
,
approx
,
color
_
exact
,
color
_
approx
)
self
.
_plot_solution_and_approx
(
grid
,
exact
,
approx
,
self
.
_
color
s
[
'
exact
'
],
self
.
_
color
s
[
'
approx
'
]
)
plt
.
legend
([
'
Exact
'
,
'
Approx
'
])
plt
.
legend
([
'
Exact
'
,
'
Approx
'
])
self
.
_plot_semilog_error
(
grid
,
pointwise_error
)
self
.
_plot_semilog_error
(
grid
,
pointwise_error
)
self
.
_plot_error
(
grid
,
exact
,
approx
)
self
.
_plot_error
(
grid
,
exact
,
approx
)
...
@@ -177,6 +183,12 @@ class NoDetection(TroubledCellDetector):
...
@@ -177,6 +183,12 @@ class NoDetection(TroubledCellDetector):
class
WaveletDetector
(
TroubledCellDetector
):
class
WaveletDetector
(
TroubledCellDetector
):
def
_check_colors
(
self
):
self
.
_colors
[
'
fine_exact
'
]
=
self
.
_colors
.
get
(
'
fine_exact
'
,
'
k-.
'
)
self
.
_colors
[
'
fine_approx
'
]
=
self
.
_colors
.
get
(
'
fine_approx
'
,
'
b-.
'
)
self
.
_colors
[
'
coarse_exact
'
]
=
self
.
_colors
.
get
(
'
coarse_exact
'
,
'
k-
'
)
self
.
_colors
[
'
coarse_approx
'
]
=
self
.
_colors
.
get
(
'
coarse_approx
'
,
'
y
'
)
def
_reset
(
self
,
config
):
def
_reset
(
self
,
config
):
# Set fixed basis and wavelet vectors
# Set fixed basis and wavelet vectors
self
.
_basis
=
OrthonormalLegendre
(
self
.
_polynom_degree
).
get_vector
(
x
)
self
.
_basis
=
OrthonormalLegendre
(
self
.
_polynom_degree
).
get_vector
(
x
)
...
@@ -214,9 +226,9 @@ class WaveletDetector(TroubledCellDetector):
...
@@ -214,9 +226,9 @@ class WaveletDetector(TroubledCellDetector):
def
_get_cells
(
self
,
multiwavelet_coeffs
,
projection
):
def
_get_cells
(
self
,
multiwavelet_coeffs
,
projection
):
return
[]
return
[]
def
plot_results
(
self
,
projection
,
troubled_cell_history
,
time_history
,
color_exact
,
color_approx
):
def
plot_results
(
self
,
projection
,
troubled_cell_history
,
time_history
):
self
.
_plot_details
(
projection
)
self
.
_plot_details
(
projection
)
super
().
plot_results
(
projection
,
troubled_cell_history
,
time_history
,
color_exact
,
color_approx
)
super
().
plot_results
(
projection
,
troubled_cell_history
,
time_history
)
def
_plot_details
(
self
,
projection
):
def
_plot_details
(
self
,
projection
):
fine_mesh
=
self
.
_mesh
[
2
:
-
2
]
fine_mesh
=
self
.
_mesh
[
2
:
-
2
]
...
@@ -308,15 +320,15 @@ class WaveletDetector(TroubledCellDetector):
...
@@ -308,15 +320,15 @@ class WaveletDetector(TroubledCellDetector):
matrix
.
append
(
row
)
matrix
.
append
(
row
)
return
matrix
return
matrix
def
_plot_mesh
(
self
,
projection
,
color_exact
,
color_approx
):
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
])
pointwise_error
=
np
.
abs
(
exact
-
approx
)
pointwise_error
=
np
.
abs
(
exact
-
approx
)
max_error
=
np
.
max
(
pointwise_error
)
max_error
=
np
.
max
(
pointwise_error
)
self
.
_plot_coarse_mesh
(
projection
,
color_exact
,
color_approx
)
self
.
_plot_coarse_mesh
(
projection
)
self
.
_plot_solution_and_approx
(
grid
,
exact
,
approx
,
'
k-.
'
,
'
b-.
'
)
self
.
_plot_solution_and_approx
(
grid
,
exact
,
approx
,
self
.
_colors
[
'
fine_exact
'
],
self
.
_colors
[
'
fine_approx
'
]
)
plt
.
legend
([
'
Exact (Coarse)
'
,
'
Approx (Coarse)
'
,
'
Exact (Fine)
'
,
'
Approx (Fine)
'
])
plt
.
legend
([
'
Exact (Coarse)
'
,
'
Approx (Coarse)
'
,
'
Exact (Fine)
'
,
'
Approx (Fine)
'
])
self
.
_plot_semilog_error
(
grid
,
pointwise_error
)
self
.
_plot_semilog_error
(
grid
,
pointwise_error
)
self
.
_plot_error
(
grid
,
exact
,
approx
)
self
.
_plot_error
(
grid
,
exact
,
approx
)
...
@@ -333,7 +345,7 @@ class WaveletDetector(TroubledCellDetector):
...
@@ -333,7 +345,7 @@ class WaveletDetector(TroubledCellDetector):
plt
.
figure
(
4
)
plt
.
figure
(
4
)
plt
.
savefig
(
self
.
_plot_dir
+
'
/coeff_details/
'
+
name
+
'
.pdf
'
)
plt
.
savefig
(
self
.
_plot_dir
+
'
/coeff_details/
'
+
name
+
'
.pdf
'
)
def
_plot_coarse_mesh
(
self
,
projection
,
color_exact
,
color_approx
):
def
_plot_coarse_mesh
(
self
,
projection
):
coarse_cell_len
=
2
*
self
.
_cell_len
coarse_cell_len
=
2
*
self
.
_cell_len
coarse_mesh
=
np
.
arange
(
self
.
_left_bound
-
(
0.5
*
coarse_cell_len
),
self
.
_right_bound
+
(
1.5
*
coarse_cell_len
),
coarse_mesh
=
np
.
arange
(
self
.
_left_bound
-
(
0.5
*
coarse_cell_len
),
self
.
_right_bound
+
(
1.5
*
coarse_cell_len
),
coarse_cell_len
)
coarse_cell_len
)
...
@@ -343,7 +355,7 @@ class WaveletDetector(TroubledCellDetector):
...
@@ -343,7 +355,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
.
_plot_solution_and_approx
(
grid
,
exact
,
approx
,
color_exact
,
color
_approx
)
self
.
_plot_solution_and_approx
(
grid
,
exact
,
approx
,
self
.
_colors
[
'
coarse_exact
'
],
self
.
_colors
[
'
coarse
_approx
'
]
)
class
Boxplot
(
WaveletDetector
):
class
Boxplot
(
WaveletDetector
):
...
...
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