Line data Source code
1 : // The libMesh Finite Element Library.
2 : // Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 :
4 : // This library is free software; you can redistribute it and/or
5 : // modify it under the terms of the GNU Lesser General Public
6 : // License as published by the Free Software Foundation; either
7 : // version 2.1 of the License, or (at your option) any later version.
8 :
9 : // This library is distributed in the hope that it will be useful,
10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : // Lesser General Public License for more details.
13 :
14 : // You should have received a copy of the GNU Lesser General Public
15 : // License along with this library; if not, write to the Free Software
16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 :
18 :
19 :
20 : // Local includes
21 : #include "libmesh/quadrature_nodal.h"
22 :
23 : #include "libmesh/enum_to_string.h"
24 : #include "libmesh/face_c0polygon.h"
25 : #include "libmesh/quadrature_trap.h"
26 : #include "libmesh/quadrature_simpson.h"
27 :
28 : namespace libMesh
29 : {
30 :
31 1050 : void QNodal::init_2D()
32 : {
33 : #if LIBMESH_DIM > 1
34 :
35 1050 : switch (_type)
36 : {
37 :
38 350 : case QUAD4:
39 : case QUADSHELL4:
40 : case TRI3:
41 : case TRISHELL3:
42 : {
43 450 : QTrap rule(/*dim=*/2, /*ignored*/_order);
44 350 : rule.init(*this);
45 100 : _points.swap (rule.get_points());
46 100 : _weights.swap(rule.get_weights());
47 100 : return;
48 : }
49 :
50 40 : case QUAD8:
51 : case QUADSHELL8:
52 : {
53 : // A rule with 8 points which is exact for linears, and
54 : // naturally produces a lumped approximation to the mass
55 : // matrix. The quadrature points are numbered the same way as
56 : // the reference element nodes.
57 232 : _points =
58 : {
59 : Point(-1,-1), Point(+1,-1), Point(+1,+1), Point(-1,+1),
60 : Point(0.,-1), Point(+1,0.), Point(0.,+1), Point(-1,0.)
61 156 : };
62 :
63 : // The weights for the Quad8 nodal quadrature rule are
64 : // obtained from the following specific steps. Other
65 : // "serendipity" type rules are obtained similarly.
66 : //
67 : // 1.) Due to the symmetry of the bi-unit square domain, we
68 : // first note that there are only two "classes" of node in the
69 : // Quad8: vertices (with associated weight wv) and edges (with
70 : // associated weight we).
71 : //
72 : // 2.) In order for such a nodal quadrature rule to be exact
73 : // for constants, the weights must sum to the area of the
74 : // reference element, and therefore we must have:
75 : // 4*wv + 4*we = 4 --> wv + we = 1
76 : //
77 : // 3.) Due to symmetry (once again), such a rule is then
78 : // automatically exact for the linear polynomials "x" and "y",
79 : // regardless of the values of wv and we.
80 : //
81 : // 4.) We therefore still have two unknowns and one equation.
82 : // Attempting to additionally make the nodal quadrature rule
83 : // exact for the quadratic polynomials "x^2" and "y^2" leads
84 : // to a rule with negative weights, namely:
85 : // wv = -1/3
86 : // we = 4/3
87 : // Note: these are the same values one obtains by integrating
88 : // the corresponding Quad8 Lagrange basis functions over the
89 : // reference element.
90 : //
91 : // Since the weights appear on the diagonal of the nodal
92 : // quadrature rule's approximation to the mass matrix, rules
93 : // with negative weights yield an indefinite mass matrix,
94 : // i.e. one with both positive and negative eigenvalues. Rules
95 : // with negative weights can also produce a negative integral
96 : // approximation to a strictly positive integrand, which may
97 : // be unacceptable in some situations.
98 : //
99 : // 5.) Requiring all positive weights therefore restricts the
100 : // nodal quadrature rule to only be exact for linears. But
101 : // there is still one free parameter remaining, and thus we
102 : // need some other criterion in order to complete the
103 : // description of the rule.
104 : //
105 : // Here, we have decided to choose the quadrature weights in
106 : // such a way that the resulting nodal quadrature mass matrix
107 : // approximation is "proportional" to the true mass matrix's
108 : // diagonal entries for the reference element. We therefore
109 : // pose the following constrained optimization problem:
110 : //
111 : // { min_{wv, we} |diag(M) - C*diag(W)|^2
112 : // (O) {
113 : // { subject to wv + we = 1
114 : //
115 : // where:
116 : // * M is the true mass matrix
117 : // * W is the nodal quadrature approximation to the mass
118 : // matrix. In this particular case:
119 : // diag(W) = [wv,wv,wv,wv,we,we,we,we]
120 : // * C = tr(M) / vol(E) is the ratio between the trace of the
121 : // true mass matrix and the volume of the reference
122 : // element. For all Lagrange finite elements, we have C<1.
123 : //
124 : // 6.) The optimization problem (O) is solved directly by
125 : // substituting the algebraic constraint into the functional
126 : // which is to be minimized, then setting the derivative with
127 : // respect to the remaining parameter equal to zero and
128 : // solving. In the Quad8 and Hex20 cases, there is only one
129 : // free parameter, while in the Prism15 case there are two
130 : // free parameters, so a 2x2 system of linear equations must
131 : // be solved.
132 40 : Real wv = Real(12) / 79;
133 40 : Real we = Real(67) / 79;
134 :
135 156 : _weights = {wv, wv, wv, wv, we, we, we, we};
136 :
137 156 : return;
138 : }
139 :
140 64 : case QUAD16:
141 : {
142 64 : _points.resize(16);
143 64 : _weights.resize(16);
144 :
145 16 : const Real third = Real(1)/3;
146 16 : const Real a = Real(1)/4, b = Real(3)/4; // Simpson 3/8 weights on [-1,1]
147 :
148 : // 1D node coordinates / weights indexed by position along the edge
149 64 : const Real x1d[4] = {-1, -third, third, 1};
150 64 : const Real w1d[4] = { a, b, b, a};
151 :
152 : // Map each Quad16 node to its (ix, iy) position on the 4x4 grid
153 : static const unsigned int ix[16] = {0,3,3,0, 1,2, 3,3, 2,1, 0,0, 1,2,2,1};
154 : static const unsigned int iy[16] = {0,0,3,3, 0,0, 1,2, 3,3, 2,1, 1,1,2,2};
155 :
156 1088 : for (unsigned int n = 0; n < 16; ++n)
157 : {
158 1024 : _points[n] = Point(x1d[ix[n]], x1d[iy[n]]);
159 1280 : _weights[n] = w1d[ix[n]] * w1d[iy[n]];
160 : }
161 16 : return;
162 : }
163 :
164 301 : case QUAD9:
165 : case QUADSHELL9:
166 : case TRI6:
167 : {
168 379 : QSimpson rule(/*dim=*/2, /*ignored*/_order);
169 301 : rule.init(*this);
170 78 : _points.swap (rule.get_points());
171 78 : _weights.swap(rule.get_weights());
172 78 : return;
173 : }
174 :
175 30 : case TRI7:
176 : {
177 : // We can't exactly represent cubics with only seven nodes,
178 : // but with w_i = integral(phi_i) for Lagrange shape functions
179 : // phi_i, we not only get exact integrals of every Lagrange
180 : // shape function, including the cubic bubble, we also get
181 : // exact integrals of the rest of P^3 too.
182 174 : _points =
183 : {
184 : Point(0.,0.), Point(+1,0.), Point(0.,+1), Point(.5,0.),
185 : Point(.5,.5), Point(0.,.5), Point(1/Real(3),1/Real(3))
186 117 : };
187 :
188 30 : Real wv = Real(1)/40;
189 30 : Real we = Real(1)/15;
190 117 : _weights = {wv, wv, wv, we, we, we, Real(9)/40};
191 117 : return;
192 : }
193 :
194 : //---------------------------------------------
195 : // Arbitrary polygon quadrature rules
196 62 : case C0POLYGON:
197 : {
198 : // C0Polygon requires the newer Quadrature API
199 62 : if (!_elem)
200 0 : libmesh_error();
201 :
202 17 : libmesh_assert(_elem->type() == C0POLYGON);
203 :
204 17 : const C0Polygon & poly = *cast_ptr<const C0Polygon *>(_elem);
205 :
206 17 : const unsigned int ns = poly.n_sides();
207 62 : const Real pi_over_ns = libMesh::pi / ns;
208 62 : const Real master_poly_area = ns * 0.25 / tan(pi_over_ns);
209 :
210 62 : const unsigned int nn = poly.n_nodes();
211 62 : const Real weight = master_poly_area / nn;
212 62 : _weights.resize(nn, weight);
213 :
214 62 : _points.resize(poly.n_nodes());
215 393 : for (auto n : make_range(nn))
216 331 : _points[n] = poly.master_point(n);
217 :
218 17 : return;
219 : }
220 :
221 0 : default:
222 0 : libmesh_error_msg("Element type not supported!:" << Utility::enum_to_string(_type));
223 : }
224 : #endif
225 : }
226 :
227 : } // namespace libMesh
|