From: Luca Heltai Date: Thu, 16 Jul 2020 18:03:26 +0000 (+0200) Subject: Added simple non local FE. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d97f09e6d5b1462464dff329b1653a0f5d02cc93;p=dealii.git Added simple non local FE. --- diff --git a/tests/non_local/CMakeLists.txt b/tests/non_local/CMakeLists.txt new file mode 100644 index 0000000000..d33eafa20b --- /dev/null +++ b/tests/non_local/CMakeLists.txt @@ -0,0 +1,4 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) +INCLUDE(../setup_testsubproject.cmake) +PROJECT(testsuite CXX) +DEAL_II_PICKUP_TESTS() diff --git a/tests/non_local/fe_q1_nonlocal.h b/tests/non_local/fe_q1_nonlocal.h new file mode 100644 index 0000000000..0e1a518af1 --- /dev/null +++ b/tests/non_local/fe_q1_nonlocal.h @@ -0,0 +1,68 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2020 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. +// +// --------------------------------------------------------------------- + + +// Define an FE_Q1_Nonlocal finite element, where dofs are not distributed +// on vertices (with dpo[0]=1) but on cells (with dpo[dim+2]=vertices_per_cell) +// and the non-local dof numeration is based on the vertex id + +#include +#include + +#include + +#include + +#include "../tests.h" + +template +std::vector +get_dpo_vector() +{ + std::vector dpo(dim + 2, 0.0); + dpo[dim + 1] = GeometryInfo::vertices_per_cell; + return dpo; +} + +template +class FE_Q1_Nonlocal : public FE_Q_Base, dim, dim> +{ +public: + FE_Q1_Nonlocal() + : FE_Q_Base, dim, dim>( + TensorProductPolynomials( + Polynomials::generate_complete_Lagrange_basis( + QGaussLobatto<1>(2).get_points())), + FiniteElementData(get_dpo_vector(), + 1, + 1, + FiniteElementData::H1), + std::vector(1, false)) + { + this->unit_support_points = QTrapez().get_points(); + } + + virtual std::unique_ptr> + clone() const override + { + return std::make_unique>(); + } + + virtual std::string + get_name() const override + { + return "FE_Q_Nonlocal"; + } +}; diff --git a/tests/non_local/fe_q1_nonlocal_01.cc b/tests/non_local/fe_q1_nonlocal_01.cc new file mode 100644 index 0000000000..5633da7015 --- /dev/null +++ b/tests/non_local/fe_q1_nonlocal_01.cc @@ -0,0 +1,49 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 1998 - 2018 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. +// +// --------------------------------------------------------------------- + +// build an FE_Q1_Nonlocal finite element, where dofs are not distributed +// on vertices (with dpo[0]=1) but on cells (with dpo[dim+2]=vertices_per_cell) + +#include +#include + +#include + +#include + +#include "../tests.h" + +#include "../non_local/fe_q1_nonlocal.h" + +template +void +test() +{ + FE_Q1_Nonlocal fe; + if (fe.n_dofs_per_cell() != GeometryInfo::vertices_per_cell) + deallog << "Not OK" << std::endl; + else + deallog << "OK" << std::endl; +} + +int +main() +{ + initlog(); + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/tests/non_local/fe_q1_nonlocal_01.output b/tests/non_local/fe_q1_nonlocal_01.output new file mode 100644 index 0000000000..fb71de2867 --- /dev/null +++ b/tests/non_local/fe_q1_nonlocal_01.output @@ -0,0 +1,4 @@ + +DEAL::OK +DEAL::OK +DEAL::OK diff --git a/tests/non_local/fe_q1_nonlocal_02.cc b/tests/non_local/fe_q1_nonlocal_02.cc new file mode 100644 index 0000000000..a490caa192 --- /dev/null +++ b/tests/non_local/fe_q1_nonlocal_02.cc @@ -0,0 +1,58 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 1998 - 2018 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. +// +// --------------------------------------------------------------------- + +// build an FE_Q1_Nonlocal finite element, and check identities. + +#include + +#include +#include + +#include + +#include "../tests.h" + +#include "../non_local/fe_q1_nonlocal.h" + +template +void +test() +{ + deallog << "DIM: " << dim << std::endl << std::endl; + FE_Q1_Nonlocal fe; + // Check that the basis functions are what we expect + const auto &quad = fe.get_unit_support_points(); + + for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i) + { + deallog << "Shape[" << i << "]: "; + for (unsigned int q = 0; q < quad.size(); ++q) + { + const auto p = quad[q]; + deallog << int(fe.shape_value(i, p)) << " "; + } + deallog << std::endl; + } +} + +int +main() +{ + initlog(); + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/tests/non_local/fe_q1_nonlocal_02.output b/tests/non_local/fe_q1_nonlocal_02.output new file mode 100644 index 0000000000..01dc4dac8b --- /dev/null +++ b/tests/non_local/fe_q1_nonlocal_02.output @@ -0,0 +1,21 @@ + +DEAL::DIM: 1 +DEAL:: +DEAL::Shape[0]: 1 0 +DEAL::Shape[1]: 0 1 +DEAL::DIM: 2 +DEAL:: +DEAL::Shape[0]: 1 0 0 0 +DEAL::Shape[1]: 0 1 0 0 +DEAL::Shape[2]: 0 0 1 0 +DEAL::Shape[3]: 0 0 0 1 +DEAL::DIM: 3 +DEAL:: +DEAL::Shape[0]: 1 0 0 0 0 0 0 0 +DEAL::Shape[1]: 0 1 0 0 0 0 0 0 +DEAL::Shape[2]: 0 0 1 0 0 0 0 0 +DEAL::Shape[3]: 0 0 0 1 0 0 0 0 +DEAL::Shape[4]: 0 0 0 0 1 0 0 0 +DEAL::Shape[5]: 0 0 0 0 0 1 0 0 +DEAL::Shape[6]: 0 0 0 0 0 0 1 0 +DEAL::Shape[7]: 0 0 0 0 0 0 0 1 diff --git a/tests/non_local/fe_q1_nonlocal_03.cc b/tests/non_local/fe_q1_nonlocal_03.cc new file mode 100644 index 0000000000..5746bba088 --- /dev/null +++ b/tests/non_local/fe_q1_nonlocal_03.cc @@ -0,0 +1,55 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 1998 - 2018 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. +// +// --------------------------------------------------------------------- + +// build an FE_Q1_Nonlocal finite element, and distribute dofs on a simple +// Triangulation. + +#include + +#include +#include + +#include + +#include "../tests.h" + +#include "../non_local/fe_q1_nonlocal.h" + +template +void +test() +{ + FE_Q1_Nonlocal fe; + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(1); + DoFHandler dh(tria); + dh.distribute_dofs(fe); + + if (dh.n_dofs() != tria.n_vertices()) + deallog << "Not OK" << std::endl; + else + deallog << "OK" << std::endl; +} + +int +main() +{ + initlog(); + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/tests/non_local/fe_q1_nonlocal_03.output b/tests/non_local/fe_q1_nonlocal_03.output new file mode 100644 index 0000000000..e69de29bb2