ImplicitIntegration is a Julia library for approximating volume and surface integrals over implicitly defined domains in arbitrary dimensions. It implements the algorithm described in
Saye, R. I. (2015). High-order quadrature methods for implicitly defined surfaces and volumes in hyperrectangles. SIAM Journal on Scientific Computing, 37(2), A993-A1019.
which allows for the computation of volume integrals of the form
\int_{\phi(\boldsymbol{x}) < 0 \ \cap \ U} f(\boldsymbol{x}) \, \mathrm{dV},
and surface integrals of the form
\int_{\phi(\boldsymbol{x}) = 0 \ \cap \ U} f(\boldsymbol{x}) \, \mathrm{dS},
where $\phi : \mathbb{R}^d \to \mathbb{R}$ is a level-set function implicitly defining the surface, and $U = [a_1, b_1] \times \ldots \times [a_d, b_d]$ is a bounding box.
Key features include:
To install, open the Julia REPL and run:
using Pkg
Pkg.add("ImplicitIntegration")
Here is how to compute the area of a unit disk in 2D:
using ImplicitIntegration
ϕ = (x) -> sqrt(x[1]^2 + x[2]^2) - 1 # level-set function
f = (x) -> 1 # integrand
result = integrate(f, ϕ, (-1.5, -1.5), (1.5, 1.5))
result.val ≈ π # true
To compute the perimeter, simply set surface = true
:
result = integrate(f, ϕ, (-1.5, -1.5), (1.5, 1.5); surface = true)
result.val ≈ 2π # true
More interesting surfaces can be obtained by changing ϕ
. Here is an example of a
quadrature for a three-dimensional Cassini
oval:
using ImplicitIntegration, StaticArrays, GLMakie, LinearAlgebra
p1, p2, p3 = SVector(-1.0, 0, -√3 / 2), SVector(1.0, 0, -√3 / 2), SVector(0, 0, √3 / 2)
b = 1.5
# surface s.t. product of distances to p1, p2, p3 is constant
ϕ = x -> (x - p1) ⋅ (x - p1) * (x - p2) ⋅ (x - p2) * (x - p3) ⋅ (x - p3) - b^2
out = quadgen(ϕ, (-2, -2, -2), (2, 2, 2); order = 1, surface = true)
scatter(out.quad.coords; markersize = 5, color = :red)
For detailed usage, examples, and advanced options, please refer to the official documentation.