Skip to content
Snippets Groups Projects
Commit 07c8b249 authored by Dominic Kempf's avatar Dominic Kempf
Browse files

Merge branch 'tests/poisson-variations' into 'master'

Tests/poisson variations

Test various poisson variations:

- 1D/2D/3D
- CG/DG
- triangles/quadrilaterals

This closes #19 and #18.

See merge request !9
parents 92b70c9a 77cb50d8
No related branches found
No related tags found
No related merge requests found
Showing
with 313 additions and 8 deletions
......@@ -72,7 +72,7 @@ def isSimplical(fem):
def isQuadrilateral(fem):
return any(fem._cell._cellname in x for x in ["vertex", "interval", "quadrilateral", "hexalateral"])
return any(fem._cell._cellname in x for x in ["vertex", "interval", "quadrilateral", "hexahedron"])
def isPk(fem):
......@@ -146,7 +146,7 @@ def name_dimension():
@preamble
def typedef_grid(name):
dim = name_dimension()
if any(_form.ufl_cell().cellname() in x for x in ["vertex", "interval", "quadrilateral", "hexalateral"]):
if any(_form.ufl_cell().cellname() in x for x in ["vertex", "interval", "quadrilateral", "hexahedron"]):
gridt = "Dune::YaspGrid<{}>".format(dim)
include_file("dune/grid/yaspgrid.hh", filetag="driver")
else:
......
......@@ -51,17 +51,16 @@ def TrialFunctions(element):
return split(TrialFunction(element))
_dg0 = FiniteElement("DG", "triangle", 0)
_dg0vec = VectorElement("DG", "triangle", 0)
class Expression(Coefficient):
def __init__(self, expr, is_global=True, on_intersection=False):
def __init__(self, expr, is_global=True, on_intersection=False, cell_type="triangle"):
assert isinstance(expr, str)
self.c_expr = expr
self.is_global = is_global
self.on_intersection = on_intersection
# Avoid ufl complaining about not matching dimension/cells
_dg0 = FiniteElement("DG", cell_type, 0)
# Initialize a coefficient with a dummy finite element map.
Coefficient.__init__(self, _dg0)
......@@ -72,12 +71,15 @@ class Expression(Coefficient):
class VectorExpression(Coefficient):
def __init__(self, expr, is_global=True, on_intersection=False):
def __init__(self, expr, is_global=True, on_intersection=False, cell_type="triangle"):
assert isinstance(expr, str)
self.c_expr = expr
self.is_global = is_global
self.on_intersection = on_intersection
# Avoid ufl complaining about not matching dimension/cells
_dg0vec = VectorElement("DG", cell_type, 0)
# Initialize a coefficient with a dummy finite element map.
Coefficient.__init__(self, _dg0vec)
......
add_subdirectory(dimension-grid-variations)
# Symlink any reference solutions
dune_symlink_to_source_files(FILES poisson_ref.vtu
poisson_dg_ref.vtu
......
#================
# 1D Tests: cg/dg
#================
add_generated_executable(UFLFILE poisson_1d_cg_interval.ufl
TARGET poisson_1d_cg_interval
FORM_COMPILER_ARGS --exact-solution-expression g --compare-dofs 1e-14 --compare-l2errorsquared 1e-7
)
dune_add_system_test(TARGET poisson_1d_cg_interval
INIFILE poisson_1d_cg_interval.mini
)
add_generated_executable(UFLFILE poisson_1d_dg_interval.ufl
TARGET poisson_1d_dg_interval
FORM_COMPILER_ARGS --exact-solution-expression g --compare-dofs 1e-2 --compare-l2errorsquared 1e-7
)
dune_add_system_test(TARGET poisson_1d_dg_interval
INIFILE poisson_1d_dg_interval.mini
)
#========================================
# 2D Tests: cg/dg, triangle/quadrilateral
#========================================
add_generated_executable(UFLFILE poisson_2d_cg_triangle.ufl
TARGET poisson_2d_cg_triangle
FORM_COMPILER_ARGS --exact-solution-expression g --compare-dofs 1e-14 --compare-l2errorsquared 1e-6
)
dune_add_system_test(TARGET poisson_2d_cg_triangle
INIFILE poisson_2d_cg_triangle.mini
)
add_generated_executable(UFLFILE poisson_2d_dg_triangle.ufl
TARGET poisson_2d_dg_triangle
FORM_COMPILER_ARGS --exact-solution-expression g --compare-dofs 1e-1 --compare-l2errorsquared 1e-4
)
dune_add_system_test(TARGET poisson_2d_dg_triangle
INIFILE poisson_2d_dg_triangle.mini
)
add_generated_executable(UFLFILE poisson_2d_cg_quadrilateral.ufl
TARGET poisson_2d_cg_quadrilateral
FORM_COMPILER_ARGS --exact-solution-expression g --compare-dofs 1e-14 --compare-l2errorsquared 1e-6
)
dune_add_system_test(TARGET poisson_2d_cg_quadrilateral
INIFILE poisson_2d_cg_quadrilateral.mini
)
add_generated_executable(UFLFILE poisson_2d_dg_quadrilateral.ufl
TARGET poisson_2d_dg_quadrilateral
FORM_COMPILER_ARGS --exact-solution-expression g --compare-dofs 1e-1 --compare-l2errorsquared 1e-4
)
dune_add_system_test(TARGET poisson_2d_dg_quadrilateral
INIFILE poisson_2d_dg_quadrilateral.mini
)
#========================================
# 3D Tests: cg/dg, tetrahedron/hexahedron
#========================================
add_generated_executable(UFLFILE poisson_3d_cg_tetrahedron.ufl
TARGET poisson_3d_cg_tetrahedron
FORM_COMPILER_ARGS --exact-solution-expression g --compare-dofs 1e-14 --compare-l2errorsquared 1e-4
)
dune_add_system_test(TARGET poisson_3d_cg_tetrahedron
INIFILE poisson_3d_cg_tetrahedron.mini
)
add_generated_executable(UFLFILE poisson_3d_dg_tetrahedron.ufl
TARGET poisson_3d_dg_tetrahedron
FORM_COMPILER_ARGS --exact-solution-expression g --compare-dofs 1e-2 --compare-l2errorsquared 1e-4
)
dune_add_system_test(TARGET poisson_3d_dg_tetrahedron
INIFILE poisson_3d_dg_tetrahedron.mini
)
add_generated_executable(UFLFILE poisson_3d_cg_hexahedron.ufl
TARGET poisson_3d_cg_hexahedron
FORM_COMPILER_ARGS --exact-solution-expression g --compare-dofs 1e-14 --compare-l2errorsquared 1e-4
)
dune_add_system_test(TARGET poisson_3d_cg_hexahedron
INIFILE poisson_3d_cg_hexahedron.mini
)
add_generated_executable(UFLFILE poisson_3d_dg_hexahedron.ufl
TARGET poisson_3d_dg_hexahedron
FORM_COMPILER_ARGS --exact-solution-expression g --compare-dofs 1 --compare-l2errorsquared 1e-3
)
dune_add_system_test(TARGET poisson_3d_dg_hexahedron
INIFILE poisson_3d_dg_hexahedron.mini
)
__name = poisson_1d_cg_interval
cells = 32
extension = 1.
[wrapper.vtkcompare]
name = {__name}
extension = vtu
cell_type = "interval"
f = Expression("return -2.0*x.size();", cell_type=cell_type)
g = Expression("return x.two_norm2();", cell_type=cell_type)
V = FiniteElement("CG", cell_type, 1, dirichlet_expression=g)
u = TrialFunction(V)
v = TestFunction(V)
forms = [(inner(grad(u), grad(v)) - f*v)*dx]
\ No newline at end of file
__name = poisson_1d_dg_interval
cells = 32
extension = 1.
[wrapper.vtkcompare]
name = {__name}
extension = vtu
cell_type = "interval"
f = Expression("return -2.0*x.size();", cell_type=cell_type)
g = Expression("return x.two_norm2();", on_intersection=True, cell_type=cell_type)
V = FiniteElement("DG", cell_type, 1)
u = TrialFunction(V)
v = TestFunction(V)
n = FacetNormal(cell_type)('+')
gamma = 1.0
theta = 1.0
r = inner(grad(u), grad(v))*dx \
+ inner(n, avg(grad(u)))*jump(v)*dS \
+ gamma*jump(u)*jump(v)*dS \
+ theta*jump(u)*inner(avg(grad(v)), n)*dS \
- inner(n, grad(u))*v*ds \
+ gamma*u*v*ds \
- theta*u*inner(grad(v), n)*ds \
- f*v*dx \
+ theta*g*inner(grad(v), n)*ds \
- gamma*g*v*ds
forms = [r]
__name = poisson_2d_cg_quadrilateral
cells = 32 32
extension = 1. 1.
[wrapper.vtkcompare]
name = {__name}
extension = vtu
cell_type = "quadrilateral"
f = Expression("return -2.0*x.size();", cell_type=cell_type)
g = Expression("return x.two_norm2();", cell_type=cell_type)
V = FiniteElement("CG", cell_type, 1, dirichlet_expression=g)
u = TrialFunction(V)
v = TestFunction(V)
forms = [(inner(grad(u), grad(v)) - f*v)*dx]
__name = poisson_2d_cg_triangle
lowerleft = 0.0 0.0
upperright = 1.0 1.0
elements = 32 32
elementType = simplical
[wrapper.vtkcompare]
name = {__name}
extension = vtu
f = Expression("return -2.0*x.size();")
g = Expression("return x.two_norm2();")
V = FiniteElement("CG", "triangle", 1, dirichlet_expression=g)
u = TrialFunction(V)
v = TestFunction(V)
forms = [(inner(grad(u), grad(v)) - f*v)*dx]
\ No newline at end of file
__name = poisson_2d_dg_quadrilateral
cells = 32 32
extension = 1. 1.
[wrapper.vtkcompare]
name = {__name}
extension = vtu
cell_type = "quadrilateral"
f = Expression("return -2.0*x.size();", cell_type=cell_type)
g = Expression("return x.two_norm2();", on_intersection=True, cell_type=cell_type)
V = FiniteElement("DG", cell_type, 1)
u = TrialFunction(V)
v = TestFunction(V)
n = FacetNormal(cell_type)('+')
gamma = 1.0
theta = 1.0
r = inner(grad(u), grad(v))*dx \
+ inner(n, avg(grad(u)))*jump(v)*dS \
+ gamma*jump(u)*jump(v)*dS \
+ theta*jump(u)*inner(avg(grad(v)), n)*dS \
- inner(n, grad(u))*v*ds \
+ gamma*u*v*ds \
- theta*u*inner(grad(v), n)*ds \
- f*v*dx \
+ theta*g*inner(grad(v), n)*ds \
- gamma*g*v*ds
forms = [r]
__name = poisson_2d_dg_triangle
lowerleft = 0.0 0.0
upperright = 1.0 1.0
elements = 32 32
elementType = simplical
[wrapper.vtkcompare]
name = {__name}
extension = vtu
f = Expression("return -2.0*x.size();")
g = Expression("return x.two_norm2();", on_intersection=True)
cell = triangle
V = FiniteElement("DG", cell, 1)
u = TrialFunction(V)
v = TestFunction(V)
n = FacetNormal(cell)('+')
gamma = 1.0
theta = 1.0
r = inner(grad(u), grad(v))*dx \
+ inner(n, avg(grad(u)))*jump(v)*dS \
+ gamma*jump(u)*jump(v)*dS \
+ theta*jump(u)*inner(avg(grad(v)), n)*dS \
- inner(n, grad(u))*v*ds \
+ gamma*u*v*ds \
- theta*u*inner(grad(v), n)*ds \
- f*v*dx \
+ theta*g*inner(grad(v), n)*ds \
- gamma*g*v*ds
forms = [r]
__name = poisson_3d_cg_hexahedron
cells = 8 8 8
extension = 1. 1. 1.
[wrapper.vtkcompare]
name = {__name}
extension = vtu
cell_type = "hexahedron"
f = Expression("return -2.0*x.size();", cell_type=cell_type)
g = Expression("return x.two_norm2();", cell_type=cell_type)
V = FiniteElement("CG", cell_type, 1, dirichlet_expression=g)
u = TrialFunction(V)
v = TestFunction(V)
forms = [(inner(grad(u), grad(v)) - f*v)*dx]
\ No newline at end of file
__name = poisson_3d_cg_tetrahedron
lowerleft = 0.0 0.0 0.0
upperright = 1.0 1.0 1.1
elements = 8 8 8
elementType = simplical
[wrapper.vtkcompare]
name = {__name}
extension = vtu
cell_type = "tetrahedron"
f = Expression("return -2.0*x.size();", cell_type=cell_type)
g = Expression("return x.two_norm2();", cell_type=cell_type)
V = FiniteElement("CG", "tetrahedron", 1, dirichlet_expression=g)
u = TrialFunction(V)
v = TestFunction(V)
forms = [(inner(grad(u), grad(v)) - f*v)*dx]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment