Skip to content

Commit d0fb972

Browse files
committed
GS up and running (weird output, though)
1 parent c0241fb commit d0fb972

File tree

6 files changed

+213
-114
lines changed

6 files changed

+213
-114
lines changed

examples/fenics_grayscott/playground.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import pySDC.core.deprecated.PFASST_blockwise_old as mp
22

33
from examples.fenics_grayscott.HookClass import fenics_output
4-
from examples.fenics_grayscott.ProblemClass import fenics_grayscott
54
from examples.fenics_grayscott.TransferClass import mesh_to_mesh_fenics
6-
from pySDC.implementations.datatype_classes.fenics_mesh import fenics_mesh
7-
from pySDC.implementations.sweeper_classes.generic_LU import generic_LU
85
from pySDC.core import CollocationClasses as collclass
96
from pySDC.core import Log
7+
from pySDC.implementations.datatype_classes.fenics_mesh import fenics_mesh
8+
from pySDC.implementations.problem_classes.ProblemClass import fenics_grayscott
9+
from pySDC.implementations.sweeper_classes.generic_LU import generic_LU
1010

1111
if __name__ == "__main__":
1212

projects/node_failure/grayscott_example.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
2-
from pySDC.core import CollocationClasses as collclass
3-
4-
from examples.fenics_grayscott.ProblemClass import fenics_grayscott
1+
import numpy as np
2+
import pySDC.core.PFASST_stepwise as mp
3+
import pySDC.helpers.fault_tolerance as ft
4+
from pySDC.core.Stats import grep_stats
55
from pySDC.core.datatype_classes.fenics_mesh import fenics_mesh
6-
from examples.fenics_grayscott.TransferClass import mesh_to_mesh_fenics
7-
# from examples.fenics_grayscott.HookClass import fenics_output
86
from pySDC.core.sweeper_classes.generic_LU import generic_LU
9-
# import pySDC.PFASST_blockwise as mp
10-
import pySDC.core.PFASST_stepwise as mp
11-
from pySDC.core import Log
12-
from pySDC.core.Stats import grep_stats, sort_stats
13-
14-
import dolfin as df
15-
import numpy as np
167

17-
import pySDC.helpers.fault_tolerance as ft
8+
from examples.fenics_grayscott.TransferClass import mesh_to_mesh_fenics
9+
from pySDC.core import CollocationClasses as collclass
10+
from pySDC.core import Log
11+
from pySDC.implementations.problem_classes.ProblemClass import fenics_grayscott
1812

1913

