示例#1
0
        private static IEnumerable <bool> ComputeTrajectoryIncrement()
        {
            // create or update aerodynamic model
            if (aerodynamicModel_ == null || !aerodynamicModel_.IsValidFor(Trajectories.AttachedVessel.mainBody))
            {
                aerodynamicModel_ = AerodynamicModelFactory.GetModel(Trajectories.AttachedVessel.mainBody);
            }
            else
            {
                aerodynamicModel_.IncrementalUpdate();
            }

            // create new VesselState from vessel, or null if it's on the ground
            VesselState state = Trajectories.AttachedVessel.LandedOrSplashed ? null : new VesselState(Trajectories.AttachedVessel);

            // iterate over patches until MaxPatchCount is reached
            for (int patchIdx = 0; patchIdx < Settings.MaxPatchCount; ++patchIdx)
            {
                // stop if we don't have a vessel state
                if (state == null)
                {
                    break;
                }

                // If we spent more time in this calculation than allowed, pause until the next frame
                if (incrementTime_.ElapsedMilliseconds > MaxIncrementTime)
                {
                    yield return(false);
                }

                // if we have a patched conics solver, check for maneuver nodes
                if (null != Trajectories.AttachedVessel.patchedConicSolver)
                {
                    // search through maneuver nodes of the vessel
                    List <ManeuverNode> maneuverNodes = Trajectories.AttachedVessel.patchedConicSolver.maneuverNodes;
                    foreach (ManeuverNode node in maneuverNodes)
                    {
                        // if the maneuver node time corresponds to the end time of the last patch
                        if (node.UT == state.Time)
                        {
                            // add the velocity change of the burn to the velocity of the last patch
                            state.Velocity += node.GetBurnVector(CreateOrbitFromState(state));
                            break;
                        }
                    }

                    // Add one patch, then pause execution after every patch
                    foreach (bool result in AddPatch(state))
                    {
                        yield return(false);
                    }
                }

                state = AddPatch_outState;
            }
        }
示例#2
0
        public AeroForceCache(double maxCacheVelocity, double maxCacheAoA, double atmosphereDepth, int vRes, int aoaRes, int altRes, VesselAerodynamicModel model)
        {
            Model = model;

            this.MaxVelocity = maxCacheVelocity;
            this.MaxAoA = maxCacheAoA;
            this.MaxAltitude = atmosphereDepth;
            VelocityResolution = vRes;
            AoAResolution = aoaRes;
            AltitudeResolution = altRes;

            InternalArray = new Vector2[VelocityResolution, AoAResolution, AltitudeResolution];
            for (int v = 0; v < VelocityResolution; ++v)
                for (int a = 0; a < AoAResolution; ++a)
                    for (int m = 0; m < AltitudeResolution; ++m)
                        InternalArray[v, a, m] = new Vector2(float.NaN, float.NaN);
        }
示例#3
0
        private IEnumerable <bool> computeTrajectoryIncrement(Vessel vessel, DescentProfile profile)
        {
            if (aerodynamicModel_ == null || !aerodynamicModel_.isValidFor(vessel, vessel.mainBody))
            {
                aerodynamicModel_ = AerodynamicModelFactory.GetModel(vessel, vessel.mainBody);
            }
            else
            {
                aerodynamicModel_.IncrementalUpdate();
            }

            var state = vessel.LandedOrSplashed ? null : new VesselState(vessel);

            for (int patchIdx = 0; patchIdx < Settings.fetch.MaxPatchCount; ++patchIdx)
            {
                if (state == null)
                {
                    break;
                }

                if (incrementTime_.ElapsedMilliseconds > MaxIncrementTime)
                {
                    yield return(false);
                }

                if (null != vessel_.patchedConicSolver)
                {
                    var maneuverNodes = vessel_.patchedConicSolver.maneuverNodes;
                    foreach (var node in maneuverNodes)
                    {
                        if (node.UT == state.time)
                        {
                            state.velocity += node.GetBurnVector(createOrbitFromState(state));
                            break;
                        }
                    }
                    foreach (var result in AddPatch(state, profile))
                    {
                        yield return(false);
                    }
                }

                state = AddPatch_outState;
            }
        }
