Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
dg_utils.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: Emanuele Caruso <emanuele1.caruso@mail.polimi.it>
22// Author: Francesco Daniele <francesco.daniele@polimi.it>
23// Author: Matteo Caldana <matteo.caldana@polimi.it>
24// Author: Nicola De March <nicola.demarch@polimi.it>
25// Author: Pedro Peixoto <ppeixoto@usp.br>
26// Author: Yeshua Giacalone <yeshua.giacalone@mail.polimi.it>
27
28#ifndef VULPES_ASSEMBLE_DG_UTILS_HPP_
29#define VULPES_ASSEMBLE_DG_UTILS_HPP_
30
31#include <mpi.h>
32
33#include <algorithm>
34#include <array>
35#include <cassert>
36#include <cmath>
37#include <functional>
38#include <iostream>
39#include <limits>
40#include <optional>
41#include <tuple>
42#include <type_traits>
43#include <vector>
44
51#include "vulpes/la/vector.hpp"
55
56namespace vulpes {
57namespace assemble {
58namespace dg {
59
70inline double sqrtNonNegative(double x, double tol = 1e-12) {
71 if (std::isnan(x)) {
72 return x;
73 }
74 if (x < -tol) {
75 pcout << "Warning: square root of negative value " << x << std::endl;
76 }
77 return std::sqrt(std::max(x, 0.0));
78}
79
87inline double computeDGError(double errH1int, double errJump) {
88 return sqrtNonNegative(errH1int * errH1int + errJump * errJump);
89}
90
108template <typename MeshType, typename FeSpaceType, typename ExprType>
110 const MeshType& mesh,
112 const ExprType& expression,
113 std::optional<uint32_t> quad_degree = std::nullopt) {
114 constexpr std::size_t Dim = MeshType::self_dim;
115 constexpr std::size_t max_tabled = Dim == 3
118 const uint32_t degree = quad_degree.value_or(
119 static_cast<uint32_t>(1 + expression.computeOrder()));
120 if (Dim > 1 && degree > max_tabled) {
121 pcout << "Warning: quadrature degree " << degree
122 << " is above the tabled simplex rules" << std::endl;
123 }
125 integrator(mesh, cell_manager, expression, degree);
126 double result = integrator.integrate();
127 if constexpr (MeshType::parallel()) {
128 MPI_Allreduce(
129 MPI_IN_PLACE, &result, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
130 }
131 return result;
132}
133
154template <
155 typename MeshType,
156 typename FeSpaceType,
157 typename DofHandlerType,
158 typename ExprType>
160 const MeshType& mesh,
162 const DofHandlerType& dof_handler,
163 const la::Vector& u_h,
164 const ExprType& u_exact_expr,
165 std::optional<uint32_t> quad_degree = std::nullopt) {
166 constexpr std::size_t Dim = MeshType::self_dim;
167 // Create the numerical solution as an FE expression
169 u_h, cell_manager.getFeSpace(), dof_handler);
170
171 // Form the difference expression: (u_h - u_exact)
172 auto diff_expr = u_h_expr - u_exact_expr;
173
174 // Form the squared difference: (u_h - u_exact)^2
175 auto diff_squared = diff_expr * diff_expr;
176
177 // Integrate the squared difference over the domain
178 const std::size_t p = cell_manager.getFeSpace().order();
179 double l2_error_squared = integrateFeExpression(
180 mesh, cell_manager, diff_squared,
181 quad_degree.value_or(
182 std::max(1 + diff_squared.computeOrder(), 2 * p + 7)));
183
184 // Return the L2 error (square root of the integral)
185 return sqrtNonNegative(l2_error_squared);
186}
187
206template <
207 typename MeshType,
208 typename FeSpaceType,
209 typename DofHandlerType,
210 typename ExprType>
212 const MeshType& mesh,
214 const DofHandlerType& dof_handler,
215 const la::Vector& u_h,
216 const ExprType& grad_u_exact_expr,
217 std::optional<uint32_t> quad_degree = std::nullopt) {
218 constexpr std::size_t Dim = MeshType::self_dim;
219
221 u_h, cell_manager.getFeSpace(), dof_handler);
222
223 auto diff_expr = grad_uh_expr - grad_u_exact_expr;
224 auto diff_squared = fe::inner(diff_expr, diff_expr);
225
226 const std::size_t p = cell_manager.getFeSpace().order();
227 double h1_semi_error_squared = integrateFeExpression(
228 mesh, cell_manager, diff_squared,
229 quad_degree.value_or(
230 std::max(1 + diff_squared.computeOrder(), 2 * p + 7)));
231
232 return sqrtNonNegative(h1_semi_error_squared);
233}
234
245template <typename MeshType>
247 const dofs::DofHandler<MeshType>& dof_handler,
248 const la::Vector& u_h,
249 const la::SparseMatrix& matrix) {
250 la::Vector temp(dof_handler, u_h.getBlockSize());
251 matrix.vmult(u_h, temp); // temp = matrix * u_h
252 return sqrtNonNegative(la::dot(u_h, temp));
253}
254
264template <std::size_t Dim>
265auto createPenaltyExpression(std::size_t order, double gamma) {
267 [order, gamma](
268 const fe::FeValues<Dim>& fe_values, const fe::CellsType<Dim>& cells) {
269 const auto& cell = *cells[fe_values.getCellId()];
270 const double penalty = gamma * order * order;
271 const double p_this = penalty / cell.diameter();
272 if (fe_values.hasFaceNeigh()) {
273 assert(&fe_values.neighValues());
274 const auto neigh_cell_id = fe_values.neighValues().getCellId();
275 const auto& neigh_cell = *cells[neigh_cell_id];
276 const double p_neigh = penalty / neigh_cell.diameter();
277 return std::max(p_this, p_neigh);
278 } else {
279 return p_this;
280 }
281 });
282}
283
288template <std::size_t Dim, typename CellType>
289double faceMeasureForPenalty(const CellType& cell, std::size_t face_id) {
290 if constexpr (Dim == 3) {
291 assert(cell.faceMeasures().size() > 0);
292 return cell.faceMeasures()[face_id];
293 } else {
294 return cell.faceDiam()[face_id];
295 }
296}
297
309template <std::size_t Dim>
310auto createPenaltyExpressionKb(std::size_t order, double gamma) {
312 [order, gamma](
313 const fe::FeValues<Dim>& fe_values, const fe::CellsType<Dim>& cells) {
314 const auto& cell = *cells[fe_values.getCellId()];
315 const auto face_id = fe_values.getFaceId();
316 const double penalty = gamma * order * order;
317 const double Cinv = cell.measure() / cell.faceKb()[face_id];
318 const double facet_measure = faceMeasureForPenalty<Dim>(cell, face_id);
319 const double p_this = penalty * Cinv * (facet_measure / cell.measure());
320 if (fe_values.hasFaceNeigh()) {
321 assert(&fe_values.neighValues());
322 const auto neigh_cell_id = fe_values.neighValues().getCellId();
323 const auto& neigh_cell = *cells[neigh_cell_id];
324 const auto neigh_face_id = fe_values.neighValues().getFaceId();
325 const double Cinv_neigh =
326 neigh_cell.measure() / neigh_cell.faceKb()[neigh_face_id];
327 const double p_neigh =
328 penalty * Cinv_neigh * (facet_measure / neigh_cell.measure());
329 return std::max(p_this, p_neigh);
330 } else {
331 return p_this;
332 }
333 });
334}
335
350template <std::size_t Dim>
351auto createPenaltyExpressionHarmonic(std::size_t order, double gamma) {
353 [order, gamma](
354 const fe::FeValues<Dim>& fe_values, const fe::CellsType<Dim>& cells) {
355 const auto& cell = *cells[fe_values.getCellId()];
356 const auto face_id = fe_values.getFaceId();
357 const double facet_measure = faceMeasureForPenalty<Dim>(cell, face_id);
358 const double penalty = gamma * order * order;
359 const double Cinv = cell.measure() / cell.faceKb()[face_id];
360 const double p_this = penalty * Cinv * (facet_measure / cell.measure());
361
362 if (fe_values.hasFaceNeigh()) {
363 const auto neigh_cell_id = fe_values.neighValues().getCellId();
364 const auto& neigh_cell = *cells[neigh_cell_id];
365 const auto neigh_face_id = fe_values.neighValues().getFaceId();
366 const double Cinv_neigh =
367 neigh_cell.measure() / neigh_cell.faceKb()[neigh_face_id];
368 const double p_neigh =
369 penalty * Cinv_neigh * (facet_measure / neigh_cell.measure());
370 // Media armonica tra p_this e p_neigh
371 return 2.0 * p_this * p_neigh / (p_this + p_neigh);
372 } else {
373 return p_this;
374 }
375 });
376}
377
384template <std::size_t Dim, typename VelocityFunc>
386 : public fe::FeExpressionBase<
387 Dim,
388 FeExpressionUpwindFromFunctionWrapper<Dim, VelocityFunc>> {
389 public:
390 static constexpr bool is_leaf = true;
391 static constexpr uint8_t is_bilinear = fe::IsNothing;
392
394 const VelocityFunc& velocity_func)
395 : m_velocity_func(velocity_func) {}
404
405 template <std::size_t I = 0, std::size_t J = 0>
406 decltype(auto) evaluate(
407 const fe::FeValues<Dim>&, std::size_t, std::size_t, std::size_t q) const {
408 return m_evals[q];
409 }
410
414 constexpr std::size_t computeOrder() const { return 0; }
415
416 constexpr bool precompute(
417 const fe::FeValues<Dim>& fe_values, const fe::CellsType<Dim>&) const {
418 const Eigen::Index nqpts = fe_values.weights().size();
419 assert(fe_values.qpts().cols() == nqpts);
420 m_evals.resize(nqpts);
421 const auto& normal = fe_values.getFaceNormal();
422 for (Eigen::Index q = 0; q < nqpts; ++q) {
423 const auto vel = m_velocity_func(fe_values.qpts().col(q));
424 const double vel_dot_n = vel.dot(normal);
425 m_evals[q] = 0.5 * (std::abs(vel_dot_n) + vel_dot_n);
426 }
427 return true;
428 }
429
430 protected:
431 const VelocityFunc m_velocity_func;
432 mutable std::vector<double> m_evals;
433};
434
444template <std::size_t Dim, typename VelocityFunc>
445auto createUpwindFlux(VelocityFunc velocity_func) {
447 velocity_func);
448}
449
461template <typename MeshType>
463 const dofs::DofHandler<MeshType>& dof_handler,
464 const la::Vector& u_h,
465 const la::Vector& u_exact,
466 const la::SparseMatrix& matrix) {
467 // Compute the residual: error_u = u_exact - u_h
468 la::Vector error_u(dof_handler, u_h.getBlockSize());
469 error_u.add(-1.0, u_h);
470 error_u.add(1.0, u_exact);
471 error_u.compress();
472
473 // Compute the error norm using the provided matrix
474 la::Vector temp(dof_handler, u_h.getBlockSize());
475 matrix.vmult(error_u, temp); // temp = matrix * error_u
476 return sqrtNonNegative(la::dot(error_u, temp));
477}
478
479// ============================================================================
480// Utilities for Handling Null Space in Periodic/Neumann Problems
481// ============================================================================
482
492inline double computeAverage(
493 const la::Vector& u, const la::Vector& rhs_const, double domain_measure) {
494 double numerator = la::dot(u, rhs_const);
495 return numerator / domain_measure;
496}
497
509template <typename MeshType>
511 const dofs::DofHandler<MeshType>& dof_handler,
512 double constant_value,
513 const la::SparseMatrix& mass_matrix,
514 const la::Vector& rhs_const) {
515 la::Vector scaled_rhs(rhs_const);
516 scaled_rhs.scale(constant_value);
517
518 la::Vector c_proj(dof_handler);
520 solver.setOperators(mass_matrix);
521 solver.solve(scaled_rhs, c_proj);
522
523 return c_proj;
524}
525
539template <typename MeshType>
541 const dofs::DofHandler<MeshType>& dof_handler,
542 la::Vector& u,
543 const la::Vector& u_reference,
544 const la::SparseMatrix& mass_matrix,
545 const la::Vector& rhs_const,
546 double domain_measure) {
547 double avg_u = computeAverage(u, rhs_const, domain_measure);
548 double avg_reference = computeAverage(u_reference, rhs_const, domain_measure);
549
550 double shift_physical = avg_reference - avg_u;
551
553 dof_handler, shift_physical, mass_matrix, rhs_const);
554
555 u.add(1.0, c_proj);
556 u.compress();
557
558 return shift_physical;
559}
560
561// ============================================================================
562// L2 Projection Helpers
563//
564// These helpers assemble the projection RHS and solve the L2 projection system
565// either for a scalar field, for a scalar component extracted from a blocked
566// mass matrix, or for a blocked vector subset.
567// ============================================================================
568
569template <
570 typename MeshType,
571 typename CellManagerType,
572 typename DofHandlerType,
573 typename FeSpaceType,
574 typename Expression>
591 const MeshType& mesh,
592 CellManagerType& cell_manager,
593 const DofHandlerType& dof_handler,
594 const FeSpaceType& fe_space,
595 const Expression& expr,
596 const la::SparseMatrix& mass_scalar) {
597 namespace fe = vulpes::fe;
598
599 fe::TestFunction v(fe_space);
600 auto wf_projection = expr * v;
601
602 assemble::WeakFormIntegratorSimplexify int_smplx_projection(
603 mesh, cell_manager, std::tuple(&wf_projection), std::tuple());
604
605 la::Vector rhs(dof_handler);
606 const std::size_t n_cells = static_cast<std::size_t>(mesh.numCells());
607 for (std::size_t cell_id = 0; cell_id < n_cells; ++cell_id) {
608 int_smplx_projection.integrate(cell_id);
609 rhs.insertValues(
610 int_smplx_projection.getIntegral(&wf_projection),
611 dof_handler.getCellToDof()[cell_id]);
612 }
613 rhs.compress();
614
615 la::Vector projected(dof_handler);
617 solver.setOperators(mass_scalar);
618 solver.solve(rhs, projected);
619 return projected;
620}
621
622template <
623 typename MeshType,
624 typename CellManagerType,
625 typename DofHandlerType,
626 typename FeSpaceType,
627 typename Expression>
650 const MeshType& mesh,
651 CellManagerType& cell_manager,
652 const DofHandlerType& dof_handler,
653 const FeSpaceType& fe_space,
654 const Expression& expr,
655 const la::SparseMatrix& mass_blocked,
656 std::size_t component) {
657 la::SparseMatrix mass_scalar(dof_handler, la::SparseMatrix::Plain, 1);
658 la::extractDiagonalBlockComponent(mass_blocked, component, mass_scalar);
660 mesh, cell_manager, dof_handler, fe_space, expr, mass_scalar);
661}
662
663template <
664 std::size_t VecSize,
665 std::size_t NFields,
666 typename MeshType,
667 typename CellManagerType,
668 typename DofHandlerType,
669 typename FeSpaceType,
670 typename Expression>
693 const MeshType& mesh,
694 CellManagerType& cell_manager,
695 const DofHandlerType& dof_handler,
696 const FeSpaceType& fe_space,
697 const Expression& expr,
698 std::size_t component_offset,
699 const la::SparseMatrix& mass_blocked) {
700 namespace fe = vulpes::fe;
701
702 assert(component_offset + VecSize <= NFields);
703
705 auto wf_projection = fe::inner(expr, v);
706
707 assemble::WeakFormIntegratorSimplexify int_smplx_projection(
708 mesh, cell_manager, std::tuple(&wf_projection), std::tuple());
709
710 la::Vector rhs(dof_handler, NFields);
711 const auto& cell_to_dof = dof_handler.getCellToDof();
712 const Eigen::Index ndof_comp = fe_space.getBasis().size();
713 const std::size_t n_cells = static_cast<std::size_t>(mesh.numCells());
714
715 std::array<PetscScalar, NFields> block_values{};
716 for (std::size_t cell_id = 0; cell_id < n_cells; ++cell_id) {
717 int_smplx_projection.integrate(cell_id);
718 const auto local = int_smplx_projection.getIntegral(&wf_projection);
719
720 for (Eigen::Index i = 0; i < ndof_comp; ++i) {
721 block_values.fill(0.0);
722 for (std::size_t c = 0; c < VecSize; ++c) {
723 block_values[component_offset + c] = local(
724 i * static_cast<Eigen::Index>(VecSize) +
725 static_cast<Eigen::Index>(c),
726 0);
727 }
728 const PetscInt block_index = cell_to_dof[cell_id][i];
729 rhs.insertValuesBlocked(block_values.data(), &block_index, 1, ADD_VALUES);
730 }
731 }
732 rhs.compress();
733
734 la::Vector projected(dof_handler, NFields);
736 solver.setOperators(mass_blocked);
737 solver.solve(rhs, projected);
738 return projected;
739}
740
741} // namespace dg
742} // namespace assemble
743} // namespace vulpes
744
745#endif // VULPES_ASSEMBLE_DG_UTILS_HPP_
Manages geometrical information about the cell and its mapping to the reference element.
Definition cell_manager.hpp:62
const auto & getFeSpace() const
Get the finite element space associated to this cell manager.
Definition cell_manager.hpp:107
Specialized integrator for scalar expressions using simplification.
Definition integrator_simplexify.hpp:735
double integrate()
Integrate the scalar expression over the entire domain.
Definition integrator_simplexify.hpp:765
auto getIntegral(auto wf_ptr, index_t loc_neigh_id=-1) const
Get the integral (matrix or vector) for the current cell.
Definition integrator_base.hpp:494
Integrator that simplexifies cells and integrates weak forms on them.
Definition integrator_simplexify.hpp:78
void integrate(index_t cell_id) override
Perform integration for a single cell.
Definition integrator_simplexify.hpp:336
Q-point based upwind flux expression built from a velocity callable.
Definition dg_utils.hpp:388
FeExpressionUpwindFromFunctionWrapper(const FeExpressionUpwindFromFunctionWrapper &)=delete
FeExpressionUpwindFromFunctionWrapper & operator=(FeExpressionUpwindFromFunctionWrapper &&)=delete
constexpr std::size_t computeOrder() const
Definition dg_utils.hpp:414
constexpr fe::UpdateFlagsType computeUpdateFlags() const
Definition dg_utils.hpp:411
std::vector< double > m_evals
Definition dg_utils.hpp:432
static constexpr bool is_leaf
Definition dg_utils.hpp:390
FeExpressionUpwindFromFunctionWrapper(FeExpressionUpwindFromFunctionWrapper &&)=delete
constexpr FeExpressionUpwindFromFunctionWrapper(const VelocityFunc &velocity_func)
Definition dg_utils.hpp:393
decltype(auto) evaluate(const fe::FeValues< Dim > &, std::size_t, std::size_t, std::size_t q) const
Definition dg_utils.hpp:406
const VelocityFunc m_velocity_func
Definition dg_utils.hpp:431
FeExpressionUpwindFromFunctionWrapper & operator=(const FeExpressionUpwindFromFunctionWrapper &)=delete
constexpr bool precompute(const fe::FeValues< Dim > &fe_values, const fe::CellsType< Dim > &) const
Definition dg_utils.hpp:416
static constexpr uint8_t is_bilinear
Definition dg_utils.hpp:391
Compute and distribute the DoFs and sparsity pattern associated with a mesh and a certain finite elem...
Definition dof_handler.hpp:72
Class that wraps the projected of a given vector of coefficients on the FE space.
Definition fe_expr_func.hpp:664
Base class for Finite Element Expressions.
Definition fe_expr_base.hpp:210
Class that wraps a function which is cell constant and need the evaluation of neighbours (e....
Definition fe_expr_func.hpp:274
Physical gradient of a DG field given its DOF coefficient vector.
Definition fe_expr_func.hpp:809
This class works as a cache table for computing efficiently the value of the basis function and its d...
Definition fe_values.hpp:94
index_t getFaceId() const
Definition fe_values.hpp:154
constexpr const auto & qpts() const
Definition fe_values.hpp:107
constexpr const auto & weights() const
Definition fe_values.hpp:105
index_t getCellId() const
Definition fe_values.hpp:143
constexpr bool hasFaceNeigh() const
Definition fe_values.hpp:141
auto & neighValues()
Definition fe_values.hpp:264
constexpr const Eigen::Vector< real_t, Dim > & getFaceNormal() const
Definition fe_values.hpp:135
A linear solver class wrapping PETSc KSP solvers.
Definition linear_solver.hpp:47
@ PrecondOnly
Definition linear_solver.hpp:57
@ LU
Definition linear_solver.hpp:71
void solve(const Vector &b, Vector &x)
Solve the linear system Ax = b.
Definition linear_solver.cpp:231
void setOperators(const SparseMatrix &A)
Set the system matrix.
Definition linear_solver.cpp:201
Definition sparse_matrix.hpp:52
@ Plain
Definition sparse_matrix.hpp:56
void vmult(const Vector &in, Vector &out) const
Definition sparse_matrix.cpp:371
A wrapper around PETSc Vec for distributed vectors.
Definition vector.hpp:54
void insertValues(const PetscScalar *values, const PetscInt *indices, PetscInt n_values, InsertMode mode=ADD_VALUES)
Insert values into the vector at specified indices.
Definition vector.cpp:108
void add(const Vector &x)
Add a vector in place (this += x).
Definition vector.hpp:281
void insertValuesBlocked(const PetscScalar *values, const PetscInt *indices, PetscInt n_values, InsertMode mode=ADD_VALUES)
Insert blocked values into the vector at specified indices.
Definition vector.cpp:117
PetscInt getBlockSize() const
Get the block size of the vector.
Definition vector.cpp:270
void compress()
Compress the vector (do intracommunication).
Definition vector.cpp:49
void scale(double value)
Scale the vector by a constant.
Definition vector.cpp:284
Definition dg_utils.hpp:58
double sqrtNonNegative(double x, double tol=1e-12)
Square root of a quantity that is non-negative in exact arithmetic (squared norms,...
Definition dg_utils.hpp:70
double computeAverage(const la::Vector &u, const la::Vector &rhs_const, double domain_measure)
Compute the spatial average of a function in modal/DG space.
Definition dg_utils.hpp:492
double computeJumpError(const dofs::DofHandler< MeshType > &dof_handler, const la::Vector &u_h, const la::SparseMatrix &matrix)
Compute the total Jump error that is: sqrt(u_h^T matrix u_h). This is used only when the provided pro...
Definition dg_utils.hpp:246
double integrateFeExpression(const MeshType &mesh, assemble::CellManager< MeshType, FeSpaceType > &cell_manager, const ExprType &expression, std::optional< uint32_t > quad_degree=std::nullopt)
Integrate a scalar finite element expression over the entire domain.
Definition dg_utils.hpp:109
la::Vector l2ProjectExpressionBlockedSubset(const MeshType &mesh, CellManagerType &cell_manager, const DofHandlerType &dof_handler, const FeSpaceType &fe_space, const Expression &expr, std::size_t component_offset, const la::SparseMatrix &mass_blocked)
L2-project a vector expression into a subset of components of a blocked vector.
Definition dg_utils.hpp:692
double computeL2Error(const MeshType &mesh, assemble::CellManager< MeshType, FeSpaceType > &cell_manager, const DofHandlerType &dof_handler, const la::Vector &u_h, const ExprType &u_exact_expr, std::optional< uint32_t > quad_degree=std::nullopt)
Compute the L2 error integral between a numerical solution and an exact expression.
Definition dg_utils.hpp:159
auto createPenaltyExpression(std::size_t order, double gamma)
Create a penalty expression for DG methods.
Definition dg_utils.hpp:265
double faceMeasureForPenalty(const CellType &cell, std::size_t face_id)
Measure |F| of a face of a cell, as used by the Kb penalties: the face diameter in 2D (equal to its l...
Definition dg_utils.hpp:289
double forceEqualMean(const dofs::DofHandler< MeshType > &dof_handler, la::Vector &u, const la::Vector &u_reference, const la::SparseMatrix &mass_matrix, const la::Vector &rhs_const, double domain_measure)
Adjust a solution to match the average of a reference solution.
Definition dg_utils.hpp:540
auto createPenaltyExpressionHarmonic(std::size_t order, double gamma)
Create a penalty expression for DG methods using the harmonic mean between the two cells.
Definition dg_utils.hpp:351
la::Vector l2ProjectExpressionScalar(const MeshType &mesh, CellManagerType &cell_manager, const DofHandlerType &dof_handler, const FeSpaceType &fe_space, const Expression &expr, const la::SparseMatrix &mass_scalar)
L2-project a scalar expression using a precomputed scalar mass matrix.
Definition dg_utils.hpp:590
auto createPenaltyExpressionKb(std::size_t order, double gamma)
Create a penalty expression for DG methods using the face's Kb.
Definition dg_utils.hpp:310
double computeError(const dofs::DofHandler< MeshType > &dof_handler, const la::Vector &u_h, const la::Vector &u_exact, const la::SparseMatrix &matrix)
Compute the error between a discrete solution and an exact one.
Definition dg_utils.hpp:462
double computeDGError(double errH1int, double errJump)
compute the total DG error by combining the H1 semi-norm error and the jump error.
Definition dg_utils.hpp:87
la::Vector projectConstantOntoModalSpace(const dofs::DofHandler< MeshType > &dof_handler, double constant_value, const la::SparseMatrix &mass_matrix, const la::Vector &rhs_const)
Project a constant value onto modal DG space using L2 projection.
Definition dg_utils.hpp:510
auto createUpwindFlux(VelocityFunc velocity_func)
Create an upwind flux expression from a velocity callable.
Definition dg_utils.hpp:445
double computeH1SemiError(const MeshType &mesh, assemble::CellManager< MeshType, FeSpaceType > &cell_manager, const DofHandlerType &dof_handler, const la::Vector &u_h, const ExprType &grad_u_exact_expr, std::optional< uint32_t > quad_degree=std::nullopt)
Compute the H1 semi-norm error integral between a numerical solution and an exact gradient.
Definition dg_utils.hpp:211
Definition cell_manager.hpp:39
Definition dof_policy.hpp:45
std::underlying_type_t< UpdateFlags > UpdateFlagsType
Definition fe_values.hpp:65
std::vector< std::unique_ptr< CellType< Dim > > > CellsType
Definition fe_expr_base.hpp:44
FeExpressionFunc< IndexBegin, IndexEnd, FeSpace::dim, FeSpace, true > TestFunction
Definition fe_expr_basis.hpp:169
@ UpdateNormals
Definition fe_values.hpp:59
@ UpdateQuadraturePts
Definition fe_values.hpp:58
@ IsNothing
Definition fe_expr_base.hpp:52
FeExpressionInner< Dim, FeExpressionU, FeExpressionV > inner(const FeExpressionBase< Dim, FeExpressionU > &u, const FeExpressionBase< Dim, FeExpressionV > &v)
Definition fe_expr_op.hpp:224
double dot(const Vector &a, const Vector &b)
Definition vector.cpp:368
void extractDiagonalBlockComponent(const SparseMatrix &blocked_mat, std::size_t component, SparseMatrix &scalar_mat, double zero_tol=0.0)
Extract one scalar diagonal component from a blocked matrix.
Definition vector_block_utils.hpp:192
static constexpr std::size_t num_triangle_tabled_rules
Number of precomputed quadrature rules for triangles.
Definition simplex.hpp:168
static constexpr std::size_t num_tetrahedron_tabled_rules
Number of precomputed quadrature rules for tetrahedra.
Definition simplex.hpp:184
Definition cell_manager.hpp:38
vulpes::utils::pcout_t & pcout
Definition pcout.hpp:160