Skip to content

Commit 23d7d25

Browse files
authored
Use recently-implemented Meshes predicates (#199)
* Bump Meshes min * Use predicates * Fix _default_rule bug * Uses predicates * Update docs Project.toml * Update test Project.toml * Update benchmark Project.toml * Use SVector in benchmarks for vector-valued integrands * Use SVector for allocation-free integrands in testing * Update CHANGELOG.md
1 parent 8f8f8fa commit 23d7d25

File tree

9 files changed

+34
-26
lines changed

9 files changed

+34
-26
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010

11-
## [0.17.0] - 2025-08-14
11+
## [0.17.0] - 2025-08-18
1212

1313
### Changed
1414

15-
- Increased minimum dependency version for Meshes.jl to `v0.52.12` and CoordRefSystems.jl to `0.16` to natively support some new geometry types.
15+
- Increased minimum dependency version for Meshes.jl to `v0.53` and CoordRefSystems.jl to `0.16` to support some new geometry types and make use of new helper functions.
1616

1717
### Removed
1818

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Enzyme = "0.13.47"
2525
FastGaussQuadrature = "1"
2626
HCubature = "1.5"
2727
LinearAlgebra = "1"
28-
Meshes = "0.52.12, 0.53, 0.54"
28+
Meshes = "0.53, 0.54"
2929
QuadGK = "2.1.1"
3030
Unitful = "1.19"
3131
julia = "1.9"

benchmark/Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
33
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
44
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
55
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
6+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
67
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
78

89
[compat]
910
BenchmarkTools = "1.5"
10-
Enzyme = "0.13.19"
11+
Enzyme = "0.13.47"
1112
LinearAlgebra = "1"
12-
Meshes = "0.51.20, 0.52"
13+
Meshes = "0.53, 0.54"
14+
StaticArrays = "1"
1315
Unitful = "1.19"
1416
julia = "1.9"

benchmark/benchmarks.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using BenchmarkTools
22
using LinearAlgebra
33
using Meshes
44
using MeshIntegrals
5+
using StaticArrays
56
using Unitful
67
import Enzyme
78

@@ -11,9 +12,12 @@ const SUITE = BenchmarkGroup()
1112
# Integrals
1213
############################################################################################
1314

15+
# Like fill but returns an SVector to eliminate integrand function allocations
16+
staticfill(val, N) = SVector(ntuple(Returns(val), N)...)
17+
1418
integrands = (
1519
(name = "Scalar", f = p -> norm(to(p))),
16-
(name = "Vector", f = p -> fill(norm(to(p)), 3))
20+
(name = "Vector", f = p -> staticfill(norm(to(p)), 3))
1721
)
1822
rules = (
1923
(name = "GaussLegendre", rule = GaussLegendre(100)),

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
88
[compat]
99
BenchmarkTools = "1"
1010
Documenter = "1"
11-
Meshes = "0.51.20, 0.52"
11+
Meshes = "0.53, 0.54"
1212
Unitful = "1.19"
1313
julia = "1.9"

src/integral.jl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# Master Integral Function
33
################################################################################
44

5+
# Default integration rule when rule arg is unspecified
6+
_default_rule(g) = ifelse(Meshes.iscurve(g), GaussKronrod(), HAdaptiveCubature())
7+
58
"""
69
integral(f, geometry[, rule]; kwargs...)
710
@@ -22,12 +25,6 @@ calculate Jacobians within the integration domain.
2225
"""
2326
function integral end
2427

25-
# Default integration rule to use if unspecified
26-
function _default_rule(geometry)
27-
ifelse(Meshes.paramdim(geometry) == 1, GaussKronrod(), HAdaptiveCubature())
28-
end
29-
30-
# If only f and geometry are specified, select default rule
3128
function integral(
3229
f,
3330
geometry::Geometry,
@@ -64,7 +61,7 @@ function _integral(
6461
_check_diff_method_support(geometry, diff_method)
6562

6663
# Only supported for 1D geometries
67-
if Meshes.paramdim(geometry) != 1
64+
if !Meshes.iscurve(geometry)
6865
msg = "GaussKronrod rules not supported in more than one parametric dimension."
6966
throw(ArgumentError(msg))
7067
end

src/integral_aliases.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function _alias_error_msg(name, N)
2-
"Performing a $name integral on a geometry with $N parametric dimensions not supported."
2+
"$name integrals not supported on a geometry without exactly $N parametric dimensions."
33
end
44

55
################################################################################
@@ -27,8 +27,8 @@ function lineintegral(
2727
rule::IntegrationRule = GaussKronrod();
2828
kwargs...
2929
)
30-
if (N = Meshes.paramdim(geometry)) != 1
31-
throw(ArgumentError(_alias_error_msg("line", N)))
30+
if !Meshes.iscurve(geometry)
31+
throw(ArgumentError(_alias_error_msg("Line", 1)))
3232
end
3333

3434
return integral(f, geometry, rule; kwargs...)
@@ -59,8 +59,8 @@ function surfaceintegral(
5959
rule::IntegrationRule = HAdaptiveCubature();
6060
kwargs...
6161
)
62-
if (N = Meshes.paramdim(geometry)) != 2
63-
throw(ArgumentError(_alias_error_msg("surface", N)))
62+
if !Meshes.issurface(geometry)
63+
throw(ArgumentError(_alias_error_msg("Surface", 2)))
6464
end
6565

6666
return integral(f, geometry, rule; kwargs...)
@@ -91,8 +91,8 @@ function volumeintegral(
9191
rule::IntegrationRule = HAdaptiveCubature();
9292
kwargs...
9393
)
94-
if (N = Meshes.paramdim(geometry)) != 3
95-
throw(ArgumentError(_alias_error_msg("volume", N)))
94+
if !Meshes.issolid(geometry)
95+
throw(ArgumentError(_alias_error_msg("Volume", 3)))
9696
end
9797

9898
return integral(f, geometry, rule; kwargs...)

test/Project.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
77
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
88
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
9+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
910
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1011
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
1112
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"
1213
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
1314

1415
[compat]
15-
Aqua = "0.7, 0.8"
16-
CoordRefSystems = "0.15, 0.16, 0.17, 0.18"
16+
Aqua = "0.8"
17+
CoordRefSystems = "0.16, 0.17, 0.18"
1718
Enzyme = "0.13.47"
1819
ExplicitImports = "1.6.0"
1920
LinearAlgebra = "1"
20-
Meshes = "0.51.20, 0.52, 0.53, 0.54"
21+
Meshes = "0.53, 0.54"
2122
SpecialFunctions = "2"
23+
StaticArrays = "1"
2224
TestItemRunner = "1"
2325
TestItems = "1"
2426
Unitful = "1.19"

test/combinations.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ This file includes tests for:
1818
import LinearAlgebra: norm
1919
using Meshes
2020
using MeshIntegrals: MeshIntegrals, GeometryOrDomain
21+
import StaticArrays: SVector
2122
import Unitful: @u_str, Quantity, ustrip
2223
import Enzyme
2324

25+
staticfill(val, N) = SVector(ntuple(Returns(val), N)...)
26+
2427
# Used for testing callable objects as integrand functions
2528
struct Callable{F <: Function}
2629
f::F
@@ -113,8 +116,8 @@ This file includes tests for:
113116
@test integral(f, testable.geometry, rule)sol rtol=rtol
114117

115118
# Vector integrand
116-
fv(p) = fill(testable.integrand(p), 3)
117-
sol_v = fill(testable.solution, 3)
119+
fv(p) = staticfill(testable.integrand(p), 3)
120+
sol_v = staticfill(testable.solution, 3)
118121
@test integral(fv, testable.geometry, rule)sol_v rtol=rtol
119122
else
120123
f = testable.integrand

0 commit comments

Comments
 (0)