using System;
namespace IStation.Numerics.Integration.GaussRule
{
///
/// Creates a Gauss-Kronrod point.
///
internal static class GaussKronrodPointFactory
{
[ThreadStatic]
private static GaussPointPair gaussKronrodPoint;
///
/// Getter for the GaussKronrodPoint.
///
/// 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.
/// Object containing the non-negative abscissas/weights, and order.
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;
}
}
}