Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/src/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_section!
set_va!
solve
solve!
init!(body_aero::BodyAerodynamics)
reinit!(body_aero::BodyAerodynamics)
linearize
```

Expand Down
2 changes: 1 addition & 1 deletion docs/src/tips_and_tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/ram_air_kite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/VortexStepMethod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/body_aerodynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.

Expand All @@ -129,15 +129,15 @@ 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)
)
idx = 1
vec = zeros(MVec3)
for wing in body_aero.wings
init!(wing)
reinit!(wing)
panel_props = wing.panel_props

# Create panels
Expand All @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions src/filament.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/panel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -184,7 +184,7 @@ function init_aero!(
end
end

function init!(
function reinit!(
panel::Panel,
section_1::Section,
section_2::Section,
Expand Down
6 changes: 3 additions & 3 deletions src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/wake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions src/wing_geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
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)
Expand All @@ -54,7 +54,7 @@
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
Expand Down Expand Up @@ -241,7 +241,7 @@
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
Expand Down Expand Up @@ -368,7 +368,7 @@
# 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
Expand All @@ -377,8 +377,8 @@

# 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])

Check warning on line 381 in src/wing_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/wing_geometry.jl#L380-L381

Added lines #L380 - L381 were not covered by tests
return nothing
end

Expand Down Expand Up @@ -593,7 +593,7 @@

# 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
Expand Down Expand Up @@ -653,7 +653,7 @@

# Generate new sections
for (i, (control_point, chord)) in enumerate(zip(control_points, chords))
@views init!(wing.refined_sections,
@views reinit!(wing.refined_sections,

Check warning on line 656 in src/wing_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/wing_geometry.jl#L656

Added line #L656 was not covered by tests
control_point - 0.25 * chord,
control_point + 0.75 * chord,
sections[i].aero_model,
Expand Down Expand Up @@ -683,7 +683,7 @@
# 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)

Check warning on line 686 in src/wing_geometry.jl

View check run for this annotation

Codecov / codecov/patch

src/wing_geometry.jl#L686

Added line #L686 was not covered by tests
end
return nothing
end
Expand Down Expand Up @@ -711,7 +711,7 @@
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
Expand Down Expand Up @@ -746,7 +746,7 @@
end

# Add final section
init!(wing.refined_sections[idx], wing.sections[end])
reinit!(wing.refined_sections[idx], wing.sections[end])
idx += 1

# Validate result
Expand Down
6 changes: 3 additions & 3 deletions test/bench.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/test_bound_filament.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/test_kite_geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/test_panel.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions test/test_results.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading