Skip to content

Commit

Permalink
stop passing an additional ivb around, fix the multi-solve chain solv…
Browse files Browse the repository at this point in the history
…er early convergence flagging bug, add some docstrings
  • Loading branch information
juddmehr committed Apr 23, 2024
1 parent 9b830c9 commit 59d8044
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 25 deletions.
27 changes: 10 additions & 17 deletions src/analysis/analyses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function analyze(
)

# - Set Up - #
problem_dimensions, prepost_containers, solve_parameter_cache_vector, solve_parameter_cache_dims, ivb, A_bb_LU, lu_decomp_flag, airfoils, idmaps = setup_analysis(
problem_dimensions, prepost_containers, solve_parameter_cache_vector, solve_parameter_cache_dims, A_bb_LU, lu_decomp_flag, airfoils, idmaps = setup_analysis(
propulsor,
options;
prepost_container_caching=prepost_container_caching,
Expand All @@ -59,7 +59,7 @@ function analyze(
#TODO: probably just call the post-process function directly and return a reset_container! of the output
if return_inputs
return [],#zero_outputs(),
(; solve_parameter_tuple..., ivb, airfoils, idmaps, panels, problem_dimensions),
(; solve_parameter_tuple..., airfoils, idmaps, panels, problem_dimensions),
false
else
return [],#zero_outputs(),
Expand All @@ -74,7 +74,6 @@ function analyze(
solve_parameter_cache_vector,
solve_parameter_cache_dims,
airfoils,
ivb,
A_bb_LU,
idmaps,
problem_dimensions,
Expand All @@ -91,7 +90,6 @@ end
solve_parameter_cache_vector,
solve_parameter_cache_dims,
airfoils,
ivb,
A_bb_LU,
idmaps,
problem_dimensions,
Expand All @@ -108,7 +106,6 @@ Analyze propulsor, assuming `setup_analysis` has been called and the outputs the
- `solve_parameter_cache_vector::Vector` : An output from `setup_analysis` containing the relevant typed cache vector of solve parameters
- `solve_parameter_cache_dims::NamedTuple` : An output from `setup_analysis` containing dimensions used for reshaping the solve parameter cache
- `airfoils::Vector{AFType}` : An output from `setup_analysis` contiaining the blade element airfoil polar objects
- `ivb::NamedTuple` : An output from `setup_analysis` containing the unit induced velocities on the body
- `A_bb_LU::LinearAlgebra.LU` : An output from `setup_analysis` that is the LU decomposition of the AIC matrix used in the panel method
- `idmaps::NamedTuple` : An output from `setup_analysis` containing bookkeeping information (index mappings)
- `problem_dimensions::NamedTuple` : An output from `setup_analysis` contiaining bookkeeping information (problem dimensions)
Expand All @@ -129,7 +126,6 @@ function analyze(
solve_parameter_cache_vector,
solve_parameter_cache_dims,
airfoils,
ivb,
A_bb_LU,
idmaps,
problem_dimensions,
Expand Down Expand Up @@ -180,16 +176,18 @@ function analyze(

if return_inputs
solve_parameter_tuple = withdraw_solve_parameter_cache(
solver_options, solve_parameter_cache_vector, solve_parameter_cache_dims
options.solver_options, solve_parameter_cache_vector, solve_parameter_cache_dims
)

return outs,
(;
prepost_containers.panels,
prepost_containers.ivb,
solve_parameter_tuple...,
blade_elements=(; blade_elements..., airfoils...),
linsys=(; linsys..., A_bb_LU),
blade_elements=(; solve_parameter_tuple.blade_elements..., airfoils...),
linsys=(; solve_parameter_tuple.linsys..., A_bb_LU),
idmaps,
problem_dimensions,
),
options.solver_options.converged[]
else
Expand Down Expand Up @@ -237,7 +235,7 @@ function analyze(
) where {TO<:OperatingPoint}

# - Set Up - #
problem_dimensions, prepost_containers, solve_parameter_cache_vector, solve_parameter_cache_dims, ivb, A_bb_LU, lu_decomp_flag, airfoils, idmaps = setup_analysis(
problem_dimensions, prepost_containers, solve_parameter_cache_vector, solve_parameter_cache_dims, A_bb_LU, lu_decomp_flag, airfoils, idmaps = setup_analysis(
propulsor,
options;
prepost_container_caching=prepost_container_caching,
Expand Down Expand Up @@ -271,7 +269,6 @@ function analyze(
solve_parameter_cache_vector,
solve_parameter_cache_dims,
airfoils,
ivb,
A_bb_LU,
idmaps,
problem_dimensions,
Expand All @@ -289,7 +286,6 @@ end
solve_parameter_cache_vector,
solve_parameter_cache_dims,
airfoils,
ivb,
A_bb_LU,
idmaps,
problem_dimensions,
Expand All @@ -307,7 +303,6 @@ Analyze propulsor, assuming `setup_analysis` has been called and the inputs are
- `solve_parameter_cache_vector::Vector` : An output from `setup_analysis` containing the relevant typed cache vector of solve parameters
- `solve_parameter_cache_dims::NamedTuple` : An output from `setup_analysis` containing dimensions used for reshaping the solve parameter cache
- `airfoils::Vector{AFType}` : An output from `setup_analysis` contiaining the blade element airfoil polar objects
- `ivb::NamedTuple` : An output from `setup_analysis` containing the unit induced velocities on the body
- `A_bb_LU::LinearAlgebra.LU` : An output from `setup_analysis` that is the LU decomposition of the AIC matrix used in the panel method
- `idmaps::NamedTuple` : An output from `setup_analysis` containing bookkeeping information (index mappings)
- `problem_dimensions::NamedTuple` : An output from `setup_analysis` contiaining bookkeeping information (problem dimensions)
Expand All @@ -329,7 +324,6 @@ function analyze(
solve_parameter_cache_vector,
solve_parameter_cache_dims,
airfoils,
ivb,
A_bb_LU,
idmaps,
problem_dimensions,
Expand Down Expand Up @@ -359,7 +353,6 @@ function analyze(
solve_parameter_cache_vector,
solve_parameter_cache_dims,
airfoils,
ivb,
A_bb_LU,
idmaps,
problem_dimensions,
Expand All @@ -381,6 +374,8 @@ function analyze(
solve_parameter_tuple...,
blade_elements=(; blade_elements..., airfoils...),
linsys=(; linsys..., A_bb_LU),
idmaps,
problem_dimensions,
),
options.solver_options.converged
else
Expand All @@ -396,7 +391,6 @@ end
solve_parameter_cache_vector,
solve_parameter_cache_dims,
airfoils,
ivb,
A_bb_LU,
idmaps,
problem_dimensions,
Expand All @@ -414,7 +408,6 @@ function analyze_multipoint(
solve_parameter_cache_vector,
solve_parameter_cache_dims,
airfoils,
ivb,
A_bb_LU,
idmaps,
problem_dimensions,
Expand Down
4 changes: 1 addition & 3 deletions src/analysis/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Perform pre-processing and cache setup (as needed) for propuslor analysis.
- `prepost_containers::NamedTuple` : Named Tuple containing reshaped views into the prepost cache
- `solve_parameter_cache_vector::Vector` : Vector containing the relevant typed cache vector of solve parameters
- `solve_parameter_cache_dims::NamedTuple` : Named Tuple containing dimensions used for reshaping the solve parameter cache
- `ivb::NamedTuple` : NamedTuple containing the unit induced velocities on the body
- `A_bb_LU::LinearAlgebra.LU` : The LU factorization of the AIC matrix used in the panel method
- `lu_decomp_flag::Bool` : flag indicating if the LU decomposition was successful
- `airfoils::Matrix{AFType}` : Matrix contiaining the blade element airfoil polar objects
Expand Down Expand Up @@ -120,7 +119,7 @@ function setup_analysis(
##### ----- PERFORM PREPROCESSING COMPUTATIONS ----- #####

# - Preprocess - #
ivb, A_bb_LU, lu_decomp_flag, airfoils, idmaps, _ = precompute_parameters!(
A_bb_LU, lu_decomp_flag, airfoils, idmaps, _ = precompute_parameters!(
solve_parameter_tuple.ivr,
solve_parameter_tuple.ivw,
solve_parameter_tuple.blade_elements,
Expand All @@ -144,7 +143,6 @@ function setup_analysis(
prepost_containers,
solve_parameter_cache_vector,
solve_parameter_cache_dims,
ivb,
A_bb_LU,
lu_decomp_flag,
airfoils,
Expand Down
36 changes: 34 additions & 2 deletions src/preprocess/geometry/body_geometry.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
"""
reinterpolate_bodies!(
rp_duct_coordinates,
rp_centerbody_coordinates,
duct_coordinates,
centerbody_coordinates,
zwake,
ncenterbody_inlet,
nduct_inlet;
finterp=FLOWMath.akima,
)
Reinterpolate duct and centerbody coordinates in order to make them compatible with the calculated wake sheet panel axial positions.
# Arguments
- `rp_duct_coordinates::Matrix{Float}` : the re-paneled duct coordinates
- `rp_centerbody_coordinates::Matrix{Float}` : the re-paneled centerbody coordinates
- `duct_coordinates::Matrix{Float}` : the input duct coordinates
- `centerbody_coordinates::Matrix{Float}` : the input centerbody coordinates
- `zwake::Matrix{Float}` : the wake sheet panel node axial positions
- `ncenterbody_inlet::Matrix{Float}` : the number of panels to use for the centerbody inlet
- `nduct_inlet::Matrix{Float}` : the number of panels to use for the duct inlet
# Keyword Arguments
- `finterp::Function=FLOWMath.akima` : interpolation method
"""
function reinterpolate_bodies!(
rp_duct_coordinates,
Expand Down Expand Up @@ -74,9 +98,17 @@ function reinterpolate_bodies!(
end

"""
transforms duct radial coordinates such that the leading rotor radius touches the duct wall.
Also finds the various rotor centerbody and tip radii based on the centerbody and duct geometry
place_duct!(rp_duct_coordinates, Rtip, rotorzloc, tip_gap)
Transform the duct radial coordinates such that the leading rotor radius touches the duct wall.
Note that this function is called AFTER the repanling function is called, such that the rotorzloc locations should line up directly with the duct and centerbody coordinates.
# Arguments
- `rp_duct_coordinates::Matrix{Float}` : the re-paneled duct coordinates
- `Rtip::Vector{Float}` : Tip radii for the rotor(s)
- `rotorzloc::Vector{Float}` : axial position(s) of the rotor(s)
- `tip_gap::Vector{Float}` : tip gap for the fore-most rotor (MUST BE ZERO for now)
"""
function place_duct!(rp_duct_coordinates, Rtip, rotorzloc, tip_gap)

Expand Down
54 changes: 54 additions & 0 deletions src/preprocess/geometry/rotor_geometry.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
"""
interpolate_blade_elements(
rsp, Rtips, Rhubs, rotor_panel_centers, nbe; finterp=FLOWMath.linear
)
Interpolate blade elements based on RotorStatorParameters inputs and number of desired blade elements (from number of wake sheet in PanelingConstants input)
# Arguments
- `rsp::RotorStatorParameters` : A RotorStatorParameters object
- `Rtips::Vector{Float}' : Vector of rotor tip radii
- `Rhubs::Vector{Float}' : Vector of rotor hub radii
- `rotor_panel_centers::Vector{Float}' : Vector of rotor panel centers
- `nbe::Int` : number of blade elements per rotor
# Keyword Arguments
- `finterp::Function=FLOWMath.linear` : interpolation method (note, using Akima splines as is done for the body geometry can lead to negative chord in some cases)
# Returns
- `blade_element_cache::NamedTuple` : A named tuple containing the cacheable blade element information excluding the airfoil data.
- `airfoils::NamedTuple` : A named tuple containing vectors of inner and outer airfoil polar data for each blade element, used in interpolating the input data at blade element locations.
"""
function interpolate_blade_elements(
rsp, Rtips, Rhubs, rotor_panel_centers, nbe; finterp=FLOWMath.linear
)
Expand Down Expand Up @@ -71,6 +92,16 @@ function interpolate_blade_elements(
(; outer_airfoil, inner_airfoil)
end

"""
interpolate_blade_elements!(
blade_element_cache, rsp, rotor_panel_centers, nbe; finterp=FLOWMath.linear
)
In-place version of interpolate_blade_elements.
# Returns
- `airfoils::NamedTuple` : A named tuple containing vectors of inner and outer airfoil polar data for each blade element, used in interpolating the input data at blade element locations.
"""
function interpolate_blade_elements!(
blade_element_cache, rsp, rotor_panel_centers, nbe; finterp=FLOWMath.linear
)
Expand Down Expand Up @@ -140,6 +171,16 @@ function interpolate_blade_elements!(
end

"""
handle
Description
# Arguments
- `var::type` :
# Keyword Arguments
- `var::type=default` :
"""
function get_blade_ends_from_body_geometry(
duct_coordinates, centerbody_coordinates, tip_gaps, rotorzloc
Expand All @@ -159,6 +200,19 @@ function get_blade_ends_from_body_geometry(
)
end

"""
get_blade_ends_from_body_geometry!(
Rtip,
Rhub,
duct_coordinates,
centerbody_coordinates,
tip_gaps,
rotorzloc;
silence_warnings=true,
)
In-place version of get_blade_ends_from_body_geometry.
"""
function get_blade_ends_from_body_geometry!(
Rtip,
Rhub,
Expand Down
2 changes: 1 addition & 1 deletion src/preprocess/preprocess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1657,5 +1657,5 @@ function precompute_parameters!(
problem_dimensions.nrotor,
)

return ivb, A_bb_LU, lu_decomp_flag, airfoils, idmaps, problem_dimensions
return A_bb_LU, lu_decomp_flag, airfoils, idmaps, problem_dimensions
end
4 changes: 2 additions & 2 deletions src/process/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function solve(
println(" " * "CSOR Solve Trace:")
end


# loop until converged or max iterations are reached
while !conv[] && iter <= solver_options.iteration_limit
# update iteration number
Expand Down Expand Up @@ -788,7 +787,8 @@ function solve(
)

# If there is only one solver, or if the first solver converged, return the solution
if length(solver_options.solvers) == 1 || solver_options.solvers[1].converged[1]
if length(solver_options.solvers) == 1 ||
solver_options.solvers[1].converged[const_cache.multipoint_index[]]
solver_options.converged[const_cache.multipoint_index[]] = solver_options.solvers[1].converged[const_cache.multipoint_index[]]
return solution
end
Expand Down

0 comments on commit 59d8044

Please sign in to comment.