From b6cc3503531def340038febf90f0e191bad4af3b Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 5 May 2021 09:58:46 -0600 Subject: [PATCH] Add a test. --- tests/fe/nedelec_projection_01.cc | 155 ++++++++++++++++++++++++++ tests/fe/nedelec_projection_01.output | 29 +++++ 2 files changed, 184 insertions(+) create mode 100644 tests/fe/nedelec_projection_01.cc create mode 100644 tests/fe/nedelec_projection_01.output diff --git a/tests/fe/nedelec_projection_01.cc b/tests/fe/nedelec_projection_01.cc new file mode 100644 index 0000000000..802d3525e0 --- /dev/null +++ b/tests/fe/nedelec_projection_01.cc @@ -0,0 +1,155 @@ +// --------------------------------------------------------------------- +// +// 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 VectorTools::project_boundary_values_curl_conforming_l2 +// also works on systems of Nedelec elements. This is a variation of a +// testcase by Abbas Ballout posted to the mailing list. + +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include + +#include + +#include "../tests.h" + + + +template +class BoundaryValues : public Function +{ +public: + BoundaryValues() + : Function(2 * dim) + {} + + void + vector_value_list(const std::vector> &points, + std::vector> & values) const override + { + for (unsigned int i = 0; i < points.size(); ++i) + { + values[i][0] = 1.0; + values[i][1] = 0.0; + if (dim == 3) + values[i][2] = 0.0; + values[i][dim + 0] = 1.0; + values[i][dim + 1] = 0.0; + if (dim == 3) + values[i][dim + 2] = 0.0; + } + } +}; + + + +template +void +test() +{ + deallog << "*** dim=" << dim << std::endl; + + Triangulation triangulation; + + GridGenerator::hyper_cube(triangulation); + triangulation.begin_active() + ->face(dim == 2 ? 2 : 4) + ->set_boundary_id(1); // set the 4th boundary id to 1 to apply dirichlet BC + + DoFHandler dof_handler(triangulation); + FESystem fe(FE_Nedelec(0), 2); + dof_handler.distribute_dofs(fe); + DoFRenumbering::component_wise(dof_handler); + + // First try to apply constraints only to the first 3 components + { + deallog << "Check 1:" << std::endl; + + AffineConstraints constraints; + + VectorTools::project_boundary_values_curl_conforming_l2( + dof_handler, + 0, // starting compenent + BoundaryValues(), + 1, // face ID1 + constraints, + StaticMappingQ1::mapping); + constraints.close(); + constraints.print(deallog.get_file_stream()); + } + + // Try again with just the second 3 components + { + deallog << "Check 2:" << std::endl; + + AffineConstraints constraints; + + VectorTools::project_boundary_values_curl_conforming_l2( + dof_handler, + dim, // starting component + BoundaryValues(), + 1, // face ID1 + constraints, + StaticMappingQ1::mapping); + constraints.close(); + constraints.print(deallog.get_file_stream()); + } + + // And now with all + { + deallog << "Check 3:" << std::endl; + + AffineConstraints constraints; + + VectorTools::project_boundary_values_curl_conforming_l2( + dof_handler, + 0, // starting compenent + BoundaryValues(), + 1, // face ID1 + constraints, + StaticMappingQ1::mapping); + VectorTools::project_boundary_values_curl_conforming_l2( + dof_handler, + dim, // starting compenent + BoundaryValues(), + 1, // face ID1 + constraints, + StaticMappingQ1::mapping); + constraints.close(); + constraints.print(deallog.get_file_stream()); + } +} + + + +int +main() +{ + initlog(); + + test<2>(); + test<3>(); +} diff --git a/tests/fe/nedelec_projection_01.output b/tests/fe/nedelec_projection_01.output new file mode 100644 index 0000000000..39c9bdadfe --- /dev/null +++ b/tests/fe/nedelec_projection_01.output @@ -0,0 +1,29 @@ + +DEAL::*** dim=2 +DEAL::Check 1: + 2 = 1.00000 +DEAL::Check 2: + 6 = 1.00000 +DEAL::Check 3: + 2 = 1.00000 + 6 = 1.00000 +DEAL::*** dim=3 +DEAL::Check 1: + 0 = 0 + 1 = 0 + 2 = 1.00000 + 3 = 1.00000 +DEAL::Check 2: + 12 = 0 + 13 = 0 + 14 = 1.00000 + 15 = 1.00000 +DEAL::Check 3: + 0 = 0 + 1 = 0 + 2 = 1.00000 + 3 = 1.00000 + 12 = 0 + 13 = 0 + 14 = 1.00000 + 15 = 1.00000 -- 2.39.5