pyrucast 0.2.1

Finite-element library in Rust, inspired by cast3m, exposed to Python
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
//! Quadrature rules on the reference element.
//!
//! A [`QuadratureRule`] returns a list of `(ξ_g, w_g)` pairs — reference
//! coordinates and weights — over the reference element of a given
//! [`ElementType`]. It is the **numerical** counterpart of an
//! [`crate::containers::finite_element_space::Interpolation`]: the points at which shape
//! functions are sampled when integrating.
//!
//! The reference frames are those documented on each `ElementType`
//! variant (see [`crate::atoms::element_type`]). The weights are calibrated so
//! that the sum equals the measure of the reference domain (i.e., 2 for
//! SEG2, 1/2 for TRI3, 4 for QUA4, 1/6 for TET4, 8 for HEX8).
//!
//! # Example
//!
//! ```
//! use pyrucast::atoms::ElementType;
//! use pyrucast::containers::finite_element_space::QuadratureRule;
//!
//! let (xi, w) = QuadratureRule::Gauss.points(ElementType::QUA4).unwrap();
//! assert_eq!(w.len(), 4);          // 2×2 Gauss-Legendre on [-1,1]²
//! let s: f64 = w.iter().sum();
//! assert!((s - 4.0).abs() < 1e-12);  // area of the reference square
//! assert_eq!(xi.len(), 4 * 2);       // n_g × ref_dim, flat
//! ```

use crate::atoms::ElementType;
use crate::error::{PyrucastError, Result};
use serde::{Deserialize, Serialize};
use std::fmt;

/// Supported quadrature rules.
///
/// The current variant (`Gauss`) selects, for each `ElementType`, the
/// **standard rule that integrates the Lagrange-1 mass matrix exactly**
/// on a straight reference element:
///
/// | ElementType | Rule | n_g |
/// |---|---|---|
/// | SEG2 | Gauss-Legendre on `[-1, +1]` | 2 |
/// | TRI3 | Hammer mid-edge on the unit simplex | 3 |
/// | QUA4 | 2×2 Gauss-Legendre tensor product | 4 |
/// | TET4 | Hammer 4-point on the unit simplex (exact for degree 2) | 4 |
/// | HEX8 | 2×2×2 Gauss-Legendre tensor product | 8 |
///
/// `POI1` has no reference frame and is rejected.
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
pub enum QuadratureRule {
    /// Standard Gauss rule, picked per element type as documented above.
    Gauss,
    /// **Reduced** integration: a single point at the element centroid (weight
    /// = the reference measure). Exact for constants only; used for
    /// selective/reduced integration — e.g. the shear term of a Timoshenko
    /// beam, to avoid shear locking.
    Reduced,
}

