Skip to content

Commit

Permalink
IMEX version of the polynomial test problem
Browse files Browse the repository at this point in the history
  • Loading branch information
brownbaerchen committed Nov 9, 2023
1 parent 9976f09 commit 375bc5e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
34 changes: 33 additions & 1 deletion pySDC/implementations/problem_classes/polynomial_test_problem.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np

from pySDC.core.Problem import ptype
from pySDC.implementations.datatype_classes.mesh import mesh
from pySDC.implementations.datatype_classes.mesh import mesh, imex_mesh


class polynomial_testequation(ptype):
Expand Down Expand Up @@ -88,3 +88,35 @@ def u_exact(self, t, **kwargs):
me = self.dtype_u(self.init)
me[:] = self.poly(t)
return me


class polynomial_testequation_IMEX(polynomial_testequation):
"""
IMEX version of the polynomial test problem that assigns half the derivative to the implicit part and the other half to the explicit part.
Keep in mind that you still cannot Really perform any solves.
"""

dtype_f = imex_mesh

def eval_f(self, u, t):
"""
Derivative of the polynomial.
Parameters
----------
u : dtype_u
Current values of the numerical solution.
t : float
Current time of the numerical solution is computed.
Returns
-------
f : dtype_f
The right-hand side of the problem.
"""

f = self.dtype_f(self.init)
derivative = self.poly.deriv(m=1)(t)
f.impl[:] = derivative / 2
f.expl[:] = derivative / 2
return f
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest


def get_controller(dt, num_nodes, quad_type, useMPI, **kwargs):
def get_controller(dt, num_nodes, quad_type, useMPI, imex, **kwargs):
"""
Gets a controller setup for the polynomial test problem.
Expand All @@ -10,17 +10,26 @@ def get_controller(dt, num_nodes, quad_type, useMPI, **kwargs):
num_nodes (int): Number of nodes
quad_type (str): Type of quadrature
useMPI (bool): Whether or not to use MPI
imex (bool): Use IMEX version of the test problem
Returns:
(dict): Stats object generated during the run
(pySDC.Controller.controller): Controller used in the run
"""
from pySDC.implementations.problem_classes.polynomial_test_problem import polynomial_testequation
from pySDC.implementations.controller_classes.controller_nonMPI import controller_nonMPI
from pySDC.implementations.convergence_controller_classes.estimate_extrapolation_error import (
EstimateExtrapolationErrorWithinQ,
)

if imex:
from pySDC.implementations.problem_classes.polynomial_test_problem import (
polynomial_testequation_IMEX as problem_class,
)
else:
from pySDC.implementations.problem_classes.polynomial_test_problem import (
polynomial_testequation as problem_class,
)

if useMPI:
from pySDC.implementations.sweeper_classes.generic_implicit_MPI import generic_implicit_MPI as sweeper_class
from mpi4py import MPI
Expand Down Expand Up @@ -55,7 +64,7 @@ def get_controller(dt, num_nodes, quad_type, useMPI, **kwargs):

# fill description dictionary for easy step instantiation
description = {}
description['problem_class'] = polynomial_testequation
description['problem_class'] = problem_class
description['problem_params'] = problem_params
description['sweeper_class'] = sweeper_class
description['sweeper_params'] = sweeper_params
Expand Down Expand Up @@ -179,6 +188,7 @@ def test_extrapolation_within_Q(num_nodes, quad_type):
'quad_type': quad_type,
'useMPI': False,
'QI': 'MIN',
'imex': False,
}

import numpy as np
Expand Down Expand Up @@ -219,5 +229,6 @@ def test_extrapolation_within_Q_MPI(num_nodes, quad_type):
'quad_type': sys.argv[2],
'useMPI': True,
'QI': 'MIN',
'imex': True,
}
check_order([5e-1, 1e-1, 8e-2, 5e-2], **kwargs)

0 comments on commit 375bc5e

Please sign in to comment.