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
cc96e216
Commit
cc96e216
authored
Oct 18, 2020
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Improved plot saving. Added option to set plot directory.
parent
26f57a85
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
-47
3 additions, 47 deletions
DG_Approximation.py
Troubled_Cell_Detector.py
+44
-0
44 additions, 0 deletions
Troubled_Cell_Detector.py
with
47 additions
and
47 deletions
DG_Approximation.py
+
3
−
47
View file @
cc96e216
...
...
@@ -12,7 +12,8 @@ TODO: Write documentation for all methods
TODO: Contemplate moving basis/wavelet matrices to Vectors_of_Polynomials
TODO: Contemplate how to make shock tubes comparable
TODO: Improve saving of plots
TODO: Improve saving of plots -> Done (moved to Troubled_Cell_Detector)
TODO: Added option to set plot directory -> Done
TODO: Extend color options
TODO: Implement type check for all kwargs and configs
TODO: Add option to not save plots
...
...
@@ -20,9 +21,7 @@ TODO: Add option to not save plots
"""
import
numpy
as
np
from
sympy
import
Symbol
,
integrate
import
os
import
math
import
timeit
import
matplotlib.pyplot
as
plt
import
Troubled_Cell_Detector
...
...
@@ -135,52 +134,9 @@ class DGScheme(object):
+
str
(
self
.
_final_time
)
+
'
__wave_speed_
'
+
str
(
self
.
_wave_speed
)
+
'
__number_of_cells_
'
\
+
str
(
self
.
_num_grid_cells
)
+
'
__polynomial_degree_
'
+
str
(
self
.
_polynom_degree
)
save_fig_1
=
True
if
save_fig_1
:
plt
.
figure
(
1
)
plt
.
savefig
(
'
testfig/exact_and_approx/
'
+
name
+
'
.pdf
'
)
# plt.clf()
save_fig_2
=
True
if
save_fig_2
:
plt
.
figure
(
2
)
plt
.
savefig
(
'
testfig/semilog_error/
'
+
name
+
'
.pdf
'
)
save_fig_3
=
True
if
save_fig_3
:
plt
.
figure
(
3
)
plt
.
savefig
(
'
testfig/error/
'
+
name
+
'
.pdf
'
)
save_fig_4
=
False
if
save_fig_4
:
plt
.
figure
(
4
)
plt
.
savefig
(
'
testfig/coeff_details/
'
+
name
+
'
.pdf
'
)
save_fig_6
=
True
if
save_fig_6
:
plt
.
figure
(
6
)
plt
.
savefig
(
'
testfig/shock_tube/
'
+
name
+
'
.pdf
'
)
self
.
_detector
.
save_plots
(
name
)
def
_reset
(
self
):
# Set paths for plot files if not existing already
if
not
os
.
path
.
exists
(
'
testfig
'
):
os
.
makedirs
(
'
testfig
'
)
if
not
os
.
path
.
exists
(
'
testfig/exact_and_approx
'
):
os
.
makedirs
(
'
testfig/exact_and_approx
'
)
if
not
os
.
path
.
exists
(
'
testfig/semilog_error
'
):
os
.
makedirs
(
'
testfig/semilog_error
'
)
if
not
os
.
path
.
exists
(
'
testfig/error
'
):
os
.
makedirs
(
'
testfig/error
'
)
if
not
os
.
path
.
exists
(
'
testfig/coeff_details
'
):
os
.
makedirs
(
'
testfig/coeff_details
'
)
if
not
os
.
path
.
exists
(
'
testfig/shock_tube
'
):
os
.
makedirs
(
'
testfig/shock_tube
'
)
# Set additional necessary instance variables
self
.
_interval_len
=
self
.
_right_bound
-
self
.
_left_bound
self
.
_cell_len
=
self
.
_interval_len
/
self
.
_num_grid_cells
...
...
This diff is collapsed.
Click to expand it.
Troubled_Cell_Detector.py
+
44
−
0
View file @
cc96e216
...
...
@@ -6,6 +6,7 @@ TODO: Check cutoff_factor/whether _is_troubled_cell works correctly \
-> Discuss! -> Seems alright; check paper (Siegfried Müller, Nils Gerhard?)
"""
import
os
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
sympy
import
Symbol
,
integrate
...
...
@@ -32,6 +33,9 @@ class TroubledCellDetector(object):
self
.
_init_cond
=
init_cond
self
.
_quadrature
=
quadrature
# Set plot directory from config if existing
self
.
_plot_dir
=
config
.
pop
(
'
plot_dir
'
,
'
fig
'
)
self
.
_reset
(
config
)
def
_reset
(
self
,
config
):
...
...
@@ -136,6 +140,36 @@ class TroubledCellDetector(object):
return
np
.
reshape
(
np
.
array
(
approx
),
(
1
,
len
(
approx
)
*
num_points
))
def
save_plots
(
self
,
name
):
# Set paths for plot files if not existing already
if
not
os
.
path
.
exists
(
self
.
_plot_dir
):
os
.
makedirs
(
self
.
_plot_dir
)
if
not
os
.
path
.
exists
(
self
.
_plot_dir
+
'
/exact_and_approx
'
):
os
.
makedirs
(
self
.
_plot_dir
+
'
/exact_and_approx
'
)
if
not
os
.
path
.
exists
(
self
.
_plot_dir
+
'
/semilog_error
'
):
os
.
makedirs
(
self
.
_plot_dir
+
'
/semilog_error
'
)
if
not
os
.
path
.
exists
(
self
.
_plot_dir
+
'
/error
'
):
os
.
makedirs
(
self
.
_plot_dir
+
'
/error
'
)
if
not
os
.
path
.
exists
(
self
.
_plot_dir
+
'
/shock_tube
'
):
os
.
makedirs
(
self
.
_plot_dir
+
'
/shock_tube
'
)
# Save plots
plt
.
figure
(
1
)
plt
.
savefig
(
self
.
_plot_dir
+
'
/exact_and_approx/
'
+
name
+
'
.pdf
'
)
plt
.
figure
(
2
)
plt
.
savefig
(
self
.
_plot_dir
+
'
/semilog_error/
'
+
name
+
'
.pdf
'
)
plt
.
figure
(
3
)
plt
.
savefig
(
self
.
_plot_dir
+
'
/error/
'
+
name
+
'
.pdf
'
)
plt
.
figure
(
6
)
plt
.
savefig
(
self
.
_plot_dir
+
'
/shock_tube/
'
+
name
+
'
.pdf
'
)
class
NoDetection
(
TroubledCellDetector
):
def
get_cells
(
self
,
projection
):
...
...
@@ -289,6 +323,16 @@ class WaveletDetector(TroubledCellDetector):
return
max_error
def
save_plots
(
self
,
name
):
super
().
save_plots
(
name
)
# Set path for details plot files if not existing already
if
not
os
.
path
.
exists
(
self
.
_plot_dir
+
'
/coeff_details
'
):
os
.
makedirs
(
self
.
_plot_dir
+
'
/coeff_details
'
)
plt
.
figure
(
4
)
plt
.
savefig
(
self
.
_plot_dir
+
'
/coeff_details/
'
+
name
+
'
.pdf
'
)
def
_plot_coarse_mesh
(
self
,
projection
,
color_exact
,
color_approx
):
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
),
...
...
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