~ubuntu-branches/ubuntu/wily/dolfin/wily-proposed

« back to all changes in this revision

Viewing changes to test/unit/python/multistage/test_RK_solver.py

  • Committer: Package Import Robot
  • Author(s): Johannes Ring
  • Date: 2015-03-17 07:57:11 UTC
  • mfrom: (1.1.18) (19.1.24 experimental)
  • Revision ID: package-import@ubuntu.com-20150317075711-1v207zbty9qmygow
Tags: 1.5.0-1
* New upstream release (closes: #780359).
* debian/control:
  - Bump Standards-Version to 3.9.6 (no changes needed).
  - Bump X-Python-Version to >= 2.7.
  - Update package names for new SONAME 1.5 (libdolfin1.4 ->
    libdolfin1.5, libdolfin1.4-dbg -> libdolfin1.5-dbg and
    libdolfin1.4-dev -> libdolfin1.5-dev).
  - Bump minimum required version for python-instant, python-ufl and
    python-ffc to 1.5.0.
  - Add python-sympy and python-six to Depends for binary package
    python-dolfin.
  - Add dh-python to Build-Depends.
  - Remove libcgal-dev from {Build-}Depends.
* Remove CSGCGALMeshGenerator3D-oom.patch since CGAL is no longer used
  by DOLFIN.
* Move debian/libdolfin1.4.install -> debian/libdolfin1.5.install.
* debian/rules: No longer any non DFSG-free stuff to remove, so update
  get-orig-source target (update debian/watch accordingly).
* Update debian/copyright and debian/copyright_hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env py.test
 
2
 
 
3
"""Unit tests for the RKSolver interface"""
 
4
 
 
5
# Copyright (C) 2013 Johan Hake
 
6
#
 
7
# This file is part of DOLFIN.
 
8
#
 
9
# DOLFIN is free software: you can redistribute it and/or modify
 
10
# it under the terms of the GNU Lesser General Public License as published by
 
11
# the Free Software Foundation, either version 3 of the License, or
 
12
# (at your option) any later version.
 
13
#
 
14
# DOLFIN is distributed in the hope that it will be useful,
 
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
17
# GNU Lesser General Public License for more details.
 
18
#
 
19
# You should have received a copy of the GNU Lesser General Public License
 
20
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
 
21
 
 
22
from __future__ import print_function
 
23
 
 
24
import pytest
 
25
from dolfin import *
 
26
import numpy as np
 
27
 
 
28
from dolfin_utils.test import *
 
29
 
 
30
 
 
31
def convergence_order(errors, base = 2):
 
32
    import math
 
33
    orders = [0.0] * (len(errors)-1)
 
34
    for i in range(len(errors)-1):
 
35
        try:
 
36
            orders[i] = math.log(errors[i]/errors[i+1], base)
 
37
        except ZeroDivisionError:
 
38
            orders[i] = numpy.nan
 
39
 
 
40
    return orders
 
41
 
 
42
@pytest.mark.slow
 
43
@skip_64bit_int  # The linear solver can fail wit 64-bit indices
 
44
@skip_in_parallel
 
45
def test_butcher_schemes_scalar():
 
46
 
 
47
    LEVEL = cpp.get_log_level()
 
48
    cpp.set_log_level(cpp.WARNING)
 
49
    mesh = UnitSquareMesh(4, 4)
 
50
 
 
51
    V = FunctionSpace(mesh, "R", 0)
 
52
    u = Function(V)
 
53
    v = TestFunction(V)
 
54
    form = u*v*dx
 
55
 
 
56
    tstop = 1.0
 
57
    u_true = Expression("exp(t)", t=tstop)
 
58
 
 
59
    for Scheme in [ForwardEuler, ExplicitMidPoint, RK4,
 
60
                   BackwardEuler, CN2, ESDIRK3, ESDIRK4]:
 
61
        scheme = Scheme(form, u)
 
62
        solver = RKSolver(scheme)
 
63
        u_errors = []
 
64
        for dt in [0.05, 0.025, 0.0125]:
 
65
            u.interpolate(Constant(1.0))
 
66
            solver.step_interval(0., tstop, dt)
 
67
            u_errors.append(u_true(0.0, 0.0) - u(0.0, 0.0))
 
68
 
 
69
        assert scheme.order()-min(convergence_order(u_errors))<0.1
 
70
 
 
71
    cpp.set_log_level(LEVEL)
 
72
 
 
73
 
 
74
@pytest.mark.slow
 
75
@skip_in_parallel
 
76
def test_butcher_schemes_vector():
 
77
 
 
78
    LEVEL = cpp.get_log_level()
 
79
    cpp.set_log_level(cpp.WARNING)
 
80
    mesh = UnitSquareMesh(4, 4)
 
81
 
 
82
    V = VectorFunctionSpace(mesh, "R", 0, dim=2)
 
83
    u = Function(V)
 
84
    v = TestFunction(V)
 
85
    form = inner(as_vector((-u[1], u[0])), v)*dx
 
86
 
 
87
    tstop = 1.0
 
88
    u_true = Expression(("cos(t)", "sin(t)"), t=tstop)
 
89
 
 
90
    for Scheme in [ForwardEuler, ExplicitMidPoint, RK4,
 
91
                   BackwardEuler, CN2, ESDIRK3, ESDIRK4]:
 
92
        scheme = Scheme(form, u)
 
93
        solver = RKSolver(scheme)
 
94
        u_errors_0 = []
 
95
        u_errors_1 = []
 
96
        for dt in [0.05, 0.025, 0.0125]:
 
97
            u.interpolate(Constant((1.0, 0.0)))
 
98
            solver.step_interval(0., tstop, dt)
 
99
            u_errors_0.append(u_true(0.0, 0.0)[0] - u(0.0, 0.0)[0])
 
100
            u_errors_1.append(u_true(0.0, 0.0)[1] - u(0.0, 0.0)[1])
 
101
 
 
102
        assert scheme.order()-min(convergence_order(u_errors_0))<0.1
 
103
        assert scheme.order()-min(convergence_order(u_errors_1))<0.1
 
104
 
 
105
    cpp.set_log_level(LEVEL)