Skip to content

Commit 0f97baf

Browse files
committed
add more docstrings
1 parent 8e1c962 commit 0f97baf

File tree

11 files changed

+158
-38
lines changed

11 files changed

+158
-38
lines changed

Diff for: docs/src/DuctAPE/private_api.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ DuctAPE.get_problem_dimensions
2424
```
2525

2626
## Caching
27-
TODO: go through through the rest of the caching directory and add the remaining files' functions
27+
TODO: finish up the caching docstrings in the integration-caches.jl file
2828

2929
### Allocation
3030

3131
The following are various helper functions used in preallocating the various caches.
3232

3333
```@docs
34+
DuctAPE.initialize_all_caches
3435
DuctAPE.allocate_wake_panel_container!
3536
DuctAPE.allocate_panel_containers!
3637
DuctAPE.allocate_panel_container!
3738
DuctAPE.allocate_body_panel_container!
3839
DuctAPE.allocate_rotor_panel_container!
3940
DuctAPE.allocate_solve_parameter_extras!
41+
DuctAPE.allocate_grid_parameter_cache
4042
```
4143

4244
### Reshaping
@@ -47,6 +49,7 @@ The following are used internally to reshape the cache vectors into more usable
4749
DuctAPE.withdraw_prepost_container_cache
4850
DuctAPE.withdraw_solve_parameter_cache
4951
DuctAPE.withdraw_solve_container_cache
52+
DuctAPE.withdraw_grid_parameter_cache
5053
```
5154

