Commit ed04b1e6 authored by lisawim's avatar lisawim
Browse files

Fixed flake8 issues

parent b5a6f3ca
......@@ -2,7 +2,6 @@ import itertools
import copy as cp
import numpy as np
import dill
import scipy
from pySDC.core.Controller import controller
from pySDC.core import Step as stepclass
......
......@@ -27,17 +27,18 @@ class log_data(hooks):
sweep=L.status.sweep, type='current L', value=L.uend[0])
self.add_to_stats(process=step.status.slot, time=L.time, level=L.level_index, iter=0,
sweep=L.status.sweep, type='voltage C', value=L.uend[1])
def main():
"""
A simple test program to do SDC/PFASST runs for the battery drain model
"""
# initialize level parameters
level_params = dict()
level_params['restol'] = 1E-10
level_params['dt'] = 1E-3
# initialize sweeper parameters
sweeper_params = dict()
sweeper_params['collocation_class'] = Collocation
......@@ -46,7 +47,7 @@ def main():
sweeper_params['num_nodes'] = 5
sweeper_params['QI'] = 'LU' # For the IMEX sweeper, the LU-trick can be activated for the implicit part
sweeper_params['initial_guess'] = 'zero'
# initialize problem parameters
problem_params = dict()
problem_params['Vs'] = 5.0
......@@ -65,7 +66,7 @@ def main():
controller_params = dict()
controller_params['logger_level'] = 20
controller_params['hook_class'] = log_data
# fill description dictionary for easy step instantiation
description = dict()
description['problem_class'] = battery # pass problem class
......@@ -78,33 +79,33 @@ def main():
assert 'errtol' not in description['step_params'].keys(), 'No exact solution known to compute error'
assert 'alpha' in description['problem_params'].keys(), 'Please supply "alpha" in the problem parameters'
assert 'V_ref' in description['problem_params'].keys(), 'Please supply "V_ref" in the problem parameters'
# set time parameters
t0 = 0.0
Tend = 2.4
# instantiate controller
controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description)
# get initial values on finest level
P = controller.MS[0].levels[0].prob
uinit = P.u_exact(t0)
# call main function to get things done...
uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend)
# fname = 'data/battery.dat'
fname = 'battery.dat'
f = open(fname, 'wb')
dill.dump(stats, f)
f.close()
# filter statistics by type (number of iterations)
filtered_stats = filter_stats(stats, type='niter')
# convert filtered statistics to list of iterations count, sorted by process
iter_counts = sort_stats(filtered_stats, sortby='time')
# compute and print statistics
min_iter = 20
max_iter = 0
......@@ -126,6 +127,7 @@ def main():
plot_voltages()
def plot_voltages(cwd='./'):
"""
Routine to plot the numerical solution of the model
......@@ -150,9 +152,8 @@ def plot_voltages(cwd='./'):
ax.set_xlabel('Time')
ax.set_ylabel('Energy')
#ax.show()
#fig.savefig('data/battery_model_solution.png', dpi=300, bbox_inches='tight')
fig.savefig('battery_model_solution.png', dpi=300, bbox_inches='tight')
fig.savefig('data/battery_model_solution.png', dpi=300, bbox_inches='tight')
if __name__ == "__main__":
main()
......@@ -30,7 +30,7 @@ def main():
# initialize problem parameters
problem_params = dict()
problem_params['duty'] = 0.5 # duty cycle
problem_params['duty'] = 0.5 # duty cycle
problem_params['fsw'] = 1e3 # switching freqency
problem_params['Vs'] = 10.0
problem_params['Rs'] = 0.5
......@@ -110,6 +110,7 @@ def main():
plot_voltages()
def plot_voltages(cwd='./'):
f = open(cwd + 'buck.dat', 'rb')
stats = dill.load(f)
......@@ -132,9 +133,8 @@ def plot_voltages(cwd='./'):
ax.set_xlabel('Time')
ax.set_ylabel('Energy')
#ax.show()
#fig.savefig('data/buck_model_solution.png', dpi=300, bbox_inches='tight')
fig.savefig('buck_model_solution.png', dpi=300, bbox_inches='tight')
fig.savefig('data/buck_model_solution.png', dpi=300, bbox_inches='tight')
if __name__ == "__main__":
main()
......@@ -86,8 +86,7 @@ def main():
Tend = 20
# instantiate controller
controller = controller_nonMPI(num_procs=1, controller_params=controller_params,
description=description)
controller = controller_nonMPI(num_procs=1, controller_params=controller_params, description=description)
# get initial values on finest level
P = controller.MS[0].levels[0].prob
......@@ -128,6 +127,7 @@ def main():
plot_voltages()
def plot_voltages(cwd='./'):
f = open(cwd + 'piline.dat', 'rb')
stats = dill.load(f)
......@@ -152,26 +152,26 @@ def plot_voltages(cwd='./'):
ax.set_xlabel('Time')
ax.set_ylabel('Energy')
#ax.show()
#fig.savefig('data/piline_model_solution.png', dpi=300, bbox_inches='tight')
fig.savefig('piline_model_solution.png', dpi=300, bbox_inches='tight')
fig.savefig('data/piline_model_solution.png', dpi=300, bbox_inches='tight')
def setup_mpl(fontsize=8):
plt_helper.setup_mpl(reset=True)
style_options = {
"font.family": "sans-serif",
"font.serif": "Computer Modern Sans Serif",
"font.serif": "Computer Modern Sans Serif",
"font.sans-serif": "Computer Modern Sans Serif",
"font.monospace": "Computer Modern Sans Serif",
"axes.labelsize": 12, # LaTeX default is 10pt font.
"legend.fontsize": 13, # Make the legend/label fonts a little smaller
"axes.xmargin": 0.03,
"axes.ymargin": 0.03,
"lines.linewidth": 1, # Make the plot lines a little smaller
"lines.linewidth": 1, # Make the plot lines a little smaller
}
mpl.rcParams.update(style_options)
if __name__ == "__main__":
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment