https://github.com/juliageometry/meshintegrals.jl
Numerical integration over Meshes.jl geometry domains
https://github.com/juliageometry/meshintegrals.jl
differential-geometry julia numerical-integration quadrature-methods scientific-computing
Last synced: 29 days ago
JSON representation
Numerical integration over Meshes.jl geometry domains
- Host: GitHub
- URL: https://github.com/juliageometry/meshintegrals.jl
- Owner: JuliaGeometry
- License: mit
- Created: 2024-01-08T23:42:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-01T05:50:54.000Z (about 1 month ago)
- Last Synced: 2025-04-12T02:12:36.308Z (29 days ago)
- Topics: differential-geometry, julia, numerical-integration, quadrature-methods, scientific-computing
- Language: Julia
- Homepage: https://juliageometry.github.io/MeshIntegrals.jl/
- Size: 970 KB
- Stars: 29
- Watchers: 4
- Forks: 5
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# MeshIntegrals.jl
[](https://JuliaGeometry.github.io/MeshIntegrals.jl/stable/)
[](https://JuliaGeometry.github.io/MeshIntegrals.jl/dev/)
[](https://opensource.org/licenses/MIT)
[](https://github.com/SciML/ColPrac)[](https://github.com/JuliaGeometry/MeshIntegrals.jl/actions/workflows/CI.yml?query=branch%3Amain)
[](https://codecov.io/gh/JuliaGeometry/MeshIntegrals.jl)
[](https://coveralls.io/github/JuliaGeometry/MeshIntegrals.jl?branch=main)
[](https://github.com/JuliaTesting/Aqua.jl)**MeshIntegrals.jl** uses differential forms to enable fast and easy numerical integration of arbitrary integrand functions over domains defined via [**Meshes.jl**](https://github.com/JuliaGeometry/Meshes.jl) geometries. This is achieved using:
- Gauss-Legendre quadrature rules from [**FastGaussQuadrature.jl**](https://github.com/JuliaApproximation/FastGaussQuadrature.jl): `GaussLegendre(n)`
- H-adaptive Gauss-Kronrod quadrature rules from [**QuadGK.jl**](https://github.com/JuliaMath/QuadGK.jl): `GaussKronrod(kwargs...)`
- H-adaptive cubature rules from [**HCubature.jl**](https://github.com/JuliaMath/HCubature.jl): `HAdaptiveCubature(kwargs...)`These solvers have support for integrand functions that produce scalars, vectors, and [**Unitful.jl**](https://github.com/PainterQubits/Unitful.jl) `Quantity` types. While HCubature.jl does not natively support `Quantity` type integrands, this package provides a compatibility layer to enable this feature.
## Usage
### Basic
```julia
integral(f, geometry)
```
Performs a numerical integration of some integrand function `f` over the domain specified by `geometry`. The integrand function can be anything callable with a method `f(::Meshes.Point)`. A default integration method will be automatically selected according to the geometry: `GaussKronrod()` for 1D, and `HAdaptiveCubature()` for all others.```julia
integral(f, geometry, rule)
```
Performs a numerical integration of some integrand function `f` over the domain specified by `geometry` using the specified integration rule, e.g. `GaussKronrod()`. The integrand function can be anything callable with a method `f(::Meshes.Point)`.Additionally, several optional keyword arguments are defined in [the API](https://juliageometry.github.io/MeshIntegrals.jl/stable/api/) to provide additional control over the integration mechanics.
### Aliases
```julia
lineintegral(f, geometry)
surfaceintegral(f, geometry)
volumeintegral(f, geometry)
```
Alias functions are provided for convenience. These are simply wrappers for `integral` that also validate that the provided `geometry` has the expected number of parametric dimensions. Like with `integral`, a `rule` can also optionally be specified as a third argument.
- `lineintegral` is used for curve-like geometries or polytopes (e.g. `Segment`, `Ray`, `BezierCurve`, `Rope`, etc)
- `surfaceintegral` is used for surfaces (e.g. `Disk`, `Sphere`, `CylinderSurface`, etc)
- `volumeintegral` is used for (3D) volumes (e.g. `Ball`, `Cone`, `Torus`, etc)### Example
```julia
using Meshes
using MeshIntegrals
using Unitful# Define a Bezier curve whose path approximates a sine-wave on the xy-plane
N = 361
curve = BezierCurve([Point(t*u"m", sin(t)*u"m", 0.0u"m") for t in range(-π, π, length=N)])# Integrand function that outputs in units of Ohms/meter
function f(p::Point)
x, y, z = to(p)
return (1 / sqrt(1 + cos(x / u"m")^2)) * u"Ω/m"
end# Use recommended defaults
integral(f, curve) # -> Approximately 2π Ω# Using aliases
lineintegral(f, curve) # -> Approximately 2π Ω
surfaceintegral(f, curve) # -> throws ArgumentError# Specifying an integration rule and settings (loosened absolute tolerance)
integral(f, curve, GaussKronrod(atol = 1e-4u"Ω")) # -> Approximately (2π ± 1e-4) Ω
```