5255
## Preprocess
@@ -255,4 +258,5 @@ DuctAPE.linear_transform
255258
DuctAPE.extract_primals!
256259
DuctAPE.lfs
257260
DuctAPE.reset_containers!
261+
DuctAPE.cache_dims!
258262
```

Diff for: src/analysis/analyses.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ function analyze(
166166
A_bb_LU,
167167
airfoils,
168168
idmaps,
169-
problem_dimensions;
169+
problem_dimensions,
170+
options.multipoint_index;
170171
write_outputs=options.write_outputs[options.multipoint_index[]],
171172
outfile=options.outfile[options.multipoint_index[]],
172173
checkoutfileexists=options.checkoutfileexists,

Diff for: src/postprocess/postprocess.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function post_process(
1212
A_bb_LU,
1313
airfoils,
1414
idmaps,
15-
problem_dimensions;
15+
problem_dimensions,
16+
multipoint_index;
1617
write_outputs=options.write_outputs,
1718
outfile=options.outfile,
1819
checkoutfileexists=options.checkoutfileexists,
@@ -120,6 +121,7 @@ function post_process(
120121
blade_elements,
121122
wakeK,
122123
idmaps,
124+
multipoint_index
123125
)
124126

125127
(;
@@ -526,6 +528,7 @@ function run_residual!(
526528
blade_elements,
527529
wakeK,
528530
idmaps,
531+
multipoint_index
529532
) where {TS<:ExternalSolverOptions}
530533

531534
#=
@@ -581,6 +584,7 @@ function run_residual!(
581584
blade_elements,
582585
wakeK,
583586
idmaps,
587+
multipoint_index
584588
)
585589

586590
#=
@@ -614,7 +618,8 @@ function run_residual!(
614618
linsys,
615619
blade_elements,
616620
wakeK,
617-
idmaps;
621+
idmaps,
622+
multipoint_index;
618623
verbose=false,
619624
)
620625

Diff for: src/preprocess/initialize_states.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ function initialize_strengths!(
635635

636636
reset_containers!(solve_containers)
637637

638-
vz_rotor=0.0
638+
vz_rotor=-Vinf[] + 1.0
639639

640640
# loop through rotors
641641
for irotor in 1:nrotor

Diff for: src/preprocess/preprocess.jl

+6-4
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ function reinterpolate_geometry(
7070
rp_duct_coordinates = zeros(TF, 2, ndn)
7171
rp_centerbody_coordinates = zeros(TF, 2, ncbn)
7272
rotor_indices_in_wake = ones(Int, nrotor)
73+
blade_element_cache = (;Rtip=zeros(TF,nrotor), Rhub=zeros(TF,nrotor))
7374

7475
reinterpolate_geometry!(
75-
@view(wake_grid[:, :, :]),
76-
@view(rp_duct_coordinates[:, :]),
77-
@view(rp_centerbody_coordinates[:, :]),
78-
@view(rotor_indices_in_wake[:]),
76+
wake_grid,
77+
rp_duct_coordinates,
78+
rp_centerbody_coordinates,
79+
rotor_indices_in_wake,
7980
duct_coordinates,
8081
centerbody_coordinates,
8182
rotorstator_parameters,
83+
blade_element_cache,
8284
paneling_constants;
8385
autoshiftduct=autoshiftduct,
8486
grid_solver_options=grid_solver_options,

Diff for: src/process/residuals/CSORresidual.jl

+17-8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function CSOR_residual!(resid, state_variables, sensitivity_parameters, constant
2525
solve_parameter_cache_dims, # dimensions for shaping the view of the parameter cache
2626
solve_container_cache, # cache for solve_containers used in solve
2727
solve_container_cache_dims, # dimensions for shaping the view of the solve cache
28+
multipoint_index,
2829
) = constants
2930

3031
# - Separate out the state variables - #
@@ -72,7 +73,8 @@ function CSOR_residual!(resid, state_variables, sensitivity_parameters, constant
7273
(; linsys..., A_bb_LU),
7374
(; blade_elements..., airfoils...),
7475
wakeK,
75-
idmaps;
76+
idmaps,
77+
multipoint_index;
7678
verbose=solver_options.verbose,
7779
)
7880

@@ -130,7 +132,8 @@ function compute_CSOR_residual!(
130132
linsys,
131133
blade_elements,
132134
wakeK,
133-
idmaps;
135+
idmaps,
136+
multipoint_index;
134137
verbose=false,
135138
)
136139

@@ -343,7 +346,7 @@ function compute_CSOR_residual!(
343346
maxBGamr,
344347
maxdeltaBGamr,
345348
maxdeltagamw,
346-
solver_options.Vconv,
349+
solver_options.Vconv[multipoint_index[]],
347350
)
348351

349352
return nothing
@@ -398,6 +401,8 @@ function relax_Gamr!(
398401
bladeomega = nrf .* ones(TF, size(Gamr, 2))
399402
omega = nrf .* ones(TF, size(Gamr, 1))
400403
deltahat = zeros(TF, size(Gamr, 1))
404+
minBGamr = zeros(TF, size(Gamr,2))
405+
401406

402407
for (i, (BG, b, delta_prev, delta)) in
403408
enumerate(zip(eachcol(Gamr), B, eachcol(delta_prev_mat), eachcol(delta_mat)))
@@ -410,21 +415,24 @@ function relax_Gamr!(
410415
# - Set the normalization value based on the maximum magnitude value of B*Gamr
411416

412417
# find max magnitude
413-
maxBGamr[i], mi = findmax(abs.(BG))
418+
maxBGamr[i], maxi = findmax(BG)
419+
minBGamr[i], mini = findmin(BG)
414420

415-
# maintain sign of original value
416-
maxBGamr[i] *= sign(BG[mi])
421+
# # maintain sign of original value
422+
# maxBGamr[i] *= sign(BG[maxi])
417423

418424
# make sure we don't have any weird jumps
419425
meang = sum(BG) / length(BG)
426+
420427
if meang > 0.0 # if mean is positive, make sure maxBGamr[i] is at least 0.1
421428
maxBGamr[i] = max(maxBGamr[i], 0.1)
422429
elseif meang < 0.0 # if mean is negative, make sure maxBGamr[i] is at most -0.1
423-
maxBGamr[i] = min(maxBGamr[i], -0.1)
430+
maxBGamr[i] = min(minBGamr[i], -0.1)
424431
else # if the average is zero, then set maxBGamr[i] to zero
425432
maxBGamr[i] = 0.0
426433
end
427434

435+
428436
# note: delta = Gamr_new .- Gamr
429437
# note: deltahat here is actually 1/deltahat which is the version needed later
430438
for (j, d) in enumerate(eachrow(deltahat))
@@ -607,11 +615,12 @@ Update CSOR residual values in place.
607615
- `maxBGamr::Float` : Maximum value of B*Gamr among all blade elements
608616
- `maxdeltaBGamr::Float` : Maximum change in B*Gamr between iterations among all blade elements
609617
- `maxdeltagamw::Vector{Float}` : Maximum change in gamw among all wake nodes (one element)
610-
- `Vconv::Vector{Float}` : Reference velocity upon which the relative convergence criteria is based (one element)
618+
- `Vconv::Float` : Reference velocity upon which the relative convergence criteria is based (one element)
611619
"""
612620
function update_CSOR_residual_values!(
613621
convergence_type::Relative, resid, maxBGamr, maxdeltaBGamr, maxdeltagamw, Vconv
614622
)
623+
615624
resid[1] = maximum(abs, maxdeltaBGamr ./ maxBGamr)
616625
resid[2] = abs.(maxdeltagamw[] / Vconv[])
617626

Diff for: src/process/solve.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function solve(
109109
# update iteration number
110110
iter[] += 1
111111
if verbose
112-
println("Iteration $(iter):")
112+
println("Iteration $(iter[]):")
113113
end
114114

115115
# Call residual
@@ -127,6 +127,7 @@ function solve(
127127
solve_parameter_cache_dims, # dimensions for shaping the view of the parameter cache
128128
solve_container_cache, # cache for solve_containers used in solve
129129
solve_container_cache_dims, # dimensions for shaping the view of the solve cache
130+
multipoint_index,
130131
),
131132
)
132133

Diff for: src/utilities/caching/caches.jl

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
"""
2+
initialize_all_caches(solver_options, paneling_constants)
3+
4+
Convenience function to initialize all caches before calling analysis.
5+
6+
# Arguments
7+
- `solver_options::SolverOptionsType` : solver options used for cache allocation dispatch
8+
- `paneling_constants::PanelingConstants` : PanelingConstants object upon which all cache sizing depends
9+
10+
# Returns
11+
- `prepost_container_caching::NamedTuple` : A named tuple containing the PreallocationTools DiffCache and a named tuple with relevant dimensions for accessing the cache.
12+
- `solve_parameter_caching::NamedTuple` : A named tuple containing the PreallocationTools DiffCache and a named tuple with relevant dimensions for accessing the cache.
13+
- `solve_container_caching::NamedTuple` : A named tuple containing the PreallocationTools DiffCache and a named tuple with relevant dimensions for accessing the cache.
214
"""
315
function initialize_all_caches(solver_options, paneling_constants)
416

@@ -17,11 +29,3 @@ function initialize_all_caches(solver_options, paneling_constants)
1729

1830
return prepost_container_caching, solve_parameter_caching, solve_container_caching
1931
end
20-
21-
"""
22-
"""
23-
function cache_dims!(total_length, l, s)
24-
dims = (; index=(total_length[] + 1):(total_length[] + l), shape=s)
25-
total_length[] += l
26-
return dims
27-
end

Diff for: src/utilities/caching/elliptic_grid_parameter_packaging.jl

+27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
"""
2+
allocate_grid_parameter_cache(pg, x, n)
3+
4+
Allocate a cache used inside the elliptic grid solve.
5+
6+
# Arguments
7+
- `pg::AbstractArray{Float,3}` : the proposed grid array
8+
- `x::AbstractVector{Float}` : the array of ξ values used in the solve
9+
- `n::AbstractVector{Float}` : the array of η values used in the solve
10+
11+
# Returns
12+
- `grid_parameter_cache::NamedTuple` : A named tuple containing the PreallocationTools DiffCache and dimensions for accessing it.
13+
"""
114
function allocate_grid_parameter_cache(pg, x, n)
215
total_length = [0]
316

@@ -19,6 +32,20 @@ function allocate_grid_parameter_cache(pg, x, n)
1932
)
2033
end
2134

35+
"""
36+
withdraw_grid_parameter_cache(vec, dims)
37+
38+
Reshape the cache used inside the elliptic grid solve.
39+
40+
# Arguments
41+
- `vec::Vector{Float}` : the cache vector
42+
- `dims::NamedTuple` : the named tuple of dimensions used to reshape the cache vector
43+
44+
# Returns
45+
- `proposed_grid::AbstractArray{Float,3}` : the proposed grid array
46+
- `xi::AbstractVector{Float}` : the array of ξ values used in the solve
47+
- `eta::AbstractVector{Float}` : the array of η values used in the solve
48+
"""
2249
function withdraw_grid_parameter_cache(vec, dims)
2350
proposed_grid = reshape(@view(vec[dims.proposed_grid.index]), dims.proposed_grid.shape)
2451

Diff for: src/utilities/misc.jl

+21
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,24 @@ function promote_propulosor_type(p)
168168
eltype(p.rotorstator_parameters.twists),
169169
)
170170
end
171+
172+
"""
173+
cache_dims!(total_length, l, s)
174+
175+
A function that returns a named tuple containing an index range and shape and increases `total_length` by `l`.
176+
177+
This function is used heavily in the cache allocation functions for setting up the dimension maps used to access the vectorized caches.
178+
179+
# Arguments
180+
- `total_length::Vector{Int}` : single element vector containing the current total length of the eventual cache vector. Modified in place.
181+
- `l::Int` : total length of the object in question
182+
- `s::Int` : size of the object in question
183+
184+
# Returns
185+
- `dims::NamedTuple` : A named tuple containing `index` and `shape` fields
186+
"""
187+
function cache_dims!(total_length, l, s)
188+
dims = (; index=(total_length[] + 1):(total_length[] + l), shape=s)
189+
total_length[] += l
190+
return dims
191+
end

0 commit comments

Comments
 (0)