Skip to content

Commit ab712c7

Browse files
authored
Calculate nodes and weights at GaussLegendre construction time (#149)
* Add fields and constructor * Use new GaussLegendre fields * Add Rope and GaussLegendre benchmarks
1 parent 3c06d76 commit ab712c7

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

benchmark/benchmarks.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ spec = (
4545
line = Line(Point(0, 0, 0), Point(1, 1, 1)),
4646
plane = Plane(Point(0, 0, 0), Vec(0, 0, 1)),
4747
ray = Ray(Point(0, 0, 0), Vec(0, 0, 1)),
48+
rope = Rope([Point(t, t, t) for t in 1:32]...),
4849
triangle = Triangle(Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1)),
4950
tetrahedron = let
5051
a = Point(0, 3, 0)
@@ -64,6 +65,7 @@ SUITE["Specializations/Scalar GaussLegendre"] = let s = BenchmarkGroup()
6465
s["Line"] = @benchmarkable integral($spec.f_exp, $spec.g.line, $spec.rule_gl)
6566
s["Plane"] = @benchmarkable integral($spec.f_exp, $spec.g.plane, $spec.rule_gl)
6667
s["Ray"] = @benchmarkable integral($spec.f_exp, $spec.g.ray, $spec.rule_gl)
68+
s["Rope"] = @benchmarkable integral($spec.f, $spec.g.rope, $spec.rule_gl)
6769
s["Triangle"] = @benchmarkable integral($spec.f, $spec.g.triangle, $spec.rule_gl)
6870
s["Tetrahedron"] = @benchmarkable integral($spec.f, $spec.g.tetrahedron, $spec.rule_gl)
6971
s
@@ -82,5 +84,14 @@ SUITE["Differentials"] = let s = BenchmarkGroup()
8284
s
8385
end
8486

87+
############################################################################################
88+
# Integration Rules
89+
###########################################################################################
90+
91+
SUITE["Rules"] = let s = BenchmarkGroup()
92+
s["GaussLegendre"] = @benchmarkable GaussLegendre($1000)
93+
s
94+
end
95+
8596
#tune!(SUITE)
8697
#run(SUITE, verbose=true)

src/integral.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,16 @@ function _integral(
7575
N = Meshes.paramdim(geometry)
7676

7777
# Get Gauss-Legendre nodes and weights of type FP for a region [-1,1]ᴺ
78-
xs, ws = FastGaussQuadrature.gausslegendre(rule.n)
79-
xsFP = Iterators.map(FP, xs)
80-
wsFP = Iterators.map(FP, ws)
81-
weight_grid = Iterators.product(ntuple(Returns(wsFP), N)...)
82-
node_grid = Iterators.product(ntuple(Returns(xsFP), N)...)
78+
xs = Iterators.map(FP, rule.nodes)
79+
ws = Iterators.map(FP, rule.weights)
80+
weight_grid = Iterators.product(ntuple(Returns(ws), N)...)
81+
node_grid = Iterators.product(ntuple(Returns(xs), N)...)
8382

8483
# Domain transformation: x [-1,1] ↦ t [0,1]
8584
t(x) = (1 // 2) * x + (1 // 2)
8685

8786
function integrand((weights, nodes))
88-
# Transforms nodes/xs, store in an NTuple
87+
# ts = t.(nodes), but non-allocating
8988
ts = ntuple(i -> t(nodes[i]), length(nodes))
9089
# Integrand function
9190
prod(weights) * f(geometry(ts...)) * differential(geometry, ts, diff_method)

src/integration_rules.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ e.g. `length(geometry)/λ`.
3333
"""
3434
struct GaussLegendre <: IntegrationRule
3535
n::Int64
36+
nodes::Vector{Float64}
37+
weights::Vector{Float64}
38+
39+
GaussLegendre(n::Int64) = new(n, FastGaussQuadrature.gausslegendre(n)...)
3640
end
3741

3842
"""

0 commit comments

Comments
 (0)