ningshuxia
2022-12-01 ad494f13d2ddf31f142cf7fb908b3a6e90395a1a
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
using System;
 
namespace IStation.Numerics.Integration.GaussRule
{
    /// <summary>
    /// Creates a Gauss-Kronrod point.
    /// </summary>
    internal static class GaussKronrodPointFactory
    {
        [ThreadStatic]
        private static GaussPointPair gaussKronrodPoint;
 
        /// <summary>
        /// Getter for the GaussKronrodPoint.
        /// </summary>
        /// <param name="order">Defines an Nth order Gauss-Kronrod rule. Precomputed Gauss-Kronrod abscissas/weights for orders 15, 21, 31, 41, 51, 61 are used, otherwise they're calculated on the fly.</param>
        /// <returns>Object containing the non-negative abscissas/weights, and order.</returns>
        public static GaussPointPair GetGaussPoint(int order)
        {
            // Try to get the GaussKronrodPoint from the cached static field.
            bool gaussKronrodPointIsCached = gaussKronrodPoint != null && gaussKronrodPoint.Order == order;
            if (!gaussKronrodPointIsCached)
            {
                // Try to find the GaussKronrodPoint in the precomputed dictionary. 
                if (!GaussKronrodPoint.PreComputed.TryGetValue(order, out gaussKronrodPoint))
                {
                    gaussKronrodPoint = GaussKronrodPoint.Generate(order, 1E-10);
                }
            }
 
            return gaussKronrodPoint;
        }
    }
}