From fa6b44da37a268468df483e434f1e6f4f6d8808e Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 15:53:17 -0400 Subject: [PATCH 01/13] Move Line and Ray to new test section --- test/runtests.jl | 95 ++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index c4fc6943..47440368 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -143,53 +143,6 @@ end map(autotest, SUPPORT_MATRIX(Float64)) end - @testset "Float32 Geometries" begin - # TODO temp disabled, see Issue #33 - #map(autotest, SUPPORT_MATRIX(Float64)) - end - - # Custom tests for Line (no measure available for reference) - @testset "Meshes.Line" begin - line = Line(pt_e(Float64), pt_w(Float64)) - - function f(p::P) where {P<:Meshes.Point} - x = ustrip(u"m", p.coords.x) - y = ustrip(u"m", p.coords.y) - z = ustrip(u"m", p.coords.z) - exp(-x^2) - end - fv(p) = fill(f(p),3) - - @test integral(f, line, GaussLegendre(100)) ≈ sqrt(π)*u"m" - @test integral(f, line, GaussKronrod()) ≈ sqrt(π)*u"m" - @test integral(f, line, HAdaptiveCubature()) ≈ sqrt(π)*u"m" - - @test integral(fv, line, GaussLegendre(100)) ≈ fill(sqrt(π)*u"m",3) - @test integral(fv, line, GaussKronrod()) ≈ fill(sqrt(π)*u"m",3) - @test integral(fv, line, HAdaptiveCubature()) ≈ fill(sqrt(π)*u"m",3) - end - - # Custom tests for Ray (no measure available for reference) - @testset "Meshes.Ray" begin - ray = Ray(origin3d(Float64), ẑ(Float64)) - - function f(p::P) where {P<:Meshes.Point} - x = ustrip(u"m", p.coords.x) - y = ustrip(u"m", p.coords.y) - z = ustrip(u"m", p.coords.z) - 2 * exp(-z^2) - end - fv(p) = fill(f(p),3) - - @test integral(f, ray, GaussLegendre(100)) ≈ sqrt(π)*u"m" - @test integral(f, ray, GaussKronrod()) ≈ sqrt(π)*u"m" - @test integral(f, ray, HAdaptiveCubature()) ≈ sqrt(π)*u"m" - - @test integral(fv, ray, GaussLegendre(100)) ≈ fill(sqrt(π)*u"m",3) - @test integral(fv, ray, GaussKronrod()) ≈ fill(sqrt(π)*u"m",3) - @test integral(fv, ray, HAdaptiveCubature()) ≈ fill(sqrt(π)*u"m",3) - end - # Custom tests for Plane (no measure available for reference) @testset "Meshes.Plane" begin plane = Plane(origin3d(Float64), ẑ(Float64)) @@ -304,6 +257,54 @@ end =# end +@testset "New Independent Tests" begin + + @testset "Meshes.Line" begin + a = Point(0.0u"m", 0.0u"m", 0.0u"m") + b = Point(1.0u"m", 1.0u"m", 1.0u"m") + line = Line(a, b) + + function f(p::P) where {P<:Meshes.Point} + ur = hypot(p.coords.x, p.coords.y, p.coords.z) + r = ustrip(u"m", ur) + exp(-r^2) + end + fv(p) = fill(f(p), 3) + sol = sqrt(π) * u"m" + vsol = fill(sol, 3) + + @test integral(f, line, GaussLegendre(100)) ≈ sol + @test integral(f, line, GaussKronrod()) ≈ sol + @test integral(f, line, HAdaptiveCubature()) ≈ sol + @test integral(fv, line, GaussLegendre(100)) ≈ vsol + @test integral(fv, line, GaussKronrod()) ≈ vsol + @test integral(fv, line, HAdaptiveCubature()) ≈ vsol + end + + @testset "Meshes.Ray" begin + a = Point(0.0u"m", 0.0u"m", 0.0u"m") + v = Vec(1.0u"m", 1.0u"m", 1.0u"m") + ray = Ray(a, v) + + function f(p::P) where {P<:Meshes.Point} + ur = hypot(p.coords.x, p.coords.y, p.coords.z) + r = ustrip(u"m", ur) + exp(-r^2) + end + fv(p) = fill(f(p), 3) + sol = sqrt(π) / 2 * u"m" + vsol = fill(sol, 3) + + @test integral(f, ray, GaussLegendre(100)) ≈ sol + @test integral(f, ray, GaussKronrod()) ≈ sol + @test integral(f, ray, HAdaptiveCubature()) ≈ sol + @test integral(fv, ray, GaussLegendre(100)) ≈ vsol + @test integral(fv, ray, GaussKronrod()) ≈ vsol + @test integral(fv, ray, HAdaptiveCubature()) ≈ vsol + end + +end + ################################################################################ # Aqua.jl Tests ################################################################################ From 3c562881af5495cd7b30b88118edf05dba372070 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 16:00:15 -0400 Subject: [PATCH 02/13] Reorganize structure --- test/runtests.jl | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 47440368..67242037 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -270,15 +270,23 @@ end exp(-r^2) end fv(p) = fill(f(p), 3) - sol = sqrt(π) * u"m" - vsol = fill(sol, 3) + # Scalar integrand + sol = sqrt(π) * u"m" @test integral(f, line, GaussLegendre(100)) ≈ sol @test integral(f, line, GaussKronrod()) ≈ sol @test integral(f, line, HAdaptiveCubature()) ≈ sol + + # Vector integrand + vsol = fill(sol, 3) @test integral(fv, line, GaussLegendre(100)) ≈ vsol @test integral(fv, line, GaussKronrod()) ≈ vsol @test integral(fv, line, HAdaptiveCubature()) ≈ vsol + + # Integral aliases + @test lineintegral(f, line) ≈ sol + @test_throws "not supported" surfaceintegral(f, line) + @test_throws "not supported" volumeintegral(f, line) end @testset "Meshes.Ray" begin @@ -292,15 +300,23 @@ end exp(-r^2) end fv(p) = fill(f(p), 3) - sol = sqrt(π) / 2 * u"m" - vsol = fill(sol, 3) + # Scalar integrand + sol = sqrt(π) / 2 * u"m" @test integral(f, ray, GaussLegendre(100)) ≈ sol @test integral(f, ray, GaussKronrod()) ≈ sol @test integral(f, ray, HAdaptiveCubature()) ≈ sol + + # Vector integrand + vsol = fill(sol, 3) @test integral(fv, ray, GaussLegendre(100)) ≈ vsol @test integral(fv, ray, GaussKronrod()) ≈ vsol @test integral(fv, ray, HAdaptiveCubature()) ≈ vsol + + # Integral aliases + @test lineintegral(f, line) ≈ sol + @test_throws "not supported" surfaceintegral(f, line) + @test_throws "not supported" volumeintegral(f, line) end end From cd0fe87818d593fd1041f3ddabb95b195cf2932f Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 16:04:20 -0400 Subject: [PATCH 03/13] Partition Aqua.jl tests into their own section --- test/runtests.jl | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 67242037..b6ab2ddc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,13 +1,26 @@ +################################################################################ +# Aqua.jl Tests +################################################################################ + using Aqua -using MeshIntegrals -using Meshes -using Test -using Unitful + +@testset "Aqua.jl" begin + # As of v0.11.4: + # - Ambiguities check disabled since it fails due to upstream findings + # - Verified that no ambiguities exist within MeshIntegrals.jl + Aqua.test_all(MeshIntegrals; ambiguities=false) +end + ################################################################################ # Infrastructure ################################################################################ +using MeshIntegrals +using Meshes +using Test +using Unitful + struct SupportItem{T, Dim, CRS, G<:Meshes.Geometry{Meshes.𝔼{Dim},CRS}} name::String type::Type{T} @@ -257,6 +270,11 @@ end =# end + +################################################################################ +# New Tests +################################################################################ + @testset "New Independent Tests" begin @testset "Meshes.Line" begin @@ -320,13 +338,3 @@ end end end - -################################################################################ -# Aqua.jl Tests -################################################################################ - -@testset "Aqua.jl" begin - # As of v0.11.4 -- Ambiguities check disabled since it fails due to upstream findings - # Verified that no ambiguities exist within MeshIntegrals.jl - Aqua.test_all(MeshIntegrals; ambiguities=false) -end From 76927064fa86fe9d0be8b6403657e8ebf6c183c4 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 16:07:19 -0400 Subject: [PATCH 04/13] Bugfix --- test/runtests.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index b6ab2ddc..d70b1933 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,9 +1,14 @@ +using Aqua +using Meshes +using MeshIntegrals +using Test +using Unitful + + ################################################################################ # Aqua.jl Tests ################################################################################ -using Aqua - @testset "Aqua.jl" begin # As of v0.11.4: # - Ambiguities check disabled since it fails due to upstream findings @@ -16,11 +21,6 @@ end # Infrastructure ################################################################################ -using MeshIntegrals -using Meshes -using Test -using Unitful - struct SupportItem{T, Dim, CRS, G<:Meshes.Geometry{Meshes.𝔼{Dim},CRS}} name::String type::Type{T} From 71c412f5f28f8e0025a0162541895722b45f4841 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 16:14:04 -0400 Subject: [PATCH 05/13] Update Plane tests --- test/runtests.jl | 51 ++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index d70b1933..b7e46e63 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -156,27 +156,6 @@ end map(autotest, SUPPORT_MATRIX(Float64)) end - # Custom tests for Plane (no measure available for reference) - @testset "Meshes.Plane" begin - plane = Plane(origin3d(Float64), ẑ(Float64)) - - function f(p::P) where {P<:Meshes.Point} - x = ustrip(u"m", p.coords.x) - y = ustrip(u"m", p.coords.y) - z = ustrip(u"m", p.coords.z) - exp(-x^2 - y^2) - end - fv(p) = fill(f(p),3) - - @test integral(f, plane, GaussLegendre(100)) ≈ π*u"m^2" - @test integral(f, plane, GaussKronrod()) ≈ π*u"m^2" - @test integral(f, plane, HAdaptiveCubature()) ≈ π*u"m^2" - - @test integral(fv, plane, GaussLegendre(100)) ≈ fill(π*u"m^2",3) - @test integral(fv, plane, GaussKronrod()) ≈ fill(π*u"m^2",3) - @test integral(fv, plane, HAdaptiveCubature()) ≈ fill(π*u"m^2",3) - end - # Custom tests for Cone @testset "Meshes.Cone" begin T = Float64 @@ -307,6 +286,36 @@ end @test_throws "not supported" volumeintegral(f, line) end + @testset "Meshes.Plane" begin + p = Point(0.0u"m", 0.0u"m", 0.0u"m") + v = Vec(0.0u"m", 0.0u"m", 1.0u"m") + plane = Plane(p, v) + + function f(p::P) where {P<:Meshes.Point} + ur = hypot(p.coords.x, p.coords.y, p.coords.z) + r = ustrip(u"m", ur) + exp(-r^2) + end + fv(p) = fill(f(p), 3) + + # Scalar integrand + sol = π * u"m^2" + @test integral(f, plane, GaussLegendre(100)) ≈ sol + @test integral(f, plane, GaussKronrod()) ≈ sol + @test integral(f, plane, HAdaptiveCubature()) ≈ sol + + # Vector integrand + vsol = fill(sol, 3) + @test integral(fv, plane, GaussLegendre(100)) ≈ vsol + @test integral(fv, plane, GaussKronrod()) ≈ vsol + @test integral(fv, plane, HAdaptiveCubature()) ≈ vsol + + # Integral aliases + @test_throws "not supported" lineintegral(f, plane) + @test surfaceintegral(f, plane) ≈ sol + @test_throws "not supported" volumeintegral(f, plane) + end + @testset "Meshes.Ray" begin a = Point(0.0u"m", 0.0u"m", 0.0u"m") v = Vec(1.0u"m", 1.0u"m", 1.0u"m") From 905e67b745e8deba1bcd9bd090e0e08a5e7fca8f Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 16:31:59 -0400 Subject: [PATCH 06/13] Bugfix --- test/runtests.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index b7e46e63..9161e653 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -341,9 +341,9 @@ end @test integral(fv, ray, HAdaptiveCubature()) ≈ vsol # Integral aliases - @test lineintegral(f, line) ≈ sol - @test_throws "not supported" surfaceintegral(f, line) - @test_throws "not supported" volumeintegral(f, line) + @test lineintegral(f, ray) ≈ sol + @test_throws "not supported" surfaceintegral(f, ray) + @test_throws "not supported" volumeintegral(f, ray) end end From 5534b7b660d5246654414874b1887d3a619277c1 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 17:12:36 -0400 Subject: [PATCH 07/13] Improved Cone tests --- test/runtests.jl | 58 ++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 9161e653..cd4d3285 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -156,33 +156,6 @@ end map(autotest, SUPPORT_MATRIX(Float64)) end - # Custom tests for Cone - @testset "Meshes.Cone" begin - T = Float64 - - cone_r = T(2.5) - cone_h = T(2.5) - - cone = let - base = Disk(plane_xy(T), cone_r) - Cone(base, Point(0, 0, cone_h)) - end - - f(p) = T(1) - fv(p) = fill(f(p), 3) - - _volume_cone_rightcircular(h, r) = T(π) * r^2 * h / 3 - cone_volume = _volume_cone_rightcircular(cone_r * u"m", cone_h * u"m") - - @test integral(f, cone, GaussLegendre(100)) ≈ cone_volume - @test_throws "not supported" integral(f, cone, GaussKronrod()) - @test integral(f, cone, HAdaptiveCubature()) ≈ cone_volume - - @test integral(fv, cone, GaussLegendre(100)) ≈ fill(cone_volume, 3) - @test_throws "not supported" integral(fv, cone, GaussKronrod()) - @test integral(fv, cone, HAdaptiveCubature()) ≈ fill(cone_volume, 3) - end - # Custom tests for ConeSurface @testset "Meshes.ConeSurface" begin T = Float64 @@ -256,6 +229,37 @@ end @testset "New Independent Tests" begin + @testset "Meshes.Cone" begin + r = 2.5u"m" + h = 2.5u"m" + origin = Point(0, 0, 0) + xy_plane = Plane(origin, Vec(0, 0, 1)) + base = Disk(xy_plane, r) + cone = Cone(base, Point(0, 0, h)) + + f(p) = 1.0 + fv(p) = fill(f(p), 3) + + _volume_cone_rightcircular(h, r) = π * r^2 * h / 3 + + # Scalar integrand + sol = _volume_cone_rightcircular(r, h) + @test integral(f, cone, GaussLegendre(100)) ≈ sol + @test_throws "not supported" integral(f, cone, GaussKronrod()) + @test integral(f, cone, HAdaptiveCubature()) ≈ sol + + # Vector integrand + vsol = fill(sol, 3) + @test integral(fv, cone, GaussLegendre(100)) ≈ vsol + @test_throws "not supported" integral(fv, cone, GaussKronrod()) + @test integral(fv, cone, HAdaptiveCubature()) ≈ vsol + + # Integral aliases + @test_throws "not supported" lineintegral(f, cone) + @test_throws "not supported" surfaceintegral(f, cone) + @test volumeintegral(f, cone) ≈ sol + end + @testset "Meshes.Line" begin a = Point(0.0u"m", 0.0u"m", 0.0u"m") b = Point(1.0u"m", 1.0u"m", 1.0u"m") From 445a510f892b5e544a54b8548967eeb0044378e5 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 19:13:48 -0400 Subject: [PATCH 08/13] Bugfix --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index cd4d3285..75374999 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -165,7 +165,7 @@ end cone = let base = Disk(plane_xy(T), cone_r) - ConeSurface(base, Point(0, 0, cone_h)) + ConeSurface(base, Point(0.0u"m", 0.0u"m", cone_h)) end f(p) = T(1) From 248b32a26630513203b265590b0241fe47394672 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 20:08:58 -0400 Subject: [PATCH 09/13] Improved ConeSurface tests and bugfix --- test/runtests.jl | 120 +++++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 57 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 75374999..93433dd7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -155,32 +155,77 @@ end @testset "Float64 Geometries" begin map(autotest, SUPPORT_MATRIX(Float64)) end +end - # Custom tests for ConeSurface - @testset "Meshes.ConeSurface" begin - T = Float64 + +################################################################################ +# New Tests +################################################################################ - cone_r = T(2.5) - cone_h = T(2.5) +@testset "New Independent Tests" begin - cone = let - base = Disk(plane_xy(T), cone_r) - ConeSurface(base, Point(0.0u"m", 0.0u"m", cone_h)) - end + @testset "Meshes.Cone" begin + r = 2.5u"m" + h = 2.5u"m" + origin = Point(0, 0, 0) + xy_plane = Plane(origin, Vec(0, 0, 1)) + base = Disk(xy_plane, r) + apex = Point(0.0u"m", 0.0u"m", h) + cone = Cone(base, apex) - f(p) = T(1) + f(p) = 1.0 fv(p) = fill(f(p), 3) - _area_cone_rightcircular(h, r) = T(π) * r^2 + T(π) * r * hypot(h, r) - cone_area = _area_cone_rightcircular(cone_r * u"m", cone_h * u"m") + _volume_cone_rightcircular(h, r) = π * r^2 * h / 3 + + # Scalar integrand + sol = _volume_cone_rightcircular(r, h) + @test integral(f, cone, GaussLegendre(100)) ≈ sol + @test_throws "not supported" integral(f, cone, GaussKronrod()) + @test integral(f, cone, HAdaptiveCubature()) ≈ sol + + # Vector integrand + vsol = fill(sol, 3) + @test integral(fv, cone, GaussLegendre(100)) ≈ vsol + @test_throws "not supported" integral(fv, cone, GaussKronrod()) + @test integral(fv, cone, HAdaptiveCubature()) ≈ vsol + + # Integral aliases + @test_throws "not supported" lineintegral(f, cone) + @test_throws "not supported" surfaceintegral(f, cone) + @test volumeintegral(f, cone) ≈ sol + end + + @testset "Meshes.ConeSurface" begin + r = 2.5u"m" + h = 2.5u"m" + origin = Point(0, 0, 0) + xy_plane = Plane(origin, Vec(0, 0, 1)) + base = Disk(xy_plane, r) + apex = Point(0.0u"m", 0.0u"m", h) + cone = ConeSurface(base, apex) + + f(p) = 1.0 + fv(p) = fill(f(p), 3) + + _area_cone_rightcircular(h, r) = (π * r^2) + (π * r * hypot(h, r)) - @test integral(f, cone, GaussLegendre(100)) ≈ cone_area - @test integral(f, cone, GaussKronrod()) ≈ cone_area - @test integral(f, cone, HAdaptiveCubature()) ≈ cone_area + # Scalar integrand + sol = _area_cone_rightcircular(h, r) + @test integral(f, cone, GaussLegendre(100)) ≈ sol + @test integral(f, cone, GaussKronrod()) ≈ sol + @test integral(f, cone, HAdaptiveCubature()) ≈ sol + + # Vector integrand + vsol = fill(sol, 3) + @test integral(fv, cone, GaussLegendre(100)) ≈ vsol + @test integral(fv, cone, GaussKronrod()) ≈ vsol + @test integral(fv, cone, HAdaptiveCubature()) ≈ vsol - @test integral(fv, cone, GaussLegendre(100)) ≈ fill(cone_area, 3) - @test integral(fv, cone, GaussKronrod()) ≈ fill(cone_area, 3) - @test integral(fv, cone, HAdaptiveCubature()) ≈ fill(cone_area, 3) + # Integral aliases + @test_throws "not supported" lineintegral(f, cone) + @test surfaceintegral(f, cone) ≈ sol + @test_throws "not supported" volumeintegral(f, cone) end #= DISABLED FrustumSurface testing due to long run times and seemingly-incorrect results @@ -220,45 +265,6 @@ end @test integral(fv, frustum, HAdaptiveCubature()) ≈ fill(frustum_area, 3) end =# -end - - -################################################################################ -# New Tests -################################################################################ - -@testset "New Independent Tests" begin - - @testset "Meshes.Cone" begin - r = 2.5u"m" - h = 2.5u"m" - origin = Point(0, 0, 0) - xy_plane = Plane(origin, Vec(0, 0, 1)) - base = Disk(xy_plane, r) - cone = Cone(base, Point(0, 0, h)) - - f(p) = 1.0 - fv(p) = fill(f(p), 3) - - _volume_cone_rightcircular(h, r) = π * r^2 * h / 3 - - # Scalar integrand - sol = _volume_cone_rightcircular(r, h) - @test integral(f, cone, GaussLegendre(100)) ≈ sol - @test_throws "not supported" integral(f, cone, GaussKronrod()) - @test integral(f, cone, HAdaptiveCubature()) ≈ sol - - # Vector integrand - vsol = fill(sol, 3) - @test integral(fv, cone, GaussLegendre(100)) ≈ vsol - @test_throws "not supported" integral(fv, cone, GaussKronrod()) - @test integral(fv, cone, HAdaptiveCubature()) ≈ vsol - - # Integral aliases - @test_throws "not supported" lineintegral(f, cone) - @test_throws "not supported" surfaceintegral(f, cone) - @test volumeintegral(f, cone) ≈ sol - end @testset "Meshes.Line" begin a = Point(0.0u"m", 0.0u"m", 0.0u"m") From f45d7bb494d20531b3307603df35ea681b28684b Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 20:28:08 -0400 Subject: [PATCH 10/13] Bugfix - use of wrong default algorithms for surface and volume --- src/integral_aliases.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/integral_aliases.jl b/src/integral_aliases.jl index 2cf0de70..92da3349 100644 --- a/src/integral_aliases.jl +++ b/src/integral_aliases.jl @@ -84,7 +84,7 @@ function surfaceintegral( Dim = Meshes.paramdim(geometry) if Dim == 2 - return integral(f, geometry, GaussKronrod()) + return integral(f, geometry, HAdaptiveCubature()) else error("Performing a surface integral on a geometry with $Dim parametric dimensions not supported.") end @@ -145,7 +145,7 @@ function volumeintegral( Dim = Meshes.paramdim(geometry) if Dim == 3 - return integral(f, geometry, GaussKronrod()) + return integral(f, geometry, HAdaptiveCubature()) else error("Performing a volume integral on a geometry with $Dim parametric dimensions not supported.") end From 246c5fb2e450e83d0ff3c0f7974e38e93804464e Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sat, 7 Sep 2024 23:42:44 -0400 Subject: [PATCH 11/13] Re-implement FrustumSurface tests --- test/runtests.jl | 57 ++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 93433dd7..82580b99 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -228,43 +228,44 @@ end @test_throws "not supported" volumeintegral(f, cone) end - #= DISABLED FrustumSurface testing due to long run times and seemingly-incorrect results - # Custom tests for FrustumSurface @testset "Meshes.FrustumSurface" begin - T = Float64 - # Create a frustum whose radius halves at the top, # i.e. the bottom half of a cone by height - bot_r = T(5//2) - top_r = T(5//4) - cone_h = T(2π) - frustum = let - plane_bot = Plane(Point(0,0,0), Vec(0,0,1)) - disk_bot = Disk(plane_bot, bot_r) - plane_top = Plane(Point(0,0,T(0.5)*cone_h), Vec(0,0,1)) - disk_top = Disk(plane_top, top_r) - FrustumSurface(disk_bot, disk_top) - end + r_bot = 2.5u"m" + r_top = 1.25u"m" + cone_h = 2π * u"m" + origin = Point(0, 0, 0) + z = Vec(0, 0, 1) + plane_bot = Plane(origin, z) + disk_bot = Disk(plane_bot, r_bot) + center_top = Point(0.0u"m", 0.0u"m", 0.5cone_h) + plane_top = Plane(center_top, z) + disk_top = Disk(plane_top, r_top) + frustum = FrustumSurface(disk_bot, disk_top) - f(p) = T(1) + f(p) = 1.0 fv(p) = fill(f(p), 3) - _area_cone_rightcircular(h, r) = T(π) * r^2 + T(π) * r * hypot(h, r) - frustum_area = let - area_projected = _area_cone_rightcircular(top_r * u"m", cone_h * u"m") - area_missing = _area_cone_rightcircular(top_r * u"m", T(0.5) * cone_h * u"m") - area_projected - area_missing - end + _area_base(r) = π * r^2 + _area_cone_walls(h, r) = π * r * hypot(h, r) - @test integral(f, frustum, GaussLegendre(100)) ≈ frustum_area - @test integral(f, frustum, GaussKronrod()) ≈ frustum_area - @test integral(f, frustum, HAdaptiveCubature()) ≈ frustum_area + # Scalar integrand + sol = let + area_walls_projected = _area_cone_walls(cone_h, r_bot) + area_walls_missing = _area_cone_walls(0.5cone_h, r_top) + area_walls = area_walls_projected - area_walls_missing + area_walls + _area_base(r_top) + _area_base(r_bot) + end + @test integral(f, frustum, GaussLegendre(100)) ≈ sol + @test integral(f, frustum, GaussKronrod()) ≈ sol + @test integral(f, frustum, HAdaptiveCubature()) ≈ sol - @test integral(fv, frustum, GaussLegendre(100)) ≈ fill(frustum_area, 3) - @test integral(fv, frustum, GaussKronrod()) ≈ fill(frustum_area, 3) - @test integral(fv, frustum, HAdaptiveCubature()) ≈ fill(frustum_area, 3) + # Vector integrand + vsol = fill(sol, 3) + @test integral(fv, frustum, GaussLegendre(100)) ≈ vsol + @test integral(fv, frustum, GaussKronrod()) ≈ vsol + @test integral(fv, frustum, HAdaptiveCubature()) ≈ vsol end - =# @testset "Meshes.Line" begin a = Point(0.0u"m", 0.0u"m", 0.0u"m") From 6d549b951f97f3ac55b6cd60a4e4992ad799f1da Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sun, 8 Sep 2024 11:43:33 -0400 Subject: [PATCH 12/13] Rename new section and clean up some formatting --- test/runtests.jl | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 82580b99..cfb4dbf6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -18,7 +18,7 @@ end ################################################################################ -# Infrastructure +# Automatic test generation ################################################################################ struct SupportItem{T, Dim, CRS, G<:Meshes.Geometry{Meshes.𝔼{Dim},CRS}} @@ -81,10 +81,7 @@ function autotest(item::SupportItem) end end end - -################################################################################ -# Integrals -################################################################################ + @testset "Integrals" begin # Spatial descriptors @@ -130,17 +127,11 @@ end SupportItem("Box{2,$T}", T, box2d(T), 1, 0, 1, 0, 1, 1, 1), SupportItem("Box{3,$T}", T, box3d(T), 1, 0, 0, 1, 1, 0, 1), SupportItem("Circle{$T}", T, circle(T), 1, 1, 0, 0, 1, 1, 1), - # Cone -- custom tests below - # ConeSurface -- custom tests below SupportItem("Cylinder{$T}", T, cyl(T), 1, 0, 0, 1, 1, 0, 1), SupportItem("CylinderSurface{$T}", T, cylsurf(T), 1, 0, 1, 0, 1, 1, 1), SupportItem("Disk{$T}", T, disk(T), 1, 0, 1, 0, 1, 1, 1), # Frustum -- not yet supported - # FrustumSurface -- not yet supported - # Line -- custom tests below SupportItem("ParaboloidSurface{$T}", T, parab(T), 1, 0, 1, 0, 1, 1, 1), - # Plane -- custom tests below - # Ray -- custom tests below SupportItem("Ring{$T}", T, ring(T), 1, 1, 0, 0, 1, 1, 1), SupportItem("Rope{$T}", T, rope(T), 1, 1, 0, 0, 1, 1, 1), SupportItem("Segment{$T}", T, segment(T), 1, 1, 0, 0, 1, 1, 1), @@ -162,7 +153,10 @@ end # New Tests ################################################################################ -@testset "New Independent Tests" begin +@testset "Function-Geometry-Algorithm Combinations" begin +# This section tests for: +# - All supported combinations of integral(f, ::Geometry, ::IntegrationAlgorithm) produce accurate results +# - Invalid applications of integral aliases (e.g. lineintegral) produce a descriptive error @testset "Meshes.Cone" begin r = 2.5u"m" From ad2fbe9f7949de7d4e686c0e49b3954085359b99 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Sun, 8 Sep 2024 11:55:36 -0400 Subject: [PATCH 13/13] Update status for Frustum, add links to relavent Issues --- docs/src/supportmatrix.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/supportmatrix.md b/docs/src/supportmatrix.md index 2afddd81..2aecb630 100644 --- a/docs/src/supportmatrix.md +++ b/docs/src/supportmatrix.md @@ -34,8 +34,8 @@ Cubature integration rules are recommended (and the default). | `Cylinder` | ✅ | 🛑 | ✅ | | `CylinderSurface` | ✅ | ✅ | ✅ | | `Disk` | ✅ | ✅ | ✅ | -| `Frustum` | 🛑 | 🛑 | 🛑 | -| `FrustumSurface` | 🛑 | 🛑 | 🛑 | +| `Frustum` | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/57) | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/57) | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/57) | +| `FrustumSurface` | ✅ | ✅ | ✅ | | `Line` | ✅ | ✅ | ✅ | | `ParaboloidSurface` | ✅ | ✅ | ✅ | | `Plane` | ✅ | ✅ | ✅ | @@ -43,9 +43,9 @@ Cubature integration rules are recommended (and the default). | `Ring` | ✅ | ✅ | ✅ | | `Rope` | ✅ | ✅ | ✅ | | `Segment` | ✅ | ✅ | ✅ | -| `SimpleMesh` | 🎗️ | 🎗️ | 🎗️ | +| `SimpleMesh` | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/27) | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/27) | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/27) | | `Sphere` in `𝔼{2}` | ✅ | ✅ | ✅ | | `Sphere` in `𝔼{3}` | ✅ | ✅ | ✅ | -| `Tetrahedron` in `𝔼{3}` | 🎗️ | ✅ | 🎗️ | +| `Tetrahedron` in `𝔼{3}` | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/40) | ✅ | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/40) | | `Triangle` | ✅ | ✅ | ✅ | | `Torus` | ✅ | ✅ | ✅ |