24#ifndef VULPES_ASSEMBLE_INTEGRATOR_BASE_HPP_
25#define VULPES_ASSEMBLE_INTEGRATOR_BASE_HPP_
33#include <unordered_map>
35#include <unsupported/Eigen/CXX11/Tensor>
61 typename FeExpressionTuple,
62 typename FeExpressionFaceTuple = std::tuple<>>
66 "fe_expression must be a tuple of pointer to FeExpression");
69 "fe_expression_face must be a tuple of pointer to FeExpression");
72 using index_t =
typename MeshType::index_t;
73 using FeType = std::remove_pointer_t<
74 std::tuple_element_t<0, FeExpressionTuple>>::FeSpaceType;
77 std::tuple_size<FeExpressionTuple>{};
80 std::tuple_size<FeExpressionFaceTuple>{};
88 std::tuple_size<FeExpressionTupleBilinear>{};
91 std::tuple_size<FeExpressionTupleLinear>{};
100 std::tuple_size<FeExpressionTupleFaceBilinear>{};
103 std::tuple_size<FeExpressionTupleFaceLinear>{};
105 static inline constexpr std::size_t
dim = MeshType::self_dim;
112 std::remove_pointer_t<
113 std::tuple_element_t<0, FeExpressionTuple>>::k_index_end -
114 std::remove_pointer_t<
115 std::tuple_element_t<0, FeExpressionTuple>>::k_index_begin;
127 const MeshType& mesh,
129 const FeExpressionTuple& fe_expression,
130 const FeExpressionFaceTuple& fe_expression_face)
135 m_fe_space(std::get<0>(fe_expression)->feSpace()) {
139 const uint32_t n_dof_loc =
m_fe_space.getBasis().size();
146 using index_t =
typename MeshType::index_t;
148 for (
index_t cid = 0; cid < mesh.getDualMap().size(); ++cid) {
149 n_max_neigh = std::max(n_max_neigh, mesh.getDualMap()[cid].size());
174 [](
const auto&... expr) {
175 return (expr->computeUpdateFlags() | ...);
181 [](
const auto&... expr) {
182 return (expr->computeUpdateFlags() | ...);
200 [](
const auto&... expr) {
201 return std::max({expr->computeOrder()...});
207 [](
const auto&... expr) {
208 return std::max({expr->computeOrder()...});
224 if (update_mapping) {
226 if constexpr (FeType::needBasisScaling()) {
273 if constexpr (FeType::needBasisScaling()) {
274 neigh_fe_values.setBasisScaling(std::sqrt(
295 if constexpr (FeType::needBasisScaling()) {
297 const double scaling2 = mapping->jacobianDet({});
298 const double scaling = std::sqrt(scaling2);
301 Eigen::Map<Eigen::Vector<double, -1>> integrals_map(
303 integrals_map /= scaling2;
306 Eigen::Map<Eigen::Vector<double, -1>> face_integrals_map(
308 face_integrals_map /= scaling2;
312 for (
index_t ni = 0; ni < n_neigh; ++ni) {
315 const double neigh_scaling = std::sqrt(neigh_map->jacobianDet({}));
316 Eigen::Map<Eigen::Vector<double, -1>> face_integrals_neigh_map(
318 face_integrals_neigh_map /= (scaling * neigh_scaling);
319 Eigen::Map<Eigen::Vector<double, -1>> face_rhs_neigh_map(
322 face_rhs_neigh_map /= neigh_scaling;
346 const auto& expr, Eigen::Index expr_id) {
347 static double s_dummy_mat = 0.0;
348 const bool expr_need_neigh =
351 return Eigen::Map<Eigen::MatrixXd>{&s_dummy_mat, 0, 0};
356 return Eigen::Map<Eigen::MatrixXd>{&s_dummy_mat, 0, 0};
363 const Eigen::Index n_dof_loc =
m_fe_space.getBasis().size();
364 return Eigen::Map<Eigen::MatrixXd>{
381 const auto& expr, Eigen::Index expr_id) {
382 static double s_dummy_vec = 0.0;
383 const bool expr_need_neigh =
386 return Eigen::Map<Eigen::VectorXd>{&s_dummy_vec, 0};
389 return Eigen::Map<Eigen::VectorXd>{&s_dummy_vec, 0};
391 const Eigen::Index n_dof_loc =
m_fe_space.getBasis().size();
396 return Eigen::Map<Eigen::VectorXd>{data_ptr, n_dof_loc *
nblocks};
411 const auto check = [](
auto it_inserted) {
412 const auto [it, inserted] = it_inserted;
414 throw std::logic_error(
415 "the same weak form is used twice in one integrator");
418 auto [bilinear_fe_expression, non_bilinear_fe_expression] =
421 bilinear_fe_expression,
422 [
this, &check](
auto expr_ptr, Eigen::Index expr_id) {
424 static_cast<void*
>(expr_ptr), &
m_integrals(0, 0, expr_id)));
427 non_bilinear_fe_expression,
428 [
this, &check](
auto expr_ptr, Eigen::Index expr_id) {
430 static_cast<void*
>(expr_ptr), &
m_rhs(0, expr_id)));
432 auto [bilinear_fe_expression_face, non_bilinear_fe_expression_face] =
435 bilinear_fe_expression_face,
436 [
this, &check](
auto expr_ptr, Eigen::Index expr_id) {
437 const bool expr_need_neigh =
439 if (expr_need_neigh) {
441 static_cast<void*
>(expr_ptr),
445 static_cast<void*
>(expr_ptr),
450 non_bilinear_fe_expression_face,
451 [
this, &check](
auto expr_ptr, Eigen::Index expr_id) {
452 const bool expr_need_neigh =
454 if (expr_need_neigh) {
456 static_cast<void*
>(expr_ptr),
460 static_cast<void*
>(expr_ptr), &
m_face_rhs(0, expr_id)));
497 (loc_neigh_id <= 0));
498 constexpr bool is_bilinear =
499 std::remove_pointer_t<
decltype(wf_ptr)>::is_bilinear ==
fe::IsBilinear;
500 const Eigen::Index n_dof_loc =
m_fe_space.getBasis().size();
501 const auto nrows = n_dof_loc *
nblocks;
502 const auto ncols = is_bilinear ? nrows : 1;
505 const bool is_neigh_form =
507 if (is_neigh_form && loc_neigh_id < 0) {
516 scratch.setZero(nrows, ncols);
517 for (
index_t ni = 0; ni < n_neigh; ++ni) {
518 scratch += Eigen::Map<const Eigen::MatrixXd>{
519 data + ni * slice_neigh_size, nrows, ncols};
521 return Eigen::Map<const Eigen::MatrixXd>{scratch.data(), nrows, ncols};
523 const auto offset = std::max(
index_t{0}, loc_neigh_id);
524 return Eigen::Map<const Eigen::MatrixXd>{
525 data + offset * slice_neigh_size, nrows, ncols};
Manages geometrical information about the cell and its mapping to the reference element.
Definition cell_manager.hpp:62
This class works as a cache table for computing efficiently the value of the basis function and its d...
Definition fe_values.hpp:94
constexpr auto split_expression_tuple(std::tuple< Ts... > t)
Definition integrator_traits.hpp:145
constexpr bool is_tuple_of_fe_expr_pointers_v
Definition integrator_traits.hpp:102
Definition cell_manager.hpp:39
std::underlying_type_t< UpdateFlags > UpdateFlagsType
Definition fe_values.hpp:65
@ UpdateNeighborCell
Definition fe_values.hpp:61
@ UpdateNeighborValues
Definition fe_values.hpp:62
@ IsBilinear
Definition fe_expr_base.hpp:55
std::conditional_t< Dim==2, Cell2D< FloatType, IndexType >, Cell3D< FloatType, IndexType > > Cell
Definition cell.hpp:267
void for_each_idxed(Tuple &&tuple, Func &&func)
Apply func to every element of tuple together with its index.
Definition vvutils.hpp:165
Definition cell_manager.hpp:38
Information about the neighbouring cell for a certain face.
Definition cell_manager.hpp:73