public int ExportSweep(CelestialBody body, double pitch, int flapSetting, bool spoilers)
        {
            if (!IsReady())
            {
                return(0);
            }

            FARAeroUtil.UpdateCurrentActiveBody(body);
            FARAeroUtil.ResetEditorParts();

            StaticAnalysisExportFile  exportdata = new StaticAnalysisExportFile();
            InstantConditionSimInput  input      = new InstantConditionSimInput(0, 0, 0, 0, 0, 0, FlightEnv.NewDefaultVal(body), pitch, flapSetting, spoilers);
            InstantConditionSimOutput output;

            Vector3d centerofmass = _instantCondition.GetCoM();

            // Loop through each combination (two dimensions).
            foreach (float mach in exportdata.MachNumberList)
            {
                input.fltenv.MachNumber = mach;
                input.alpha             = 0;                              // zero is used as a neutral value for the reset
                _instantCondition.ResetClCdCmSteady(centerofmass, input); // reset old results (particularly cossweep) that may not reflect the current mach number

                foreach (float aoadeg in exportdata.AoADegreeList)
                {
                    input.alpha = aoadeg;
                    _instantCondition.GetClCdCmSteady(input, out output, true, true);
                    exportdata.AddDatapoint(mach, aoadeg, output.Cl, output.Cd, output.Cm);
                }
            }

            exportdata.Export();
            return(exportdata.DataCount);
        }
Exemple #2
0
        public void LateUpdate()
        {
            FARAeroUtil.ResetEditorParts();
            FARBaseAerodynamics.GlobalCoLReady = false;

            if (EditorLogic.fetch)
            {
                if (editorGUI == null)
                {
                    editorGUI = new FAREditorGUI();
                    //editorGUI.LoadGUIParameters();
                    editorGUI.RestartCtrlGUI();
                }
                if (EditorLogic.startPod != null)
                {
                    var editorShip = FARAeroUtil.AllEditorParts;


                    if (FARAeroUtil.EditorAboutToAttach() && count++ >= 10)
                    {
                        EditorPartsChanged = true;
                        count = 0;
                    }

                    if (part_count_all != editorShip.Count || part_count_ship != EditorLogic.SortedShipList.Count || EditorPartsChanged)
                    {
                        FindPartsWithoutFARModel(editorShip);
                        foreach (Part p in editorShip)
                        {
                            foreach (PartModule m in p.Modules)
                            {
                                if (m is FARBaseAerodynamics)
                                {
                                    (m as FARBaseAerodynamics).ClearShielding();
                                }
                            }
                        }

                        foreach (Part p in editorShip)
                        {
                            foreach (PartModule m in p.Modules)
                            {
                                if (m is FARPartModule)
                                {
                                    (m as FARPartModule).ForceOnVesselPartsChange();
                                }
                            }
                        }

                        part_count_all     = editorShip.Count;
                        part_count_ship    = EditorLogic.SortedShipList.Count;
                        EditorPartsChanged = false;
                    }
                }
            }
        }
Exemple #3
0
        public void LateUpdate()
        {
            if (!CompatibilityChecker.IsAllCompatible())
            {
                return;
            }

            FARAeroUtil.ResetEditorParts();
            FARBaseAerodynamics.GlobalCoLReady = false;

            if (EditorLogic.fetch)
            {
                if (editorGUI == null)
                {
                    editorGUI = new FAREditorGUI();
                    //editorGUI.LoadGUIParameters();
                    editorGUI.RestartCtrlGUI();
                    GameEvents.onEditorUndo.Add(editorGUI.ResetAll);
                    GameEvents.onEditorRedo.Add(editorGUI.ResetAll);
                }
                if (EditorLogic.RootPart != null)
                {
                    editorShip = FARAeroUtil.AllEditorParts;

                    if (buttonsNeedInitializing)
                    {
                        InitializeButtons();
                    }

                    /*if (EditorLogic.RootPart != lastRootPart)
                     * {
                     *  lastRootPart = EditorLogic.RootPart;
                     *  EditorPartsChanged = true;
                     * }*/

                    if (FARAeroUtil.EditorAboutToAttach() && count++ >= 20)
                    {
                        EditorPartsChanged = true;
                        count = 0;
                    }

                    if (part_count_all != editorShip.Count || part_count_ship != EditorLogic.SortedShipList.Count || EditorPartsChanged)
                    {
                        UpdateEditorShipModules();
                    }
                }
                else if (!buttonsNeedInitializing)
                {
                    DestroyButtons();
                }
            }
        }
