Skip to content

Commit 1d51a57

Browse files
author
Daniel Ruprecht
committed
matrices LHS and RHS in test_imexsweeper are now created by a function of the imex_sweeper class
1 parent 8306fc0 commit 1d51a57

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

pySDC/sweeper_classes/imex_1st_order.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,20 @@ def compute_end_point(self):
156156
return None
157157

158158
def get_sweeper_mats(self):
159+
"""
160+
Returns the three matrices Q, QI, QE which define the sweeper. The first row and column, corresponding to the left starting value, are removed to correspond to the notation
161+
introduced in Ruprecht & Speck, ``Spectral deferred corrections with fast-wave slow-wave splitting'', 2016
162+
"""
159163
QE = self.QE[1:,1:]
160164
QI = self.QI[1:,1:]
161165
Q = self.coll.Qmat[1:,1:]
162166
return QE, QI, Q
163167

164168
def get_scalar_problems_sweeper_mats(self, lambdas=[None, None]):
169+
"""
170+
For a scalar problem, an IMEX-SDC sweep can be written in matrix formulation. This function returns the corresponding matrices.
171+
See Ruprecht & Speck, ``Spectral deferred corrections with fast-wave slow-wave splitting'', 2016 for the derivation.
172+
"""
165173
QE, QI, Q = self.get_sweeper_mats()
166174
if lambdas==[None,None]:
167175
pass
@@ -171,4 +179,8 @@ def get_scalar_problems_sweeper_mats(self, lambdas=[None, None]):
171179
lambda_fast = lambdas[0]
172180
lambda_slow = lambdas[1]
173181
assert abs(lambda_slow)<=abs(lambda_fast), "First entry in parameter lambdas (lambda_fast) has to be greater than second entry (lambda_slow)"
174-
return QE, QI, Q
182+
nnodes = self.coll.num_nodes
183+
dt = self.level.dt
184+
LHS = np.eye(nnodes) - dt*( lambda_fast*QI + lambda_slow*QE )
185+
RHS = dt*( (lambda_fast+lambda_slow)*Q - (lambda_fast*QI + lambda_slow*QE) )
186+
return LHS, RHS

tests/test_imexsweeper.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@ def setupLevelStepProblem(self):
3232
problem = level.prob
3333
return step, level, problem, nnodes
3434

35-
def setupSweeperMatrices(self, step, level, problem):
36-
nnodes = step.levels[0].sweep.coll.num_nodes
37-
# Build SDC sweep matrix
38-
QE, QI, Q = level.sweep.get_sweeper_mats()
39-
dt = step.status.dt
40-
LHS = np.eye(nnodes) - step.status.dt*( problem.lambda_f[0]*QI + problem.lambda_s[0]*QE )
41-
RHS = step.status.dt*( (problem.lambda_f[0]+problem.lambda_s[0])*Q - (problem.lambda_f[0]*QI + problem.lambda_s[0]*QE) )
35+
def setupSweeperMatrices(self, level, problem):
36+
lambdas = [ problem.lambda_f[0] , problem.lambda_s[0] ]
37+
LHS, RHS = level.sweep.get_scalar_problems_sweeper_mats( lambdas = lambdas )
4238
return LHS, RHS
4339

4440
#
@@ -112,7 +108,7 @@ def test_sweepequalmatrix(self):
112108
# Perform node-to-node SDC sweep
113109
level.sweep.update_nodes()
114110

115-
LHS, RHS = self.setupSweeperMatrices(step, level, problem)
111+
LHS, RHS = self.setupSweeperMatrices(level, problem)
116112

117113
unew = np.linalg.inv(LHS).dot( u0full + RHS.dot(u0full) )
118114
usweep = np.array([ level.u[l].values.flatten() for l in range(1,nnodes+1) ])
@@ -193,7 +189,7 @@ def test_manysweepsequalmatrix(self):
193189
level.sweep.update_nodes()
194190
usweep = np.array([ level.u[l].values.flatten() for l in range(1,nnodes+1) ])
195191

196-
LHS, RHS = self.setupSweeperMatrices(step, level, problem)
192+
LHS, RHS = self.setupSweeperMatrices(level, problem)
197193
unew = u0full
198194
for i in range(0,K):
199195
unew = np.linalg.inv(LHS).dot( u0full + RHS.dot(unew) )
@@ -207,6 +203,7 @@ def test_manysweepsequalmatrix(self):
207203
Mat_sweep = Mat_sweep + np.linalg.matrix_power(Pinv.dot(RHS),i).dot(Pinv)
208204
usweep_onematrix = Mat_sweep.dot(u0full)
209205
assert np.linalg.norm( usweep_onematrix - usweep, np.infty )<1e-14, "Single-matrix multiple sweep formulation yields different result than multiple sweeps in node-to-node or matrix form form"
206+
210207

211208
#
212209
# Make sure that update function for K sweeps computed from K-sweep matrix gives same result as K sweeps in node-to-node form plus compute_end_point
@@ -226,7 +223,7 @@ def test_manysweepupdate(self):
226223
level.sweep.compute_end_point()
227224
uend_sweep = level.uend.values
228225

229-
LHS, RHS = self.setupSweeperMatrices(step, level, problem)
226+
LHS, RHS = self.setupSweeperMatrices(level, problem)
230227
# Build single matrix representing K sweeps
231228
Pinv = np.linalg.inv(LHS)
232229
Mat_sweep = np.linalg.matrix_power(Pinv.dot(RHS), K)
@@ -238,6 +235,7 @@ def test_manysweepupdate(self):
238235
uend_matrix = update*self.pparams['u0']
239236
assert abs(uend_matrix - uend_sweep)<1e-14, "Node-to-node sweep plus update yields different result than update function computed through K-sweep matrix"
240237

238+
241239
#
242240
# Make sure that creating a sweeper object with a collocation object with right_is_node=False and do_coll_update=False throws an exception
243241
#

0 commit comments

Comments
 (0)