// ------------------------------------------------------------------------ // // SPDX-License-Identifier: LGPL-2.1-or-later // Copyright (C) 2016 - 2025 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_matrix_creator_templates_h #define dealii_matrix_creator_templates_h #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DEAL_II_WITH_PETSC # include # include # include #endif #ifdef DEAL_II_WITH_TRILINOS # include # include # include # include #endif #include #include DEAL_II_NAMESPACE_OPEN namespace MatrixCreator { namespace internal { namespace AssemblerData { template struct Scratch { Scratch(const ::dealii::hp::FECollection &fe, const UpdateFlags update_flags, const Function *coefficient, const Function *rhs_function, const ::dealii::hp::QCollection &quadrature, const ::dealii::hp::MappingCollection &mapping) : fe_collection(fe) , quadrature_collection(quadrature) , mapping_collection(mapping) , x_fe_values(mapping_collection, fe_collection, quadrature_collection, update_flags) , coefficient_values(quadrature_collection.max_n_quadrature_points()) , coefficient_vector_values( quadrature_collection.max_n_quadrature_points(), dealii::Vector(fe_collection.n_components())) , rhs_values(quadrature_collection.max_n_quadrature_points()) , rhs_vector_values(quadrature_collection.max_n_quadrature_points(), dealii::Vector( fe_collection.n_components())) , coefficient(coefficient) , rhs_function(rhs_function) , update_flags(update_flags) {} Scratch(const Scratch &data) : fe_collection(data.fe_collection) , quadrature_collection(data.quadrature_collection) , mapping_collection(data.mapping_collection) , x_fe_values(mapping_collection, fe_collection, quadrature_collection, data.update_flags) , coefficient_values(data.coefficient_values) , coefficient_vector_values(data.coefficient_vector_values) , rhs_values(data.rhs_values) , rhs_vector_values(data.rhs_vector_values) , coefficient(data.coefficient) , rhs_function(data.rhs_function) , update_flags(data.update_flags) {} Scratch & operator=(const Scratch &) { DEAL_II_NOT_IMPLEMENTED(); return *this; } const ::dealii::hp::FECollection &fe_collection; const ::dealii::hp::QCollection &quadrature_collection; const ::dealii::hp::MappingCollection &mapping_collection; ::dealii::hp::FEValues x_fe_values; std::vector coefficient_values; std::vector> coefficient_vector_values; std::vector rhs_values; std::vector> rhs_vector_values; const Function *coefficient; const Function *rhs_function; const UpdateFlags update_flags; }; template struct CopyData { std::vector dof_indices; FullMatrix cell_matrix; dealii::Vector cell_rhs; const AffineConstraints *constraints; bool is_locally_owned; }; } // namespace AssemblerData template void mass_assembler( const CellIterator &cell, MatrixCreator::internal::AssemblerData::Scratch &data, MatrixCreator::internal::AssemblerData::CopyData ©_data) { copy_data.is_locally_owned = cell->is_locally_owned(); if (copy_data.is_locally_owned == false) return; data.x_fe_values.reinit(cell); const FEValues &fe_values = data.x_fe_values.get_present_fe_values(); const unsigned int dofs_per_cell = fe_values.dofs_per_cell, n_q_points = fe_values.n_quadrature_points; const FiniteElement &fe = fe_values.get_fe(); const unsigned int n_components = fe.n_components(); Assert(data.rhs_function == nullptr || data.rhs_function->n_components == 1 || data.rhs_function->n_components == n_components, ::dealii::MatrixCreator::ExcComponentMismatch()); Assert(data.coefficient == nullptr || data.coefficient->n_components == 1 || data.coefficient->n_components == n_components, ::dealii::MatrixCreator::ExcComponentMismatch()); copy_data.cell_matrix.reinit(dofs_per_cell, dofs_per_cell); copy_data.cell_rhs.reinit(dofs_per_cell); copy_data.dof_indices.resize(dofs_per_cell); cell->get_dof_indices(copy_data.dof_indices); const bool use_rhs_function = data.rhs_function != nullptr; if (use_rhs_function) { if (data.rhs_function->n_components == 1) { data.rhs_values.resize(n_q_points); data.rhs_function->value_list(fe_values.get_quadrature_points(), data.rhs_values); } else { data.rhs_vector_values.resize( n_q_points, dealii::Vector(n_components)); data.rhs_function->vector_value_list( fe_values.get_quadrature_points(), data.rhs_vector_values); } } const bool use_coefficient = data.coefficient != nullptr; if (use_coefficient) { if (data.coefficient->n_components == 1) { data.coefficient_values.resize(n_q_points); data.coefficient->value_list(fe_values.get_quadrature_points(), data.coefficient_values); } else { data.coefficient_vector_values.resize( n_q_points, dealii::Vector(n_components)); data.coefficient->vector_value_list( fe_values.get_quadrature_points(), data.coefficient_vector_values); } } const std::vector &JxW = fe_values.get_JxW_values(); for (unsigned int i = 0; i < dofs_per_cell; ++i) if (fe.is_primitive()) { const unsigned int component_i = fe.system_to_component_index(i).first; const double *phi_i = &fe_values.shape_value(i, 0); // use symmetry in the mass matrix here: // just need to calculate the diagonal // and half of the elements above the // diagonal for (unsigned int j = i; j < dofs_per_cell; ++j) if ((n_components == 1) || (fe.system_to_component_index(j).first == component_i)) { const double *phi_j = &fe_values.shape_value(j, 0); number add_data = 0; if (use_coefficient) { if (data.coefficient->n_components == 1) for (unsigned int point = 0; point < n_q_points; ++point) add_data += (data.coefficient_values[point] * phi_i[point] * phi_j[point] * JxW[point]); else for (unsigned int point = 0; point < n_q_points; ++point) add_data += (data.coefficient_vector_values[point]( component_i) * phi_i[point] * phi_j[point] * JxW[point]); } else for (unsigned int point = 0; point < n_q_points; ++point) add_data += phi_i[point] * phi_j[point] * JxW[point]; // this is even ok for i==j, since then // we just write the same value twice. copy_data.cell_matrix(i, j) = add_data; copy_data.cell_matrix(j, i) = add_data; } if (use_rhs_function) { number add_data = 0; if (data.rhs_function->n_components == 1) for (unsigned int point = 0; point < n_q_points; ++point) add_data += data.rhs_values[point] * phi_i[point] * JxW[point]; else for (unsigned int point = 0; point < n_q_points; ++point) add_data += data.rhs_vector_values[point](component_i) * phi_i[point] * JxW[point]; copy_data.cell_rhs(i) = add_data; } } else { // non-primitive vector-valued FE, using // symmetry again for (unsigned int j = i; j < dofs_per_cell; ++j) { number add_data = 0; for (unsigned int comp_i = 0; comp_i < n_components; ++comp_i) if (fe.get_nonzero_components(i)[comp_i] && fe.get_nonzero_components(j)[comp_i]) { if (use_coefficient) { if (data.coefficient->n_components == 1) for (unsigned int point = 0; point < n_q_points; ++point) add_data += (data.coefficient_values[point] * fe_values.shape_value_component(i, point, comp_i) * fe_values.shape_value_component(j, point, comp_i) * JxW[point]); else for (unsigned int point = 0; point < n_q_points; ++point) add_data += (data.coefficient_vector_values[point](comp_i) * fe_values.shape_value_component(i, point, comp_i) * fe_values.shape_value_component(j, point, comp_i) * JxW[point]); } else for (unsigned int point = 0; point < n_q_points; ++point) add_data += fe_values.shape_value_component(i, point, comp_i) * fe_values.shape_value_component(j, point, comp_i) * JxW[point]; } copy_data.cell_matrix(i, j) = add_data; copy_data.cell_matrix(j, i) = add_data; } if (use_rhs_function) { number add_data = 0; for (unsigned int comp_i = 0; comp_i < n_components; ++comp_i) if (fe.get_nonzero_components(i)[comp_i]) { if (data.rhs_function->n_components == 1) for (unsigned int point = 0; point < n_q_points; ++point) add_data += data.rhs_values[point] * fe_values.shape_value_component(i, point, comp_i) * JxW[point]; else for (unsigned int point = 0; point < n_q_points; ++point) add_data += data.rhs_vector_values[point](comp_i) * fe_values.shape_value_component(i, point, comp_i) * JxW[point]; } copy_data.cell_rhs(i) = add_data; } } } template void laplace_assembler( const CellIterator &cell, MatrixCreator::internal::AssemblerData::Scratch &data, MatrixCreator::internal::AssemblerData::CopyData ©_data) { copy_data.is_locally_owned = cell->is_locally_owned(); if (copy_data.is_locally_owned == false) return; data.x_fe_values.reinit(cell); const FEValues &fe_values = data.x_fe_values.get_present_fe_values(); const unsigned int dofs_per_cell = fe_values.dofs_per_cell, n_q_points = fe_values.n_quadrature_points; const FiniteElement &fe = fe_values.get_fe(); const unsigned int n_components = fe.n_components(); Assert(data.rhs_function == nullptr || data.rhs_function->n_components == 1 || data.rhs_function->n_components == n_components, ::dealii::MatrixCreator::ExcComponentMismatch()); Assert(data.coefficient == nullptr || data.coefficient->n_components == 1 || data.coefficient->n_components == n_components, ::dealii::MatrixCreator::ExcComponentMismatch()); copy_data.cell_matrix.reinit(dofs_per_cell, dofs_per_cell); copy_data.cell_rhs.reinit(dofs_per_cell); copy_data.dof_indices.resize(dofs_per_cell); cell->get_dof_indices(copy_data.dof_indices); const bool use_rhs_function = data.rhs_function != nullptr; if (use_rhs_function) { if (data.rhs_function->n_components == 1) { data.rhs_values.resize(n_q_points); data.rhs_function->value_list(fe_values.get_quadrature_points(), data.rhs_values); } else { data.rhs_vector_values.resize( n_q_points, dealii::Vector(n_components)); data.rhs_function->vector_value_list( fe_values.get_quadrature_points(), data.rhs_vector_values); } } const bool use_coefficient = data.coefficient != nullptr; if (use_coefficient) { if (data.coefficient->n_components == 1) { data.coefficient_values.resize(n_q_points); data.coefficient->value_list(fe_values.get_quadrature_points(), data.coefficient_values); } else { data.coefficient_vector_values.resize( n_q_points, dealii::Vector(n_components)); data.coefficient->vector_value_list( fe_values.get_quadrature_points(), data.coefficient_vector_values); } } const std::vector &JxW = fe_values.get_JxW_values(); Number add_data; for (unsigned int i = 0; i < dofs_per_cell; ++i) if (fe.is_primitive()) { const unsigned int component_i = fe.system_to_component_index(i).first; const Tensor<1, spacedim> *grad_phi_i = &fe_values.shape_grad(i, 0); // can use symmetry for (unsigned int j = i; j < dofs_per_cell; ++j) if ((n_components == 1) || (fe.system_to_component_index(j).first == component_i)) { const Tensor<1, spacedim> *grad_phi_j = &fe_values.shape_grad(j, 0); add_data = 0; if (use_coefficient) { if (data.coefficient->n_components == 1) for (unsigned int point = 0; point < n_q_points; ++point) add_data += ((grad_phi_i[point] * grad_phi_j[point]) * JxW[point] * data.coefficient_values[point]); else for (unsigned int point = 0; point < n_q_points; ++point) add_data += ((grad_phi_i[point] * grad_phi_j[point]) * JxW[point] * data.coefficient_vector_values[point]( component_i)); } else for (unsigned int point = 0; point < n_q_points; ++point) add_data += (grad_phi_i[point] * grad_phi_j[point]) * JxW[point]; copy_data.cell_matrix(i, j) = add_data; copy_data.cell_matrix(j, i) = add_data; } if (use_rhs_function) { const double *phi_i = &fe_values.shape_value(i, 0); add_data = 0; if (data.rhs_function->n_components == 1) for (unsigned int point = 0; point < n_q_points; ++point) add_data += phi_i[point] * JxW[point] * data.rhs_values[point]; else for (unsigned int point = 0; point < n_q_points; ++point) add_data += phi_i[point] * JxW[point] * data.rhs_vector_values[point](component_i); copy_data.cell_rhs(i) = add_data; } } else { // non-primitive vector-valued FE for (unsigned int j = i; j < dofs_per_cell; ++j) { add_data = 0; for (unsigned int comp_i = 0; comp_i < n_components; ++comp_i) if (fe.get_nonzero_components(i)[comp_i] && fe.get_nonzero_components(j)[comp_i]) { if (use_coefficient) { if (data.coefficient->n_components == 1) for (unsigned int point = 0; point < n_q_points; ++point) add_data += ((fe_values.shape_grad_component(i, point, comp_i) * fe_values.shape_grad_component(j, point, comp_i)) * JxW[point] * data.coefficient_values[point]); else for (unsigned int point = 0; point < n_q_points; ++point) add_data += ((fe_values.shape_grad_component(i, point, comp_i) * fe_values.shape_grad_component(j, point, comp_i)) * JxW[point] * data.coefficient_vector_values[point](comp_i)); } else for (unsigned int point = 0; point < n_q_points; ++point) add_data += (fe_values.shape_grad_component(i, point, comp_i) * fe_values.shape_grad_component(j, point, comp_i)) * JxW[point]; } copy_data.cell_matrix(i, j) = add_data; copy_data.cell_matrix(j, i) = add_data; } if (use_rhs_function) { add_data = 0; for (unsigned int comp_i = 0; comp_i < n_components; ++comp_i) if (fe.get_nonzero_components(i)[comp_i]) { if (data.rhs_function->n_components == 1) for (unsigned int point = 0; point < n_q_points; ++point) add_data += fe_values.shape_value_component(i, point, comp_i) * JxW[point] * data.rhs_values[point]; else for (unsigned int point = 0; point < n_q_points; ++point) add_data += fe_values.shape_value_component(i, point, comp_i) * JxW[point] * data.rhs_vector_values[point](comp_i); } copy_data.cell_rhs(i) = add_data; } } } template void copy_local_to_global(const AssemblerData::CopyData &data, MatrixType *matrix, VectorType *right_hand_side) { if (data.is_locally_owned == false) return; const unsigned int dofs_per_cell = data.dof_indices.size(); Assert(data.cell_matrix.m() == dofs_per_cell, ExcInternalError()); Assert(data.cell_matrix.n() == dofs_per_cell, ExcInternalError()); Assert((right_hand_side == nullptr) || (data.cell_rhs.size() == dofs_per_cell), ExcInternalError()); if (right_hand_side != nullptr) data.constraints->distribute_local_to_global(data.cell_matrix, data.cell_rhs, data.dof_indices, *matrix, *right_hand_side); else data.constraints->distribute_local_to_global(data.cell_matrix, data.dof_indices, *matrix); } namespace AssemblerBoundary { struct Scratch { Scratch() = default; }; template struct CopyData { CopyData(); unsigned int dofs_per_cell; std::vector dofs; std::vector> dof_is_on_face; typename DoFHandler::active_cell_iterator cell; std::vector> cell_matrix; std::vector> cell_vector; }; template CopyData::CopyData() : dofs_per_cell(numbers::invalid_unsigned_int) {} } // namespace AssemblerBoundary } // namespace internal } // namespace MatrixCreator namespace MatrixCreator { template void create_mass_matrix( const Mapping &mapping, const DoFHandler &dof, const Quadrature &q, MatrixType &matrix, const Function *const coefficient, const AffineConstraints &constraints) { Assert(matrix.m() == dof.n_dofs(), ExcDimensionMismatch(matrix.m(), dof.n_dofs())); Assert(matrix.n() == dof.n_dofs(), ExcDimensionMismatch(matrix.n(), dof.n_dofs())); const auto &fe_collection = dof.get_fe_collection(); hp::QCollection q_collection(q); hp::MappingCollection mapping_collection(mapping); MatrixCreator::internal::AssemblerData:: Scratch assembler_data(fe_collection, update_values | update_JxW_values | (coefficient != nullptr ? update_quadrature_points : UpdateFlags(0)), coefficient, /*rhs_function=*/nullptr, q_collection, mapping_collection); MatrixCreator::internal::AssemblerData::CopyData< typename MatrixType::value_type> copy_data; copy_data.cell_matrix.reinit( assembler_data.fe_collection.max_dofs_per_cell(), assembler_data.fe_collection.max_dofs_per_cell()); copy_data.cell_rhs.reinit(assembler_data.fe_collection.max_dofs_per_cell()); copy_data.dof_indices.resize( assembler_data.fe_collection.max_dofs_per_cell()); copy_data.constraints = &constraints; WorkStream::run( dof.begin_active(), static_cast::active_cell_iterator>( dof.end()), &MatrixCreator::internal::mass_assembler< dim, spacedim, typename DoFHandler::active_cell_iterator, typename MatrixType::value_type>, [&matrix]( const internal::AssemblerData::CopyData &data) { MatrixCreator::internal::copy_local_to_global( data, &matrix, static_cast *>(nullptr)); }, assembler_data, copy_data); matrix.compress(VectorOperation::add); } template void create_mass_matrix( const DoFHandler &dof, const Quadrature &q, MatrixType &matrix, const Function *const coefficient, const AffineConstraints &constraints) { create_mass_matrix(get_default_linear_mapping(dof.get_triangulation()), dof, q, matrix, coefficient, constraints); } template void create_mass_matrix( const Mapping &mapping, const DoFHandler &dof, const Quadrature &q, MatrixType &matrix, const Function &rhs, Vector &rhs_vector, const Function *const coefficient, const AffineConstraints &constraints) { Assert(matrix.m() == dof.n_dofs(), ExcDimensionMismatch(matrix.m(), dof.n_dofs())); Assert(matrix.n() == dof.n_dofs(), ExcDimensionMismatch(matrix.n(), dof.n_dofs())); const auto &fe_collection = dof.get_fe_collection(); hp::QCollection q_collection(q); hp::MappingCollection mapping_collection(mapping); MatrixCreator::internal::AssemblerData:: Scratch assembler_data(fe_collection, update_values | update_JxW_values | update_quadrature_points, coefficient, &rhs, q_collection, mapping_collection); MatrixCreator::internal::AssemblerData::CopyData< typename MatrixType::value_type> copy_data; copy_data.cell_matrix.reinit( assembler_data.fe_collection.max_dofs_per_cell(), assembler_data.fe_collection.max_dofs_per_cell()); copy_data.cell_rhs.reinit(assembler_data.fe_collection.max_dofs_per_cell()); copy_data.dof_indices.resize( assembler_data.fe_collection.max_dofs_per_cell()); copy_data.constraints = &constraints; WorkStream::run( dof.begin_active(), static_cast::active_cell_iterator>( dof.end()), &MatrixCreator::internal::mass_assembler< dim, spacedim, typename DoFHandler::active_cell_iterator, typename MatrixType::value_type>, [&matrix, &rhs_vector]( const internal::AssemblerData::CopyData &data) { MatrixCreator::internal::copy_local_to_global(data, &matrix, &rhs_vector); }, assembler_data, copy_data); matrix.compress(VectorOperation::add); } template void create_mass_matrix( const DoFHandler &dof, const Quadrature &q, MatrixType &matrix, const Function &rhs, Vector &rhs_vector, const Function *const coefficient, const AffineConstraints &constraints) { create_mass_matrix(get_default_linear_mapping(dof.get_triangulation()), dof, q, matrix, rhs, rhs_vector, coefficient, constraints); } template void create_mass_matrix( const hp::MappingCollection &mapping, const DoFHandler &dof, const hp::QCollection &q, MatrixType &matrix, const Function *const coefficient, const AffineConstraints &constraints) { Assert(matrix.m() == dof.n_dofs(), ExcDimensionMismatch(matrix.m(), dof.n_dofs())); Assert(matrix.n() == dof.n_dofs(), ExcDimensionMismatch(matrix.n(), dof.n_dofs())); MatrixCreator::internal::AssemblerData:: Scratch assembler_data(dof.get_fe_collection(), update_values | update_JxW_values | (coefficient != nullptr ? update_quadrature_points : UpdateFlags(0)), coefficient, /*rhs_function=*/nullptr, q, mapping); MatrixCreator::internal::AssemblerData::CopyData< typename MatrixType::value_type> copy_data; copy_data.cell_matrix.reinit( assembler_data.fe_collection.max_dofs_per_cell(), assembler_data.fe_collection.max_dofs_per_cell()); copy_data.cell_rhs.reinit(assembler_data.fe_collection.max_dofs_per_cell()); copy_data.dof_indices.resize( assembler_data.fe_collection.max_dofs_per_cell()); copy_data.constraints = &constraints; WorkStream::run( dof.begin_active(), static_cast::active_cell_iterator>( dof.end()), &MatrixCreator::internal::mass_assembler< dim, spacedim, typename DoFHandler::active_cell_iterator, typename MatrixType::value_type>, [&matrix]( const internal::AssemblerData::CopyData &data) { MatrixCreator::internal::copy_local_to_global( data, &matrix, static_cast *>(nullptr)); }, assembler_data, copy_data); matrix.compress(VectorOperation::add); } template void create_mass_matrix( const DoFHandler &dof, const hp::QCollection &q, MatrixType &matrix, const Function *const coefficient, const AffineConstraints &constraints) { create_mass_matrix(hp::StaticMappingQ1::mapping_collection, dof, q, matrix, coefficient, constraints); } template void create_mass_matrix( const hp::MappingCollection &mapping, const DoFHandler &dof, const hp::QCollection &q, MatrixType &matrix, const Function &rhs, Vector &rhs_vector, const Function *const coefficient, const AffineConstraints &constraints) { Assert(matrix.m() == dof.n_dofs(), ExcDimensionMismatch(matrix.m(), dof.n_dofs())); Assert(matrix.n() == dof.n_dofs(), ExcDimensionMismatch(matrix.n(), dof.n_dofs())); MatrixCreator::internal::AssemblerData:: Scratch assembler_data(dof.get_fe_collection(), update_values | update_JxW_values | update_quadrature_points, coefficient, &rhs, q, mapping); MatrixCreator::internal::AssemblerData::CopyData< typename MatrixType::value_type> copy_data; copy_data.cell_matrix.reinit( assembler_data.fe_collection.max_dofs_per_cell(), assembler_data.fe_collection.max_dofs_per_cell()); copy_data.cell_rhs.reinit(assembler_data.fe_collection.max_dofs_per_cell()); copy_data.dof_indices.resize( assembler_data.fe_collection.max_dofs_per_cell()); copy_data.constraints = &constraints; WorkStream::run( dof.begin_active(), static_cast::active_cell_iterator>( dof.end()), &MatrixCreator::internal::mass_assembler< dim, spacedim, typename DoFHandler::active_cell_iterator, typename MatrixType::value_type>, [&matrix, &rhs_vector]( const internal::AssemblerData::CopyData &data) { MatrixCreator::internal::copy_local_to_global(data, &matrix, &rhs_vector); }, assembler_data, copy_data); matrix.compress(VectorOperation::add); } template void create_mass_matrix( const DoFHandler &dof, const hp::QCollection &q, MatrixType &matrix, const Function &rhs, Vector &rhs_vector, const Function *const coefficient, const AffineConstraints &constraints) { create_mass_matrix(hp::StaticMappingQ1::mapping_collection, dof, q, matrix, rhs, rhs_vector, coefficient, constraints); } namespace internal { template void inline create_boundary_mass_matrix_1( const typename DoFHandler::active_cell_iterator &cell, const MatrixCreator::internal::AssemblerBoundary::Scratch &, MatrixCreator::internal::AssemblerBoundary:: CopyData ©_data, const Mapping &mapping, const FiniteElement &fe, const Quadrature &q, const std::map *> &boundary_functions, const Function *const coefficient, const std::vector &component_mapping) { // Most assertions for this function are in the calling function // before creating threads. const unsigned int n_components = fe.n_components(); const unsigned int n_function_components = boundary_functions.begin()->second->n_components; const bool fe_is_system = (n_components != 1); const bool fe_is_hermite = (dynamic_cast *>(&fe) != nullptr); const bool fe_is_primitive = fe.is_primitive(); copy_data.cell = cell; copy_data.dofs_per_cell = fe.n_dofs_per_cell(); UpdateFlags update_flags = UpdateFlags(update_values | update_JxW_values | update_normal_vectors | update_quadrature_points); if (fe_is_hermite) update_flags = update_flags | update_mapping; FEFaceValues fe_values(mapping, fe, q, update_flags); // two variables for the coefficient, one for the two cases // indicated in the name std::vector coefficient_values(fe_values.n_quadrature_points, 1.); std::vector> coefficient_vector_values( fe_values.n_quadrature_points, Vector(n_components)); const bool coefficient_is_vector = (coefficient != nullptr && coefficient->n_components != 1); std::vector rhs_values_scalar(fe_values.n_quadrature_points); std::vector> rhs_values_system( fe_values.n_quadrature_points, Vector(n_function_components)); copy_data.dofs.resize(copy_data.dofs_per_cell); cell->get_dof_indices(copy_data.dofs); std::vector dofs_on_face_vector; // Because CopyData objects are reused and emplace_back is // used, dof_is_on_face, cell_matrix, and cell_vector must be // cleared before they are reused copy_data.dof_is_on_face.clear(); copy_data.cell_matrix.clear(); copy_data.cell_vector.clear(); for (const unsigned int face : cell->face_indices()) // check if this face is on that part of the boundary we are // interested in if (boundary_functions.find(cell->face(face)->boundary_id()) != boundary_functions.end()) { copy_data.cell_matrix.emplace_back(copy_data.dofs_per_cell, copy_data.dofs_per_cell); copy_data.cell_vector.emplace_back(copy_data.dofs_per_cell); fe_values.reinit(cell, face); if (fe_is_system) // FE has several components { boundary_functions.find(cell->face(face)->boundary_id()) ->second->vector_value_list(fe_values.get_quadrature_points(), rhs_values_system); if (coefficient_is_vector) // If coefficient is vector valued, fill all // components coefficient->vector_value_list( fe_values.get_quadrature_points(), coefficient_vector_values); else { // If a scalar function is given, update the // values, if not, use the default one set in the // constructor above if (coefficient != nullptr) coefficient->value_list(fe_values.get_quadrature_points(), coefficient_values); // Copy scalar values into vector for (unsigned int point = 0; point < fe_values.n_quadrature_points; ++point) coefficient_vector_values[point] = coefficient_values[point]; } // Special treatment for Hdiv elements, // where only normal components should be projected. // For Hdiv we need to compute (u dot n, v dot n) which // can be done as sum over dim components of // u[c] * n[c] * v[c] * n[c] = u[c] * v[c] * // normal_adjustment[c] Same approach does not work for Hcurl, // so we throw an exception. Default value 1.0 allows for use // with non Hdiv elements std::vector> normal_adjustment( fe_values.n_quadrature_points, std::vector(n_components, 1.)); for (unsigned int comp = 0; comp < n_components; ++comp) { const FiniteElement &base = fe.base_element(fe.component_to_base_index(comp).first); const unsigned int bcomp = fe.component_to_base_index(comp).second; if (!base.conforms(FiniteElementData::H1) && base.conforms(FiniteElementData::Hdiv) && fe_is_primitive) DEAL_II_NOT_IMPLEMENTED(); if (!base.conforms(FiniteElementData::H1) && base.conforms(FiniteElementData::Hcurl)) DEAL_II_NOT_IMPLEMENTED(); if (!base.conforms(FiniteElementData::H1) && base.conforms(FiniteElementData::Hdiv)) for (unsigned int point = 0; point < fe_values.n_quadrature_points; ++point) normal_adjustment[point][comp] = fe_values.normal_vector(point)[bcomp] * fe_values.normal_vector(point)[bcomp]; } for (unsigned int point = 0; point < fe_values.n_quadrature_points; ++point) { const double weight = fe_values.JxW(point); for (unsigned int i = 0; i < fe_values.dofs_per_cell; ++i) if (fe_is_primitive) { for (unsigned int j = 0; j < fe_values.dofs_per_cell; ++j) { if (fe.system_to_component_index(j).first == fe.system_to_component_index(i).first) { copy_data.cell_matrix.back()(i, j) += coefficient_vector_values[point]( fe.system_to_component_index(i).first) * weight * fe_values.shape_value(j, point) * fe_values.shape_value(i, point); } } copy_data.cell_vector.back()(i) += rhs_values_system[point]( component_mapping[fe.system_to_component_index(i) .first]) * fe_values.shape_value(i, point) * weight; } else { for (unsigned int comp = 0; comp < n_components; ++comp) { for (unsigned int j = 0; j < fe_values.dofs_per_cell; ++j) copy_data.cell_matrix.back()(i, j) += coefficient_vector_values[point](comp) * fe_values.shape_value_component(j, point, comp) * fe_values.shape_value_component(i, point, comp) * normal_adjustment[point][comp] * weight; copy_data.cell_vector.back()(i) += rhs_values_system[point]( component_mapping[comp]) * fe_values.shape_value_component(i, point, comp) * normal_adjustment[point][comp] * weight; } } } } else // FE is a scalar one { boundary_functions.find(cell->face(face)->boundary_id()) ->second->value_list(fe_values.get_quadrature_points(), rhs_values_scalar); if (coefficient != nullptr) coefficient->value_list(fe_values.get_quadrature_points(), coefficient_values); for (unsigned int point = 0; point < fe_values.n_quadrature_points; ++point) { const double weight = fe_values.JxW(point); for (unsigned int i = 0; i < fe_values.dofs_per_cell; ++i) { const double v = fe_values.shape_value(i, point); for (unsigned int j = 0; j < fe_values.dofs_per_cell; ++j) { const double u = fe_values.shape_value(j, point); copy_data.cell_matrix.back()(i, j) += (coefficient_values[point] * u * v * weight); } copy_data.cell_vector.back()(i) += rhs_values_scalar[point] * v * weight; } } } dofs_on_face_vector.resize(fe.n_dofs_per_face(face)); cell->face(face)->get_dof_indices(dofs_on_face_vector); // for each dof on the cell, have a flag whether it is on // the face copy_data.dof_is_on_face.emplace_back(copy_data.dofs_per_cell); // check for each of the dofs on this cell whether it is // on the face for (unsigned int i = 0; i < copy_data.dofs_per_cell; ++i) copy_data.dof_is_on_face.back()[i] = (std::find(dofs_on_face_vector.begin(), dofs_on_face_vector.end(), copy_data.dofs[i]) != dofs_on_face_vector.end()); } } template void copy_boundary_mass_matrix_1( const MatrixCreator::internal::AssemblerBoundary:: CopyData ©_data, const std::map *> &boundary_functions, const std::vector &dof_to_boundary_mapping, SparseMatrix &matrix, Vector &rhs_vector) { // now transfer cell matrix and vector to the whole boundary matrix // // in the following: dof[i] holds the global index of the i-th degree of // freedom on the present cell. If it is also a dof on the boundary, it // must be a nonzero entry in the dof_to_boundary_mapping and then // the boundary index of this dof is dof_to_boundary_mapping[dof[i]]. // // if dof[i] is not on the boundary, it should be zero on the boundary // therefore on all quadrature points and finally all of its // entries in the cell matrix and vector should be zero. If not, we // throw an error (note: because of the evaluation of the shape // functions only up to machine precision, the term "must be zero" // really should mean: "should be very small". since this is only an // assertion and not part of the code, we may choose "very small" // quite arbitrarily) // // the main problem here is that the matrix or vector entry should also // be zero if the degree of freedom dof[i] is on the boundary, but not // on the present face, i.e. on another face of the same cell also // on the boundary. We can therefore not rely on the // dof_to_boundary_mapping[dof[i]] being !=-1, we really have to // determine whether dof[i] is a dof on the present face. We do so // by getting the dofs on the face into @p{dofs_on_face_vector}, // a vector as always. Usually, searching in a vector is // inefficient, so we copy the dofs into a set, which enables binary // searches. unsigned int pos(0); for (const unsigned int face : copy_data.cell->face_indices()) { // check if this face is on that part of // the boundary we are interested in if (boundary_functions.find( copy_data.cell->face(face)->boundary_id()) != boundary_functions.end()) { for (unsigned int i = 0; i < copy_data.dofs_per_cell; ++i) { if (copy_data.dof_is_on_face[pos][i] && dof_to_boundary_mapping[copy_data.dofs[i]] != numbers::invalid_dof_index) { for (unsigned int j = 0; j < copy_data.dofs_per_cell; ++j) if (copy_data.dof_is_on_face[pos][j] && dof_to_boundary_mapping[copy_data.dofs[j]] != numbers::invalid_dof_index) { AssertIsFinite(copy_data.cell_matrix[pos](i, j)); matrix.add( dof_to_boundary_mapping[copy_data.dofs[i]], dof_to_boundary_mapping[copy_data.dofs[j]], copy_data.cell_matrix[pos](i, j)); } AssertIsFinite(copy_data.cell_vector[pos](i)); rhs_vector(dof_to_boundary_mapping[copy_data.dofs[i]]) += copy_data.cell_vector[pos](i); } } ++pos; } } } template <> void inline create_boundary_mass_matrix_1<1, 3, float>( const DoFHandler<1, 3>::active_cell_iterator & /*cell*/, const MatrixCreator::internal::AssemblerBoundary::Scratch &, MatrixCreator::internal::AssemblerBoundary::CopyData<1, 3, float> & /*copy_data*/, const Mapping<1, 3> &, const FiniteElement<1, 3> &, const Quadrature<0> &, const std::map *> & /*boundary_functions*/, const Function<3, float> *const /*coefficient*/, const std::vector & /*component_mapping*/) { DEAL_II_NOT_IMPLEMENTED(); } template <> void inline create_boundary_mass_matrix_1<1, 3, double>( const DoFHandler<1, 3>::active_cell_iterator & /*cell*/, const MatrixCreator::internal::AssemblerBoundary::Scratch &, MatrixCreator::internal::AssemblerBoundary::CopyData<1, 3, double> & /*copy_data*/, const Mapping<1, 3> &, const FiniteElement<1, 3> &, const Quadrature<0> &, const std::map *> & /*boundary_functions*/, const Function<3, double> *const /*coefficient*/, const std::vector & /*component_mapping*/) { DEAL_II_NOT_IMPLEMENTED(); } } // namespace internal template void create_boundary_mass_matrix( const Mapping &mapping, const DoFHandler &dof, const Quadrature &q, SparseMatrix &matrix, const std::map *> &boundary_functions, Vector &rhs_vector, std::vector &dof_to_boundary_mapping, const Function *const coefficient, std::vector component_mapping) { // what would that be in 1d? the // identity matrix on the boundary // dofs? if (dim == 1) { DEAL_II_NOT_IMPLEMENTED(); return; } const FiniteElement &fe = dof.get_fe(); const unsigned int n_components = fe.n_components(); const bool fe_is_hermite = (dynamic_cast *>(&fe) != nullptr); Assert(fe_is_hermite || matrix.n() == dof.n_boundary_dofs(boundary_functions), ExcInternalError()); Assert(matrix.n() == matrix.m(), ExcInternalError()); Assert(matrix.n() == rhs_vector.size(), ExcInternalError()); Assert(boundary_functions.size() != 0, ExcInternalError()); Assert(dof_to_boundary_mapping.size() == dof.n_dofs(), ExcInternalError()); Assert(coefficient == nullptr || coefficient->n_components == 1 || coefficient->n_components == n_components, ExcComponentMismatch()); if (component_mapping.empty()) { AssertDimension(n_components, boundary_functions.begin()->second->n_components); for (unsigned int i = 0; i < n_components; ++i) component_mapping.push_back(i); } else AssertDimension(n_components, component_mapping.size()); MatrixCreator::internal::AssemblerBoundary::Scratch scratch; MatrixCreator::internal::AssemblerBoundary::CopyData copy_data; WorkStream::run( dof.begin_active(), dof.end(), [&mapping, &fe, &q, &boundary_functions, coefficient, &component_mapping]( const typename DoFHandler::active_cell_iterator &cell, const MatrixCreator::internal::AssemblerBoundary::Scratch &scratch_data, MatrixCreator::internal::AssemblerBoundary:: CopyData ©_data) { internal::create_boundary_mass_matrix_1(cell, scratch_data, copy_data, mapping, fe, q, boundary_functions, coefficient, component_mapping); }, [&boundary_functions, &dof_to_boundary_mapping, &matrix, &rhs_vector]( const MatrixCreator::internal::AssemblerBoundary:: CopyData ©_data) { internal::copy_boundary_mass_matrix_1(copy_data, boundary_functions, dof_to_boundary_mapping, matrix, rhs_vector); }, scratch, copy_data); } namespace internal { template void create_hp_boundary_mass_matrix_1( const typename DoFHandler::active_cell_iterator &cell, const MatrixCreator::internal::AssemblerBoundary::Scratch &, MatrixCreator::internal::AssemblerBoundary :: CopyData ©_data, const hp::MappingCollection &mapping, const hp::FECollection &fe_collection, const hp::QCollection &q, const std::map *> &boundary_functions, const Function *const coefficient, const std::vector &component_mapping) { const unsigned int n_components = fe_collection.n_components(); const unsigned int n_function_components = boundary_functions.begin()->second->n_components; const FiniteElement &fe = cell->get_fe(); const bool fe_is_system = (n_components != 1); const bool fe_is_primitive = fe.is_primitive(); copy_data.cell = cell; copy_data.dofs_per_cell = fe.n_dofs_per_cell(); copy_data.dofs.resize(copy_data.dofs_per_cell); cell->get_dof_indices(copy_data.dofs); UpdateFlags update_flags = UpdateFlags(update_values | update_JxW_values | update_normal_vectors | update_quadrature_points); hp::FEFaceValues x_fe_values(mapping, fe_collection, q, update_flags); // two variables for the coefficient, // one for the two cases indicated in // the name std::vector coefficient_values; std::vector> coefficient_vector_values; const bool coefficient_is_vector = (coefficient != nullptr && coefficient->n_components != 1); std::vector rhs_values_scalar; std::vector> rhs_values_system; std::vector dofs_on_face_vector; copy_data.dofs.resize(copy_data.dofs_per_cell); cell->get_dof_indices(copy_data.dofs); // Because CopyData objects are reused and that push_back is used, // dof_is_on_face, cell_matrix, and cell_vector must be cleared before // they are reused copy_data.dof_is_on_face.clear(); copy_data.cell_matrix.clear(); copy_data.cell_vector.clear(); for (const unsigned int face : cell->face_indices()) // check if this face is on that part of // the boundary we are interested in if (boundary_functions.find(cell->face(face)->boundary_id()) != boundary_functions.end()) { x_fe_values.reinit(cell, face); const FEFaceValues &fe_values = x_fe_values.get_present_fe_values(); copy_data.cell_matrix.emplace_back(copy_data.dofs_per_cell, copy_data.dofs_per_cell); copy_data.cell_vector.emplace_back(copy_data.dofs_per_cell); if (fe_is_system) // FE has several components { coefficient_vector_values.resize(fe_values.n_quadrature_points, Vector(n_components)); coefficient_values.resize(fe_values.n_quadrature_points, 1.); rhs_values_system.resize(fe_values.n_quadrature_points, Vector(n_function_components)); boundary_functions.find(cell->face(face)->boundary_id()) ->second->vector_value_list(fe_values.get_quadrature_points(), rhs_values_system); if (coefficient_is_vector) // In case coefficient is vector-valued, fill // all components coefficient->vector_value_list( fe_values.get_quadrature_points(), coefficient_vector_values); else // In case the scalar function is given, update the // values, if not - use the default (1.0) { if (coefficient != nullptr) coefficient->value_list(fe_values.get_quadrature_points(), coefficient_values); for (unsigned int point = 0; point < fe_values.n_quadrature_points; ++point) coefficient_vector_values[point] = coefficient_values[point]; } // Special treatment for Hdiv elements, // where only normal components should be projected. // For Hdiv we need to compute (u dot n, v dot n) which // can be done as sum over dim components of // u[c] * n[c] * v[c] * n[c] = u[c] * v[c] * // normal_adjustment[c] Same approach does not work for Hcurl, // so we throw an exception. Default value 1.0 allows for use // with non Hdiv elements std::vector> normal_adjustment( fe_values.n_quadrature_points, std::vector(n_components, 1.)); for (unsigned int comp = 0; comp < n_components; ++comp) { const FiniteElement &base = fe.base_element(fe.component_to_base_index(comp).first); const unsigned int bcomp = fe.component_to_base_index(comp).second; if (!base.conforms(FiniteElementData::H1) && base.conforms(FiniteElementData::Hdiv) && fe_is_primitive) DEAL_II_NOT_IMPLEMENTED(); if (!base.conforms(FiniteElementData::H1) && base.conforms(FiniteElementData::Hcurl)) DEAL_II_NOT_IMPLEMENTED(); if (!base.conforms(FiniteElementData::H1) && base.conforms(FiniteElementData::Hdiv)) for (unsigned int point = 0; point < fe_values.n_quadrature_points; ++point) normal_adjustment[point][comp] = fe_values.normal_vector(point)[bcomp] * fe_values.normal_vector(point)[bcomp]; } for (unsigned int point = 0; point < fe_values.n_quadrature_points; ++point) { const double weight = fe_values.JxW(point); for (unsigned int i = 0; i < fe_values.dofs_per_cell; ++i) if (fe_is_primitive) { for (unsigned int j = 0; j < fe_values.dofs_per_cell; ++j) { if (fe.system_to_component_index(i).first == fe.system_to_component_index(j).first) { copy_data.cell_matrix.back()(i, j) += coefficient_vector_values[point]( fe.system_to_component_index(i).first) * fe_values.shape_value(i, point) * fe_values.shape_value(j, point) * weight; } } copy_data.cell_vector.back()(i) += rhs_values_system[point]( component_mapping[fe.system_to_component_index(i) .first]) * fe_values.shape_value(i, point) * weight; } else { for (unsigned int comp = 0; comp < n_components; ++comp) { for (unsigned int j = 0; j < fe_values.dofs_per_cell; ++j) copy_data.cell_matrix.back()(i, j) += coefficient_vector_values[point](comp) * fe_values.shape_value_component(i, point, comp) * fe_values.shape_value_component(j, point, comp) * normal_adjustment[point][comp] * weight; copy_data.cell_vector.back()(i) += rhs_values_system[point]( component_mapping[comp]) * fe_values.shape_value_component(i, point, comp) * normal_adjustment[point][comp] * weight; } } } } else // FE is scalar { coefficient_values.resize(fe_values.n_quadrature_points, 1.); rhs_values_scalar.resize(fe_values.n_quadrature_points); boundary_functions.find(cell->face(face)->boundary_id()) ->second->value_list(fe_values.get_quadrature_points(), rhs_values_scalar); if (coefficient != nullptr) { coefficient_values.resize(fe_values.n_quadrature_points); coefficient->value_list(fe_values.get_quadrature_points(), coefficient_values); } for (unsigned int point = 0; point < fe_values.n_quadrature_points; ++point) { const double weight = fe_values.JxW(point); for (unsigned int i = 0; i < fe_values.dofs_per_cell; ++i) { const double v = fe_values.shape_value(i, point); for (unsigned int j = 0; j < fe_values.dofs_per_cell; ++j) { const double u = fe_values.shape_value(j, point); copy_data.cell_matrix.back()(i, j) += (coefficient_values[point] * v * u * weight); } copy_data.cell_vector.back()(i) += rhs_values_scalar[point] * v * weight; } } } dofs_on_face_vector.resize(fe.n_dofs_per_face(face)); cell->face(face)->get_dof_indices(dofs_on_face_vector, cell->active_fe_index()); // for each dof on the cell, have a // flag whether it is on the face copy_data.dof_is_on_face.emplace_back(copy_data.dofs_per_cell); // check for each of the dofs on this cell // whether it is on the face for (unsigned int i = 0; i < copy_data.dofs_per_cell; ++i) copy_data.dof_is_on_face.back()[i] = (std::find(dofs_on_face_vector.begin(), dofs_on_face_vector.end(), copy_data.dofs[i]) != dofs_on_face_vector.end()); } } template void copy_hp_boundary_mass_matrix_1( const MatrixCreator::internal::AssemblerBoundary :: CopyData ©_data, const std::map *> &boundary_functions, const std::vector &dof_to_boundary_mapping, SparseMatrix &matrix, Vector &rhs_vector) { // now transfer cell matrix and vector to the whole boundary matrix // // in the following: dof[i] holds the global index of the i-th degree of // freedom on the present cell. If it is also a dof on the boundary, it // must be a nonzero entry in the dof_to_boundary_mapping and then // the boundary index of this dof is dof_to_boundary_mapping[dof[i]]. // // if dof[i] is not on the boundary, it should be zero on the boundary // therefore on all quadrature points and finally all of its // entries in the cell matrix and vector should be zero. If not, we // throw an error (note: because of the evaluation of the shape // functions only up to machine precision, the term "must be zero" // really should mean: "should be very small". since this is only an // assertion and not part of the code, we may choose "very small" // quite arbitrarily) // // the main problem here is that the matrix or vector entry should also // be zero if the degree of freedom dof[i] is on the boundary, but not // on the present face, i.e. on another face of the same cell also // on the boundary. We can therefore not rely on the // dof_to_boundary_mapping[dof[i]] being !=-1, we really have to // determine whether dof[i] is a dof on the present face. We do so // by getting the dofs on the face into @p{dofs_on_face_vector}, // a vector as always. Usually, searching in a vector is // inefficient, so we copy the dofs into a set, which enables binary // searches. unsigned int pos(0); for (const unsigned int face : copy_data.cell->face_indices()) { // check if this face is on that part of // the boundary we are interested in if (boundary_functions.find( copy_data.cell->face(face)->boundary_id()) != boundary_functions.end()) { if constexpr (running_in_debug_mode()) { // in debug mode: compute an element in the matrix which is // guaranteed to belong to a boundary dof. We do this to check // that the entries in the cell matrix are guaranteed to be // zero if the respective dof is not on the boundary. Since // because of round-off, the actual value of the matrix entry // may be only close to zero, we assert that it is small // relative to an element which is guaranteed to be nonzero. // (absolute smallness does not suffice since the size of the // domain scales in here) // // for this purpose we seek the diagonal of the matrix, where // there must be an element belonging to the boundary. we take // the maximum diagonal entry. types::global_dof_index max_element = 0; for (const auto index : dof_to_boundary_mapping) if ((index != numbers::invalid_dof_index) && (index > max_element)) max_element = index; Assert(max_element == matrix.n() - 1, ExcInternalError()); double max_diag_entry = 0; for (unsigned int i = 0; i < copy_data.dofs_per_cell; ++i) if (std::abs(copy_data.cell_matrix[pos](i, i)) > max_diag_entry) max_diag_entry = std::abs(copy_data.cell_matrix[pos](i, i)); } for (unsigned int i = 0; i < copy_data.dofs_per_cell; ++i) { if (copy_data.dof_is_on_face[pos][i] && dof_to_boundary_mapping[copy_data.dofs[i]] != numbers::invalid_dof_index) { for (unsigned int j = 0; j < copy_data.dofs_per_cell; ++j) if (copy_data.dof_is_on_face[pos][j] && dof_to_boundary_mapping[copy_data.dofs[j]] != numbers::invalid_dof_index) { AssertIsFinite(copy_data.cell_matrix[pos](i, j)); matrix.add( dof_to_boundary_mapping[copy_data.dofs[i]], dof_to_boundary_mapping[copy_data.dofs[j]], copy_data.cell_matrix[pos](i, j)); } AssertIsFinite(copy_data.cell_vector[pos](i)); rhs_vector(dof_to_boundary_mapping[copy_data.dofs[i]]) += copy_data.cell_vector[pos](i); } } ++pos; } } } } // namespace internal template void create_boundary_mass_matrix( const DoFHandler &dof, const Quadrature &q, SparseMatrix &matrix, const std::map *> &rhs, Vector &rhs_vector, std::vector &dof_to_boundary_mapping, const Function *const a, std::vector component_mapping) { create_boundary_mass_matrix(get_default_linear_mapping( dof.get_triangulation()), dof, q, matrix, rhs, rhs_vector, dof_to_boundary_mapping, a, component_mapping); } template void create_boundary_mass_matrix( const hp::MappingCollection &mapping, const DoFHandler &dof, const hp::QCollection &q, SparseMatrix &matrix, const std::map *> &boundary_functions, Vector &rhs_vector, std::vector &dof_to_boundary_mapping, const Function *const coefficient, std::vector component_mapping) { // what would that be in 1d? the // identity matrix on the boundary // dofs? if (dim == 1) { DEAL_II_NOT_IMPLEMENTED(); return; } const hp::FECollection &fe_collection = dof.get_fe_collection(); const unsigned int n_components = fe_collection.n_components(); Assert(matrix.n() == dof.n_boundary_dofs(boundary_functions), ExcInternalError()); Assert(matrix.n() == matrix.m(), ExcInternalError()); Assert(matrix.n() == rhs_vector.size(), ExcInternalError()); Assert(boundary_functions.size() != 0, ExcInternalError()); Assert(dof_to_boundary_mapping.size() == dof.n_dofs(), ExcInternalError()); Assert(coefficient == nullptr || coefficient->n_components == 1 || coefficient->n_components == n_components, ExcComponentMismatch()); if (component_mapping.empty()) { AssertDimension(n_components, boundary_functions.begin()->second->n_components); for (unsigned int i = 0; i < n_components; ++i) component_mapping.push_back(i); } else AssertDimension(n_components, component_mapping.size()); MatrixCreator::internal::AssemblerBoundary::Scratch scratch; MatrixCreator::internal::AssemblerBoundary::CopyData copy_data; WorkStream::run( dof.begin_active(), dof.end(), [&mapping, &fe_collection, &q, &boundary_functions, coefficient, &component_mapping]( const typename DoFHandler::active_cell_iterator &cell, const MatrixCreator::internal::AssemblerBoundary::Scratch &scratch_data, MatrixCreator::internal::AssemblerBoundary :: CopyData ©_data) { internal::create_hp_boundary_mass_matrix_1(cell, scratch_data, copy_data, mapping, fe_collection, q, boundary_functions, coefficient, component_mapping); }, [&boundary_functions, &dof_to_boundary_mapping, &matrix, &rhs_vector]( const MatrixCreator::internal::AssemblerBoundary :: CopyData ©_data) { internal::copy_hp_boundary_mass_matrix_1(copy_data, boundary_functions, dof_to_boundary_mapping, matrix, rhs_vector); }, scratch, copy_data); } template void create_boundary_mass_matrix( const DoFHandler &dof, const hp::QCollection &q, SparseMatrix &matrix, const std::map *> &rhs, Vector &rhs_vector, std::vector &dof_to_boundary_mapping, const Function *const a, std::vector component_mapping) { create_boundary_mass_matrix( hp::StaticMappingQ1::mapping_collection, dof, q, matrix, rhs, rhs_vector, dof_to_boundary_mapping, a, component_mapping); } template void create_laplace_matrix( const Mapping &mapping, const DoFHandler &dof, const Quadrature &q, MatrixType &matrix, const Function *const coefficient, const AffineConstraints &constraints) { Assert(matrix.m() == dof.n_dofs(), ExcDimensionMismatch(matrix.m(), dof.n_dofs())); Assert(matrix.n() == dof.n_dofs(), ExcDimensionMismatch(matrix.n(), dof.n_dofs())); const auto &fe_collection = dof.get_fe_collection(); hp::QCollection q_collection(q); hp::MappingCollection mapping_collection(mapping); MatrixCreator::internal::AssemblerData:: Scratch assembler_data(fe_collection, update_gradients | update_JxW_values | (coefficient != nullptr ? update_quadrature_points : UpdateFlags(0)), coefficient, /*rhs_function=*/nullptr, q_collection, mapping_collection); MatrixCreator::internal::AssemblerData::CopyData< typename MatrixType::value_type> copy_data; copy_data.cell_matrix.reinit( assembler_data.fe_collection.max_dofs_per_cell(), assembler_data.fe_collection.max_dofs_per_cell()); copy_data.cell_rhs.reinit(assembler_data.fe_collection.max_dofs_per_cell()); copy_data.dof_indices.resize( assembler_data.fe_collection.max_dofs_per_cell()); copy_data.constraints = &constraints; WorkStream::run( dof.begin_active(), static_cast::active_cell_iterator>( dof.end()), &MatrixCreator::internal::laplace_assembler< dim, spacedim, typename DoFHandler::active_cell_iterator, typename MatrixType::value_type>, [&matrix]( const internal::AssemblerData::CopyData &data) { MatrixCreator::internal::copy_local_to_global( data, &matrix, static_cast *>(nullptr)); }, assembler_data, copy_data); matrix.compress(VectorOperation::add); } template void create_laplace_matrix( const DoFHandler &dof, const Quadrature &q, MatrixType &matrix, const Function *const coefficient, const AffineConstraints &constraints) { create_laplace_matrix(get_default_linear_mapping(dof.get_triangulation()), dof, q, matrix, coefficient, constraints); } template void create_laplace_matrix( const Mapping &mapping, const DoFHandler &dof, const Quadrature &q, MatrixType &matrix, const Function &rhs, Vector &rhs_vector, const Function *const coefficient, const AffineConstraints &constraints) { Assert(matrix.m() == dof.n_dofs(), ExcDimensionMismatch(matrix.m(), dof.n_dofs())); Assert(matrix.n() == dof.n_dofs(), ExcDimensionMismatch(matrix.n(), dof.n_dofs())); const auto &fe_collection = dof.get_fe_collection(); hp::QCollection q_collection(q); hp::MappingCollection mapping_collection(mapping); MatrixCreator::internal::AssemblerData:: Scratch assembler_data(fe_collection, update_gradients | update_values | update_JxW_values | update_quadrature_points, coefficient, &rhs, q_collection, mapping_collection); MatrixCreator::internal::AssemblerData::CopyData< typename MatrixType::value_type> copy_data; copy_data.cell_matrix.reinit( assembler_data.fe_collection.max_dofs_per_cell(), assembler_data.fe_collection.max_dofs_per_cell()); copy_data.cell_rhs.reinit(assembler_data.fe_collection.max_dofs_per_cell()); copy_data.dof_indices.resize( assembler_data.fe_collection.max_dofs_per_cell()); copy_data.constraints = &constraints; WorkStream::run( dof.begin_active(), static_cast::active_cell_iterator>( dof.end()), &MatrixCreator::internal::laplace_assembler< dim, spacedim, typename DoFHandler::active_cell_iterator, typename MatrixType::value_type>, [&matrix, &rhs_vector]( const internal::AssemblerData::CopyData &data) { MatrixCreator::internal::copy_local_to_global(data, &matrix, &rhs_vector); }, assembler_data, copy_data); matrix.compress(VectorOperation::add); } template void create_laplace_matrix( const DoFHandler &dof, const Quadrature &q, MatrixType &matrix, const Function &rhs, Vector &rhs_vector, const Function *const coefficient, const AffineConstraints &constraints) { create_laplace_matrix(get_default_linear_mapping(dof.get_triangulation()), dof, q, matrix, rhs, rhs_vector, coefficient, constraints); } template void create_laplace_matrix( const hp::MappingCollection &mapping, const DoFHandler &dof, const hp::QCollection &q, MatrixType &matrix, const Function *const coefficient, const AffineConstraints &constraints) { Assert(matrix.m() == dof.n_dofs(), ExcDimensionMismatch(matrix.m(), dof.n_dofs())); Assert(matrix.n() == dof.n_dofs(), ExcDimensionMismatch(matrix.n(), dof.n_dofs())); MatrixCreator::internal::AssemblerData:: Scratch assembler_data(dof.get_fe_collection(), update_gradients | update_JxW_values | (coefficient != nullptr ? update_quadrature_points : UpdateFlags(0)), coefficient, /*rhs_function=*/nullptr, q, mapping); MatrixCreator::internal::AssemblerData::CopyData< typename MatrixType::value_type> copy_data; copy_data.cell_matrix.reinit( assembler_data.fe_collection.max_dofs_per_cell(), assembler_data.fe_collection.max_dofs_per_cell()); copy_data.cell_rhs.reinit(assembler_data.fe_collection.max_dofs_per_cell()); copy_data.dof_indices.resize( assembler_data.fe_collection.max_dofs_per_cell()); copy_data.constraints = &constraints; WorkStream::run( dof.begin_active(), static_cast::active_cell_iterator>( dof.end()), &MatrixCreator::internal::laplace_assembler< dim, spacedim, typename DoFHandler::active_cell_iterator, typename MatrixType::value_type>, [&matrix]( const internal::AssemblerData::CopyData &data) { MatrixCreator::internal::copy_local_to_global( data, &matrix, static_cast *>(nullptr)); }, assembler_data, copy_data); matrix.compress(VectorOperation::add); } template void create_laplace_matrix( const DoFHandler &dof, const hp::QCollection &q, MatrixType &matrix, const Function *const coefficient, const AffineConstraints &constraints) { create_laplace_matrix( hp::StaticMappingQ1::mapping_collection, dof, q, matrix, coefficient, constraints); } template void create_laplace_matrix( const hp::MappingCollection &mapping, const DoFHandler &dof, const hp::QCollection &q, MatrixType &matrix, const Function &rhs, Vector &rhs_vector, const Function *const coefficient, const AffineConstraints &constraints) { Assert(matrix.m() == dof.n_dofs(), ExcDimensionMismatch(matrix.m(), dof.n_dofs())); Assert(matrix.n() == dof.n_dofs(), ExcDimensionMismatch(matrix.n(), dof.n_dofs())); MatrixCreator::internal::AssemblerData:: Scratch assembler_data(dof.get_fe_collection(), update_gradients | update_values | update_JxW_values | update_quadrature_points, coefficient, &rhs, q, mapping); MatrixCreator::internal::AssemblerData::CopyData< typename MatrixType::value_type> copy_data; copy_data.cell_matrix.reinit( assembler_data.fe_collection.max_dofs_per_cell(), assembler_data.fe_collection.max_dofs_per_cell()); copy_data.cell_rhs.reinit(assembler_data.fe_collection.max_dofs_per_cell()); copy_data.dof_indices.resize( assembler_data.fe_collection.max_dofs_per_cell()); copy_data.constraints = &constraints; WorkStream::run( dof.begin_active(), static_cast::active_cell_iterator>( dof.end()), &MatrixCreator::internal::laplace_assembler< dim, spacedim, typename DoFHandler::active_cell_iterator, typename MatrixType::value_type>, [&matrix, &rhs_vector]( const internal::AssemblerData::CopyData &data) { MatrixCreator::internal::copy_local_to_global(data, &matrix, &rhs_vector); }, assembler_data, copy_data); matrix.compress(VectorOperation::add); } template void create_laplace_matrix( const DoFHandler &dof, const hp::QCollection &q, MatrixType &matrix, const Function &rhs, Vector &rhs_vector, const Function *const coefficient, const AffineConstraints &constraints) { create_laplace_matrix( hp::StaticMappingQ1::mapping_collection, dof, q, matrix, rhs, rhs_vector, coefficient, constraints); } } // namespace MatrixCreator DEAL_II_NAMESPACE_CLOSE #endif