Exemple #4
0
        public GraphData MachNumberSweep(
            double aoAdegrees,
            double pitch,
            double lowerBound,
            double upperBound,
            int numPoints,
            int flapSetting,
            bool spoilers,
            CelestialBody body
            )
        {
            FARAeroUtil.UpdateCurrentActiveBody(body);

            FARAeroUtil.ResetEditorParts();

            var ClValues    = new double[numPoints];
            var CdValues    = new double[numPoints];
            var CmValues    = new double[numPoints];
            var LDValues    = new double[numPoints];
            var AlphaValues = new double[numPoints];

            var input = new InstantConditionSimInput(aoAdegrees, 0, 0, 0, 0, 0, 0, pitch, flapSetting, spoilers);

            for (int i = 0; i < numPoints; i++)
            {
                input.machNumber = i / (double)numPoints * (upperBound - lowerBound) + lowerBound;

                if (input.machNumber.NearlyEqual(0))
                {
                    input.machNumber = 0.001;
                }

                _instantCondition.GetClCdCmSteady(input, out InstantConditionSimOutput output, i == 0);
                AlphaValues[i] = input.machNumber;
                ClValues[i]    = output.Cl;
                CdValues[i]    = output.Cd;
                CmValues[i]    = output.Cm;
                LDValues[i]    = output.Cl * 0.1 / output.Cd;
            }

            var data = new GraphData {
                xValues = AlphaValues
            };

            data.AddData(ClValues, FARConfig.GUIColors.ClColor, Localizer.Format("FARAbbrevCl"), true);
            data.AddData(CdValues, FARConfig.GUIColors.CdColor, Localizer.Format("FARAbbrevCd"), true);
            data.AddData(CmValues, FARConfig.GUIColors.CmColor, Localizer.Format("FARAbbrevCm"), true);
            data.AddData(LDValues, FARConfig.GUIColors.LdColor, Localizer.Format("FARAbbrevL_D"), true);

            return(data);
        }
