MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
bounds.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_BOUNDS
13#define MFEM_BOUNDS
14
15#include "../config/config.hpp"
16#include "fespace.hpp"
17
18namespace mfem
19{
20
21/** @name Piecewise linear bounds of bases
22 \brief Piecewise linear bounds of bases can be used to compute bounds on the grid function in each element. The bounds for the bases are constructed based on the following parameters:
23
24 (i) @b nb: number of bases/nodes in 1D (i.e. polynomial order+1),
25
26 (ii) @b b_type: bases type, 0 - Lagrange interpolants on Gauss-Legendre nodes, 1 - Lagrange interpolants on Gauss-Lobatto-Legendre nodes, and
27 2 - Positive/Bernstein bases on uniformly distributed nodes,
28
29 (iii) @b ncp: number of control points used to construct the piecewise linear bounds
30
31 (iv) @b cp_type: control point distribution. 0 - GL + end-points,
32 1 - Chebyshev.
33
34 Note: @b nb and @b b_type are inferred directly from the grid-function.
35
36 If the user does not specify @b ncp and @b cp_type, the minimum value of
37 @b ncp is used that would bound the bases for the @b cp_type. We default
38 to @b cp_type = 0 as it requires fewer number of points to bound the bases. Typically, @b ncp = 2 @b nb is sufficient to get fairly compact bounds, and increasing @b ncp results in tighter bounds.
39
40 Finally, only tensor-product elements are currently supported.
41
42 For more technical details see:
43 Mittal et al., "General Field Evaluation in High-Order Meshes on GPUs" &
44 Dzanic et al., "A method for bounding high-order finite element
45 functions: Applications to mesh validity and bounds-preserving limiters".
46*/
48{
49private:
50 int nb; // #mesh nodes in 1D
51 int ncp; // #control points in 1D
52 int b_type; // bases type: 0 - GL, 1 - GLL, 2 - Bernstein
53 int cp_type; // control points type: 0 - GL+Ends, 1 - Chebyshev
54 bool proj = true; // Use linear projection to compute bounds.
55 real_t tol = 0.0; // offset bounds to avoid round-off errors
56 Vector nodes, weights, control_points;
57 DenseMatrix lbound, ubound; // nb x ncp matrices with bounds of all bases
58 // Some auxillary storage for computing the bounds with Bernstein
59 DenseMatrix basisMatNodes; // Bernstein bases at equispaced nodes
60 DenseMatrix basisMatInt; // Bernstein bases at GLL nodes
61 Vector nodes_int, weights_int; // Integration nodes and weights
62 DenseMatrix basisMatLU; // Used to compute LU factors for Bernstein
63 mutable Array<int> lu_ip;
64
65 // stores min_ncp for nb = 2..12 for Lagrange interpolants on GL nodes
66 // with GL+end points and Chebyshev points as control points
67 static constexpr int min_ncp_gl_x[2][11]= {{3,5,6,8,9,10,11,11,12,13,14},
68 {3,5,8,9,11,12,14,15,17,18,20}
69 };
70
71 // stores min_ncp for nb = 2..12 for Lagrange interpolants on GLL nodes
72 // with GL+end points and Chebyshev points as control points
73 static constexpr int min_ncp_gll_x[2][11]= {{3,5,7,8,9,10,12,13,14,15,16},
74 {3,5,8,10,12,13,15,17,19,21,22}
75 };
76
77 // stores min_ncp for nb = 2..12 for Bernstein bases with GL+end points
78 // and Chebyshev points as control points
79 static constexpr int min_ncp_pos_x[2][11]= {{3,5,7,8,8,9,10,10,11,12,13},
80 {3,5,8,9,11,12,13,13,14,15,16}
81 };
82
83public:
84 // Constructor
85 PLBound(const int nb_i, const int ncp_i, const int b_type_i,
86 const int cp_type_i, const real_t tol_i)
87 {
88 Setup(nb_i, ncp_i, b_type_i, cp_type_i, tol_i);
89 }
90
91 // Constructor
92 PLBound(const FiniteElementSpace *fes,
93 const int ncp_i = -1, const int cp_type_i = 0);
94
95 // Get minimum number of control points needed to bound the given bases
96 int GetMinimumPointsForGivenBases(int nb_i, int b_type_i,
97 int cp_type_i) const;
98
99 // Print information about the bounds
100 void Print(std::ostream &outp = mfem::out) const;
101
102 // Enable (default) or disable linear projection before bounding.
103 // This projection increases the computational cost but results in tighter
104 // bounds.
105 void SetProjectionFlagForBounding(bool proj_) { proj = proj_; }
106
107 /// Compute piecewise linear bounds for the lexicographically-ordered
108 /// coefficients in @a coeff in 1D/2D/3D.
109 void GetNDBounds(const int rdim, const Vector &coeff,
110 Vector &intmin, Vector &intmax) const;
111
112 /// Get number of control points used to compute the bounds.
113 int GetNControlPoints() const { return ncp; }
114private:
115 /// Compute piecewise linear bounds for the lexicographically-ordered
116 /// coefficients in @a coeff in 1D.
117 void Get1DBounds(const Vector &coeff, Vector &intmin, Vector &intmax) const;
118
119 /// Compute piecewise linear bounds for the lexicographically-ordered
120 /// coefficients in @a coeff in 2D.
121 void Get2DBounds(const Vector &coeff, Vector &intmin, Vector &intmax) const;
122
123 /// Compute piecewise linear bounds for the lexicographically-ordered
124 /// coefficients in @a coeff in 3D.
125 void Get3DBounds(const Vector &coeff, Vector &intmin, Vector &intmax) const;
126
127 /// Setup matrix used to compute values at given 1D locations in [0,1]
128 /// for Bernstein bases.
129 void SetupBernsteinBasisMat(DenseMatrix &basisMat, Vector &nodesBern) const;
130
131 void Setup(const int nb_i, const int ncp_i, const int b_type_i,
132 const int cp_type_i, const real_t tol_i);
133};
134
135} // namespace mfem
136
137#endif // MFEM_BOUNDS
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:208
void GetNDBounds(const int rdim, const Vector &coeff, Vector &intmin, Vector &intmax) const
Definition bounds.cpp:631
void Print(std::ostream &outp=mfem::out) const
Definition bounds.cpp:701
PLBound(const int nb_i, const int ncp_i, const int b_type_i, const int cp_type_i, const real_t tol_i)
Definition bounds.hpp:85
int GetNControlPoints() const
Get number of control points used to compute the bounds.
Definition bounds.hpp:113
void SetProjectionFlagForBounding(bool proj_)
Definition bounds.hpp:105
int GetMinimumPointsForGivenBases(int nb_i, int b_type_i, int cp_type_i) const
Definition bounds.cpp:673
Vector data type.
Definition vector.hpp:82
real_t proj(GridFunction &psi, real_t target_volume, real_t tol=1e-12, int max_its=10)
Bregman projection of ρ = sigmoid(ψ) onto the subspace ∫_Ω ρ dx = θ vol(Ω) as follows:
Definition ex37.cpp:72
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition globals.hpp:66
float real_t
Definition config.hpp:46