impl QuadratureRule {
    /// Short name.
    pub fn name(self) -> &'static str {
        match self {
            Self::Gauss => "GAUSS",
            Self::Reduced => "REDUCED",
        }
    }

    /// Parse from a short name (case-insensitive).
    pub fn from_name(s: &str) -> Option<Self> {
        match s.to_ascii_uppercase().as_str() {
            "GAUSS" => Some(Self::Gauss),
            "REDUCED" => Some(Self::Reduced),
            _ => None,
        }
    }

    /// Whether this rule is defined for `element_type`.
    pub fn is_compatible_with(self, element_type: ElementType) -> bool {
        !matches!(element_type, ElementType::POI1)
    }

    /// Number of integration points for this rule on `element_type`.
    pub fn point_count(self, element_type: ElementType) -> Result<usize> {
        self.check_compat(element_type)?;
        Ok(match (self, element_type) {
            (Self::Gauss, ElementType::SEG2) => 2,
            (Self::Gauss, ElementType::TRI3) => 3,
            (Self::Gauss, ElementType::QUA4) => 4,
            (Self::Gauss, ElementType::TET4) => 4,
            (Self::Gauss, ElementType::PYRA5) => 8,
            (Self::Gauss, ElementType::PENTA6) => 6,
            (Self::Gauss, ElementType::HEX8) => 8,
            (Self::Gauss, ElementType::SEG3) => 3,
            (Self::Gauss, ElementType::TRI6) => 6,
            (Self::Gauss, ElementType::QUA8 | ElementType::QUA9) => 9,
            (Self::Gauss, ElementType::TET10) => 11,
            (Self::Gauss, ElementType::PENTA15) => 18,
            (Self::Gauss, ElementType::HEX20 | ElementType::HEX27) => 27,
            (Self::Reduced, _) => 1,
            (_, ElementType::POI1) => unreachable!(),
        })
    }

    /// Reference points and weights of the rule.
    ///
    /// Returns `(xi, w)`:
    /// - `xi` is a flat row-major buffer of length `n_g × ref_dim`,
    ///   with `xi[g * ref_dim .. (g+1) * ref_dim]` the coordinates of
    ///   the `g`-th integration point;
    /// - `w` has length `n_g`.
    pub fn points(self, element_type: ElementType) -> Result<(Vec<f64>, Vec<f64>)> {
        self.check_compat(element_type)?;
        Ok(match (self, element_type) {
            (Self::Gauss, ElementType::SEG2) => {
                let a = 1.0 / 3.0_f64.sqrt();
                (vec![-a, a], vec![1.0, 1.0])
            }
            (Self::Gauss, ElementType::TRI3) => (
                vec![
                    0.5, 0.0, //
                    0.5, 0.5, //
                    0.0, 0.5,
                ],
                vec![1.0 / 6.0; 3],
            ),
            (Self::Gauss, ElementType::QUA4) => {
                let a = 1.0 / 3.0_f64.sqrt();
                (
                    vec![
                        -a, -a, //
                        a, -a, //
                        a, a, //
                        -a, a,
                    ],
                    vec![1.0; 4],
                )
            }
            (Self::Gauss, ElementType::TET4) => {
                let alpha = (5.0 - 5.0_f64.sqrt()) / 20.0;
                let beta = (5.0 + 3.0 * 5.0_f64.sqrt()) / 20.0;
                (
                    vec![
                        alpha, alpha, alpha, //
                        beta, alpha, alpha, //
                        alpha, beta, alpha, //
                        alpha, alpha, beta,
                    ],
                    vec![1.0 / 24.0; 4],
                )
            }
            (Self::Gauss, ElementType::PYRA5) => {
                // A pyramid is not a product of simplices, so it gets a
                // **conical** product rule: 2 × 2 Gauss–Legendre across the
                // square cross-section, times a 2-point Gauss–Jacobi rule in
                // `ζ`.
                //
                // The Jacobi weight is what makes it work. Writing a point as
                // `ξ = a(1-ζ)`, `η = b(1-ζ)` with `a, b ∈ [-1, 1]`, the change
                // of variables brings out `dξ dη = (1-ζ)² da db` — exactly the
                // cross-section shrinking toward the apex. Integrating the
                // `ζ` direction against that `(1-ζ)²` is a Gauss–Jacobi rule
                // with `α = 2`, whose two nodes are the roots of
                // `z² - (2/3) z + 1/15`, namely `1/3 ∓ √10/15`.
                //
                // The weights then sum to `2 × 2 × 1/3 = 4/3`, the volume of
                // the reference pyramid — the check the test below makes.
                let a = 1.0 / 3.0_f64.sqrt();
                let spread = 10.0_f64.sqrt() / 15.0;
                let (z0, z1) = (1.0 / 3.0 - spread, 1.0 / 3.0 + spread);
                // From the first two moments of `(1-z)²` on `[0, 1]`:
                // `w0 + w1 = 1/3` and `w0 z0 + w1 z1 = 1/12`.
                let w1 = (1.0 / 12.0 - z0 / 3.0) / (z1 - z0);
                let w0 = 1.0 / 3.0 - w1;
                let mut xi = Vec::with_capacity(8 * 3);
                let mut w = Vec::with_capacity(8);
                for &sa in &[-a, a] {
                    for &sb in &[-a, a] {
                        for &(z, wz) in &[(z0, w0), (z1, w1)] {
                            xi.push(sa * (1.0 - z));
                            xi.push(sb * (1.0 - z));
                            xi.push(z);
                            w.push(wz);
                        }
                    }
                }
                (xi, w)
            }
            (Self::Gauss, ElementType::PENTA6) => {
                // Tensor product of the 3-point TRI3 rule (weights 1/6) with
                // the 2-point Gauss rule mapped to ζ ∈ [0, 1] (weights 1/2).
                let g = 0.5 / 3.0_f64.sqrt();
                let tri = [(0.5, 0.0), (0.5, 0.5), (0.0, 0.5)];
                let zeta = [0.5 - g, 0.5 + g];
                let mut xi = Vec::with_capacity(6 * 3);
                let mut w = Vec::with_capacity(6);
                for &(a, b) in &tri {
                    for &z in &zeta {
                        xi.push(a);
                        xi.push(b);
                        xi.push(z);
                        w.push((1.0 / 6.0) * 0.5);
                    }
                }
                (xi, w)
            }
            (Self::Gauss, ElementType::HEX8) => {
                let a = 1.0 / 3.0_f64.sqrt();
                let mut xi = Vec::with_capacity(8 * 3);
                for &z in &[-a, a] {
                    for &y in &[-a, a] {
                        for &x in &[-a, a] {
                            xi.push(x);
                            xi.push(y);
                            xi.push(z);
                        }
                    }
                }
                // The bottom face is traversed in row-major (x then y) so the
                // resulting order is not strictly CCW within a face. That is
                // fine: the rule is symmetric and the order is opaque to
                // callers, who only care about (xi_g, w_g) as a set.
                (xi, vec![1.0; 8])
            }
            // ── Quadratic (Lagrange-2) rules ────────────────────────────────
            (Self::Gauss, ElementType::SEG3) => {
                // 3-point Gauss-Legendre on [-1, 1] (exact to degree 5).
                let (p, w) = gauss3_1d();
                (p.to_vec(), w.to_vec())
            }
            (Self::Gauss, ElementType::TRI6) => tri6_gauss(),
            (Self::Gauss, ElementType::QUA8 | ElementType::QUA9) => {
                // 3×3 tensor product of the 3-point rule (exact deg 5 / dir).
                let (p, w) = gauss3_1d();
                let mut xi = Vec::with_capacity(9 * 2);
                let mut wt = Vec::with_capacity(9);
                for j in 0..3 {
                    for i in 0..3 {
                        xi.push(p[i]);
                        xi.push(p[j]);
                        wt.push(w[i] * w[j]);
                    }
                }
                (xi, wt)
            }
            (Self::Gauss, ElementType::TET10) => {
                // Keast degree-4, 11-point rule (reference volume 1/6). One
                // centroid point (negative weight), a 4-orbit and a 6-orbit.
                let a = 1.0 / 14.0;
                let b = 11.0 / 14.0;
                let d = 0.399_403_576_166_799;
                let c = 0.100_596_423_833_201;
                let (w0, w1, w2) = (-74.0 / 5625.0, 343.0 / 45000.0, 56.0 / 2250.0);
                let mut xi = vec![0.25, 0.25, 0.25];
                let mut w = vec![w0];
                for p in [[a, a, a], [b, a, a], [a, b, a], [a, a, b]] {
                    xi.extend_from_slice(&p);
                    w.push(w1);
                }
                for p in [
                    [d, c, c],
                    [c, d, c],
                    [c, c, d],
                    [d, d, c],
                    [d, c, d],
                    [c, d, d],
                ] {
                    xi.extend_from_slice(&p);
                    w.push(w2);
                }
                (xi, w)
            }
            (Self::Gauss, ElementType::PENTA15) => {
                // Tensor product of the 6-point TRI6 rule with the 3-point
                // Gauss rule mapped to ζ ∈ [0, 1] (weights halved).
                let (tri_xi, tri_w) = tri6_gauss();
                let (gp, gw) = gauss3_1d();
                let mut xi = Vec::with_capacity(18 * 3);
                let mut w = Vec::with_capacity(18);
                for tg in 0..tri_w.len() {
                    for k in 0..3 {
                        xi.push(tri_xi[2 * tg]);
                        xi.push(tri_xi[2 * tg + 1]);
                        xi.push(0.5 + 0.5 * gp[k]);
                        w.push(tri_w[tg] * 0.5 * gw[k]);
                    }
                }
                (xi, w)
            }
            (Self::Gauss, ElementType::HEX20 | ElementType::HEX27) => {
                // 3×3×3 tensor product of the 3-point rule.
                let (p, w) = gauss3_1d();
                let mut xi = Vec::with_capacity(27 * 3);
                let mut wt = Vec::with_capacity(27);
                for k in 0..3 {
                    for j in 0..3 {
                        for i in 0..3 {
                            xi.push(p[i]);
                            xi.push(p[j]);
                            xi.push(p[k]);
                            wt.push(w[i] * w[j] * w[k]);
                        }
                    }
                }
                (xi, wt)
            }
            // Reduced: one point at the centroid, weight = reference measure.
            (Self::Reduced, et) => match et {
                ElementType::SEG2 | ElementType::SEG3 => (vec![0.0], vec![2.0]),
                ElementType::TRI3 | ElementType::TRI6 => (vec![1.0 / 3.0, 1.0 / 3.0], vec![0.5]),
                ElementType::QUA4 | ElementType::QUA8 | ElementType::QUA9 => {
                    (vec![0.0, 0.0], vec![4.0])
                }
                ElementType::TET4 | ElementType::TET10 => (vec![0.25, 0.25, 0.25], vec![1.0 / 6.0]),
                ElementType::PENTA6 | ElementType::PENTA15 => {
                    (vec![1.0 / 3.0, 1.0 / 3.0, 0.5], vec![0.5])
                }
                // Centroid of the reference pyramid is a quarter of the way
                // up; its volume is 4/3.
                ElementType::PYRA5 => (vec![0.0, 0.0, 0.25], vec![4.0 / 3.0]),
                ElementType::HEX8 | ElementType::HEX20 | ElementType::HEX27 => {
                    (vec![0.0, 0.0, 0.0], vec![8.0])
                }
                ElementType::POI1 => unreachable!(),
            },
            (_, ElementType::POI1) => unreachable!(),
        })
    }

    fn check_compat(self, element_type: ElementType) -> Result<()> {
        if !self.is_compatible_with(element_type) {
            return Err(PyrucastError::Message(format!(
                "quadrature {} is not defined for {}",
                self, element_type
            )));
        }
        Ok(())
    }
}

