Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secant #65

Merged
merged 4 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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