# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
#
# Modified by Steven Vandekerckhove, 2014
# Modified by Tormod Landet, 2015

import pytest
import numpy
from dolfin import *
from dolfin_utils.test import skip_in_parallel
from dolfin_utils.test import set_parameters_fixture
ghost_mode = set_parameters_fixture("ghost_mode", ["shared_facet"])


def test_solve_global_rhs():
    mesh = UnitCubeMesh(2, 3, 3)
    V = FunctionSpace(mesh, "Discontinuous Lagrange", 2)
    W = FunctionSpace(mesh, "Lagrange", 2)

    u, v = TrialFunction(V), TestFunction(V)
    f = Expression("x[0]*x[0] + x[0]*x[1] + x[1]*x[1]", element=W.ufl_element())

    # Forms for projection
    a, L = inner(v, u)*dx, inner(v, f)*dx

    solvers = [LocalSolver.SolverType_LU, LocalSolver.SolverType_Cholesky]
    for solver_type in solvers:
Exemple #2
0
# (at your option) any later version.
#
# DOLFIN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.

from __future__ import division
import numpy
from dolfin import *
from dolfin_utils.test import set_parameters_fixture

ghost_mode = set_parameters_fixture("ghost_mode", ["shared_facet"])


def test_local_assembler_1D():
    mesh = UnitIntervalMesh(20)
    V = FunctionSpace(mesh, 'CG', 1)
    u = TrialFunction(V)
    v = TestFunction(V)
    c = Cell(mesh, 0)

    a_scalar = Constant(1) * dx(domain=mesh)
    a_vector = v * dx
    a_matrix = u * v * dx

    A_scalar = assemble_local(a_scalar, c)
    A_vector = assemble_local(a_vector, c)
Exemple #3
0
    reference = numpy.array((0, 1, 0, 1, 0, 1, 0, 1))
    # Only compare against reference in serial (don't know how to
    # compare in parallel)
    for i in range(mesh.num_cells()):
        assert mesh.cell_orientations()[i] == reference[i]

    mesh = BoundaryMesh(UnitSquareMesh(2, 2), "exterior")
    mesh.init_cell_orientations(Expression(("x[0]", "x[1]", "x[2]"), degree=1))
    print(mesh.cell_orientations())


# - Facilities to run tests on combination of meshes

ghost_mode = set_parameters_fixture("ghost_mode", [
    "none",
    "shared_facet",
    "shared_vertex",
])

def _create_two_quads(good):
    """Create mesh with two quads either with good or
    bad ordering according to bool parameter
    """
    mesh = Mesh()
    e = MeshEditor()
    e.open(mesh, "quadrilateral", 2, 2, degree=1)
    e.init_vertices(6)
    e.init_cells(2)
    e.add_vertex(0, Point(0, 0))
    e.add_vertex(1, Point(1, 0))
    e.add_vertex(2, Point(2, 0))
    reference = numpy.array((0, 1, 0, 1, 0, 1, 0, 1))
    # Only compare against reference in serial (don't know how to
    # compare in parallel)
    for i in range(mesh.num_cells()):
        assert mesh.cell_orientations()[i] == reference[i]

    mesh = BoundaryMesh(UnitSquareMesh(2, 2), "exterior")
    mesh.init_cell_orientations(Expression(("x[0]", "x[1]", "x[2]"), degree=1))
    print(mesh.cell_orientations())


# - Facilities to run tests on combination of meshes

ghost_mode = set_parameters_fixture("ghost_mode", [
    "none",
    "shared_facet",
    "shared_vertex",
])

