Skip to content

Commit bc0b219

Browse files
committed
Initial support for conversion from 4C to deal.II
1 parent 43590bd commit bc0b219

17 files changed

+1964
-0
lines changed

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ add_subdirectory(contact_constitutivelaw)
2222
add_subdirectory(core)
2323
add_subdirectory(coupling)
2424
add_subdirectory(cut)
25+
if(FOUR_C_WITH_DEAL_II)
26+
add_subdirectory(deal_ii)
27+
endif()
2528
add_subdirectory(ehl)
2629
add_subdirectory(elch)
2730
add_subdirectory(fbi)

src/deal_ii/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
four_c_auto_define_module(NO_CYCLES)
9+
10+
# deal.II support is a pure extension of the core module and may not depend on any other module
11+
four_c_add_dependency(${AUTO_DEFINED_MODULE_NAME} core)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
#ifndef FOUR_C_DEAL_II_CONTEXT_HPP
9+
#define FOUR_C_DEAL_II_CONTEXT_HPP
10+
11+
#include "4C_config.hpp"
12+
13+
#include <memory>
14+
15+
FOUR_C_NAMESPACE_OPEN
16+
17+
namespace DealiiWrappers
18+
{
19+
20+
// forward declaration
21+
namespace Internal
22+
{
23+
template <int dim, int spacedim>
24+
struct ContextImplementation;
25+
}
26+
27+
/**
28+
* This class holds data which helps other classes and functions in this namespace to understand
29+
* the link between 4C and deal.II data structures. There is no documented and supported
30+
* functionality for this class. In fact, you should not try to do anything with the internals of
31+
* this class.
32+
*/
33+
template <int dim, int spacedim = dim>
34+
struct Context
35+
{
36+
std::shared_ptr<Internal::ContextImplementation<dim, spacedim>> pimpl_;
37+
};
38+
} // namespace DealiiWrappers
39+
40+
FOUR_C_NAMESPACE_CLOSE
41+
42+
#endif
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
#ifndef FOUR_C_DEAL_II_CONTEXT_IMPLEMENTATION_HPP
9+
#define FOUR_C_DEAL_II_CONTEXT_IMPLEMENTATION_HPP
10+
11+
#include "4C_config.hpp"
12+
13+
#include "4C_deal_ii_context.hpp"
14+
#include "4C_fem_discretization.hpp"
15+
16+
#include <deal.II/hp/fe_collection.h>
17+
#include <deal.II/hp/mapping_collection.h>
18+
19+
#include <unordered_map>
20+
#include <vector>
21+
22+
FOUR_C_NAMESPACE_OPEN
23+
24+
namespace DealiiWrappers::Internal
25+
{
26+
template <int dim, int spacedim = dim>
27+
struct ContextImplementation
28+
{
29+
//! Store the local mapping between deal.II cells and 4C elements
30+
std::unordered_map<int, int> cell_index_to_element_lid;
31+
32+
//! All dealii::FiniteElement objects that are required for the original 4C discretization.
33+
dealii::hp::FECollection<dim, spacedim> finite_elements;
34+
35+
//! The names of the FiniteElements in #finite_elements.
36+
std::vector<std::string> finite_element_names;
37+
};
38+
} // namespace DealiiWrappers::Internal
39+
40+
FOUR_C_NAMESPACE_CLOSE
41+
42+
#endif
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
#ifndef FOUR_C_DEAL_II_DOFS_HPP
9+
#define FOUR_C_DEAL_II_DOFS_HPP
10+
11+
#include "4C_config.hpp"
12+
13+
#include "4C_deal_ii_context.hpp"
14+
15+
#include <deal.II/dofs/dof_handler.h>
16+
17+
FOUR_C_NAMESPACE_OPEN
18+
19+
namespace Core::FE
20+
{
21+
class Discretization;
22+
}
23+
24+
namespace DealiiWrappers
25+
{
26+
/**
27+
* @brief Assigns a finite element and degrees of freedom to the given @p dof_handler.
28+
*
29+
* The information about the finite element and degrees of freedom is taken from the
30+
* @p context object, which was created during create_triangulation(). After calling this
31+
* function, the @p dof_handler will be set up to mimic the finite element space inside
32+
* the @p discretization object.
33+
*/
34+
template <int dim, int spacedim>
35+
void assign_fes_and_dofs(dealii::DoFHandler<dim, spacedim>& dof_handler,
36+
const Core::FE::Discretization& discretization, Context<dim, spacedim>& context);
37+
38+
} // namespace DealiiWrappers
39+
40+
FOUR_C_NAMESPACE_CLOSE
41+
42+
#endif

0 commit comments

Comments
 (0)