Skip to content

Commit 2430ab5

Browse files
author
Thomas Baumann
committed
Interpolation now also works for 2D problems
1 parent ff522dd commit 2430ab5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pySDC/implementations/convergence_controller_classes/adaptive_collocation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def switch_sweeper(self, S):
105105
P = L.prob
106106

107107
# store solution of current level which will be interpolated to new level
108-
u_old = L.u.copy()
108+
u_old = [me.flatten() for me in L.u]
109109
nodes_old = L.sweep.coll.nodes.copy()
110110

111111
# change sweeper
@@ -119,12 +119,13 @@ def switch_sweeper(self, S):
119119
# interpolate solution of old collocation problem to new one
120120
nodes_new = L.sweep.coll.nodes.copy()
121121
interpolator = LagrangeApproximation(points=np.append(0, nodes_old))
122+
122123
u_inter = interpolator.getInterpolationMatrix(np.append(0, nodes_new)) @ u_old
123124

124125
# assign the interpolated values to the nodes in the level
125126
for i in range(0, len(u_inter)):
126127
me = P.dtype_u(P.init)
127-
me[:] = u_inter[i]
128+
me[:] = np.reshape(u_inter[i], P.init[0])
128129
L.u[i] = me
129130

130131
# reevaluate rhs

pySDC/implementations/convergence_controller_classes/adaptivity.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,13 @@ def get_local_error_estimate(self, controller, S, **kwargs):
448448

449449

450450
class AdaptivityCollocation(AdaptivityBase):
451+
"""
452+
Control the step size via a collocation based estimate of the local error.
453+
The error estimate works by subtracting two solutions to collocation problems with different order. You can
454+
interpolate between collocation methods as much as you want but the adaptive step size selection will always be
455+
based on the last switch of quadrature.
456+
"""
457+
451458
def setup(self, controller, params, description, **kwargs):
452459
"""
453460
Add a default value for control order to the parameters.
@@ -537,8 +544,11 @@ def get_new_step_size(self, controller, S, **kwargs):
537544
lvl = S.levels[0]
538545

539546
# compute next step size
540-
order = self.status.order[-2] + 1 # local order of second to most accurate solution
547+
order = (
548+
min(self.status.order[-2::]) + 1
549+
) # local order of less accurate of the last two collocation problems
541550
e_est = self.get_local_error_estimate(controller, S)
551+
542552
lvl.status.dt_new = self.compute_optimal_step_size(
543553
self.params.beta, lvl.params.dt, self.params.e_tol, e_est, order
544554
)

0 commit comments

Comments
 (0)