Skip to content

Commit

Permalink
Finish setting up Vahana2 simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
EdoAlvarezR committed Feb 24, 2021
1 parent 76e06e2 commit 6a61c2d
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 35 deletions.
57 changes: 38 additions & 19 deletions examples/vahana2/vahana2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end

# ------------ DRIVERS ---------------------------------------------------------

function run_simulation_vahana(; save_path=extdrive_path*"vahana2_sim03",
function run_simulation_vahana(; save_path=extdrive_path*"vahana2_sim10",
prompt=true,
run_name="vahana2",
verbose=true, v_lvl=1)
Expand All @@ -53,21 +53,29 @@ function run_simulation_vahana(; save_path=extdrive_path*"vahana2_sim03",
n_factor = 1 # Refinement factor
add_rotors = true # Whether to include rotors

# Maneuver to perform
## 72 steps per rev settings
Vcruise = 0.25 * 125*0.44704 # Cruise speed
Vinf(x,t) = 1e-5*[1,0,-1] # (m/s) freestream velocity, if 0 the simulation might crash
RPMh_w = 600.0 # RPM of main wing rotors in hover
telapsed = 30.0 # Total time to perform maneuver
nsteps = 21600 # Time steps

# # Maneuver to perform
# Vcruise = 0.125 * 125*0.44704 # Cruise speed
# RPMh_w = 600 # RPM of main wing rotors in hover
# telapsed = 60.0 # Total time to perform maneuver
# nsteps = 9000 # Time steps

# Maneuver to perform
Vcruise = 0.25 * 125*0.44704 # Cruise speed
Vinf(x,t) = 1e-5*[1,0,-1] # (m/s) freestream velocity, if 0 the simulation might crash
# RPMh_w = 200 # RPM of main wing rotors in hover
# RPMh_w = 20
RPMh_w = 100
telapsed = 30.0 # Total time to perform maneuver
nsteps = 1500 # Time steps
# nsteps = 100
# # Maneuver to perform
# Vcruise = 0.25 * 125*0.44704 # Cruise speed
# Vinf(x,t) = 1e-5*[1,0,-1] # (m/s) freestream velocity, if 0 the simulation might crash
# # RPMh_w = 200 # RPM of main wing rotors in hover
# # RPMh_w = 20
# RPMh_w = 100
# telapsed = 30.0 # Total time to perform maneuver
# nsteps = 1500 # Time steps
# # nsteps = 100

dt = telapsed/nsteps

Expand Down Expand Up @@ -150,7 +158,11 @@ function run_simulation_vahana(; save_path=extdrive_path*"vahana2_sim03",


# ----------------- WAKE TREATMENT FUNCTION --------------------------------
runtime_function(args...; optargs...) = remove_particles_lowstrength(args...; optargs...) || monitor(args...; optargs...)
remove_particles(args...; optargs...) = (remove_particles_lowstrength(args...; optargs...)
|| remove_particles_sphere(args...; optargs...))

# ----------------- RUNTIME FUNCTION ---------------------------------------
runtime_function(args...; optargs...) = remove_particles(args...; optargs...) || monitor(args...; optargs...)

# ----------------- RUN SIMULATION -----------------------------------------
pfield = uns.run_simulation(simulation, nsteps;
Expand Down Expand Up @@ -183,18 +195,25 @@ function run_simulation_vahana(; save_path=extdrive_path*"vahana2_sim03",
end


function visualize_maneuver_vahana(; save_path=extdrive_path*"vahana2_maneuver00/",
function visualize_maneuver_vahana(; save_path=extdrive_path*"vahana2_maneuver02/",
prompt=true,
run_name="vahana2",
verbose=true, v_lvl=0,
paraview=true,
optargs...)

# Maneuver to perform
## 72 steps per rev settings
Vcruise = 0.25 * 125*0.44704 # Cruise speed
RPMh_w = 400.0 # RPM of main wing rotors in hover
RPMh_w = 600.0 # RPM of main wing rotors in hover
telapsed = 30.0 # Total time to perform maneuver
nsteps = 100 # Time steps
nsteps = 21600 # Time steps

# # Maneuver to perform
# Vcruise = 0.25 * 125*0.44704 # Cruise speed
# RPMh_w = 400.0 # RPM of main wing rotors in hover
# telapsed = 30.0 # Total time to perform maneuver
# nsteps = 100 # Time steps

# # Maneuver to perform
# Vcruise = 0.25 * 125*0.44704 # Cruise speed
Expand Down Expand Up @@ -301,11 +320,11 @@ function visualize_geometry_vahana(; save_path=extdrive_path*"vahana2_geometry01
# Save vehicle
strn = uns.save_vtk(vehicle, run_name; path=save_path, save_horseshoes=false)

# # Save ground
# for (i, ground) in enumerate(grounds)
# gt.save(ground, run_name*"_Ground$i"; path=save_path)
# strn *= run_name*"_Ground$i.vtk;"
# end
# Save ground
for (i, ground) in enumerate(grounds)
gt.save(ground, run_name*"_Ground$i"; path=save_path)
strn *= run_name*"_Ground$i.vtk;"
end

# Call Paraview
run(`paraview --data="$save_path/$strn"`)
Expand Down
31 changes: 18 additions & 13 deletions examples/vahana2/vahana2_geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ function generate_geometry_vahana(;
tr_w = 1.0 # Taper ratio
twist_r_w = 7.5 # (deg) twist at root
twist_t_w = twist_r_w # (deg) twist at tip
lambda_w = 10.0 # (deg) sweep
gamma_w = 0.0 # (deg) dihedral
lambda_w = main_outtilt # (deg) sweep
gamma_w = 5.0 # (deg) dihedral
n_w = 12*n_factor # Number of horseshoes per side of wing
r_w = 2.0 # Horseshoe expansion ratio
md_w = 0.9 # Ratio of length of middle section
Expand Down Expand Up @@ -232,11 +232,12 @@ function generate_geometry_vahana(;
symmetric=true, chordalign=0.0,
_ign1=true)
# Left section
pos_l_w = [-(1-md_w), -0]
# pos_l_w = [-(1-md_w), -0]
pos_l_w = [0, -(1-md_w)] # Here I'm defining this wing section from right to left
clen_l_w = [1, clen_md_w[end]]
twist_l_w = [twist_t_w, twist_md_w[end]]
wing_L = vlm.complexWing(b_w, AR_w, ceil(Int, (1-md_w)*n_w/2), pos_l_w, clen_l_w,
twist_l_w, lambda_w*ones(1), gamma_w*ones(1);
twist_l_w, -lambda_w*ones(1), -gamma_w*ones(1);
symmetric=false, chordalign=0.0,
_ign1=true)
# Right section
Expand Down Expand Up @@ -271,13 +272,14 @@ function generate_geometry_vahana(;
if add_rotors
if verbose; println("\t"^(v_lvl+2)*"Generating main wing propellers..."); end;
O_prop_w = [
(ypos - md_w*b_w/2)*[tan(lambda_w*pi/180), 0, tan(gamma_w*pi/180)] +
(ypos - md_w*b_w/2)*[tan(lambda_w*pi/180), 0, -tan(gamma_w*pi/180)] +
ypos*[0, 1, 0] +
[-(i in stacked ? stckd_xoc_offset : xoc_offset_main)*AR_w/b_w, 0, 0] +
[0, 0, (in in stacked ? stckd_zoc_offset : 0)*AR_w/b_w]
[0, 0, (i in stacked ? stckd_zoc_offset*tan(gamma_w*pi/180) : 0)*AR_w/b_w]
for (i, ypos) in enumerate(y_pos_prop_w)]
props_w = vlm.Rotor[]
props_w_stacked = vlm.Rotor[]
props_w_stacked_up = vlm.Rotor[]
props_w_stacked_low = vlm.Rotor[]
for i in 1:2*np_w
right = i<=np_w # Indicates which side of the wing

Expand All @@ -304,7 +306,7 @@ function generate_geometry_vahana(;
push!(props_w, this_prop)

else
push!(props_w_stacked, this_prop)
push!(props_w_stacked_up, this_prop)

copy_prop = deepcopy(stackedrotors[ 1+(i+1*!stckd_corotating)%2 ])

Expand All @@ -331,7 +333,7 @@ function generate_geometry_vahana(;
this_prop._polarroot = copy_prop._polarroot
this_prop._polartip = copy_prop._polartip

push!(props_w_stacked, this_prop)
push!(props_w_stacked_low, this_prop)
end
end
end
Expand All @@ -340,8 +342,11 @@ function generate_geometry_vahana(;
main_wing_fixed = vlm.WingSystem()
vlm.addwing(main_wing_fixed, "WingM", wing_md)
if add_rotors
for (i, prop) in enumerate(props_w_stacked)
vlm.addwing(main_wing_fixed, "StackedProp$i", prop)
for (i, prop) in enumerate(props_w_stacked_up)
vlm.addwing(main_wing_fixed, "StackedPropUp$i", prop)
end
for (i, prop) in enumerate(props_w_stacked_low)
vlm.addwing(main_wing_fixed, "StackedPropLow$i", prop)
end
end

Expand Down Expand Up @@ -542,7 +547,7 @@ function generate_geometry_vahana(;
vlm.addwing(system, "TandemWing", tandem_wing)

if add_rotors
rotors = vcat(props_w, props_w_stacked, props_tw)
rotors = vcat(props_w, props_w_stacked_up, props_w_stacked_low, props_tw)
end

# ------------ GROUND SURFACE ----------------------------------------
Expand All @@ -558,7 +563,7 @@ function generate_geometry_vahana(;

# Rotors grouped by systems of the same RPM
if add_rotors
rotor_systems = (props_w, props_w_stacked, props_tw)
rotor_systems = (props_w, props_w_stacked_up, props_w_stacked_low, props_tw)
else
rotor_systems = ()
end
Expand Down
95 changes: 94 additions & 1 deletion examples/vahana2/vahana2_kinematics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ function generate_maneuver_vahana(; disp_plot=false, add_rotors=true, V0=0.0001)
RPM1 = 1.10
RPM2 = 1.50
RPM3 = 0.75
RPM3_stacked = 1e-7
RPM4 = 1.00
RPM5 = 0.90

r_RPMh_stup = 1.25 # Ratio between stacked and main rotors in hover
r_RPMh_tw = 0.75 # Ratio between tandem and main wing RPM in hover

# NOTE: -x is in the direction of flight and +z is climb with ground at z=0
Expand Down Expand Up @@ -303,6 +305,97 @@ function generate_maneuver_vahana(; disp_plot=false, add_rotors=true, V0=0.0001)
end
end

"""
Receives a nondimensional time between 0 and 1, and returns the RPM of
stacked upper rotors in main wing non-dimensionalized by the hover RPM.
"""
function RPM_stacked_up(t)

# ------------ TAKE OFF ------------------------------------------------
if t<t1
# Weibull acceleration to target climb
if t<t1/5
val = t / (t1/5)
RPM_w = RPM1*(1.05-exp(-(5*val)^2))
# Weibull decceleration to hover
else
val = 1 - (t-t1/5) / (1-t1/5)
RPM_w = 1.0 + (RPM1-1.0)*(1-exp(-(2*val)^5))
end

return r_RPMh_stup*RPM_w

# ------------ TRANSITION ----------------------------------------------
elseif t<t2
# Increases RPM to sustain forward flight and hover
if (t-t1)<(t2-t1)*0.65
val = (t-t1)/((t2-t1)*0.65)
RPM_tw = r_RPMh_tw*(1.0 + (RPM2-1.0)*(1-exp(-(2*val)^5)))
# Decreases RPM as it tilts the wing out of hover support
else
val = 1 - (t2-t)/(t2-((t2-t1)*0.65 + t1))
RPM_tw = r_RPMh_tw*(RPM2 + val*(RPM3_stacked-RPM2))
end

return RPM_tw

# ------------ CRUISE --------------------------------------------------
elseif t<t3
return RPM3_stacked

# ------------ TRANSITION ----------------------------------------------
elseif t<t4
# Weibull decceleration to hover
val = 1.5 * (1 - (t-t3) / (t4-t3))
RPM_w = RPM4 + (RPM3_stacked-RPM4)*(1-exp(-(val)^3))
return r_RPMh_stup*RPM_w

# ------------ LANDING -------------------------------------------------
else
# Weibull acceleration to target descend
if (t-t4)<(1-t4)*0.75
val = (t-t4) / ((1-t4)*0.75)
RPM_w = RPM4 + (RPM5-RPM4)*(1-exp(-(3*val)^5))
# Weibull decceleration to hover
else
val = ((t-t4) - (1-t4)*0.75) / ((1-t4)*(1-0.75))
val = val + 0.60
RPM_w = RPM5*(3.0*(val)^(3.0-1)*exp(-(val)^5.0))/1.0
end

return r_RPMh_stup*RPM_w
end
end


"""
Receives a nondimensional time between 0 and 1, and returns the RPM of
stacked lower rotors in main wing non-dimensionalized by the hover RPM.
"""
function RPM_stacked_low(t)

# ------------ TAKE OFF ------------------------------------------------
if t<t1
return RPM_stacked_up(t)

# ------------ TRANSITION ----------------------------------------------
elseif t<t2
return RPM_stacked_up(t)

# ------------ CRUISE --------------------------------------------------
elseif t<t3
return RPM_stacked_up(t)

# ------------ TRANSITION ----------------------------------------------
elseif t<t4
return RPM_stacked_up(t)

# ------------ LANDING -------------------------------------------------
else
return RPM_stacked_up(t)
end
end

"""
Receives a nondimensional time between 0 and 1, and returns the
tandem wing RPM non-dimensionalized by the hover RPM.
Expand Down Expand Up @@ -351,7 +444,7 @@ function generate_maneuver_vahana(; disp_plot=false, add_rotors=true, V0=0.0001)
############################################################################
angle = (angle_main, angle_tandem)
if add_rotors
RPM = (RPM_main, RPM_tandem)
RPM = (RPM_main, RPM_stacked_up, RPM_stacked_low, RPM_tandem)
else
RPM = ()
end
Expand Down
23 changes: 21 additions & 2 deletions examples/vahana2/vahana2_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,31 @@
=###############################################################################


function remove_particles_lowstrength(sim, PFIELD, T, DT)
function remove_particles_lowstrength(sim, PFIELD, T, DT; crit=0.00001^2)

for i in vpm.get_np(PFIELD):-1:1
P = vpm.get_particle(PFIELD, i)

if P.Gamma[1]*P.Gamma[1] + P.Gamma[2]*P.Gamma[2] + P.Gamma[3]*P.Gamma[3] < 0.001^2
if P.Gamma[1]*P.Gamma[1] + P.Gamma[2]*P.Gamma[2] + P.Gamma[3]*P.Gamma[3] < crit
vpm.remove_particle(PFIELD, i)
end
end

return false
end


function remove_particles_sphere(sim, PFIELD, T, DT; Rsphere2=(3*5.86)^2)

Xvehicle = sim.vehicle.system.O

for i in vpm.get_np(PFIELD):-1:1
P = vpm.get_particle(PFIELD, i)
X1 = P.X[1] - Xvehicle[1]
X2 = P.X[2] - Xvehicle[2]
X3 = P.X[3] - Xvehicle[3]

if X1*X1 + X2*X2 + X3*X3 > Rsphere2
vpm.remove_particle(PFIELD, i)
end
end
Expand Down

0 comments on commit 6a61c2d

Please sign in to comment.