Skip to content
Snippets Groups Projects
Commit bb461d96 authored by Andreas Dedner's avatar Andreas Dedner
Browse files

added some python tests

parent 38e8e53e
No related branches found
No related tags found
1 merge request!140Feature/add python bindings
Pipeline #25985 passed
......@@ -7,3 +7,22 @@ include:
before_script:
- . /duneci/bin/duneci-init-job
- duneci-install-module https://gitlab.dune-project.org/core/dune-common.git
debian-11-gcc-9-17-python:
image: duneci/debian:11
script: duneci-standard-test
variables:
DUNECI_TOOLCHAIN: gcc-9-17
# so we need some variables to build the dune-py module during execution of the first python test:
# we need to find the dune mdoule
DUNE_CONTROL_PATH: /duneci/modules:$CI_PROJECT_DIR
# the position for the dune-py module
DUNE_PY_DIR: /duneci/modules/dune-py
# during dune-py build this variable is used - do know a way to access
# the CMAKE_FLAGS used to build the modules...
DUNE_CMAKE_FLAGS: "CC=gcc-9 CXX=g++-9 -DCMAKE_CXX_FLAGS='-std=c++17 -O2 -g -Wall -fdiagnostics-color=always' -DDUNE_ENABLE_PYTHONBINDINGS=ON -DDUNE_MAX_TEST_CORES=4 -DBUILD_SHARED_LIBS=TRUE -DDUNE_PYTHON_INSTALL_LOCATION=none -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_LATEX=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_Alberta=TRUE -DCMAKE_DISABLE_FIND_PACKAGE_Vc=TRUE -DCMAKE_DISABLE_DOCUMENTATION=TRUE"
# cmake flags we use for all dune moudle - important is that build shared libs is set (need some better way of doing this)
DUNECI_CMAKE_FLAGS: $DUNE_CMAKE_FLAGS
# finally set the python path to all modules
PYTHONPATH: /duneci/modules/dune-common/build-cmake/python:/duneci/modules/dune-geometry/build-cmake/python:$CI_PROJECT_DIR/build-cmake/python
tags: [duneci]
add_subdirectory(geometry)
add_subdirectory(python)
# if Python bindings are enabled, include necessary sub directories.
if( DUNE_ENABLE_PYTHONBINDINGS )
add_subdirectory("python")
endif()
add_subdirectory(geometry)
add_subdirectory(test)
dune_python_add_test(NAME pyrefelement
COMMAND ${PYTHON_EXECUTABLE} refelement.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
LABELS quick)
dune_python_add_test(NAME pygeometrytype
COMMAND ${PYTHON_EXECUTABLE} geometrytype.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
LABELS quick)
dune_python_add_test(NAME pytestquad
COMMAND ${PYTHON_EXECUTABLE} test_quad.py
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
LABELS quick)
from dune.geometry import *
# make sure t can be reconstructed from str(t)
for t in (vertex, line, triangle, quadrilateral, tetrahedron, pyramid, prism, hexahedron):
assert GeometryType(str(t)) == t
for d in range(10):
assert GeometryType(str(simplex(d))) == simplex(d)
assert GeometryType(str(cube(d))) == cube(d)
assert GeometryType(str(none(d))) == none(d)
# make sure simplices with special names can be constructed by general mechanism
for d, t in enumerate((vertex, line, triangle, tetrahedron)):
assert GeometryType("simplex(" + str(d) + ")") == t
assert GeometryType("general( 0, " + str(d) + ")") == t
# make sure cube with special names can be constructed by general mechanism
for d, t in enumerate((vertex, line, quadrilateral, hexahedron)):
assert GeometryType("cube(" + str(d) + ")") == t
assert GeometryType("general( " + str(2**d-1) + ", " + str(d) + ")") == t
from dune.geometry import referenceElement
from dune.geometry import vertex, line, triangle, quadrilateral, tetrahedron, pyramid, prism, hexahedron, none
def test(r):
for codim in range(r.dimension+1):
types = r.types(codim)
if len(types) != r.size(codim):
raise Exception("types tuple has wrong size")
for i in range(len(types)):
if types[i] != r.type(i, codim):
raise Exception("types tuple has wrong content")
for codim in range(r.dimension+1):
positions = r.positions(codim)
if len(positions) != r.size(codim):
raise Exception("positions tuple has wrong size")
for i in range(len(positions)):
if positions[i] != r.position(i, codim):
raise Exception("positions tuple has wrong content")
if r.dimension > 0:
normals = r.integrationOuterNormals
if len(normals) != r.size(1):
raise Exception("integrationOuterNormals has wrong size")
for i in range(len(normals)):
if normals[i] != r.integrationOuterNormal(i):
raise Exception("integrationOuterNormals has wrong content")
test(referenceElement(vertex))
test(referenceElement(line))
test(referenceElement(triangle))
test(referenceElement(quadrilateral))
test(referenceElement(tetrahedron))
test(referenceElement(pyramid))
test(referenceElement(prism))
test(referenceElement(hexahedron))
for dim in range(4):
if referenceElement(none(dim)) is not None:
raise Exception("got reference element for geometry type none")
import time, math, numpy
import dune.geometry as geo
def monomial(p):
def function(point):
return sum( x**p for x in point)
return function
result = {3: # integral for sum_i x_i^p over reference element
{geo.line: 1./4.,
geo.triangle: 0.1,
geo.quadrilateral: 1./2.,
geo.tetrahedron: 1./40.,
geo.pyramid: None,
geo.prism: None,
geo.hexahedron: 3./4.,
},
4:
{geo.line: 1./5.,
geo.triangle: 1./15.,
geo.quadrilateral: 2./5.,
geo.tetrahedron: 1./70.,
geo.pyramid: None,
geo.prism: None,
geo.hexahedron: 3./5.,
},
}
for order in [3,4]:
rules = geo.quadratureRules(order)
p = monomial(order)
for t in (geo.line, geo.triangle, geo.quadrilateral,
geo.tetrahedron, geo.pyramid, geo.prism, geo.hexahedron):
value1 = 0
for q in rules(t):
value1 += p(q.position)*q.weight
hatxs, hatws = rules(t).get()
value2 = numpy.sum(p(hatxs) * hatws, axis=-1)
# print(order,t,value2)
assert abs(value1-value2)<1e-14
if result[order][t] is not None:
assert abs(result[order][t] - value1)<1e-12
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