1+ import numpy as np
2+
13from pySDC .implementations .problem_classes .HeatEquation_1D_FD import heat1d
24from pySDC .implementations .problem_classes .AdvectionEquation_1D_FD import advection1d
5+ from pySDC .implementations .problem_classes .TestEquation_0D import testequation0d
36from pySDC .implementations .datatype_classes .mesh import mesh
7+ from pySDC .implementations .datatype_classes .complex_mesh import mesh as cmesh
48from pySDC .implementations .collocation_classes .gauss_radau_right import CollGaussRadau_Right
59from pySDC .implementations .sweeper_classes .generic_implicit import generic_implicit
610from pySDC .implementations .transfer_classes .TransferMesh import mesh_to_mesh
11+ from pySDC .implementations .transfer_classes .TransferMesh_NoCoarse import mesh_to_mesh as mesh_to_mesh_nocoarse
712from pySDC .implementations .controller_classes .allinclusive_multigrid_nonMPI import allinclusive_multigrid_nonMPI
813from pySDC .projects .matrixPFASST .allinclusive_matrix_nonMPI import allinclusive_matrix_nonMPI
914
1015from pySDC .helpers .stats_helper import filter_stats , sort_stats
1116
1217
13- def diffusion_setup (mu = 0.0 ):
18+ def diffusion_setup (par = 0.0 ):
1419 """
1520 Setup routine for advection test
1621
1722 Args:
18- mu (float): parameter for controlling stiffness
23+ par (float): parameter for controlling stiffness
1924 """
2025 # initialize level parameters
2126 level_params = dict ()
@@ -32,7 +37,7 @@ def diffusion_setup(mu=0.0):
3237
3338 # initialize problem parameters
3439 problem_params = dict ()
35- problem_params ['nu' ] = mu # diffusion coefficient
40+ problem_params ['nu' ] = par # diffusion coefficient
3641 problem_params ['freq' ] = 4 # frequency for the test value
3742 problem_params ['nvars' ] = [127 , 63 ] # number of degrees of freedom for each level
3843
@@ -66,12 +71,12 @@ def diffusion_setup(mu=0.0):
6671 return description , controller_params
6772
6873
69- def advection_setup (mu = 0.0 ):
74+ def advection_setup (par = 0.0 ):
7075 """
7176 Setup routine for advection test
7277
7378 Args:
74- mu (float): parameter for controlling stiffness
79+ par (float): parameter for controlling stiffness
7580 """
7681 # initialize level parameters
7782 level_params = dict ()
@@ -88,7 +93,7 @@ def advection_setup(mu=0.0):
8893
8994 # initialize problem parameters
9095 problem_params = dict ()
91- problem_params ['c' ] = mu
96+ problem_params ['c' ] = par
9297 problem_params ['freq' ] = 4 # frequency for the test value
9398 problem_params ['nvars' ] = [128 , 64 ] # number of degrees of freedom for each level
9499 problem_params ['order' ] = 2
@@ -125,13 +130,80 @@ def advection_setup(mu=0.0):
125130 return description , controller_params
126131
127132
128- def compare_controllers (type = None , mu = 0.0 , f = None ):
133+ def testequation_setup ():
134+ """
135+ Setup routine for the test equation
136+
137+ Args:
138+ par (float): parameter for controlling stiffness
139+ """
140+ # initialize level parameters
141+ level_params = dict ()
142+ level_params ['restol' ] = 1E-08
143+ level_params ['dt' ] = 0.25
144+ level_params ['nsweeps' ] = [3 , 1 ]
145+
146+ # initialize sweeper parameters
147+ sweeper_params = dict ()
148+ sweeper_params ['collocation_class' ] = CollGaussRadau_Right
149+ sweeper_params ['num_nodes' ] = [3 , 2 ]
150+ sweeper_params ['QI' ] = 'LU'
151+ sweeper_params ['spread' ] = True
152+
153+ # initialize problem parameters
154+ problem_params = dict ()
155+ problem_params ['u0' ] = 1.0 # initial value (for all instances)
156+ # use single values like this...
157+ # problem_params['lambdas'] = [[-1.0]]
158+ # .. or a list of values like this ...
159+ # problem_params['lambdas'] = [[-1.0, -2.0, 1j, -1j]]
160+ # .. or a whole block of values like this
161+ ilim_left = - 11
162+ ilim_right = 0
163+ rlim_left = 0
164+ rlim_right = 11
165+ ilam = 1j * np .logspace (ilim_left , ilim_right , 11 )
166+ rlam = - 1 * np .logspace (rlim_left , rlim_right , 11 )
167+ lambdas = []
168+ for rl in rlam :
169+ for il in ilam :
170+ lambdas .append (rl + il )
171+ problem_params ['lambdas' ] = [lambdas ]
172+ # note: PFASST will do all of those at once, but without interaction (realized via diagonal matrix).
173+ # The propagation matrix will be diagonal too, corresponding to the respective lambda value.
174+
175+ # initialize step parameters
176+ step_params = dict ()
177+ step_params ['maxiter' ] = 50
178+
179+ # initialize controller parameters
180+ controller_params = dict ()
181+ controller_params ['logger_level' ] = 30
182+ controller_params ['predict' ] = False
183+
184+ # fill description dictionary for easy step instantiation
185+ description = dict ()
186+ description ['problem_class' ] = testequation0d # pass problem class
187+ description ['problem_params' ] = problem_params # pass problem parameters
188+ description ['dtype_u' ] = cmesh # pass data type for u
189+ description ['dtype_f' ] = cmesh # pass data type for f
190+ description ['sweeper_class' ] = generic_implicit # pass sweeper
191+ description ['sweeper_params' ] = sweeper_params # pass sweeper parameters
192+ description ['level_params' ] = level_params # pass level parameters
193+ description ['step_params' ] = step_params # pass step parameters
194+ description ['space_transfer_class' ] = mesh_to_mesh_nocoarse # pass spatial transfer class
195+ description ['space_transfer_params' ] = dict () # pass paramters for spatial transfer
196+
197+ return description , controller_params
198+
199+
200+ def compare_controllers (type = None , par = 0.0 , f = None ):
129201 """
130202 A simple test program to compare PFASST runs with matrix-based and matrix-free controllers
131203
132204 Args:
133205 type (str): setup type
134- mu (float) parameter for controlling stiffness
206+ par (float) parameter for controlling stiffness
135207 f: file handler
136208 """
137209
@@ -140,13 +212,15 @@ def compare_controllers(type=None, mu=0.0, f=None):
140212 Tend = 1.0
141213
142214 if type == 'diffusion' :
143- description , controller_params = diffusion_setup (mu )
215+ description , controller_params = diffusion_setup (par )
144216 elif type == 'advection' :
145- description , controller_params = advection_setup (mu )
217+ description , controller_params = advection_setup (par )
218+ elif type == 'testequation' :
219+ description , controller_params = testequation_setup ()
146220 else :
147221 raise ValueError ('No valis setup type provided, aborting..' )
148222
149- out = '\n Working with %s setup and parameter %3.1e..' % (type , mu )
223+ out = '\n Working with %s setup and parameter %3.1e..' % (type , par )
150224 f .write (out + '\n ' )
151225 print (out )
152226
@@ -178,7 +252,7 @@ def compare_controllers(type=None, mu=0.0, f=None):
178252 f .write (out + '\n ' )
179253 print (out )
180254
181- assert diff < 2.0E -15 , 'ERROR: difference between matrix-based and matrix-free result is too large, got %s' % diff
255+ assert diff < 2.3E -15 , 'ERROR: difference between matrix-based and matrix-free result is too large, got %s' % diff
182256
183257 # filter statistics by type (number of iterations)
184258 filtered_stats_mat = filter_stats (stats_mat , type = 'niter' )
@@ -201,12 +275,13 @@ def compare_controllers(type=None, mu=0.0, f=None):
201275
202276def main ():
203277
204- mu_list = [1E-02 , 1.0 , 1E+02 ]
278+ par_list = [1E-02 , 1.0 , 1E+02 ]
205279
206- f = open ('comparison_matrix_vs_nomat_detail.txt' , 'a' )
207- for mu in mu_list :
208- compare_controllers (type = 'diffusion' , mu = mu , f = f )
209- compare_controllers (type = 'advection' , mu = mu , f = f )
280+ f = open ('comparison_matrix_vs_nomat_detail.txt' , 'w' )
281+ for par in par_list :
282+ compare_controllers (type = 'diffusion' , par = par , f = f )
283+ compare_controllers (type = 'advection' , par = par , f = f )
284+ compare_controllers (type = 'testequation' , par = 0.0 , f = f )
210285 f .close ()
211286
212287
0 commit comments