mesh_factories = [
    (UnitIntervalMesh, (8, )),
    (UnitSquareMesh, (4, 4)),
    (UnitDiscMesh.create, (MPI.comm_world, 10, 1, 2)),
    (UnitDiscMesh.create, (MPI.comm_world, 10, 2, 2)),
    (UnitDiscMesh.create, (MPI.comm_world, 10, 1, 3)),
    (UnitDiscMesh.create, (MPI.comm_world, 10, 2, 3)),
    (SphericalShellMesh.create, (
        MPI.comm_world,
        1,
    )),
    (SphericalShellMesh.create, (
Exemple #5
0
from dolfin import *
import ufl
import numpy
import sys
import pytest
from dolfin_utils.test import set_parameters_fixture, skip_in_parallel, fixture

from ufl.classes import CellOrientation, CellNormal, CellCoordinate, \
CellOrigin, Jacobian, JacobianInverse, JacobianDeterminant

# This was for debugging, don't enable this permanently here in tests
# parameters["reorder_dofs_serial"] = False
any_representation = \
  set_parameters_fixture("form_compiler.representation",
                             ["quadrature", "uflacs"])
uflacs_representation_only \
    = set_parameters_fixture("form_compiler.representation",
                             ["uflacs"])


def create_mesh(vertices, cells, cellname="simplex"):
    """Given list of vertex coordinate tuples and cell vertex index
tuples, build and return a mesh.

    """

    # Get dimensions
    gdim = len(vertices[0])

    # Automatic choice of cellname for simplices
    if cellname == "simplex":
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import pytest
from dolfin import *
import numpy as np

from dolfin_utils.test import set_parameters_fixture

optimize = set_parameters_fixture('form_compiler.optimize', [True])

# Exclude some tests for now
scalar_excludes = [RK4, CN2, ExplicitMidPoint, ESDIRK3, ESDIRK4]

# Build test methods using function closure so 1 test is generated per Scheme and
# test case
@pytest.fixture(params=["ForwardEuler", "ExplicitMidPoint", "RK4",
                        "BackwardEuler", "CN2", "ESDIRK3", "ESDIRK4",
                        "GRL1", "RL1", "GRL2", "RL2"])
def Scheme(request):
    return eval(request.param)

def convergence_order(errors, base = 2):
    import math
    orders = [0.0] * (len(errors)-1)
Exemple #7
0
from dolfin_utils.test import set_parameters_fixture, skip_in_parallel

from ufl.classes import CellOrientation, CellNormal, CellCoordinate, \
CellOrigin, Jacobian, JacobianInverse, JacobianDeterminant

# This was for debugging, don't enable this permanently here in tests
# parameters["reorder_dofs_serial"] = False

# Hack to skip uflacs parameter if not installed. There's probably a
# cleaner way to do this with pytest.
try:
    import uflacs
    _uflacs = ["uflacs"]
except:
    _uflacs = []
any_representation = set_parameters_fixture("form_compiler.representation",
                                            ["quadrature"] + _uflacs)
uflacs_representation_only \
    = set_parameters_fixture("form_compiler.representation",
                             _uflacs)


def create_mesh(vertices, cells, cellname="simplex"):
    """Given list of vertex coordinate tuples and cell vertex index
tuples, build and return a mesh.

    """

    # Get dimensions
    gdim = len(vertices[0])

    # Automatic choice of cellname for simplices
Exemple #8
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import pytest
from dolfin import *
import numpy as np

from dolfin_utils.test import set_parameters_fixture

optimize = set_parameters_fixture('form_compiler.optimize', [True])

# Exclude some tests for now
scalar_excludes = [RK4, CN2, ExplicitMidPoint, ESDIRK3, ESDIRK4]


# Build test methods using function closure so 1 test is generated per Scheme and
# test case
@pytest.fixture(params=[
    "ForwardEuler", "ExplicitMidPoint", "RK4", "BackwardEuler", "CN2",
    "ESDIRK3", "ESDIRK4", "GRL1", "RL1", "GRL2", "RL2"
])
def Scheme(request):
    return eval(request.param)

from ufl.classes import CellOrientation, CellNormal, CellCoordinate, CellOrigin, Jacobian, JacobianInverse, JacobianDeterminant


# This was for debugging, don't enable this permanently here in tests
#parameters["reorder_dofs_serial"] = False


# Hack to skip uflacs parameter if not installed. There's probably a
# cleaner way to do this with pytest.
try:
    import uflacs
    _uflacs = ["uflacs"]
except:
    _uflacs = []
any_representation = set_parameters_fixture("form_compiler.representation", ["quadrature"] + _uflacs)
uflacs_representation_only = set_parameters_fixture("form_compiler.representation", _uflacs)


def create_mesh(vertices, cells, cellname="simplex"):
    "Given list of vertex coordinate tuples and cell vertex index tuples, build and return a mesh."

    # Get dimensions
    gdim = len(vertices[0])

    # Automatic choice of cellname for simplices
    if cellname == "simplex":
        num_cell_vertices = len(cells[0])
        cellname = {1: "vertex",
                    2: "interval",
                    3: "triangle",
from dolfin import *
import ufl
import numpy
import sys
import pytest
from dolfin_utils.test import set_parameters_fixture, skip_in_parallel, fixture

from ufl.classes import CellOrientation, CellNormal, CellCoordinate, \
CellOrigin, Jacobian, JacobianInverse, JacobianDeterminant

# This was for debugging, don't enable this permanently here in tests
# parameters["reorder_dofs_serial"] = False
any_representation = \
  set_parameters_fixture("form_compiler.representation",
                             ["quadrature", "uflacs"])
uflacs_representation_only \
    = set_parameters_fixture("form_compiler.representation",
                             ["uflacs"])


def create_mesh(vertices, cells, cellname="simplex"):
    """Given list of vertex coordinate tuples and cell vertex index
tuples, build and return a mesh.

    """

    # Get dimensions
    gdim = len(vertices[0])

    # Automatic choice of cellname for simplices
    if cellname == "simplex":
Exemple #11
0
from dolfin import (UnitSquareMesh, UnitIntervalMesh, UnitCubeMesh, MPI,
                    CellType, VectorFunctionSpace, FunctionSpace, MixedElement,
                    FiniteElement, VectorElement, Point, Cells, SubDomain,
                    DOLFIN_EPS)
from dolfin_utils.test import fixture, skip_in_serial, skip_in_parallel, set_parameters_fixture

xfail = pytest.mark.xfail(strict=True)


@fixture
def mesh():
    return UnitSquareMesh(MPI.comm_world, 4, 4)


reorder_dofs = set_parameters_fixture("reorder_dofs_serial", [True, False])


@pytest.mark.skip
@pytest.mark.parametrize(
    'mesh_factory',
    [
        (UnitIntervalMesh, (
            MPI.comm_world,
            8,
        )),
        (UnitSquareMesh, (MPI.comm_world, 4, 4)),
        (UnitCubeMesh, (MPI.comm_world, 2, 2, 2)),
        # cell.contains(Point) does not work correctly
        # for quad/hex cells once it is fixed, this test will pass
        xfail((UnitSquareMesh,