Skip to content

Commit 049de88

Browse files
committed
Change API to use keyword arguments
1 parent 2088483 commit 049de88

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

src/schemes/boundary/prescribed_motion.jl

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function (prescribed_motion::Nothing)(system::AbstractSystem, t, semi)
100100
end
101101

102102
"""
103-
OscillatingMotion2D(frequency, translation_vector, rotation_angle, rotation_center;
103+
OscillatingMotion2D(; frequency, translation_vector, rotation_angle, rotation_center,
104104
rotation_phase_offset=0, tspan=(-Inf, Inf),
105105
ramp_up_tspan=(0.0, 0.0), moving_particles=nothing)
106106
@@ -109,25 +109,41 @@ The motion is a combination of a translation and a rotation around a center poin
109109
with the same frequency. Note that a phase offset can be specified for a rotation
110110
that is out of sync with the translation.
111111
112-
# Arguments
112+
# Keywords
113113
- `frequency`: Frequency of the oscillation in Hz.
114114
- `translation_vector`: Vector specifying the amplitude and direction of the translation.
115115
- `rotation_angle`: Maximum rotation angle in radians.
116116
- `rotation_center`: Center point of the rotation as an `SVector`.
117117
118-
# Keywords
118+
# Keywords (optional)
119119
- `rotation_phase_offset=0`: Phase offset of the rotation in number of periods (`1` = 1 period).
120120
- `tspan=(-Inf, Inf)`: Time span in which the motion is active. Outside of this time span,
121121
particles remain at their last position.
122-
- `ramp_up_tspan=(0.0, 0.0)`: Time span in which the motion is smoothly ramped up from zero
123-
to full amplitude. Outside of this time span, the motion has full amplitude.
124-
If the length of the time span is zero, no ramp-up is applied.
122+
- `ramp_up_tspan`: Time span in which the motion is smoothly ramped up from zero
123+
to full amplitude.
124+
Outside of this time span, the motion has full amplitude.
125+
Default is no ramp-up.
125126
- `moving_particles`: Indices of moving particles. Default is each particle in the system
126127
for the [`WallBoundarySystem`](@ref) and all clamped particles
127128
for the [`TotalLagrangianSPHSystem`](@ref).
129+
130+
# Examples
131+
```jldoctest; output = false, filter = r"PrescribedMotion{.*"
132+
# Oscillating motion with frequency 1 Hz, translation amplitude 1 in x-direction,
133+
# rotation angle 90 degrees (pi/2) around the origin.
134+
frequency = 1.0
135+
translation_vector = SVector(1.0, 0.0)
136+
rotation_angle = pi / 2
137+
rotation_center = SVector(0.0, 0.0)
138+
139+
motion = OscillatingMotion2D(frequency, translation_vector, rotation_angle,
140+
rotation_center)
141+
142+
# output
143+
PrescribedMotion{...}
128144
"""
129-
function OscillatingMotion2D(frequency, translation_vector, rotation_angle, rotation_center;
130-
rotation_phase_offset=0, tspan=(-Inf, Inf),
145+
function OscillatingMotion2D(; frequency, translation_vector, rotation_angle,
146+
rotation_center, rotation_phase_offset=0, tspan=(-Inf, Inf),
131147
ramp_up_tspan=(0.0, 0.0), moving_particles=nothing)
132148
@inline function movement_function(x, t)
133149
if isfinite(tspan[1])

test/schemes/boundary/prescribed_motion.jl

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
rotation_angle = pi
88
rotation_center = SVector(0.0, 0.0)
99

10-
motion = OscillatingMotion2D(frequency, translation_vector, rotation_angle,
10+
motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle,
1111
rotation_center)
1212
movement_function = motion.movement_function
1313

@@ -29,7 +29,7 @@
2929
rotation_angle = 0.0
3030
rotation_center = SVector(0.0, 0.0)
3131

32-
motion = OscillatingMotion2D(frequency, translation_vector, rotation_angle,
32+
motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle,
3333
rotation_center)
3434
movement_function = motion.movement_function
3535

@@ -47,8 +47,8 @@
4747
rotation_center = SVector(0.0, 0.0)
4848
tspan = (0.4, 1.4)
4949

50-
motion = OscillatingMotion2D(frequency, translation_vector, rotation_angle,
51-
rotation_center; tspan=tspan)
50+
motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle,
51+
rotation_center, tspan)
5252
movement_function = motion.movement_function
5353

5454
@test isapprox(movement_function([0.0, 0.0], 0.4), [0.0, 0.0], atol=eps())
@@ -64,7 +64,7 @@
6464
rotation_angle = pi / 2
6565
rotation_center = SVector(0.0, 0.0)
6666

67-
motion = OscillatingMotion2D(frequency, translation_vector, rotation_angle,
67+
motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle,
6868
rotation_center)
6969
movement_function = motion.movement_function
7070

@@ -82,9 +82,8 @@
8282
rotation_center = SVector(0.0, 0.0)
8383
rotation_phase_offset = 0.25
8484

85-
motion = OscillatingMotion2D(frequency, translation_vector, rotation_angle,
86-
rotation_center;
87-
rotation_phase_offset=rotation_phase_offset)
85+
motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle,
86+
rotation_center, rotation_phase_offset)
8887
movement_function = motion.movement_function
8988

9089
@test isapprox(movement_function([1.0, 0.0], 0.0), [0.0, -1.0], atol=eps())
@@ -101,9 +100,8 @@
101100
rotation_center = SVector(0.0, 0.0)
102101
ramp_up_tspan = (0.0, 1.0)
103102

104-
motion = OscillatingMotion2D(frequency, translation_vector, rotation_angle,
105-
rotation_center;
106-
ramp_up_tspan=ramp_up_tspan)
103+
motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle,
104+
rotation_center, ramp_up_tspan)
107105
movement_function = motion.movement_function
108106

109107
@test isapprox(movement_function([0.0, 0.0], 0.0), [0.0, 0.0], atol=eps())
@@ -126,9 +124,8 @@
126124
rotation_center = SVector(0.0, 0.0)
127125
tspan = (0.5, 1.5)
128126

129-
motion = OscillatingMotion2D(frequency, translation_vector, rotation_angle,
130-
rotation_center;
131-
tspan=tspan)
127+
motion = OscillatingMotion2D(; frequency, translation_vector, rotation_angle,
128+
rotation_center, tspan)
132129
ismoving = motion.is_moving
133130

134131
@test !ismoving(-0.5)

0 commit comments

Comments
 (0)