Exemple #5
0
        private void ResetEditorEvent(ShipConstruct construct)
        {
            FARAeroUtil.ResetEditorParts();

            if (EditorLogic.RootPart != null)
            {
                List <Part> partsList = EditorLogic.SortedShipList;
                for (int i = 0; i < partsList.Count; i++)
                {
                    UpdateGeometryModule(partsList[i]);
                }
            }

            RequestUpdateVoxel();
        }
        private void ResetEditorEvent(ShipConstruct construct)
        {
            FARAeroUtil.ResetEditorParts(); // Rodhern: Partial fix to https://github.com/ferram4/Ferram-Aerospace-Research/issues/177 .

            if (EditorLogic.RootPart != null)
            {
                List <Part> partsList = EditorLogic.SortedShipList;
                for (int i = 0; i < partsList.Count; i++)
                {
                    UpdateGeometryModule(partsList[i]);
                }
            }

            RequestUpdateVoxel();
        }
        public GraphData MachNumberSweep(double aoAdegrees, double pitch, double lowerBound, double upperBound, int numPoints, int flapSetting, bool spoilers, CelestialBody body)
        {
            FARAeroUtil.UpdateCurrentActiveBody(body);

            FARAeroUtil.ResetEditorParts();

            double[] ClValues    = new double[(int)numPoints];
            double[] CdValues    = new double[(int)numPoints];
            double[] CmValues    = new double[(int)numPoints];
            double[] LDValues    = new double[(int)numPoints];
            double[] AlphaValues = new double[(int)numPoints];

            InstantConditionSimInput input = new InstantConditionSimInput(aoAdegrees, 0, 0, 0, 0, 0, FlightEnv.NewDefaultVal(body), pitch, flapSetting, spoilers);

            for (int i = 0; i < numPoints; i++)
            {
                input.fltenv.MachNumber = lowerBound + (upperBound - lowerBound) * (i == 0? 0 : i / (numPoints - 1.0));

                if (input.fltenv.MachNumber < 1E-3)
                {
                    input.fltenv.MachNumber = 1E-3;
                }

                InstantConditionSimOutput output;

                _instantCondition.GetClCdCmSteady(input, out output, i == 0, false);
                AlphaValues[i] = input.fltenv.MachNumber;
                ClValues[i]    = output.Cl;
                CdValues[i]    = output.Cd;
                CmValues[i]    = output.Cm;
                LDValues[i]    = output.Cl * 0.1 / output.Cd;
            }

            GraphData data = new GraphData();

            data.xValues = AlphaValues;
            data.AddData(ClValues, GUIColors.GetColor(0), Localizer.Format("FARAbbrevCl"), true);
            data.AddData(CdValues, GUIColors.GetColor(1), Localizer.Format("FARAbbrevCd"), true);
            data.AddData(CmValues, GUIColors.GetColor(2), Localizer.Format("FARAbbrevCm"), true);
            data.AddData(LDValues, GUIColors.GetColor(3), Localizer.Format("FARAbbrevL_D"), true);

            data.exportdata.AddSizeVariables(_instantCondition, pitch, flapSetting, spoilers);
            data.exportdata.AddMachSweepXVariable(aoAdegrees, AlphaValues);
            data.exportdata.AddYVariables(data);

            return(data);
        }
Exemple #8
0
        public GraphData MachNumberSweep(double aoAdegrees, double pitch, double lowerBound, double upperBound, int numPoints, int flapSetting, bool spoilers, CelestialBody body)
        {
            FARAeroUtil.UpdateCurrentActiveBody(body);

            FARAeroUtil.ResetEditorParts();

            double[] ClValues    = new double[(int)numPoints];
            double[] CdValues    = new double[(int)numPoints];
            double[] CmValues    = new double[(int)numPoints];
            double[] LDValues    = new double[(int)numPoints];
            double[] AlphaValues = new double[(int)numPoints];

            InstantConditionSimInput input = new InstantConditionSimInput(aoAdegrees, 0, 0, 0, 0, 0, 0, pitch, flapSetting, spoilers);

            for (int i = 0; i < numPoints; i++)
            {
                input.machNumber = i / (double)numPoints * (upperBound - lowerBound) + lowerBound;

                if (input.machNumber == 0)
                {
                    input.machNumber = 0.001;
                }

                InstantConditionSimOutput output;

                _instantCondition.GetClCdCmSteady(input, out output, i == 0);
                AlphaValues[i] = input.machNumber;
                ClValues[i]    = output.Cl;
                CdValues[i]    = output.Cd;
                CmValues[i]    = output.Cm;
                LDValues[i]    = output.Cl * 0.1 / output.Cd;
            }

            GraphData data = new GraphData();

            data.xValues = AlphaValues;
            data.AddData(ClValues, GUIColors.GetColor(0), "Cl", true);
            data.AddData(CdValues, GUIColors.GetColor(1), "Cd", true);
            data.AddData(CmValues, GUIColors.GetColor(2), "Cm", true);
            data.AddData(LDValues, GUIColors.GetColor(3), "L/D", true);

            return(data);
        }
