From: Martin Kronbichler Date: Mon, 30 May 2022 20:34:47 +0000 (+0200) Subject: Make VectorTools::project compile with complex numbers X-Git-Tag: v9.4.0-rc1~101^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1d316ad1c75a76e1850ef05d6c44684a481bfe5;p=dealii.git Make VectorTools::project compile with complex numbers --- diff --git a/include/deal.II/numerics/vector_tools_project.templates.h b/include/deal.II/numerics/vector_tools_project.templates.h index 45ef53965d..719a20fc12 100644 --- a/include/deal.II/numerics/vector_tools_project.templates.h +++ b/include/deal.II/numerics/vector_tools_project.templates.h @@ -445,6 +445,8 @@ namespace VectorTools vec_result.compress(VectorOperation::insert); } + + /** * Return whether the boundary values try to constrain a degree of freedom * that is already constrained to something else @@ -769,19 +771,23 @@ namespace VectorTools } /** - * Specialization of project() for the case dim==spacedim. - * Check if we can use the MatrixFree implementation or need - * to use the matrix based one. + * Specialization of project() for the case dim==spacedim and with correct + * number types for MatrixFree support. Check if we actually can use the + * MatrixFree implementation or need to use the matrix based one + * nonetheless based on the number of components. */ - template - void + template + std::enable_if_t< + !numbers::NumberTraits::is_complex && + (dim == spacedim), + void> project( - const Mapping & mapping, - const DoFHandler & dof, - const AffineConstraints &constraints, - const Quadrature & quadrature, - const Function & function, - VectorType & vec_result, + const Mapping & mapping, + const DoFHandler & dof, + const AffineConstraints & constraints, + const Quadrature & quadrature, + const Function &function, + VectorType & vec_result, const bool enforce_zero_boundary, const Quadrature &q_boundary, const bool project_to_boundary_first) @@ -826,6 +832,40 @@ namespace VectorTools project_to_boundary_first); } } + + /** + * Specialization of project() for complex numbers or `dim < spacedim`, + * for which we are sure that we cannot use the MatrixFree implementation. + */ + template + std::enable_if_t< + numbers::NumberTraits::is_complex || + (dim < spacedim), + void> + project( + const Mapping & mapping, + const DoFHandler & dof, + const AffineConstraints & constraints, + const Quadrature & quadrature, + const Function &function, + VectorType & vec_result, + const bool enforce_zero_boundary, + const Quadrature &q_boundary, + const bool project_to_boundary_first) + { + Assert((dynamic_cast *>( + &(dof.get_triangulation())) == nullptr), + ExcNotImplemented()); + do_project(mapping, + dof, + constraints, + quadrature, + function, + vec_result, + enforce_zero_boundary, + q_boundary, + project_to_boundary_first); + } } // namespace internal template @@ -900,44 +940,15 @@ namespace VectorTools const Quadrature &q_boundary, const bool project_to_boundary_first) { - if (dim == spacedim) - { - const Mapping *const mapping_ptr = - dynamic_cast *>(&mapping); - const DoFHandler *const dof_ptr = - dynamic_cast *>(&dof); - const Function *const function_ptr = - dynamic_cast *>( - &function); - Assert(mapping_ptr != nullptr, ExcInternalError()); - Assert(dof_ptr != nullptr, ExcInternalError()); - internal::project(*mapping_ptr, - *dof_ptr, - constraints, - quadrature, - *function_ptr, - vec_result, - enforce_zero_boundary, - q_boundary, - project_to_boundary_first); - } - else - { - Assert( - (dynamic_cast *>( - &(dof.get_triangulation())) == nullptr), - ExcNotImplemented()); - internal::do_project(mapping, - dof, - constraints, - quadrature, - function, - vec_result, - enforce_zero_boundary, - q_boundary, - project_to_boundary_first); - } + internal::project(mapping, + dof, + constraints, + quadrature, + function, + vec_result, + enforce_zero_boundary, + q_boundary, + project_to_boundary_first); }