44
55@testitem " Meshes.Ball 2D" setup= [Setup] begin
66 origin = Point (0 , 0 )
7- ball = Ball (origin, 2.8 )
7+ radius = 2.8
8+ ball = Ball (origin, radius)
89
9- f (p) = 1.0
10+ function f (p:: P ) where {P <: Meshes.Point }
11+ r = ustrip (u " m" , norm (to (p)))
12+ exp (- r^ 2 )
13+ end
1014 fv (p) = fill (f (p), 3 )
1115
1216 # Scalar integrand
13- sol = Meshes . measure (ball)
17+ sol = (π - π * exp ( - radius ^ 2 )) * u " m^2 "
1418 @test integral (f, ball, GaussLegendre (100 )) ≈ sol
1519 @test integral (f, ball, GaussKronrod ()) ≈ sol
1620 @test integral (f, ball, HAdaptiveCubature ()) ≈ sol
2832end
2933
3034@testitem " Meshes.Ball 3D" setup= [Setup] begin
31- origin = Point (0 , 0 , 0 )
32- ball = Ball (origin, 2.8 )
35+ using SpecialFunctions: erf
3336
34- f (p) = 1.0
37+ center = Point (1 , 2 , 3 )
38+ radius = 2.8 u " m"
39+ ball = Ball (center, radius)
40+
41+ function f (p:: P ) where {P <: Meshes.Point }
42+ offset = p - center
43+ ur = norm (offset)
44+ r = ustrip (u " m" , ur)
45+ exp (- r^ 2 )
46+ end
3547 fv (p) = fill (f (p), 3 )
3648
3749 # Scalar integrand
38- sol = Meshes. measure (ball)
50+ r = ustrip (u " m" , radius)
51+ sol = (π^ (3 / 2 ) * erf (r) - 2 π * exp (- r^ 2 ) * r) * u " m^3"
3952 @test integral (f, ball, GaussLegendre (100 )) ≈ sol
4053 @test_throws " not supported" integral (f, ball, GaussKronrod ())≈ sol
4154 @test integral (f, ball, HAdaptiveCubature ()) ≈ sol
@@ -201,16 +214,21 @@ end
201214end
202215
203216@testitem " Meshes.Circle" setup= [Setup] begin
204- origin = Point (0 , 0 , 0 )
205- ẑ = Vec (0 , 0 , 1 )
206- xy_plane = Plane (origin, ẑ)
207- circle = Circle (xy_plane, 2.5 )
217+ center = Point (1 , 2 , 3 )
218+ n̂ = Vec (1 / 2 , 1 / 2 , sqrt (2 ) / 2 )
219+ plane = Plane (center, n̂)
220+ radius = 4.4
221+ circle = Circle (plane, radius)
208222
209- f (p) = 1.0
223+ function f (p:: P ) where {P <: Meshes.Point }
224+ offset = p - center
225+ r = ustrip (u " m" , norm (offset))
226+ exp (- r^ 2 )
227+ end
210228 fv (p) = fill (f (p), 3 )
211229
212230 # Scalar integrand
213- sol = Meshes . measure (circle)
231+ sol = 2 π * radius * exp ( - radius ^ 2 ) * u " m "
214232 @test integral (f, circle, GaussLegendre (100 )) ≈ sol
215233 @test integral (f, circle, GaussKronrod ()) ≈ sol
216234 @test integral (f, circle, HAdaptiveCubature ()) ≈ sol
@@ -344,16 +362,21 @@ end
344362end
345363
346364@testitem " Meshes.Disk" setup= [Setup] begin
347- origin = Point (0 , 0 , 0 )
348- ẑ = Vec (0 , 0 , 1 )
349- xy_plane = Plane (origin, ẑ)
350- disk = Disk (xy_plane, 2.5 )
365+ center = Point (1 , 2 , 3 )
366+ n̂ = Vec (1 / 2 , 1 / 2 , sqrt (2 ) / 2 )
367+ plane = Plane (center, n̂)
368+ radius = 2.5
369+ disk = Disk (plane, radius)
351370
352- f (p) = 1.0
371+ function f (p:: P ) where {P <: Meshes.Point }
372+ offset = p - center
373+ r = ustrip (u " m" , norm (offset))
374+ exp (- r^ 2 )
375+ end
353376 fv (p) = fill (f (p), 3 )
354377
355378 # Scalar integrand
356- sol = Meshes . measure (disk)
379+ sol = (π - π * exp ( - radius ^ 2 )) * u " m^2 "
357380 @test integral (f, disk, GaussLegendre (100 )) ≈ sol
358381 @test integral (f, disk, GaussKronrod ()) ≈ sol
359382 @test integral (f, disk, HAdaptiveCubature ()) ≈ sol
467490 line = Line (a, b)
468491
469492 function f (p:: P ) where {P <: Meshes.Point }
470- ur = hypot (p. coords. x, p. coords. y, p. coords. z)
471- r = ustrip (u " m" , ur)
493+ r = ustrip (u " m" , norm (to (p)))
472494 exp (- r^ 2 )
473495 end
474496 fv (p) = fill (f (p), 3 )
521543 # If the version is specified as minimal compat bound in the Project.toml, the downgrade test fails
522544 if pkgversion (Meshes) >= v " 0.51.20"
523545 using CoordRefSystems: Polar
524- using LinearAlgebra: norm
525546
526547 # Parameterize a circle centered on origin with specified radius
527548 radius = 4.4
570591 plane = Plane (p, v)
571592
572593 function f (p:: P ) where {P <: Meshes.Point }
573- ur = hypot (p. coords. x, p. coords. y, p. coords. z)
574- r = ustrip (u " m" , ur)
594+ r = ustrip (u " m" , norm (to (p)))
575595 exp (- r^ 2 )
576596 end
577597 fv (p) = fill (f (p), 3 )
599619 quadrangle = Quadrangle ((- 1.0 , 0.0 ), (- 1.0 , 1.0 ), (1.0 , 1.0 ), (1.0 , 0.0 ))
600620
601621 function f (p:: P ) where {P <: Meshes.Point }
602- ur = hypot (p. coords. x, p. coords. y)
603- r = ustrip (u " m" , ur)
622+ r = ustrip (u " m" , norm (to (p)))
604623 exp (- r^ 2 )
605624 end
606625 fv (p) = fill (f (p), 3 )
629648 ray = Ray (a, v)
630649
631650 function f (p:: P ) where {P <: Meshes.Point }
632- ur = hypot (p. coords. x, p. coords. y, p. coords. z)
633- r = ustrip (u " m" , ur)
651+ r = ustrip (u " m" , norm (to (p)))
634652 exp (- r^ 2 )
635653 end
636654 fv (p) = fill (f (p), 3 )
725743 a, b = (7.1 , 4.6 ) # arbitrary constants > 0
726744
727745 function f (p:: P ) where {P <: Meshes.Point }
728- ur = hypot (p. coords. x, p. coords. y, p. coords. z)
729- r = ustrip (u " m" , ur)
746+ r = ustrip (u " m" , norm (to (p)))
730747 exp (r * log (a) + (1 - r) * log (b))
731748 end
732749 fv (p) = fill (f (p), 3 )
755772 sphere = Sphere (origin, radius)
756773
757774 function f (p:: P ) where {P <: Meshes.Point }
758- ur = hypot (p. coords. x, p. coords. y)
759- r = ustrip (u " m" , ur)
775+ r = ustrip (u " m" , norm (to (p)))
760776 exp (- r^ 2 )
761777 end
762778 fv (p) = fill (f (p), 3 )
@@ -780,14 +796,23 @@ end
780796end
781797
782798@testitem " Meshes.Sphere 3D" setup= [Setup] begin
783- origin = Point (0 , 0 , 0 )
784- sphere = Sphere (origin, 4.4 )
799+ using CoordRefSystems: Cartesian, Spherical
785800
786- f (p) = 1.0
801+ center = Point (1 , 2 , 3 )
802+ radius = 4.4 u " m"
803+ sphere = Sphere (center, radius)
804+
805+ function f (p:: P ) where {P <: Meshes.Point }
806+ rθφ = convert (Spherical, Cartesian ((p - center). .. ))
807+ r = ustrip (rθφ. r)
808+ θ = ustrip (rθφ. θ)
809+ φ = ustrip (rθφ. ϕ)
810+ sin (φ)^ 2 + cos (θ)^ 2
811+ end
787812 fv (p) = fill (f (p), 3 )
788813
789814 # Scalar integrand
790- sol = Meshes . measure (sphere )
815+ sol = ( 2 π * radius ^ 2 ) + ( 4 π / 3 * radius ^ 2 )
791816 @test integral (f, sphere, GaussLegendre (100 )) ≈ sol
792817 @test integral (f, sphere, GaussKronrod ()) ≈ sol
793818 @test integral (f, sphere, HAdaptiveCubature ()) ≈ sol
0 commit comments