Exemple #9
0
        public GraphData AngleOfAttackSweep(double machNumber, double pitch, double lowerBound, double upperBound, int numPoints, int flapSetting, bool spoilers, CelestialBody body)
        {
            if (machNumber == 0)
            {
                machNumber = 0.001;
            }

            InstantConditionSimInput input = new InstantConditionSimInput(0, 0, 0, 0, 0, 0, machNumber, pitch, flapSetting, spoilers);

            FARAeroUtil.UpdateCurrentActiveBody(body);

            FARAeroUtil.ResetEditorParts();


            double[] ClValues    = new double[(int)numPoints];
            double[] CdValues    = new double[(int)numPoints];
            double[] CmValues    = new double[(int)numPoints];
            double[] LDValues    = new double[(int)numPoints];
            double[] AlphaValues = new double[(int)numPoints];
            double[] ClValues2   = new double[(int)numPoints];
            double[] CdValues2   = new double[(int)numPoints];
            double[] CmValues2   = new double[(int)numPoints];
            double[] LDValues2   = new double[(int)numPoints];

            for (int i = 0; i < 2 * numPoints; i++)
            {
                double angle = 0;
                if (i < numPoints)
                {
                    angle = i / (double)numPoints * (upperBound - lowerBound) + lowerBound;
                }
                else
                {
                    angle = (i - (double)numPoints + 1) / (double)numPoints * (lowerBound - upperBound) + upperBound;
                }

                input.alpha = angle;

                InstantConditionSimOutput output;

                _instantCondition.GetClCdCmSteady(input, out output, i == 0);

                //                MonoBehaviour.print("Cl: " + Cl + " Cd: " + Cd);
                if (i < numPoints)
                {
                    AlphaValues[i] = angle;
                    ClValues[i]    = output.Cl;
                    CdValues[i]    = output.Cd;
                    CmValues[i]    = output.Cm;
                    LDValues[i]    = output.Cl * 0.1 / output.Cd;
                }
                else
                {
                    ClValues2[numPoints * 2 - 1 - i] = output.Cl;
                    CdValues2[numPoints * 2 - 1 - i] = output.Cd;
                    CmValues2[numPoints * 2 - 1 - i] = output.Cm;
                    LDValues2[numPoints * 2 - 1 - i] = output.Cl * 0.1 / output.Cd;
                }
            }

            GraphData data = new GraphData();

            data.xValues = AlphaValues;
            data.AddData(ClValues2, GUIColors.GetColor(0) * 0.5f, "Cl2", false);
            data.AddData(ClValues, GUIColors.GetColor(0), "Cl", true);

            data.AddData(CdValues2, GUIColors.GetColor(1) * 0.5f, "Cd2", false);
            data.AddData(CdValues, GUIColors.GetColor(1), "Cd", true);

            data.AddData(CmValues2, GUIColors.GetColor(2) * 0.5f, "Cm2", false);
            data.AddData(CmValues, GUIColors.GetColor(2), "Cm", true);

            data.AddData(LDValues2, GUIColors.GetColor(3) * 0.5f, "L/D2", false);
            data.AddData(LDValues, GUIColors.GetColor(3), "L/D", true);


            return(data);
        }
