Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
integrator_qfree.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2026 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Matteo Caldana <matteo.caldana@polimi.it>
22// Author: Pedro Peixoto <ppeixoto@usp.br>
23
24#ifndef VULPES_ASSEMBLE_INTEGRATOR_QFREE_HPP_
25#define VULPES_ASSEMBLE_INTEGRATOR_QFREE_HPP_
26
27#include <algorithm>
28#include <limits>
29#include <map>
30#include <set>
31#include <stdexcept>
32#include <tuple>
33#include <vector>
34
35#include <unsupported/Eigen/CXX11/Tensor>
36
40
41namespace vulpes {
42namespace assemble {
43
62template <std::size_t Dim>
66 uint16_t integr_id;
69 std::array<uint8_t, Dim * 2> evalut_id;
72 std::vector<std::pair<double, std::array<uint8_t, Dim * 2>>> gather;
73};
74
83 double coef;
86 std::size_t integr_id;
87
94 bool operator<(const CompressedMonomial& other) const {
95 return std::tie(coef, integr_id) < std::tie(other.coef, other.integr_id);
96 }
97};
98
110 uint16_t integr_id;
113 uint16_t evalut_id;
116 uint32_t gather_id;
117
124 bool operator<(const CompressedGatheredMonomial& other) const {
125 return std::tie(integr_id, evalut_id, gather_id) <
126 std::tie(other.integr_id, other.evalut_id, other.gather_id);
127 }
128};
129
226template <
227 typename MeshType,
228 typename FeExpressionTuple,
229 typename FeExpressionFaceTuple = std::tuple<>>
231 MeshType,
232 FeExpressionTuple,
233 FeExpressionFaceTuple> {
234 public:
235 // Aliases for base types and dimension-related constants
237 MeshType,
238 FeExpressionTuple,
239 FeExpressionFaceTuple>;
241 static inline constexpr std::size_t dim = MeshType::self_dim;
243 static inline constexpr uint32_t s_n_expr =
246 static inline constexpr uint32_t s_n_face_expr =
249 static inline constexpr uint32_t s_n_expr_bilinear =
252 static inline constexpr uint32_t s_n_expr_linear =
255 static inline constexpr uint32_t s_n_face_expr_bilinear =
258 static inline constexpr uint32_t s_n_face_expr_linear =
260
261 // Aliases for FE and Polynomial types
262 using FeType = std::remove_pointer_t<
263 std::tuple_element_t<0, FeExpressionTuple>>::FeSpaceType;
265 using PolyType = FeType::FeSpaceType::PolynomialFast;
267 using MonoType = PolyType::MonomialType;
276 std::decay_t<decltype(PolyType{}.template liftDimension<0, 2 * dim>())>;
278 using MonoTypeLifted = PolyTypeLifted::MonomialType;
280 using index_t = typename MeshType::index_t;
281
283 static inline constexpr index_t s_n_blocks =
285
286 // Custom data structures for storing and processing polynomials
288 using GatheredPolynomial = std::vector<GatheredMonomial<dim>>;
290 using GatheredPolynomialCoef = std::vector<std::pair<double, uint16_t>>;
298
307 const MeshType& mesh,
308 CellManager<MeshType, FeType>& cell_manager,
309 const FeExpressionTuple& fe_expression,
310 const FeExpressionFaceTuple& fe_expression_face =
311 FeExpressionFaceTuple{});
312
317 void integrate(index_t cell_id);
318
319 protected:
335 const datastructure::CrsMapUncompressed<MonoType>& uncompressed_table);
336
351 void buildLookupTables();
352
368 std::array<std::vector<GatheredPolynomial>, s_n_face_expr_bilinear>
370
385 std::vector<std::array<uint8_t, dim * 2>> buildUniqueEvaTableLiftedMonomials(
386 const std::array<std::vector<GatheredPolynomial>, s_n_face_expr_bilinear>&
387 gathered_monos_table);
388
414 const std::array<std::vector<GatheredPolynomial>, s_n_face_expr_bilinear>&
415 gathered_monos_table);
416
436
444 Eigen::Matrix<double, dim, 2> computeRefToNeighRefMap() const {
445 Eigen::Matrix<double, dim, 2> neigh_flat_mapping;
446 if (this->m_need_neigh_values && this->m_cell_neigh_info.have_neigh) {
447 const auto& neigh_map = *this->m_cell_manager.getMapping(
448 this->m_cell_neigh_info.neigh_cell_id);
449
450 // Get periodic shift in physical coordinates (if mesh is periodic)
451 const auto periodic_shift = this->m_cell_manager.getPeriodicShift(
452 this->m_cell_neigh_info.neigh_cell_id, this->m_cell_id);
453
454 // Composed transformation: current->physical->neighbor with periodic
455 // shift
456 neigh_flat_mapping.col(0) = neigh_map.getJacobianInv().array() *
457 this->m_mapping->getJacobian().array();
458 neigh_flat_mapping.col(1) =
459 neigh_map.getJacobianInv().array() *
460 (this->m_mapping->getTranslation().array() +
461 periodic_shift.array()) +
462 neigh_map.getTranslationInv().array();
463 }
464 return neigh_flat_mapping;
465 }
466
472 void integrateVolumeCell(const double* aints_data);
473
482
493
500 void integrateFaceCell(const double* eints_data, double nanson);
501
504 using TypeIJ = std::array<Eigen::Index, 3>;
510 using TypeI = std::array<Eigen::Index, 2>;
514
515 // --- Member Variables ---
516
517 // Bilinear (matrix) volume expressions
519 std::array<FlatPolyType, s_n_expr_bilinear> m_poly_table_flat;
522 std::array<FlatPolyType, s_n_expr_bilinear> m_poly_table_flat_nodupes;
525 std::array<RepeatingTableIJ, s_n_expr_bilinear> m_poly_table_flat_ijs_table;
526
527 // Linear (RHS) volume expressions
529 std::array<FlatPolyType, s_n_expr_linear> m_poly_table_flat_linear;
532 std::array<FlatPolyType, s_n_expr_linear> m_poly_table_flat_linear_nodupes;
535 std::array<RepeatingTableI, s_n_expr_linear>
537
538 // Bilinear (matrix) face expressions
540 std::array<FlatPolyType, s_n_face_expr_bilinear> m_poly_table_face_flat;
542 std::array<FlatPolyType, s_n_face_expr_bilinear>
545 std::array<RepeatingTableIJ, s_n_face_expr_bilinear>
547
548 // Linear (RHS) face expressions
550 std::array<FlatPolyType, s_n_face_expr_linear> m_poly_table_face_flat_linear;
552 std::array<FlatPolyType, s_n_face_expr_linear>
555 std::array<RepeatingTableI, s_n_face_expr_linear>
557
558 // Lifted (neighbor-dependent) bilinear face expressions
561 std::array<FlatPolyTypeLifted, s_n_face_expr_bilinear>
564 std::array<CompressedListGatheredPoly, s_n_face_expr_bilinear>
568 std::array<CompressedListGatheredPoly, s_n_face_expr_bilinear>
571 std::array<RepeatingTableIJ, s_n_face_expr_bilinear>
573
578 std::vector<std::array<uint8_t, dim * 2>> m_eva_idx_table;
587
590 std::vector<double> m_gather_coef;
593 std::vector<double> m_eval_table_ext;
594
597 std::array<Eigen::Index, s_n_expr_bilinear> m_npoly_comps_volume;
600 std::array<Eigen::Index, s_n_expr_linear> m_npoly_comps_volume_linear;
603 std::array<Eigen::Index, s_n_face_expr_bilinear> m_npoly_comps_face;
606 std::array<Eigen::Index, s_n_face_expr_linear> m_npoly_comps_face_linear;
607};
608
609template <
610 typename MeshType,
611 typename FeExpressionTuple,
612 typename FeExpressionFaceTuple>
614 MeshType,
615 FeExpressionTuple,
616 FeExpressionFaceTuple>::FlatPolyType
619 MeshType,
620 FeExpressionTuple,
621 FeExpressionFaceTuple>::MonoType>& uncompressed_table) {
622 // compress the table
623 const auto compr_table_uncompr_monos =
624 uncompressed_table.template compress<index_t>();
625 // compress the monomials
626 FlatPolyType compr_table_compr_monos;
627 compr_table_compr_monos.indices() = compr_table_uncompr_monos.indices();
628 std::array<std::size_t, dim> exp;
629 for (const auto& mono : compr_table_uncompr_monos.data()) {
630 for (std::size_t d = 0; d < dim; ++d) {
631 exp[d] = mono.exp()[d];
632 }
633 compr_table_compr_monos.data().emplace_back(
635 }
636 return compr_table_compr_monos;
637};
638
639template <
640 typename MeshType,
641 typename FeExpressionTuple,
642 typename FeExpressionFaceTuple>
645 const MeshType& mesh,
646 CellManager<MeshType, FeType>& cell_manager,
647 const FeExpressionTuple& fe_expression,
648 const FeExpressionFaceTuple& fe_expression_face)
650 mesh, cell_manager, fe_expression, fe_expression_face) {
651 const Eigen::Index n_dof_loc = this->m_fe_space.getBasis().size();
652
653 // Cache polynomials for all expressions in reference configuration.
654 // The coefficient from the physical mapping is applied on the fly during
655 // integration via evaluatePolyCoef. Bilinear forms loop over (bj,bi,j,i);
656 // linear (RHS) forms loop over (bi,i) only -- no trial function.
657 const auto [bilinear_exprs, linear_exprs] =
659
661 bilinear_exprs, [this, n_dof_loc](const auto& expr, std::size_t idx) {
663 std::size_t poly_idx = 0;
664 for (Eigen::Index bj = 0; bj < s_n_blocks; ++bj) {
665 for (Eigen::Index bi = 0; bi < s_n_blocks; ++bi) {
666 for (Eigen::Index j = 0; j < n_dof_loc; ++j) {
667 for (Eigen::Index i = 0; i < n_dof_loc; ++i) {
668 const Eigen::Matrix<PolyType, 1, -1> poly_comps =
669 expr->evaluatePoly(this->m_fe_values, j, i, bj, bi)
670 .unaryExpr([](const auto& p) {
671 return p.template to<double>();
672 });
673 m_npoly_comps_volume[idx] = poly_comps.size();
674 for (Eigen::Index k = 0; k < poly_comps.size(); ++k) {
675 auto& row = poly_table_tmp.getRow(poly_idx);
676 for (const auto& monomial : poly_comps[k].data()) {
677 row.push_back(monomial);
678 }
679 poly_idx++;
680 }
681 }
682 }
683 }
684 }
685 m_poly_table_flat[idx] = compress(poly_table_tmp);
686 });
687
689 linear_exprs, [this, n_dof_loc](const auto& expr, std::size_t idx) {
691 std::size_t poly_idx = 0;
692 for (Eigen::Index bi = 0; bi < s_n_blocks; ++bi) {
693 for (Eigen::Index i = 0; i < n_dof_loc; ++i) {
694 const Eigen::Matrix<PolyType, 1, -1> poly_comps =
695 expr->evaluatePoly(this->m_fe_values, 0, i, 0, bi)
696 .unaryExpr(
697 [](const auto& p) { return p.template to<double>(); });
698 m_npoly_comps_volume_linear[idx] = poly_comps.size();
699 for (Eigen::Index k = 0; k < poly_comps.size(); ++k) {
700 auto& row = poly_table_tmp.getRow(poly_idx);
701 for (const auto& monomial : poly_comps[k].data()) {
702 row.push_back(monomial);
703 }
704 poly_idx++;
705 }
706 }
707 }
708 m_poly_table_flat_linear[idx] = compress(poly_table_tmp);
709 });
710
711 // Face expressions: bilinear forms may need neighbor mapping (lifted
712 // polynomials); linear forms use local test basis only (non-lifted).
713 const auto [bilinear_face_exprs, linear_face_exprs] =
714 internal::split_expression_tuple(fe_expression_face);
715
717 bilinear_face_exprs,
718 [this, n_dof_loc](const auto& expr, std::size_t idx) {
719 using PolyMatType = std::decay_t<decltype(expr->evaluatePoly(
720 this->m_fe_values, 0, 0, 0, 0))>;
721 constexpr auto expr_poly_dim = PolyMatType::Scalar::dim;
722
723 using MonoTypeCurr =
724 std::conditional_t<expr_poly_dim == dim, MonoType, MonoTypeLifted>;
726 std::size_t poly_idx = 0;
727 for (Eigen::Index bj = 0; bj < s_n_blocks; ++bj) {
728 for (Eigen::Index bi = 0; bi < s_n_blocks; ++bi) {
729 for (Eigen::Index j = 0; j < n_dof_loc; ++j) {
730 for (Eigen::Index i = 0; i < n_dof_loc; ++i) {
731 using ExprPolyType = std::conditional_t<
732 expr_poly_dim == dim, PolyType, PolyTypeLifted>;
733 const Eigen::Matrix<ExprPolyType, 1, -1> poly_comps =
734 expr->evaluatePoly(this->m_fe_values, j, i, bj, bi)
735 .unaryExpr([](const auto& p) {
736 return p.template to<double>();
737 });
738 m_npoly_comps_face[idx] = poly_comps.size();
739 for (Eigen::Index k = 0; k < poly_comps.size(); ++k) {
740 auto& row = poly_table_tmp.getRow(poly_idx);
741 for (const auto& monomial : poly_comps[k].data()) {
742 row.push_back(monomial);
743 }
744 poly_idx++;
745 }
746 }
747 }
748 }
749 }
750
751 if constexpr (expr_poly_dim == dim) {
752 m_poly_table_face_flat[idx] = compress(poly_table_tmp);
753 } else {
754 // compressing lifted monomials is more complex, we first have
755 // to save them all, than apply gathering
757 poly_table_tmp.template compress<index_t>();
758 }
759 });
760
762 linear_face_exprs, [this, n_dof_loc](const auto& expr, std::size_t idx) {
764 std::size_t poly_idx = 0;
765 for (Eigen::Index bi = 0; bi < s_n_blocks; ++bi) {
766 for (Eigen::Index i = 0; i < n_dof_loc; ++i) {
767 const Eigen::Matrix<PolyType, 1, -1> poly_comps =
768 expr->evaluatePoly(this->m_fe_values, 0, i, 0, bi)
769 .unaryExpr(
770 [](const auto& p) { return p.template to<double>(); });
771 m_npoly_comps_face_linear[idx] = poly_comps.size();
772 for (Eigen::Index k = 0; k < poly_comps.size(); ++k) {
773 auto& row = poly_table_tmp.getRow(poly_idx);
774 for (const auto& monomial : poly_comps[k].data()) {
775 row.push_back(monomial);
776 }
777 poly_idx++;
778 }
779 }
780 }
781 m_poly_table_face_flat_linear[idx] = compress(poly_table_tmp);
782 });
783 // speed-up polynomial evaluation by gathering common monomials
785 // often polynomials are repeated in a local matrix
786 // we find out where are the repetitions and build a table
787 // with one of each kind of polynomial and a table with the
788 // list of entriens where it should be put
790}
791
792template <
793 typename MeshType,
794 typename FeExpressionTuple,
795 typename FeExpressionFaceTuple>
797 MeshType,
798 FeExpressionTuple,
799 FeExpressionFaceTuple>::buildLookupTables() {
800 const Eigen::Index n_dof_loc = this->m_fe_space.getBasis().size();
801
802 // Bilinear (matrix) polynomial tables: slice is (bj,bi,j,i,k).
803 // Apply the same deduplication to volume, face, and lifted-face tables.
804 const auto bilinear_tables = std::tuple(
805 std::tuple(
809 std::tuple(
813 std::tuple(
817
818 vutils::for_each(bilinear_tables, [n_dof_loc, this](auto tpts) {
819 auto tpt = std::get<0>(tpts);
820 auto tpt_nodup = std::get<1>(tpts);
821 auto tpt_ijk = std::get<2>(tpts);
822 for (std::size_t exi = 0; exi < tpt->size(); ++exi) {
823 using MonomialType = std::decay_t<decltype((*tpt)[0][0][0])>;
824 using PolynomialType = std::vector<MonomialType>;
825 const auto npolys = (*tpt)[exi].size();
826 const auto slice_size = n_dof_loc * n_dof_loc * s_n_blocks * s_n_blocks;
827 const auto n_k_comps = npolys / slice_size;
828
829 index_t poly_idx = 0;
830 std::vector<index_t> keep_idxs;
832 std::map<PolynomialType, std::size_t> unq_polys;
833 // dummy just to compute automatically the `kbibj` offset
834 Eigen::Tensor<double, 3> dummy(n_k_comps, s_n_blocks, s_n_blocks);
835 for (Eigen::Index bj = 0; bj < s_n_blocks; ++bj) {
836 for (Eigen::Index bi = 0; bi < s_n_blocks; ++bi) {
837 for (Eigen::Index j = 0; j < n_dof_loc; ++j) {
838 for (Eigen::Index i = 0; i < n_dof_loc; ++i) {
839 for (Eigen::Index k = 0; k < n_k_comps; ++k) {
840 const auto kbibj = &dummy(k, bi, bj) - dummy.data();
841 const TypeIJ ij = {
842 i * s_n_blocks + bi, j * s_n_blocks + bj, kbibj};
843 PolynomialType poly;
844 for (auto mono : (*tpt)[exi][poly_idx]) {
845 poly.push_back(mono);
846 }
847 std::sort(poly.begin(), poly.end());
848 if (poly.size()) {
849 const auto [it, inserted] =
850 unq_polys.emplace(poly, unq_polys.size());
851 table.getRow(it->second).push_back(ij);
852 if (inserted) {
853 keep_idxs.push_back(poly_idx);
854 }
855 }
856 poly_idx++;
857 }
858 }
859 }
860 }
861 }
862
863 (*tpt_nodup)[exi] = (*tpt)[exi].slice(keep_idxs);
864 (*tpt_ijk)[exi] = table.template compress<index_t>();
865 }
866 });
867
868 // Linear (RHS) polynomial tables: slice is (bi,i,k) -- no trial index.
869 const auto linear_tables = std::tuple(
870 std::tuple(
873 std::tuple(
877
878 vutils::for_each(linear_tables, [n_dof_loc, this](auto tpts) {
879 auto tpt = std::get<0>(tpts);
880 auto tpt_nodup = std::get<1>(tpts);
881 auto tpt_i = std::get<2>(tpts);
882 for (std::size_t exi = 0; exi < tpt->size(); ++exi) {
883 using MonomialType = std::decay_t<decltype((*tpt)[0][0][0])>;
884 using PolynomialType = std::vector<MonomialType>;
885 const auto npolys = (*tpt)[exi].size();
886 const auto slice_size = n_dof_loc * s_n_blocks;
887 const auto n_k_comps = npolys / slice_size;
888
889 index_t poly_idx = 0;
890 std::vector<index_t> keep_idxs;
892 std::map<PolynomialType, std::size_t> unq_polys;
893 // dummy to compute kbi offset in (k, bi) layout
894 Eigen::Tensor<double, 2> dummy(n_k_comps, s_n_blocks);
895 for (Eigen::Index bi = 0; bi < s_n_blocks; ++bi) {
896 for (Eigen::Index i = 0; i < n_dof_loc; ++i) {
897 for (Eigen::Index k = 0; k < n_k_comps; ++k) {
898 const auto kbi = &dummy(k, bi) - dummy.data();
899 const TypeI i_entry = {i * s_n_blocks + bi, kbi};
900 PolynomialType poly;
901 for (auto mono : (*tpt)[exi][poly_idx]) {
902 poly.push_back(mono);
903 }
904 std::sort(poly.begin(), poly.end());
905 if (poly.size()) {
906 const auto [it, inserted] =
907 unq_polys.emplace(poly, unq_polys.size());
908 table.getRow(it->second).push_back(i_entry);
909 if (inserted) {
910 keep_idxs.push_back(poly_idx);
911 }
912 }
913 poly_idx++;
914 }
915 }
916 }
917
918 (*tpt_nodup)[exi] = (*tpt)[exi].slice(keep_idxs);
919 (*tpt_i)[exi] = table.template compress<index_t>();
920 }
921 });
922}
923
924template <
925 typename MeshType,
926 typename FeExpressionTuple,
927 typename FeExpressionFaceTuple>
928std::array<
929 std::vector<typename WeakFormIntegratorQFree<
930 MeshType,
931 FeExpressionTuple,
932 FeExpressionFaceTuple>::GatheredPolynomial>,
934 MeshType,
935 FeExpressionTuple,
936 FeExpressionFaceTuple>::s_n_face_expr_bilinear>
939 // gather the lifted monomials
940 std::array<std::vector<GatheredPolynomial>, s_n_face_expr_bilinear>
941 gathered_monos_table;
942 for (std::size_t i = 0; i < m_poly_table_face_lifted_flat.size(); ++i) {
943 const auto& old_table = m_poly_table_face_lifted_flat[i];
944 for (index_t poly_id = 0; poly_id < old_table.size(); ++poly_id) {
945 GatheredPolynomial gathered_poly;
946 for (const auto& mono : old_table[poly_id]) {
947 // in the monomial exponent, split the first dim components (the ones
948 // that must be integrated and with respect to which we gather), and
949 // the evaluation components (the last 2 * dim ones, which come from
950 // the cartesian mapping)
951 std::array<uint32_t, dim> int_ids;
952 for (std::size_t d = 0; d < dim; ++d) {
953 int_ids[d] = mono.exp()[d];
954 }
955 std::array<uint8_t, dim * 2> eva_ids;
956 for (std::size_t d = 0; d < dim * 2; ++d) {
957 eva_ids[d] = mono.exp()[d + dim];
958 }
959 const auto lin_id = monomial::getLinearIndex<dim, uint32_t>(int_ids);
960 if (lin_id > std::numeric_limits<uint16_t>::max()) {
961 throw std::length_error(
962 "QFree: polynomial degree too high for the 16-bit monomial "
963 "index, use the Simplexify integrator");
964 }
965 const uint16_t int_id = lin_id;
966
967 // search among gathered monomials if we already have
968 // a monomial with the common term
969 std::size_t mono_id = -1;
970 for (std::size_t j = 0; j < gathered_poly.size(); ++j) {
971 if (gathered_poly[j].integr_id == int_id) {
972 mono_id = j;
973 break;
974 }
975 }
976 if (mono_id == std::size_t(-1)) {
977 // if the common term is not present, we add a new term
978 gathered_poly.push_back(GatheredMonomial<dim>{
979 .integr_id = int_id,
980 .evalut_id = {0},
981 .gather = {{mono.coef(), eva_ids}}});
982 } else {
983 // the term is already presend, we append the non-common part
984 gathered_poly[mono_id].gather.push_back({mono.coef(), eva_ids});
985 }
986 }
987 // extract for each gathered monomial the common part in the
988 // gathered part. E.g. x(ab + a) -> xa(b + 1)
989 for (auto& mono : gathered_poly) {
990 std::array<uint8_t, dim * 2> min_id;
991 min_id.fill(255);
992 // find the common part
993 for (const auto& c : mono.gather) {
994 for (std::size_t d = 0; d < dim * 2; ++d) {
995 min_id[d] = std::min(min_id[d], c.second[d]);
996 }
997 }
998 // remove the common part from the gathered
999 mono.evalut_id = min_id;
1000 for (auto& c : mono.gather) {
1001 for (std::size_t d = 0; d < dim * 2; ++d) {
1002 c.second[d] -= min_id[d];
1003 }
1004 }
1005 }
1006 gathered_monos_table[i].push_back(gathered_poly);
1007 }
1008 }
1009 return gathered_monos_table;
1010}
1011
1012// Builds a unique evaluation coefficient table from all gathered monomials.
1013template <
1014 typename MeshType,
1015 typename FeExpressionTuple,
1016 typename FeExpressionFaceTuple>
1017std::vector<std::array<
1018 uint8_t,
1020 MeshType,
1021 FeExpressionTuple,
1022 FeExpressionFaceTuple>::dim *
1023 2>>
1026 const std::array<
1027 std::vector<GatheredPolynomial>,
1028 s_n_face_expr_bilinear>& gathered_monos_table) {
1029 std::set<std::array<uint8_t, dim * 2>> eva_set;
1030 for (const auto& gathered_monos : gathered_monos_table) {
1031 for (const auto& poly : gathered_monos) {
1032 for (const auto& mono : poly) {
1033 eva_set.insert(mono.evalut_id);
1034 for (const auto& entry : mono.gather) {
1035 eva_set.insert(entry.second);
1036 }
1037 }
1038 }
1039 }
1040 return std::vector<std::array<uint8_t, dim * 2>>(
1041 eva_set.begin(), eva_set.end());
1042}
1043
1044template <
1045 typename MeshType,
1046 typename FeExpressionTuple,
1047 typename FeExpressionFaceTuple>
1049 MeshType,
1050 FeExpressionTuple,
1051 FeExpressionFaceTuple>::
1052 compressGatheredLiftedPolynomials(
1053 const std::array<
1054 std::vector<GatheredPolynomial>,
1055 s_n_face_expr_bilinear>& gathered_monos_table) {
1056 if (m_eva_idx_table.size() > std::numeric_limits<uint16_t>::max()) {
1057 throw std::length_error(
1058 "QFree: too many evaluation monomials for the 16-bit index, use the "
1059 "Simplexify integrator");
1060 }
1061 // compress the monomials, consists in two steps
1062 // 1. the GatheredMonomial becomes a CompressedGatheredMonomial
1063 // 2. find the unique gather coefficients needed for the compressed monos
1064 using GatheredPolynomialCoef = std::vector<std::pair<double, uint16_t>>;
1065 std::map<GatheredPolynomialCoef, uint32_t> gather_table;
1066 using CompressedGatheredPolynomial = std::vector<CompressedGatheredMonomial>;
1067 std::array<std::vector<CompressedGatheredPolynomial>, s_n_face_expr_bilinear>
1068 compr_gathered_monos_table;
1069 for (std::size_t expr_id = 0; expr_id < compr_gathered_monos_table.size();
1070 ++expr_id) {
1071 auto& compr_gathered_monos = compr_gathered_monos_table[expr_id];
1072 compr_gathered_monos.resize(gathered_monos_table[expr_id].size());
1073 for (std::size_t i = 0; i < gathered_monos_table[expr_id].size(); ++i) {
1074 const auto& poly = gathered_monos_table[expr_id][i];
1075 compr_gathered_monos[i].resize(poly.size());
1076 for (std::size_t j = 0; j < poly.size(); ++j) {
1077 const auto& mono = poly[j];
1078 auto& compr_mono = compr_gathered_monos[i][j];
1079 compr_mono.integr_id = mono.integr_id;
1080 // transform the exponent array into a index
1081 const auto it = std::lower_bound(
1082 m_eva_idx_table.begin(), m_eva_idx_table.end(), mono.evalut_id);
1083 assert(it != m_eva_idx_table.end());
1084 assert(*it == mono.evalut_id);
1085 compr_mono.evalut_id = std::distance(m_eva_idx_table.begin(), it);
1086 // transform the gather part into a index
1087 // this is done by suitably updating the gather_table
1088 std::vector<std::pair<double, uint16_t>> sorted_gather;
1089 for (const auto& [coef, eval_id] : mono.gather) {
1090 const auto eval_it = std::lower_bound(
1091 m_eva_idx_table.begin(), m_eva_idx_table.end(), eval_id);
1092 assert(eval_it != m_eva_idx_table.end());
1093 assert(*eval_it == eval_id);
1094 sorted_gather.push_back(
1095 {coef, std::distance(m_eva_idx_table.begin(), eval_it)});
1096 }
1097 std::sort(sorted_gather.begin(), sorted_gather.end());
1098 const auto [gather_it, inserted] =
1099 gather_table.emplace(sorted_gather, (uint32_t)gather_table.size());
1100 compr_mono.gather_id = gather_it->second;
1101 }
1102 }
1103
1105 CompressedListGatheredPoly{compr_gathered_monos_table[expr_id]};
1106 }
1107 if (gather_table.size() > std::numeric_limits<uint32_t>::max()) {
1108 throw std::length_error("QFree: gather table exceeds the 32-bit index");
1109 }
1110 // compress the gather table
1111 std::vector<GatheredPolynomialCoef> gather_table_flat(gather_table.size());
1112 for (const auto& [gather, id] : gather_table) {
1113 gather_table_flat[id] = gather;
1114 }
1115 m_gathered_monos = decltype(m_gathered_monos)(gather_table_flat);
1116}
1117
1118template <
1119 typename MeshType,
1120 typename FeExpressionTuple,
1121 typename FeExpressionFaceTuple>
1123 MeshType,
1124 FeExpressionTuple,
1125 FeExpressionFaceTuple>::gatherLiftedMonomials() {
1126 const auto gathered_monos_table = gatherUncompressedLiftedMonomials();
1127 // find all the unique coefficients of the evaluate part
1129 // compress the gathered monomials
1130 compressGatheredLiftedPolynomials(gathered_monos_table);
1131}
1132
1133template <
1134 typename MeshType,
1135 typename FeExpressionTuple,
1136 typename FeExpressionFaceTuple>
1138 MeshType,
1139 FeExpressionTuple,
1140 FeExpressionFaceTuple>::integrateVolumeCell(const double* aints_data) {
1141 Profiler::start("integrate-volume-qfree");
1142 const double jac_det = this->m_mapping->jacobianDet({});
1143 std::vector<double> buffer;
1144
1145 const auto [bilinear_exprs, linear_exprs] =
1147
1149 bilinear_exprs, [this, jac_det, aints_data, &buffer](
1150 const auto& expr, Eigen::Index expr_id) {
1151 {
1152 const auto& table = m_poly_table_flat_nodupes[expr_id];
1153 buffer.resize(table.size());
1154 for (index_t i = 0; i < table.size(); ++i) {
1155 double integral = 0.0;
1156 for (const auto mono : table[i]) {
1157 integral += mono.coef * aints_data[mono.integr_id];
1158 }
1159 buffer[i] = integral;
1160 }
1161 }
1162 expr->precompute(this->m_fe_values, this->m_cell_manager.getCells());
1163 const auto& table = m_poly_table_flat_ijs_table[expr_id];
1164
1165 Profiler::start("evaluatePolyCoef+cacheVolume");
1166 const auto K = m_npoly_comps_volume[expr_id];
1167 Eigen::Tensor<double, 3> coefs(K, s_n_blocks, s_n_blocks);
1168 for (Eigen::Index bj = 0; bj < s_n_blocks; ++bj) {
1169 for (Eigen::Index bi = 0; bi < s_n_blocks; ++bi) {
1170 const auto coef = expr->evaluatePolyCoef(
1171 *(this->m_mapping), this->m_fe_values, bj, bi);
1172 assert(coef.size() == K);
1173 assert(coef.rows() == 1);
1174 for (Eigen::Index k = 0; k < K; ++k) {
1175 coefs(k, bi, bj) = coef(0, k);
1176 }
1177 }
1178 }
1179 Profiler::stop("evaluatePolyCoef+cacheVolume");
1180
1181 for (index_t pid = 0; pid < table.size(); ++pid) {
1182 const auto integral = jac_det * buffer[pid];
1183 for (const auto ijk : table[pid]) {
1184 this->m_integrals(ijk[0], ijk[1], expr_id) +=
1185 coefs.data()[ijk[2]] * integral;
1186 }
1187 }
1188 });
1189
1190 if constexpr (s_n_expr_linear > 0) {
1192 linear_exprs, [this, jac_det, aints_data, &buffer](
1193 const auto& expr, Eigen::Index expr_id) {
1194 {
1195 const auto& table = m_poly_table_flat_linear_nodupes[expr_id];
1196 buffer.resize(table.size());
1197 for (index_t i = 0; i < table.size(); ++i) {
1198 double integral = 0.0;
1199 for (const auto mono : table[i]) {
1200 integral += mono.coef * aints_data[mono.integr_id];
1201 }
1202 buffer[i] = integral;
1203 }
1204 }
1205 expr->precompute(this->m_fe_values, this->m_cell_manager.getCells());
1206 const auto& table = m_poly_table_flat_linear_ijs_table[expr_id];
1207
1208 const auto K = m_npoly_comps_volume_linear[expr_id];
1209 Eigen::Tensor<double, 2> coefs(K, s_n_blocks);
1210 for (Eigen::Index bi = 0; bi < s_n_blocks; ++bi) {
1211 const auto coef = expr->evaluatePolyCoef(
1212 *(this->m_mapping), this->m_fe_values, 0, bi);
1213 assert(coef.size() == K);
1214 assert(coef.rows() == 1);
1215 for (Eigen::Index k = 0; k < K; ++k) {
1216 coefs(k, bi) = coef(0, k);
1217 }
1218 }
1219
1220 for (index_t pid = 0; pid < table.size(); ++pid) {
1221 const auto integral = jac_det * buffer[pid];
1222 for (const auto ij : table[pid]) {
1223 this->m_rhs(ij[0], expr_id) += coefs.data()[ij[1]] * integral;
1224 }
1225 }
1226 });
1227 }
1228
1229 Profiler::stop("integrate-volume-qfree");
1230}
1231
1232template <
1233 typename MeshType,
1234 typename FeExpressionTuple,
1235 typename FeExpressionFaceTuple>
1236double
1239 const double jac_det = this->m_mapping->jacobianDet({});
1240 const auto jac = this->m_mapping->getJacobian();
1241 const auto& cell = this->getCell(this->m_cell_id);
1242 const Eigen::Vector<double, dim> ns = cell.normals().col(this->m_face_id);
1243 const Eigen::Vector<double, dim> Fns = jac.array() * ns.array();
1244 this->m_fe_values.setFaceNormal(ns);
1245 // ||JF^-TN||, where F jacobian of ref-to-physic, J is |det(F)|,
1246 // N unit outer in ref. By exploiting linearity and F is diagonal we have
1247 // J/||Fn||, where n is the unit normal in physical space. See:
1248 // https://en.wikipedia.org/wiki/Finite_strain_theory#Transformation_of_a_surface_and_volume_element
1249 const double nanson = jac_det / Fns.norm();
1250 return nanson;
1251}
1252
1253template <
1254 typename MeshType,
1255 typename FeExpressionTuple,
1256 typename FeExpressionFaceTuple>
1258 MeshType,
1259 FeExpressionTuple,
1260 FeExpressionFaceTuple>::precomputeMonomialCoefsForFace() {
1261 Profiler::start("integrate::precomputeMonomialCoefsForFace::pt1");
1262 const Eigen::Matrix<double, dim, 2> neigh_map = computeRefToNeighRefMap();
1263 Eigen::Matrix<double, dim * 2, -1> eval_table(dim * 2, 32);
1264 eval_table.col(0) = Eigen::VectorXd::Ones(dim * 2);
1265 eval_table.col(1) =
1266 Eigen::Map<const Eigen::VectorXd>(neigh_map.data(), dim * 2);
1267 for (Eigen::Index i = 2; i < eval_table.cols(); ++i) {
1268 eval_table.col(i) =
1269 eval_table.col(i - 1).array() * eval_table.col(1).array();
1270 }
1271 m_eval_table_ext.resize(m_eva_idx_table.size());
1272 std::fill(m_eval_table_ext.begin(), m_eval_table_ext.end(), 1.0);
1273 for (std::size_t i = 0; i < m_eval_table_ext.size(); ++i) {
1274 for (std::size_t d = 0; d < 2 * dim; ++d) {
1275 m_eval_table_ext[i] *= eval_table(d, m_eva_idx_table[i][d]);
1276 }
1277 }
1278 Profiler::stop("integrate::precomputeMonomialCoefsForFace::pt1");
1279
1280 Profiler::start("integrate::precomputeMonomialCoefsForFace::pt2");
1281 m_gather_coef.resize(m_gathered_monos.size());
1282 std::fill(m_gather_coef.begin(), m_gather_coef.end(), 0.0);
1283 for (std::size_t i = 0; i < m_gather_coef.size(); ++i) {
1284 for (const auto& [coef, id] : m_gathered_monos[i]) {
1285 m_gather_coef[i] += coef * m_eval_table_ext[id];
1286 }
1287 }
1288 Profiler::stop("integrate::precomputeMonomialCoefsForFace::pt2");
1289}
1290
1291template <
1292 typename MeshType,
1293 typename FeExpressionTuple,
1294 typename FeExpressionFaceTuple>
1296 MeshType,
1297 FeExpressionTuple,
1298 FeExpressionFaceTuple>::
1299 integrateFaceCell(const double* eints_data, double nanson) {
1300 std::vector<double> buffer;
1301 const auto [bilinear_face_exprs, linear_face_exprs] =
1303
1305 bilinear_face_exprs, [this, nanson, eints_data, &buffer](
1306 const auto& expr, Eigen::Index expr_id) {
1307 using PolyMatType = std::decay_t<decltype(expr->evaluatePoly(
1308 this->m_fe_values, 0, 0, 0, 0))>;
1309 constexpr auto expr_poly_dim = PolyMatType::Scalar::dim;
1310
1311 auto curr_integral = this->getCurrFaceIntegral(expr, expr_id);
1312 if (!curr_integral.size()) {
1313 return;
1314 }
1315
1316 // pre-compute integrals of monomials
1317 Profiler::start("integrate::integrateFaceCell::init");
1318 if constexpr (expr_poly_dim == dim) {
1319 const auto& table = m_poly_table_face_flat_nodupes[expr_id];
1320 buffer.resize(table.size());
1321 for (index_t i = 0; i < table.size(); ++i) {
1322 double integral = 0.0;
1323 for (const auto mono : table[i]) {
1324 integral += mono.coef * eints_data[mono.integr_id];
1325 }
1326 buffer[i] = integral;
1327 }
1328 } else {
1329 const auto& table =
1331 buffer.resize(table.size());
1332 for (index_t i = 0; i < table.size(); ++i) {
1333 double integral = 0.0;
1334 for (const auto mono : table[i]) {
1335 integral += m_gather_coef[mono.gather_id] *
1336 m_eval_table_ext[mono.evalut_id] *
1337 eints_data[mono.integr_id];
1338 }
1339 buffer[i] = integral;
1340 }
1341 }
1342 Profiler::stop("integrate::integrateFaceCell::init");
1343
1344 // prepare buffer of coefficients with suitable duplicates
1345 // (the look-up is more expensive than putting everything in cache)
1346 Profiler::start("integrate::integrateFaceCell::cache");
1347 const auto K = m_npoly_comps_face[expr_id];
1348 Eigen::Tensor<double, 3> coefs(K, s_n_blocks, s_n_blocks);
1349 for (Eigen::Index bj = 0; bj < s_n_blocks; ++bj) {
1350 for (Eigen::Index bi = 0; bi < s_n_blocks; ++bi) {
1351 const auto coef = expr->evaluatePolyCoef(
1352 *(this->m_mapping), this->m_fe_values, bj, bi);
1353 assert(coef.size() == K);
1354 assert(coef.rows() == 1);
1355 for (Eigen::Index k = 0; k < K; ++k) {
1356 coefs(k, bi, bj) = coef(0, k);
1357 }
1358 }
1359 }
1360 Profiler::stop("integrate::integrateFaceCell::cache");
1361
1362 // actually compute the integrals by combining integrals of the
1363 // monomials and their coefficient
1364 Profiler::start("integrate::integrateFaceCell::eval");
1365 using TableType = std::decay_t<std::conditional_t<
1366 expr_poly_dim == dim, decltype(m_poly_table_face_flat_ijs_table[0]),
1368 const TableType* table = nullptr;
1369 if constexpr (expr_poly_dim == dim) {
1370 table = &m_poly_table_face_flat_ijs_table[expr_id];
1371 } else {
1373 }
1374 for (index_t pid = 0; pid < (*table).size(); ++pid) {
1375 const auto integral = nanson * buffer[pid];
1376 for (const auto ijk : (*table)[pid]) {
1377 curr_integral(ijk[0], ijk[1]) += coefs.data()[ijk[2]] * integral;
1378 }
1379 }
1380 Profiler::stop("integrate::integrateFaceCell::eval");
1381 });
1382
1383 if constexpr (s_n_face_expr_linear > 0) {
1385 linear_face_exprs, [this, nanson, eints_data, &buffer](
1386 const auto& expr, Eigen::Index expr_id) {
1387 auto curr_rhs = this->getCurrFaceRhs(expr, expr_id);
1388 if (!curr_rhs.size()) {
1389 return;
1390 }
1391
1392 const auto& table = m_poly_table_face_flat_linear_nodupes[expr_id];
1393 buffer.resize(table.size());
1394 for (index_t i = 0; i < table.size(); ++i) {
1395 double integral = 0.0;
1396 for (const auto mono : table[i]) {
1397 integral += mono.coef * eints_data[mono.integr_id];
1398 }
1399 buffer[i] = integral;
1400 }
1401
1402 const auto K = m_npoly_comps_face_linear[expr_id];
1403 Eigen::Tensor<double, 2> coefs(K, s_n_blocks);
1404 for (Eigen::Index bi = 0; bi < s_n_blocks; ++bi) {
1405 const auto coef = expr->evaluatePolyCoef(
1406 *(this->m_mapping), this->m_fe_values, 0, bi);
1407 assert(coef.size() == K);
1408 assert(coef.rows() == 1);
1409 for (Eigen::Index k = 0; k < K; ++k) {
1410 coefs(k, bi) = coef(0, k);
1411 }
1412 }
1413
1414 const auto& ij_table =
1416 for (index_t pid = 0; pid < ij_table.size(); ++pid) {
1417 const auto integral = nanson * buffer[pid];
1418 for (const auto ij : ij_table[pid]) {
1419 curr_rhs(ij[0]) += coefs.data()[ij[1]] * integral;
1420 }
1421 }
1422 });
1423 }
1424}
1425
1426template <
1427 typename MeshType,
1428 typename FeExpressionTuple,
1429 typename FeExpressionFaceTuple>
1431 MeshType,
1432 FeExpressionTuple,
1433 FeExpressionFaceTuple>::integrate(index_t cell_id) {
1434 this->preallocate(cell_id);
1435 auto& cell = this->getCell(this->m_cell_id, true);
1436
1437 // TODO: change integration P/Q depending of polynomial type
1438 const auto order = std::max(this->m_order, this->m_order_face);
1439 Profiler::start("integrate::integrateMonomialsQFree");
1440 const auto integrateMonomials =
1442 const auto [aints, eints] = integrateMonomials(cell, order);
1443 Profiler::stop("integrate::integrateMonomialsQFree");
1444
1445 integrateVolumeCell(aints.begin());
1446
1447 const auto eints_data = eints.begin();
1448 const auto slice_dim = aints.numel();
1449 for (this->m_face_id = 0; this->m_face_id < cell.nfaces();
1450 ++this->m_face_id) {
1451 this->findCellNeigh();
1452 const double* eints_curr_data = eints_data + this->m_face_id * slice_dim;
1453 const double nanson = updateFaceNormalAndGetNanson();
1454 Profiler::start("integrate::precomputeMonomialCoefsForFace");
1456 Profiler::stop("integrate::precomputeMonomialCoefsForFace");
1457 Profiler::start("integrate::integrateFaceCell");
1458 integrateFaceCell(eints_curr_data, nanson);
1459 Profiler::stop("integrate::integrateFaceCell");
1460 }
1461
1462 this->applyBasisScaling();
1463}
1464
1465} // namespace assemble
1466} // namespace vulpes
1467
1468#endif // VULPES_ASSEMBLE_INTEGRATOR_QFREE_HPP_
static void stop(const char *label)
stop(label) when recording is on.
Definition profiler.hpp:90
static void start(const char *label)
start(label) when recording is on.
Definition profiler.hpp:84
Manages geometrical information about the cell and its mapping to the reference element.
Definition cell_manager.hpp:62
Eigen::Map< Eigen::VectorXd > getCurrFaceRhs(const auto &expr, Eigen::Index expr_id)
Definition integrator_base.hpp:380
WeakFormIntegratorBase(const MeshType &mesh, CellManager< MeshType, FeType > &cell_manager, const FeExpressionTuple &fe_expression, const std::tuple<> &fe_expression_face)
Definition integrator_base.hpp:126
static constexpr index_t s_n_face_expr_linear
Definition integrator_base.hpp:102
Eigen::Map< Eigen::MatrixXd > getCurrFaceIntegral(const auto &expr, Eigen::Index expr_id)
Definition integrator_base.hpp:345
Eigen::Tensor< double, 3 > m_integrals
Definition integrator_base.hpp:562
void preallocate(index_t cell_id)
Definition integrator_base.hpp:239
CellManager< MeshType, FeType > & m_cell_manager
Definition integrator_base.hpp:532
const CellType & getCell(index_t cell_id, bool update_mapping=false)
Definition integrator_base.hpp:222
static constexpr index_t s_n_face_expr_bilinear
Definition integrator_base.hpp:99
Implements a quadrature-free finite element integrator.
Definition integrator_qfree.hpp:233
void gatherLiftedMonomials()
Orchestrates the gathering and compression of lifted monomials.
Definition integrator_qfree.hpp:1125
void precomputeMonomialCoefsForFace()
Precomputes the values of the evaluation parts of the gathered monomials for the current face.
Definition integrator_qfree.hpp:1260
datastructure::CrsMap< TypeIJ, index_t > RepeatingTableIJ
A compressed map used as a lookup table for repeated bilinear polynomials.
Definition integrator_qfree.hpp:507
std::array< FlatPolyType, s_n_expr_linear > m_poly_table_flat_linear
Polynomial tables for linear volume expressions.
Definition integrator_qfree.hpp:529
std::array< RepeatingTableIJ, s_n_expr_bilinear > m_poly_table_flat_ijs_table
Lookup table mapping unique bilinear volume polynomials to (row, col, k) entries.
Definition integrator_qfree.hpp:525
typename MeshType::index_t index_t
The index type used by the mesh.
Definition integrator_qfree.hpp:280
WeakFormIntegratorBase< MeshType, FeExpressionTuple, FeExpressionFaceTuple > WeakFormIntegratorBaseType
Definition integrator_qfree.hpp:236
std::array< CompressedListGatheredPoly, s_n_face_expr_bilinear > m_poly_table_face_lifted_gathered
Compressed and gathered version of m_poly_table_face_lifted_flat.
Definition integrator_qfree.hpp:565
void integrateVolumeCell(const double *aints_data)
Integrates all volume expressions over the current cell.
Definition integrator_qfree.hpp:1140
std::array< std::vector< GatheredPolynomial >, s_n_face_expr_bilinear > gatherUncompressedLiftedMonomials()
Gathers terms for lifted monomials from face expressions (uncompressed stage).
Definition integrator_qfree.hpp:938
datastructure::CrsMap< CompressedGatheredMonomial, index_t > CompressedListGatheredPoly
A compressed representation of a list of gathered polynomials.
Definition integrator_qfree.hpp:296
std::array< Eigen::Index, s_n_face_expr_linear > m_npoly_comps_face_linear
Stores the number of polynomial components for each linear face expression.
Definition integrator_qfree.hpp:606
Eigen::Matrix< double, dim, 2 > computeRefToNeighRefMap() const
Computes the affine mapping from the current cell's reference space to a neighbor's reference space.
Definition integrator_qfree.hpp:444
static constexpr uint32_t s_n_expr_bilinear
The number of bilinear volume expressions.
Definition integrator_qfree.hpp:249
std::array< FlatPolyType, s_n_expr_bilinear > m_poly_table_flat_nodupes
Unique polynomials for bilinear volume expressions, after deduplication.
Definition integrator_qfree.hpp:522
PolyType::MonomialType MonoType
The monomial type for standard polynomials.
Definition integrator_qfree.hpp:267
std::array< Eigen::Index, s_n_expr_linear > m_npoly_comps_volume_linear
Stores the number of polynomial components for each linear volume expression.
Definition integrator_qfree.hpp:600
std::array< Eigen::Index, 2 > TypeI
Helper type for storing indices (i * s_n_blocks + bi, k) for the linear (RHS) lookup table – no trial...
Definition integrator_qfree.hpp:510
PolyTypeLifted::MonomialType MonoTypeLifted
The monomial type for lifted polynomials.
Definition integrator_qfree.hpp:278
std::array< FlatPolyType, s_n_expr_bilinear > m_poly_table_flat
Polynomial tables for bilinear volume expressions.
Definition integrator_qfree.hpp:519
void integrate(index_t cell_id)
Performs the full integration process for a given cell.
Definition integrator_qfree.hpp:1433
datastructure::CrsMap< std::pair< double, uint16_t >, index_t > m_gathered_monos
Stores the unique "gathered" parts of monomials. Each row corresponds to a gather_id and contains a l...
Definition integrator_qfree.hpp:586
std::array< Eigen::Index, 3 > TypeIJ
Helper type for storing indices (i * s_n_blocks + bi, j * s_n_blocks + bj, k) for the bilinear lookup...
Definition integrator_qfree.hpp:504
std::vector< double > m_eval_table_ext
Buffer storing the computed values of the unique evaluation monomials (from m_eva_idx_table) for the ...
Definition integrator_qfree.hpp:593
static constexpr uint32_t s_n_face_expr_linear
The number of linear (RHS) face expressions.
Definition integrator_qfree.hpp:258
std::decay_t< decltype(PolyType{}.template liftDimension< 0, 2 *dim >())> PolyTypeLifted
The polynomial type "lifted" to a higher dimension. This is used for face integrals involving neighbo...
Definition integrator_qfree.hpp:275
std::vector< std::pair< double, uint16_t > > GatheredPolynomialCoef
Coefficients for a compressed gathered polynomial.
Definition integrator_qfree.hpp:290
static constexpr uint32_t s_n_face_expr_bilinear
The number of bilinear face expressions.
Definition integrator_qfree.hpp:255
datastructure::CrsMap< CompressedMonomial, index_t > FlatPolyType
A compressed representation of a list of standard polynomials.
Definition integrator_qfree.hpp:294
std::vector< std::array< uint8_t, dim *2 > > buildUniqueEvaTableLiftedMonomials(const std::array< std::vector< GatheredPolynomial >, s_n_face_expr_bilinear > &gathered_monos_table)
Scans all gathered (lifted) monomials to build a table of unique evaluation exponents.
Definition integrator_qfree.hpp:1025
std::remove_pointer_t< std::tuple_element_t< 0, FeExpressionTuple > >::FeSpaceType FeType
Definition integrator_qfree.hpp:262
FlatPolyType compress(const datastructure::CrsMapUncompressed< MonoType > &uncompressed_table)
Compresses a table of polynomials.
Definition integrator_qfree.hpp:618
std::vector< std::array< uint8_t, dim *2 > > m_eva_idx_table
A table mapping a unique integer ID to a monomial exponent array. Used to evaluate the mapping-depend...
Definition integrator_qfree.hpp:578
std::array< RepeatingTableIJ, s_n_face_expr_bilinear > m_poly_table_face_lifted_gathered_ijs_table
Lookup table for lifted bilinear face polynomials.
Definition integrator_qfree.hpp:572
std::array< Eigen::Index, s_n_face_expr_bilinear > m_npoly_comps_face
Stores the number of polynomial components for each bilinear face expression.
Definition integrator_qfree.hpp:603
std::array< FlatPolyType, s_n_face_expr_linear > m_poly_table_face_flat_linear_nodupes
Unique polynomials for linear face expressions.
Definition integrator_qfree.hpp:553
std::array< RepeatingTableIJ, s_n_face_expr_bilinear > m_poly_table_face_flat_ijs_table
Lookup table for bilinear face polynomials.
Definition integrator_qfree.hpp:546
std::array< FlatPolyTypeLifted, s_n_face_expr_bilinear > m_poly_table_face_lifted_flat
Uncompressed polynomial tables for lifted bilinear face expressions.
Definition integrator_qfree.hpp:562
static constexpr uint32_t s_n_face_expr
The number of face expressions.
Definition integrator_qfree.hpp:246
void buildLookupTables()
Builds lookup tables to identify and reuse identical polynomials.
Definition integrator_qfree.hpp:799
std::array< Eigen::Index, s_n_expr_bilinear > m_npoly_comps_volume
Stores the number of polynomial components for each bilinear volume expression.
Definition integrator_qfree.hpp:597
static constexpr index_t s_n_blocks
The number of blocks for vector/tensor-valued problems.
Definition integrator_qfree.hpp:283
std::array< RepeatingTableI, s_n_expr_linear > m_poly_table_flat_linear_ijs_table
Lookup table mapping unique linear volume polynomials to (row, k) entries.
Definition integrator_qfree.hpp:536
std::vector< double > m_gather_coef
Buffer storing the computed values of the gathered parts (from m_gathered_monos) for the current face...
Definition integrator_qfree.hpp:590
std::vector< GatheredMonomial< dim > > GatheredPolynomial
An uncompressed gathered polynomial for a single entry.
Definition integrator_qfree.hpp:288
void compressGatheredLiftedPolynomials(const std::array< std::vector< GatheredPolynomial >, s_n_face_expr_bilinear > &gathered_monos_table)
Compresses the gathered monomials into their final integer-ID-based format.
Definition integrator_qfree.hpp:1052
std::array< FlatPolyType, s_n_face_expr_bilinear > m_poly_table_face_flat_nodupes
Unique polynomials for bilinear face expressions.
Definition integrator_qfree.hpp:543
static constexpr uint32_t s_n_expr_linear
The number of linear (RHS) volume expressions.
Definition integrator_qfree.hpp:252
std::array< FlatPolyType, s_n_expr_linear > m_poly_table_flat_linear_nodupes
Unique polynomials for linear volume expressions, after deduplication.
Definition integrator_qfree.hpp:532
void integrateFaceCell(const double *eints_data, double nanson)
Integrates all face expressions over the current face of the cell.
Definition integrator_qfree.hpp:1299
double updateFaceNormalAndGetNanson()
Updates the face normal vector in m_fe_values and computes the Nanson's formula factor.
Definition integrator_qfree.hpp:1238
std::array< FlatPolyType, s_n_face_expr_linear > m_poly_table_face_flat_linear
Polynomial tables for linear face expressions (non-lifted).
Definition integrator_qfree.hpp:550
static constexpr std::size_t dim
The spatial dimension of the mesh.
Definition integrator_qfree.hpp:241
datastructure::CrsMap< MonoTypeLifted, index_t > FlatPolyTypeLifted
A compressed representation of a list of lifted polynomials.
Definition integrator_qfree.hpp:292
FeType::FeSpaceType::PolynomialFast PolyType
The polynomial type used for standard basis functions.
Definition integrator_qfree.hpp:265
std::array< RepeatingTableI, s_n_face_expr_linear > m_poly_table_face_flat_linear_ijs_table
Lookup table for linear face polynomials.
Definition integrator_qfree.hpp:556
std::array< FlatPolyType, s_n_face_expr_bilinear > m_poly_table_face_flat
Polynomial tables for bilinear face expressions (non-lifted).
Definition integrator_qfree.hpp:540
std::array< CompressedListGatheredPoly, s_n_face_expr_bilinear > m_poly_table_face_lifted_gathered_nodupes
Unique polynomials for lifted bilinear face expressions, after gathering and deduplication.
Definition integrator_qfree.hpp:569
WeakFormIntegratorQFree(const MeshType &mesh, CellManager< MeshType, FeType > &cell_manager, const FeExpressionTuple &fe_expression, const FeExpressionFaceTuple &fe_expression_face=FeExpressionFaceTuple{})
Constructs the quadrature-free integrator.
Definition integrator_qfree.hpp:644
static constexpr uint32_t s_n_expr
The number of volume expressions.
Definition integrator_qfree.hpp:243
datastructure::CrsMap< TypeI, index_t > RepeatingTableI
A compressed map used as a lookup table for repeated linear polynomials.
Definition integrator_qfree.hpp:513
A class that behaves like a vector of vectors, providing automatic row range checking.
Definition crs_map.hpp:758
SmallVector< DataType, N > & getRow(std::size_t row_idx)
Access a row of the matrix as a mutable reference.
Definition crs_map.hpp:857
Definition crs_map.hpp:72
const auto & indices() const
Constant accessor to the indices buffer.
Definition crs_map.hpp:442
const auto & data() const
Constant accessor to the data buffer.
Definition crs_map.hpp:438
constexpr auto split_expression_tuple(std::tuple< Ts... > t)
Definition integrator_traits.hpp:145
Definition cell_manager.hpp:39
Definition monomial.hpp:44
T getLinearIndex(const std::array< T, Dim > &monomial)
Computes the linear index given the exponents of the monomial.
Definition monomial.hpp:218
auto integrateMonomialsQFree(const geometry::Cell< Dim, FloatType, IndexType > &elem, IndexType deg)
Definition qfree.hpp:264
void for_each_idxed(Tuple &&tuple, Func &&func)
Apply func to every element of tuple together with its index.
Definition vvutils.hpp:165
void for_each(Tuple &&tuple, Func &&func)
Apply func to every element of tuple, in order.
Definition vvutils.hpp:142
Definition cell_manager.hpp:38
A fully compressed representation of a gathered monomial GatheredMonomial for face integrals.
Definition integrator_qfree.hpp:107
uint16_t evalut_id
ID for the common evaluation part (lookup for mapping-related coefficients).
Definition integrator_qfree.hpp:113
bool operator<(const CompressedGatheredMonomial &other) const
Comparison operator to allow sorting and storing in ordered containers.
Definition integrator_qfree.hpp:124
uint32_t gather_id
ID for the gathered sum of terms (lookup for the expression in parentheses).
Definition integrator_qfree.hpp:116
uint16_t integr_id
ID for the integrable part of the monomial (lookup for ).
Definition integrator_qfree.hpp:110
A compressed representation of a standard monomial.
Definition integrator_qfree.hpp:81
double coef
The coefficient of the monomial.
Definition integrator_qfree.hpp:83
bool operator<(const CompressedMonomial &other) const
Comparison operator to allow sorting and storing in ordered containers.
Definition integrator_qfree.hpp:94
std::size_t integr_id
A unique ID representing the monomial's exponents, obtained via linearization (e.g....
Definition integrator_qfree.hpp:86
Represents a monomial after the "gathering" process for face integrals.
Definition integrator_qfree.hpp:63
std::vector< std::pair< double, std::array< uint8_t, Dim *2 > > > gather
A collection of remaining terms. Each pair contains a coefficient and the exponents of the non-common...
Definition integrator_qfree.hpp:72
std::array< uint8_t, Dim *2 > evalut_id
A unique ID for the common evaluation part of the monomial (e.g., the term in ).
Definition integrator_qfree.hpp:69
uint16_t integr_id
A unique ID representing the part of the monomial to be integrated (e.g., ).
Definition integrator_qfree.hpp:66