/// 3-point Gauss-Legendre rule on `[-1, 1]` (exact to degree 5): points
/// `(∓√(3/5), 0, +√(3/5))`, weights `(5/9, 8/9, 5/9)`.
fn gauss3_1d() -> ([f64; 3], [f64; 3]) {
    let a = (3.0_f64 / 5.0).sqrt();
    ([-a, 0.0, a], [5.0 / 9.0, 8.0 / 9.0, 5.0 / 9.0])
}

/// 6-point degree-4 symmetric rule on the unit triangle (Dunavant). Returns
/// `(xi, w)` with `xi` row-major over 6 points × 2 coordinates; the weights
/// sum to the reference area `1/2`.
fn tri6_gauss() -> (Vec<f64>, Vec<f64>) {
    // Two 3-point orbits (b, b), (1-2b, b), (b, 1-2b).
    let b1 = 0.445_948_490_915_965;
    let b2 = 0.091_576_213_509_771;
    let w1 = 0.223_381_589_678_011 / 2.0;
    let w2 = 0.109_951_743_655_322 / 2.0;
    let orbit = |b: f64| {
        let a = 1.0 - 2.0 * b;
        [(b, b), (a, b), (b, a)]
    };
    let mut xi = Vec::with_capacity(6 * 2);
    let mut w = Vec::with_capacity(6);
    for (b, weight) in [(b1, w1), (b2, w2)] {
        for (x, y) in orbit(b) {
            xi.push(x);
            xi.push(y);
            w.push(weight);
        }
    }
    (xi, w)
}

