svMultiPhysics
Loading...
Searching...
No Matches
QuadratureRule.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others.
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef SVMP_FE_QUADRATURE_RULE_H
5#define SVMP_FE_QUADRATURE_RULE_H
6
7/**
8 * @file QuadratureRule.h
9 * @brief Value type for reference-space quadrature rules.
10 * @ingroup FE_Quadrature
11 */
12
13/**
14 * @defgroup FE_Quadrature Quadrature
15 * @ingroup FE
16 * @brief Integration rules on canonical reference cells.
17 *
18 * @details
19 * A QuadratureRule owns ordered reference coordinates and weights for
20 * @f[
21 * \int_{\hat K} f(\hat x)\,d\hat x
22 * \approx \sum_q w_q f(\hat x_q).
23 * @f]
24 * Supported families use these canonical reference cells:
25 *
26 * | Family | Reference cell | Measure |
27 * |----------|-------------------------------------------|-----------|
28 * | Point | @f$(0,0,0)@f$ | @f$1@f$ |
29 * | Line | @f$[-1,1]@f$ | @f$2@f$ |
30 * | Triangle | @f$\{(x,y):x,y\geq0,\ x+y\leq1\}@f$ | @f$1/2@f$ |
31 * | Quad | @f$[-1,1]^2@f$ | @f$4@f$ |
32 * | Tetra | @f$\{(x,y,z):x,y,z\geq0,\ x+y+z\leq1\}@f$ | @f$1/6@f$ |
33 * | Hex | @f$[-1,1]^3@f$ | @f$8@f$ |
34 * | Wedge | unit triangle @f$\times[-1,1]@f$ | @f$1@f$ |
35 *
36 * The family therefore determines both reference dimension and cell measure.
37 * Quadrature points are not required to lie inside the reference cell.
38 * Generating code is responsible for verifying weight normalization and
39 * declared polynomial exactness through analytic moment tests.
40 */
41
42#include "FE/Common/Types.h"
43#include "FE/Math/Vector.h"
44
45#include <cstddef>
46#include <span>
47#include <vector>
48
49namespace svmp::FE::quadrature {
50
51/** @addtogroup FE_Quadrature
52 * @{
53 */
54
55/**
56 * @brief Three-component coordinate used for every reference quadrature point.
57 *
58 * Only the first QuadratureRule::dimension() components are active; remaining
59 * components must be zero.
60 */
62
63/**
64 * @brief Owning value type for quadrature rules on canonical reference cells.
65 *
66 * Construction requires:
67 *
68 * - a supported cell family and non-negative polynomial exactness;
69 * - a vector of points, with at least one element;
70 * - for all points, coordinates must be finite;
71 * - for all points, coordinates beyond the reference dimension of the cell
72 * family must be equal to zero; and
73 * - a vector of finite weights, with as many elements as the points.
74 *
75 * The constructor checks each requirement and throws InvalidArgumentException
76 * when one is violated.
77 *
78 * Points may be duplicate or outside the reference cell, and weights may be
79 * zero or negative. Construction does not verify weight normalization or
80 * polynomial exactness.
81 */
82class QuadratureRule final {
83public:
84 /**
85 * @brief Construct a rule from complete point and weight data.
86 * @param family Reference-cell family; also determines dimension and measure.
87 * @param polynomial_exactness Declared total-degree polynomial exactness.
88 * @param points Ordered reference coordinates.
89 * @param weights Weights paired with @p points.
90 * @throws InvalidArgumentException If a construction requirement is violated.
91 */
92 explicit QuadratureRule(
93 svmp::CellFamily family,
95 std::vector<QuadPoint> points,
96 std::vector<double> weights);
97
98 /** @brief Return the number of point/weight pairs. */
99 std::size_t num_points() const noexcept { return points_.size(); }
100
101 /** @brief Return the declared total-degree polynomial exactness. */
102 int polynomial_exactness() const noexcept { return polynomial_exactness_; }
103
104 /**
105 * @brief Return the reference dimension and active QuadPoint component count.
106 */
107 std::size_t dimension() const;
108
109 /** @brief Return the canonical reference-cell family. */
110 svmp::CellFamily cell_family() const noexcept { return cell_family_; }
111
112 /**
113 * @brief Return point @p i without bounds checking.
114 * @pre @p i is less than num_points().
115 */
116 const QuadPoint& point(std::size_t i) const noexcept { return points_[i]; }
117
118 /**
119 * @brief Return the weight paired with point @p i without bounds checking.
120 * @pre @p i is less than num_points().
121 */
122 double weight(std::size_t i) const noexcept { return weights_[i]; }
123
124 /** @brief Return a read-only view of all points in integration order. */
125 std::span<const QuadPoint> points() const noexcept { return points_; }
126
127 /** @brief Return a read-only view of all weights in point order. */
128 std::span<const double> weights() const noexcept { return weights_; }
129
130 /** @brief Return the reference-cell measure derived from cell_family(). */
131 double reference_cell_measure() const;
132
133private:
134 svmp::CellFamily cell_family_; ///< Canonical reference topology.
135 int polynomial_exactness_; ///< Exactness declared by the generator.
136 std::vector<QuadPoint> points_; ///< Ordered reference coordinates.
137 std::vector<double> weights_; ///< Weights paired with points_.
138};
139
140/** @} */
141
142} // namespace svmp::FE::quadrature
143
144#endif // SVMP_FE_QUADRATURE_RULE_H
Fixed-size vector types for FE computations, backed by Eigen.
Fundamental type definitions for the finite element library.
Owning value type for quadrature rules on canonical reference cells.
Definition QuadratureRule.h:82
std::span< const double > weights() const noexcept
Return a read-only view of all weights in point order.
Definition QuadratureRule.h:128
std::size_t dimension() const
Return the reference dimension and active QuadPoint component count.
Definition QuadratureRule.cpp:66
std::span< const QuadPoint > points() const noexcept
Return a read-only view of all points in integration order.
Definition QuadratureRule.h:125
std::size_t num_points() const noexcept
Return the number of point/weight pairs.
Definition QuadratureRule.h:99
double reference_cell_measure() const
Return the reference-cell measure derived from cell_family().
Definition QuadratureRule.cpp:71
int polynomial_exactness() const noexcept
Return the declared total-degree polynomial exactness.
Definition QuadratureRule.h:102
double weight(std::size_t i) const noexcept
Return the weight paired with point i without bounds checking.
Definition QuadratureRule.h:122
svmp::CellFamily cell_family() const noexcept
Return the canonical reference-cell family.
Definition QuadratureRule.h:110
const QuadPoint & point(std::size_t i) const noexcept
Return point i without bounds checking.
Definition QuadratureRule.h:116
CellFamily
Minimal fallback for svmp::CellFamily when the Mesh library is unavailable.
Definition Types.h:44
math::Vector< double, 3 > QuadPoint
Three-component coordinate used for every reference quadrature point.
Definition QuadratureRule.h:61
Eigen::Matrix< T, static_cast< int >(N), 1 > Vector
Fixed-size column vector for element-level computations.
Definition Vector.h:51