示例#4
0
        public AeroForceCache(double maxCacheVelocity, double maxCacheAoA, double atmosphereDepth, int vRes, int aoaRes, int altRes, VesselAerodynamicModel model)
        {
            Model              = model;
            MaxVelocity        = maxCacheVelocity;
            MaxAoA             = maxCacheAoA;
            MaxAltitude        = atmosphereDepth;
            VelocityResolution = vRes;
            AoAResolution      = aoaRes;
            AltitudeResolution = altRes;

            InternalArray = new Vector2d[VelocityResolution, AoAResolution, AltitudeResolution];
            for (int v = 0; v < VelocityResolution; ++v)
            {
                for (int a = 0; a < AoAResolution; ++a)
                {
                    for (int m = 0; m < AltitudeResolution; ++m)
                    {
                        InternalArray[v, a, m] = new Vector2d(double.NaN, double.NaN);
                    }
                }
            }
        }
        internal void ComputeTrajectory()
        {
            if (!VesselHasParts)// || AttachedVessel.LandedOrSplashed)
            {
                increment_time = 0d;
                Patches.Clear();
                return;
            }

            try
            {
                // start of trajectory calculation in current frame
                increment_time = Util.Clocks;

                // create or update aerodynamic model
                if (aerodynamicModel_ == null || !aerodynamicModel_.IsValidFor(AttachedVessel.mainBody))
                {
                    aerodynamicModel_ = AerodynamicModelFactory.GetModel(this, AttachedVessel.mainBody);
                }
                else
                {
                    aerodynamicModel_.UpdateVesselMass();
                }

                // if there is no ongoing partial computation, start a new one
                if (partialComputation_ == null)
                {
                    //total_time = Util.Clocks;

                    // restart the public buffers
                    patchesBackBuffer_.Clear();
                    maxAccelBackBuffer_ = 0;

                    // Create enumerator for Trajectory increment calculator
                    partialComputation_ = ComputeTrajectoryIncrement().GetEnumerator();
                }

                // we are finished when there are no more partial computations to be done
                bool finished = !partialComputation_.MoveNext();

                // when calculation is finished,
                if (finished)
                {
                    // swap the buffers for the patches and the maximum acceleration,
                    // "publishing" the results
                    List <Patch> tmp = Patches;
                    Patches            = patchesBackBuffer_;
                    patchesBackBuffer_ = tmp;

                    MaxAccel = maxAccelBackBuffer_;

                    // Reset partial computation
                    partialComputation_.Dispose();
                    partialComputation_ = null;

                    // how long did the whole calculation take?
                    //total_time = Util.ElapsedMilliseconds(total_time);
                }

                // how long did the calculation in this frame take?
                increment_time = Util.ElapsedMilliseconds(increment_time);
            }
            catch (Exception)
            {
                ++ErrorCount;
                throw;
            }
        }
示例#6
0
        private IEnumerable<bool> computeTrajectoryIncrement(Vessel vessel, DescentProfile profile)
        {
            if (aerodynamicModel_ == null || !aerodynamicModel_.isValidFor(vessel, vessel.mainBody))
                aerodynamicModel_ = AerodynamicModelFactory.GetModel(vessel, vessel.mainBody);
            else
                aerodynamicModel_.IncrementalUpdate();

            var state = vessel.LandedOrSplashed ? null : new VesselState(vessel);
            for (int patchIdx = 0; patchIdx < Settings.fetch.MaxPatchCount; ++patchIdx)
            {
                if (state == null)
                    break;

                if (incrementTime_.ElapsedMilliseconds > MaxIncrementTime)
                    yield return false;

                if (null != vessel_.patchedConicSolver)
                {
                    var maneuverNodes = vessel_.patchedConicSolver.maneuverNodes;
                    foreach (var node in maneuverNodes)
                    {
                        if (node.UT == state.time)
                        {
                            state.velocity += node.GetBurnVector(createOrbitFromState(state));
                            break;
                        }
                    }
                    foreach (var result in AddPatch(state, profile))
                        yield return false;
                }

                state = AddPatch_outState;
            }
        }
示例#7
0
        public void ComputeTrajectory(Vessel vessel)
        {
            patches_.Clear();

            vessel_ = vessel;

            if (vessel == null)
                return;

            if (aerodynamicModel_ == null || !aerodynamicModel_.isValidFor(vessel))
                aerodynamicModel_ = new VesselAerodynamicModel(vessel);
            else
                aerodynamicModel_.IncrementalUpdate();

            var state = vessel.LandedOrSplashed ? null : new VesselState(vessel);
            for (int patchIdx = 0; patchIdx < MaxPatchCount; ++patchIdx)
            {
                if (state == null)
                    break;
                state = AddPatch(state);
            }
        }