From 6b0edb64f0add9a9f8678a82c2604a392164c997 Mon Sep 17 00:00:00 2001 From: Daniel Ingraham Date: Wed, 17 Jan 2024 12:48:51 -0500 Subject: [PATCH 1/5] Expose `npts` in `solve` to user --- src/CCBlade.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CCBlade.jl b/src/CCBlade.jl index 6ddb6c2..46f652e 100644 --- a/src/CCBlade.jl +++ b/src/CCBlade.jl @@ -375,11 +375,12 @@ Solve the BEM equations for given rotor geometry and operating point. - `rotor::Rotor`: rotor properties - `section::Section`: section properties - `op::OperatingPoint`: operating point +- `npts::Int = 10`: number of discretization points for `phi` state variable, used to find bracket for residual solve **Returns** - `outputs::Outputs`: BEM output data including loads, induction factors, etc. """ -function solve(rotor, section, op) +function solve(rotor, section, op, npts=10) # error handling if typeof(section) <: AbstractVector @@ -392,7 +393,7 @@ function solve(rotor, section, op) end # parameters - npts = 10 # number of discretization points to find bracket in residual solve + # npts = 10 # number of discretization points to find bracket in residual solve # unpack Vx = op.Vx From 91b685c25a6c8e1d5db9a203d8a04d1a64bfb410 Mon Sep 17 00:00:00 2001 From: Daniel Ingraham Date: Wed, 17 Jan 2024 12:52:09 -0500 Subject: [PATCH 2/5] `solve` `npts` docstring fix --- src/CCBlade.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CCBlade.jl b/src/CCBlade.jl index 46f652e..8953ef6 100644 --- a/src/CCBlade.jl +++ b/src/CCBlade.jl @@ -367,7 +367,7 @@ end """ - solve(rotor, section, op) + solve(rotor, section, op, npts=10) Solve the BEM equations for given rotor geometry and operating point. From aa8ff49413ceeabc3f4dfd296a39ce6854173e00 Mon Sep 17 00:00:00 2001 From: Daniel Ingraham Date: Wed, 17 Jan 2024 15:19:04 -0500 Subject: [PATCH 3/5] add `forcebackwardsearch` to `solve` --- src/CCBlade.jl | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/CCBlade.jl b/src/CCBlade.jl index 8953ef6..6b82395 100644 --- a/src/CCBlade.jl +++ b/src/CCBlade.jl @@ -342,7 +342,7 @@ interval (xmin, xmax) into n intervals. Returns found, xl, xu. If found = true a bracket was found between (xl, xu) """ -function firstbracket(f, xmin, xmax, n, backwardsearch=false) +function firstbracket(f, xmin, xmax, n, backwardsearch=false, verbose=false) xvec = range(xmin, xmax, length=n) if backwardsearch # start from xmax and work backwards @@ -352,6 +352,9 @@ function firstbracket(f, xmin, xmax, n, backwardsearch=false) fprev = f(xvec[1]) for i = 2:n fnext = f(xvec[i]) + if verbose + println("xprev = $(xvec[i-1]), xnext = $(xvec[i]), fprev = $(fprev), fnext = $(fnext)") + end if fprev*fnext < 0 # bracket found if backwardsearch return true, xvec[i], xvec[i-1] @@ -367,7 +370,7 @@ end """ - solve(rotor, section, op, npts=10) + solve(rotor, section, op; npts=10, forcebackwardsearch=false) Solve the BEM equations for given rotor geometry and operating point. @@ -376,11 +379,12 @@ Solve the BEM equations for given rotor geometry and operating point. - `section::Section`: section properties - `op::OperatingPoint`: operating point - `npts::Int = 10`: number of discretization points for `phi` state variable, used to find bracket for residual solve +- `forcebackwardsearch::Bool = false`: if true, force bracket search from high `phi` values to low, otherwise let `solve` decide **Returns** - `outputs::Outputs`: BEM output data including loads, induction factors, etc. """ -function solve(rotor, section, op, npts=10) +function solve(rotor, section, op; npts=10, forcebackwardsearch=false) # error handling if typeof(section) <: AbstractVector @@ -470,15 +474,19 @@ function solve(rotor, section, op, npts=10) for j = 1:length(order) # quadrant orders. In most cases it should find root in first quadrant searched. phimin, phimax = order[j] - # check to see if it would be faster to reverse the bracket search direction - backwardsearch = false - if !startfrom90 - if phimin == -pi/2 || phimax == -pi/2 # q2 or q4 - backwardsearch = true - end + if forcebackwardsearch + backwardsearch = true else - if phimax == pi/2 # q1 - backwardsearch = true + # check to see if it would be faster to reverse the bracket search direction + backwardsearch = false + if !startfrom90 + if phimin == -pi/2 || phimax == -pi/2 # q2 or q4 + backwardsearch = true + end + else + if phimax == pi/2 # q1 + backwardsearch = true + end end end From d9a29143da5cac750ee05a2d1debd507b276ab06 Mon Sep 17 00:00:00 2001 From: Daniel Ingraham Date: Wed, 17 Jan 2024 15:56:34 -0500 Subject: [PATCH 4/5] Add `epsilon_everywhere` to `solve` --- src/CCBlade.jl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/CCBlade.jl b/src/CCBlade.jl index 6b82395..2411157 100644 --- a/src/CCBlade.jl +++ b/src/CCBlade.jl @@ -370,7 +370,7 @@ end """ - solve(rotor, section, op; npts=10, forcebackwardsearch=false) + solve(rotor, section, op; npts=10, forcebackwardsearch=false, epsilon_everywhere=false) Solve the BEM equations for given rotor geometry and operating point. @@ -380,11 +380,12 @@ Solve the BEM equations for given rotor geometry and operating point. - `op::OperatingPoint`: operating point - `npts::Int = 10`: number of discretization points for `phi` state variable, used to find bracket for residual solve - `forcebackwardsearch::Bool = false`: if true, force bracket search from high `phi` values to low, otherwise let `solve` decide +- `epsilon_everywhere::Bool = false`: if true, don't evaluate at intersections of `phi` quadrants (`pi/2`, `-pi/2`, etc.) **Returns** - `outputs::Outputs`: BEM output data including loads, induction factors, etc. """ -function solve(rotor, section, op; npts=10, forcebackwardsearch=false) +function solve(rotor, section, op; npts=10, forcebackwardsearch=false, epsilon_everywhere=false) # error handling if typeof(section) <: AbstractVector @@ -410,10 +411,17 @@ function solve(rotor, section, op; npts=10, forcebackwardsearch=false) # quadrants epsilon = 1e-6 - q1 = [epsilon, pi/2] - q2 = [-pi/2, -epsilon] - q3 = [pi/2, pi-epsilon] - q4 = [-pi+epsilon, -pi/2] + if epsilon_everywhere + q1 = [epsilon, pi/2-epsilon] + q2 = [-pi/2+epsilon, -epsilon] + q3 = [pi/2+epsilon, pi-epsilon] + q4 = [-pi+epsilon, -pi/2-epsilon] + else + q1 = [epsilon, pi/2] + q2 = [-pi/2, -epsilon] + q3 = [pi/2, pi-epsilon] + q4 = [-pi+epsilon, -pi/2] + end if Vx_is_zero && Vy_is_zero return Outputs() From 68edb2c7f31534da22eb7063ce78ec2dac7bf2fc Mon Sep 17 00:00:00 2001 From: Daniel Ingraham Date: Tue, 6 Feb 2024 11:09:13 -0500 Subject: [PATCH 5/5] Remove some debug print statements --- src/CCBlade.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/CCBlade.jl b/src/CCBlade.jl index 2411157..dc12ede 100644 --- a/src/CCBlade.jl +++ b/src/CCBlade.jl @@ -300,7 +300,6 @@ function residual_and_outputs(phi, x, p) #rotor, section, op) R = sin(phi)/(1 + a) - Vx/Vy*cos(phi)/(1 - ap) end - # ------- loads --------- W = sqrt((Vx + u)^2 + (Vy - v)^2) Np = cn*0.5*rho*W^2*chord @@ -342,7 +341,7 @@ interval (xmin, xmax) into n intervals. Returns found, xl, xu. If found = true a bracket was found between (xl, xu) """ -function firstbracket(f, xmin, xmax, n, backwardsearch=false, verbose=false) +function firstbracket(f, xmin, xmax, n, backwardsearch=false) xvec = range(xmin, xmax, length=n) if backwardsearch # start from xmax and work backwards @@ -352,9 +351,6 @@ function firstbracket(f, xmin, xmax, n, backwardsearch=false, verbose=false) fprev = f(xvec[1]) for i = 2:n fnext = f(xvec[i]) - if verbose - println("xprev = $(xvec[i-1]), xnext = $(xvec[i]), fprev = $(fprev), fnext = $(fnext)") - end if fprev*fnext < 0 # bracket found if backwardsearch return true, xvec[i], xvec[i-1]