Skip to content

Commit 2be6175

Browse files
JoshuaLampertgithub-actions[bot]mikeingold
authored
Add tests for ParametrizedCurve (#105)
* add tests for ParametrizedCurve * update support matrix * only run tests for newer Meshes version * fix typo * Update test/combinations.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix typo in version number * use norm * Update test/combinations.jl Co-authored-by: Michael Ingold <[email protected]> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Michael Ingold <[email protected]>
1 parent d2371a6 commit 2be6175

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

docs/src/supportmatrix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Cubature integration rules are recommended (and the default).
4040
| `Hexahedron` ||||
4141
| `Line` ||||
4242
| `ParaboloidSurface` ||||
43+
| `ParametrizedCurve` ||||
4344
| `Plane` ||||
4445
| `Polyarea` | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/28) | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/28) | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/28) |
4546
| `Pyramid` | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/28) | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/28) | [🎗️](https://github.com/mikeingold/MeshIntegrals.jl/issues/28) |

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3+
CoordRefSystems = "b46f11dc-f210-4604-bfba-323c1ec968cb"
34
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
45
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
56
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
@@ -12,6 +13,7 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
1213

1314
[compat]
1415
Aqua = "0.7, 0.8"
16+
CoordRefSystems = "0.12, 0.13, 0.14, 0.15"
1517
ExplicitImports = "1.6.0"
1618
LinearAlgebra = "1"
1719
Meshes = "0.50, 0.51"

test/combinations.jl

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,54 @@ end
516516
@test_throws "not supported" volumeintegral(f, parab)
517517
end
518518

519+
@testitem "ParametrizedCurve" setup=[Setup] begin
520+
# ParametrizedCurve has been added in Meshes v0.51.20
521+
# If the version is specified as minimal compat bound in the Project.toml, the downgrade test fails
522+
if pkgversion(Meshes) >= v"0.51.20"
523+
using CoordRefSystems: Polar
524+
using LinearAlgebra: norm
525+
526+
# Parameterize a circle centered on origin with specified radius
527+
radius = 4.4
528+
curve_cart = ParametrizedCurve(
529+
t -> Point(radius * cos(t), radius * sin(t)), (0.0, 2π))
530+
curve_polar = ParametrizedCurve(t -> Point(Polar(radius, t)), (0.0, 2π))
531+
532+
function f(p::P) where {P <: Meshes.Point}
533+
ur = norm(to(p))
534+
r = ustrip(u"m", ur)
535+
exp(-r^2)
536+
end
537+
fv(p) = fill(f(p), 3)
538+
539+
# Scalar integrand
540+
sol = 2π * radius * exp(-radius^2) * u"m"
541+
@test integral(f, curve_cart, GaussLegendre(100)) sol
542+
@test integral(f, curve_cart, GaussKronrod()) sol
543+
@test integral(f, curve_cart, HAdaptiveCubature()) sol
544+
@test integral(f, curve_polar, GaussLegendre(100)) sol
545+
@test integral(f, curve_polar, GaussKronrod()) sol
546+
@test integral(f, curve_polar, HAdaptiveCubature()) sol
547+
548+
# Vector integrand
549+
vsol = fill(sol, 3)
550+
@test integral(fv, curve_cart, GaussLegendre(100)) vsol
551+
@test integral(fv, curve_cart, GaussKronrod()) vsol
552+
@test integral(fv, curve_cart, HAdaptiveCubature()) vsol
553+
@test integral(fv, curve_polar, GaussLegendre(100)) vsol
554+
@test integral(fv, curve_polar, GaussKronrod()) vsol
555+
@test integral(fv, curve_polar, HAdaptiveCubature()) vsol
556+
557+
# Integral aliases
558+
@test lineintegral(f, curve_cart) sol
559+
@test_throws "not supported" surfaceintegral(f, curve_cart)
560+
@test_throws "not supported" volumeintegral(f, curve_cart)
561+
@test lineintegral(f, curve_polar) sol
562+
@test_throws "not supported" surfaceintegral(f, curve_polar)
563+
@test_throws "not supported" volumeintegral(f, curve_polar)
564+
end
565+
end
566+
519567
@testitem "Meshes.Plane" setup=[Setup] begin
520568
p = Point(0.0u"m", 0.0u"m", 0.0u"m")
521569
v = Vec(0.0u"m", 0.0u"m", 1.0u"m")
@@ -703,13 +751,18 @@ end
703751

704752
@testitem "Meshes.Sphere 2D" setup=[Setup] begin
705753
origin = Point(0, 0)
706-
sphere = Sphere(origin, 4.4)
754+
radius = 4.4
755+
sphere = Sphere(origin, radius)
707756

708-
f(p) = 1.0
757+
function f(p::P) where {P <: Meshes.Point}
758+
ur = hypot(p.coords.x, p.coords.y)
759+
r = ustrip(u"m", ur)
760+
exp(-r^2)
761+
end
709762
fv(p) = fill(f(p), 3)
710763

711764
# Scalar integrand
712-
sol = Meshes.measure(sphere)
765+
sol = 2π * radius * exp(-radius^2) * u"m"
713766
@test integral(f, sphere, GaussLegendre(100)) sol
714767
@test integral(f, sphere, GaussKronrod()) sol
715768
@test integral(f, sphere, HAdaptiveCubature()) sol

0 commit comments

Comments
 (0)