Skip to content

Commit 41c5dfe

Browse files
v0.14-DEV: Consolidate terminology to IntegrationRule (#82)
* Change package version to target * Rename file * Change Algorithm to Rule and update docstrings * Change algorithm to rule * Update coding standards for consistency * Update include reference * Update naming in docs * Update naming to rule * Update coding style * Export IntegrationRule * Update naming * Update naming * Update naming * Update code style * Apply suggestions from code review Co-authored-by: Joshua Lampert <[email protected]> --------- Co-authored-by: Joshua Lampert <[email protected]>
1 parent bdd69e2 commit 41c5dfe

20 files changed

+223
-220
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "MeshIntegrals"
22
uuid = "dadec2fd-bbe0-4da4-9dbe-476c782c8e47"
3-
version = "0.13.5"
3+
version = "0.14.0-DEV"
44

55
[deps]
66
CoordRefSystems = "b46f11dc-f210-4604-bfba-323c1ec968cb"

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ integral(f, geometry)
2626
Performs a numerical integration of some integrand function `f(p::Meshes.Point)` over the domain specified by `geometry`. A default integration method will be automatically selected according to the geometry: `GaussKronrod()` for 1D, and `HAdaptiveCubature()` for all others.
2727

2828
```julia
29-
integral(f, geometry, algorithm, FP=Float64)
29+
integral(f, geometry, rule, FP=Float64)
3030
```
31-
Performs a numerical integration of some integrand function `f(p::Meshes.Point)` over the domain specified by `geometry` using the specified integration algorithm, e.g. `GaussKronrod()`.
31+
Performs a numerical integration of some integrand function `f(p::Meshes.Point)` over the domain specified by `geometry` using the specified integration rule, e.g. `GaussKronrod()`.
3232

3333
Optionally, a fourth argument can be provided to specify the floating point precision level desired. This setting can be manipulated if your integrand function produces outputs with alternate floating point precision (e.g. `Float16`, `BigFloat`, etc) AND you'd prefer to avoid implicit type promotions.
3434

@@ -37,7 +37,7 @@ lineintegral(f, geometry)
3737
surfaceintegral(f, geometry)
3838
volumeintegral(f, geometry)
3939
```
40-
Alias functions are provided for convenience. These are simply wrappers for `integral` that first validate that the provided `geometry` has the expected number of parametric/manifold dimensions. Like with `integral` in the examples above, the `algorithm` can also be specified as a third-argument.
40+
Alias functions are provided for convenience. These are simply wrappers for `integral` that first validate that the provided `geometry` has the expected number of parametric/manifold dimensions. Like with `integral` in the examples above, the `rule` can also be specified as a third-argument.
4141
- `lineintegral` for curve-like geometries or polytopes (e.g. `Segment`, `Ray`, `BezierCurve`, `Rope`, etc)
4242
- `surfaceintegral` for surfaces (e.g. `Disk`, `Sphere`, `CylinderSurface`, etc)
4343
- `volumeintegral` for (3D) volumes (e.g. `Ball`, `Cone`, `Torus`, etc)

docs/src/api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ MeshIntegrals.surfaceintegral
1414
MeshIntegrals.volumeintegral
1515
```
1616

17-
## Integration Algorithms
17+
## Integration Rules
1818

1919
```@docs
2020
MeshIntegrals.GaussKronrod

docs/src/supportmatrix.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Support Matrix
22

3-
While this library aims to support all possible integration algorithms and **Meshes.jl**
3+
While this library aims to support all possible integration rules and **Meshes.jl**
44
geometry types, some combinations are ill-suited and some others are simplu not yet
55
implemented. The following Support Matrix aims to capture the current development state of
6-
all geometry/algorithm combinations. Entries with a green check mark are fully supported
6+
all geometry/rule combinations. Entries with a green check mark are fully supported
77
and have passing unit tests that provide some confidence they produce accurate results.
88

99
In general, Gauss-Kronrod integration rules are recommended (and the default) for geometries

src/MeshIntegrals.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ module MeshIntegrals
1111
include("utils.jl")
1212
export jacobian, derivative, unitdirection
1313

14-
include("integration_algorithms.jl")
15-
export GaussKronrod, GaussLegendre, HAdaptiveCubature
14+
include("integration_rules.jl")
15+
export IntegrationRule, GaussKronrod, GaussLegendre, HAdaptiveCubature
1616

1717
include("integral.jl")
18+
export integral
19+
1820
include("integral_aliases.jl")
19-
export integral, lineintegral, surfaceintegral, volumeintegral
21+
export lineintegral, surfaceintegral, volumeintegral
2022

2123
# Integration methods specialized for particular geometries
2224
include("specializations/BezierCurve.jl")

src/integral.jl

+31-31
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
"""
66
integral(f, geometry)
7-
integral(f, geometry, algorithm)
8-
integral(f, geometry, algorithm, FP)
7+
integral(f, geometry, rule)
8+
integral(f, geometry, rule, FP)
99
1010
Numerically integrate a given function `f(::Point)` over the domain defined by
11-
a `geometry` using a particular `integration algorithm` with floating point
11+
a `geometry` using a particular numerical integration `rule` with floating point
1212
precision of type `FP`.
1313
1414
# Arguments
1515
- `f`: an integrand function with a method `f(::Meshes.Point)`
1616
- `geometry`: some `Meshes.Geometry` that defines the integration domain
17-
- `algorithm`: optionally, the `IntegrationAlgorithm` used for the integration (by default `GaussKronrod()` in 1D and `HAdaptiveCubature()` else)
17+
- `rule`: optionally, the `IntegrationRule` used for integration (by default `GaussKronrod()` in 1D and `HAdaptiveCubature()` else)
1818
- `FP`: optionally, the floating point precision desired (`Float64` by default)
1919
2020
Note that reducing `FP` below `Float64` will incur some loss of precision. By
@@ -23,7 +23,7 @@ contrast, increasing `FP` to e.g. `BigFloat` will typically increase precision
2323
"""
2424
function integral end
2525

26-
# If only f and geometry are specified, select default algorithm
26+
# If only f and geometry are specified, select default rule
2727
function integral(
2828
f::F,
2929
geometry::G
@@ -33,14 +33,14 @@ function integral(
3333
_integral(f, geometry, rule)
3434
end
3535

36-
# with algorithm and T specified
36+
# with rule and T specified
3737
function integral(
3838
f::F,
3939
geometry::G,
40-
settings::I,
40+
rule::I,
4141
FP::Type{T} = Float64
42-
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationAlgorithm, T<:AbstractFloat}
43-
_integral(f, geometry, settings, FP)
42+
) where {F<:Function, G<:Meshes.Geometry, I<:IntegrationRule, T<:AbstractFloat}
43+
_integral(f, geometry, rule, FP)
4444
end
4545

4646

@@ -52,31 +52,31 @@ end
5252
function _integral(
5353
f,
5454
geometry,
55-
settings::GaussKronrod,
55+
rule::GaussKronrod,
5656
FP::Type{T} = Float64
5757
) where {T<:AbstractFloat}
5858
# Run the appropriate integral type
59-
Dim = Meshes.paramdim(geometry)
60-
if Dim == 1
61-
return _integral_1d(f, geometry, settings, FP)
62-
elseif Dim == 2
63-
return _integral_2d(f, geometry, settings, FP)
64-
elseif Dim == 3
65-
return _integral_3d(f, geometry, settings, FP)
59+
N = Meshes.paramdim(geometry)
60+
if N == 1
61+
return _integral_1d(f, geometry, rule, FP)
62+
elseif N == 2
63+
return _integral_2d(f, geometry, rule, FP)
64+
elseif N == 3
65+
return _integral_3d(f, geometry, rule, FP)
6666
end
6767
end
6868

6969
# GaussLegendre
7070
function _integral(
7171
f,
7272
geometry,
73-
settings::GaussLegendre,
73+
rule::GaussLegendre,
7474
FP::Type{T} = Float64
7575
) where {T<:AbstractFloat}
7676
N = Meshes.paramdim(geometry)
7777

7878
# Get Gauss-Legendre nodes and weights for a region [-1,1]^N
79-
xs, ws = _gausslegendre(FP, settings.n)
79+
xs, ws = _gausslegendre(FP, rule.n)
8080
weights = Iterators.product(ntuple(Returns(ws), N)...)
8181
nodes = Iterators.product(ntuple(Returns(xs), N)...)
8282

@@ -95,21 +95,21 @@ end
9595
function _integral(
9696
f,
9797
geometry,
98-
settings::HAdaptiveCubature,
98+
rule::HAdaptiveCubature,
9999
FP::Type{T} = Float64
100100
) where {T<:AbstractFloat}
101-
Dim = Meshes.paramdim(geometry)
101+
N = Meshes.paramdim(geometry)
102102

103103
integrand(t) = f(geometry(t...)) * differential(geometry, t)
104104

105105
# HCubature doesn't support functions that output Unitful Quantity types
106106
# Establish the units that are output by f
107-
testpoint_parametriccoord = fill(FP(0.5),Dim)
107+
testpoint_parametriccoord = fill(FP(0.5), N)
108108
integrandunits = Unitful.unit.(integrand(testpoint_parametriccoord))
109109
# Create a wrapper that returns only the value component in those units
110110
uintegrand(uv) = Unitful.ustrip.(integrandunits, integrand(uv))
111111
# Integrate only the unitless values
112-
value = HCubature.hcubature(uintegrand, zeros(FP,Dim), ones(FP,Dim); settings.kwargs...)[1]
112+
value = HCubature.hcubature(uintegrand, zeros(FP,N), ones(FP,N); rule.kwargs...)[1]
113113

114114
# Reapply units
115115
return value .* integrandunits
@@ -122,29 +122,29 @@ end
122122
function _integral_1d(
123123
f,
124124
geometry,
125-
settings::GaussKronrod,
125+
rule::GaussKronrod,
126126
FP::Type{T} = Float64
127127
) where {T<:AbstractFloat}
128-
integrand(t) = f(geometry(t)) * differential(geometry, [t])
129-
return QuadGK.quadgk(integrand, FP(0), FP(1); settings.kwargs...)[1]
128+
integrand(t) = f(geometry(t)) * differential(geometry, (t))
129+
return QuadGK.quadgk(integrand, zero(FP), one(FP); rule.kwargs...)[1]
130130
end
131131

132132
function _integral_2d(
133133
f,
134134
geometry2d,
135-
settings::GaussKronrod,
135+
rule::GaussKronrod,
136136
FP::Type{T} = Float64
137137
) where {T<:AbstractFloat}
138-
integrand(u,v) = f(geometry2d(u,v)) * differential(geometry2d, [u,v])
139-
∫₁(v) = QuadGK.quadgk(u -> integrand(u,v), FP(0), FP(1); settings.kwargs...)[1]
140-
return QuadGK.quadgk(v -> ∫₁(v), FP(0), FP(1); settings.kwargs...)[1]
138+
integrand(u,v) = f(geometry2d(u,v)) * differential(geometry2d, (u,v))
139+
∫₁(v) = QuadGK.quadgk(u -> integrand(u,v), zero(FP), one(FP); rule.kwargs...)[1]
140+
return QuadGK.quadgk(v -> ∫₁(v), zero(FP), one(FP); rule.kwargs...)[1]
141141
end
142142

143143
# Integrating volumes with GaussKronrod not supported by default
144144
function _integral_3d(
145145
f,
146146
geometry,
147-
settings::GaussKronrod,
147+
rule::GaussKronrod,
148148
FP::Type{T} = Float64
149149
) where {T<:AbstractFloat}
150150
error("Integrating this volume type with GaussKronrod not supported.")

0 commit comments

Comments
 (0)