// ------------------------------------------------------------------------ // // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (C) 2020 - 2023 by the deal.II authors // // This file is part of the deal.II library. // // Part of the source code is dual licensed under Apache-2.0 WITH // LLVM-exception OR LGPL-2.1-or-later. Detailed license information // governing the source code and code contributions can be found in // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. // // ------------------------------------------------------------------------ #ifndef dealii_vector_tools_point_gradient_templates_h #define dealii_vector_tools_point_gradient_templates_h #include #include #include #include #include #include #include #include #include #include #include #include DEAL_II_NAMESPACE_OPEN namespace VectorTools { template DEAL_II_CXX20_REQUIRES(concepts::is_dealii_vector_type) void point_gradient( const DoFHandler &dof, const VectorType &fe_function, const Point &point, std::vector> &gradients) { if (dof.has_hp_capabilities() == false) point_gradient(get_default_linear_mapping(dof.get_triangulation()), dof, fe_function, point, gradients); else point_gradient(hp::StaticMappingQ1::mapping_collection, dof, fe_function, point, gradients); } template DEAL_II_CXX20_REQUIRES(concepts::is_dealii_vector_type) Tensor<1, spacedim, typename VectorType::value_type> point_gradient( const DoFHandler &dof, const VectorType &fe_function, const Point &point) { if (dof.has_hp_capabilities() == false) return point_gradient(get_default_linear_mapping(dof.get_triangulation()), dof, fe_function, point); else return point_gradient( hp::StaticMappingQ1::mapping_collection, dof, fe_function, point); } template DEAL_II_CXX20_REQUIRES(concepts::is_dealii_vector_type) void point_gradient( const Mapping &mapping, const DoFHandler &dof, const VectorType &fe_function, const Point &point, std::vector> &gradient) { const FiniteElement &fe = dof.get_fe(); Assert(gradient.size() == fe.n_components(), ExcDimensionMismatch(gradient.size(), fe.n_components())); // first find the cell in which this point // is, initialize a quadrature rule with // it, and then a FEValues object const std::pair::active_cell_iterator, Point> cell_point = GridTools::find_active_cell_around_point(mapping, dof, point); AssertThrow(cell_point.first.state() == IteratorState::valid && cell_point.first->is_locally_owned(), ExcPointNotAvailableHere()); Assert(GeometryInfo::distance_to_unit_cell(cell_point.second) < 1e-10, ExcInternalError()); const Quadrature quadrature( cell_point.first->reference_cell().closest_point(cell_point.second)); FEValues fe_values(mapping, fe, quadrature, update_gradients); fe_values.reinit(cell_point.first); // then use this to get the gradients of // the given fe_function at this point using Number = typename VectorType::value_type; std::vector>> u_gradient( 1, std::vector>(fe.n_components())); fe_values.get_function_gradients(fe_function, u_gradient); gradient = u_gradient[0]; } template DEAL_II_CXX20_REQUIRES(concepts::is_dealii_vector_type) void point_gradient( const hp::MappingCollection &mapping, const DoFHandler &dof, const VectorType &fe_function, const Point &point, std::vector> &gradient) { using Number = typename VectorType::value_type; const hp::FECollection &fe = dof.get_fe_collection(); Assert(gradient.size() == fe.n_components(), ExcDimensionMismatch(gradient.size(), fe.n_components())); // first find the cell in which this point // is, initialize a quadrature rule with // it, and then a FEValues object const std::pair::active_cell_iterator, Point> cell_point = GridTools::find_active_cell_around_point(mapping, dof, point); AssertThrow(cell_point.first.state() == IteratorState::valid && cell_point.first->is_locally_owned(), ExcPointNotAvailableHere()); Assert(GeometryInfo::distance_to_unit_cell(cell_point.second) < 1e-10, ExcInternalError()); const Quadrature quadrature( cell_point.first->reference_cell().closest_point(cell_point.second)); hp::FEValues hp_fe_values(mapping, fe, hp::QCollection(quadrature), update_gradients); hp_fe_values.reinit(cell_point.first); const FEValues &fe_values = hp_fe_values.get_present_fe_values(); std::vector>> u_gradient( 1, std::vector>(fe.n_components())); fe_values.get_function_gradients(fe_function, u_gradient); gradient = u_gradient[0]; } template DEAL_II_CXX20_REQUIRES(concepts::is_dealii_vector_type) Tensor<1, spacedim, typename VectorType::value_type> point_gradient( const Mapping &mapping, const DoFHandler &dof, const VectorType &fe_function, const Point &point) { Assert(dof.get_fe(0).n_components() == 1, ExcMessage( "Finite element is not scalar as is necessary for this function")); std::vector> gradient(1); point_gradient(mapping, dof, fe_function, point, gradient); return gradient[0]; } template DEAL_II_CXX20_REQUIRES(concepts::is_dealii_vector_type) Tensor<1, spacedim, typename VectorType::value_type> point_gradient( const hp::MappingCollection &mapping, const DoFHandler &dof, const VectorType &fe_function, const Point &point) { Assert(dof.get_fe(0).n_components() == 1, ExcMessage( "Finite element is not scalar as is necessary for this function")); std::vector> gradient(1); point_gradient(mapping, dof, fe_function, point, gradient); return gradient[0]; } } // namespace VectorTools DEAL_II_NAMESPACE_CLOSE #endif // dealii_vector_tools_point_gradient_templates_h