-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Printf | ||
using KiteModels, KitePodModels, KiteUtils | ||
|
||
set = deepcopy(load_settings("system.yaml")) | ||
|
||
set.abs_tol=0.0006 | ||
set.rel_tol=0.00001 | ||
|
||
# the following values can be changed to match your interest | ||
dt = 0.05 | ||
set.solver="DFBDF" # IDA or DFBDF | ||
STEPS = 300 | ||
PLOT = true | ||
FRONT_VIEW = false | ||
ZOOM = true | ||
PRINT = false | ||
STATISTIC = false | ||
# end of user parameter section # | ||
|
||
kcu::KCU = KCU(set) | ||
kps4::KPS4 = KPS4(kcu) | ||
|
||
if PLOT | ||
using Pkg | ||
if ! ("ControlPlots" ∈ keys(Pkg.project().dependencies)) | ||
using TestEnv; TestEnv.activate() | ||
end | ||
using ControlPlots | ||
end | ||
|
||
function simulate(integrator, steps, plot=false) | ||
iter = 0 | ||
for i in 1:steps | ||
if PRINT | ||
lift, drag = KiteModels.lift_drag(kps4) | ||
@printf "%.2f: " round(integrator.t, digits=2) | ||
println("lift, drag [N]: $(round(lift, digits=2)), $(round(drag, digits=2))") | ||
end | ||
|
||
KiteModels.next_step!(kps4, integrator; set_speed=0, dt) | ||
iter += kps4.iter | ||
|
||
if plot | ||
reltime = i*dt-dt | ||
if mod(i, 5) == 1 | ||
plot2d(kps4.pos, reltime; zoom=ZOOM, front=FRONT_VIEW, segments=set.segments) | ||
end | ||
end | ||
end | ||
iter / steps | ||
end | ||
|
||
integrator = KiteModels.init_sim!(kps4; delta=0.0, stiffness_factor=1, prn=STATISTIC) | ||
|
||
if PLOT | ||
av_steps = simulate(integrator, STEPS, true) | ||
else | ||
println("\nStarting simulation...") | ||
simulate(integrator, 100) | ||
runtime = @elapsed av_steps = simulate(integrator, STEPS-100) | ||
println("\nTotal simulation time: $(round(runtime, digits=3)) s") | ||
speed = (STEPS-100) / runtime * dt | ||
println("Simulation speed: $(round(speed, digits=2)) times realtime.") | ||
end | ||
lift, drag = KiteModels.lift_drag(kps4) | ||
println("lift, drag [N]: $(round(lift, digits=2)), $(round(drag, digits=2))") | ||
println("Average number of callbacks per time step: $av_steps") |