Skip to content

Commit 273f690

Browse files
committed
fix syntax and clean up
1 parent bd7d9c8 commit 273f690

19 files changed

+1549
-4629
lines changed

examples/duct.jl

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,23 @@ points = hcat(xs, ys)
104104
# Generate body of revolution
105105
body = pnl.generate_revolution_liftbody(bodytype, points, NDIVS_theta;
106106
bodyoptargs = (
107-
CPoffset=1e-14,
107+
CPoffset=1e-10,
108108
kerneloffset=1e-8,
109109
kernelcutoff=1e-14,
110110
characteristiclength=(args...)->d*aspectratio,
111-
semiinfinite_wake=true
111+
semiinfinite_wake=false
112112
)
113113
)
114114

115-
# body.shedding = body.shedding[:,1:1]
115+
# body.shedding[1] = body.shedding[1][:,1:1]
116116
# body.nsheddings = 1
117117
# body.shedding_full .= -1
118118
# idx_shed = body.shedding[1, 1]
119-
# body.shedding_full[:, idx_shed] .= view(body.shedding, 2:3, 1)
120-
# idx_shed = body.shedding[4, 1]
121-
# body.shedding_full[:, idx_shed] .= view(body.shedding, 5:6, 1)
119+
# body.shedding_full[1:2, idx_shed] .= view(body.shedding[1], 2:3, 1)
120+
# body.shedding_full[3:4, idx_shed] .= 1
121+
# idx_shed = body.shedding[1][4, 1]
122+
# body.shedding_full[1:2, idx_shed] .= view(body.shedding[1], 5:6, 1)
123+
# body.shedding_full[3:4, idx_shed] .= 1
122124

123125
println("Number of panels:\t$(body.ncells)")
124126

@@ -141,19 +143,19 @@ AOA = AOAs[i]
141143

142144
# Unitary direction of semi-infinite vortex at points `a` and `b` of each
143145
# trailing edge panel
144-
body.Das[1] .= repeat(Vinf/magVinf, 1, body.nsheddings)
145-
body.Dbs[1] .= repeat(Vinf/magVinf, 1, body.nsheddings)
146+
body.Das[1] .= repeat(Vinf/magVinf, 1, size(body.Das[1], 2))
147+
body.Dbs[1] .= repeat(Vinf/magVinf, 1, size(body.Dbs[1], 2))
146148

147149
# Solve body (panel strengths) giving `Uinfs` as boundary conditions and
148150
# `Das` and `Dbs` as trailing edge rigid wake direction
149151
# @time pnl.solve(body, Uinfs, Das, Dbs)
150-
leaf_size = 50
152+
leaf_size = 100
151153
expansion_order = 10
152154
multipole_acceptance = 0.4
153155
backend = pnl.FastMultipoleBackend(;
154156
expansion_order,
155157
multipole_acceptance,
156-
leaf_size
158+
leaf_size=20
157159
)
158160
# backend = pnl.DirectBackend()
159161
# global solver = pnl.Backslash(body; least_squares=true)
@@ -169,65 +171,62 @@ AOA = AOAs[i]
169171
# leaf_size=10
170172
# )
171173
# )
172-
println("Initializaing solver...")
173-
@time solver = pnl.FGSSolver(body;
174-
max_iterations=500, # Maximum number of iterations
175-
tolerance=1.0e-6, # Convergence tolerance
176-
rlx=1.0, # Relaxation factor
177-
expansion_order,
178-
multipole_acceptance,
179-
leaf_size,
180-
shrink=true,
181-
recenter=false,
182-
)
183-
# solver = pnl.BackslashDirichlet(body)
184-
185-
println("\nSolving...")
186-
187-
# profile
188-
# using Profile, PProf
189-
190-
pnl.solve2!(body, Uinfs, solver; backend)
191-
# @profile pnl.solve2!(body, Uinfs, solver; backend)
192-
# Profile.clear()
193-
# @profile pnl.solve2!(body, Uinfs, solver; backend)
194-
# pprof()
174+
# function test_solver(inner_iterations, reverse_pass)
175+
# println("Initializing solver with inner_iterations=$inner_iterations, reverse_pass=$reverse_pass...")
176+
println("Initializaing solver...")
177+
@time solver = pnl.FGSSolver(body;
178+
max_iterations=500, # Maximum number of iterations
179+
tolerance=1.0e-6, # Convergence tolerance
180+
rlx=1.0, # Relaxation factor
181+
expansion_order,
182+
multipole_acceptance,
183+
leaf_size,
184+
shrink=true,
185+
recenter=false,
186+
inner_iterations=20,
187+
reverse_pass=false,
188+
verbose=false
189+
)
190+
# solver = pnl.BackslashDirichlet(body)
191+
192+
println("\nSolving...")
193+
194+
# profile
195+
# using Profile, PProf
196+
197+
@time pnl.solve2!(body, Uinfs, solver; backend)
198+
# @profile pnl.solve2!(body, Uinfs, solver; backend)
199+
# Profile.clear()
200+
# @profile pnl.solve2!(body, Uinfs, solver; backend)
201+
# pprof()
202+
203+
# end
204+
205+
# for reverse_pass in [true, false]
206+
# for inner_iterations in [1, 2, 4, 8, 16, 32]
207+
# test_solver(inner_iterations, reverse_pass)
208+
# end
209+
# end
195210

196211
# ----------------- POST PROCESSING ----------------------------------------
197212
println("\nPost processing...")
198213

199214
# Calculate surface velocity U on the body
200-
@time Us = pnl.calcfield_U(body, body; backend)
215+
@time Us = pnl.calcfield_U!(body, body; backend)
216+
pnl.apply_freestream!(body, Uinfs[:,1])
201217

202-
# NOTE: Since the boundary integral equation of the potential flow has a
203-
# discontinuity at the boundary, we need to add the gradient of the
204-
# doublet strength to get an accurate surface velocity
205-
206-
# Calculate surface velocity U_∇μ due to the gradient of the doublet strength
207-
Gammai = kernel == pnl.VortexRing ? 1 : kernel == Union{pnl.ConstantSource, pnl.ConstantDoublet} ? 2 : 0
208-
UDeltaGamma = pnl.calcfield_Ugradmu(body; Gammai)
209-
# UDeltaGamma = pnl.calcfield_Ugradmu(body; sharpTE=true, force_cellTE=false)
210-
211-
# Add both velocities together
212-
pnl.addfields(body, "Ugradmu", "U")
213-
214-
# Calculate pressure coefficient (based on U + U_∇μ)
215-
@time Cps = pnl.calcfield_Cp(body, magVinf)
218+
# Calculate pressure coefficient (based on body.velocity)
219+
@time Cps = pnl.calcfield_Cp!(body.Cp, body, magVinf; correct_kuttacondition=true)
216220

217221
# Calculate the force of each panel (based on Cp)
218-
@time Fs = pnl.calcfield_F(body, magVinf, rho)
222+
@time Fs = pnl.calcfield_F!(body, magVinf, rho)
219223

220224
# check normal flow condition
221-
Us_tot = pnl.get_field(body, "U")["field_data"] # total velocity
222-
Us_tot = [Us_tot[j][i] for i=1:3, j=1:size(Us_tot,1)]
223-
normals = pnl._calc_normals(body)
225+
Us_tot = body.velocity
224226
Udotn = sum(Us_tot .* normals, dims=1)
225227
resid = maximum(abs.(Udotn))
226228
println("Max flow tangency residual: $resid")
227229

228-
normals = pnl.calc_normals(body)
229-
CPs_inside = pnl._calc_controlpoints(body, normals; off=-1e-10)
230-
231230
# ----------------- COMPARISON TO EXPERIMENTAL DATA ------------------------
232231
# Plot surface pressure along slices of the duct
233232
fig, axs = plot_Cp(body, AOA)
@@ -250,8 +249,7 @@ AOA = AOAs[i]
250249
name *= kernel == pnl.VortexRing ? "_vortexring" :
251250
kernel == Union{pnl.ConstantSource, pnl.ConstantDoublet} ? "_source_doublet" :
252251
""
253-
global vtks *= pnl.save(body, name; path=save_path, num=i,
254-
wake_panel=false, debug=false, out_wake=false)
252+
global vtks *= pnl.write_vtk(name, body, i, 0.0; overwrite=true)
255253
end
256254

257255
# end

examples/duct_postprocessing.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ function plot_Cp(body, AOA; plot_experimental=true)
2626

2727
# Data filter to get only +z or only -z data points
2828
slicefilter(x, i) = (x[3] >= 0) == upperside
29-
30-
slicepoints, sliceCps = pnl.slicefield(body, "Cp",
31-
position, direction, row;
32-
filter=slicefilter)
29+
slicepoints, sliceCps = pnl.slice_scalarfield(body, :Cp, 2, 0.0, 0.1; filter=slicefilter)
3330

3431
side = upperside ? "upper" : "lower"
3532

examples/duct_unsteady.jl

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ body = pnl.generate_revolution_liftbody(bodytype, points, NDIVS_theta;
112112
)
113113
)
114114

115-
# body.shedding = body.shedding[:,1:1]
116-
# body.nsheddings = 1
117-
# body.shedding_full .= -1
118-
# idx_shed = body.shedding[1, 1]
119-
# body.shedding_full[:, idx_shed] .= view(body.shedding, 2:3, 1)
120-
# idx_shed = body.shedding[4, 1]
121-
# body.shedding_full[:, idx_shed] .= view(body.shedding, 5:6, 1)
122-
123115
println("Number of panels:\t$(body.ncells)")
124116

125117
vtks = save_path*"/" # String with VTK output files
@@ -137,8 +129,20 @@ AOA = AOAs[i]
137129
# Freestream at every control point
138130
Uinf(t) = Vinf
139131

132+
# prepare other inputs
133+
eta = 0.3
134+
frames = nothing
135+
maneuver = (args...; optargs...) -> nothing
136+
l = d * aspectratio
137+
dt = magVinf / l / (n_rfl * 500)
138+
t_range = range(0.0, step=dt, length=201)
139+
140+
# update wake directions
141+
body.Das[1] .= repeat(Vinf*dt*eta, 1, size(body.Das, 2))
142+
body.Dbs[1] .= repeat(Vinf*dt*eta, 1, size(body.Dbs, 2))
143+
140144
# select backend for N-body interactions
141-
leaf_size = 150
145+
leaf_size = 20
142146
expansion_order = 10
143147
multipole_acceptance = 0.4
144148
backend = pnl.FastMultipoleBackend(;
@@ -163,27 +167,21 @@ AOA = AOAs[i]
163167
# )
164168
println("Initializaing solver...")
165169
@time body_solver = pnl.FGSSolver(body;
166-
max_iterations=100, # Maximum number of iterations
167-
tolerance=1.0e-7, # Convergence tolerance
168-
rlx=0.1, # Relaxation factor
170+
max_iterations=50, # Maximum number of iterations
171+
inner_iterations=10, # Maximum number of inner iterations
172+
reverse_pass=true, # Whether to do reverse sweeps or not
173+
tolerance=1.0e-6, # Convergence tolerance
174+
rlx=1.0, # Relaxation factor
169175
expansion_order,
170176
multipole_acceptance,
171-
leaf_size,
177+
leaf_size=150,
172178
shrink=true,
173179
recenter=false,
174180
)
175181
# solver = pnl.BackslashDirichlet(body)
176182

177183
# initialize wake
178-
wake = pnl.PanelWake(body; nwakerows=10)
179-
180-
# prepare other inputs
181-
eta = 0.3
182-
frames = nothing
183-
maneuver = (args...; optargs...) -> nothing
184-
l = d * aspectratio
185-
dt = magVinf / l / (n_rfl * 5)
186-
t_range = range(0.0, step=dt, length=15)
184+
wake = pnl.PanelWake(body; nwakerows=201)
187185

188186
println("\nBegin simulation...")
189187
@time begin

examples/single_triangle_body.jl

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ using FLOWPanel
55
const pnl = FLOWPanel
66
using FLOWPanel.gt.Meshes
77
import FLOWPanel.PyPlot as plt
8+
colormap = plt.get_cmap("RdBu",15)
9+
810

911
function make_single_triangle_body(; semiinfinite_wake=false)
1012
pnl = FLOWPanel
@@ -31,15 +33,15 @@ function make_single_triangle_body(; semiinfinite_wake=false)
3133
# body = pnl.NonLiftingBody{pnl.ConstantDoublet}(grid)
3234
# body = pnl.NonLiftingBody{Union{pnl.ConstantSource, pnl.ConstantDoublet}}(grid)
3335

34-
shedding = zeros(Int, 6, 1)
35-
shedding[1,1] = 1
36-
shedding[2,1] = 2
37-
shedding[3,1] = 3
38-
shedding[4,1] = -1
36+
shedding = zeros(Int, 6, 0)
37+
# shedding[1,1] = 1
38+
# shedding[2,1] = 2
39+
# shedding[3,1] = 3
40+
# shedding[4,1] = -1
3941
body = pnl.RigidWakeBody{Union{pnl.ConstantSource, pnl.ConstantDoublet}}(grid, [shedding];
4042
semiinfinite_wake)
41-
body.Das[1][2,:] .= -1
42-
body.Dbs[1][2,:] .= -1
43+
# body.Das[1][2,:] .= -1
44+
# body.Dbs[1][2,:] .= -1
4345

4446
return body
4547
end
@@ -52,13 +54,13 @@ str = 1.0
5254
# body.strength[1,1] = str
5355
body.strength[1,2] = str
5456

55-
normals = pnl._calc_normals(body)
57+
normals = pnl.calc_normals!(body)
5658
@show normals # outward facing
57-
cps = pnl._calc_controlpoints(body, normals; off=1e-14)
59+
cps = pnl.calc_controlpoints!(body, normals; off=1e-14)
5860

5961
# compute velocity at a line of points above the triangle
6062
npoints = 1000
61-
dz = range(-1.0, stop=1.0, length=npoints) .* 5.0
63+
dz = range(-1.0, stop=1.0, length=npoints) .* 1.0
6264
points = hcat([ cps[:,1] .+ [0.0,0.0,z] for z in dz ]...) # points above centroid of triangle
6365
# points = hcat([ cps[:,1] .+ z .* normals[:,1] for z in dz ]...) # points above centroid of triangle
6466
# points = hcat([[0.33; 0.33; 0.0] .+ [z; z; z] for z in dz ]...) # points in y from the centroid
@@ -127,6 +129,21 @@ axs[1].plot(dz, phi_semiinfinite2, ":", label="semi-infinite panel2")
127129
axs[1].legend()
128130
plt.tight_layout()
129131

132+
# plot results with flipped axes
133+
fig3 = plt.figure("verify panel flipped")
134+
fig3.clf()
135+
fig3.add_subplot(121, xlabel=L"\phi", ylabel="z")
136+
fig3.add_subplot(122, xlabel=L"\vec{u} \cdot \hat{n}", ylabel="z")
137+
axs3 = fig3.get_axes()
138+
axs3[1].plot(phi_direct, dz, label="direct", color=colormap(14))
139+
axs3[2].plot(out_direct_z, dz, label="direct", color=colormap(14))
140+
for ax in axs3
141+
ax.spines["top"].set_visible(false)
142+
ax.spines["right"].set_visible(false)
143+
end
144+
145+
plt.tight_layout()
146+
130147
fig2 = plt.figure("error")
131148
fig2.clf()
132149
axs2 = fig2.add_subplot(111, xlabel="z", ylabel="error")

src/FLOWPanel.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export solve, save, Uind!, phi!,
2222
# ------------ GENERIC MODULES -------------------------------------------------
2323
import Dierckx
2424
import LinearAlgebra as LA
25-
import LinearAlgebra: I
25+
import LinearAlgebra: I, lu!, ldiv!
2626
import Krylov
2727
import LinearOperators
2828
import SimpleNonlinearSolve
@@ -67,12 +67,15 @@ const Im = Array(1.0I, 3, 3)
6767
# Shedding matrix for a RigidWakeBody without shedding
6868
const noshedding = zeros(Int, 6, 0)
6969

70+
const SEMIINFINITE_LENGTH = Array{Float64,0}(undef)
71+
SEMIINFINITE_LENGTH[] = 10.0
72+
7073
# ------------ HEADERS ---------------------------------------------------------
7174
for header_name in ["elements", "linearsolver", "fmm",
7275
"abstractbody", "solver",
7376
"nonliftingbody",
7477
"abstractliftingbody", "liftingbody",
75-
"multibody", "elements_fmm",
78+
"multibody", "elements_fmm", "frames",
7679
"liftingline",
7780
"utils", "postprocess",
7881
"wake", "simulate",

0 commit comments

Comments
 (0)