Skip to content

Commit 0f25135

Browse files
committed
started removing dtypes from frontends (WIP)
1 parent b8bd45f commit 0f25135

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

pySDC/core/Level.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,13 @@ class level(FrozenClass):
4444
tau (list of dtype_u): FAS correction, allocated via step class if necessary
4545
"""
4646

47-
def __init__(self, problem_class, problem_params, dtype_u, dtype_f, sweeper_class, sweeper_params,
48-
level_params, level_index):
47+
def __init__(self, problem_class, problem_params, sweeper_class, sweeper_params, level_params, level_index):
4948
"""
5049
Initialization routine
5150
5251
Args:
5352
problem_class: problem class
5453
problem_params (dict): parameters for the problem to be initialized
55-
dtype_u: data type of the dofs
56-
dtype_f: data type of the RHS
5754
sweeper_class: sweeper class
5855
sweeper_params (dict): parameters for the sweeper (contains collocation)
5956
level_params (dict): parameters given by the user, will be added as attributes
@@ -62,7 +59,7 @@ def __init__(self, problem_class, problem_params, dtype_u, dtype_f, sweeper_clas
6259

6360
# instantiate sweeper, problem and hooks
6461
self.__sweep = sweeper_class(sweeper_params)
65-
self.__prob = problem_class(problem_params, dtype_u, dtype_f)
62+
self.__prob = problem_class(problem_params)
6663

6764
# set level parameters and status
6865
self.params = _Pars(level_params)

pySDC/core/Step.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ def __generate_hierarchy(self, descr):
8585
descr (dict): dictionary containing the description of the levels as list per key
8686
"""
8787

88+
assert 'dtype_u' not in descr
89+
assert 'dtype_f' not in descr
90+
8891
# assert the existence of all the keys we need to set up at least on level
89-
essential_keys = ['problem_class', 'dtype_u', 'dtype_f', 'sweeper_class', 'sweeper_params', 'level_params']
92+
essential_keys = ['problem_class', 'sweeper_class', 'sweeper_params', 'level_params']
9093
for key in essential_keys:
9194
if key not in descr:
9295
msg = 'need %s to instantiate step, only got %s' % (key, str(descr.keys()))
@@ -131,8 +134,6 @@ def __generate_hierarchy(self, descr):
131134

132135
L = levclass.level(problem_class=descr_list[l]['problem_class'],
133136
problem_params=descr_list[l]['problem_params'],
134-
dtype_u=descr_list[l]['dtype_u'],
135-
dtype_f=descr_list[l]['dtype_f'],
136137
sweeper_class=descr_list[l]['sweeper_class'],
137138
sweeper_params=descr_list[l]['sweeper_params'],
138139
level_params=descr_list[l]['level_params'],

pySDC/implementations/problem_classes/GeneralizedFisher_1D_PETSc.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import numpy as np
22
from petsc4py import PETSc
33

4+
from pySDC.implementations.datatype_classes.petsc_dmda_grid import petsc_data, rhs_2comp_petsc_data, rhs_imex_petsc_data
5+
46
from pySDC.core.Problem import ptype
57
from pySDC.core.Errors import ParameterError
68

@@ -181,14 +183,14 @@ class petsc_fisher_multiimplicit(ptype):
181183
"""
182184
Problem class implementing the multi-implicit 1D generalized Fisher equation with periodic BC and PETSc
183185
"""
184-
def __init__(self, problem_params, dtype_u, dtype_f):
186+
def __init__(self, problem_params, dtype_u=petsc_data, dtype_f=rhs_2comp_petsc_data):
185187
"""
186188
Initialization routine
187189
188190
Args:
189191
problem_params: custom parameters for the example
190-
dtype_u: particle data type (will be passed parent class)
191-
dtype_f: acceleration data type (will be passed parent class)
192+
dtype_u: PETSc data type (will be passed to parent class)
193+
dtype_f: PETSc data type with 2 components (will be passed to parent class)
192194
"""
193195

194196
# define optional parameters
@@ -440,6 +442,20 @@ class petsc_fisher_fullyimplicit(petsc_fisher_multiimplicit):
440442
Problem class implementing the fully-implicit 2D Gray-Scott reaction-diffusion equation with periodic BC and PETSc
441443
"""
442444

445+
def __init__(self, problem_params, dtype_u=petsc_data, dtype_f=petsc_data):
446+
"""
447+
Initialization routine
448+
449+
Args:
450+
problem_params: custom parameters for the example
451+
dtype_u: PETSc data type (will be passed to parent class)
452+
dtype_f: PETSc data type (will be passed to parent class)
453+
"""
454+
455+
# invoke super init, passing number of dofs, dtype_u and dtype_f
456+
super(petsc_fisher_fullyimplicit, self).__init__(problem_params=problem_params, dtype_u=dtype_u,
457+
dtype_f=dtype_f)
458+
443459
def eval_f(self, u, t):
444460
"""
445461
Routine to evaluate the RHS
@@ -499,6 +515,20 @@ class petsc_fisher_semiimplicit(petsc_fisher_multiimplicit):
499515
Problem class implementing the semi-implicit 2D Gray-Scott reaction-diffusion equation with periodic BC and PETSc
500516
"""
501517

518+
def __init__(self, problem_params, dtype_u=petsc_data, dtype_f=rhs_imex_petsc_data):
519+
"""
520+
Initialization routine
521+
522+
Args:
523+
problem_params: custom parameters for the example
524+
dtype_u: PETSc data type (will be passed to parent class)
525+
dtype_f: PETSc data type with implicit and explicit parts (will be passed to parent class)
526+
"""
527+
528+
# invoke super init, passing number of dofs, dtype_u and dtype_f
529+
super(petsc_fisher_semiimplicit, self).__init__(problem_params=problem_params, dtype_u=dtype_u,
530+
dtype_f=dtype_f)
531+
502532
def eval_f(self, u, t):
503533
"""
504534
Routine to evaluate the RHS

pySDC/projects/SDC_showdown/SDC_timing_Fisher.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from pySDC.implementations.problem_classes.GeneralizedFisher_1D_PETSc import petsc_fisher_multiimplicit, \
66
petsc_fisher_fullyimplicit, petsc_fisher_semiimplicit
7-
from pySDC.implementations.datatype_classes.petsc_dmda_grid import petsc_data, rhs_2comp_petsc_data, rhs_imex_petsc_data
87
from pySDC.implementations.collocation_classes.gauss_radau_right import CollGaussRadau_Right
98
from pySDC.implementations.sweeper_classes.multi_implicit import multi_implicit
109
from pySDC.implementations.sweeper_classes.imex_1st_order import imex_1st_order
@@ -69,8 +68,6 @@ def setup_parameters():
6968
description = dict()
7069
description['problem_class'] = None # pass problem class
7170
description['problem_params'] = problem_params # pass problem parameters
72-
description['dtype_u'] = petsc_data # pass data type for u
73-
description['dtype_f'] = None # pass data type for f
7471
description['sweeper_class'] = None # pass sweeper (see part B)
7572
description['sweeper_params'] = sweeper_params # pass sweeper parameters
7673
description['level_params'] = level_params # pass level parameters
@@ -100,15 +97,12 @@ def run_SDC_variant(variant=None, inexact=False):
10097
# add stuff based on variant
10198
if variant == 'fully-implicit':
10299
description['problem_class'] = petsc_fisher_fullyimplicit
103-
description['dtype_f'] = petsc_data
104100
description['sweeper_class'] = generic_implicit
105101
elif variant == 'semi-implicit':
106102
description['problem_class'] = petsc_fisher_semiimplicit
107-
description['dtype_f'] = rhs_imex_petsc_data
108103
description['sweeper_class'] = imex_1st_order
109104
elif variant == 'multi-implicit':
110105
description['problem_class'] = petsc_fisher_multiimplicit
111-
description['dtype_f'] = rhs_2comp_petsc_data
112106
description['sweeper_class'] = multi_implicit
113107
else:
114108
raise NotImplemented('Wrong variant specified, got %s' % variant)
@@ -209,7 +203,7 @@ def show_results(fname):
209203
return None
210204

211205

212-
def main():
206+
def main(cwd=''):
213207
"""
214208
Main driver
215209
@@ -225,7 +219,7 @@ def main():
225219
results[(variant, 'inexact')] = run_SDC_variant(variant=variant, inexact=True)
226220

227221
# dump result
228-
fname = 'data/timings_SDC_variants_Fisher'
222+
fname = cwd + 'data/timings_SDC_variants_Fisher'
229223
file = open(fname + '.pkl', 'wb')
230224
pickle.dump(results, file)
231225
file.close()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ matplotlib>=1.5.3
55
pep8
66
dill>=0.2.6
77
numba>=0.35
8+
petsc4py>=3.10.0
89
pyfftw

0 commit comments

Comments
 (0)