|
| 1 | +# Note that more tests for `PrescribedMotion` are in `test/systems/boundary_system.jl`. |
| 2 | +@testset verbose=true "PrescribedMotion" begin |
| 3 | + @testset "OscillatingMotion2D" begin |
| 4 | + @testset "Simple Rotation" begin |
| 5 | + frequency = 1.0 |
| 6 | + translation_vector = SVector(0.0, 0.0) |
| 7 | + rotation_angle = pi |
| 8 | + rotation_center = SVector(0.0, 0.0) |
| 9 | + |
| 10 | + motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle, |
| 11 | + rotation_center) |
| 12 | + movement_function = motion.movement_function |
| 13 | + |
| 14 | + @test isapprox(movement_function([1.0, 0.0], 0.0), [1.0, 0.0], atol=eps()) |
| 15 | + # Initial position after one phase |
| 16 | + @test isapprox(movement_function([1.0, 0.0], 1.0), [1.0, 0.0], atol=10eps()) |
| 17 | + # Initial position after one half phase |
| 18 | + @test isapprox(movement_function([1.0, 0.0], 0.5), [1.0, 0.0], atol=10eps()) |
| 19 | + # Half rotation after one quarter phase (rotation angle is one half rotation) |
| 20 | + @test isapprox(movement_function([1.0, 0.0], 0.25), [-1.0, 0.0], atol=10eps()) |
| 21 | + # Quarter rotation (0.5 * rotation_angle = 90 degrees) |
| 22 | + @test isapprox(movement_function([1.0, 0.0], asin(0.5) / 2pi), [0.0, 1.0], |
| 23 | + atol=10eps()) |
| 24 | + end |
| 25 | + |
| 26 | + @testset "Simple Translation" begin |
| 27 | + frequency = 1.0 |
| 28 | + translation_vector = SVector(1.0, 0.0) |
| 29 | + rotation_angle = 0.0 |
| 30 | + rotation_center = SVector(0.0, 0.0) |
| 31 | + |
| 32 | + motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle, |
| 33 | + rotation_center) |
| 34 | + movement_function = motion.movement_function |
| 35 | + |
| 36 | + @test isapprox(movement_function([0.0, 0.0], 0.0), [0.0, 0.0], atol=eps()) |
| 37 | + @test isapprox(movement_function([0.0, 0.0], 0.25), [1.0, 0.0], atol=10eps()) |
| 38 | + @test isapprox(movement_function([0.0, 0.0], 0.5), [0.0, 0.0], atol=10eps()) |
| 39 | + @test isapprox(movement_function([0.0, 0.0], 0.75), [-1.0, 0.0], atol=10eps()) |
| 40 | + @test isapprox(movement_function([0.0, 0.0], 1.0), [0.0, 0.0], atol=10eps()) |
| 41 | + end |
| 42 | + |
| 43 | + @testset "Simple Translation tspan" begin |
| 44 | + frequency = 1.0 |
| 45 | + translation_vector = SVector(1.0, 0.0) |
| 46 | + rotation_angle = 0.0 |
| 47 | + rotation_center = SVector(0.0, 0.0) |
| 48 | + tspan = (0.4, 1.4) |
| 49 | + |
| 50 | + motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle, |
| 51 | + rotation_center, tspan) |
| 52 | + movement_function = motion.movement_function |
| 53 | + |
| 54 | + @test isapprox(movement_function([0.0, 0.0], 0.4), [0.0, 0.0], atol=eps()) |
| 55 | + @test isapprox(movement_function([0.0, 0.0], 0.65), [1.0, 0.0], atol=10eps()) |
| 56 | + @test isapprox(movement_function([0.0, 0.0], 0.9), [0.0, 0.0], atol=10eps()) |
| 57 | + @test isapprox(movement_function([0.0, 0.0], 1.15), [-1.0, 0.0], atol=10eps()) |
| 58 | + @test isapprox(movement_function([0.0, 0.0], 1.4), [0.0, 0.0], atol=10eps()) |
| 59 | + end |
| 60 | + |
| 61 | + @testset "Combined Rotation and Translation" begin |
| 62 | + frequency = 1.0 |
| 63 | + translation_vector = SVector(1.0, 0.0) |
| 64 | + rotation_angle = pi / 2 |
| 65 | + rotation_center = SVector(0.0, 0.0) |
| 66 | + |
| 67 | + motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle, |
| 68 | + rotation_center) |
| 69 | + movement_function = motion.movement_function |
| 70 | + |
| 71 | + @test isapprox(movement_function([1.0, 0.0], 0.0), [1.0, 0.0], atol=eps()) |
| 72 | + @test isapprox(movement_function([1.0, 0.0], 0.25), [1.0, 1.0], atol=10eps()) |
| 73 | + @test isapprox(movement_function([1.0, 0.0], 0.5), [1.0, 0.0], atol=10eps()) |
| 74 | + @test isapprox(movement_function([1.0, 0.0], 0.75), [-1.0, -1.0], atol=10eps()) |
| 75 | + @test isapprox(movement_function([1.0, 0.0], 1.0), [1.0, 0.0], atol=10eps()) |
| 76 | + end |
| 77 | + |
| 78 | + @testset "Phase Offset" begin |
| 79 | + frequency = 1.0 |
| 80 | + translation_vector = SVector(1.0, 0.0) |
| 81 | + rotation_angle = pi / 2 |
| 82 | + rotation_center = SVector(0.0, 0.0) |
| 83 | + rotation_phase_offset = 0.25 |
| 84 | + |
| 85 | + motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle, |
| 86 | + rotation_center, rotation_phase_offset) |
| 87 | + movement_function = motion.movement_function |
| 88 | + |
| 89 | + @test isapprox(movement_function([1.0, 0.0], 0.0), [0.0, -1.0], atol=eps()) |
| 90 | + @test isapprox(movement_function([1.0, 0.0], 0.25), [2.0, 0.0], atol=10eps()) |
| 91 | + @test isapprox(movement_function([1.0, 0.0], 0.5), [0.0, 1.0], atol=10eps()) |
| 92 | + @test isapprox(movement_function([1.0, 0.0], 0.75), [0.0, 0.0], atol=10eps()) |
| 93 | + @test isapprox(movement_function([1.0, 0.0], 1.0), [0.0, -1.0], atol=10eps()) |
| 94 | + end |
| 95 | + |
| 96 | + @testset "Ramp-up" begin |
| 97 | + frequency = 1.0 |
| 98 | + translation_vector = SVector(1.0, 0.0) |
| 99 | + rotation_angle = 0.0 |
| 100 | + rotation_center = SVector(0.0, 0.0) |
| 101 | + ramp_up_tspan = (0.0, 1.0) |
| 102 | + |
| 103 | + motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle, |
| 104 | + rotation_center, ramp_up_tspan) |
| 105 | + movement_function = motion.movement_function |
| 106 | + |
| 107 | + @test isapprox(movement_function([0.0, 0.0], 0.0), [0.0, 0.0], atol=eps()) |
| 108 | + # During ramp-up, amplitude is reduced |
| 109 | + @test isapprox(movement_function([0.0, 0.0], 0.25), [0.15625, 0.0], |
| 110 | + atol=10eps()) |
| 111 | + @test isapprox(movement_function([0.0, 0.0], 0.5), [0.0, 0.0], atol=10eps()) |
| 112 | + # Less reduction at later times during ramp-up |
| 113 | + @test isapprox(movement_function([0.0, 0.0], 0.75), [-0.84375, 0.0], |
| 114 | + atol=10eps()) |
| 115 | + @test isapprox(movement_function([0.0, 0.0], 1.0), [0.0, 0.0], atol=10eps()) |
| 116 | + # After ramp-up, full amplitude |
| 117 | + @test isapprox(movement_function([0.0, 0.0], 1.25), [1.0, 0.0], atol=10eps()) |
| 118 | + end |
| 119 | + |
| 120 | + @testset "tspan" begin |
| 121 | + frequency = 1.0 |
| 122 | + translation_vector = SVector(1.0, 0.0) |
| 123 | + rotation_angle = 0.0 |
| 124 | + rotation_center = SVector(0.0, 0.0) |
| 125 | + tspan = (0.5, 1.5) |
| 126 | + |
| 127 | + motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle, |
| 128 | + rotation_center, tspan) |
| 129 | + ismoving = motion.is_moving |
| 130 | + |
| 131 | + @test !ismoving(-0.5) |
| 132 | + @test !ismoving(0.0) |
| 133 | + @test !ismoving(0.25) |
| 134 | + @test ismoving(0.5) |
| 135 | + @test ismoving(1.0) |
| 136 | + @test ismoving(1.5) |
| 137 | + @test !ismoving(1.75) |
| 138 | + end |
| 139 | + end |
| 140 | +end |
0 commit comments