Skip to content

Commit

Permalink
update code and tests to allow for various implemented quadrature opt…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
juddmehr committed Apr 4, 2024
1 parent c97f772 commit 9a81bfa
Show file tree
Hide file tree
Showing 11 changed files with 795 additions and 75 deletions.
2 changes: 0 additions & 2 deletions src/DuctAPE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ using ForwardDiff # used for jacobian for newton solver
using FLOWMath # used for various items, mostly interpolation
using Printf # used when verbose option is selected

using Primes # used in Romberg integration settings

#---------------------------------#
# EXPORTS #
#---------------------------------#
Expand Down
18 changes: 9 additions & 9 deletions src/preprocess/preprocess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1580,15 +1580,15 @@ function precompute_parameters!(
operating_point,
reference_parameters,
problem_dimensions=nothing;
grid_solver_options=options.wake_solver_options,
integration_options=options.integration_options,
autoshiftduct=options.autoshiftduct,
itcpshift=options.itcpshift,
axistol=options.axistol,
tegaptol=options.tegaptol,
finterp=options.finterp,
silence_warnings=options.silence_warnings,
verbose=options.verbose,
grid_solver_options=GridSolverOptions(),
integration_options=IntegrationOptions(),
autoshiftduct=true,
itcpshift=0.05,
axistol=1e-15,
tegaptol=1e1 * eps(),
finterp=fm.akima,
silence_warnings=true,
verbose=false,
)

