|
| 1 | +// This file is part of 4C multiphysics licensed under the |
| 2 | +// GNU Lesser General Public License v3.0 or later. |
| 3 | +// |
| 4 | +// See the LICENSE.md file in the top-level for license information. |
| 5 | +// |
| 6 | +// SPDX-License-Identifier: LGPL-3.0-or-later |
| 7 | + |
| 8 | +#include "4C_deal_ii_dofs.hpp" |
| 9 | + |
| 10 | +#include "4C_deal_ii_context_implementation.hpp" |
| 11 | +#include "4C_deal_ii_element_conversion.hpp" |
| 12 | +#include "4C_fem_discretization.hpp" |
| 13 | + |
| 14 | +#include <deal.II/fe/fe_system.h> |
| 15 | +#include <deal.II/fe/fe_tools.h> |
| 16 | +#include <deal.II/fe/mapping_q.h> |
| 17 | +#include <deal.II/hp/mapping_collection.h> |
| 18 | + |
| 19 | +FOUR_C_NAMESPACE_OPEN |
| 20 | + |
| 21 | +namespace DealiiWrappers |
| 22 | +{ |
| 23 | + |
| 24 | + template <int dim, int spacedim> |
| 25 | + void assign_fes_and_dofs(dealii::DoFHandler<dim, spacedim>& dof_handler, |
| 26 | + const Core::FE::Discretization& discretization, Context<dim, spacedim>& context) |
| 27 | + { |
| 28 | + const auto& fe_collection = context.pimpl_->finite_elements; |
| 29 | + const auto& fe_names = context.pimpl_->finite_element_names; |
| 30 | + |
| 31 | + // Loop all cells again and set the correct fe index within the collection |
| 32 | + for (const auto& cell : dof_handler.active_cell_iterators()) |
| 33 | + { |
| 34 | + if (!cell->is_locally_owned()) continue; |
| 35 | + |
| 36 | + const auto four_c_element_lid = context.pimpl_->cell_index_to_element_lid[cell->index()]; |
| 37 | + const auto* four_c_element = discretization.l_row_element(four_c_element_lid); |
| 38 | + |
| 39 | + auto iter = std::find(fe_names.begin(), fe_names.end(), |
| 40 | + ElementConversion::dealii_fe_name(four_c_element->shape())); |
| 41 | + FOUR_C_ASSERT(iter != fe_names.end(), |
| 42 | + "The finite element name '{}' is not in the list of finite element names.", |
| 43 | + ElementConversion::dealii_fe_name(four_c_element->shape())); |
| 44 | + |
| 45 | + const unsigned index = std::distance(fe_names.begin(), iter); |
| 46 | + cell->set_active_fe_index(index); |
| 47 | + } |
| 48 | + |
| 49 | + // Now distribute the dofs, which will use the previously set index |
| 50 | + dof_handler.distribute_dofs(fe_collection); |
| 51 | + |
| 52 | + // Depending on the element types we need to construct an appropriate mapping collection |
| 53 | + FOUR_C_ASSERT(fe_collection.size() == 1, |
| 54 | + "The current implementation only supports a single finite element type per " |
| 55 | + "discretization."); |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | + // explicit instantiation |
| 60 | + template void assign_fes_and_dofs(dealii::DoFHandler<3, 3>&, |
| 61 | + const Core::FE::Discretization& discretization, Context<3, 3>& context); |
| 62 | +} // namespace DealiiWrappers |
| 63 | + |
| 64 | +FOUR_C_NAMESPACE_CLOSE |
0 commit comments