Skip to content
Snippets Groups Projects
Commit c044c846 authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[python|grid] add simple intersection test

parent 971ab377
No related branches found
No related tags found
1 merge request!20Update bindings
Pipeline #62326 failed
......@@ -18,3 +18,4 @@ add_subdirectory(common)
add_subdirectory(functions)
add_subdirectory(grid)
add_subdirectory(la)
add_subdirectory(test)
# ~~~
# This file is part of the dune-xt project:
# https://github.com/dune-community/dune-xt
# Copyright 2009-2020 dune-xt developers and contributors. All rights reserved.
# License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
# or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
# with "runtime exception" (http://www.dune-project.org/license.html)
# Authors:
# Felix Schindler (2020)
# ~~~
dune_pybindxi_add_module(_test_grid_intersection EXCLUDE_FROM_ALL grid_intersection.cc)
# ~~~
# This file is part of the dune-xt project:
# https://github.com/dune-community/dune-xt
# Copyright 2009-2020 dune-xt developers and contributors. All rights reserved.
# License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
# or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
# with "runtime exception" (http://www.dune-project.org/license.html)
# Authors:
# Felix Schindler (2020)
# ~~~
// This file is part of the dune-xt project:
// https://github.com/dune-community/dune-xt
// Copyright 2009-2020 dune-xt developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
// or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
// with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
// Felix Schindler (2019)
// René Fritze (2018 - 2019)
// Tobias Leibner (2020)
#include "config.h"
#include <dune/pybindxi/pybind11.h>
#include <dune/pybindxi/functional.h>
#include <python/dune/xt/common/bindings.hh>
#include <python/dune/xt/common/exceptions.bindings.hh>
#include <dune/xt/grid/grids.hh>
#include <dune/xt/grid/gridprovider/provider.hh>
PYBIND11_MODULE(_test_grid_intersection, m)
{
namespace py = pybind11;
using namespace pybind11::literals;
using namespace Dune::XT;
using G = GRID_2D;
using I = Grid::extract_intersection_t<typename G::LeafGridView>;
py::module::import("dune.xt.common");
py::module::import("dune.xt.grid");
m.def("call_on_each_intersection", [](Grid::GridProvider<G>& grid, std::function<void(const I&)> generic_function) {
auto gv = grid.leaf_view();
for (auto&& element : elements(gv))
for (auto&& intersection : intersections(gv, element))
generic_function(intersection);
});
}
# ~~~
# This file is part of the dune-xt project:
# https://github.com/dune-community/dune-xt
# Copyright 2009-2020 dune-xt developers and contributors. All rights reserved.
# License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
# or GPL-2.0+ (http://opensource.org/licenses/gpl-license)
# with "runtime exception" (http://www.dune-project.org/license.html)
# Authors:
# Felix Schindler (2016 - 2017)
# René Fritze (2018 - 2019)
# Tim Keil (2018)
# Tobias Leibner (2018 - 2020)
# ~~~
import pytest
from dune.xt.grid import Dim, Cube, make_cube_grid
from dune.xt.test._test_grid_intersection import call_on_each_intersection
def test_print():
grid = make_cube_grid(Dim(2), Cube(), [0, 0], [1, 1], [2, 2])
call_on_each_intersection(grid, lambda intersection: print(intersection))
def test_boundary():
grid = make_cube_grid(Dim(2), Cube(), [0, 0], [1, 1], [2, 2])
call_on_each_intersection(grid, lambda intersection: print(intersection.boundary))
def test_boundary_segment_index():
grid = make_cube_grid(Dim(2), Cube(), [0, 0], [1, 1], [2, 2])
call_on_each_intersection(grid, lambda intersection: print(intersection.boundary_segment_index))
def test_neighbor():
grid = make_cube_grid(Dim(2), Cube(), [0, 0], [1, 1], [2, 2])
call_on_each_intersection(grid, lambda intersection: print(intersection.neighbor))
def test_index_in_inside():
grid = make_cube_grid(Dim(2), Cube(), [0, 0], [1, 1], [2, 2])
call_on_each_intersection(grid, lambda intersection: print(intersection.index_in_inside))
def test_index_in_outside():
grid = make_cube_grid(Dim(2), Cube(), [0, 0], [1, 1], [2, 2])
call_on_each_intersection(grid, lambda intersection: print(intersection.index_in_outside))
def test_center_unit_outer_normal():
grid = make_cube_grid(Dim(2), Cube(), [0, 0], [1, 1], [2, 2])
call_on_each_intersection(grid, lambda intersection: print(intersection.center_unit_outer_normal))
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