Class LebedevQuadrature
Inspired by the sphere_lebedev_rule C++ code by John Burkardt,
itself based on the public domain "Lebedev-Laikov" algorithm and tables by
Vyacheslav Lebedev and Dmitri Laikov.
For a rule of a given order N, with unit points (x_i,y_i,z_i) and weights
w_i (which sum to 1), the integral of a function f over the unit sphere is
approximated as 4*PI * sum(w_i * f(x_i,y_i,z_i)).
Usage: the simplest way to integrate a function over the unit sphere is to call
integrate(TrivariateFunction, int) with the function to integrate and the desired
order (number of points), for example:
double integral = LebedevQuadrature.integrate((x, y, z) -> x * x + y * y + z * z, 110);
The order must be one of the values listed in AVAILABLE_ORDERS; higher orders give
a more accurate approximation at the cost of evaluating the function at more points. When the
required accuracy is unknown in advance, getRuleAtLeast(int) can be used to pick the
smallest available rule with at least a given number of points. For repeated integrations with
the same order, it is more efficient to retrieve the LebedevQuadrature.Rule once with getRule(int)
or getRuleAtLeast(int) and reuse it, evaluating the function directly on its points and
weights, rather than calling integrate(TrivariateFunction, int) repeatedly.
Reference: Vyacheslav Lebedev, Dmitri Laikov, "A quadrature formula for the sphere of the 131st algebraic order of accuracy", Russian Academy of Sciences Doklady Mathematics, Volume 59, Number 3, 1999, pages 477-481.
Original algorithm and tables: Vyacheslav Lebedev and Dmitri Laikov- Since:
- 4.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA Lebedev quadrature rule: unit-sphere points and weights (weights sum to 1). -
Method Summary
Modifier and TypeMethodDescriptionstatic intgenOh(int code, double aIn, double bIn, double v, double[] x, double[] y, double[] z, double[] w, int start) Generate points under OH (octahedral) symmetry, given a point specified by A and B, with weight V, writing into x/y/z/w starting at indexstart.static LebedevQuadrature.RulegetRule(int order) Get the Lebedev rule with the given exact order.static LebedevQuadrature.RulegetRuleAtLeast(int minimumOrder) Get the smallest available rule with at least the requested number of points.static doubleintegrate(TrivariateFunction function, int order) Integrate a function over the surface of the unit sphere using the Lebedev rule of the given order.
-
Method Details
-
getRuleAtLeast
Get the smallest available rule with at least the requested number of points.- Parameters:
minimumOrder- minimum number of points desired- Returns:
- a Lebedev rule
-
getRule
Get the Lebedev rule with the given exact order.- Parameters:
order- number of points, must be one ofAVAILABLE_ORDERS- Returns:
- a Lebedev rule
- Throws:
MathIllegalArgumentException- iforderis not one ofAVAILABLE_ORDERS
-
integrate
Integrate a function over the surface of the unit sphere using the Lebedev rule of the given order.- Parameters:
function- function to integrate, taking the Cartesian coordinates of a unit-sphere pointorder- number of points, must be one ofAVAILABLE_ORDERS- Returns:
- approximation of the integral of
functionover the unit sphere - Throws:
MathIllegalArgumentException- iforderis not one ofAVAILABLE_ORDERSNullArgumentException- iffunctionis null
-
genOh
public static int genOh(int code, double aIn, double bIn, double v, double[] x, double[] y, double[] z, double[] w, int start) Generate points under OH (octahedral) symmetry, given a point specified by A and B, with weight V, writing into x/y/z/w starting at indexstart.- Parameters:
code- symmetry code selecting the point pattern to generateaIn- coordinate value AbIn- coordinate value Bv- weight assigned to the generated pointsx- array to write generated x coordinates intoy- array to write generated y coordinates intoz- array to write generated z coordinates intow- array to write generated weights intostart- index to start writing points at- Returns:
- the number of points generated
-