Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
fe_expr_basis.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_FE_FE_EXPRESSIONS_FE_EXPR_BASIS_HPP_
25#define VULPES_FE_FE_EXPRESSIONS_FE_EXPR_BASIS_HPP_
26
29
30namespace vulpes {
31namespace fe {
32
33template <
34 std::size_t IndexBegin,
35 std::size_t IndexEnd,
36 std::size_t Dim,
37 typename FeSpace,
38 bool IsTest = false>
40 : public FeExpressionBase<
41 Dim,
42 FeExpressionFunc<IndexBegin, IndexEnd, Dim, FeSpace, IsTest>> {
43 public:
44 static constexpr bool is_leaf = true;
45 static constexpr uint8_t is_bilinear = IsTest ? IsLinearTest : IsLinearTrial;
46 using FeSpaceType = FeSpace;
47 using PolynomialType = std::decay_t<decltype(FeSpace{0}.getBasis()[0])>;
48 static constexpr std::size_t k_n_comp = IndexEnd - IndexBegin;
49
50 static constexpr std::size_t k_index_begin = IndexBegin;
51 static constexpr std::size_t k_index_end = IndexEnd;
52
53 explicit constexpr FeExpressionFunc(const FeSpace& fe_space)
54 : m_fe_space(fe_space) {};
59
60 constexpr const FeSpace& feSpace() const { return m_fe_space; }
61
62 template <std::size_t J = 0, std::size_t I = 0>
63 decltype(auto) evaluate(
64 const FeValues<Dim>& fe_values,
65 std::size_t j,
66 std::size_t i,
67 std::size_t q) const {
68 using ScalarType = typename FeValues<Dim>::real_t;
69 if constexpr (IsTest) {
70 if constexpr (k_index_begin <= I && I < k_index_end) {
71 if constexpr (k_n_comp == 1) {
72 return fe_values.getShapeEval()(i, q);
73 } else {
74 static constexpr auto DI = I - IndexBegin;
76 fe_values.getShapeEval()(i, q));
77 }
78 } else {
79 return void();
80 }
81 } else {
82 if constexpr (k_index_begin <= J && J < k_index_end) {
83 if constexpr (k_n_comp == 1) {
84 return fe_values.getShapeEval()(j, q);
85 } else {
86 static constexpr auto DJ = J - IndexBegin;
88 fe_values.getShapeEval()(j, q));
89 }
90 } else {
91 return void();
92 }
93 }
94 }
95
96 constexpr UpdateFlagsType computeUpdateFlags() const { return UpdateValues; }
97 constexpr std::size_t computeOrder() const { return m_fe_space.order(); }
98
99 decltype(auto) evaluatePoly(
100 const FeValues<Dim>&,
101 std::size_t j,
102 std::size_t i,
103 std::size_t bi,
104 std::size_t bj) const {
105 if constexpr (IsTest) {
106 if (k_index_begin <= bj && bj < k_index_end) {
107 if constexpr (k_n_comp == 1) {
108 return Eigen::Vector<PolynomialType, 1>{m_fe_space.getBasis()[i]};
109 } else {
110 Eigen::Vector<PolynomialType, k_n_comp> result;
111 result(bj - IndexBegin) = m_fe_space.getBasis()[i];
112 return result;
113 }
114 } else {
115 if constexpr (k_n_comp == 1) {
116 return Eigen::Vector<PolynomialType, 1>{};
117 } else {
118 return Eigen::Vector<PolynomialType, k_n_comp>{};
119 }
120 }
121 } else {
122 if (k_index_begin <= bi && bi < k_index_end) {
123 if constexpr (k_n_comp == 1) {
124 return Eigen::Vector<PolynomialType, 1>{m_fe_space.getBasis()[j]};
125 } else {
126 Eigen::Vector<PolynomialType, k_n_comp> result;
127 result(bi - IndexBegin) = m_fe_space.getBasis()[j];
128 return result;
129 }
130 } else {
131 if constexpr (k_n_comp == 1) {
132 return Eigen::Vector<PolynomialType, 1>{};
133 } else {
134 return Eigen::Vector<PolynomialType, k_n_comp>{};
135 }
136 }
137 }
138 }
139
140 decltype(auto) evaluatePolyCoef(
141 const auto&, const auto&, std::size_t, std::size_t) const {
142 using ScalarType = typename FeValues<Dim>::real_t;
143 if constexpr (k_n_comp == 1) {
144 return Eigen::Vector<ScalarType, 1>{1.0};
145 } else {
146 return Eigen::Vector<ScalarType, k_n_comp>{
147 Eigen::Vector<ScalarType, k_n_comp>::Ones()};
148 }
149 }
150 constexpr bool precompute(const FeValues<Dim>&, const CellsType<Dim>&) const {
151 return true;
152 }
153
154 protected:
155 const FeSpace& m_fe_space;
156};
157
158template <
159 typename FeSpace,
160 std::size_t IndexBegin = 0,
161 std::size_t IndexEnd = 1>
164
165template <
166 typename FeSpace,
167 std::size_t IndexBegin = 0,
168 std::size_t IndexEnd = 1>
171
173
174template <
175 std::size_t IndexBegin,
176 std::size_t IndexEnd,
177 std::size_t Dim,
178 typename FeSpace,
179 bool IsTest = false>
181 : public FeExpressionBase<
182 Dim,
183 FeExpressionGradFunc<IndexBegin, IndexEnd, Dim, FeSpace, IsTest>> {
184 public:
185 static constexpr bool is_leaf = false;
186 static constexpr uint8_t is_bilinear = IsTest ? IsLinearTest : IsLinearTrial;
187 using FeSpaceType = FeSpace;
188 using PolynomialType = std::decay_t<decltype(FeSpace{0}.getBasis()[0])>;
189
190 static constexpr std::size_t k_index_begin = IndexBegin;
191 static constexpr std::size_t k_index_end = IndexEnd;
192
196
197 constexpr const auto& feSpace() const { return m_w.feSpace(); }
198
199 template <std::size_t J = 0, std::size_t I = 0>
200 decltype(auto) evaluate(
201 const FeValues<Dim>& fe_values,
202 std::size_t j,
203 std::size_t i,
204 std::size_t q) const {
205 if constexpr (IsTest) {
206 if constexpr (k_index_begin <= I && I < k_index_end) {
207 if constexpr (k_index_end - k_index_begin == 1) {
208 return fe_values.getGradEval()(i, q);
209 } else {
210 static_assert(k_index_end - k_index_begin == Dim);
211 static constexpr auto DI = I - IndexBegin;
212 return EigenVulpes::makeRowMat<DI>(fe_values.getGradEval()(i, q));
213 }
214 } else {
215 return void();
216 }
217 } else {
218 if constexpr (k_index_begin <= J && J < k_index_end) {
219 if constexpr (k_index_end - k_index_begin == 1) {
220 return fe_values.getGradEval()(j, q);
221 } else {
222 static_assert(k_index_end - k_index_begin == Dim);
223 static constexpr auto DJ = J - IndexBegin;
224 return EigenVulpes::makeRowMat<DJ>(fe_values.getGradEval()(j, q));
225 }
226 } else {
227 return void();
228 }
229 }
230 }
231
233 return UpdateGradients;
234 }
235 constexpr std::size_t computeOrder() const {
236 return m_w.computeOrder() > 0 ? m_w.computeOrder() - 1 : 0;
237 }
238
239 decltype(auto) evaluatePoly(
240 const FeValues<Dim>&,
241 std::size_t j,
242 std::size_t i,
243 std::size_t bi,
244 std::size_t bj) const {
245 // WARNING gradient is not cached, we expect to be done by the user
246 if constexpr (IsTest) {
247 if (k_index_begin <= bj && bj < k_index_end) {
248 if constexpr (k_index_end - k_index_begin == 1) {
249 return feSpace().getBasis()[i].gradient();
250 } else {
251 static_assert(k_index_end - k_index_begin == Dim);
252 Eigen::Matrix<PolynomialType, Dim, Dim> result;
253 result.row(bj - IndexBegin) = feSpace().getBasis()[i].gradient();
254 return Eigen::Vector<PolynomialType, Dim * Dim>{result.reshaped()};
255 }
256 } else {
257 if constexpr (k_index_end - k_index_begin == 1) {
258 return Eigen::Vector<PolynomialType, Dim>{};
259 } else {
260 return Eigen::Vector<PolynomialType, Dim * Dim>{};
261 }
262 }
263 } else {
264 if (k_index_begin <= bi && bi < k_index_end) {
265 if constexpr (k_index_end - k_index_begin == 1) {
266 return feSpace().getBasis()[j].gradient();
267 } else {
268 static_assert(k_index_end - k_index_begin == Dim);
269 Eigen::Matrix<PolynomialType, Dim, Dim> result;
270 result.row(bi - IndexBegin) = feSpace().getBasis()[j].gradient();
271 return Eigen::Vector<PolynomialType, Dim * Dim>{result.reshaped()};
272 }
273 } else {
274 if constexpr (k_index_end - k_index_begin == 1) {
275 return Eigen::Vector<PolynomialType, Dim>{};
276 } else {
277 return Eigen::Vector<PolynomialType, Dim * Dim>{};
278 }
279 }
280 }
281 }
282
283 decltype(auto) evaluatePolyCoef(
284 const auto& mapping, const auto&, std::size_t, std::size_t) const {
285 using CoefType = std::decay_t<decltype(mapping.jacobianInv({}))>;
286 static_assert(CoefType::RowsAtCompileTime > 0);
287 static_assert(CoefType::ColsAtCompileTime == 1);
288 if constexpr (k_index_end - k_index_begin == 1) {
289 return mapping.jacobianInv({});
290 } else {
291 const auto row_jac = mapping.jacobianInv({});
292 using ScalarType = typename FeValues<Dim>::real_t;
293 Eigen::Vector<ScalarType, Dim * Dim> result;
294 for (std::size_t i = 0; i < Dim * Dim; ++i) {
295 result(i) = row_jac(i / Dim);
296 }
297 return result;
298 }
299 }
300
301 constexpr bool precompute(const FeValues<Dim>&, const CellsType<Dim>&) const {
302 return true;
303 }
304
305 protected:
307};
308
309template <
310 std::size_t IndexBegin,
311 std::size_t IndexEnd,
312 std::size_t Dim,
313 typename FeSpace,
314 bool IsTest>
319
321
322template <
323 std::size_t IndexBegin,
324 std::size_t IndexEnd,
325 std::size_t Dim,
326 typename FeSpace,
327 bool IsTest = false>
329 : public FeExpressionBase<
330 Dim,
331 FeExpressionSymGradFunc<IndexBegin, IndexEnd, Dim, FeSpace, IsTest>> {
332 public:
333 static constexpr bool is_leaf = false;
334 static constexpr uint8_t is_bilinear = IsTest ? IsLinearTest : IsLinearTrial;
335 using FeSpaceType = FeSpace;
336 using PolynomialType = std::decay_t<decltype(FeSpace{0}.getBasis()[0])>;
337
338 static constexpr std::size_t k_index_begin = IndexBegin;
339 static constexpr std::size_t k_index_end = IndexEnd;
340
344
345 constexpr const auto& feSpace() const { return m_w.feSpace(); }
346
347 template <std::size_t J = 0, std::size_t I = 0>
348 decltype(auto) evaluate(
349 const FeValues<Dim>& fe_values,
350 std::size_t j,
351 std::size_t i,
352 std::size_t q) const {
353 if constexpr (IsTest) {
354 if constexpr (k_index_begin <= I && I < k_index_end) {
355 static constexpr auto DI = I - IndexBegin;
356 return EigenVulpes::makeSymMat<DI>(fe_values.getGradEval()(i, q));
357 } else {
358 return void();
359 }
360 } else {
361 if constexpr (k_index_begin <= J && J < k_index_end) {
362 static constexpr auto DJ = J - IndexBegin;
363 return EigenVulpes::makeSymMat<DJ>(fe_values.getGradEval()(j, q));
364 } else {
365 return void();
366 }
367 }
368 }
369
371 return UpdateGradients;
372 }
373 constexpr std::size_t computeOrder() const {
374 return m_w.computeOrder() > 0 ? m_w.computeOrder() - 1 : 0;
375 }
376
377 decltype(auto) evaluatePoly(
378 const FeValues<Dim>&,
379 std::size_t j,
380 std::size_t i,
381 std::size_t bi,
382 std::size_t bj) const {
383 // WARNING gradient is not cached, we expect to be done by the user
384 if constexpr (IsTest) {
385 if (k_index_begin <= bj && bj < k_index_end) {
386 if constexpr (k_index_end - k_index_begin == 1) {
387 return feSpace().getBasis()[i].gradient();
388 } else {
389 static_assert(k_index_end - k_index_begin == Dim);
390 Eigen::Matrix<PolynomialType, Dim, Dim> result;
391 using real_t = PolynomialType::ScalarType;
392 const auto halfp = feSpace().getBasis()[i] * real_t(0.5);
393 result.row(bj - IndexBegin) = halfp.gradient();
394 result.col(bj - IndexBegin) += halfp.gradient();
395 return Eigen::Vector<PolynomialType, Dim * Dim>{result.reshaped()};
396 }
397 } else {
398 if constexpr (k_index_end - k_index_begin == 1) {
399 return Eigen::Vector<PolynomialType, Dim>{};
400 } else {
401 return Eigen::Vector<PolynomialType, Dim * Dim>{};
402 }
403 }
404 } else {
405 if (k_index_begin <= bi && bi < k_index_end) {
406 if constexpr (k_index_end - k_index_begin == 1) {
407 return feSpace().getBasis()[j].gradient();
408 } else {
409 static_assert(k_index_end - k_index_begin == Dim);
410 Eigen::Matrix<PolynomialType, Dim, Dim> result;
411 using real_t = PolynomialType::ScalarType;
412 const auto halfp = feSpace().getBasis()[j] * real_t(0.5);
413 result.row(bi - IndexBegin) = halfp.gradient();
414 result.col(bi - IndexBegin) += halfp.gradient();
415 return Eigen::Vector<PolynomialType, Dim * Dim>{result.reshaped()};
416 }
417 } else {
418 if constexpr (k_index_end - k_index_begin == 1) {
419 return Eigen::Vector<PolynomialType, Dim>{};
420 } else {
421 return Eigen::Vector<PolynomialType, Dim * Dim>{};
422 }
423 }
424 }
425 }
426
427 decltype(auto) evaluatePolyCoef(
428 const auto& mapping, const auto&, std::size_t bi, std::size_t bj) const {
429 static_assert(
430 k_index_end - k_index_begin == Dim &&
431 "The SymGrad is defined only for vector spaces.");
432 const auto jac_row = mapping.jacobianInv({});
433 using ScalarType = typename FeValues<Dim>::real_t;
434 Eigen::Matrix<ScalarType, Dim, Dim> jac_mat =
435 Eigen::Matrix<ScalarType, Dim, Dim>::Zero();
436 if constexpr (IsTest) {
437 jac_mat.row(bj - IndexBegin) = jac_row;
438 jac_mat.col(bj - IndexBegin) = jac_row;
439 } else {
440 jac_mat.row(bi - IndexBegin) = jac_row;
441 jac_mat.col(bi - IndexBegin) = jac_row;
442 }
443 return Eigen::Vector<ScalarType, Dim * Dim>{jac_mat.reshaped()};
444 }
445
446 constexpr bool precompute(const FeValues<Dim>&, const CellsType<Dim>&) const {
447 return true;
448 }
449
450 protected:
452};
453
454template <
455 std::size_t IndexBegin,
456 std::size_t IndexEnd,
457 std::size_t Dim,
458 typename FeSpace,
459 bool IsTest>
464
466
467template <
468 std::size_t IndexBegin,
469 std::size_t IndexEnd,
470 std::size_t Dim,
471 typename FeSpace,
472 bool IsTest = false>
474 Dim,
475 FeExpressionTraceSymGradFunc<
476 IndexBegin,
477 IndexEnd,
478 Dim,
479 FeSpace,
480 IsTest>> {
481 public:
482 static constexpr bool is_leaf = false;
483 static constexpr uint8_t is_bilinear = IsTest ? IsLinearTest : IsLinearTrial;
484 using FeSpaceType = FeSpace;
485 using PolynomialType = std::decay_t<decltype(FeSpace{0}.getBasis()[0])>;
486
487 static constexpr std::size_t k_index_begin = IndexBegin;
488 static constexpr std::size_t k_index_end = IndexEnd;
489
493
494 constexpr const auto& feSpace() const { return m_w.feSpace(); }
495
496 template <std::size_t J = 0, std::size_t I = 0>
497 decltype(auto) evaluate(
498 const FeValues<Dim>& fe_values,
499 std::size_t j,
500 std::size_t i,
501 std::size_t q) const {
502 if constexpr (IsTest) {
503 if constexpr (k_index_begin <= I && I < k_index_end) {
504 static constexpr auto DI = I - IndexBegin;
505 return fe_values.getGradEval()(i, q)[DI];
506 } else {
507 return void();
508 }
509 } else {
510 if constexpr (k_index_begin <= J && J < k_index_end) {
511 static constexpr auto DJ = J - IndexBegin;
512 return fe_values.getGradEval()(j, q)[DJ];
513 } else {
514 return void();
515 }
516 }
517 }
518
520 return UpdateGradients;
521 }
522 constexpr std::size_t computeOrder() const {
523 return m_w.computeOrder() > 0 ? m_w.computeOrder() - 1 : 0;
524 }
525
526 Eigen::Vector<PolynomialType, 1> evaluatePoly(
527 const FeValues<Dim>&,
528 std::size_t j,
529 std::size_t i,
530 std::size_t bi,
531 std::size_t bj) const {
532 if constexpr (IsTest) {
533 if (k_index_begin <= bj && bj < k_index_end) {
534 return Eigen::Vector<PolynomialType, 1>{
535 feSpace().getBasis()[i].gradient()[bj - IndexBegin]};
536 } else {
537 return Eigen::Vector<PolynomialType, 1>{};
538 }
539 } else {
540 if (k_index_begin <= bi && bi < k_index_end) {
541 return Eigen::Vector<PolynomialType, 1>{
542 feSpace().getBasis()[j].gradient()[bi - IndexBegin]};
543 } else {
544 return Eigen::Vector<PolynomialType, 1>{};
545 }
546 }
547 }
548
549 decltype(auto) evaluatePolyCoef(
550 const auto& mapping, const auto&, std::size_t bi, std::size_t bj) const {
551 using CoefType = std::decay_t<decltype(mapping.jacobianInv({}))>;
552 using ScalarType = typename FeValues<Dim>::real_t;
553 static_assert(CoefType::RowsAtCompileTime > 0);
554 static_assert(CoefType::ColsAtCompileTime == 1);
555 if constexpr (IsTest) {
556 const auto DJ = bj - IndexBegin;
557 return Eigen::Vector<ScalarType, 1>{mapping.jacobianInv({})[DJ]};
558 } else {
559 const auto DI = bi - IndexBegin;
560 return Eigen::Vector<ScalarType, 1>{mapping.jacobianInv({})[DI]};
561 }
562 }
563
564 constexpr bool precompute(const FeValues<Dim>&, const CellsType<Dim>&) const {
565 return true;
566 }
567
568 protected:
570};
571
572template <
573 std::size_t IndexBegin,
574 std::size_t IndexEnd,
575 std::size_t Dim,
576 typename FeSpace,
577 bool IsTest>
582 IndexBegin, IndexEnd, Dim, FeSpace, IsTest>{w};
583}
584
585template <
586 std::size_t IndexBegin,
587 std::size_t IndexEnd,
588 std::size_t Dim,
589 typename FeSpace,
590 bool IsTest>
595
597
598template <
599 std::size_t IndexBegin,
600 std::size_t IndexEnd,
601 std::size_t Dim,
602 typename FeSpace,
603 bool IsTest>
605 Dim,
606 FeExpressionNeighborFunc<
607 IndexBegin,
608 IndexEnd,
609 Dim,
610 FeSpace,
611 IsTest>> {
612 public:
613 static constexpr bool is_leaf = false;
614 static constexpr uint8_t is_bilinear = IsTest ? IsLinearTest : IsLinearTrial;
615
616 using FeSpaceType = FeSpace;
617
618 static constexpr std::size_t k_index_begin = IndexBegin;
619 static constexpr std::size_t k_index_end = IndexEnd;
620
624
625 constexpr const auto& feSpace() const { return m_w.feSpace(); }
626
627 template <std::size_t J = 0, std::size_t I = 0>
628 decltype(auto) evaluate(
629 const FeValues<Dim>& fe_values,
630 std::size_t j,
631 std::size_t i,
632 std::size_t q) const {
633 assert(&fe_values.neighValues());
634 return m_w.template evaluate<J, I>(fe_values.neighValues(), j, i, q);
635 }
636
638 // UpdateValues is required so that evalAndApplyMapping computes
639 // getShapeEval() on the neighbour FeValues before evaluate() reads it.
641 }
642 constexpr std::size_t computeOrder() const { return m_w.computeOrder(); }
643
644 decltype(auto) evaluatePoly(
645 const FeValues<Dim>& fe_values,
646 std::size_t j,
647 std::size_t i,
648 std::size_t bi,
649 std::size_t bj) const {
650 using TypeW =
651 std::decay_t<decltype(m_w.evaluatePoly(fe_values, j, i, 0, 0))>;
652 constexpr int RowsW = TypeW::RowsAtCompileTime;
653 constexpr int ColsW = TypeW::ColsAtCompileTime;
654 // NOLINTBEGIN
655 using PolyTypeLifted =
656 std::decay_t<decltype(TypeW{}(0, 0).applyCartesianMapping())>;
657 // NOLINTEND
658 return Eigen::Matrix<PolyTypeLifted, RowsW, ColsW>{
659 m_w.evaluatePoly(fe_values, j, i, bi, bj)
660 .unaryExpr(
661 [](const auto& poly) { return poly.applyCartesianMapping(); })};
662 }
663
664 decltype(auto) evaluatePolyCoef(
665 const auto& mapping,
666 const auto& fe_values,
667 std::size_t bi,
668 std::size_t bj) const {
669 return m_w.evaluatePolyCoef(mapping, fe_values, bi, bj);
670 }
671
672 constexpr bool precompute(const FeValues<Dim>&, const CellsType<Dim>&) const {
673 return true;
674 }
675
676 protected:
678};
679
680template <
681 std::size_t IndexBegin,
682 std::size_t IndexEnd,
683 std::size_t Dim,
684 typename FeSpace,
685 bool IsTest>
691
692// ============================================================================
693// FeExpressionSelfFunc: Evaluates expression on current cell in per-face mode
694// ============================================================================
695// Similar to neigh() but evaluates the function using current cell values.
696// This triggers UpdateNeighborValues (per-face evaluation) without
697// UpdateNeighborCell. Use case: Outflow upwind flux where u_upwind = u_current
698// but needs per-face integral.
699template <
700 std::size_t IndexBegin,
701 std::size_t IndexEnd,
702 std::size_t Dim,
703 typename FeSpace,
704 bool IsTest>
706 : public FeExpressionBase<
707 Dim,
708 FeExpressionSelfFunc<IndexBegin, IndexEnd, Dim, FeSpace, IsTest>> {
709 public:
710 static constexpr bool is_leaf = false;
711 static constexpr uint8_t is_bilinear = IsTest ? IsLinearTest : IsLinearTrial;
712
713 using FeSpaceType = FeSpace;
714
715 static constexpr std::size_t k_index_begin = IndexBegin;
716 static constexpr std::size_t k_index_end = IndexEnd;
717
721
722 constexpr const auto& feSpace() const { return m_w.feSpace(); }
723
724 template <std::size_t J = 0, std::size_t I = 0>
725 decltype(auto) evaluate(
726 const FeValues<Dim>& fe_values,
727 std::size_t j,
728 std::size_t i,
729 std::size_t q) const {
730 // Evaluate on CURRENT cell, but in per-face mode (set by
731 // UpdateNeighborValues flag)
732 return m_w.template evaluate<J, I>(fe_values, j, i, q);
733 }
734
736 // Must use UpdateNeighborValues to get per-face indexed storage.
737 // Otherwise all faces accumulate into single buffer (including unwanted
738 // inflow faces).
740 }
741 constexpr std::size_t computeOrder() const { return m_w.computeOrder(); }
742
743 decltype(auto) evaluatePoly(
744 const FeValues<Dim>& fe_values,
745 std::size_t j,
746 std::size_t i,
747 std::size_t bi,
748 std::size_t bj) const {
749 using TypeW =
750 std::decay_t<decltype(m_w.evaluatePoly(fe_values, j, i, 0, 0))>;
751 constexpr int RowsW = TypeW::RowsAtCompileTime;
752 constexpr int ColsW = TypeW::ColsAtCompileTime;
753 // NOLINTBEGIN
754 using PolyTypeLifted =
755 std::decay_t<decltype(TypeW{}(0, 0).applyCartesianMapping())>;
756 // NOLINTEND
757 return Eigen::Matrix<PolyTypeLifted, RowsW, ColsW>{
758 m_w.evaluatePoly(fe_values, j, i, bi, bj)
759 .unaryExpr(
760 [](const auto& poly) { return poly.applyCartesianMapping(); })};
761 }
762
763 decltype(auto) evaluatePolyCoef(
764 const auto& mapping,
765 const auto& fe_values,
766 std::size_t bi,
767 std::size_t bj) const {
768 return m_w.evaluatePolyCoef(mapping, fe_values, bi, bj);
769 }
770
771 constexpr bool precompute(const FeValues<Dim>&, const CellsType<Dim>&) const {
772 return true;
773 }
774
775 protected:
777};
778
779template <
780 std::size_t IndexBegin,
781 std::size_t IndexEnd,
782 std::size_t Dim,
783 typename FeSpace,
784 bool IsTest>
789
790} // namespace fe
791} // namespace vulpes
792
793#endif // VULPES_FE_FE_EXPRESSIONS_FE_EXPR_BASIS_HPP_
Eigen expression for a vector with a single non-zero component.
Definition eigen.hpp:318
Base class for Finite Element Expressions.
Definition fe_expr_base.hpp:210
Definition fe_expr_basis.hpp:42
FeExpressionFunc(const FeExpressionFunc &)=delete
FeExpressionFunc & operator=(FeExpressionFunc &&)=delete
static constexpr std::size_t k_index_end
Definition fe_expr_basis.hpp:51
FeExpressionFunc & operator=(const FeExpressionFunc &)=delete
decltype(auto) evaluate(const FeValues< Dim > &fe_values, std::size_t j, std::size_t i, std::size_t q) const
Definition fe_expr_basis.hpp:63
FeExpressionFunc(FeExpressionFunc &&)=delete
static constexpr std::size_t k_index_begin
Definition fe_expr_basis.hpp:50
decltype(auto) evaluatePolyCoef(const auto &, const auto &, std::size_t, std::size_t) const
Definition fe_expr_basis.hpp:140
constexpr bool precompute(const FeValues< Dim > &, const CellsType< Dim > &) const
Definition fe_expr_basis.hpp:150
decltype(auto) evaluatePoly(const FeValues< Dim > &, std::size_t j, std::size_t i, std::size_t bi, std::size_t bj) const
Definition fe_expr_basis.hpp:99
static constexpr std::size_t k_n_comp
Definition fe_expr_basis.hpp:48
constexpr const FeSpace & feSpace() const
Definition fe_expr_basis.hpp:60
FeSpace FeSpaceType
Definition fe_expr_basis.hpp:46
constexpr std::size_t computeOrder() const
Definition fe_expr_basis.hpp:97
constexpr FeExpressionFunc(const FeSpace &fe_space)
Definition fe_expr_basis.hpp:53
static constexpr uint8_t is_bilinear
Definition fe_expr_basis.hpp:45
constexpr UpdateFlagsType computeUpdateFlags() const
Definition fe_expr_basis.hpp:96
std::decay_t< decltype(FeSpace{0}.getBasis()[0])> PolynomialType
Definition fe_expr_basis.hpp:47
Definition fe_expr_basis.hpp:183
decltype(auto) evaluatePoly(const FeValues< Dim > &, std::size_t j, std::size_t i, std::size_t bi, std::size_t bj) const
Definition fe_expr_basis.hpp:239
const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > & m_w
Definition fe_expr_basis.hpp:306
decltype(auto) evaluatePolyCoef(const auto &mapping, const auto &, std::size_t, std::size_t) const
Definition fe_expr_basis.hpp:283
decltype(auto) evaluate(const FeValues< Dim > &fe_values, std::size_t j, std::size_t i, std::size_t q) const
Definition fe_expr_basis.hpp:200
static constexpr std::size_t k_index_end
Definition fe_expr_basis.hpp:191
constexpr std::size_t computeOrder() const
Definition fe_expr_basis.hpp:235
constexpr bool precompute(const FeValues< Dim > &, const CellsType< Dim > &) const
Definition fe_expr_basis.hpp:301
constexpr const auto & feSpace() const
Definition fe_expr_basis.hpp:197
static constexpr bool is_leaf
Definition fe_expr_basis.hpp:185
static constexpr uint8_t is_bilinear
Definition fe_expr_basis.hpp:186
std::decay_t< decltype(FeSpace{0}.getBasis()[0])> PolynomialType
Definition fe_expr_basis.hpp:188
FeExpressionGradFunc(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:193
constexpr UpdateFlagsType computeUpdateFlags() const
Definition fe_expr_basis.hpp:232
FeSpace FeSpaceType
Definition fe_expr_basis.hpp:187
static constexpr std::size_t k_index_begin
Definition fe_expr_basis.hpp:190
Definition fe_expr_basis.hpp:611
constexpr UpdateFlagsType computeUpdateFlags() const
Definition fe_expr_basis.hpp:637
decltype(auto) evaluatePoly(const FeValues< Dim > &fe_values, std::size_t j, std::size_t i, std::size_t bi, std::size_t bj) const
Definition fe_expr_basis.hpp:644
decltype(auto) evaluatePolyCoef(const auto &mapping, const auto &fe_values, std::size_t bi, std::size_t bj) const
Definition fe_expr_basis.hpp:664
static constexpr bool is_leaf
Definition fe_expr_basis.hpp:613
constexpr const auto & feSpace() const
Definition fe_expr_basis.hpp:625
static constexpr uint8_t is_bilinear
Definition fe_expr_basis.hpp:614
decltype(auto) evaluate(const FeValues< Dim > &fe_values, std::size_t j, std::size_t i, std::size_t q) const
Definition fe_expr_basis.hpp:628
static constexpr std::size_t k_index_begin
Definition fe_expr_basis.hpp:618
FeExpressionNeighborFunc(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:621
static constexpr std::size_t k_index_end
Definition fe_expr_basis.hpp:619
FeSpace FeSpaceType
Definition fe_expr_basis.hpp:616
constexpr std::size_t computeOrder() const
Definition fe_expr_basis.hpp:642
constexpr bool precompute(const FeValues< Dim > &, const CellsType< Dim > &) const
Definition fe_expr_basis.hpp:672
const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > & m_w
Definition fe_expr_basis.hpp:677
Definition fe_expr_basis.hpp:708
constexpr UpdateFlagsType computeUpdateFlags() const
Definition fe_expr_basis.hpp:735
constexpr std::size_t computeOrder() const
Definition fe_expr_basis.hpp:741
const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > & m_w
Definition fe_expr_basis.hpp:776
static constexpr std::size_t k_index_begin
Definition fe_expr_basis.hpp:715
constexpr bool precompute(const FeValues< Dim > &, const CellsType< Dim > &) const
Definition fe_expr_basis.hpp:771
static constexpr std::size_t k_index_end
Definition fe_expr_basis.hpp:716
decltype(auto) evaluatePoly(const FeValues< Dim > &fe_values, std::size_t j, std::size_t i, std::size_t bi, std::size_t bj) const
Definition fe_expr_basis.hpp:743
FeSpace FeSpaceType
Definition fe_expr_basis.hpp:713
FeExpressionSelfFunc(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:718
static constexpr bool is_leaf
Definition fe_expr_basis.hpp:710
decltype(auto) evaluatePolyCoef(const auto &mapping, const auto &fe_values, std::size_t bi, std::size_t bj) const
Definition fe_expr_basis.hpp:763
constexpr const auto & feSpace() const
Definition fe_expr_basis.hpp:722
static constexpr uint8_t is_bilinear
Definition fe_expr_basis.hpp:711
decltype(auto) evaluate(const FeValues< Dim > &fe_values, std::size_t j, std::size_t i, std::size_t q) const
Definition fe_expr_basis.hpp:725
Definition fe_expr_basis.hpp:331
FeExpressionSymGradFunc(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:341
constexpr const auto & feSpace() const
Definition fe_expr_basis.hpp:345
constexpr std::size_t computeOrder() const
Definition fe_expr_basis.hpp:373
constexpr bool precompute(const FeValues< Dim > &, const CellsType< Dim > &) const
Definition fe_expr_basis.hpp:446
const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > & m_w
Definition fe_expr_basis.hpp:451
static constexpr bool is_leaf
Definition fe_expr_basis.hpp:333
decltype(auto) evaluatePolyCoef(const auto &mapping, const auto &, std::size_t bi, std::size_t bj) const
Definition fe_expr_basis.hpp:427
decltype(auto) evaluate(const FeValues< Dim > &fe_values, std::size_t j, std::size_t i, std::size_t q) const
Definition fe_expr_basis.hpp:348
std::decay_t< decltype(FeSpace{0}.getBasis()[0])> PolynomialType
Definition fe_expr_basis.hpp:336
constexpr UpdateFlagsType computeUpdateFlags() const
Definition fe_expr_basis.hpp:370
static constexpr std::size_t k_index_begin
Definition fe_expr_basis.hpp:338
static constexpr uint8_t is_bilinear
Definition fe_expr_basis.hpp:334
decltype(auto) evaluatePoly(const FeValues< Dim > &, std::size_t j, std::size_t i, std::size_t bi, std::size_t bj) const
Definition fe_expr_basis.hpp:377
FeSpace FeSpaceType
Definition fe_expr_basis.hpp:335
static constexpr std::size_t k_index_end
Definition fe_expr_basis.hpp:339
Definition fe_expr_basis.hpp:480
const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > & m_w
Definition fe_expr_basis.hpp:569
constexpr bool precompute(const FeValues< Dim > &, const CellsType< Dim > &) const
Definition fe_expr_basis.hpp:564
Eigen::Vector< PolynomialType, 1 > evaluatePoly(const FeValues< Dim > &, std::size_t j, std::size_t i, std::size_t bi, std::size_t bj) const
Definition fe_expr_basis.hpp:526
decltype(auto) evaluate(const FeValues< Dim > &fe_values, std::size_t j, std::size_t i, std::size_t q) const
Definition fe_expr_basis.hpp:497
static constexpr bool is_leaf
Definition fe_expr_basis.hpp:482
static constexpr uint8_t is_bilinear
Definition fe_expr_basis.hpp:483
FeSpace FeSpaceType
Definition fe_expr_basis.hpp:484
decltype(auto) evaluatePolyCoef(const auto &mapping, const auto &, std::size_t bi, std::size_t bj) const
Definition fe_expr_basis.hpp:549
std::decay_t< decltype(FeSpace{0}.getBasis()[0])> PolynomialType
Definition fe_expr_basis.hpp:485
static constexpr std::size_t k_index_end
Definition fe_expr_basis.hpp:488
static constexpr std::size_t k_index_begin
Definition fe_expr_basis.hpp:487
constexpr UpdateFlagsType computeUpdateFlags() const
Definition fe_expr_basis.hpp:519
FeExpressionTraceSymGradFunc(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:490
constexpr const auto & feSpace() const
Definition fe_expr_basis.hpp:494
constexpr std::size_t computeOrder() const
Definition fe_expr_basis.hpp:522
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 const auto & getShapeEval() const
Definition fe_values.hpp:103
constexpr const auto & getGradEval() const
Definition fe_values.hpp:104
auto & neighValues()
Definition fe_values.hpp:264
double real_t
Definition fe_values.hpp:96
SymMat< CrossId, ArgType > makeSymMat(const Eigen::MatrixBase< ArgType > &arg)
Build a SymMat expression from a column vector.
Definition eigen.hpp:137
RowMat< RowId, ArgType > makeRowMat(const Eigen::MatrixBase< ArgType > &arg)
Build a RowMat expression from a column vector.
Definition eigen.hpp:243
Definition dof_policy.hpp:45
FeExpressionNeighborFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > neigh(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:686
FeExpressionSymGradFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > symgrad(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:460
FeExpressionTraceSymGradFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > trsymgrad(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:579
std::underlying_type_t< UpdateFlags > UpdateFlagsType
Definition fe_values.hpp:65
FeExpressionTraceSymGradFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > div(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:591
std::vector< std::unique_ptr< CellType< Dim > > > CellsType
Definition fe_expr_base.hpp:44
FeExpressionFunc< IndexBegin, IndexEnd, FeSpace::dim, FeSpace, false > TrialFunction
Definition fe_expr_basis.hpp:162
FeExpressionFunc< IndexBegin, IndexEnd, FeSpace::dim, FeSpace, true > TestFunction
Definition fe_expr_basis.hpp:169
@ UpdateNeighborCell
Definition fe_values.hpp:61
@ UpdateNeighborValues
Definition fe_values.hpp:62
@ UpdateValues
Definition fe_values.hpp:54
@ UpdateGradients
Definition fe_values.hpp:55
@ IsLinearTest
Definition fe_expr_base.hpp:53
@ IsLinearTrial
Definition fe_expr_base.hpp:54
FeExpressionGradFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > grad(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:315
FeExpressionSelfFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > self(const FeExpressionFunc< IndexBegin, IndexEnd, Dim, FeSpace, IsTest > &w)
Definition fe_expr_basis.hpp:785
Definition cell_manager.hpp:38