impl fmt::Display for QuadratureRule {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(self.name())
    }
}

impl crate::dump::Dump for QuadratureRule {
    fn render(&self, _opts: &crate::dump::DumpOptions) -> String {
        self.to_string()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    fn ref_volume(et: ElementType) -> f64 {
        match et {
            ElementType::SEG2 | ElementType::SEG3 => 2.0,
            ElementType::TRI3 | ElementType::TRI6 => 0.5,
            ElementType::QUA4 | ElementType::QUA8 | ElementType::QUA9 => 4.0,
            ElementType::TET4 | ElementType::TET10 => 1.0 / 6.0,
            ElementType::PENTA6 | ElementType::PENTA15 => 0.5,
            // Square base of side 2 tapering to a point: ∫₀¹ (2(1-ζ))² dζ.
            ElementType::PYRA5 => 4.0 / 3.0,
            ElementType::HEX8 | ElementType::HEX20 | ElementType::HEX27 => 8.0,
            ElementType::POI1 => unreachable!(),
        }
    }

    /// Every non-POI1 element type, for parametric quadrature tests.
    const ALL_FE_TYPES: [ElementType; 15] = [
        ElementType::SEG2,
        ElementType::TRI3,
        ElementType::QUA4,
        ElementType::TET4,
        ElementType::PYRA5,
        ElementType::PENTA6,
        ElementType::HEX8,
        ElementType::SEG3,
        ElementType::TRI6,
        ElementType::QUA8,
        ElementType::TET10,
        ElementType::PENTA15,
        ElementType::HEX20,
        ElementType::QUA9,
        ElementType::HEX27,
    ];

    #[test]
    fn weights_sum_to_reference_volume() {
        for et in ALL_FE_TYPES {
            let (_xi, w) = QuadratureRule::Gauss.points(et).unwrap();
            let s: f64 = w.iter().sum();
            let expected = ref_volume(et);
            assert!(
                (s - expected).abs() < 1e-12,
                "{}: weights sum = {} ≠ {}",
                et,
                s,
                expected
            );
        }
    }

    #[test]
    fn buffer_layouts() {
        for et in ALL_FE_TYPES {
            let n_g = QuadratureRule::Gauss.point_count(et).unwrap();
            let (xi, w) = QuadratureRule::Gauss.points(et).unwrap();
            assert_eq!(w.len(), n_g);
            assert_eq!(xi.len(), n_g * et.topological_dim());
        }
    }

    /// On SEG2, the 2-point Gauss rule must integrate `∫_{-1}^{1} ξ^p dξ`
    /// exactly for `p ≤ 3`.
    #[test]
    fn gauss_seg2_exact_up_to_degree_3() {
        let (xi, w) = QuadratureRule::Gauss.points(ElementType::SEG2).unwrap();
        for p in 0..=3 {
            let mut sum = 0.0;
            for g in 0..w.len() {
                sum += w[g] * xi[g].powi(p);
            }
            // ∫_{-1}^{1} ξ^p dξ = 2/(p+1) if p even, else 0.
            let expected = if p % 2 == 0 {
                2.0 / (p + 1) as f64
            } else {
                0.0
            };
            assert!(
                (sum - expected).abs() < 1e-12,
                "SEG2 Gauss not exact for ξ^{}: got {}, expected {}",
                p,
                sum,
                expected
            );
        }
    }

    /// On TRI3, the Hammer mid-edge rule must integrate any polynomial
    /// of degree ≤ 2 exactly. Test on `f(ξ, η) = ξ²` whose exact integral
    /// over the unit simplex is 1/12.
    #[test]
    fn gauss_tri3_exact_for_degree_2() {
        let (xi, w) = QuadratureRule::Gauss.points(ElementType::TRI3).unwrap();
        let mut sum = 0.0;
        for g in 0..w.len() {
            let a = xi[g * 2];
            sum += w[g] * a * a;
        }
        let expected = 1.0 / 12.0;
        assert!(
            (sum - expected).abs() < 1e-12,
            "TRI3 Gauss: ∫ξ² = {} ≠ {}",
            sum,
            expected
        );
    }

    /// Factorial helper for the exact simplex-monomial integrals.
    fn fact(n: u32) -> f64 {
        (1..=n).map(|k| k as f64).product::<f64>().max(1.0)
    }

    /// The custom TRI6 (degree-4) rule integrates every monomial `ξ^p η^q`
    /// with `p + q ≤ 4` exactly; on the unit triangle
    /// `∫ ξ^p η^q = p! q! / (p+q+2)!`.
    #[test]
    fn gauss_tri6_exact_up_to_degree_4() {
        let (xi, w) = QuadratureRule::Gauss.points(ElementType::TRI6).unwrap();
        for p in 0..=4u32 {
            for q in 0..=(4 - p) {
                let mut sum = 0.0;
                for g in 0..w.len() {
                    sum += w[g] * xi[2 * g].powi(p as i32) * xi[2 * g + 1].powi(q as i32);
                }
                let expected = fact(p) * fact(q) / fact(p + q + 2);
                assert!(
                    (sum - expected).abs() < 1e-12,
                    "TRI6: ∫ξ^{p}η^{q} = {sum} ≠ {expected}"
                );
            }
        }
    }

    /// The custom TET10 (Keast degree-4) rule integrates every monomial
    /// `ξ^p η^q ζ^r` with `p + q + r ≤ 4` exactly; on the unit tetrahedron
    /// `∫ ξ^p η^q ζ^r = p! q! r! / (p+q+r+3)!`.
    #[test]
    fn gauss_tet10_exact_up_to_degree_4() {
        let (xi, w) = QuadratureRule::Gauss.points(ElementType::TET10).unwrap();
        for p in 0..=4u32 {
            for q in 0..=(4 - p) {
                for r in 0..=(4 - p - q) {
                    let mut sum = 0.0;
                    for g in 0..w.len() {
                        sum += w[g]
                            * xi[3 * g].powi(p as i32)
                            * xi[3 * g + 1].powi(q as i32)
                            * xi[3 * g + 2].powi(r as i32);
                    }
                    let expected = fact(p) * fact(q) * fact(r) / fact(p + q + r + 3);
                    assert!(
                        (sum - expected).abs() < 1e-12,
                        "TET10: ∫ξ^{p}η^{q}ζ^{r} = {sum} ≠ {expected}"
                    );
                }
            }
        }
    }

    #[test]
    fn rejects_poi1() {
        assert!(!QuadratureRule::Gauss.is_compatible_with(ElementType::POI1));
        assert!(QuadratureRule::Gauss.points(ElementType::POI1).is_err());
        assert!(QuadratureRule::Gauss
            .point_count(ElementType::POI1)
            .is_err());
    }

    #[test]
    fn display_and_parsing() {
        assert_eq!(format!("{}", QuadratureRule::Gauss), "GAUSS");
        assert_eq!(
            QuadratureRule::from_name("gauss"),
            Some(QuadratureRule::Gauss)
        );
        assert_eq!(QuadratureRule::from_name("unknown"), None);
    }
}