@@ -110,7 +110,7 @@ sol::VSMSolution = VSMSolution(): The result of calling [solve!](@ref)
110110 artificial_damping:: NamedTuple{(:k2, :k4), Tuple{Float64, Float64}} = (k2= 0.1 , k4= 0.0 )
111111
112112 # Additional settings
113- type_initial_gamma_distribution:: InitialGammaDistribution = ELLIPTIC
113+ type_initial_gamma_distribution:: InitialGammaDistribution = ZEROS
114114 core_radius_fraction:: Float64 = 1e-20
115115 mu:: Float64 = 1.81e-5
116116 is_only_f_and_gamma_output:: Bool = false
@@ -121,6 +121,7 @@ sol::VSMSolution = VSMSolution(): The result of calling [solve!](@ref)
121121 cache:: Vector{PreallocationTools.LazyBufferCache{typeof(identity), typeof(identity)}} = [LazyBufferCache () for _ in 1 : 11 ]
122122 cache_base:: Vector{PreallocationTools.LazyBufferCache{typeof(identity), typeof(identity)}} = [LazyBufferCache ()]
123123 cache_solve:: Vector{PreallocationTools.LazyBufferCache{typeof(identity), typeof(identity)}} = [LazyBufferCache ()]
124+ cache_lin:: Vector{PreallocationTools.LazyBufferCache{typeof(identity), typeof(identity)}} = [LazyBufferCache () for _ in 1 : 4 ]
124125
125126 # Solution
126127 sol:: VSMSolution{P} = VSMSolution (P)
@@ -624,26 +625,43 @@ Linearize the ram air wing aero model around an operating point using automatic
624625- `forces_op`: Forces at the operating point [Fx, Fy, Fz, Mx, My, Mz]
625626"""
626627function linearize (solver:: Solver , body_aero:: BodyAerodynamics , wing:: RamAirWing , y;
627- alpha_idxs = 1 : 4 ,
628+ theta_idxs = 1 : 4 ,
628629 delta_idxs= nothing ,
629630 va_idxs= nothing ,
630631 omega_idxs= nothing ,
631632 kwargs... )
632633
633- init_va = copy (body_aero. va)
634- init_alpha_beta = copy (y[alpha_idxs])
635- zero_delta = zeros (alpha_idxs)
634+ init_va = solver. cache_lin[1 ][body_aero. va]
635+ init_va .= body_aero. va
636+ if ! isnothing (theta_idxs)
637+ last_theta = solver. cache_lin[2 ][y[theta_idxs]]
638+ last_theta .= y[theta_idxs]
639+ end
640+ if ! isnothing (delta_idxs)
641+ last_delta = solver. cache_lin[3 ][y[delta_idxs]]
642+ last_delta .= y[delta_idxs]
643+ end
636644
637645 # Function to compute forces for given control inputs
638646 function calc_results! (results, y)
639- if ! isnothing (alpha_idxs) && isnothing (delta_idxs)
640- @views VortexStepMethod. smooth_deform! (wing, y[alpha_idxs], zero_delta)
641- elseif ! isnothing (alpha_idxs) && ! isnothing (delta_idxs)
642- @views VortexStepMethod. smooth_deform! (wing, y[alpha_idxs], y[delta_idxs])
647+ @views theta_angles = isnothing (theta_idxs) ? nothing : y[theta_idxs]
648+ @views delta_angles = isnothing (delta_idxs) ? nothing : y[delta_idxs]
649+
650+ if ! isnothing (theta_angles)
651+ if isnothing (delta_angles)
652+ if ! all (theta_angles .== last_theta)
653+ VortexStepMethod. group_deform! (wing, theta_angles; smooth= false )
654+ VortexStepMethod. init! (body_aero; init_aero= false )
655+ last_theta .= theta_angles
656+ end
657+ elseif ! all (delta_angles .== last_delta) || ! all (theta_angles .== last_theta)
658+ VortexStepMethod. group_deform! (wing, theta_angles, delta_angles; smooth= false )
659+ VortexStepMethod. init! (body_aero; init_aero= false )
660+ last_theta .= theta_angles
661+ last_delta .= delta_angles
662+ end
643663 end
644664
645- VortexStepMethod. init! (body_aero; init_aero= false )
646-
647665 if ! isnothing (va_idxs) && isnothing (omega_idxs)
648666 set_va! (body_aero, y[va_idxs])
649667 elseif ! isnothing (va_idxs) && ! isnothing (omega_idxs)
@@ -661,7 +679,7 @@ function linearize(solver::Solver, body_aero::BodyAerodynamics, wing::RamAirWing
661679
662680 results = zeros (3 + 3 + length (solver. sol. moment_coeff_dist))
663681 jac = zeros (length (results), length (y))
664- backend = AutoFiniteDiff (absstep= 1e-3 , relstep= 1e-3 )
682+ backend = AutoFiniteDiff (absstep= 1e2 solver . atol , relstep= 1e2 solver . rtol )
665683 prep = prepare_jacobian (calc_results!, results, backend, y)
666684 jacobian! (calc_results!, results, jac, prep, backend, y)
667685
0 commit comments