diff --git a/dune/gdt/test/interpolations/boundary.hh b/dune/gdt/test/interpolations/boundary.hh new file mode 100644 index 0000000000000000000000000000000000000000..b16e758de4181ab0255f3f245b7ed916db4128fb --- /dev/null +++ b/dune/gdt/test/interpolations/boundary.hh @@ -0,0 +1,102 @@ +// This file is part of the dune-gdt project: +// https://github.com/dune-community/dune-gdt +// Copyright 2010-2018 dune-gdt 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) + +#ifndef DUNE_GDT_TEST_INTERPOLATIONS_BOUNDARY_HH +#define DUNE_GDT_TEST_INTERPOLATIONS_BOUNDARY_HH + +#include <dune/xt/common/fvector.hh> +#include <dune/xt/common/string.hh> +#include <dune/xt/common/test/gtest/gtest.h> +#include <dune/xt/grid/boundaryinfo/normalbased.hh> +#include <dune/xt/grid/gridprovider/cube.hh> +#include <dune/xt/grid/structuredgridfactory.hh> +#include <dune/xt/grid/type_traits.hh> +#include <dune/xt/functions/constant.hh> +#include <dune/xt/functions/generic/function.hh> + +#include <dune/gdt/discretefunction/default.hh> +#include <dune/gdt/interpolations/boundary.hh> +#include <dune/gdt/local/bilinear-forms/integrals.hh> +#include <dune/gdt/local/integrands/product.hh> +#include <dune/gdt/norms.hh> +#include <dune/gdt/spaces/h1/continuous-lagrange.hh> + +namespace Dune { +namespace GDT { +namespace Test { + + +template <class G> +struct BoundaryInterpolationOnLeafViewTest : public ::testing::Test +{ + static_assert(XT::Grid::is_grid<G>::value, ""); + + using GV = typename G::LeafGridView; + using D = typename GV::ctype; + static const constexpr size_t d = GV::dimension; + using E = XT::Grid::extract_entity_t<GV>; + using I = XT::Grid::extract_intersection_t<GV>; + using M = XT::LA::IstlRowMajorSparseMatrix<double>; + using V = XT::LA::IstlDenseVector<double>; + + std::shared_ptr<XT::Grid::GridProvider<G>> grid_provider; + std::shared_ptr<XT::Functions::ConstantFunction<d>> source; + std::shared_ptr<XT::Grid::NormalBasedBoundaryInfo<I>> boundary_info; + std::shared_ptr<ContinuousLagrangeSpace<GV>> space; + std::shared_ptr<DiscreteFunction<V, GV>> range; + std::shared_ptr<XT::Functions::GenericFunction<d>> expected_range; + + virtual std::shared_ptr<XT::Grid::GridProvider<G>> make_grid() + { + return std::make_shared<XT::Grid::GridProvider<G>>( + XT::Grid::make_cube_grid<G>(XT::Common::from_string<FieldVector<double, d>>("[-1 0 0 0]"), + XT::Common::from_string<FieldVector<double, d>>("[1 1 1 1]"), + XT::Common::from_string<std::array<unsigned int, d>>("[2 1 1 1]"))); + } + + void SetUp() override + { + grid_provider = make_grid(); + space = + std::make_shared<ContinuousLagrangeSpace<GV>>(make_continuous_lagrange_space(grid_provider->leaf_view(), 1)); + source = std::make_shared<XT::Functions::ConstantFunction<d>>(1.); + range = std::make_shared<DiscreteFunction<V, GV>>(*space); + expected_range = std::make_shared<XT::Functions::GenericFunction<d>>([](const auto&) { return 1; }, + [](const auto& x, const auto&) { + if (x[0] > 0) + return x[0]; + else + return 0.; + }); + boundary_info = std::make_shared<XT::Grid::NormalBasedBoundaryInfo<I>>(); + boundary_info->register_new_normal(XT::Common::from_string<FieldVector<double, d>>("[1 0 0 0]"), + new XT::Grid::DirichletBoundary()); + } // ... SetUp(...) + + void interpolates_correctly() + { + interpolate(source->template as_grid_function<E>(), + *range, + space->grid_view(), + *boundary_info, + XT::Grid::DirichletBoundary()); + const auto expected_L2_error = 1e-15; + const auto l2_error = compute_l2_norm(space->grid_view(), expected_range->template as_grid_function<E>() - *range); + EXPECT_LT(l2_error, expected_L2_error) + << "XT::Common::Test::get_unique_test_name() = '" << XT::Common::Test::get_unique_test_name() << "'"; + + } // ... interpolates_correctly(...) +}; // struct BoundaryInterpolationOnLeafViewTest + + +} // namespace Test +} // namespace GDT +} // namespace Dune + +#endif // DUNE_GDT_TEST_INTERPOLATIONS_BOUNDARY_HH diff --git a/dune/gdt/test/interpolations/interpolations_boundary__cubic_2d_grids.cc b/dune/gdt/test/interpolations/interpolations_boundary__cubic_2d_grids.cc new file mode 100644 index 0000000000000000000000000000000000000000..592f326c2841b47188de525c62425ac6cf4c4003 --- /dev/null +++ b/dune/gdt/test/interpolations/interpolations_boundary__cubic_2d_grids.cc @@ -0,0 +1,35 @@ +// This file is part of the dune-gdt project: +// https://github.com/dune-community/dune-gdt +// Copyright 2010-2018 dune-gdt 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) + +#include <dune/xt/common/test/main.hxx> // <- this one has to come first (includes the config.h)! + +#include <dune/xt/grid/grids.hh> + +#include "boundary.hh" + + +using Cubic2dGrids = ::testing::Types<YASP_2D_EQUIDISTANT_OFFSET +#if HAVE_DUNE_ALUGRID + , + ALU_2D_CUBE +#endif +#if HAVE_DUNE_UGGRID + , + UG_2D +#endif + >; + + +template <class G> +using BoundaryInterpolation = Dune::GDT::Test::BoundaryInterpolationOnLeafViewTest<G>; +TYPED_TEST_CASE(BoundaryInterpolation, Cubic2dGrids); +TYPED_TEST(BoundaryInterpolation, interpolates_correctly) +{ + this->interpolates_correctly(); +} diff --git a/dune/gdt/test/interpolations/interpolations_boundary__cubic_3d_grids.cc b/dune/gdt/test/interpolations/interpolations_boundary__cubic_3d_grids.cc new file mode 100644 index 0000000000000000000000000000000000000000..8e443daa4327709a5e7d62776e0f5f29ba73ac45 --- /dev/null +++ b/dune/gdt/test/interpolations/interpolations_boundary__cubic_3d_grids.cc @@ -0,0 +1,35 @@ +// This file is part of the dune-gdt project: +// https://github.com/dune-community/dune-gdt +// Copyright 2010-2018 dune-gdt 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) + +#include <dune/xt/common/test/main.hxx> // <- this one has to come first (includes the config.h)! + +#include <dune/xt/grid/grids.hh> + +#include "boundary.hh" + + +using Cubic3dGrids = ::testing::Types<YASP_3D_EQUIDISTANT_OFFSET +#if HAVE_DUNE_ALUGRID + , + ALU_3D_CUBE +#endif +#if HAVE_DUNE_UGGRID + , + UG_3D +#endif + >; + + +template <class G> +using BoundaryInterpolation = Dune::GDT::Test::BoundaryInterpolationOnLeafViewTest<G>; +TYPED_TEST_CASE(BoundaryInterpolation, Cubic3dGrids); +TYPED_TEST(BoundaryInterpolation, interpolates_correctly) +{ + this->interpolates_correctly(); +} diff --git a/dune/gdt/test/interpolations/interpolations_boundary__cubic_4d_grids.cc b/dune/gdt/test/interpolations/interpolations_boundary__cubic_4d_grids.cc new file mode 100644 index 0000000000000000000000000000000000000000..137b72ac1f46add550682368fd67a0b9df78d8bc --- /dev/null +++ b/dune/gdt/test/interpolations/interpolations_boundary__cubic_4d_grids.cc @@ -0,0 +1,26 @@ +// This file is part of the dune-gdt project: +// https://github.com/dune-community/dune-gdt +// Copyright 2010-2018 dune-gdt 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) + +#include <dune/xt/common/test/main.hxx> // <- this one has to come first (includes the config.h)! + +#include <dune/xt/grid/grids.hh> + +#include "boundary.hh" + + +using Cubic4dGrids = ::testing::Types<YASP_4D_EQUIDISTANT_OFFSET>; + + +template <class G> +using BoundaryInterpolation = Dune::GDT::Test::BoundaryInterpolationOnLeafViewTest<G>; +TYPED_TEST_CASE(BoundaryInterpolation, Cubic4dGrids); +TYPED_TEST(BoundaryInterpolation, interpolates_correctly) +{ + this->interpolates_correctly(); +} diff --git a/dune/gdt/test/interpolations/interpolations_boundary__simplicial_1d_grids.cc b/dune/gdt/test/interpolations/interpolations_boundary__simplicial_1d_grids.cc new file mode 100644 index 0000000000000000000000000000000000000000..61bc231b0b4d714350f79a95258aa682918ba873 --- /dev/null +++ b/dune/gdt/test/interpolations/interpolations_boundary__simplicial_1d_grids.cc @@ -0,0 +1,26 @@ +// This file is part of the dune-gdt project: +// https://github.com/dune-community/dune-gdt +// Copyright 2010-2018 dune-gdt 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) + +#include <dune/xt/common/test/main.hxx> // <- this one has to come first (includes the config.h)! + +#include <dune/xt/grid/grids.hh> + +#include "boundary.hh" + + +using Simplicial1dGrids = ::testing::Types<ONED_1D, YASP_1D_EQUIDISTANT_OFFSET>; + + +template <class G> +using BoundaryInterpolation = Dune::GDT::Test::BoundaryInterpolationOnLeafViewTest<G>; +TYPED_TEST_CASE(BoundaryInterpolation, Simplicial1dGrids); +TYPED_TEST(BoundaryInterpolation, interpolates_correctly) +{ + this->interpolates_correctly(); +} diff --git a/dune/gdt/test/interpolations/interpolations_boundary__simplicial_2d_grids.cc b/dune/gdt/test/interpolations/interpolations_boundary__simplicial_2d_grids.cc new file mode 100644 index 0000000000000000000000000000000000000000..cd7bbc0c9f9239e02a8156958718dcb7c0ac51f9 --- /dev/null +++ b/dune/gdt/test/interpolations/interpolations_boundary__simplicial_2d_grids.cc @@ -0,0 +1,37 @@ +// This file is part of the dune-gdt project: +// https://github.com/dune-community/dune-gdt +// Copyright 2010-2018 dune-gdt 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) + +#include <dune/xt/common/test/main.hxx> // <- this one has to come first (includes the config.h)! + +#include <dune/xt/grid/grids.hh> + +#include "boundary.hh" + + +using Simplicial2dGrids = ::testing::Types< +#if HAVE_DUNE_ALUGRID + ALU_2D_SIMPLEX_CONFORMING, + ALU_2D_SIMPLEX_NONCONFORMING +#endif +#if HAVE_DUNE_ALUGRID && HAVE_DUNE_UGGRID + , +#endif +#if HAVE_DUNE_UGGRID + UG_2D +#endif + >; + + +template <class G> +using BoundaryInterpolation = Dune::GDT::Test::BoundaryInterpolationOnLeafViewTest<G>; +TYPED_TEST_CASE(BoundaryInterpolation, Simplicial2dGrids); +TYPED_TEST(BoundaryInterpolation, interpolates_correctly) +{ + this->interpolates_correctly(); +} diff --git a/dune/gdt/test/interpolations/interpolations_boundary__simplicial_3d_grids.cc b/dune/gdt/test/interpolations/interpolations_boundary__simplicial_3d_grids.cc new file mode 100644 index 0000000000000000000000000000000000000000..2522bafeb107f298b7674063ab1fe27ec5779a5d --- /dev/null +++ b/dune/gdt/test/interpolations/interpolations_boundary__simplicial_3d_grids.cc @@ -0,0 +1,37 @@ +// This file is part of the dune-gdt project: +// https://github.com/dune-community/dune-gdt +// Copyright 2010-2018 dune-gdt 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) + +#include <dune/xt/common/test/main.hxx> // <- this one has to come first (includes the config.h)! + +#include <dune/xt/grid/grids.hh> + +#include "boundary.hh" + + +using Simplicial3dGrids = ::testing::Types< +#if HAVE_DUNE_ALUGRID + ALU_3D_SIMPLEX_CONFORMING, + ALU_3D_SIMPLEX_NONCONFORMING +#endif +#if HAVE_DUNE_ALUGRID && HAVE_DUNE_UGGRID + , +#endif +#if HAVE_DUNE_UGGRID + UG_3D +#endif + >; + + +template <class G> +using BoundaryInterpolation = Dune::GDT::Test::BoundaryInterpolationOnLeafViewTest<G>; +TYPED_TEST_CASE(BoundaryInterpolation, Simplicial3dGrids); +TYPED_TEST(BoundaryInterpolation, interpolates_correctly) +{ + this->interpolates_correctly(); +}