From d492fd9b2c1bdeb7cdc740485c6eb1d7bb7b0453 Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Sun, 9 Jan 2022 08:36:58 +0100 Subject: [PATCH] Add some more tests --- tests/meshworker/scratch_data_09a_hp.cc | 110 ++++++++++++++++++ tests/meshworker/scratch_data_09a_hp.output | 14 +++ tests/meshworker/scratch_data_09b_hp.cc | 120 ++++++++++++++++++++ tests/meshworker/scratch_data_09b_hp.output | 11 ++ tests/meshworker/scratch_data_09c_hp.cc | 110 ++++++++++++++++++ tests/meshworker/scratch_data_09c_hp.output | 10 ++ tests/meshworker/scratch_data_09d_hp.cc | 109 ++++++++++++++++++ tests/meshworker/scratch_data_09d_hp.output | 8 ++ 8 files changed, 492 insertions(+) create mode 100644 tests/meshworker/scratch_data_09a_hp.cc create mode 100644 tests/meshworker/scratch_data_09a_hp.output create mode 100644 tests/meshworker/scratch_data_09b_hp.cc create mode 100644 tests/meshworker/scratch_data_09b_hp.output create mode 100644 tests/meshworker/scratch_data_09c_hp.cc create mode 100644 tests/meshworker/scratch_data_09c_hp.output create mode 100644 tests/meshworker/scratch_data_09d_hp.cc create mode 100644 tests/meshworker/scratch_data_09d_hp.output diff --git a/tests/meshworker/scratch_data_09a_hp.cc b/tests/meshworker/scratch_data_09a_hp.cc new file mode 100644 index 0000000000..73710d854e --- /dev/null +++ b/tests/meshworker/scratch_data_09a_hp.cc @@ -0,0 +1,110 @@ +/* --------------------------------------------------------------------- + * + * Copyright (C) 2021 by the deal.II authors + * + * This file is part of the deal.II library. + * + * The deal.II library is free software; you can use it, redistribute + * it, and/or modify it under the terms of the GNU Lesser General + * Public License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * The full text of the license can be found in the file LICENSE.md at + * the top level directory of deal.II. + * + * --------------------------------------------------------------------- + */ + +// Check that ScratchData returns the correct solution values, gradients, etc. +// - Scalar valued FE +// - hp variant + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include + +#include "../tests.h" + + +template +void +run(const ExtractorType &extractor) +{ + LogStream::Prefix prefix("Dim " + Utilities::to_string(dim)); + std::cout << "Dim: " << dim << std::endl; + + hp::FECollection fe(FE_Q(1), + FE_Q(3)); + hp::QCollection qf_cell(QGauss(fe[0].degree + 1), + QGauss(fe[1].degree + 1)); + hp::QCollection qf_face(QGauss(fe[0].degree + 1), + QGauss(fe[1].degree + 1)); + + Triangulation triangulation; + GridGenerator::hyper_cube(triangulation); + + DoFHandler dof_handler(triangulation); + dof_handler.begin_active()->set_active_fe_index(1); + dof_handler.distribute_dofs(fe); + + Vector solution(dof_handler.n_dofs()); + VectorTools::interpolate(dof_handler, + Functions::CosineFunction( + fe.n_components()), + solution); + + const UpdateFlags update_flags = + update_values | update_gradients | update_hessians | update_3rd_derivatives; + MeshWorker::ScratchData scratch_data(fe, + qf_cell, + update_flags); + + const auto cell = dof_handler.begin_active(); + scratch_data.reinit(cell); + scratch_data.extract_local_dof_values("solution", solution); + + deallog << "Value: " << scratch_data.get_values("solution", extractor)[0] + << std::endl; + deallog << "Gradient: " + << scratch_data.get_gradients("solution", extractor)[0] << std::endl; + deallog << "Hessian: " << scratch_data.get_hessians("solution", extractor)[0] + << std::endl; + deallog << "Laplacian: " + << scratch_data.get_laplacians("solution", extractor)[0] << std::endl; + deallog << "Third derivative: " + << scratch_data.get_third_derivatives("solution", extractor)[0] + << std::endl; + + deallog << "OK" << std::endl; +} + + +int +main(int argc, char *argv[]) +{ + initlog(); + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + FEValuesExtractors::Scalar extractor(0); + + run<2>(extractor); + run<3>(extractor); + + deallog << "OK" << std::endl; +} diff --git a/tests/meshworker/scratch_data_09a_hp.output b/tests/meshworker/scratch_data_09a_hp.output new file mode 100644 index 0000000000..584d7eb272 --- /dev/null +++ b/tests/meshworker/scratch_data_09a_hp.output @@ -0,0 +1,14 @@ + +DEAL:Dim 2::Value: 0.991562 +DEAL:Dim 2::Gradient: -0.158724 -0.158724 +DEAL:Dim 2::Hessian: -2.76461 0.0254076 0.0254076 -2.76461 +DEAL:Dim 2::Laplacian: -5.52923 +DEAL:Dim 2::Third derivative: 2.62952 0.442544 0.442544 0.442544 0.442544 0.442544 0.442544 2.62952 +DEAL:Dim 2::OK +DEAL:Dim 3::Value: 0.987370 +DEAL:Dim 3::Gradient: -0.158053 -0.158053 -0.158053 +DEAL:Dim 3::Hessian: -2.75292 0.0253002 0.0253002 0.0253002 -2.75292 0.0253002 0.0253002 0.0253002 -2.75292 +DEAL:Dim 3::Laplacian: -8.25877 +DEAL:Dim 3::Third derivative: 2.61841 0.440673 0.440673 0.440673 0.440673 -0.00404991 0.440673 -0.00404991 0.440673 0.440673 0.440673 -0.00404991 0.440673 2.61841 0.440673 -0.00404991 0.440673 0.440673 0.440673 -0.00404991 0.440673 -0.00404991 0.440673 0.440673 0.440673 0.440673 2.61841 +DEAL:Dim 3::OK +DEAL::OK diff --git a/tests/meshworker/scratch_data_09b_hp.cc b/tests/meshworker/scratch_data_09b_hp.cc new file mode 100644 index 0000000000..6f3b0350ae --- /dev/null +++ b/tests/meshworker/scratch_data_09b_hp.cc @@ -0,0 +1,120 @@ +/* --------------------------------------------------------------------- + * + * Copyright (C) 2021 by the deal.II authors + * + * This file is part of the deal.II library. + * + * The deal.II library is free software; you can use it, redistribute + * it, and/or modify it under the terms of the GNU Lesser General + * Public License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * The full text of the license can be found in the file LICENSE.md at + * the top level directory of deal.II. + * + * --------------------------------------------------------------------- + */ + +// Check that ScratchData returns the correct solution values, gradients, etc. +// - Vector valued FE +// - hp variant + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include + +#include "../tests.h" + + +template +void +run(const ExtractorType &extractor) +{ + LogStream::Prefix prefix("Dim " + Utilities::to_string(dim)); + std::cout << "Dim: " << dim << std::endl; + + hp::FECollection fe( + FESystem(FE_Q(1), dim), + FESystem(FE_Q(3), dim)); + hp::QCollection qf_cell(QGauss(fe[0].degree + 1), + QGauss(fe[1].degree + 1)); + hp::QCollection qf_face(QGauss(fe[0].degree + 1), + QGauss(fe[1].degree + 1)); + + Triangulation triangulation; + GridGenerator::hyper_cube(triangulation); + + DoFHandler dof_handler(triangulation); + dof_handler.begin_active()->set_active_fe_index(1); + dof_handler.distribute_dofs(fe); + + Vector solution(dof_handler.n_dofs()); + VectorTools::interpolate(dof_handler, + Functions::CosineFunction( + fe.n_components()), + solution); + + const UpdateFlags update_flags = + update_values | update_gradients | update_hessians | update_3rd_derivatives; + MeshWorker::ScratchData scratch_data(fe, + qf_cell, + update_flags); + + const auto cell = dof_handler.begin_active(); + scratch_data.reinit(cell); + scratch_data.extract_local_dof_values("solution", solution); + + deallog << "Value: " << scratch_data.get_values("solution", extractor)[0] + << std::endl; + deallog << "Gradient: " + << scratch_data.get_gradients("solution", extractor)[0] << std::endl; + deallog << "Symmetric gradient: " + << scratch_data.get_symmetric_gradients("solution", extractor)[0] + << std::endl; + deallog << "Divergence: " + << scratch_data.get_divergences("solution", extractor)[0] + << std::endl; + deallog << "Curl: " << scratch_data.get_curls("solution", extractor)[0] + << std::endl; + deallog << "Hessian: " << scratch_data.get_hessians("solution", extractor)[0] + << std::endl; + deallog << "Laplacian: " + << scratch_data.get_laplacians("solution", extractor)[0] << std::endl; + deallog << "Third derivative: " + << scratch_data.get_third_derivatives("solution", extractor)[0] + << std::endl; + + deallog << "OK" << std::endl; +} + + +int +main(int argc, char *argv[]) +{ + initlog(); + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + FEValuesExtractors::Vector extractor(0); + + // Just run in 3d, so we can extract the curl + run<3>(extractor); + + deallog << "OK" << std::endl; +} diff --git a/tests/meshworker/scratch_data_09b_hp.output b/tests/meshworker/scratch_data_09b_hp.output new file mode 100644 index 0000000000..e8d10d04de --- /dev/null +++ b/tests/meshworker/scratch_data_09b_hp.output @@ -0,0 +1,11 @@ + +DEAL:Dim 3::Value: 0.987370 0.987370 0.987370 +DEAL:Dim 3::Gradient: -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 +DEAL:Dim 3::Symmetric gradient: -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 +DEAL:Dim 3::Divergence: -0.474158 +DEAL:Dim 3::Curl: 1.11890e-16 7.88432e-16 6.54858e-16 +DEAL:Dim 3::Hessian: -2.75292 0.0253002 0.0253002 0.0253002 -2.75292 0.0253002 0.0253002 0.0253002 -2.75292 -2.75292 0.0253002 0.0253002 0.0253002 -2.75292 0.0253002 0.0253002 0.0253002 -2.75292 -2.75292 0.0253002 0.0253002 0.0253002 -2.75292 0.0253002 0.0253002 0.0253002 -2.75292 +DEAL:Dim 3::Laplacian: -8.25877 -8.25877 -8.25877 +DEAL:Dim 3::Third derivative: 2.61841 0.440673 0.440673 0.440673 0.440673 -0.00404991 0.440673 -0.00404991 0.440673 0.440673 0.440673 -0.00404991 0.440673 2.61841 0.440673 -0.00404991 0.440673 0.440673 0.440673 -0.00404991 0.440673 -0.00404991 0.440673 0.440673 0.440673 0.440673 2.61841 2.61841 0.440673 0.440673 0.440673 0.440673 -0.00404991 0.440673 -0.00404991 0.440673 0.440673 0.440673 -0.00404991 0.440673 2.61841 0.440673 -0.00404991 0.440673 0.440673 0.440673 -0.00404991 0.440673 -0.00404991 0.440673 0.440673 0.440673 0.440673 2.61841 2.61841 0.440673 0.440673 0.440673 0.440673 -0.00404991 0.440673 -0.00404991 0.440673 0.440673 0.440673 -0.00404991 0.440673 2.61841 0.440673 -0.00404991 0.440673 0.440673 0.440673 -0.00404991 0.440673 -0.00404991 0.440673 0.440673 0.440673 0.440673 2.61841 +DEAL:Dim 3::OK +DEAL::OK diff --git a/tests/meshworker/scratch_data_09c_hp.cc b/tests/meshworker/scratch_data_09c_hp.cc new file mode 100644 index 0000000000..c6285477db --- /dev/null +++ b/tests/meshworker/scratch_data_09c_hp.cc @@ -0,0 +1,110 @@ +/* --------------------------------------------------------------------- + * + * Copyright (C) 2021 by the deal.II authors + * + * This file is part of the deal.II library. + * + * The deal.II library is free software; you can use it, redistribute + * it, and/or modify it under the terms of the GNU Lesser General + * Public License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * The full text of the license can be found in the file LICENSE.md at + * the top level directory of deal.II. + * + * --------------------------------------------------------------------- + */ + +// Check that ScratchData returns the correct solution values, gradients, etc. +// - Tensor valued FE +// - hp variant + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include + +#include "../tests.h" + + +template +void +run(const ExtractorType &extractor) +{ + LogStream::Prefix prefix("Dim " + Utilities::to_string(dim)); + std::cout << "Dim: " << dim << std::endl; + + hp::FECollection fe( + FESystem(FE_Q(1), + Tensor<2, dim>::n_independent_components), + FESystem(FE_Q(3), + Tensor<2, dim>::n_independent_components)); + hp::QCollection qf_cell(QGauss(fe[0].degree + 1), + QGauss(fe[1].degree + 1)); + hp::QCollection qf_face(QGauss(fe[0].degree + 1), + QGauss(fe[1].degree + 1)); + + Triangulation triangulation; + GridGenerator::hyper_cube(triangulation); + + DoFHandler dof_handler(triangulation); + dof_handler.begin_active()->set_active_fe_index(1); + dof_handler.distribute_dofs(fe); + + Vector solution(dof_handler.n_dofs()); + VectorTools::interpolate(dof_handler, + Functions::CosineFunction( + fe.n_components()), + solution); + + const UpdateFlags update_flags = update_values | update_gradients; + MeshWorker::ScratchData scratch_data(fe, + qf_cell, + update_flags); + + const auto cell = dof_handler.begin_active(); + scratch_data.reinit(cell); + scratch_data.extract_local_dof_values("solution", solution); + + deallog << "Value: " << scratch_data.get_values("solution", extractor)[0] + << std::endl; + deallog << "Gradient: " + << scratch_data.get_gradients("solution", extractor)[0] << std::endl; + deallog << "Divergence: " + << scratch_data.get_divergences("solution", extractor)[0] + << std::endl; + + deallog << "OK" << std::endl; +} + + +int +main(int argc, char *argv[]) +{ + initlog(); + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + FEValuesExtractors::Tensor<2> extractor(0); + + run<2>(extractor); + run<3>(extractor); + + deallog << "OK" << std::endl; +} diff --git a/tests/meshworker/scratch_data_09c_hp.output b/tests/meshworker/scratch_data_09c_hp.output new file mode 100644 index 0000000000..7d8e560039 --- /dev/null +++ b/tests/meshworker/scratch_data_09c_hp.output @@ -0,0 +1,10 @@ + +DEAL:Dim 2::Value: 0.991562 0.991562 0.991562 0.991562 +DEAL:Dim 2::Gradient: -0.158724 -0.158724 -0.158724 -0.158724 -0.158724 -0.158724 -0.158724 -0.158724 +DEAL:Dim 2::Divergence: -0.317447 -0.317447 +DEAL:Dim 2::OK +DEAL:Dim 3::Value: 0.987370 0.987370 0.987370 0.987370 0.987370 0.987370 0.987370 0.987370 0.987370 +DEAL:Dim 3::Gradient: -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 -0.158053 +DEAL:Dim 3::Divergence: -0.474158 -0.474158 -0.474158 +DEAL:Dim 3::OK +DEAL::OK diff --git a/tests/meshworker/scratch_data_09d_hp.cc b/tests/meshworker/scratch_data_09d_hp.cc new file mode 100644 index 0000000000..91eea3f80c --- /dev/null +++ b/tests/meshworker/scratch_data_09d_hp.cc @@ -0,0 +1,109 @@ +/* --------------------------------------------------------------------- + * + * Copyright (C) 2021 by the deal.II authors + * + * This file is part of the deal.II library. + * + * The deal.II library is free software; you can use it, redistribute + * it, and/or modify it under the terms of the GNU Lesser General + * Public License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * The full text of the license can be found in the file LICENSE.md at + * the top level directory of deal.II. + * + * --------------------------------------------------------------------- + */ + +// Check that ScratchData returns the correct solution values, gradients, etc. +// - Symmetric tensor valued FE +// - hp variant + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include + +#include "../tests.h" + + +template +void +run(const ExtractorType &extractor) +{ + LogStream::Prefix prefix("Dim " + Utilities::to_string(dim)); + std::cout << "Dim: " << dim << std::endl; + + hp::FECollection fe( + FESystem(FE_Q(1), + SymmetricTensor<2, dim>::n_independent_components), + FESystem(FE_Q(3), + SymmetricTensor<2, dim>::n_independent_components)); + hp::QCollection qf_cell(QGauss(fe[0].degree + 1), + QGauss(fe[1].degree + 1)); + hp::QCollection qf_face(QGauss(fe[0].degree + 1), + QGauss(fe[1].degree + 1)); + + + Triangulation triangulation; + GridGenerator::hyper_cube(triangulation); + + DoFHandler dof_handler(triangulation); + dof_handler.begin_active()->set_active_fe_index(1); + dof_handler.distribute_dofs(fe); + + Vector solution(dof_handler.n_dofs()); + VectorTools::interpolate(dof_handler, + Functions::CosineFunction( + fe.n_components()), + solution); + + const UpdateFlags update_flags = update_values | update_gradients; + MeshWorker::ScratchData scratch_data(fe, + qf_cell, + update_flags); + + const auto cell = dof_handler.begin_active(); + scratch_data.reinit(cell); + scratch_data.extract_local_dof_values("solution", solution); + + deallog << "Value: " << scratch_data.get_values("solution", extractor)[0] + << std::endl; + deallog << "Divergence: " + << scratch_data.get_divergences("solution", extractor)[0] + << std::endl; + + deallog << "OK" << std::endl; +} + + +int +main(int argc, char *argv[]) +{ + initlog(); + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + FEValuesExtractors::SymmetricTensor<2> extractor(0); + + run<2>(extractor); + run<3>(extractor); + + deallog << "OK" << std::endl; +} diff --git a/tests/meshworker/scratch_data_09d_hp.output b/tests/meshworker/scratch_data_09d_hp.output new file mode 100644 index 0000000000..c9b8c573ac --- /dev/null +++ b/tests/meshworker/scratch_data_09d_hp.output @@ -0,0 +1,8 @@ + +DEAL:Dim 2::Value: 0.991562 0.991562 0.991562 0.991562 +DEAL:Dim 2::Divergence: -0.317447 -0.317447 +DEAL:Dim 2::OK +DEAL:Dim 3::Value: 0.987370 0.987370 0.987370 0.987370 0.987370 0.987370 0.987370 0.987370 0.987370 +DEAL:Dim 3::Divergence: -0.474158 -0.474158 -0.474158 +DEAL:Dim 3::OK +DEAL::OK -- 2.39.5