2014
if __name__ == "__main__":
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import numpy as np
2+
3+
import projects.node_failure.emulate_hard_faults as ft
4+
from projects.node_failure.allinclusive_classic_nonMPI_hard_faults import allinclusive_classic_nonMPI_hard_faults
5+
from pySDC.helpers.stats_helper import filter_stats, sort_stats
6+
from pySDC.implementations.collocation_classes.gauss_radau_right import CollGaussRadau_Right
7+
from pySDC.implementations.sweeper_classes.generic_LU import generic_LU
8+
from pySDC.implementations.datatype_classes.fenics_mesh import fenics_mesh
9+
from pySDC.implementations.transfer_classes.TransferFenicsMesh import mesh_to_mesh_fenics
10+
from pySDC.implementations.problem_classes.GrayScott_1D_FEniCS_implicit import fenics_grayscott
11+
12+
13+
# noinspection PyShadowingNames,PyShadowingBuiltins
14+
def main(ft_strategies):
15+
"""
16+
This routine generates the heatmaps showing the residual for node failures at different steps and iterations
17+
"""
18+
19+
num_procs = 32
20+
21+
# setup parameters "in time"
22+
t0 = 0
23+
dt = 2.0
24+
Tend = 1280.0
25+
Nsteps = int((Tend-t0)/dt)
26+
27+
# initialize level parameters
28+
level_params = dict()
29+
level_params['restol'] = 1E-07
30+
level_params['dt'] = dt
31+
32+
# initialize step parameters
33+
step_params = dict()
34+
step_params['maxiter'] = 50
35+
36+
# initialize space transfer parameters
37+
space_transfer_params = dict()
38+
space_transfer_params['finter'] = True
39+
40+
# initialize sweeper parameters
41+
sweeper_params = dict()
42+
sweeper_params['collocation_class'] = CollGaussRadau_Right
43+
sweeper_params['num_nodes'] = [3]
44+
sweeper_params['QI'] = 'LU'
45+
46+
# initialize controller parameters
47+
controller_params = dict()
48+
controller_params['logger_level'] = 20
49+
50+
# initialize problem parameters
51+
problem_params = dict()
52+
# problem_params['Du'] = 1.0
53+
# problem_params['Dv'] = 0.01
54+
# problem_params['A'] = 0.01
55+
# problem_params['B'] = 0.10
56+
# splitting pulses until steady state
57+
# problem_params['Du'] = 1.0
58+
# problem_params['Dv'] = 0.01
59+
# problem_params['A'] = 0.02
60+
# problem_params['B'] = 0.079
61+
# splitting pulses until steady state
62+
problem_params['Du'] = 1.0
63+
problem_params['Dv'] = 0.01
64+
problem_params['A'] = 0.09
65+
problem_params['B'] = 0.086
66+
67+
problem_params['t0'] = t0 # ugly, but necessary to set up ProblemClass
68+
problem_params['c_nvars'] = [256]
69+
problem_params['family'] = 'CG'
70+
problem_params['order'] = [4]
71+
problem_params['refinements'] = [1, 0]
72+
73+
# fill description dictionary for easy step instantiation
74+
description = dict()
75+
description['problem_class'] = fenics_grayscott # pass problem class
76+
description['problem_params'] = problem_params # pass problem parameters
77+
description['dtype_u'] = fenics_mesh # pass data type for u
78+
description['dtype_f'] = fenics_mesh # pass data type for f
79+
description['sweeper_class'] = generic_LU # pass sweeper (see part B)
80+
description['sweeper_params'] = sweeper_params # pass sweeper parameters
81+
description['level_params'] = level_params # pass level parameters
82+
description['step_params'] = step_params # pass step parameters
83+
description['space_transfer_class'] = mesh_to_mesh_fenics # pass spatial transfer class
84+
description['space_transfer_params'] = space_transfer_params # pass paramters for spatial transfer
85+
86+
ft.hard_random = 0.03
87+
88+
controller = allinclusive_classic_nonMPI_hard_faults(num_procs=num_procs,
89+
controller_params=controller_params,
90+
description=description)
91+
92+
# get initial values on finest level
93+
P = controller.MS[0].levels[0].prob
94+
uinit = P.u_exact(t0)
95+
96+
for strategy in ft_strategies:
97+
98+
print('------------------------------------------ working on strategy ', strategy)
99+
ft.strategy = strategy
100+
101+
# read in reference data from clean run, will provide reproducable locations for faults
102+
if strategy is not 'NOFAULT':
103+
reffile = np.load('data/PFASST_GRAYSCOTT_stats_hf_NOFAULT_P16.npz')
104+
ft.refdata = reffile['hard_stats']
105+
106+
# call main function to get things done...
107+
uend, stats = controller.run(u0=uinit, t0=t0, Tend=Tend)
108+
109+
# get residuals of the run
110+
extract_stats = filter_stats(stats, type='residual_post_iteration')
111+
112+
# find boundaries for x-,y- and c-axis as well as arrays
113+
maxprocs = 0
114+
maxiter = 0
115+
minres = 0
116+
maxres = -99
117+
for k, v in extract_stats.items():
118+
maxprocs = max(maxprocs, getattr(k, 'process'))
119+
maxiter = max(maxiter, getattr(k, 'iter'))
120+
minres = min(minres, np.log10(v))
121+
maxres = max(maxres, np.log10(v))
122+
123+
# grep residuals and put into array
124+
residual = np.zeros((maxiter, maxprocs + 1))
125+
residual[:] = -99
126+
for k, v in extract_stats.items():
127+
step = getattr(k, 'process')
128+
iter = getattr(k, 'iter')
129+
if iter is not -1:
130+
residual[iter - 1, step] = np.log10(v)
131+
132+
# stats magic: get niter (probably redundant with maxiter)
133+
extract_stats = filter_stats(stats, level=-1, type='niter')
134+
sortedlist_stats = sort_stats(extract_stats, sortby='process')
135+
iter_count = np.zeros(Nsteps)
136+
for item in sortedlist_stats:
137+
iter_count[item[0]] = item[1]
138+
print(iter_count)
139+
140+
np.savez('data/PFASST_GRAYSCOTT_stats_hf_' + ft.strategy + '_P' + str(num_procs), residual=residual,
141+
iter_count=iter_count, hard_stats=ft.hard_stats)
142+
143+
144+
if __name__ == "__main__":
145+
# ft_strategies = ['SPREAD', 'SPREAD_PREDICT', 'INTERP', 'INTERP_PREDICT']
146+
ft_strategies = ['NOFAULT']
147+
148+
main(ft_strategies=ft_strategies)

pySDC/implementations/datatype_classes/fenics_mesh.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ def __init__(self, init=None, val=0.0):
3030
self.values = df.Function(init.V, init.values)
3131
self.V = init.V
3232
# if init is a number or a tuple of numbers, create mesh object with val as initial value
33-
elif isinstance(init, df.FunctionSpace):
33+
else:
3434
self.values = df.Function(init)
3535
self.V = init
36+
# (FIXME: cannot define type of functionspace)
37+
# elif isinstance(init, type(df.FunctionSpace)):
38+
# self.values = df.Function(init)
39+
# self.V = init
3640
# something is wrong, if none of the ones above hit
37-
else:
38-
raise DataError('something went wrong during %s initialization' % type(self))
41+
# else:
42+
# raise DataError('something went wrong during %s initialization' % type(init))
3943

4044
def __add__(self, other):
4145
"""

0 commit comments

Comments
 (0)