This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Multistage solver and element family

0 votes

I am trying to understand the multistage solver in Fenics 1.3. I looked at the unit tests in RKSolver.py

Does the RKSolver only work for "R" elements...? Just change the element to "DG0" (or "CG1") and the tests fail.

I know that using "R" elements, we only have a global degree of freedom. Am I missing something when using other elements like "DG0"...?

asked Jan 17, 2014 by Vijay Murthy FEniCS Novice (960 points)
edited Jan 18, 2014 by Vijay Murthy

1 Answer

+2 votes

Have a look in:

dolfin/demo/undocumented/multistage-solver/python/demo_multi-stage-solver.py
answered Jan 17, 2014 by johanhake FEniCS Expert (22,480 points)

Thanks for the link to the example. I tried to follow the approach there.

I wanted to try with DG elements and either Dirichlet or Periodic boundary conditions. However neither seem to work. I dont know why.

from dolfin import *
import math

cpp.set_log_level(cpp.WARNING)

class PeriodicBoundary(SubDomain):
    def inside(self, x, on_boundary):
        return bool(x[0] < DOLFIN_EPS and
                x[0] > -DOLFIN_EPS and on_boundary)
    def map(self, x, y):
        y[0] = x[0] - 1.0
pbc = PeriodicBoundary()

mesh = UnitIntervalMesh(4)
V = FunctionSpace(mesh, "DG", 0)#, constrained_domain=pbc)
u = Function(V)
v = TestFunction(V)
form = u*v*dx

t=Constant(0.0)
T=1.0
dt=0.1

dbc = DirichletBC(V, 0.0, "x[0] < DOLFIN_EPS || x[0]-1.0 > -DOLFIN_EPS")

scheme=ESDIRK4(form, u, t, [dbc])
#scheme=ESDIRK4(form, u, t, [pbc])
solver=RKSolver(scheme)

u.interpolate(Constant(1.0))

print float(scheme.t()), u(0.0), u(0.5), u(1.0), math.exp(float(scheme.t()))
while float(scheme.t()) < T-DOLFIN_EPS:
    solver.step(dt)
    print float(scheme.t()), u(0.0), u(0.5), u(1.0), math.exp(float(scheme.t()))

As output I get (where the last column is the exact answer)

0.0 1.0 1.0 1.0 1.0
0.1 1.09201179045 1.09201179045 1.09201179045 1.10517091808
0.2 1.19248975048 1.19248975048 1.19248975048 1.22140275816
0.3 1.30221286751 1.30221286751 1.30221286751 1.34985880758
0.4 1.422031805 1.422031805 1.422031805 1.49182469764
0.5 1.55287549745 1.55287549745 1.55287549745 1.6487212707
0.6 1.69575835232 1.69575835232 1.69575835232 1.82211880039
0.7 1.85178811449 1.85178811449 1.85178811449 2.01375270747
0.8 2.02217445443 2.02217445443 2.02217445443 2.22554092849
0.9 2.20823834658 2.20823834658 2.20823834658 2.45960311116
1.0 2.41142231059 2.41142231059 2.41142231059 2.71828182846
...