diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 44060bae..fdf1ce1e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -133,6 +133,9 @@ jobs: shell: bash - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 + - name: Build PyCall + run: julia --project=docs/ -e 'ENV["PYTHON"]=""; using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate(); Pkg.build("PyCall")' + shell: bash - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-docdeploy@v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index b3e91394..e01b6697 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,18 @@ SPDX-FileCopyrightText: 2025 Uwe Fechner, Bart van de Lint SPDX-License-Identifier: MIT --> +### Unreleased +#### Changed +- rename `init_sim!` to `init!` +- removed the parameter `upwind_dir!` from `init!`; use set.upwind_dir instead. Careful: This is in degrees. +- the function `init!` accepts (and ignores) the parameters `delta` and `stiffness_factor` if applied to a + SymbolicAWEModel +### Added +- add the test script test_interface.jl +- add the field `integrator` to KPS4 and KPS3 structs ### KiteModels v0.8.1 2025-06-20 -#### CHANGED +#### Changed - renamed POWER to POWER_LINE and STEERING to STEERING_LINE - improved documentation, fixed example diff --git a/data/settings.yaml b/data/settings.yaml index 6bf23425..24aed0c5 100644 --- a/data/settings.yaml +++ b/data/settings.yaml @@ -11,10 +11,18 @@ system: fixed_font: "" # name or filepath+filename of alternative fixed pitch font, e.g. Liberation Mono initial: - l_tethers: [150.0, 0, 0] # initial tether length [m] - elevation: [70.8] # initial elevation angle [deg] - v_reel_outs: [0.0, 0 ,0] # initial reel out speed [m/s] - depower: [25.0] # initial depower settings [%] + elevations: [70.8] # initial elevation angle [deg] + elevation_rates: [0.0] # initial elevation rate [deg/s] + azimuths: [0.0] # initial azimuth angle [deg] + azimuth_rates: [0.0] # initial azimuth rate [deg/s] + headings: [0.0] # initial heading angle [deg] + heading_rates: [0.0] # initial heading rate [deg/s] + # three values are only needed for RamAirKite, for KPS3 and KPS4 use only the first value + l_tethers: [150.0] # initial tether lengths [m] + kite_distances: [51.0] # initial kite distances [m] + v_reel_outs: [0.0] # initial reel out speeds [m/s] + depowers: [25.0] # initial depower settings [%] + steerings: [0.0] # initial steering settings [%] solver: abs_tol: 0.0006 # absolute tolerance of the DAE solver [m, m/s] diff --git a/docs/src/examples_4p.md b/docs/src/examples_4p.md index 78ed166b..b6a658ab 100644 --- a/docs/src/examples_4p.md +++ b/docs/src/examples_4p.md @@ -30,7 +30,7 @@ Then we call the function `find_steady_state` which uses a non-linear solver to find_steady_state!(kps, prn=true) ``` Finding the steady state of the 4-point model is difficult and it only works when we artificially reduce the stiffness by a factor -of 0.035. In the function [`init_sim!`](@ref) this factor is slowly increased to 1.0. +of 0.035. In the function [`init!`](@ref) this factor is slowly increased to 1.0. To plot the result in 2D we extract the vectors of the x and z coordinates of the tether particles with a for loop: ```julia diff --git a/docs/src/functions.md b/docs/src/functions.md index 0d34cda9..4be3c824 100644 --- a/docs/src/functions.md +++ b/docs/src/functions.md @@ -55,7 +55,7 @@ SysState ## High level simulation interface ```@docs -init_sim! +init! next_step! ``` diff --git a/docs/src/index.md b/docs/src/index.md index 19ab607e..a92cdacf 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -83,7 +83,7 @@ times faster. - the documentation was improved ## Provides -The types [`KPS3`](@ref), [`KPS4`](@ref) and [`SymbolicAWEModel`](@ref), representing the one point, the four point kite model and the ram air kite model, together with the high level simulation interface consisting of the functions [`init_sim!`](@ref) and [`next_step!`](@ref). Other kite models can be added inside or outside of this package by implementing the non-generic methods required for an AbstractKiteModel. +The types [`KPS3`](@ref), [`KPS4`](@ref) and [`SymbolicAWEModel`](@ref), representing the one point, the four point kite model and the ram air kite model, together with the high level simulation interface consisting of the functions [`init!`](@ref) and [`next_step!`](@ref). Other kite models can be added inside or outside of this package by implementing the non-generic methods required for an AbstractKiteModel. Additional functions to provide inputs and outputs of the model on each time step. In particular the constructor [`SysState`](@ref) can be called once per time step to create a SysState struct for logging or for displaying the state in a viewer. For the KPS3 and KPS4 model, once per time step the [`residual!`](@ref) function is called as many times as needed to find the solution at the end diff --git a/docs/src/tutorial_system_structure.md b/docs/src/tutorial_system_structure.md index 396b661d..73993cd0 100644 --- a/docs/src/tutorial_system_structure.md +++ b/docs/src/tutorial_system_structure.md @@ -69,7 +69,7 @@ If the system looks good, we can easily model it, by first creating a [`Symbolic ```julia sam = SymbolicAWEModel(set, sys_struct) -init_sim!(sam; remake=false) +init!(sam; remake=false) for i in 1:80 plot(sam, i/set.sample_freq) next_step!(sam) diff --git a/examples/bench.jl b/examples/bench.jl index 6a0e3ec1..58a1d835 100644 --- a/examples/bench.jl +++ b/examples/bench.jl @@ -34,7 +34,7 @@ function simulate(integrator, steps) iter / steps end -integrator = KiteModels.init_sim!(kps4; delta=0, stiffness_factor=0.5, prn=STATISTIC) +integrator = KiteModels.init!(kps4; delta=0, stiffness_factor=0.5, prn=STATISTIC) println("\nStarting simulation...") simulate(integrator, 100) diff --git a/examples/bench_4p.jl b/examples/bench_4p.jl index 94c53d1c..60806859 100644 --- a/examples/bench_4p.jl +++ b/examples/bench_4p.jl @@ -52,7 +52,7 @@ function simulate(integrator, steps, offset=0) iter / steps end -integrator = KiteModels.init_sim!(kps4, delta=0, stiffness_factor=0.5, prn=STATISTIC) +integrator = KiteModels.init!(kps4, delta=0, stiffness_factor=0.5, prn=STATISTIC) println("\nStarting simulation...") simulate(integrator, 100, 100) diff --git a/examples/calc_spectrum.jl b/examples/calc_spectrum.jl index 7216744e..03c51000 100644 --- a/examples/calc_spectrum.jl +++ b/examples/calc_spectrum.jl @@ -100,7 +100,7 @@ function sim_and_plot(set; depower=DEPOWER, f_ex) set.elevation = 67.0 kcu::KCU = KCU(set) kps4::KPS4 = KPS4(kcu) - integrator = KiteModels.init_sim!(kps4; delta=0.001*0, stiffness_factor=1, prn=STATISTIC) + integrator = KiteModels.init!(kps4; delta=0.001*0, stiffness_factor=1, prn=STATISTIC) set_depower_steering(kps4.kcu, depower, 0.0) simulate(kps4, integrator, logger, STEPS, f_ex) save_log(logger, "tmp") diff --git a/examples/compare_kps3_kps4.jl b/examples/compare_kps3_kps4.jl index e147da6f..6c942e2c 100644 --- a/examples/compare_kps3_kps4.jl +++ b/examples/compare_kps3_kps4.jl @@ -55,7 +55,7 @@ function simulate(s, integrator, steps, plot=false; fig="") iter / steps end -integrator = KiteModels.init_sim!(kps3, delta=0.001, stiffness_factor=0.5, prn=STATISTIC) +integrator = KiteModels.init!(kps3, delta=0.001, stiffness_factor=0.5, prn=STATISTIC) av_steps = simulate(kps3, integrator, STEPS, true; fig="kps3") lift, drag = KiteModels.lift_drag(kps3) @@ -65,7 +65,7 @@ println("winch_force [N]: $(round(winch_force(kps3), digits=2))") println("Average number of callbacks per time step: $(round(av_steps, digits=2))") kps4.set.alpha_zero = ALPHA_ZERO -integrator = KiteModels.init_sim!(kps4; delta=0.001, stiffness_factor=1, prn=STATISTIC) +integrator = KiteModels.init!(kps4; delta=0.001, stiffness_factor=1, prn=STATISTIC) av_steps = simulate(kps4, integrator, STEPS, true; fig="kps4") lift, drag = KiteModels.lift_drag(kps4) diff --git a/examples/initial_reel_out_4p.jl b/examples/initial_reel_out_4p.jl index 22dbd1d4..60cbbe74 100644 --- a/examples/initial_reel_out_4p.jl +++ b/examples/initial_reel_out_4p.jl @@ -69,7 +69,7 @@ function simulate(integrator, steps, plot=false) iter / steps end -integrator = KiteModels.init_sim!(kps4; delta=0.000, stiffness_factor=0.25, prn=STATISTIC) +integrator = KiteModels.init!(kps4; delta=0.000, stiffness_factor=0.25, prn=STATISTIC) kps4.sync_speed = set.v_reel_out if PLOT diff --git a/examples/initial_reel_out_4p_torque_control.jl b/examples/initial_reel_out_4p_torque_control.jl index 7749acea..16aa231e 100644 --- a/examples/initial_reel_out_4p_torque_control.jl +++ b/examples/initial_reel_out_4p_torque_control.jl @@ -89,7 +89,7 @@ end kps4.sync_speed = set.v_reel_out kps4.wm.last_set_speed = set.v_reel_out -integrator = KiteModels.init_sim!(kps4; delta=0.00015, stiffness_factor=0.8, prn=STATISTIC) +integrator = KiteModels.init!(kps4; delta=0.00015, stiffness_factor=0.8, prn=STATISTIC) if PLOT av_steps = simulate(integrator, STEPS, true) diff --git a/examples/lin_ram_model.jl b/examples/lin_ram_model.jl index 0bfcaa3f..0b844462 100644 --- a/examples/lin_ram_model.jl +++ b/examples/lin_ram_model.jl @@ -61,7 +61,7 @@ lin_outputs = @variables heading(t_nounits)[1] # Initialize at elevation with linearization outputs s.sys_struct.winches[2].tether_length += 0.2 s.sys_struct.winches[3].tether_length += 0.2 -KiteModels.init_sim!(s; +KiteModels.init!(s; remake=false, reload=true, lin_outputs # Specify which outputs to track in linear model diff --git a/examples/plot_alpha2.jl b/examples/plot_alpha2.jl index d02d45ab..95abae62 100644 --- a/examples/plot_alpha2.jl +++ b/examples/plot_alpha2.jl @@ -57,7 +57,7 @@ function simulate(integrator, steps, offset=0) iter / steps end -integrator = KiteModels.init_sim!(kps4, stiffness_factor=0.5, prn=STATISTIC) +integrator = KiteModels.init!(kps4, stiffness_factor=0.5, prn=STATISTIC) println("\nStarting simulation...") simulate(integrator, 100, 100) diff --git a/examples/plot_cl_cd.jl b/examples/plot_cl_cd.jl index 0c489e08..c3451d53 100644 --- a/examples/plot_cl_cd.jl +++ b/examples/plot_cl_cd.jl @@ -97,7 +97,7 @@ for depower in DEPOWER kcu = KCU(set) kps4 = KPS4(kcu) - integrator = KiteModels.init_sim!(kps4; delta=0.03, stiffness_factor=0.05, prn=STATISTIC) + integrator = KiteModels.init!(kps4; delta=0.03, stiffness_factor=0.05, prn=STATISTIC) if ! isnothing(integrator) try cl, cd = simulate(kps4, integrator, logger, STEPS) diff --git a/examples/plot_parking_test.jl b/examples/plot_parking_test.jl index af0a95b9..62d3de4d 100644 --- a/examples/plot_parking_test.jl +++ b/examples/plot_parking_test.jl @@ -115,7 +115,7 @@ for depower in DEPOWER kps4::KPS4 = KPS4(kcu) set.elevation += 5 set.v_wind = V_WIND_200[i] / 1.348881340489221 * calc_wind_factor(kps4.am, HEIGHT[i])/1.348881340489221 - integrator = KiteModels.init_sim!(kps4; delta=0.001*0, stiffness_factor=1, prn=STATISTIC) + integrator = KiteModels.init!(kps4; delta=0.001*0, stiffness_factor=1, prn=STATISTIC) if ! isnothing(integrator) try cl, cd = simulate(kps4, integrator, logger, STEPS) diff --git a/examples/plot_pitch_stability.jl b/examples/plot_pitch_stability.jl index e946035a..05a8d2ec 100644 --- a/examples/plot_pitch_stability.jl +++ b/examples/plot_pitch_stability.jl @@ -110,7 +110,7 @@ kcu::KCU = KCU(set) kps4::KPS4 = KPS4(kcu) set.elevation += 5 set.v_wind = V_WIND_200 -integrator = KiteModels.init_sim!(kps4; delta=0.001*0, stiffness_factor=1, prn=STATISTIC) +integrator = KiteModels.init!(kps4; delta=0.001*0, stiffness_factor=1, prn=STATISTIC) if ! isnothing(integrator) simulate(kps4, integrator, logger, STEPS) set_depower_steering(kps4.kcu, depower, 0.0) diff --git a/examples/plot_side_cl.jl b/examples/plot_side_cl.jl index 7b42f20f..5583e52f 100644 --- a/examples/plot_side_cl.jl +++ b/examples/plot_side_cl.jl @@ -81,10 +81,10 @@ STEERING = zeros(length(SET_STEERING)) SIDE_CL = zeros(length(SET_STEERING)) for (i, set_steering) in pairs(SET_STEERING) local side_cl, integrator - integrator = KiteModels.init_sim!(kps4; delta=0.001, stiffness_factor=1, prn=STATISTIC) + integrator = KiteModels.init!(kps4; delta=0.001, stiffness_factor=1, prn=STATISTIC) side_cl, steering = simulate(integrator, STEPS, set_steering, plot=false) if side_cl == 0.0 - integrator = KiteModels.init_sim!(kps4; delta=0.001, stiffness_factor=1, prn=STATISTIC) + integrator = KiteModels.init!(kps4; delta=0.001, stiffness_factor=1, prn=STATISTIC) side_cl, steering = simulate(integrator, STEPS, set_steering, plot=false) end SIDE_CL[i] = side_cl diff --git a/examples/ram_air_kite.jl b/examples/ram_air_kite.jl index 5a79e266..5ad10857 100644 --- a/examples/ram_air_kite.jl +++ b/examples/ram_air_kite.jl @@ -49,7 +49,7 @@ toc() # Initialize at elevation set.l_tethers[2] += 0.2 set.l_tethers[3] += 0.2 -init_sim!(sam; remake=false, reload=false) +init!(sam; remake=false, reload=false) sys = sam.sys @info "System initialized at:" diff --git a/examples/reel_out_1p.jl b/examples/reel_out_1p.jl index ec72d268..271ce53f 100644 --- a/examples/reel_out_1p.jl +++ b/examples/reel_out_1p.jl @@ -61,7 +61,7 @@ function simulate(integrator, steps, plot=false) iter / steps end -integrator = KiteModels.init_sim!(kps3, delta=0, stiffness_factor=0.04, prn=STATISTIC) +integrator = KiteModels.init!(kps3, delta=0, stiffness_factor=0.04, prn=STATISTIC) kps3.sync_speed = 0.0 if PLOT diff --git a/examples/reel_out_4p.jl b/examples/reel_out_4p.jl index 7b52fc8c..b97755ce 100644 --- a/examples/reel_out_4p.jl +++ b/examples/reel_out_4p.jl @@ -66,7 +66,7 @@ function simulate(integrator, steps, plot=false) iter / steps end -integrator = KiteModels.init_sim!(kps4; delta=0, stiffness_factor=1, prn=STATISTIC) +integrator = KiteModels.init!(kps4; delta=0, stiffness_factor=1, prn=STATISTIC) kps4.sync_speed = 0.0 if PLOT diff --git a/examples/reel_out_4p_torque_control.jl b/examples/reel_out_4p_torque_control.jl index 7fbe997a..3c660f1a 100644 --- a/examples/reel_out_4p_torque_control.jl +++ b/examples/reel_out_4p_torque_control.jl @@ -70,7 +70,7 @@ function simulate(integrator, steps, plot=false) iter / steps end -integrator = KiteModels.init_sim!(kps4; delta=0, stiffness_factor=1, prn=STATISTIC) +integrator = KiteModels.init!(kps4; delta=0, stiffness_factor=1, prn=STATISTIC) kps4.sync_speed = 0.0 if PLOT diff --git a/examples/simulate_simple.jl b/examples/simulate_simple.jl index fc6e939e..51161628 100644 --- a/examples/simulate_simple.jl +++ b/examples/simulate_simple.jl @@ -62,8 +62,8 @@ function simulate(integrator, steps, plot=false) end iter / steps end - -integrator = KiteModels.init_sim!(kps4; delta=0.0, stiffness_factor=1, upwind_dir=UPWIND_DIR, prn=STATISTIC) +kps4.set.upwind_dir = rad2deg(UPWIND_DIR) +integrator = KiteModels.init!(kps4; delta=0.0, stiffness_factor=1, prn=STATISTIC) if PLOT global flight_log diff --git a/examples/simulate_steering.jl b/examples/simulate_steering.jl index 5362814c..7aa6983c 100644 --- a/examples/simulate_steering.jl +++ b/examples/simulate_steering.jl @@ -64,7 +64,7 @@ function simulate(integrator, steps, plot=false) iter / steps end -integrator = KiteModels.init_sim!(kps3; delta=0, stiffness_factor=0.04, prn=STATISTIC) +integrator = KiteModels.init!(kps3; delta=0, stiffness_factor=0.04, prn=STATISTIC) if PLOT av_steps = simulate(integrator, STEPS, true) diff --git a/examples/steering_test_1p.jl b/examples/steering_test_1p.jl index f9698301..beb81ecd 100644 --- a/examples/steering_test_1p.jl +++ b/examples/steering_test_1p.jl @@ -99,7 +99,7 @@ function simulate(integrator, steps; plot=false) end end -integrator = KiteModels.init_sim!(kps3; delta=0.0, stiffness_factor=1, prn=STATISTIC) +integrator = KiteModels.init!(kps3; delta=0.0, stiffness_factor=1, prn=STATISTIC) simulate(integrator, STEPS; plot=true) function delay(x, y, t_max = 10) diff --git a/examples/steering_test_4p.jl b/examples/steering_test_4p.jl index 9d74a1ed..78a922ca 100644 --- a/examples/steering_test_4p.jl +++ b/examples/steering_test_4p.jl @@ -104,7 +104,7 @@ function simulate(integrator, steps; plot=false) end -integrator = KiteModels.init_sim!(kps4; delta=0.0, stiffness_factor=1, prn=STATISTIC) +integrator = KiteModels.init!(kps4; delta=0.0, stiffness_factor=1, prn=STATISTIC) simulate(integrator, STEPS; plot=true) function delay(x, y, t_max = 10) diff --git a/examples/test_init_1p.jl b/examples/test_init_1p.jl index 266a216b..f10f661a 100644 --- a/examples/test_init_1p.jl +++ b/examples/test_init_1p.jl @@ -38,7 +38,7 @@ logger = Logger(set.segments + 1, STEPS) kcu::KCU = KCU(set) kps3::KPS3 = KPS3(kcu) -integrator = KiteModels.init_sim!(kps3; delta=0.03, stiffness_factor=0.1, prn=STATISTIC) +integrator = KiteModels.init!(kps3; delta=0.03, stiffness_factor=0.1, prn=STATISTIC) lift, drag = lift_drag(kps3) sys_state = KiteModels.SysState(kps3) log!(logger, sys_state) diff --git a/examples/test_init_4p.jl b/examples/test_init_4p.jl index 44546192..e1c06fe0 100644 --- a/examples/test_init_4p.jl +++ b/examples/test_init_4p.jl @@ -39,7 +39,7 @@ logger = Logger(set.segments + 5, STEPS) kcu::KCU = KCU(set) kps4::KPS4 = KPS4(kcu) -integrator = KiteModels.init_sim!(kps4; delta=0.03, stiffness_factor=0.01, upwind_dir=UPWIND_DIR, prn=STATISTIC) +integrator = KiteModels.init!(kps4; delta=0.03, stiffness_factor=0.01, upwind_dir=UPWIND_DIR, prn=STATISTIC) for i=1:80 next_step!(kps4, integrator; set_speed=kps4.set.v_reel_out, dt) end diff --git a/examples/test_steady_state.jl b/examples/test_steady_state.jl index e7465b4a..af78aac1 100644 --- a/examples/test_steady_state.jl +++ b/examples/test_steady_state.jl @@ -12,7 +12,7 @@ kps4::KPS4 = KPS4(kcu) clear!(kps4) KiteModels.set_depower_steering!(kps4, kps4.set.depower_offset/100.0, 0.0) -@time KiteModels.init_sim!(kps4; delta=0.001, stiffness_factor=0.5, prn=false) +@time KiteModels.init!(kps4; delta=0.001, stiffness_factor=0.5, prn=false) println("\nlift, drag [N] : $(KiteModels.lift_drag(kps4))") println("\nSpring forces:") diff --git a/examples/tether.jl b/examples/tether.jl index e1983659..f74eaef6 100644 --- a/examples/tether.jl +++ b/examples/tether.jl @@ -30,7 +30,7 @@ plot(sys_struct, 0.0) sam = SymbolicAWEModel(set, sys_struct) -init_sim!(sam; remake=false) +init!(sam; remake=false) for i in 1:80 plot(sam, i/set.sample_freq) next_step!(sam) diff --git a/examples_3d/parking_4p.jl b/examples_3d/parking_4p.jl index 7c4de90e..e61ea333 100644 --- a/examples_3d/parking_4p.jl +++ b/examples_3d/parking_4p.jl @@ -85,7 +85,7 @@ function simulate(integrator, steps, plot=PLOT) iter / steps end -integrator = KiteModels.init_sim!(kps4, delta=0, stiffness_factor=0.5, prn=STATISTIC) +integrator = KiteModels.init!(kps4, delta=0, stiffness_factor=0.5, prn=STATISTIC) println("\nStarting simulation...") simulate(integrator, STEPS) diff --git a/mwes/mwe_01.jl b/mwes/mwe_01.jl index e1b24c96..8e38aa9e 100644 --- a/mwes/mwe_01.jl +++ b/mwes/mwe_01.jl @@ -6,5 +6,5 @@ using KiteModels kps4::KPS4 = KPS4(KCU(se())) -integrator = KiteModels.init_sim!(kps4; stiffness_factor=0.035, prn=false) +integrator = KiteModels.init!(kps4; stiffness_factor=0.035, prn=false) nothing \ No newline at end of file diff --git a/mwes/mwe_02.jl b/mwes/mwe_02.jl index aef1e1cd..5a9882ab 100644 --- a/mwes/mwe_02.jl +++ b/mwes/mwe_02.jl @@ -11,7 +11,7 @@ set.solver="DFBDF" kps4::KPS4 = KPS4(KCU(set)) STEPS = 200 -integrator = KiteModels.init_sim!(kps4; stiffness_factor=0.035, prn=false) +integrator = KiteModels.init!(kps4; stiffness_factor=0.035, prn=false) next_step!(kps4, integrator, set_speed = 0, dt=0.05) @timev next_step!(kps4, integrator; set_speed = 0, dt=0.05) function nsteps(kps4, integrator) diff --git a/mwes/mwe_10.jl b/mwes/mwe_10.jl index df16f645..17a9b0cb 100644 --- a/mwes/mwe_10.jl +++ b/mwes/mwe_10.jl @@ -6,5 +6,5 @@ using KiteModels kps4_3L::SymbolicAWEModel = SymbolicAWEModel(KCU(se())) -integrator = KiteModels.init_sim!(kps4_3L; stiffness_factor=0.035, prn=false) +integrator = KiteModels.init!(kps4_3L; stiffness_factor=0.035, prn=false) nothing \ No newline at end of file diff --git a/mwes/mwe_11.jl b/mwes/mwe_11.jl index 5af0c520..0ec1420e 100644 --- a/mwes/mwe_11.jl +++ b/mwes/mwe_11.jl @@ -15,5 +15,5 @@ kps3::KPS3 = KPS3(kcu) reltime = 0.0 -integrator = KiteModels.init_sim!(kps3, stiffness_factor=0.04) +integrator = KiteModels.init!(kps3, stiffness_factor=0.04) plot2d(kps3.pos, reltime; zoom=false, front=false, segments=set.segments) \ No newline at end of file diff --git a/mwes/mwe_11b.jl b/mwes/mwe_11b.jl index 02de68e9..836d246c 100644 --- a/mwes/mwe_11b.jl +++ b/mwes/mwe_11b.jl @@ -14,5 +14,5 @@ kcu::KCU = KCU(set) kps4::KPS4 = KPS4(kcu) reltime = 0.0 -integrator = KiteModels.init_sim!(kps4, stiffness_factor=0.5) +integrator = KiteModels.init!(kps4, stiffness_factor=0.5) plot2d(kps4.pos, reltime; zoom=true, front=false, segments=set.segments) \ No newline at end of file diff --git a/mwes/mwe_12.jl b/mwes/mwe_12.jl index 2cae0895..14860087 100644 --- a/mwes/mwe_12.jl +++ b/mwes/mwe_12.jl @@ -15,5 +15,5 @@ kcu::KCU = KCU(set) kps3::KPS3 = KPS3(kcu) reltime = 0.0 -integrator = KiteModels.init_sim!(kps3, stiffness_factor=0.04) +integrator = KiteModels.init!(kps3, stiffness_factor=0.04) plot2d(kps3.pos, reltime; zoom=false, front=false, segments=set.segments) \ No newline at end of file diff --git a/mwes/mwe_12b.jl b/mwes/mwe_12b.jl index b17bf331..93991bb0 100644 --- a/mwes/mwe_12b.jl +++ b/mwes/mwe_12b.jl @@ -15,7 +15,7 @@ kcu::KCU = KCU(set) kps4::KPS4 = KPS4(kcu) reltime = 0.0 -integrator = KiteModels.init_sim!(kps4, stiffness_factor=0.5) +integrator = KiteModels.init!(kps4, stiffness_factor=0.5) lines, sc, txt = nothing, nothing, nothing plot2d(kps4.pos, reltime; zoom=true, front=false, segments=set.segments, lines, sc, txt) diff --git a/mwes/mwe_26.jl b/mwes/mwe_26.jl index a975fd8d..1c5c6414 100644 --- a/mwes/mwe_26.jl +++ b/mwes/mwe_26.jl @@ -13,7 +13,7 @@ set.v_wind = 50 kps4::KPS4 = KPS4(KCU(set)) STEPS = 200 -integrator = KiteModels.init_sim!(kps4; stiffness_factor=0.5, prn=false) +integrator = KiteModels.init!(kps4; stiffness_factor=0.5, prn=false) next_step!(kps4, integrator, set_speed = 0, dt=0.05) function nsteps(kps4, integrator) diff --git a/mwes/mwe_27.jl b/mwes/mwe_27.jl index 399e4d4e..daa4f292 100644 --- a/mwes/mwe_27.jl +++ b/mwes/mwe_27.jl @@ -5,4 +5,4 @@ using KiteModels set = load_settings("system_ram.yaml") sam = SymbolicAWEModel(set) -KiteModels.init_sim!(sam; remake=false, reload=false) \ No newline at end of file +KiteModels.init!(sam; remake=false, reload=false) \ No newline at end of file diff --git a/src/KPS3.jl b/src/KPS3.jl index 4abe7c94..c7405418 100644 --- a/src/KPS3.jl +++ b/src/KPS3.jl @@ -36,7 +36,7 @@ $(TYPEDFIELDS) "Reference to winch model as implemented in the package WinchModels" wm::Union{AbstractWinchModel, Nothing} = nothing "Integrator, storing the current state" - integrator::Union{OrdinaryDiffEqCore.ODEIntegrator, Nothing} = nothing + integrator::Union{OrdinaryDiffEqCore.ODEIntegrator, Sundials.IDAIntegrator, Nothing} = nothing "Iterations, number of calls to the function residual!" iter:: Int64 = 0 "Function for calculation the lift coefficent, using a spline based on the provided value pairs." diff --git a/src/KPS4.jl b/src/KPS4.jl index 88df5603..9918e4b1 100644 --- a/src/KPS4.jl +++ b/src/KPS4.jl @@ -69,7 +69,7 @@ $(TYPEDFIELDS) "Reference to winch model as implemented in the package WinchModels" wm::AbstractWinchModel "Integrator, storing the current state" - integrator::Union{OrdinaryDiffEqCore.ODEIntegrator, Nothing} = nothing + integrator::Union{OrdinaryDiffEqCore.ODEIntegrator, Sundials.IDAIntegrator, Nothing} = nothing "Iterations, number of calls to the function residual!" iter:: Int64 = 0 "Function for calculation the lift coefficient, using a spline based on the provided value pairs." diff --git a/src/KiteModels.jl b/src/KiteModels.jl index b3f2a452..ae639a06 100644 --- a/src/KiteModels.jl +++ b/src/KiteModels.jl @@ -37,9 +37,9 @@ using ADTypes: AutoFiniteDiff import ModelingToolkit.SciMLBase: successful_retcode export KPS3, KPS4, SymbolicAWEModel, KVec3, SimFloat, ProfileLaw, EXP, LOG, EXPLOG # constants and types -export calc_set_cl_cd!, copy_examples, copy_bin, update_sys_state! # helper functions -export clear!, find_steady_state!, residual! # low level workers -export init_sim!, init!, reinit!, next_step!, init_pos_vel # high level workers +export calc_set_cl_cd!, copy_examples, copy_bin, update_sys_state! # helper functions +export clear!, find_steady_state!, residual! # low level workers +export init!, reinit!, next_step!, init_pos_vel # high level workers export pos_kite, calc_height, calc_elevation, calc_azimuth, calc_heading, calc_course, calc_orient_quat, calc_aoa # getters export calc_azimuth_north, calc_azimuth_east export winch_force, lift_drag, cl_cd, lift_over_drag, unstretched_length, tether_length, v_wind_kite # getters @@ -538,7 +538,7 @@ function calc_pre_tension(s::AKM) end """ - init_sim!(s::AKM; stiffness_factor=0.5, delta=0.0001, upwind_dir=-pi/2, + init!(s::AKM; stiffness_factor=0.5, delta=0.0001, prn=false) -> OrdinaryDiffEqCore.ODEIntegrator Initializes the integrator of the model (KPS3 and KPS4 only). @@ -547,15 +547,14 @@ Parameters: - s: an instance of an abstract kite model - stiffness_factor: factor applied to the tether stiffness during initialization - delta: initial stretch of the tether during the steady state calculation -- upwind_dir: upwind direction in radians, the direction the wind is coming from. Zero is at north; - clockwise positive. Default: -pi/2, wind from west. - prn: if set to true, print the detailed solver results Returns: An instance of an `ODEIntegrator`. """ -function init_sim!(s::AKM; stiffness_factor=0.5, delta=0.0001, upwind_dir=-pi/2, prn=false) +function init!(s::AKM; stiffness_factor=0.5, delta=0.0001, prn=false) clear!(s) + upwind_dir = deg2rad(s.set.upwind_dir) s.stiffness_factor = stiffness_factor try @@ -563,7 +562,7 @@ function init_sim!(s::AKM; stiffness_factor=0.5, delta=0.0001, upwind_dir=-pi/2, catch e if e isa AssertionError println("ERROR: Failure to find initial steady state in find_steady_state! function!\n"* - "Try to increase the delta parameter or to decrease the initial_stiffness of the init_sim! function.") + "Try to increase the delta parameter or to decrease the initial_stiffness of the init! function.") return nothing else rethrow(e) @@ -598,7 +597,7 @@ function init_sim!(s::AKM; stiffness_factor=0.5, delta=0.0001, upwind_dir=-pi/2, set_initial_velocity!(s) end s.v_reel_out = s.set.v_reel_out - return integrator + s.integrator = integrator end @@ -610,7 +609,7 @@ Calculates the next simulation step. Either `set_speed` or `set_torque` must be Parameters: - s: an instance of an abstract kite model -- integrator: an integrator instance as returned by the function [`init_sim!`](@ref) +- integrator: an integrator instance as returned by the function [`init!`](@ref) - set_speed: set value of reel out speed in m/s or nothing - set_torque: set value of the torque in Nm or nothing - set_force: set value of the force in N or nothing (only for logging, not used otherwise) diff --git a/src/precompile.jl b/src/precompile.jl index f7d58509..e716be33 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -49,8 +49,8 @@ end @compile_workload begin # all calls in this block will be precompiled, regardless of whether( # they belong to your package or not (on Julia 1.8 and higher) - integrator = KiteModels.init_sim!(kps3_; stiffness_factor=0.035, prn=false) - integrator = KiteModels.init_sim!(kps4_; delta=0.03, stiffness_factor=0.05, prn=false) + integrator = KiteModels.init!(kps3_; stiffness_factor=0.035, prn=false) + integrator = KiteModels.init!(kps4_; delta=0.03, stiffness_factor=0.05, prn=false) sam_set = load_settings("system_ram.yaml") sam_set.segments = 3 @@ -87,7 +87,7 @@ end s = SymbolicAWEModel(sam_set) # Initialize at elevation - KiteModels.init_sim!(s; prn=false, precompile=true) + KiteModels.init!(s; prn=false, precompile=true) @info "Copying $output_file to $model_file !" cp(output_file, model_file; force=true) find_steady_state!(s) diff --git a/src/symbolic_awe_model.jl b/src/symbolic_awe_model.jl index afea5f06..08b60488 100644 --- a/src/symbolic_awe_model.jl +++ b/src/symbolic_awe_model.jl @@ -113,7 +113,7 @@ The aerodynamic models provide forces and moments acting on wing components. - `vsm_solvers::Vector{<:VortexStepMethod.Solver}=VortexStepMethod.Solver[]`: VSM solvers for aerodynamic calculations # Returns -- `SymbolicAWEModel`: Model ready for symbolic equation generation via [`init_sim!`](@ref) +- `SymbolicAWEModel`: Model ready for symbolic equation generation via [`init!`](@ref) # Example ```julia @@ -158,7 +158,7 @@ This convenience constructor creates a complete AWE model using default configur - `set::Settings`: Configuration parameters (see [KiteUtils.Settings](https://ufechner7.github.io/KiteUtils.jl/stable/types/#KiteUtils.Settings)) # Returns -- `SymbolicAWEModel`: Model ready for symbolic equation generation via [`init_sim!`](@ref) +- `SymbolicAWEModel`: Model ready for symbolic equation generation via [`init!`](@ref) # Example ```julia @@ -166,7 +166,7 @@ set = se() # Load default settings model = SymbolicAWEModel(set) # Initialize and run simulation -init_sim!(model) +init!(model) for i in 1:1000 next_step!(model) end @@ -181,7 +181,7 @@ function SymbolicAWEModel(set::Settings) end function update_sys_state!(ss::SysState, s::SymbolicAWEModel, zoom=1.0) - isnothing(s.integrator) && error("run init_sim!(s) first") + isnothing(s.integrator) && error("run init!(s) first") ss.time = s.integrator.t # Use integrator time # Get the state vectors from the integrator @@ -262,7 +262,7 @@ function SysState(s::SymbolicAWEModel, zoom=1.0) end """ - init_sim!(s::SymbolicAWEModel; solver=nothing, adaptive=true, prn=true, + init!(s::SymbolicAWEModel; solver=nothing, adaptive=true, prn=true, precompile=false, remake=false, reload=false, lin_outputs=Num[]) -> OrdinaryDiffEqCore.ODEIntegrator @@ -288,6 +288,8 @@ and only update the state variables. Otherwise, it will create a new model from # Keyword arguments - `solver`: Solver algorithm to use. If `nothing`, defaults to `FBDF()` or `QNDF()` based on `s.set.solver`. - `adaptive::Bool=true`: Whether to use adaptive time stepping. +- `stiffness_factor=nothing`: ignored, for backwards compatibility +- `delta=nothing`: ignored, for backwards compatibility - `prn::Bool=true`: Whether to print progress information. - `precompile::Bool=false`: Whether to build problem for precompilation. - `remake::Bool=false`: If true, forces the system to be rebuilt, even if a serialized model exists. @@ -297,8 +299,8 @@ and only update the state variables. Otherwise, it will create a new model from # Returns - `integrator::OrdinaryDiffEqCore.ODEIntegrator`: The initialized ODE integrator. """ -function init_sim!(s::SymbolicAWEModel; - solver=nothing, adaptive=true, prn=true, +function init!(s::SymbolicAWEModel; + solver=nothing, stiffness_factor = nothing, delta = nothing, adaptive=true, prn=true, precompile=false, remake=false, reload=false, lin_outputs=Num[] ) @@ -360,7 +362,7 @@ function init_sim!(s::SymbolicAWEModel; end function linearize(s::SymbolicAWEModel; set_values=s.get_set_values(s.integrator)) - isnothing(s.lin_prob) && error("Run init_sim! with remake=true and lin_outputs=...") + isnothing(s.lin_prob) && error("Run init! with remake=true and lin_outputs=...") s.set_lin_vsm(s.lin_prob, s.get_vsm(s.integrator)) s.set_lin_set_values(s.lin_prob, set_values) s.set_lin_unknowns(s.lin_prob, s.get_unknowns(s.integrator)) @@ -397,7 +399,7 @@ and only updates the state variables to match the current initial settings. - `Nothing` # Throws -- `ArgumentError`: If no serialized problem exists (run `init_sim!` first) +- `ArgumentError`: If no serialized problem exists (run `init!` first) """ function reinit!( s::SymbolicAWEModel, @@ -415,7 +417,7 @@ function reinit!( if isnothing(s.prob) || reload model_path = joinpath(KiteUtils.get_data_path(), get_model_name(s.set; precompile)) - !ispath(model_path) && error("$model_path not found. Run init_sim!(s::SymbolicAWEModel) first.") + !ispath(model_path) && error("$model_path not found. Run init!(s::SymbolicAWEModel) first.") try s.serialized_model = deserialize(model_path) catch e @@ -441,7 +443,7 @@ function reinit!( adaptive, dt, abstol=s.set.abs_tol, reltol=s.set.rel_tol, save_on=false, save_everystep=false) !s.set.quasi_static && (length(s.unknowns_vec) != length(s.integrator.u)) && error("sam.integrator unknowns of length $(length(s.integrator.u)) should equal sam.unknowns_vec of length $(length(s.unknowns_vec)). - Maybe you forgot to run init_sim!(model; remake=true)?") + Maybe you forgot to run init!(model; remake=true)?") end prn && @info "Initialized integrator in $t seconds" end diff --git a/test/create_xz_file.jl b/test/create_xz_file.jl index 4575dd69..2911a08b 100644 --- a/test/create_xz_file.jl +++ b/test/create_xz_file.jl @@ -35,7 +35,7 @@ toc() # Initialize at elevation s.sys_struct.winches[2].tether_length += 0.2 s.sys_struct.winches[3].tether_length += 0.2 -KiteModels.init_sim!(s; remake=false, reload=true) +KiteModels.init!(s; remake=false, reload=true) sys = s.sys @info "System initialized at:" diff --git a/test/test_for_precompile.jl b/test/test_for_precompile.jl index b98b900e..b71269a9 100644 --- a/test/test_for_precompile.jl +++ b/test/test_for_precompile.jl @@ -98,7 +98,7 @@ let end (integrator.p.iter - start) / steps end - integrator = KiteModels.init_sim!(kps4, prn=STATISTIC) + integrator = KiteModels.init!(kps4, prn=STATISTIC) kps4.stiffness_factor = 0.04 simulate(integrator, 100, true) end @@ -112,7 +112,7 @@ if ! haskey(ENV, "NO_MTK") s = SymbolicAWEModel(sam_set) # Initialize at elevation - KiteModels.init_sim!(s; prn=false, precompile=true) + KiteModels.init!(s; prn=false, precompile=true) find_steady_state!(s) steps = Int(round(10 / 0.05)) logger = Logger(length(s.sys_struct.points), steps) diff --git a/test/test_interface.jl b/test/test_interface.jl index 32c6fe83..bf78d62d 100644 --- a/test/test_interface.jl +++ b/test/test_interface.jl @@ -2,12 +2,15 @@ # SPDX-License-Identifier: MIT using KiteModels, KiteUtils, Test +# the following line is needed because VortexStepMethod also exports init! +using KiteModels: init! -set = load_settings("system.yaml") +# set_data_path("data") +set = deepcopy(load_settings("system.yaml")) kps3::KPS3 = KPS3(set) kps4::KPS4 = KPS4(set) -set = load_settings("system_ram.yaml") -sam::SymbolicAWEModel = SymbolicAWEModel(set) +set_ram = deepcopy(load_settings("system_ram.yaml")) +sam::SymbolicAWEModel = SymbolicAWEModel(set_ram) @testset "KPS3 constructor interface" begin @test kps3 isa KiteUtils.AbstractKiteModel @@ -30,4 +33,25 @@ end @test sam.am isa AtmosphericModel @test sam.iter isa Int64 end -nothing + +@testset "KPS3 init! interface" begin + kps4.set.upwind_dir = rad2deg(-pi/2) + integ = init!(kps3; stiffness_factor=0.5, delta=0.0001, prn=false) + @test integ isa KiteModels.OrdinaryDiffEqCore.ODEIntegrator + @test kps3.integrator isa KiteModels.OrdinaryDiffEqCore.ODEIntegrator +end + +@testset "KPS4 init! interface" begin + kps4.set.upwind_dir = rad2deg(-pi/2) + integ = init!(kps4; stiffness_factor=0.5, delta=0.0001, prn=false) + @test integ isa KiteModels.OrdinaryDiffEqCore.ODEIntegrator + @test kps4.integrator isa KiteModels.OrdinaryDiffEqCore.ODEIntegrator +end + +@testset "SymbolicAWEModel init! interface" begin + sam.set.upwind_dir = rad2deg(-pi/2) + integ = init!(sam; stiffness_factor=0.5, delta=0.0001, prn=false) + @test integ isa KiteModels.OrdinaryDiffEqCore.ODEIntegrator + @test kps4.integrator isa KiteModels.OrdinaryDiffEqCore.ODEIntegrator +end +nothing \ No newline at end of file diff --git a/test/test_kps4.jl b/test/test_kps4.jl index 904ff8de..42d90915 100644 --- a/test/test_kps4.jl +++ b/test/test_kps4.jl @@ -518,7 +518,7 @@ println("--> test_simulate") STEPS = 500 kps4.set.depower = 23.6 kps4.set.solver = "IDA" - integrator = KiteModels.init_sim!(kps4; stiffness_factor=0.5, prn=false) + integrator = KiteModels.init!(kps4; stiffness_factor=0.5, prn=false) # println("\nStarting simulation...") simulate(integrator, 100) av_steps = simulate(integrator, STEPS-100) @@ -548,7 +548,7 @@ println("<-- finished test_simulate") @testset "Raptures" begin kps4_ = KPS4(KCU(set)) - integrator = KiteModels.init_sim!(kps4_; stiffness_factor=0.035, prn=false) + integrator = KiteModels.init!(kps4_; stiffness_factor=0.035, prn=false) kps4_.set.version = 2 kps4_.stiffness_factor = 3 @test maximum(spring_forces(kps4_; prn=false)) > 9000 diff --git a/test/test_ram_air_kite.jl b/test/test_ram_air_kite.jl index 6d84958c..a9bca9d8 100644 --- a/test/test_ram_air_kite.jl +++ b/test/test_ram_air_kite.jl @@ -27,8 +27,8 @@ const BUILD_SYS = true @info "Creating s:" @time s = SymbolicAWEModel(set) - s.set.abs_tol = 1e-2 - s.set.rel_tol = 1e-2 + s.set.abs_tol = 1e-4 + s.set.rel_tol = 1e-4 # Initialize at elevation set.elevation = 80.0 @@ -45,7 +45,7 @@ const BUILD_SYS = true # 1. First time initialization - should create new model @info "Testing initial init! (should create new model if it doesn't exist yet)..." - @time KiteModels.init_sim!(s; prn=true) + @time KiteModels.init!(s; prn=true) # Check that serialization worked @test isfile(model_path) @@ -62,9 +62,9 @@ const BUILD_SYS = true first_integrator_ptr = objectid(s.integrator) first_sys_struct_ptr = objectid(s.sys_struct) - # 2. First init_sim! - should load from serialized file - @info "Testing first init_sim! (should load serialized file)..." - @time KiteModels.init_sim!(s; prn=true, reload=false) + # 2. First init! - should load from serialized file + @info "Testing first init! (should load serialized file)..." + @time KiteModels.init!(s; prn=true, reload=false) next_step!(s) # Check that it's a new integrator @@ -73,9 +73,9 @@ const BUILD_SYS = true @test first_integrator_ptr != second_integrator_ptr @test first_sys_struct_ptr == second_sys_struct_ptr - # 3. Second init_sim! - should reuse existing integrator - @info "Testing second init_sim! (should reuse integrator)..." - @time KiteModels.init_sim!(s; prn=true, reload=false) + # 3. Second init! - should reuse existing integrator + @info "Testing second init! (should reuse integrator)..." + @time KiteModels.init!(s; prn=true, reload=false) # This should create a new point system but reuse the existing integrator third_integrator_ptr = objectid(s.integrator) @@ -108,7 +108,7 @@ const BUILD_SYS = true end @testset "State Consistency" begin - KiteModels.init_sim!(s, prn=true, reload=false) + KiteModels.init!(s, prn=true, reload=false) sys_state_before = KiteModels.SysState(s) @test isapprox(norm(s.integrator[s.sys.Q_b_w]), 1.0, atol=TOL) @test isapprox(sys_state_before.elevation, deg2rad(set.elevation), atol=1e-2) @@ -116,7 +116,7 @@ const BUILD_SYS = true # Change measurement and reinitialize old_elevation = set.elevation set.elevation = 85.0 - KiteModels.init_sim!(s, prn=true, reload=false) + KiteModels.init!(s, prn=true, reload=false) # Get new state using SysState sys_state_after = KiteModels.SysState(s) @@ -166,7 +166,7 @@ const BUILD_SYS = true function test_step(s, d_set_values=zeros(3); dt=0.05, steps=5) s.integrator.ps[s.sys.stabilize] = true - for i in 1:1÷dt + for i in 1:1÷0.1 next_step!(s; dt, vsm_interval=1) end s.integrator.ps[s.sys.stabilize] = false @@ -202,7 +202,7 @@ const BUILD_SYS = true @testset "Simulation Step with SysState" begin # Basic step and time advancement test - KiteModels.init_sim!(s; prn=true, reload=false) + KiteModels.init!(s; prn=true, reload=false) sys_state_before = KiteModels.SysState(s) # Run a simulation step with zero set values @@ -226,7 +226,7 @@ const BUILD_SYS = true # Initialize at 60 degrees elevation set.elevation = 60.0 - KiteModels.init_sim!(s; prn=true) + KiteModels.init!(s; prn=true) # Verify initial conditions using SysState sys_state_init = KiteModels.SysState(s) @@ -254,35 +254,37 @@ const BUILD_SYS = true return diff end - @testset "Steering Response Using SysState" begin - # Initialize model at moderate elevation - set.elevation = 70.0 - KiteModels.init_sim!(s; prn=true, reload=false) - test_step(s) - sys_state_initial = KiteModels.SysState(s) - - # steering right - KiteModels.init_sim!(s; prn=true, reload=false) - test_step(s, [0, 10, -10]; steps=20) - sys_state_right = KiteModels.SysState(s) - - # steering left - KiteModels.init_sim!(s; prn=true, reload=false) - test_step(s, [0, -10, 10]; steps=20) - sys_state_left = KiteModels.SysState(s) - - # Check steering values - @info "Steering:" sys_state_right.steering sys_state_left.steering - @test sys_state_right.steering > 3.0 - @test sys_state_left.steering < -3.0 - - # Check heading changes - right_heading_diff = angle_diff(sys_state_right.heading, sys_state_initial.heading) - @test right_heading_diff ≈ 0.9 atol=0.2 - left_heading_diff = angle_diff(sys_state_left.heading, sys_state_initial.heading) - @test left_heading_diff ≈ -0.9 atol=0.2 + if build_is_production_build + @testset "Steering Response Using SysState" begin + # Initialize model at moderate elevation + set.elevation = 70.0 + KiteModels.init!(s; prn=true, reload=false) + test_step(s) + sys_state_initial = KiteModels.SysState(s) + + # steering right + KiteModels.init!(s; prn=true, reload=false) + test_step(s, [0, 10, -10]; steps=20) + sys_state_right = KiteModels.SysState(s) + + # steering left + KiteModels.init!(s; prn=true, reload=false) + test_step(s, [0, -10, 10]; steps=20) + sys_state_left = KiteModels.SysState(s) + + # Check steering values + @info "Steering:" sys_state_right.steering sys_state_left.steering + @test sys_state_right.steering > 3.0 + @test sys_state_left.steering < -3.0 + + # Check heading changes + right_heading_diff = angle_diff(sys_state_right.heading, sys_state_initial.heading) + @test right_heading_diff ≈ 0.9 atol=0.2 + left_heading_diff = angle_diff(sys_state_left.heading, sys_state_initial.heading) + @test left_heading_diff ≈ -0.9 atol=0.2 + end + test_plot(s) end - test_plot(s) end @testset "Just a tether, without winch or kite" begin @@ -310,7 +312,7 @@ const BUILD_SYS = true sam = SymbolicAWEModel(set, sys_struct) sys = sam.sys - init_sim!(sam; remake=false) + KiteModels.init!(sam; remake=false) @test isapprox(sam.integrator[sam.sys.pos[:, end]], [8.682408883346524, 0.0, 0.7596123493895988], atol=1e-2) for i in 1:100 next_step!(sam) @@ -325,4 +327,4 @@ end # Restore original data path set_data_path(old_path) -nothing \ No newline at end of file +nothing diff --git a/test/test_sundials.jl b/test/test_sundials.jl index 25306fb5..42d06236 100644 --- a/test/test_sundials.jl +++ b/test/test_sundials.jl @@ -16,7 +16,7 @@ const kps4 = KPS4{Float64, KVec3, 6+4+1}() function residual!(res, yd, y::MVector{S, Float64}, s::KPS4, time) where S end -function init_sim!(t_end=1.0) +function init!(t_end=1.0) y0 = MVector{62, Float64}([13.970413450119487, 0.0, 21.238692070636343, 27.65581376097752, 0.0, 42.66213714321849, 40.976226230518435, 0.0, 64.314401166278, 53.87184032029182, 0.0, 86.22231803750196, 66.28915240374937, 0.0, 108.4048292516046, 78.17713830204762, 0.0, 130.87545423106485, 79.56930502428155, 0.0, 135.70836376062155, 80.90383289255747, 0.0, 137.7696816741141, 80.60126812407692, 2.4016533873456325, 135.3023287520457, 80.60126812407692, -2.4016533873456325, 135.3023287520457, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 150.0, 0.0]) yd0= MVector{62, Float64}([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -9.81, 0.0, 0.0, -9.81, 0.0, 0.0, -9.81, 0.0, 0.0, -9.81, 0.0, 0.0, -9.81, 0.0, 0.0, -9.81, 0.0, 0.0, -9.81, 0.0, 0.0, -9.81, 0.0, 0.0, -9.81, 0.0, 0.0, -9.81, 0.0, 0.0]) differential_vars = ones(Bool, length(y0)) @@ -29,6 +29,6 @@ end @testset "test_simulate " begin STEPS = 500 - integrator = init_sim!() + integrator = init!() end nothing