Skip to content
Snippets Groups Projects
Commit 2e17d521 authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Outsourced run command for SM rule 'approximate_solution' into script.

parent 9b0bacf0
Branches
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
"""Script to approximate solution with Discontinuous Galerkin.
@author: Laura C. Kühle
"""
import sys
import time
from tcd.DG_Approximation import DGScheme
def main() -> None:
"""Approximate solution."""
with open(str(snakemake.log[0]), 'w', encoding='utf-8') as logfile:
sys.stdout = logfile
sys.stderr = logfile
tic = time.perf_counter()
if len(snakemake.input) > 0:
snakemake.params['dg_params']['detector_config']['model_state'] = \
snakemake.input[0]
print(snakemake.params['dg_params'])
dg_scheme = DGScheme(**snakemake.params['dg_params'])
dg_scheme.approximate(
data_file=snakemake.params['plot_dir'] + '/' +
snakemake.wildcards['scheme'])
toc = time.perf_counter()
print(f'Time: {toc-tic:0.4f}s')
if __name__ == '__main__':
if "snakemake" in locals():
main()
else:
print('Not Defined.')
...@@ -3,21 +3,22 @@ import time ...@@ -3,21 +3,22 @@ import time
from scripts.tcd import Initial_Condition from scripts.tcd import Initial_Condition
from scripts.tcd import Quadrature from scripts.tcd import Quadrature
from scripts.tcd.DG_Approximation import DGScheme
from scripts.tcd.Plotting import plot_approximation_results from scripts.tcd.Plotting import plot_approximation_results
configfile: 'config.yaml' configfile: 'config.yaml'
PLOTS = ['error', 'exact_and_approx', 'semilog_error', 'shock_tube'] PLOTS = ['error', 'exact_and_approx', 'semilog_error', 'shock_tube']
DIR = config['data_dir'] DIR = config['data_dir']
SCHEMES = config['schemes'] SCHEMES = config['schemes']
rule all: rule all:
input: input:
expand(DIR + '/fig/{plot}/{scheme}.pdf', plot=PLOTS, expand(DIR + '/fig/{plot}/{scheme}.pdf', plot=PLOTS, scheme=SCHEMES)
scheme=SCHEMES)
default_target: True default_target: True
def get_ANN_model(wildcards): def get_ANN_model(wildcards):
if config['schemes'][wildcards.scheme]['detector'] == \ if config['schemes'][wildcards.scheme]['detector'] == \
'ArtificialNeuralNetwork': 'ArtificialNeuralNetwork':
...@@ -25,6 +26,7 @@ def get_ANN_model(wildcards): ...@@ -25,6 +26,7 @@ def get_ANN_model(wildcards):
wildcards.scheme]['detector_config']['model_state'] wildcards.scheme]['detector_config']['model_state']
return [] return []
rule approximate_solution: rule approximate_solution:
input: input:
get_ANN_model get_ANN_model
...@@ -35,24 +37,9 @@ rule approximate_solution: ...@@ -35,24 +37,9 @@ rule approximate_solution:
plot_dir = DIR + '/fig' plot_dir = DIR + '/fig'
log: log:
DIR+'/log/approximate_solution/{scheme}.log' DIR+'/log/approximate_solution/{scheme}.log'
run: script:
with open(str(log), 'w') as logfile: '../scripts/approximate_solution.py'
sys.stdout = logfile
sys.stderr = logfile
tic = time.perf_counter()
if len(input) > 0:
params.dg_params['detector_config']['model_state'] = input
print(params.dg_params)
dg_scheme = DGScheme(**params.dg_params)
dg_scheme.approximate(
data_file=params.plot_dir+'/'+wildcards.scheme)
toc = time.perf_counter()
print(f'Time: {toc - tic:0.4f}s')
rule plot_approximation_results: rule plot_approximation_results:
input: input:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment