Skip to content

Commit

Permalink
Generate fluid domain in Vahana 2 example
Browse files Browse the repository at this point in the history
  • Loading branch information
EdoAlvarezR committed Aug 3, 2022
1 parent 1560bf5 commit 7383411
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 12 deletions.
113 changes: 112 additions & 1 deletion examples/vahana2/run.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,114 @@
include("vahana2.jl")

run_simulation_vahana(; prompt=true)


############## Run simulation ##################################################
# run_simulation_vahana(; prompt=true)
################################################################################



this_folder_path = splitdir(splitdir(@__FILE__)[1])[1]
this_folder_name = splitdir(splitdir(@__FILE__)[1])[2]

this_file_path = splitdir(@__FILE__)[1]
this_file_name = splitext(splitdir(@__FILE__)[2])[1]

# Default path where to save data
extdrive_path = this_folder_path*"/"

println("Number of threads: $(Threads.nthreads())")

# ------------ INPUTS AND OUTPUTS ----------------------------------------------
sim_name = "vahana2-transition-101" # Name of simulation to process
# sim_name = "vahana2-transition-202"
# sim_name = "vahana2-transition-105-test"


sim_name = "run-"*sim_name
save_path = extdrive_path*sim_name*"-postprocess100"

# nums = 0:1600 # Time steps to proces
# nums = collect(0:30) .+ 830
# nums = 500:899
# nums = 275:780
# nums = 3:36
# nums = [1480, 1080, 700, 504]
# nums = [1, 400, 800, 1020]
# nums = [1, 400, 800, 1200, 1600, 2060]

nums = collect(1000:4:2060)

reverse!(nums)

Rref = 0.75 # (m) reference blade radius


# OUTPUT OPTIONS
prompt = true # Whether to promp the user
debug = true # Debug mode
verbose = true # Enable verbose
v_lvl = 0 # Verbose indentation level

# ------------ PROCESS SIMULATION ----------------------------------------------
read_path = joinpath(extdrive_path, sim_name)

# Calculate forces and moments
# postprocessing_forceandmoment(read_path, save_path*"-forcesandmoments00", nums;
# prompt=prompt, debug=debug,
# verbose=verbose, v_lvl=v_lvl)


# Calculate statistics of forces and moments
# postprocessing_statistics(read_path, save_path*"-statistics09", nums;
# prompt=prompt, debug=debug,
# verbose=verbose, v_lvl=v_lvl)





# Compute fluid domain
nthreads = 1
nthread = 1
dnum = floor(Int, length(nums)/nthreads)
threaded_nums = [view(nums, dnum*i+1:(i<nthreads-1 ? dnum*(i+1) : length(nums))) for i in 0:nthreads-1]

for these_nums in threaded_nums[nthread:nthread]

this_save_path = save_path*"-fdom01"*(nthreads!=1 ? "-$nthread" : "")

println("Starting postprocessing ($(this_save_path))...")

postprocessing_fluiddomain(read_path, this_save_path, these_nums;
# PROCESSING OPTIONS
# fdx=1/160, # Scaling of cell length
# maxparticles=Int(30e6),
fdx=1/140,
maxparticles=Int(24e6),
# fdx=1/120,
# maxparticles=Int(20e6),
# maxparticles=Int(24e6),
# fdx=1/80,
# maxparticles=Int(8e6),
# maxparticles=Int(12e6),
static_particles=true,
# fmm=vpm.FMM(; p=4, ncrit=50, theta=0.4, phi=0.5), # FMM parameters
fmm=vpm.FMM(; p=4, ncrit=50, theta=0.4, phi=0.3),
f_sigma=0.5, # Smoothing radii of node particles as sigma = f_sigma*meansigma
# f_sigma=1.0,
maxmagGamma=Inf, # Any vortex strengths larger than this get clipped to this value
# maxsigma=Inf, # Any particles larger than this get shrunk to this value
maxsigma=Rref/4,
# SIMULATION INFORMATION
ttot=30.0,
tstart=0.20*30.0, # Starting time of simulation
nsteps=2*4*5400,
start_kinmaneuver=false,
# Vref=30.0,
Vref=0.25 * 125*0.44704,
# OUTPUT OPTIONS
prompt=true)

println("Fluid domain saved under $(this_save_path)")
end
111 changes: 100 additions & 11 deletions examples/vahana2/vahana2_postprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ function postprocessing_fluiddomain(read_path, save_path, nums;
# PROCESSING OPTIONS
fdx=1/80, # Scaling of cell length
static_particles=false, # Add static particles
fsgm=1.0, # Scaling of smoothing radii
maxparticles=Int(2e6),
maxsigma=Inf, # Any particles larger than this get shrunk to this value
maxmagGamma=Inf, # Any vortex strengths larger than this get clipped to this value
# SIMULATION INFORMATION
ttot=30.0,
nsteps=4*5400,
Expand All @@ -40,9 +41,8 @@ function postprocessing_fluiddomain(read_path, save_path, nums;
# OUTPUT OPTIONS
run_name="vahana2",
prompt=true, paraview=false, debug=false,
verbose=true, v_lvl=0)

# fsgm = 0.35 # Scaling of smoothing radii
verbose=true, v_lvl=0,
optargs...)

# Maneuver parameters
# ttot = 30.0 # Total time to perform maneuver
Expand All @@ -65,36 +65,125 @@ function postprocessing_fluiddomain(read_path, save_path, nums;
L = 1.6*b # Length of fluid domain
dx = fdx*b # Cell length

Lx, Ly, Lz = 1.2*L, L, 0.6*L # Length in each direction
# Lx, Ly, Lz = 1.2*L, L, 0.6*L # Length in each direction
Lx, Ly, Lz = 1.08*L, L, 0.55*L
dx, dy, dz = dx, 1*dx, 0.5*dx # Cell length in each direction
nx, ny, nz = Lx/dx, Ly/dy, Lz/dz # Number of cells in each direction

X0 = [0.35*L, 0, 0.125*L] # Center of fluid domain
# X0 = [0.35*L, 0, 0.125*L] # Center of fluid domain
X0 = [0.40*L, 0, 0.115*L]

P_min = -[Lx, Ly, Lz]/2
P_max = [Lx, Ly, Lz]/2
NDIVS = Int.(ceil.([nx, ny, nz]))

origin(pfield, num) = X0 + Xn(num)
# origin(pfield, num) = X0
orientation(pfield, num) = gt.rotation_matrix(-angles(num)...)


# -------------- PROCESSING SETUP -----------------------------------------------
file_pref = run_name*"_pfield"
other_file_prefs = static_particles ? [run_name*"_staticpfield"] : []
other_read_paths = static_particles ? [read_path] : []
file_pref_out = run_name*"-fdom-"

# origin(pfield, num) = X0 + Xn(num) #NOTE: UNCOMMENT THIS
origin(pfield, num) = X0
orientation(pfield, num) = gt.rotation_matrix(-angles(num)...)
# Create save path
if save_path != read_path
gt.create_path(save_path, prompt)
end

# Copy this driver file
cp(splitdir(@__FILE__)[1], save_path*"/code"; force=true)


# Pre-processing function
function preprocessing(pfield, num, grids)
count = 0
count2 = 0
count3 = 0
countnan = 0
sigma_mean = 0
magGamma_mean = 0
magGamma2_mean = 0

for P in vpm.iterate(pfield; include_static=true)

# Check for large sigma
if P.sigma[1] > maxsigma
sigma_mean += P.sigma[1]
P.sigma[1] = maxsigma
count += 1
end

# Check for Gamma with NaN value
nangamma = !prod(isnan.(P.Gamma) .== false)

if nangamma
P.Gamma .= 1e-9
countnan += 1
end

# Check for blown-up Gamma
magGamma = norm(P.Gamma)

if magGamma > maxmagGamma
for i in 1:3; P.Gamma[i] = maxmagGamma * P.Gamma[i]/magGamma; end;
magGamma_mean += magGamma
count2 += 1
end

# Makes sure that the minimum Gamma is different than zero
if magGamma < 1e-13
P.Gamma .+= 1e-12
magGamma2_mean += magGamma
count3 += 1
end

if isnan(magGamma_mean)
println("NaN found in magGamma_mean!")
@show count
@show count2
@show countnan
end

end

sigma_mean /= count
magGamma_mean /= count2
magGamma2_mean /= count3

if verbose
if count!=0
println("\t"^(v_lvl+1)*"Shrunk $count particles."*
" Average sigma of shrunk particles:\t$(sigma_mean)")
end
if countnan!=0
println("\t"^(v_lvl+1)*"Found and corrected $(countnan) NaN values.")
end
if count2!=0
println("\t"^(v_lvl+1)*"Reset $count2 particle strengths (too strong)."*
" Average magGamma of reset particles:\t$(magGamma_mean)")
end
if count3!=0
println("\t"^(v_lvl+1)*"Reset $count3 particle strengths (too weak)."*
" Average magGamma of reset particles:\t$(magGamma2_mean)")
end
end
end

evaluate_fluiddomain_vtk(P_min, P_max, NDIVS, maxparticles,
nums, read_path, file_pref;
# O=X0,
origin=origin,
orientation=orientation,
scale_sigma=fsgm,
other_file_prefs=other_file_prefs,
other_read_paths=other_read_paths,
verbose=verbose, v_lvl=v_lvl,
debug=debug, save_path=save_path,
file_pref=file_pref_out
file_pref=file_pref_out,
userfunction_pfield=preprocessing,
optargs...
)
end

Expand Down

0 comments on commit 7383411

Please sign in to comment.