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
440409e2
Commit
440409e2
authored
3 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Added saving of approximation data.
parent
a7470ccc
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
+44
-6
44 additions, 6 deletions
DG_Approximation.py
workflows/approximation.smk
+1
-1
1 addition, 1 deletion
workflows/approximation.smk
with
45 additions
and
7 deletions
DG_Approximation.py
+
44
−
6
View file @
440409e2
...
...
@@ -3,13 +3,13 @@
@author: Laura C. Kühle
Urgent:
TODO: Add way of saving data (np.savez(
'
data/
'
+ name,
coefficients=projection, troubled_cells=troubled_cells)) -> Done
TODO: Move plotting into separate function
TODO: Adapt TCD from Soraya
(Dropbox->...->TEST_troubled-cell-detector->Troubled_Cell_Detector)
TODO: Add way of saving data (np.savez(
'
data/
'
+ name,
coefficients=projection, troubled_cells=troubled_cells) )
TODO: Add verbose output
TODO: Improve file naming (e.g. use
'
.
'
instead of
'
__
'
)
TODO: Move plotting into separate function
Critical, but not urgent:
TODO: Use cfl_number for updating, not just time
...
...
@@ -36,6 +36,7 @@ TODO: Add type annotations to function heads
"""
import
os
import
json
import
numpy
as
np
from
sympy
import
Symbol
import
math
...
...
@@ -53,6 +54,18 @@ matplotlib.use('Agg')
x
=
Symbol
(
'
x
'
)
def
encode_ndarray
(
obj
):
if
isinstance
(
obj
,
np
.
ndarray
):
return
obj
.
tolist
()
return
obj
def
decode_ndarray
(
obj
):
if
isinstance
(
obj
,
list
):
return
np
.
asarray
(
obj
)
return
obj
class
DGScheme
:
"""
Class for Discontinuous Galerkin Method.
...
...
@@ -190,7 +203,7 @@ class DGScheme:
self
.
_polynomial_degree
,
self
.
_num_grid_cells
,
self
.
_detector
,
self
.
_limiter
)
def
approximate
(
self
):
def
approximate
(
self
,
data_name
):
"""
Approximates projection.
Initializes projection and evolves it in time. Each time step consists
...
...
@@ -200,6 +213,11 @@ class DGScheme:
At final time, result and error plots are
generated and, if verbose flag is set, also displayed.
Attributes
----------
data_name : str
Name of data.
"""
projection
=
self
.
_do_initial_projection
(
self
.
_init_cond
)
...
...
@@ -227,10 +245,30 @@ class DGScheme:
current_time
+=
time_step
# Save approximation results in dictionary
approx_stats
=
{
'
projection
'
:
projection
,
'
time_history
'
:
time_history
,
'
troubled_cell_history
'
:
troubled_cell_history
}
# Encode all ndarrays to fit JSON format
approx_stats
=
{
key
:
encode_ndarray
(
approx_stats
[
key
])
for
key
in
approx_stats
.
keys
()}
# Save approximation results in JSON format
with
open
(
self
.
_plot_dir
+
'
/
'
+
data_name
+
'
.json
'
,
'
w
'
)
\
as
json_file
:
json_file
.
write
(
json
.
dumps
(
approx_stats
))
# Read approximation results
with
open
(
self
.
_plot_dir
+
'
/
'
+
data_name
+
'
.json
'
)
as
json_file
:
approx_stats
=
json
.
load
(
json_file
)
# Decode all ndarrays by converting lists
approx_stats
=
{
key
:
decode_ndarray
(
approx_stats
[
key
])
for
key
in
approx_stats
.
keys
()}
# Plot exact/approximate results, errors, shock tubes,
# and any detector-dependant plots
self
.
_detector
.
plot_results
(
projection
,
troubled_cell_history
,
time_history
)
self
.
_detector
.
plot_results
(
**
approx_stats
)
def
save_plots
(
self
,
plot_name
):
"""
Saves plotted results.
...
...
This diff is collapsed.
Click to expand it.
workflows/approximation.smk
+
1
−
1
View file @
440409e2
...
...
@@ -48,7 +48,7 @@ rule approximate_solution:
print(params.dg_params)
dg_scheme = DGScheme(plot_dir=params.plot_dir, **params.dg_params)
dg_scheme.approximate()
dg_scheme.approximate(
wildcards.scheme
)
dg_scheme.save_plots(wildcards.scheme)
toc = time.perf_counter()
...
...
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