Skip to content

Commit

Permalink
Merge pull request #65 from dkavolis/secant
Browse files Browse the repository at this point in the history
Secant
  • Loading branch information
dkavolis authored May 23, 2019
2 parents dcfa17c + b242c5d commit 3cb4f9d
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ You should have received a copy of the GNU General Public License

using System;
using System.Collections.Generic;
using System.Globalization;
using ferram4;
using FerramAerospaceResearch.FARUtils;
using UnityEngine;
Expand Down Expand Up @@ -249,8 +250,16 @@ double phi
_instantCondition.GetClCdCmSteady(input, out pertOutput, true, true);
//Longitudinal Mess
_instantCondition.SetState(machNumber, neededCl, CoM, 0, input.flaps, input.spoilers);
FARMathUtil.OptimizationResult optResult =
FARMathUtil.Secant(_instantCondition.FunctionIterateForAlpha,
0,
10,
1e-4,
1e-4,
minLimit: -90,
maxLimit: 90);
alpha = optResult.Result;

alpha = FARMathUtil.SelectedSearchMethod(machNumber, _instantCondition.FunctionIterateForAlpha);
input.alpha = alpha;
nominalOutput = _instantCondition.iterationOutput;

Expand All @@ -260,19 +269,29 @@ double phi

stabDerivOutput.stableCl = neededCl;
stabDerivOutput.stableCd = nominalOutput.Cd;
stabDerivOutput.stableAoA = alpha;
stabDerivOutput.stableAoA = optResult.Converged ? alpha : double.NaN;
stabDerivOutput.stableAoAState = "";
if (Math.Abs((nominalOutput.Cl - neededCl) / neededCl) > 0.1)
if (optResult.Converged && Math.Abs((nominalOutput.Cl - neededCl) / neededCl) > 0.1)
stabDerivOutput.stableAoAState = nominalOutput.Cl > neededCl ? "<" : ">";

FARLogger.Info("Cl needed: " +
neededCl +
neededCl.ToString(CultureInfo.InvariantCulture) +
", AoA: " +
alpha +
stabDerivOutput.stableAoA.ToString(CultureInfo.InvariantCulture) +
", Cl: " +
nominalOutput.Cl +
nominalOutput.Cl.ToString(CultureInfo.InvariantCulture) +
", Cd: " +
nominalOutput.Cd);
nominalOutput.Cd.ToString(CultureInfo.InvariantCulture) +
", function calls: " +
optResult.FunctionCalls.ToString());

if (!optResult.Converged)
{
// couldn't find stable AoA, no reason to compute invalid stability derivatives
for (int i = 3; i < 24; i++)
stabDerivOutput.stabDerivs[i] = double.NaN;
return stabDerivOutput;
}

//vert vel derivs
pertOutput.Cl = (pertOutput.Cl - nominalOutput.Cl) / (2 * FARMathUtil.deg2rad);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public void ArrowAnim(ArrowPointer velArrow)

private void SetAngleVectors(double aoA)
{
if (double.IsNaN(aoA))
aoA = 0;
aoA *= FARMathUtil.deg2rad;

aoAVec = EditorDriver.editorFacility == EditorFacility.SPH
Expand Down Expand Up @@ -418,7 +420,7 @@ private static void StabilityLabel(string text1, double val, string text2, strin
{
Color color = Color.white;
if (sign != 0)
color = Math.Sign(val) == sign ? Color.green : Color.red;
color = !double.IsNaN(val) && Math.Sign(val) == sign ? Color.green : Color.red;

var style = new GUIStyle(GUI.skin.label);
style.normal.textColor = style.hover.textColor = color;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private static void StabilityLabel(string text1, double val, string text2, strin
{
Color color = Color.white;
if (sign != 0)
color = Math.Sign(val) == sign ? Color.green : Color.red;
color = !double.IsNaN(val) && Math.Sign(val) == sign ? Color.green : Color.red;

var style = new GUIStyle(GUI.skin.label);
style.normal.textColor = style.hover.textColor = color;
Expand Down
Loading

0 comments on commit 3cb4f9d

Please sign in to comment.