# - Reset Caches - #
Expand Down
6 changes: 3 additions & 3 deletions src/preprocess/velocities/body_aic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ function vortex_aic_boundary_on_boundary!(
if isnothing(integration_caches)
# integration_cache = zeros(eltype(controlpoint), 20)
nominal_integration_cache = allocate_integration_containers(
integration_options.nominal, eltype(VEL)
integration_options.nominal, eltype(AICn)
)
singular_integration_cache = allocate_integration_containers(
integration_options.singular, eltype(VEL)
integration_options.singular, eltype(AICn)
)
else
nominal_integration_cache = integration_caches.nominal
Expand Down Expand Up @@ -164,7 +164,7 @@ function vortex_aic_boundary_on_field(
nodemap,
influence_length,
integration_options;
integration_caches=integration_cache,
integration_caches=integration_caches,
)

return AICn
Expand Down
5 changes: 5 additions & 0 deletions src/preprocess/velocities/gausslegendre_integrals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ function nominal_vortex_panel_integration!(
containers;
debug=false,
)
reset_containers!(containers)

# - Sample Function - #
for (s, t) in zip(eachrow(containers.samples), integration_options.sample_points)
# Define function to integrate
Expand Down Expand Up @@ -48,6 +50,7 @@ function self_vortex_panel_integration!(
containers;
debug=false,
)
reset_containers!(containers)

# - Sample Function - #
for (s, t) in zip(eachrow(containers.samples), integration_options.sample_points)
Expand Down Expand Up @@ -93,6 +96,7 @@ function nominal_source_panel_integration!(
containers;
debug=false,
)
reset_containers!(containers)

# - Sample Function - #
for (s, t) in zip(eachrow(containers.samples), integration_options.sample_points)
Expand Down Expand Up @@ -127,6 +131,7 @@ function self_source_panel_integration!(
containers;
debug=false,
)
reset_containers!(containers)

# - Sample Function - #
for (s, t) in zip(eachrow(containers.samples), integration_options.sample_points)
Expand Down
4 changes: 2 additions & 2 deletions src/preprocess/velocities/induced_velocity_matrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function induced_velocities_from_vortex_panels_on_points(
influence_lengths,
strengths,
integration_options;
cache_vec=cache_vec,
integration_caches=integration_caches,
)

return VEL
Expand Down Expand Up @@ -170,7 +170,7 @@ function induced_velocities_from_source_panels_on_points(
controlpoints,
nodes,
nodemap,
influence_lengthss,
influence_lengths,
strengths,
integration_options;
integration_caches=integration_caches,
Expand Down
29 changes: 15 additions & 14 deletions src/preprocess/velocities/romberg_integrals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ function extrapolate!(V, err, fh; power=2, atol=1e-6)
for i in (numeval - 1):-1:1
f_i, h_i = fh[i + (firstindex(fh) - 1)]
c = (h_i[] / h_prime[])^power
println((f_ip1 - f_i))
@. f_ip1 += (f_ip1 - f_i) / (c - 1)
fh[i + (firstindex(fh) - 1)] = (f_ip1, h_i)
err_prime = norm.(f_ip1 - f_i)
minerr_prime = min.(minerr_prime, err_prime)
if err_prime < err
V, err = f_ip1, err_prime
V[:], err = f_ip1, err_prime
end
end

# - converged - #
all(err .<= atol) && break
# all(err .<= atol) && break
end

return V, err
Expand All @@ -67,6 +66,7 @@ function nominal_vortex_panel_integration!(
containers;
debug=false,
)
reset_containers!(containers)

# - Loop through number of subdivisions (start with 2) - #
for ii in 1:(integration_options.max_subdivisions)
Expand All @@ -82,7 +82,7 @@ function nominal_vortex_panel_integration!(
t = (i - 0.5) / nint

# get sample velocity
dt.nominal_vortex_induced_velocity_sample!(
nominal_vortex_induced_velocity_sample!(
@view(containers.samples[ii])[1][1],
t,
node1,
Expand All @@ -98,7 +98,7 @@ function nominal_vortex_panel_integration!(

if ii > 1
# extrapolate once you can
dt.extrapolate!(
extrapolate!(
V,
@view(containers.sample_cache[1:4]),
@view(containers.samples[1:ii]);
Expand All @@ -123,10 +123,10 @@ function self_vortex_panel_integration!(
node2,
influence_length,
controlpoint,
containers,
containers;
debug=false,
)

reset_containers!(containers)
# - Loop through number of subdivisions (start with 2) - #
for ii in 1:(integration_options.max_subdivisions)
nint = 2^ii
Expand All @@ -141,7 +141,7 @@ function self_vortex_panel_integration!(
t = (i - 0.5) / nint

# get sample velocity
dt.self_vortex_induced_velocity_sample!(
self_vortex_induced_velocity_sample!(
@view(containers.samples[ii])[1][1],
t,
node1,
Expand All @@ -165,7 +165,7 @@ function self_vortex_panel_integration!(

if ii > 1
# extrapolate once you can
dt.extrapolate!(
extrapolate!(
V,
@view(containers.sample_cache[1:4]),
@view(containers.samples[1:ii]);
Expand Down Expand Up @@ -198,6 +198,7 @@ function nominal_source_panel_integration!(
containers;
debug=false,
)
reset_containers!(containers)

# - Loop through number of subdivisions (start with 2) - #
for ii in 1:(integration_options.max_subdivisions)
Expand All @@ -213,7 +214,7 @@ function nominal_source_panel_integration!(
t = (i - 0.5) / nint

# get sample velocity
dt.nominal_source_induced_velocity_sample!(
nominal_source_induced_velocity_sample!(
@view(containers.samples[ii])[1][1],
t,
node1,
Expand All @@ -229,7 +230,7 @@ function nominal_source_panel_integration!(

if ii > 1
# extrapolate once you can
dt.extrapolate!(
extrapolate!(
V,
@view(containers.sample_cache[1:4]),
@view(containers.samples[1:ii]);
Expand Down Expand Up @@ -257,7 +258,7 @@ function self_source_panel_integration!(
containers;
debug=false,
)

reset_containers!(containers)
# - Loop through number of subdivisions (start with 2) - #
for ii in 1:(integration_options.max_subdivisions)
nint = 2^ii
Expand All @@ -272,7 +273,7 @@ function self_source_panel_integration!(
t = (i - 0.5) / nint

# get sample velocity
dt.self_source_induced_velocity_sample!(
self_source_induced_velocity_sample!(
@view(containers.samples[ii])[1][1],
t,
node1,
Expand All @@ -296,7 +297,7 @@ function self_source_panel_integration!(

if ii > 1
# extrapolate once you can
dt.extrapolate!(
extrapolate!(
V,
@view(containers.sample_cache[1:4]),
@view(containers.samples[1:ii]);
Expand Down
12 changes: 4 additions & 8 deletions src/utilities/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,15 @@ end
# QUADRATURE TYPES #
#---------------------------------#

@kwdef struct Romberg{TI,TF,TP,TV} <: IntegrationMethod
@kwdef struct Romberg{TI,TF} <: IntegrationMethod
max_subdivisions::TI = 10
atol::TF = 1e-6
end

function set_romberg_options(; max_subdivisions=10, atol=1e-6)
return Romberg(; max_subdivisions, atol)
end

@kwdef struct GaussKronrod{TI,TF} <: IntegrationMethod
order::TI = 5
maxevals::TI = 1000
atol::TF = 1e-12
order::TI = 7
maxevals::TI = 10^7
atol::TF = 0
end

struct GaussLegendre{TN,TW} <: IntegrationMethod
Expand Down
12 changes: 10 additions & 2 deletions src/utilities/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,16 @@ function reset_containers!(c)
for p in propertynames(c)
cp = getfield(c, p)
if typeof(cp) <: AbstractArray
#do nothing if it's a string
(eltype(cp) == String) || (cp .= 0)
if eltype(cp) <: Tuple
for i in 1:length(cp[1])
for j in 1:length(cp)
cp[j][i] .= 0.0
end
end
else
#do nothing if it's a string
(eltype(cp) == String) || (cp .= 0)
end
else
reset_containers!(cp)
end
Expand Down
Loading

0 comments on commit 9a81bfa

Please sign in to comment.