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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Christine Kühle
Troubled Cell Detection
Commits
6b87e5d0
Commit
6b87e5d0
authored
3 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Moved plotting into separate function.
parent
78553b35
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
DG_Approximation.py
+29
-29
29 additions, 29 deletions
DG_Approximation.py
config.yaml
+6
-6
6 additions, 6 deletions
config.yaml
workflows/approximation.smk
+5
-4
5 additions, 4 deletions
workflows/approximation.smk
with
40 additions
and
39 deletions
DG_Approximation.py
+
29
−
29
View file @
6b87e5d0
...
...
@@ -3,7 +3,8 @@
@author: Laura C. Kühle
Urgent:
TODO: Move plotting into separate function
TODO: Move plotting into separate function -> Done
TODO: Move plotting into separate rule
TODO: Adapt TCD from Soraya
(Dropbox->...->TEST_troubled-cell-detector->Troubled_Cell_Detector)
TODO: Add verbose output
...
...
@@ -201,22 +202,19 @@ class DGScheme:
self
.
_polynomial_degree
,
self
.
_num_grid_cells
,
self
.
_detector
,
self
.
_limiter
)
def
approximate
(
self
,
data_
dir
,
data_nam
e
):
def
approximate
(
self
,
data_
fil
e
):
"""
Approximates projection.
Initializes projection and evolves it in time. Each time step consists
of three parts: A projection update, a troubled-cell detection,
and limiting based on the detected cells.
At final time, result and error plots are
generated and, if verbose flag is set, also displayed.
At final time, results are saved in JSON file.
Attributes
----------
data_dir: str
Path to directory in which data is saved.
data_name : str
Name of data.
data_file: str
Path to file in which data will be saved.
"""
projection
=
self
.
_do_initial_projection
(
self
.
_init_cond
)
...
...
@@ -254,12 +252,28 @@ class DGScheme:
for
key
in
approx_stats
.
keys
()}
# Save approximation results in JSON format
with
open
(
data_
dir
+
'
/
'
+
data_nam
e
+
'
.json
'
,
'
w
'
)
\
with
open
(
data_
fil
e
+
'
.json
'
,
'
w
'
)
\
as
json_file
:
json_file
.
write
(
json
.
dumps
(
approx_stats
))
def
plot_approximation_results
(
self
,
data_file
,
directory
,
plot_name
):
"""
Plots given approximation results.
Generates plots based on given data, sets plot directory if not
already existing, and saves plots.
Parameters
----------
data_file: str
Path to data file for plotting.
directory: str
Path to directory in which plots will be saved.
plot_name : str
Name of plot.
"""
# Read approximation results
with
open
(
data_
dir
+
'
/
'
+
data_nam
e
+
'
.json
'
)
as
json_file
:
with
open
(
data_
fil
e
+
'
.json
'
)
as
json_file
:
approx_stats
=
json
.
load
(
json_file
)
# Decode all ndarrays by converting lists
...
...
@@ -270,32 +284,18 @@ class DGScheme:
# and any detector-dependant plots
self
.
_detector
.
plot_results
(
**
approx_stats
)
def
save_plots
(
self
,
plot_dir
,
plot_name
):
"""
Saves plotted results.
Sets plot directory, if not already existing, and saves plots
generated during the last approximation.
Parameters
----------
plot_dir: str
Path to directory in which plots are saved.
plot_name : str
Name of plot.
"""
# Set paths for plot files if not existing already
if
not
os
.
path
.
exists
(
plot_dir
):
os
.
makedirs
(
plot_dir
)
if
not
os
.
path
.
exists
(
directory
):
os
.
makedirs
(
directory
)
# Save plots
for
identifier
in
plt
.
get_figlabels
():
# Set path for figure directory if not existing already
if
not
os
.
path
.
exists
(
plot_dir
+
'
/
'
+
identifier
):
os
.
makedirs
(
plot_dir
+
'
/
'
+
identifier
)
if
not
os
.
path
.
exists
(
directory
+
'
/
'
+
identifier
):
os
.
makedirs
(
directory
+
'
/
'
+
identifier
)
plt
.
figure
(
identifier
)
plt
.
savefig
(
plot_dir
+
'
/
'
+
identifier
+
'
/
'
+
plt
.
savefig
(
directory
+
'
/
'
+
identifier
+
'
/
'
+
plot_name
+
'
.pdf
'
)
def
_reset
(
self
):
...
...
This diff is collapsed.
Click to expand it.
config.yaml
+
6
−
6
View file @
6b87e5d0
data_dir
:
'
model-
Soraya_
Mar
02
'
data_dir
:
'
model-Mar
14
'
random_seed
:
1234
# Parameter for Approximation with Troubled Cell Detection
Approximation
:
plot_dir
:
'
fig-
Soraya_
Mar
02
'
plot_dir
:
'
fig-Mar
14
'
schemes
:
Separation_Test
:
...
...
@@ -21,7 +21,7 @@ Approximation:
detector_config
:
fold_len
:
16
whisker_len
:
3
add_reconstructions
:
Fals
e
add_reconstructions
:
Tru
e
model_state
:
'
Adam.model.pt'
init_cond
:
'
Sine'
...
...
@@ -52,7 +52,7 @@ ANN_Data:
smooth_troubled_balance
:
0.5
stencil_length
:
3
add_reconstructions
:
Fals
e
add_reconstructions
:
Tru
e
# Initial Conditions for Training Data
functions
:
...
...
@@ -87,7 +87,7 @@ ANN_Training:
threshold
:
1.0e-5
batch_size
:
500
model
:
ThreeLayerReLu
model_config
:
{
input_size
:
3
}
model_config
:
{}
loss_function
:
BCELoss
optimizer
:
Adam
SGD
:
...
...
@@ -95,7 +95,7 @@ ANN_Training:
threshold
:
1.0e-5
batch_size
:
500
model
:
ThreeLayerReLu
model_config
:
{
input_size
:
3
}
model_config
:
{}
loss_function
:
BCELoss
optimizer
:
SGD
...
...
This diff is collapsed.
Click to expand it.
workflows/approximation.smk
+
5
−
4
View file @
6b87e5d0
...
...
@@ -48,10 +48,11 @@ rule approximate_solution:
print(params.dg_params)
dg_scheme = DGScheme(**params.dg_params)
dg_scheme.approximate(data_dir=params.plot_dir,
data_name=wildcards.scheme)
dg_scheme.save_plots(plot_dir=params.plot_dir,
plot_name=wildcards.scheme)
dg_scheme.approximate(
data_file=params.plot_dir+'/'+wildcards.scheme)
dg_scheme.plot_approximation_results(directory=params.plot_dir,
plot_name=wildcards.scheme,
data_file=params.plot_dir+'/'+wildcards.scheme)
toc = time.perf_counter()
print(f'Time: {toc - tic:0.4f}s')
\ No newline at end of file
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