Exemple #10
0
        public GraphData AngleOfAttackSweep(
            double machNumber,
            double pitch,
            double lowerBound,
            double upperBound,
            int numPoints,
            int flapSetting,
            bool spoilers,
            CelestialBody body
            )
        {
            if (machNumber.NearlyEqual(0))
            {
                machNumber = 0.001;
            }

            var input = new InstantConditionSimInput(0, 0, 0, 0, 0, 0, machNumber, pitch, flapSetting, spoilers);

            FARAeroUtil.UpdateCurrentActiveBody(body);

            FARAeroUtil.ResetEditorParts();


            var ClValues    = new double[numPoints];
            var CdValues    = new double[numPoints];
            var CmValues    = new double[numPoints];
            var LDValues    = new double[numPoints];
            var AlphaValues = new double[numPoints];
            var ClValues2   = new double[numPoints];
            var CdValues2   = new double[numPoints];
            var CmValues2   = new double[numPoints];
            var LDValues2   = new double[numPoints];

            for (int i = 0; i < 2 * numPoints; i++)
            {
                double angle;
                if (i < numPoints)
                {
                    angle = i / (double)numPoints * (upperBound - lowerBound) + lowerBound;
                }
                else
                {
                    angle = (i - (double)numPoints + 1) / numPoints * (lowerBound - upperBound) + upperBound;
                }

                input.alpha = angle;

                _instantCondition.GetClCdCmSteady(input, out InstantConditionSimOutput output, i == 0);

                if (i < numPoints)
                {
                    AlphaValues[i] = angle;
                    ClValues[i]    = output.Cl;
                    CdValues[i]    = output.Cd;
                    CmValues[i]    = output.Cm;
                    LDValues[i]    = output.Cl * 0.1 / output.Cd;
                }
                else
                {
                    ClValues2[numPoints * 2 - 1 - i] = output.Cl;
                    CdValues2[numPoints * 2 - 1 - i] = output.Cd;
                    CmValues2[numPoints * 2 - 1 - i] = output.Cm;
                    LDValues2[numPoints * 2 - 1 - i] = output.Cl * 0.1 / output.Cd;
                }
            }

            var data = new GraphData {
                xValues = AlphaValues
            };

            data.AddData(ClValues2, FARConfig.GUIColors.ClColor * 0.5f, "Cl2", false);
            data.AddData(ClValues, FARConfig.GUIColors.ClColor, Localizer.Format("FARAbbrevCl"), true);

            data.AddData(CdValues2, FARConfig.GUIColors.CdColor * 0.5f, "Cd2", false);
            data.AddData(CdValues, FARConfig.GUIColors.CdColor, Localizer.Format("FARAbbrevCd"), true);

            data.AddData(CmValues2, FARConfig.GUIColors.CmColor * 0.5f, "Cm2", false);
            data.AddData(CmValues, FARConfig.GUIColors.CmColor, Localizer.Format("FARAbbrevCm"), true);

            data.AddData(LDValues2, FARConfig.GUIColors.LdColor * 0.5f, "L/D2", false);
            data.AddData(LDValues, FARConfig.GUIColors.LdColor, Localizer.Format("FARAbbrevL_D"), true);


            return(data);
        }
        public GraphData AngleOfAttackSweep(double machNumber, double pitch, double lowerBound, double upperBound, int numPoints, int flapSetting, bool spoilers, CelestialBody body)
        {
            if (machNumber < 1E-3)
            {
                machNumber = 1E-3;
            }

            FARAeroUtil.UpdateCurrentActiveBody(body);

            FARAeroUtil.ResetEditorParts();

            double[] ClValues    = new double[(int)numPoints];
            double[] CdValues    = new double[(int)numPoints];
            double[] CmValues    = new double[(int)numPoints];
            double[] LDValues    = new double[(int)numPoints];
            double[] AlphaValues = new double[(int)numPoints];
            double[] ClValues2   = new double[(int)numPoints];
            double[] CdValues2   = new double[(int)numPoints];
            double[] CmValues2   = new double[(int)numPoints];
            double[] LDValues2   = new double[(int)numPoints];

            InstantConditionSimInput input = new InstantConditionSimInput(0, 0, 0, 0, 0, 0, FlightEnv.NewDefaultVal(body), pitch, flapSetting, spoilers);

            input.fltenv.MachNumber = machNumber;

            for (int i = 0; i < 2 * numPoints; i++)
            {
                double angle = 0;
                if (i < numPoints)
                {
                    angle = lowerBound + (upperBound - lowerBound) * (i == 0? 0 : i / (numPoints - 1.0));
                }
                else
                {
                    angle = upperBound + (lowerBound - upperBound) * (i == numPoints ? 0 : (i - numPoints) / (numPoints - 1.0));
                }
                input.alpha = angle;

                InstantConditionSimOutput output;

                _instantCondition.GetClCdCmSteady(input, out output, i == 0, false);

                if (i < numPoints)
                {
                    AlphaValues[i] = angle;
                    ClValues[i]    = output.Cl;
                    CdValues[i]    = output.Cd;
                    CmValues[i]    = output.Cm;
                    LDValues[i]    = output.Cl * 0.1 / output.Cd;
                }
                else
                {
                    ClValues2[numPoints * 2 - 1 - i] = output.Cl;
                    CdValues2[numPoints * 2 - 1 - i] = output.Cd;
                    CmValues2[numPoints * 2 - 1 - i] = output.Cm;
                    LDValues2[numPoints * 2 - 1 - i] = output.Cl * 0.1 / output.Cd;
                }
            }

            GraphData data = new GraphData();

            data.xValues = AlphaValues;
            data.AddData(ClValues2, GUIColors.GetColor(0) * 0.5f, "Cl2", false);
            data.AddData(ClValues, GUIColors.GetColor(0), Localizer.Format("FARAbbrevCl"), true);
            data.AddData(CdValues2, GUIColors.GetColor(1) * 0.5f, "Cd2", false);
            data.AddData(CdValues, GUIColors.GetColor(1), Localizer.Format("FARAbbrevCd"), true);
            data.AddData(CmValues2, GUIColors.GetColor(2) * 0.5f, "Cm2", false);
            data.AddData(CmValues, GUIColors.GetColor(2), Localizer.Format("FARAbbrevCm"), true);
            data.AddData(LDValues2, GUIColors.GetColor(3) * 0.5f, "L/D2", false);
            data.AddData(LDValues, GUIColors.GetColor(3), Localizer.Format("FARAbbrevL_D"), true);

            data.exportdata.AddSizeVariables(_instantCondition, pitch, flapSetting, spoilers);
            data.exportdata.AddAoASweepXVariable(machNumber, AlphaValues);
            data.exportdata.AddYVariables(data);

            return(data);
        }
        public void LateUpdate()
        {
            if (!CompatibilityChecker.IsAllCompatible())
            {
                return;
            }

            FARAeroUtil.ResetEditorParts();
            FARBaseAerodynamics.GlobalCoLReady = false;

            if (EditorLogic.fetch)
            {
                if (editorGUI == null)
                {
                    editorGUI = new FAREditorGUI();
                    //editorGUI.LoadGUIParameters();
                    editorGUI.RestartCtrlGUI();
                }
                if (EditorLogic.startPod != null)
                {
                    var editorShip = FARAeroUtil.AllEditorParts;


                    if (FARAeroUtil.EditorAboutToAttach() && count++ >= 10)
                    {
                        EditorPartsChanged = true;
                        count = 0;
                    }

                    if (part_count_all != editorShip.Count || part_count_ship != EditorLogic.SortedShipList.Count || EditorPartsChanged)
                    {
                        FindPartsWithoutFARModel(editorShip);
                        for (int i = 0; i < editorShip.Count; i++)
                        {
                            Part p = editorShip[i];
                            for (int j = 0; j < p.Modules.Count; j++)
                            {
                                PartModule m = p.Modules[j];
                                if (m is FARBaseAerodynamics)
                                {
                                    (m as FARBaseAerodynamics).ClearShielding();
                                }
                            }
                        }

                        for (int i = 0; i < editorShip.Count; i++)
                        {
                            Part p = editorShip[i];
                            for (int j = 0; j < p.Modules.Count; j++)
                            {
                                PartModule m = p.Modules[j];
                                if (m is FARPartModule)
                                {
                                    (m as FARPartModule).ForceOnVesselPartsChange();
                                }
                            }
                        }
                        part_count_all     = editorShip.Count;
                        part_count_ship    = EditorLogic.SortedShipList.Count;
                        EditorPartsChanged = false;
                    }
                }
            }
        }