From 3d6c05f11cf7c03eb734f19e3b36c34e777e7c08 Mon Sep 17 00:00:00 2001 From: 1-Bart-1 Date: Fri, 11 Jul 2025 11:58:07 +0200 Subject: [PATCH] Rename init to reinit --- NEWS.md | 2 +- docs/src/functions.md | 2 +- docs/src/tips_and_tricks.md | 2 +- examples/ram_air_kite.jl | 4 ++-- src/VortexStepMethod.jl | 2 +- src/body_aerodynamics.jl | 10 +++++----- src/filament.jl | 4 ++-- src/panel.jl | 8 ++++---- src/solver.jl | 6 +++--- src/wake.jl | 4 ++-- src/wing_geometry.jl | 24 ++++++++++++------------ test/bench.jl | 6 +++--- test/test_bound_filament.jl | 8 ++++---- test/test_kite_geometry.jl | 4 ++-- test/test_panel.jl | 4 ++-- test/test_results.jl | 8 ++++---- test/test_semi_infinite_filament.jl | 2 +- 17 files changed, 50 insertions(+), 50 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1ff029b5..e1a520dd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -35,7 +35,7 @@ ### Changed - The fields that had as type a `Matrix of size Px1` have now the type `Vector` - Many new fields of the type `VSMSolution` documented -- `init!(body_aero)` is now a public function +- `reinit!(body_aero)` is now a public function ### Added - Added the option to use nonlinear solve to calculate the gamma distribution #140 - New page `Tips and tricks` added to the documentation diff --git a/docs/src/functions.md b/docs/src/functions.md index 01f7d576..341f8630 100644 --- a/docs/src/functions.md +++ b/docs/src/functions.md @@ -11,7 +11,7 @@ add_section! set_va! solve solve! -init!(body_aero::BodyAerodynamics) +reinit!(body_aero::BodyAerodynamics) linearize ``` diff --git a/docs/src/tips_and_tricks.md b/docs/src/tips_and_tricks.md index a5cf0993..64995f34 100644 --- a/docs/src/tips_and_tricks.md +++ b/docs/src/tips_and_tricks.md @@ -17,7 +17,7 @@ If running the example `ram_air_kite.jl` fails, try to run the `cleanup.jl` scri Currently, the `solve!()` function returns the results as [VSMSolution](@ref) struct. The function solve() returns a dictionary with the results. The `solve!()` function is faster, and the `solve()` contains many more entries, therefore the first function is good for integration in dynamic models and the second one better suited for aerodynamic analysis. ## Performance -Calling `init!(body_aero; init_aero=false)` is very fast. After calling `deform!(wing)`, you have to run `init!(body_aero; init_aero=false)` to apply the deformed wing to the body aerodynamics. This is in turn necessary for the linearization from deformation to aerodynamic coefficients for RAM-air kites. +Calling `reinit!(body_aero; init_aero=false)` is very fast. After calling `deform!(wing)`, you have to run `reinit!(body_aero; init_aero=false)` to apply the deformed wing to the body aerodynamics. This is in turn necessary for the linearization from deformation to aerodynamic coefficients for RAM-air kites. ## Contributing Please, read [CONTRIBUTING.md](https://github.com/OpenSourceAWE/VortexStepMethod.jl/blob/main/CONTRIBUTING.md) diff --git a/examples/ram_air_kite.jl b/examples/ram_air_kite.jl index 9717bac4..ab30b027 100644 --- a/examples/ram_air_kite.jl +++ b/examples/ram_air_kite.jl @@ -12,14 +12,14 @@ LINEARIZE = false wing = RamAirWing("data/ram_air_kite_body.obj", "data/ram_air_kite_foil.dat"; prn=PRN) body_aero = BodyAerodynamics([wing];) println("First init") -@time VortexStepMethod.init!(body_aero) +@time VortexStepMethod.reinit!(body_aero) if DEFORM # Linear interpolation of alpha from 10° at one tip to 0° at the other println("Deform") @time VortexStepMethod.smooth_deform!(wing, deg2rad.([10,20,10,0]), deg2rad.([-10,0,-10,0])) println("Deform init") - @time VortexStepMethod.init!(body_aero; init_aero=false) + @time VortexStepMethod.reinit!(body_aero; init_aero=false) end # Create solvers diff --git a/src/VortexStepMethod.jl b/src/VortexStepMethod.jl index ee97a02f..15d3829b 100644 --- a/src/VortexStepMethod.jl +++ b/src/VortexStepMethod.jl @@ -26,7 +26,7 @@ using Xfoil # Export public interface export VSMSettings, WingSettings, SolverSettings, vs -export Wing, Section, RamAirWing, init! +export Wing, Section, RamAirWing, reinit! export BodyAerodynamics export Solver, solve, solve_base!, solve!, VSMSolution, linearize export calculate_results diff --git a/src/body_aerodynamics.jl b/src/body_aerodynamics.jl index 9e893536..6860ac94 100644 --- a/src/body_aerodynamics.jl +++ b/src/body_aerodynamics.jl @@ -94,7 +94,7 @@ function BodyAerodynamics( end body_aero = BodyAerodynamics{length(panels)}(; panels, wings) - init!(body_aero; va, omega) + reinit!(body_aero; va, omega) return body_aero end @@ -114,7 +114,7 @@ function Base.setproperty!(obj::BodyAerodynamics, sym::Symbol, val) end """ - init!(body_aero::BodyAerodynamics; init_aero, va, omega) + reinit!(body_aero::BodyAerodynamics; init_aero, va, omega) Initialize a BodyAerodynamics struct in-place by setting up panels and coefficients. @@ -129,7 +129,7 @@ Initialize a BodyAerodynamics struct in-place by setting up panels and coefficie # Returns nothing """ -function init!(body_aero::BodyAerodynamics; +function reinit!(body_aero::BodyAerodynamics; init_aero=true, va=[15.0, 0.0, 0.0], omega=zeros(MVec3) @@ -137,7 +137,7 @@ function init!(body_aero::BodyAerodynamics; idx = 1 vec = zeros(MVec3) for wing in body_aero.wings - init!(wing) + reinit!(wing) panel_props = wing.panel_props # Create panels @@ -147,7 +147,7 @@ function init!(body_aero::BodyAerodynamics; else delta = 0.0 end - @views init!( + @views reinit!( body_aero.panels[idx], wing.refined_sections[i], wing.refined_sections[i+1], diff --git a/src/filament.jl b/src/filament.jl index 09685f32..22b5fc8d 100644 --- a/src/filament.jl +++ b/src/filament.jl @@ -28,7 +28,7 @@ Represents a bound vortex filament defined by two points. initialized::Bool = false end -function init!(filament::BoundFilament, x1, x2, vec=zeros(MVec3)) +function reinit!(filament::BoundFilament, x1, x2, vec=zeros(MVec3)) filament.x1 .= x1 filament.x2 .= x2 vec .= x2 .- x1 @@ -173,7 +173,7 @@ Represents a semi-infinite vortex filament. initialized::Bool = false end -function init!(filament::SemiInfiniteFilament, x1::PosVector, direction::PosVector, vel_mag::Real, filament_direction::Real) +function reinit!(filament::SemiInfiniteFilament, x1::PosVector, direction::PosVector, vel_mag::Real, filament_direction::Real) filament.x1 .= x1 filament.direction .= direction filament.vel_mag = vel_mag diff --git a/src/panel.jl b/src/panel.jl index e6992aaa..23886f4d 100644 --- a/src/panel.jl +++ b/src/panel.jl @@ -102,9 +102,9 @@ function init_pos!( panel.corner_points[:, 4] = panel.LE_point_2 vec .= bound_point_2 .- bound_point_1 panel.width = norm(vec) - init!(panel.filaments[1], bound_point_2, bound_point_1, vec) - init!(panel.filaments[2], bound_point_1, panel.TE_point_1, vec) - init!(panel.filaments[3], panel.TE_point_2, bound_point_2, vec) + reinit!(panel.filaments[1], bound_point_2, bound_point_1, vec) + reinit!(panel.filaments[2], bound_point_1, panel.TE_point_1, vec) + reinit!(panel.filaments[3], panel.TE_point_2, bound_point_2, vec) panel.bound_point_1 .= bound_point_1 panel.bound_point_2 .= bound_point_2 @@ -184,7 +184,7 @@ function init_aero!( end end -function init!( +function reinit!( panel::Panel, section_1::Section, section_2::Section, diff --git a/src/solver.jl b/src/solver.jl index b6f684ef..36a8b632 100644 --- a/src/solver.jl +++ b/src/solver.jl @@ -707,20 +707,20 @@ function linearize(solver::Solver, body_aero::BodyAerodynamics, y::Vector{T}; if !isnothing(theta_angles) && isnothing(delta_angles) if !all(theta_angles .== last_theta) VortexStepMethod.group_deform!(wing, theta_angles, nothing; smooth=false) - VortexStepMethod.init!(body_aero; init_aero=false) + VortexStepMethod.reinit!(body_aero; init_aero=false) last_theta .= theta_angles end elseif !isnothing(theta_angles) && !isnothing(delta_angles) if !all(delta_angles .== last_delta) || !all(theta_angles .== last_theta) VortexStepMethod.group_deform!(wing, theta_angles, delta_angles; smooth=false) - VortexStepMethod.init!(body_aero; init_aero=false) + VortexStepMethod.reinit!(body_aero; init_aero=false) last_theta .= theta_angles last_delta .= delta_angles end elseif isnothing(theta_angles) && !isnothing(delta_angles) if !all(delta_angles .== last_delta) VortexStepMethod.group_deform!(wing, nothing, delta_angles; smooth=false) - VortexStepMethod.init!(body_aero; init_aero=false) + VortexStepMethod.reinit!(body_aero; init_aero=false) last_delta .= delta_angles end end diff --git a/src/wake.jl b/src/wake.jl index 1d1fab4a..eeffe8d2 100644 --- a/src/wake.jl +++ b/src/wake.jl @@ -18,14 +18,14 @@ function frozen_wake!(body_aero::BodyAerodynamics, va_distribution) va_i = va_distribution[i, :] vel_mag = norm(va_i) direction = va_i / vel_mag - init!( + reinit!( panel.filaments[4], panel.TE_point_1, direction, vel_mag, 1 ) - init!( + reinit!( panel.filaments[5], panel.TE_point_2, direction, diff --git a/src/wing_geometry.jl b/src/wing_geometry.jl index 116cbd2d..d7950894 100644 --- a/src/wing_geometry.jl +++ b/src/wing_geometry.jl @@ -36,11 +36,11 @@ function Section(LE_point, TE_point, aero_model) end """ - init!(section::Section, LE_point::PosVector, TE_point::PosVector, aero_model=nothing, aero_data=nothing) + reinit!(section::Section, LE_point::PosVector, TE_point::PosVector, aero_model=nothing, aero_data=nothing) Function to update a [Section](@ref) in place. """ -function init!(section::Section, LE_point, TE_point, aero_model=nothing, aero_data=nothing) +function reinit!(section::Section, LE_point, TE_point, aero_model=nothing, aero_data=nothing) section.LE_point .= LE_point section.TE_point .= TE_point (!isnothing(aero_model)) && (section.aero_model = aero_model) @@ -54,7 +54,7 @@ function init!(section::Section, LE_point, TE_point, aero_model=nothing, aero_da nothing end -function init!(refined_section::Section, section::Section) +function reinit!(refined_section::Section, section::Section) refined_section.LE_point .= section.LE_point refined_section.TE_point .= section.TE_point refined_section.aero_model = section.aero_model @@ -241,7 +241,7 @@ function Wing(n_panels::Int; Wing(n_panels, n_groups, spanwise_distribution, panel_props, spanwise_direction, Section[], Section[], remove_nan) end -function init!(wing::AbstractWing) +function reinit!(wing::AbstractWing) refine_aerodynamic_mesh!(wing) # Calculate panel properties @@ -368,7 +368,7 @@ function refine_aerodynamic_mesh!(wing::AbstractWing) # Handle special cases if wing.spanwise_distribution == UNCHANGED || length(wing.sections) == n_sections for i in eachindex(wing.sections) - init!(wing.refined_sections[i], wing.sections[i]) + reinit!(wing.refined_sections[i], wing.sections[i]) end return nothing end @@ -377,8 +377,8 @@ function refine_aerodynamic_mesh!(wing::AbstractWing) # Handle two-section case if n_sections == 2 - init!(wing.refined_sections[1], LE[1,:], TE[1,:], aero_model[1], aero_data[1]) - init!(wing.refined_sections[2], LE[end,:], TE[end,:], aero_model[end], aero_data[end]) + reinit!(wing.refined_sections[1], LE[1,:], TE[1,:], aero_model[1], aero_data[1]) + reinit!(wing.refined_sections[2], LE[end,:], TE[end,:], aero_model[end], aero_data[end]) return nothing end @@ -593,7 +593,7 @@ function refine_mesh_for_linear_cosine_distribution!( # Create new section if endpoints || (i != 1 && i != n_sections) - @views init!(wing.refined_sections[idx], new_LE[i,:], new_TE[i,:], aero_model[1], new_data) + @views reinit!(wing.refined_sections[idx], new_LE[i,:], new_TE[i,:], aero_model[1], new_data) idx += 1 end end @@ -653,7 +653,7 @@ function calculate_cosine_van_Garrel!(wing::AbstractWing, idx) # Generate new sections for (i, (control_point, chord)) in enumerate(zip(control_points, chords)) - @views init!(wing.refined_sections, + @views reinit!(wing.refined_sections, control_point - 0.25 * chord, control_point + 0.75 * chord, sections[i].aero_model, @@ -683,7 +683,7 @@ function refine_mesh_by_splitting_provided_sections!(wing::AbstractWing) # Check if refinement is needed if n_panels_provided == n_panels_desired for (refined_section, section) in zip(wing.refined_sections, wing.sections) - init!(refined_section, section) + reinit!(refined_section, section) end return nothing end @@ -711,7 +711,7 @@ function refine_mesh_by_splitting_provided_sections!(wing::AbstractWing) idx = 1 for left_section_index in 1:n_section_pairs # Add left section of pair - init!(wing.refined_sections[idx], wing.sections[left_section_index]) + reinit!(wing.refined_sections[idx], wing.sections[left_section_index]) idx += 1 # Calculate new sections for this pair @@ -746,7 +746,7 @@ function refine_mesh_by_splitting_provided_sections!(wing::AbstractWing) end # Add final section - init!(wing.refined_sections[idx], wing.sections[end]) + reinit!(wing.refined_sections[idx], wing.sections[end]) idx += 1 # Validate result diff --git a/test/bench.jl b/test/bench.jl index 504359ec..5acfb95f 100644 --- a/test/bench.jl +++ b/test/bench.jl @@ -15,7 +15,7 @@ using VortexStepMethod: calculate_AIC_matrices!, gamma_loop!, calculate_results, velocity_3D_trailing_vortex!, velocity_3D_trailing_vortex_semiinfinite!, Panel, - init! + reinit! using Test using LinearAlgebra @@ -55,10 +55,10 @@ using LinearAlgebra body_aero = BodyAerodynamics([wing]) unchanged_body_aero = BodyAerodynamics([unchanged_wing]) - init!(unchanged_body_aero) + reinit!(unchanged_body_aero) @testset "Re-initialization" begin - result = @benchmark init!($unchanged_body_aero; init_aero=false) samples=1 evals=1 + result = @benchmark reinit!($unchanged_body_aero; init_aero=false) samples=1 evals=1 @info "Re-initializing Allocations: $(result.allocs) \t Memory: $(result.memory)" @test result.allocs ≤ 50 end diff --git a/test/test_bound_filament.jl b/test/test_bound_filament.jl index a02df8ef..d8faadcb 100644 --- a/test/test_bound_filament.jl +++ b/test/test_bound_filament.jl @@ -1,11 +1,11 @@ -using VortexStepMethod: BoundFilament, velocity_3D_bound_vortex!, init! +using VortexStepMethod: BoundFilament, velocity_3D_bound_vortex!, reinit! using LinearAlgebra using Test # Test helper functions function create_test_filament() fil = BoundFilament() - init!(fil, [0.0, 0.0, 0.0], [1.0, 0.0, 0.0]) + reinit!(fil, [0.0, 0.0, 0.0], [1.0, 0.0, 0.0]) return fil end @@ -72,7 +72,7 @@ end @testset "Long Filament" begin filament = BoundFilament() - init!(filament, [0.0, 0.0, 0.0], [1e6, 0.0, 0.0]) + reinit!(filament, [0.0, 0.0, 0.0], [1e6, 0.0, 0.0]) control_point = [5e5, 1.0, 0.0] velocity_3D_bound_vortex!( @@ -122,7 +122,7 @@ end @testset "Symmetry" begin filament = BoundFilament() - init!(filament, [-1.0, 0.0, 0.0], [1.0, 0.0, 0.0]) + reinit!(filament, [-1.0, 0.0, 0.0], [1.0, 0.0, 0.0]) velocity_3D_bound_vortex!(v1, filament, [0.0, 1.0, 0.0], gamma, core_radius_fraction, work_vectors) velocity_3D_bound_vortex!(v2, filament, [0.0, -1.0, 0.0], gamma, core_radius_fraction, work_vectors) diff --git a/test/test_kite_geometry.jl b/test/test_kite_geometry.jl index 9111496a..74b6fd9c 100644 --- a/test/test_kite_geometry.jl +++ b/test/test_kite_geometry.jl @@ -199,7 +199,7 @@ using Serialization delta_dist = fill(deg2rad(5.0), wing.n_panels) # 5 degrees trailing edge deflection VortexStepMethod.deform!(wing, theta_dist, delta_dist) - VortexStepMethod.init!(body_aero) + VortexStepMethod.reinit!(body_aero) # Check if TE point changed after deformation deformed_te_point = copy(body_aero.panels[i].TE_point_1) @@ -214,7 +214,7 @@ using Serialization zero_delta_dist = zeros(wing.n_panels) VortexStepMethod.deform!(wing, zero_theta_dist, zero_delta_dist) - VortexStepMethod.init!(body_aero) + VortexStepMethod.reinit!(body_aero) # Check if TE point returned to original position reset_te_point = copy(body_aero.panels[i].TE_point_1) diff --git a/test/test_panel.jl b/test/test_panel.jl index 1f56acd6..ff4a89ba 100644 --- a/test/test_panel.jl +++ b/test/test_panel.jl @@ -1,4 +1,4 @@ -using VortexStepMethod: Panel, Section, calculate_relative_alpha_and_relative_velocity, calculate_cl, calculate_cd_cm, init! +using VortexStepMethod: Panel, Section, calculate_relative_alpha_and_relative_velocity, calculate_cl, calculate_cd_cm, reinit! using Interpolations: linear_interpolation, Line using LinearAlgebra using Test @@ -36,7 +36,7 @@ function create_panel(section1::Section, section2::Section) y_airf = y_airf ./ norm(y_airf) panel = Panel() - init!( + reinit!( panel, section1, section2, diff --git a/test/test_results.jl b/test/test_results.jl index 42339988..fd3470fc 100644 --- a/test/test_results.jl +++ b/test/test_results.jl @@ -1,5 +1,5 @@ using VortexStepMethod -using VortexStepMethod: calculate_cl, calculate_cd_cm, calculate_projected_area, calculate_AIC_matrices!, init! +using VortexStepMethod: calculate_cl, calculate_cd_cm, calculate_projected_area, calculate_AIC_matrices!, reinit! using LinearAlgebra using Test using Logging @@ -101,7 +101,7 @@ end throw(ArgumentError()) end VortexStepMethod.group_deform!(ram_wing, reset_theta, reset_delta; smooth=false) - init!(body_aero; init_aero=false, va=reset_va, omega=reset_omega) + reinit!(body_aero; init_aero=false, va=reset_va, omega=reset_omega) # Get nonlinear solution nonlin_res = VortexStepMethod.solve!(solver, body_aero, nothing; log=false) @@ -176,7 +176,7 @@ end @testset "$combo_name" begin # Start with a fresh model for each combination test VortexStepMethod.group_deform!(ram_wing, theta, delta; smooth=false) - init!(body_aero; init_aero=false, va, omega) + reinit!(body_aero; init_aero=false, va, omega) # Create the appropriate input vector for this combination input_vec = Vector{Float64}(undef, length(active_indices)) @@ -228,7 +228,7 @@ end # Apply to nonlinear model VortexStepMethod.group_deform!(ram_wing, perturbed_theta, perturbed_delta; smooth=false) - init!(body_aero; init_aero=false, va=perturbed_va, omega=perturbed_omega) + reinit!(body_aero; init_aero=false, va=perturbed_va, omega=perturbed_omega) # Get nonlinear solution with perturbation nonlin_res = VortexStepMethod.solve!(solver, body_aero; log=false) diff --git a/test/test_semi_infinite_filament.jl b/test/test_semi_infinite_filament.jl index 7b82ac48..e21ec1cd 100644 --- a/test/test_semi_infinite_filament.jl +++ b/test/test_semi_infinite_filament.jl @@ -9,7 +9,7 @@ function create_test_filament2() filament_direction = 1 vel_mag = 1.0 filament = SemiInfiniteFilament() - init!(filament, x1, direction, vel_mag, filament_direction) + reinit!(filament, x1, direction, vel_mag, filament_direction) return filament end