257257 body = AutoBody (circ)
258258 for i in 2 : 20
259259 body += AutoBody (circ,(x,t)-> x- rand (2 ))
260- @test sizeof (body) == i
260+ @test sizeof (body) ≤ i
261261 end
262262
263263 # test curvature, 2D and 3D
596596 @test all (meanflow1. t .== meanflow2. t)
597597 end
598598 @test_nowarn rm (test_dir, recursive= true )
599+ end
600+ @testset " RigidMap.jl" begin
601+ for T ∈ (Float32,Float64)
602+ # initialize a rigid body
603+ sdf (x,t) = sqrt (sum (abs2,x))- 1
604+ body = AutoBody (sdf, RigidMap (SA{T}[0 ,0 ],T (0 )))
605+ # check sdf
606+ @test all (measure (body,SA{T}[1.5 ,0 ],0 ) .≈ (1 / 2 ,SA{T}[1 ,0 ],SA{T}[0 ,0 ]))
607+ # rotate and add linear velocity
608+ body = setmap (body;θ= T (π/ 4 ),V= SA{T}[1.0 ,0 ])
609+ # check sdf and velocity
610+ @test all (measure (body,SA{T}[1.5 ,0 ],0 ) .≈ (1 / 2 ,SA{T}[1 ,0 ],SA{T}[1 ,0 ]))
611+ # add angular velocity
612+ body = setmap (body;ω= T (0.1 ))
613+ @test all (measure (body,SA{T}[1.5 ,0 ],0 ) .≈ (1 / 2 ,SA{T}[1 ,0 ],SA{T}[1 ,1.5 * 0.1 ]))
614+ # 3D rigid body
615+ body3D = AutoBody (sdf, RigidMap (SA{T}[0 ,0 ,0 ],SA{T}[0 ,0 ,0 ];xₚ= SA{T}[- .5 ,0 ,0 ]))
616+ @test all (measure (body3D,SA{T}[1.5 ,0 ,0 ],0 ) .≈ (1 / 2 ,SA{T}[1 ,0 ,0 ],SA{T}[0 ,0 ,0 ]))
617+ # test rotations about x, y, and z
618+ # rotate by 180 degrees about x-axis, should not change
619+ body3D = setmap (body3D;θ= SA{T}[π,0 ,0 ])
620+ @test all (measure (body3D,SA{T}[1.5 ,0 ,0 ],0 ) .≈ (1 / 2 ,SA{T}[1 ,0 ,0 ],SA{T}[0 ,0 ,0 ]))
621+ # now rotate by 180 around y=axis, should invert z-component of normal
622+ body3D = setmap (body3D;θ= SA{T}[0 ,π,0 ],V= SA{T}[1.0 ,0 ,0 ])
623+ @test all (measure (body3D,SA{T}[1.5 ,0 ,0 ],0 ) .≈ (1.5 ,SA{T}[1 ,0 ,0 ],SA{T}[1 ,0 ,0 ]))
624+ body3D = setmap (body3D;θ= SA{T}[0 ,0 ,π],V= SA{T}[1.0 ,0 ,0 ])
625+ @test all (measure (body3D,SA{T}[1.5 ,0 ,0 ],0 ) .≈ (1.5 ,SA{T}[1 ,0 ,0 ],SA{T}[1 ,0 ,0 ]))
626+ # 3D rigid body with linear and angular velocity
627+ body3D = setmap (body3D;θ= SA{T}[0 ,0 ,0 ],V= SA{T}[1.0 ,0 ,0 ],ω= SA{T}[0 ,0 ,0.1 ])
628+ @test all (measure (body3D,SA{T}[1.5 ,0 ,0 ],0 ) .≈ (1 / 2 ,SA{T}[1 ,0 ,0 ],SA{T}[1 ,0.2 ,0 ]))
629+ @test all (measure (body3D,SA{T}[0 ,1.5 ,0 ],0 ) .≈ (1 / 2 ,SA{T}[0 ,1 ,0 ],SA{T}[0.85 ,0.05 ,0 ]))
630+ @test all (measure (body3D,SA{T}[1.5 ,1.5 ,1.5 ],0 ) .≈ (√ (3 * (1.5 ^ 2 ))- 1 ,SA{T}[√ (1 / 3 ),√ (1 / 3 ),√ (1 / 3 )],SA{T}[.85 ,0.2 ,0 ]))
631+ # three 3D rotations
632+ body3D = setmap (body3D;V= SA{T}[1.0 ,0 ,0 ],ω= SA{T}[0 ,- 0.1 ,0.1 ])
633+ @test all (measure (body3D,SA{T}[1.5 ,0 ,0 ],0 ) .≈ (1 / 2 ,SA{T}[1 ,0 ,0 ],SA{T}[1 ,0.2 ,0.2 ]))
634+ @test all (measure (body3D,SA{T}[0 ,1.5 ,1.5 ],0 ) .≈ (√ (2 * (1.5 ^ 2 ))- 1 ,SA{T}[0 ,√ (1 / 2 ),√ (1 / 2 )],SA{T}[0.7 ,0.05 ,0.05 ]))
635+ # test for a SetMap
636+ body = AutoBody (sdf, RigidMap (SA{T}[0 ,0 ],T (0 ))) + AutoBody (sdf, RigidMap (SA{T}[1 ,1 ],T (0 )))
637+ body = setmap (body;θ= T (π/ 4 ),V= SA{T}[1.0 ,0 ])
638+ @test all (body. a. map. θ == body. b. map. θ == T (π/ 4 ))
639+ @test all (body. a. map. V .≈ body. b. map. V .≈ [1 ,0 ])
640+ # try measure in the sim using different backends
641+ for array in arrays
642+ body = AutoBody ((x,t)-> sqrt (sum (abs2,x))- 4 ,RigidMap (SA{T}[16 ,16 ,16 ],SA{T}[0 ,0 ,0 ];
643+ V= SA{T}[0 ,0 ,0 ],ω= SA{T}[0 ,- 0.1 ,0.1 ]))
644+ sim = Simulation ((32 ,32 ,32 ),(1 ,0 ,0 ),8 ;body,T,mem= array)
645+ @test GPUArrays. @allowscalar all (extrema (sim. flow. V) .≈ (- 0.9 ,0.9 ))
646+ sim. body = setmap (sim. body;x₀= SA{T}[16 ,16 ,12 ])
647+ @test GPUArrays. @allowscalar all (sim. flow. μ₀[17 ,17 ,17 ,:] .≈ 0 )
648+ end
649+ end
650+ rmap = RigidMap (SA[0. ,0. ],π/ 4 )
651+ body = AutoBody ((x,t)-> √ (x' x)- 1 ,rmap)- AutoBody ((x,t)-> √ (x' x)- 0.5 ,rmap) # annulus
652+ @test all (measure (setmap (body,ω= 1. ),SA[0.25 ,0. ],0 ) .≈ (0.25 ,SA[- 1 ,0 ],SA[0 ,0.25 ]))
599653end
0 commit comments