From: Jean-Paul Pelteret Date: Wed, 9 Aug 2017 22:35:01 +0000 (-0600) Subject: Add tests for FEValuesViews::get_function_*_from_local_dof_values X-Git-Tag: v9.0.0-rc1~1291^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e48e75dc542271113e210793f0cb41535e3438d3;p=dealii.git Add tests for FEValuesViews::get_function_*_from_local_dof_values --- diff --git a/tests/fe/fe_values_view_get_function_from_local_dof_values_01.cc b/tests/fe/fe_values_view_get_function_from_local_dof_values_01.cc new file mode 100644 index 0000000000..1f16914f35 --- /dev/null +++ b/tests/fe/fe_values_view_get_function_from_local_dof_values_01.cc @@ -0,0 +1,398 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// Check that FEValuesViews::get_function_*_from_local_dof_values +// works with different number types. + +#include "../tests.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +template +void test_view (const Vector &solution, + const FEValues &fe_values, + const unsigned int &n_q_points, + const ExtractorType &extractor, + const std::vector &local_dof_values); + +// Scalar view +template +void test_view (const Vector &solution, + const FEValues &fe_values, + const unsigned int &n_q_points, + const FEValuesExtractors::Scalar &extractor, + const std::vector &local_dof_values) +{ + typedef typename std::remove_reference::type>::type View; + const View &fe_values_view = fe_values[extractor]; + + // Typedefs + typedef typename View::template OutputType OutputType; + typedef typename ProductType::type value_type; + typedef typename ProductType::type gradient_type; + typedef typename ProductType::type hessian_type; + typedef typename ProductType::type laplacian_type; + typedef typename ProductType::type third_derivative_type; + + // Values + std::vector qp_values_local(n_q_points); + std::vector qp_values_global (n_q_points); + fe_values_view.get_function_values_from_local_dof_values(local_dof_values, qp_values_local); + fe_values_view.get_function_values (solution,qp_values_global); + + // Gradients + std::vector qp_grads_local(n_q_points); + std::vector qp_grads_global (n_q_points); + fe_values_view.get_function_gradients_from_local_dof_values(local_dof_values, qp_grads_local); + fe_values_view.get_function_gradients (solution,qp_grads_global); + + // Hessians + std::vector qp_hess_local(n_q_points); + std::vector qp_hess_global (n_q_points); + fe_values_view.get_function_hessians_from_local_dof_values(local_dof_values, qp_hess_local); + fe_values_view.get_function_hessians (solution,qp_hess_global); + + // Laplacians + std::vector qp_laplace_local(n_q_points); + std::vector qp_laplace_global(n_q_points); + fe_values_view.get_function_laplacians_from_local_dof_values(local_dof_values, qp_laplace_local); + fe_values_view.get_function_laplacians (solution,qp_laplace_global); + + // Third derivatives + std::vector qp_third_deriv_local(n_q_points); + std::vector qp_third_deriv_global(n_q_points); + fe_values_view.get_function_third_derivatives_from_local_dof_values(local_dof_values, qp_third_deriv_local); + fe_values_view.get_function_third_derivatives (solution,qp_third_deriv_global); + + // Output + for (unsigned int q=0; q +void test_view (const Vector &solution, + const FEValues &fe_values, + const unsigned int &n_q_points, + const FEValuesExtractors::Vector &extractor, + const std::vector &local_dof_values) +{ + typedef typename std::remove_reference::type>::type View; + const View &fe_values_view = fe_values[extractor]; + + // Typedefs + typedef typename View::template OutputType OutputType; + typedef typename ProductType::type value_type; + typedef typename ProductType::type gradient_type; + typedef typename ProductType::type symmetric_gradient_type; + typedef typename ProductType::type divergence_type; + typedef typename ProductType::type curl_type; + typedef typename ProductType::type hessian_type; + typedef typename ProductType::type laplacian_type; + typedef typename ProductType::type third_derivative_type; + + // Values + std::vector qp_values_local(n_q_points); + std::vector qp_values_global (n_q_points); + fe_values_view.get_function_values_from_local_dof_values(local_dof_values, qp_values_local); + fe_values_view.get_function_values (solution,qp_values_global); + + // Gradients + std::vector qp_grads_local(n_q_points); + std::vector qp_grads_global (n_q_points); + fe_values_view.get_function_gradients_from_local_dof_values(local_dof_values, qp_grads_local); + fe_values_view.get_function_gradients (solution,qp_grads_global); + + // Symmetric gradients + std::vector qp_symm_grads_local(n_q_points); + std::vector qp_symm_grads_global (n_q_points); + fe_values_view.get_function_symmetric_gradients_from_local_dof_values(local_dof_values, qp_symm_grads_local); + fe_values_view.get_function_symmetric_gradients (solution,qp_symm_grads_global); + + // Divergences + std::vector qp_divs_local(n_q_points); + std::vector qp_divs_global (n_q_points); + fe_values_view.get_function_divergences_from_local_dof_values(local_dof_values, qp_divs_local); + fe_values_view.get_function_divergences (solution,qp_divs_global); + + // Curls + std::vector qp_curls_local(n_q_points); + std::vector qp_curls_global (n_q_points); + fe_values_view.get_function_curls_from_local_dof_values(local_dof_values, qp_curls_local); + fe_values_view.get_function_curls (solution,qp_curls_global); + + // Hessians + std::vector qp_hess_local(n_q_points); + std::vector qp_hess_global (n_q_points); + fe_values_view.get_function_hessians_from_local_dof_values(local_dof_values, qp_hess_local); + fe_values_view.get_function_hessians (solution,qp_hess_global); + + // Laplacians + std::vector qp_laplace_local(n_q_points); + std::vector qp_laplace_global(n_q_points); + fe_values_view.get_function_laplacians_from_local_dof_values(local_dof_values, qp_laplace_local); + fe_values_view.get_function_laplacians (solution,qp_laplace_global); + + // Third derivatives + std::vector qp_third_deriv_local(n_q_points); + std::vector qp_third_deriv_global(n_q_points); + fe_values_view.get_function_third_derivatives_from_local_dof_values(local_dof_values, qp_third_deriv_local); + fe_values_view.get_function_third_derivatives (solution,qp_third_deriv_global); + + // Output + for (unsigned int q=0; q +void test_view (const Vector &solution, + const FEValues &fe_values, + const unsigned int &n_q_points, + const FEValuesExtractors::SymmetricTensor<2> &extractor, + const std::vector &local_dof_values) +{ + typedef typename std::remove_reference::type>::type View; + const View &fe_values_view = fe_values[extractor]; + + // Typedefs + typedef typename View::template OutputType OutputType; + typedef typename ProductType::type value_type; + typedef typename ProductType::type divergence_type; + + // Values + std::vector qp_values_local(n_q_points); + std::vector qp_values_global (n_q_points); + fe_values_view.get_function_values_from_local_dof_values(local_dof_values, qp_values_local); + fe_values_view.get_function_values (solution,qp_values_global); + + // Divergences + std::vector qp_divs_local(n_q_points); + std::vector qp_divs_global (n_q_points); + fe_values_view.get_function_divergences_from_local_dof_values(local_dof_values, qp_divs_local); + fe_values_view.get_function_divergences (solution,qp_divs_global); + + // Output + for (unsigned int q=0; q +void test_view (const Vector &solution, + const FEValues &fe_values, + const unsigned int &n_q_points, + const FEValuesExtractors::Tensor<2> &extractor, + const std::vector &local_dof_values) +{ + typedef typename std::remove_reference::type>::type View; + const View &fe_values_view = fe_values[extractor]; + + // Typedefs + typedef typename View::template OutputType OutputType; + typedef typename ProductType::type value_type; + typedef typename ProductType::type divergence_type; + + // Values + std::vector qp_values_local(n_q_points); + std::vector qp_values_global (n_q_points); + fe_values_view.get_function_values_from_local_dof_values(local_dof_values, qp_values_local); + fe_values_view.get_function_values (solution,qp_values_global); + + // Divergences + std::vector qp_divs_local(n_q_points); + std::vector qp_divs_global (n_q_points); + fe_values_view.get_function_divergences_from_local_dof_values(local_dof_values, qp_divs_local); + fe_values_view.get_function_divergences (solution,qp_divs_global); + + // Output + for (unsigned int q=0; q +void test_extractor (const FEType &fe, + const ExtractorType &extractor) +{ + QGauss quadrature_formula(2); + + Triangulation tria; + DoFHandler dof_handler (tria); + Vector solution; + + GridGenerator::hyper_cube (tria, -1, 1); + tria.refine_global(1); + dof_handler.distribute_dofs (fe); + DoFRenumbering::random(dof_handler); + solution.reinit (dof_handler.n_dofs()); + + // Populate with non-trivial values + for (unsigned int i=0; i fe_values (fe, quadrature_formula, + update_values | update_gradients | update_hessians | update_3rd_derivatives); + std::vector local_dof_indices (fe.dofs_per_cell); + + typename DoFHandler::active_cell_iterator cell = dof_handler.begin_active(); + { + fe_values.reinit (cell); + cell->get_dof_indices (local_dof_indices); + + std::vector local_dof_values(fe.dofs_per_cell); + cell->get_dof_values(solution,local_dof_values.begin(), local_dof_values.end()); + + // Convert the DoF values so that they are potentially of + // a different number type + std::vector local_dof_values_other(fe.dofs_per_cell); + for (unsigned int i=0; i +void test() +{ + const unsigned int degree = 3; // Need third derivatives + + deallog.push("Scalar"); + { + FE_Q fe (degree); + FEValuesExtractors::Scalar extractor (0); + test_extractor(fe, extractor); + } + deallog.pop(); + + deallog.push("Vector"); + { + FESystem fe (FE_Q (degree), dim); + FEValuesExtractors::Vector extractor (0); + test_extractor(fe, extractor); + } + deallog.pop(); + + deallog.push("SymmetricTensor"); + { + FESystem fe (FE_Q (degree), SymmetricTensor<2,dim>::n_independent_components); + FEValuesExtractors::SymmetricTensor<2> extractor (0); + test_extractor(fe, extractor); + } + deallog.pop(); + + deallog.push("Tensor"); + { + FESystem fe (FE_Q (degree), Tensor<2,dim>::n_independent_components); + FEValuesExtractors::Tensor<2> extractor (0); + test_extractor(fe, extractor); + } + deallog.pop(); +} + +int main (int argc, char **argv) +{ + initlog(); + deallog.threshold_double(1.e-10); + + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads()); + + deallog.push("Float"); + { + test(); + } + deallog.pop(); + + deallog.push("Double"); + { + test(); + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/fe/fe_values_view_get_function_from_local_dof_values_01.output b/tests/fe/fe_values_view_get_function_from_local_dof_values_01.output new file mode 100644 index 0000000000..d781ec5f29 --- /dev/null +++ b/tests/fe/fe_values_view_get_function_from_local_dof_values_01.output @@ -0,0 +1,10 @@ + +DEAL:Float:Scalar::OK +DEAL:Float:Vector::OK +DEAL:Float:SymmetricTensor::OK +DEAL:Float:Tensor::OK +DEAL:Double:Scalar::OK +DEAL:Double:Vector::OK +DEAL:Double:SymmetricTensor::OK +DEAL:Double:Tensor::OK +DEAL::OK diff --git a/tests/fe/fe_values_view_get_function_from_local_dof_values_02.cc b/tests/fe/fe_values_view_get_function_from_local_dof_values_02.cc new file mode 100644 index 0000000000..cd22f313d7 --- /dev/null +++ b/tests/fe/fe_values_view_get_function_from_local_dof_values_02.cc @@ -0,0 +1,298 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// Check that FEValuesViews::get_function_*_from_local_dof_values +// works with different number types. +// As opposed to fe_values_view_get_function_from_local_dof_values_01.cc, this +// test does not check the output types, but rather that all necessary +// instantiations are in place and that no assertions are triggered. +// This is because FEValuesViews::get_function_* cannot work with Sacado types. + +#include "../tests.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +template +void test_view (const Vector &solution, + const FEValues &fe_values, + const unsigned int &n_q_points, + const ExtractorType &extractor, + const std::vector &local_dof_values); + +// Scalar view +template +void test_view (const Vector &solution, + const FEValues &fe_values, + const unsigned int &n_q_points, + const FEValuesExtractors::Scalar &extractor, + const std::vector &local_dof_values) +{ + typedef typename std::remove_reference::type>::type View; + const View &fe_values_view = fe_values[extractor]; + + // Typedefs + typedef typename View::template OutputType OutputType; + + // Values + std::vector qp_values_local(n_q_points); + fe_values_view.get_function_values_from_local_dof_values(local_dof_values, qp_values_local); + + // Gradients + std::vector qp_grads_local(n_q_points); + fe_values_view.get_function_gradients_from_local_dof_values(local_dof_values, qp_grads_local); + + // Hessians + std::vector qp_hess_local(n_q_points); + fe_values_view.get_function_hessians_from_local_dof_values(local_dof_values, qp_hess_local); + + // Laplacians + std::vector qp_laplace_local(n_q_points); + fe_values_view.get_function_laplacians_from_local_dof_values(local_dof_values, qp_laplace_local); + + // Third derivatives + std::vector qp_third_deriv_local(n_q_points); + fe_values_view.get_function_third_derivatives_from_local_dof_values(local_dof_values, qp_third_deriv_local); +} + +// Vector view +template +void test_view (const Vector &solution, + const FEValues &fe_values, + const unsigned int &n_q_points, + const FEValuesExtractors::Vector &extractor, + const std::vector &local_dof_values) +{ + typedef typename std::remove_reference::type>::type View; + const View &fe_values_view = fe_values[extractor]; + + // Typedefs + typedef typename View::template OutputType OutputType; + + // Values + std::vector qp_values_local(n_q_points); + fe_values_view.get_function_values_from_local_dof_values(local_dof_values, qp_values_local); + + // Gradients + std::vector qp_grads_local(n_q_points); + fe_values_view.get_function_gradients_from_local_dof_values(local_dof_values, qp_grads_local); + + // Symmetric gradients + std::vector qp_symm_grads_local(n_q_points); + fe_values_view.get_function_symmetric_gradients_from_local_dof_values(local_dof_values, qp_symm_grads_local); + + // Divergences + std::vector qp_divs_local(n_q_points); + fe_values_view.get_function_divergences_from_local_dof_values(local_dof_values, qp_divs_local); + + // Curls + std::vector qp_curls_local(n_q_points); + fe_values_view.get_function_curls_from_local_dof_values(local_dof_values, qp_curls_local); + + // Hessians + std::vector qp_hess_local(n_q_points); + fe_values_view.get_function_hessians_from_local_dof_values(local_dof_values, qp_hess_local); + + // Laplacians + std::vector qp_laplace_local(n_q_points); + fe_values_view.get_function_laplacians_from_local_dof_values(local_dof_values, qp_laplace_local); + + // Third derivatives + std::vector qp_third_deriv_local(n_q_points); + fe_values_view.get_function_third_derivatives_from_local_dof_values(local_dof_values, qp_third_deriv_local); +} + +// SymmetricTensor view +template +void test_view (const Vector &solution, + const FEValues &fe_values, + const unsigned int &n_q_points, + const FEValuesExtractors::SymmetricTensor<2> &extractor, + const std::vector &local_dof_values) +{ + typedef typename std::remove_reference::type>::type View; + const View &fe_values_view = fe_values[extractor]; + + // Typedefs + typedef typename View::template OutputType OutputType; + typedef typename ProductType::type value_type; + typedef typename ProductType::type divergence_type; + + // Values + std::vector qp_values_local(n_q_points); + fe_values_view.get_function_values_from_local_dof_values(local_dof_values, qp_values_local); + + // Divergences + std::vector qp_divs_local(n_q_points); + fe_values_view.get_function_divergences_from_local_dof_values(local_dof_values, qp_divs_local); +} + +// Tensor view +template +void test_view (const Vector &solution, + const FEValues &fe_values, + const unsigned int &n_q_points, + const FEValuesExtractors::Tensor<2> &extractor, + const std::vector &local_dof_values) +{ + typedef typename std::remove_reference::type>::type View; + const View &fe_values_view = fe_values[extractor]; + + // Typedefs + typedef typename View::template OutputType OutputType; + typedef typename ProductType::type value_type; + typedef typename ProductType::type divergence_type; + + // Values + std::vector qp_values_local(n_q_points); + fe_values_view.get_function_values_from_local_dof_values(local_dof_values, qp_values_local); + + // Divergences + std::vector qp_divs_local(n_q_points); + fe_values_view.get_function_divergences_from_local_dof_values(local_dof_values, qp_divs_local); +} + +template +void test_extractor (const FEType &fe, + const ExtractorType &extractor) +{ + QGauss quadrature_formula(2); + + Triangulation tria; + DoFHandler dof_handler (tria); + Vector solution; + + GridGenerator::hyper_cube (tria, -1, 1); + tria.refine_global(1); + dof_handler.distribute_dofs (fe); + DoFRenumbering::random(dof_handler); + solution.reinit (dof_handler.n_dofs()); + + // Populate with non-trivial values + for (unsigned int i=0; i fe_values (fe, quadrature_formula, + update_values | update_gradients | update_hessians | update_3rd_derivatives); + std::vector local_dof_indices (fe.dofs_per_cell); + + typename DoFHandler::active_cell_iterator cell = dof_handler.begin_active(); + { + fe_values.reinit (cell); + cell->get_dof_indices (local_dof_indices); + + std::vector local_dof_values(fe.dofs_per_cell); + cell->get_dof_values(solution,local_dof_values.begin(), local_dof_values.end()); + + // Convert the DoF values so that they are potentially of + // a different number type + std::vector local_dof_values_other(fe.dofs_per_cell); + for (unsigned int i=0; i +void test() +{ + const unsigned int degree = 3; // Need third derivatives + + deallog.push("Scalar"); + { + FE_Q fe (degree); + FEValuesExtractors::Scalar extractor (0); + test_extractor(fe, extractor); + } + deallog.pop(); + + deallog.push("Vector"); + { + FESystem fe (FE_Q (degree), dim); + FEValuesExtractors::Vector extractor (0); + test_extractor(fe, extractor); + } + deallog.pop(); + + deallog.push("SymmetricTensor"); + { + FESystem fe (FE_Q (degree), SymmetricTensor<2,dim>::n_independent_components); + FEValuesExtractors::SymmetricTensor<2> extractor (0); + test_extractor(fe, extractor); + } + deallog.pop(); + + deallog.push("Tensor"); + { + FESystem fe (FE_Q (degree), Tensor<2,dim>::n_independent_components); + FEValuesExtractors::Tensor<2> extractor (0); + test_extractor(fe, extractor); + } + deallog.pop(); +} + +int main (int argc, char **argv) +{ + initlog(); + deallog.threshold_double(1.e-10); + + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads()); + + deallog.push("Sacado::Fad::DFad"); + { + test>(); + } + deallog.pop(); + + deallog.push("Sacado::Fad::DFad>"); + { + test>>(); + } + deallog.pop(); + + deallog.push("Sacado::Fad::DFad"); + { + test>(); + } + deallog.pop(); + + deallog.push("Sacado::Fad::DFad>"); + { + test>>(); + } + deallog.pop(); + + deallog << "OK" << std::endl; +} diff --git a/tests/fe/fe_values_view_get_function_from_local_dof_values_02.with_trilinos=true.output b/tests/fe/fe_values_view_get_function_from_local_dof_values_02.with_trilinos=true.output new file mode 100644 index 0000000000..4552037494 --- /dev/null +++ b/tests/fe/fe_values_view_get_function_from_local_dof_values_02.with_trilinos=true.output @@ -0,0 +1,18 @@ + +DEAL:Sacado::Fad::DFad:Scalar::OK +DEAL:Sacado::Fad::DFad:Vector::OK +DEAL:Sacado::Fad::DFad:SymmetricTensor::OK +DEAL:Sacado::Fad::DFad:Tensor::OK +DEAL:Sacado::Fad::DFad>:Scalar::OK +DEAL:Sacado::Fad::DFad>:Vector::OK +DEAL:Sacado::Fad::DFad>:SymmetricTensor::OK +DEAL:Sacado::Fad::DFad>:Tensor::OK +DEAL:Sacado::Fad::DFad:Scalar::OK +DEAL:Sacado::Fad::DFad:Vector::OK +DEAL:Sacado::Fad::DFad:SymmetricTensor::OK +DEAL:Sacado::Fad::DFad:Tensor::OK +DEAL:Sacado::Fad::DFad>:Scalar::OK +DEAL:Sacado::Fad::DFad>:Vector::OK +DEAL:Sacado::Fad::DFad>:SymmetricTensor::OK +DEAL:Sacado::Fad::DFad>:Tensor::OK +DEAL::OK