|
516 | 516 | @test_throws "not supported" volumeintegral(f, parab)
|
517 | 517 | end
|
518 | 518 |
|
| 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 | + |
519 | 567 | @testitem "Meshes.Plane" setup=[Setup] begin
|
520 | 568 | p = Point(0.0u"m", 0.0u"m", 0.0u"m")
|
521 | 569 | v = Vec(0.0u"m", 0.0u"m", 1.0u"m")
|
@@ -703,13 +751,18 @@ end
|
703 | 751 |
|
704 | 752 | @testitem "Meshes.Sphere 2D" setup=[Setup] begin
|
705 | 753 | origin = Point(0, 0)
|
706 |
| - sphere = Sphere(origin, 4.4) |
| 754 | + radius = 4.4 |
| 755 | + sphere = Sphere(origin, radius) |
707 | 756 |
|
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 |
709 | 762 | fv(p) = fill(f(p), 3)
|
710 | 763 |
|
711 | 764 | # Scalar integrand
|
712 |
| - sol = Meshes.measure(sphere) |
| 765 | + sol = 2π * radius * exp(-radius^2) * u"m" |
713 | 766 | @test integral(f, sphere, GaussLegendre(100)) ≈ sol
|
714 | 767 | @test integral(f, sphere, GaussKronrod()) ≈ sol
|
715 | 768 | @test integral(f, sphere, HAdaptiveCubature()) ≈ sol
|
|
0 commit comments