Click or drag to resize

Segments

SegmentDefinitions are the fundamental type in the Segment Propagation Library. This topic explains what segments are, how they work, and other basic concepts. It also includes descriptions and examples for each type of segment provided by the library.

Note Note

The functionality described in this topic requires a license for the Segment Propagation Library.

Segments

Traditionally, propagation in STK Desktop usually involved setting up an object's initial conditions and then propagating until some time limit is hit. Although such tools and libraries are very useful, they may be too simple to model a vehicle's whole trajectory. There was no way to handle cases when the way the object is propagated needs to change.

For example, consider what it would take to propagate a satellite through an impulsive maneuver. There is a lot of plumbing and busy work you would need to do. First, you would propagate starting from your initial conditions, then determine the time of maneuver, which is the time at which you stop your initial propagation. Then you would take that final state, apply the maneuver, then propagate forward from that new state. Finally, you would have to manually stitch together the ephemeris, being careful about the discontinuity at the time of the maneuver.

Automating that kind of trajectory design is exactly what the Segment Propagation Library is for. You would first define a NumericalPropagatorSegment with a NumericalPropagatorDefinition and a StoppingCondition, then an ImpulsiveManeuverSegment with your delta-v and other maneuver information, and finally a second NumericalPropagatorSegment stopping at your desired event. Finally, you put them all into a SegmentList, propagate, and you get your final ephemeris out.

Note Note

Although the examples given in the documentation are for spacecraft, most of the segments can be used for any kind of propagation. See the Aircraft Propagation topic for information on propagating aircraft using the same concepts.

Types of Segments

The segment types included range from general base types to controlling the flow of segments to ones specific for satellite propagation forward or backward in time. If some part of your trajectory cannot be represented as one of these segments then you can extend the library to add to the capability yourself, or contact AGI to request the additional capability.

Each of these segment types are described in more detail in the Individual Segments section below.

The Segment Life Cycle

Segments follow the Create-Set-Call pattern like most of the rest of DME Component Libraries. After determining how to split your desired trajectory into segments, instantiate and configure each segment. Generally you will construct an overall SegmentList by adding each segment to the Segments list. Then, call GetSegmentListPropagator on the overall SegmentList, which returns a SegmentPropagator. When you call Propagate, all individual segments added to the list will be propagated in order. With a few exceptions, the final state of each segment will be used as the initial state of the next segment (except for the NumericalInitialStateSegment which defines its own initial state. FollowSegment can also be configured to ignore the previous segment's final state). Once propagation is finished, a SegmentResults is returned. When propagating a SegmentList, a SegmentListResults will be returned. The ephemeris for each segment can be accessed by calling GetDateMotionCollectionOfOverallTrajectory, and other information can be interrogated as well. In addition, the SegmentResults created by some segments (SegmentList, TargetedSegmentList, and NumericalPropagatorSegment) can be cast to a more specific type deriving from SegmentResults, as shown in later examples.

In order to change the configuration of your segments during propagation, such as to solve for a constrained trajectory or to enable or disable some elements, use a TargetedSegmentList instead of a SegmentList. TargetedSegmentLists, in addition to a list of segments, have a list of TargetedSegmentListOperators that will alter the configuration of the segments in a defined way.

One of the most common TargetedSegmentListOperators is the TargetedSegmentListDifferentialCorrector. This operator works by treating the computed trajectory as a multivariable function. Each segment that can be varied by the function solver has methods to aid in the creation of a SegmentPropagatorVariable to feed to the targeted segment list's differential corrector. Or, you can use a ParameterizedScalarVariable to control wrapped geometry types in the nested segments. Once the corrector is added to the TargetedSegmentList and everything is configured, propagation can commence just like the normal SegmentList. Function solvers will compute the trajectory, vary the variables, and recompute, iterating over and over again towards a goal.

Segment Adapters

Most segments require that you specify the identifications of the elements getting propagated and what ReferenceFrame, Axes, or object that the propagated values will be defined in, and a StateElementAdapterDefinition. When the SegmentPropagators are configured, the segment will take the previous segment's defined-in object (ReferenceFrame, Axes...) for each of that segment's elements. Having retrieved those values, the current segment will create an adapter that will perform the transformation of the final value of the previous segment at propagation time. These adapters are preserved in the SegmentResults as well.

All in all, this means that your segments do not all need to propagate in the same frame. If you are modeling a trajectory from the Earth to the Moon, you can break it up into two segments; the first in the Earth's inertial frame, and the second in the Moon's inertial frame. When you get the results for these two segments, the ephemeris for each individual segment will be in whatever frame you defined it in, but when you call GetDateMotionCollectionOfOverallTrajectory, you can specify the defined-in object to get the entire ephemeris in the desired frame or axes.

Note that many segments will handle the adapter configuration automatically. NumericalPropagatorSegment, for example, knows how to create adapters for all built in PropagationStateElements and AuxiliaryStateElements. SegmentList leverages its nested segments to create the adapters. Also, some segments that are used for control flow (such as ReturnSegment and StopSegment) are designed to use the previous segment's defined-in objects, since they themselves do not modify or propagate a state.

Individual Segments

InitialStateSegment

InitialStateSegment<T> is a segment that will have in its results a single state initialized from the InitialState property. You will need to configure the adapters on this segment by calling SetElementAndAdapter. It should only be used as the first segment to get propagated that isn't a SegmentList. Otherwise there will be a discontinuity, as the final state of the previous segment will be ignored by this segment.

Any InitialStateSegment<T> should be the first segment to get propagated (that is not a SegmentList or TargetedSegmentList). However, this segment is not required as long as one of the following is true:

This segment is the only segment that allows for the values in the initial state to be modified by a TargetedSegmentListOperator. See the Multivariable Function Solvers topic for more information.

The following code sample demonstrates how to configure a simple InitialStateSegment<T>:

C#
EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth;

SegmentList overallList = new SegmentList();

// create our initial state segment
InitialStateSegment<BasicState> initialStateSegment = new InitialStateSegment<BasicState>();

// define the state
BasicState initialState = new BasicState();
initialState.AddStateElementMotion(SatelliteMotionIdentification,
                                   new Motion<Cartesian>(new Cartesian(8000000, 0, 0),
                                                         new Cartesian(0, 5500, 5500)));
initialState.CurrentDate = TimeConstants.J2000;

initialStateSegment.InitialState = initialState;

// set the adapter and ReferenceFrame for this segment
initialStateSegment.SetElementAndAdapter(new ReferenceFrameAdapter(SatelliteMotionIdentification, earth.InertialFrame));

// create some propagate segment
PropagateSegment propagateSegment = CreateAndConfigurePropagateSegment();

// compose the segments together
overallList.Segments.Add(initialStateSegment);
overallList.Segments.Add(propagateSegment);

// propagate
SegmentListPropagator propagator = overallList.GetSegmentListPropagator(new EvaluatorGroup(), null);

SegmentListResults results = propagator.PropagateSegmentList();
BasicState firstPropagatedState = (BasicState)results.EntireComputedEphemeris[0];
// firstPropagateState will be the same as initialState

BasicLaunchSegment

BasicLaunchSegment is a segment that produces ephemeris in the configured CentralBody's fixed frame. The underlying physical model of this segment uses an ellipse approximating the trajectory in the central body's fixed frame from the launch position to the burnout position. This trajectory is then sampled for output via simple interpolation. The segment begins at the configured launch position and epoch. The launch position may be augmented with an optional initial acceleration. The segment ends at a configured burnout epoch (launch epoch plus time of flight) with the burnout position specified in the same frame as the launch position. The burnout velocity may be specified in either the fixed frame with a specified velocity magnitude, or in the inertial frame with a specified velocity magnitude, flight path angle, and azimuthal angle. In the fixed frame mode the flight path angle is zero and the inclination of the final state is determined by the arc between the launch and burnout states.

See BasicLaunchSegment for the complete set of options.

Some important remarks regarding this segment:

  • The state element adapter must be set.

  • The positions for both launch and burnout by default assume the CentralBody fixed frame. Both positions must be set in the same frame.

  • It is important to note that the burnout velocity can be specified in either fixed or inertial frames, irrespective of the frame used for the positions.

  • If the input states have information for orders greater than 0, this information is ignored.

  • This segment may produce warnings indicating potential issues when attempting to create an ellipse for interpolation. See the documentation for BasicLaunchSegmentResults for the types of warnings and their meanings.

The following code sample demonstrates how to configure a BasicLaunchSegment:

C#
EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth;

// Launch and burnout points. Higher order terms in the motion are ignored, and may be optionally computed by the propagator.
Cartesian launchLocation = earth.Shape.CartographicToCartesian(new Cartographic(Trig.DegreesToRadians(1.5), Trig.DegreesToRadians(7.0), 0));
Motion<Cartesian> launchMotion = new Motion<Cartesian>(launchLocation);
Cartesian burnoutLocation = earth.Shape.CartographicToCartesian(new Cartographic(Trig.DegreesToRadians(89), Trig.DegreesToRadians(47.0), 3000000));
Motion<Cartesian> burnoutMotion = new Motion<Cartesian>(burnoutLocation);
// Motion ID
string motionElementID = "LaunchMotion";

// Segment definition.
BasicLaunchSegment basicLaunchSegment = new BasicLaunchSegment(Duration.FromSeconds(60.0)); // 60 second step size.
basicLaunchSegment.SetElementAndAdapter(new ReferenceFrameAdapter(motionElementID, earth.FixedFrame)); // The input positions are in the Earth fixed frame.
basicLaunchSegment.CentralBody = earth;

// Launch state.
var launchState = new BasicState();
launchState.AddStateElementMotion(motionElementID, launchMotion);
launchState.CurrentDate = new GregorianDate(2017, 10, 3).ToJulianDate();
basicLaunchSegment.LaunchState = launchState;
basicLaunchSegment.MotionID = motionElementID;

// Burnout state.
var burnoutState = new BasicState();
burnoutState.AddStateElementMotion(motionElementID, burnoutMotion);
burnoutState.CurrentDate = launchState.CurrentDate.AddMinutes(10.0); // 600 seconds is the time of flight.
basicLaunchSegment.BurnoutState = burnoutState;
basicLaunchSegment.BurnoutVelocityFrame = SimpleAscentPropagatorBurnoutVelocityFrame.FixedFrame;
basicLaunchSegment.BurnoutVelocityMagnitude = 7299.76; // In SI units in the Earth's fixed frame.

SegmentPropagator launchPropagator = basicLaunchSegment.GetSegmentPropagator();
SegmentResults results = launchPropagator.Propagate();

// Cast the results to check the warnings property.
BasicLaunchSegmentResults resultsWithWarningsProperty = results as BasicLaunchSegmentResults;

NumericalInitialStateSegment

NumericalInitialStateSegment is an InitialStateSegment<T>: that will initialize its InitialState property from a NumericalPropagatorDefinition. Its adapters will be configured automatically for this segment.

The following code sample demonstrates how to configure a simple NumericalInitialStateSegment:

C#
SegmentList overallList = new SegmentList();

// create the segment
NumericalInitialStateSegment initialStateSegment = new NumericalInitialStateSegment();
initialStateSegment.Name = "Initial_State_Segment";

// for the NumericalInitialStateSegment, the initial state will be configured 
// with the initial values stored in a NumericalPropagatorDefinition
PropagationNewtonianPoint propagationPoint = CreatePropagatedNewtonianPoint(SatelliteMotionIdentification);
NumericalPropagatorDefinition numericalPropagator = CreateNumericalPropagator(propagationPoint);
initialStateSegment.PropagatorDefinition = numericalPropagator;
// adapters are configured automatically

// use the same NumericalPropagatorDefinition when configuring the propagate segment
NumericalPropagatorSegment propagationSegment = ConfigureNumericalPropagatorSegment(numericalPropagator, propagationPoint);

overallList.Segments.Add(initialStateSegment);
overallList.Segments.Add(propagationSegment);

// get the propagator and propagate
EvaluatorGroup group = new EvaluatorGroup();
SegmentPropagator segmentPropagator = overallList.GetSegmentPropagator(group);

SegmentResults propagationResults = segmentPropagator.Propagate();

PropagateSegment

This segment will take a StoppablePropagator, and propagate it forward or backward in time, stopping when one of its StoppingConditions is satisfied. The SegmentResults returned will be an instance of PropagateSegmentResults, and will include information regarding how propagation was stopped. You will need to configure the adapters on this segment by calling SetElementAndAdapter, however, some derived types will configure the elements and adapters automatically.

Normally this segment will propagate from the previous segment's final state. However, when there is no such segment before this one providing a final state, it will start from the initial state returned from GetInitialState. However, if that initial state is null, and no initial state passed into the propagate method, an exception will be thrown.

The thresholds of the StoppingConditions can be modified by a TargetedSegmentListOperator.

The following code sample demonstrates how to create a PropagateSegment with a StoppingCondition:

C#
// general settings
EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth;
Motion<Cartesian> initialConditions = new Motion<Cartesian>(new Cartesian(8000000, 0, 0),
                                                            new Cartesian(1500, 8500, 0));
JulianDate initialDate = TimeConstants.J2000;

// configure the wrapped stoppable propagator
TwoBodyStoppablePropagator twoBodyPropagator = new TwoBodyStoppablePropagator();
twoBodyPropagator.GravitationalParameter = WorldGeodeticSystem1984.GravitationalParameter;
twoBodyPropagator.PropagationFrame = earth.InertialFrame;
twoBodyPropagator.Step = Duration.FromMinutes(5.0);
twoBodyPropagator.PropagationPointIdentification = SatelliteMotionIdentification;
twoBodyPropagator.InitialDate = initialDate;
twoBodyPropagator.InitialMotion = initialConditions;

// make the segment
PropagateSegment propSegment = new PropagateSegment(twoBodyPropagator);

// add a stopping condition
propSegment.StoppingConditions.Add(new DurationStoppingCondition(Duration.FromHours(1.0)));

// configure the element and adapter on the propagator
propSegment.SetElementAndAdapter(new ReferenceFrameAdapter(SatelliteMotionIdentification,
                                                           earth.InertialFrame));

// get our propagator and propagate
SegmentPropagator propagator = propSegment.GetSegmentPropagator();
PropagateSegmentResults results = (PropagateSegmentResults)propagator.Propagate();

NumericalPropagatorSegment

This segment will take a NumericalPropagatorDefinition, and propagate it forward or backward in time, stopping when one of its StoppingConditions is satisfied. The adapters on this segment will be configured automatically.

Normally this segment will propagate from the previous segment's final state. However, when there is no such segment before this one providing a final state, it will start from the initial condition of its configured PropagatorDefinition.

The following code sample demonstrates how to create a NumericalPropagatorSegment with two StoppingConditions:

C#
// create the segment
NumericalPropagatorSegment propagatorSegment = new NumericalPropagatorSegment();
propagatorSegment.Name = "Propagator_Segment";

// create and add the NumericalPropagatorDefinition
PropagationNewtonianPoint propagationPoint = CreatePropagatedNewtonianPoint(SatelliteMotionIdentification);
NumericalPropagatorDefinition numericalPropagator = CreateNumericalPropagator(propagationPoint);
propagatorSegment.PropagatorDefinition = numericalPropagator;

// create and add a stopping condition
DurationStoppingCondition durationStop = new DurationStoppingCondition(Duration.FromDays(10));
durationStop.Name = "Duration_of_10days_Stopping_Condition";
propagatorSegment.StoppingConditions.Add(durationStop);

// create and add a second stopping condition
ScalarStoppingCondition altitudeStoppingCondition =
    new ScalarStoppingCondition(new ScalarCartographicElement(earth,
                                                              propagationPoint.IntegrationPoint,
                                                              CartographicElement.Height),
                                500000.0, // 500 km desired value
                                0.01, // 1 cm tolerance
                                StopType.AnyThreshold);
altitudeStoppingCondition.Name = "Altitude_Of_500km_Stopping_Condition";
propagatorSegment.StoppingConditions.Add(altitudeStoppingCondition);

// get the propagator and propagate
SegmentPropagator numericalSegmentPropagator = propagatorSegment.GetSegmentPropagator();
PropagateSegmentResults propagationResults = (PropagateSegmentResults)numericalSegmentPropagator.Propagate();

HoldSegment

This segment will create a ConstantStateStoppablePropagator, and propagate it forward or backward in time, stopping when one of its StoppingConditions is satisfied. You can configure the adapters on this segment by calling SetElementAndAdapter, to change the ReferenceFrame, Axes, or defined-in object of an element from what it was in the previous segment. However, if the state elements from the previous segment are already in the desired frame or axes, no adapter is needed.

This segment does not provide an initial state. It will throw an exception if no state is passed to the propagate method.

The following code sample demonstrates how to create a HoldSegment:

C#
EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth;
PropagateSegment firstSegment = CreateAndConfigurePropagateSegment();

// initially propagating in the inertial frame
firstSegment.SetElementAndAdapter(new ReferenceFrameAdapter(SatelliteMotionIdentification, earth.InertialFrame));

// stop when our range to our target is 0
ScalarStoppingCondition rangeOfZeroStoppingCondition = CreateRangeOfZeroStoppingCondition();
firstSegment.StoppingConditions.Add(rangeOfZeroStoppingCondition);

// hold our fixed position for 2 days
HoldSegment holdSegment = new HoldSegment();
holdSegment.Step = Duration.FromMinutes(3.0);
holdSegment.StoppingConditions.Add(new DurationStoppingCondition(Duration.FromDays(2)));
holdSegment.SetElementAndAdapter(new ReferenceFrameAdapter(SatelliteMotionIdentification, earth.FixedFrame));

SegmentList list = new SegmentList();
list.Segments.Add(firstSegment);
list.Segments.Add(holdSegment);

SegmentListPropagator propagator = list.GetSegmentListPropagator();

FollowSegment

With this segment, the initial and final state of propagation can be configured beyond the default behavior of the segments. This segment will take a StoppablePropagator, and then evaluate the segment's StartOfFollowSegment and EndOfFollowSegment, returning the propagated results in between. You will need to configure the adapters on this segment by calling SetElementAndAdapter. This segment can be useful if you have an ephemeris extended into the future and you want to perform a maneuver, but you don't know when.

Since the initial state of the segment may not use the final state of the previous segment, there can be a discontinuity in the results if this is not the first ephemeris producing segment.

The following code sample demonstrates how to create a FollowSegment:

C#
EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth;
string covarianceIdentification = "Covariance";

StkEphemerisFile ephemerisFile = GetEphemerisFile(); // get our ephemeris file

// configure our state with the ephemeris file data
GeometryDynamicState dynamicState = new GeometryDynamicState();
Point ephemerisLocationPoint = ephemerisFile.CreatePoint();
Covariance3By3DynamicMatrix covariance = new Covariance3By3DynamicMatrix(ephemerisFile.CreateCovarianceInterpolator());

dynamicState.SetElement(SatelliteMotionIdentification, ephemerisLocationPoint);
dynamicState.SetElement(covarianceIdentification, covariance);

// create the wrapped stoppable propagator
DynamicStateStoppablePropagator stoppablePropagator = new DynamicStateStoppablePropagator();
stoppablePropagator.DynamicState = dynamicState;

// create our segment
FollowSegment follow = new FollowSegment(stoppablePropagator);
// set our adapters
follow.SetElementAndAdapter(new ReferenceFrameAdapter(SatelliteMotionIdentification, earth.InertialFrame));
follow.SetElementAndAdapter(new SimpleAdapter<Matrix>(covarianceIdentification));

// create our stopping condition
DurationStoppingCondition stoppingCondition = new DurationStoppingCondition();
// we are going to run in a differential corrector where we control our stopping condition threshold
ParameterizedDurationVariable durationTripVariable =
    new ParameterizedDurationVariable(Duration.FromMinutes(30), 60, 1, follow);
stoppingCondition.Threshold = durationTripVariable.Value;
follow.StoppingConditions.Add(stoppingCondition);

// we know that we need to spend at least an hour in the parking orbit
follow.StartOfFollowSegment =
    new FollowSegmentStartsWithStoppingConditions(new DurationStoppingCondition(Duration.FromHours(1)));

// let the configured conditions end the propagation
follow.EndOfFollowSegment = new FollowSegmentEndsAsWithDefaultConditions();

// and after we stop the previous segment, perform a maneuver
ImpulsiveManeuverSegment impulsiveManeuver = new ImpulsiveManeuverSegment();
ImpulsiveManeuverInformation leaveParkingOrbit =
    new ImpulsiveManeuverInformation(SatelliteMotionIdentification,
                                     new Cartesian(1000, 0, 0),
                                     earth.InertialFrame.Axes);
impulsiveManeuver.Maneuver = leaveParkingOrbit;

// configure our overall list
TargetedSegmentList segmentList = new TargetedSegmentList();
segmentList.Segments.Add(follow);
segmentList.Segments.Add(impulsiveManeuver);
// add more segments

// configure our differential corrector
TargetedSegmentListDifferentialCorrector differentialCorrector = new TargetedSegmentListDifferentialCorrector();

// the constraint
ScalarAtEndOfSegmentConstraint trueAnomalyConstraint = new ScalarAtEndOfSegmentConstraint();

// we need to use the parameter in the constraint to create our point
ParameterizedOnStatePoint constraintPoint =
    new ParameterizedOnStatePoint(trueAnomalyConstraint.Parameter,
                                  earth.InertialFrame,
                                  SatelliteMotionIdentification);

// with the point, we can create our true anomaly
Scalar trueAnomalyScalarForConstraint =
    new ScalarModifiedKeplerianElement(WorldGeodeticSystem1984.GravitationalParameter,
                                       constraintPoint,
                                       KeplerianElement.TrueAnomaly,
                                       earth.InertialFrame);
trueAnomalyConstraint.Scalar = trueAnomalyScalarForConstraint;
trueAnomalyConstraint.DesiredValue = Trig.DegreesToRadians(180.0);
trueAnomalyConstraint.Segment = follow;
trueAnomalyConstraint.Settings.Tolerance = 0.0001;

// finish configuring our differential corrector
differentialCorrector.Constraints.Add(trueAnomalyConstraint);
differentialCorrector.Variables.Add(durationTripVariable);

// add the corrector to our targeted segment list
segmentList.Operators.Add(differentialCorrector);

// propagate
SegmentListPropagator propagator = segmentList.GetSegmentListPropagator();
SegmentListResults results = propagator.PropagateSegmentList();

ImpulsiveManeuverSegment

ImpulsiveManeuverSegment applies a change to the velocity of one or more Cartesian propagation elements in the state. This will result in a discontinuity in the velocity. Two ephemeris points are returned in its SegmentResults, one before the maneuver and one after the maneuver. The adapters on this segment will be configured automatically.

One concern about satellites performing maneuvers is that they may run out of fuel. By changing the InvalidFuelUseBehavior property on the particular maneuver information, you can control what will happen if the vehicle would run out of fuel during the maneuver. You can set it to throw an exception, to stop propagating, to perform only the amount of the maneuver possible, or to do the entire requested maneuver regardless of the fuel state. Regardless of which option is selected, the RanOutOfFuel property in the returned results will be set to true.

ImpulsiveManeuverInformation takes in the rocket's exhaust velocity in order to perform the fuel usage calculation. If instead you have the specific impulse of your rocket engine, you can generally calculate the exhaust velocity by multiplying the specific impulse by EarthSurfaceGravity

Every property except for the Orientation can be directly modified by a TargetedSegmentListOperator. Note that the Orientation can depend on the position and velocity of the spacecraft, but to do so you have to use the PropagationPoint included in the ImpulsiveManeuverInformation.

The following code sample demonstrates how to configure an ImpulsiveManeuverSegment by adding an ImpulsiveManeuverInformation:

C#
// create the segment
ImpulsiveManeuverSegment impulsiveManeuverSegment = new ImpulsiveManeuverSegment();
impulsiveManeuverSegment.Name = "Impulsive_Maneuver";

// create the maneuver information for the particular point element getting propagated 
ImpulsiveManeuverInformation maneuverInformation =
    new ImpulsiveManeuverInformation(SatelliteMotionIdentification,
                                     new Cartesian(103.2, 0.002, 1.02), // delta-v, meters/second
                                     null);
maneuverInformation.Orientation = new AxesVelocityOrbitNormal(maneuverInformation.PropagationPoint, earth);
impulsiveManeuverSegment.Maneuver = maneuverInformation;

// add the impulsive maneuver segment to a segment list (since the ImpulsiveManeuverSegment 
// can't be the first or only segment propagated)
someSegmentList.Segments.Add(impulsiveManeuverSegment);

// get the propagator and propagate
SegmentListPropagator propagator = someSegmentList.GetSegmentListPropagator();
SegmentListResults overallResults = propagator.PropagateSegmentList();

// get the specific results
SegmentResults temporaryResults = overallResults.GetResultsOfSegment(impulsiveManeuverSegment);
ImpulsiveManeuverSegmentResults impulsiveManeuverResults = (ImpulsiveManeuverSegmentResults)temporaryResults;

FiniteManeuverSegment

There are many times when an impulsive maneuver is not realistic enough. If you need an accurate simulation of a burn, or you want to model a low-thrust satellite, you will need to model them as finite maneuvers.

In order to accomplish this higher fidelity modeling, the Segment Propagation Library includes ContinuousThrustForceModel which can be used in conjunction with PropagationNewtonianPoint to model a thrust. This force model takes the thrust vector and adds it to the list of forces applied to the propagation point. You can configure it as follows:

C#
PropagationNewtonianPoint propagationPoint = CreatePropagatedNewtonianPoint(SatelliteMotionIdentification);
NumericalPropagatorDefinition basePropagator = CreateNumericalPropagator(propagationPoint);

PropagationScalar fuelMassScalar = new PropagationScalar(500); // start with 500 kg of fuel
fuelMassScalar.Identification = "Fuel Mass";

AuxiliaryStateScalar dryMass = new AuxiliaryStateScalar(500); // and 500 kg dry mass
dryMass.Identification = "Dry Mass";

propagationPoint.Mass = fuelMassScalar.IntegrationValue + dryMass.AuxiliaryScalar;

basePropagator.IntegrationElements.Add(fuelMassScalar);
basePropagator.AuxiliaryElements.Add(dryMass);

double nominalFuelFlow = -0.02; // kg/sec, negative because fuel will be consumed
ScalarFixed fuelFlowRateScalar = new ScalarFixed(nominalFuelFlow);

// set the derivative on the fuel mass propagation element
fuelMassScalar.ScalarDerivative = fuelFlowRateScalar;

double isp = 250; // seconds
Cartesian thrustDirection = new Cartesian(0, 0, 1); // unit vector
Vector thrustVector = ContinuousThrustForceModel.CreateIspThrustVector(isp, fuelFlowRateScalar, new AxesVelocityOrbitNormal(propagationPoint.IntegrationPoint), thrustDirection);

ContinuousThrustForceModel thrustForce = new ContinuousThrustForceModel(thrustVector, propagationPoint.IntegrationFrame.Axes);

propagationPoint.AppliedForces.Add(thrustForce);

Let's break this code down a little bit. First, we define our propagator and our PropagationNewtonianPoint. With those created, we configure our dry mass and fuel mass. After configuring the preceding items we create our thrust Vector using a helper method on ContinuousThrustForceModel. This helper method constructs a thrust vector based on the Tsiolkovsky rocket equation (it is easy to use any vector you desire). Finally, we create our force model, assign the vector, and add it to our point.

That is most of the work needed for successful propagation with a FiniteManeuverSegment. Now let's go over a more complete example of usage. In order for us to get a working example of this segment, we will first instantiate the setup segment, then create and apply stopping conditions, and finally execute propagation. Presented is a basic example; it is simple to add other stopping conditions, auto-sequences for the stopping conditions, and other propagation elements.

C#
FiniteManeuverSegment segment = new FiniteManeuverSegment();
segment.Name = "Finite Maneuver";
segment.PropagatorDefinition = basePropagator;

DurationStoppingCondition tenMinuteBurn = new DurationStoppingCondition(Duration.FromMinutes(10));
segment.StoppingConditions.Add(tenMinuteBurn);

// add a stopping condition to run out of fuel
StoppingCondition outOfFuelStoppingCondition = FiniteManeuverSegment.CreateOutOfFuelStoppingCondition(fuelMassScalar.IntegrationValue, "Out of Fuel", true);
segment.StoppingConditions.Add(outOfFuelStoppingCondition);

var propagator = segment.GetSegmentPropagator();
var results = propagator.Propagate();

If you are modeling a high energy maneuver that doesn't take too long, often you would like to start the burn before the end of the previous segment. For example, an impulsive maneuver at perigee makes sense to raise your orbit, but you often want the finite version of that maneuver to have its time centered on the perigee. The FiniteManeuverSegment lets you start the maneuver earlier in propagation by setting the BurnCenteringDuration as shown. The intent of this construct is that it will be set to the threshold of a DurationStoppingCondition. The value of BurnCenteringDuration will be evaluated at propagation time. That Duration will be halved and assigned the opposite sign of the direction of propagation (so if we are propagating backwards, a positive time will be used). Then a state will be generated by the most recent segment that propagated through that time, and that new state will be the initial state of the maneuver segment. The overall results of the previous segments will also be truncated to end at the evaluated time.

C#
InitialStateSegment<BasicState> initialState = ConfigureInitialStateSegment();
PropagateSegment initialPropagation = CreateAndConfigurePropagateSegment();

FiniteManeuverSegment finiteManeuverSegment = BasicFiniteManeuver();

DurationStoppingCondition durationCondition = new DurationStoppingCondition(Duration.FromMinutes(5.0));
finiteManeuverSegment.StoppingConditions.Add(durationCondition);
finiteManeuverSegment.BurnCenteringDuration = durationCondition.Threshold;

PropagateSegment finalPropagation = CreateAndConfigurePropagateSegment();

SegmentList mcs = new SegmentList();
mcs.Segments.Add(initialState);
mcs.Segments.Add(initialPropagation);
mcs.Segments.Add(finiteManeuverSegment);
mcs.Segments.Add(finalPropagation);

SegmentListResults results = mcs.GetSegmentListPropagator().PropagateSegmentList();
PropagateSegmentResults firstPropagateSegmentResults = (PropagateSegmentResults)results.GetResultsOfSegment(initialPropagation);
FiniteManeuverSegmentResults maneuverResults = (FiniteManeuverSegmentResults)results.GetResultsOfSegment(finiteManeuverSegment);

Occasionally, it is useful to fix your thrust vector to what it was at a specific time. For example, maybe your spacecraft has guidance systems that hold its orientation constant during a burn as opposed to adjusting attitude. In a situation such as this, the AxesFixedAtJulianDate should be used for the burn axes. These axes will hold an orientation at a specific time. This time of fixation does not have to be known until the propagator is run. To further illustrate this example, let's complicate the scenario to imagine using burn centering. The fixation time in this more complicated case can be set to a parameter that gets evaluated at propagation time.

To choose when the segment that was previous to the finite maneuver ends and when the engine is actually ignited, you can construct a parameter from the IgnitionState or PropagationStartState state parameters on the FiniteManeuverSegment.

C#
FiniteManeuverSegment segment = new FiniteManeuverSegment();
segment.Name = "Finite Maneuver";

// CreatePropagatedNewtonianPoint also creates fuel and dry mass elements
PropagationNewtonianPoint propagationPoint = CreatePropagatedNewtonianPoint(SatelliteMotionIdentification);
NumericalPropagatorDefinition basePropagator = CreateNumericalPropagator(propagationPoint);
segment.PropagatorDefinition = basePropagator;

PropagationScalar fuelMassElement = ConfigureDefaultMassesAndReturnFuelElement(propagationPoint, basePropagator, 500, 500);

double nominalFuelFlow = -0.02; // kg/sec, negative because fuel will be consumed
ScalarFixed fuelFlowRateScalar = new ScalarFixed(nominalFuelFlow);
fuelMassElement.ScalarDerivative = fuelFlowRateScalar;

double isp = 250; // seconds
Cartesian thrustDirection = new Cartesian(0, 0, 1); // unit vector
AxesVelocityOrbitNormal axesThatWillGetFixed = new AxesVelocityOrbitNormal(propagationPoint.IntegrationPoint);
AxesFixedAtJulianDate axesFixedAtEngineIgnition = new AxesFixedAtJulianDate(axesThatWillGetFixed, new TimeFromStateValueDefinition(segment.IgnitionState));
Vector thrustVector = ContinuousThrustForceModel.CreateIspThrustVector(isp, fuelFlowRateScalar, axesFixedAtEngineIgnition, thrustDirection);

ContinuousThrustForceModel thrustForce = new ContinuousThrustForceModel(thrustVector, propagationPoint.IntegrationFrame.Axes);

propagationPoint.AppliedForces.Add(thrustForce);

StoppingCondition tenMinuteBurn = new DurationStoppingCondition(Duration.FromMinutes(10.0));
segment.StoppingConditions.Add(tenMinuteBurn);

// add a stopping condition to run out of fuel
StoppingCondition outOfFuelStoppingCondition = FiniteManeuverSegment.CreateOutOfFuelStoppingCondition(fuelMassElement.IntegrationValue, "Out of Fuel", true);
segment.StoppingConditions.Add(outOfFuelStoppingCondition);

var propagator = segment.GetSegmentPropagator();
var results = propagator.Propagate();

You can construct your ThrustVector with any of DME Component Libraries geometry types. To demonstrate how flexible the system is, we are going to create a Scalar that will allow you to change the thrust direction, and then use this to zero out the inclination of an orbit with a low thrust engine.

First, we create our Scalar. This scalar will return 1 or negative 1 based on the Z component of the passed in vector. This scalar will also scale down a little as the Z component of the vector becomes small.

C#
public class ScalarSwitchingOnVelocityVector : Scalar
{
    public ScalarSwitchingOnVelocityVector()
    {
    }

    public ScalarSwitchingOnVelocityVector(Vector vector)
    {
        m_vector = vector;
    }

    protected ScalarSwitchingOnVelocityVector(ScalarSwitchingOnVelocityVector existingInstance, CopyContext context)
        : base(existingInstance, context)
    {
        m_vector = context.UpdateReference(existingInstance.m_vector);
    }

    public override object Clone(CopyContext context)
    {
        return new ScalarSwitchingOnVelocityVector(this, context);
    }

    protected override bool CheckForSameDefinition(Scalar other)
    {
        var o = other as ScalarSwitchingOnVelocityVector;
        return o != null &&
               AreSameDefinition(m_vector, o.m_vector) &&
               CheckForSameDefinition(o);
    }

    protected virtual bool CheckForSameDefinition(ScalarSwitchingOnVelocityVector other)
    {
        return other != null && other.GetType() == typeof(ScalarSwitchingOnVelocityVector);
    }

    protected override int ComputeCurrentDefinitionHashCode()
    {
        return HashCode.Combine(typeof(ScalarSwitchingOnVelocityVector).GetHashCode(),
                                base.ComputeCurrentDefinitionHashCode(),
                                GetDefinitionHashCode(m_vector));
    }

    public override void EnumerateDependencies(DependencyEnumerator enumerator)
    {
        base.EnumerateDependencies(enumerator);
        enumerator.Enumerate(m_vector);
    }

    public override ScalarEvaluator GetEvaluator(EvaluatorGroup group)
    {
        if (group == null)
            throw new ArgumentNullException("group");

        PropertyInvalidException.ValidateNonNull(m_vector, "Vector");

        return group.CreateEvaluator<ScalarEvaluator>(CreateEvaluator);
    }

    private ScalarEvaluator CreateEvaluator(EvaluatorGroup group)
    {
        return new Evaluator(group, m_vector.GetEvaluator(group));
    }

    public Vector Vector
    {
        get { return m_vector; }
        set
        {
            ThrowIfFrozen();
            m_vector = value;
        }
    }

    private Vector m_vector;

    private sealed class Evaluator : ScalarEvaluator
    {
        public Evaluator(EvaluatorGroup group, VectorEvaluator evaluator)
            : base(group)
        {
            m_evaluator = evaluator;
        }

        private Evaluator(Evaluator existingInstance, CopyContext context)
            : base(existingInstance, context)
        {
            m_evaluator = existingInstance.m_evaluator;
            UpdateEvaluatorReferences(context);
        }

        public override object Clone(CopyContext context)
        {
            return new Evaluator(this, context);
        }

        protected override void Dispose(bool disposing)
        {
            if (m_isDisposed || !disposing)
                return;

            m_isDisposed = true;
            m_evaluator.Dispose();
        }

        public override bool IsThreadSafe
        {
            get { return false; }
        }

        public override void UpdateEvaluatorReferences(CopyContext context)
        {
            m_evaluator = context.UpdateReference(m_evaluator);
        }

        public override TimeIntervalCollection GetAvailabilityIntervals(TimeIntervalCollection consideredIntervals)
        {
            return m_evaluator.GetAvailabilityIntervals(consideredIntervals);
        }

        public override bool IsAvailable(JulianDate date)
        {
            return m_evaluator.IsAvailable(date);
        }

        public override bool IsTimeVarying
        {
            get { return m_evaluator.IsTimeVarying; }
        }

        public override Motion<double> Evaluate(JulianDate date, int order)
        {
            var motion = m_evaluator.Evaluate(date, order + 1);

            double value = motion.Value.Z;
            if (value == 0)
            {
                return new Motion<double>(0);
            }

            // throttle down as our Z speed gets low
            double multiple = -1;
            if (Math.Abs(value) < 10)
            {
                multiple = multiple * value * 0.1;
            }

            return new Motion<double>(multiple * Math.Sign(value));
        }

        private bool m_isDisposed;
        private VectorEvaluator m_evaluator;
    }
}

We begin by defining the initial conditions and setting up the basic types that we will use.

C#
double earthGm = WorldGeodeticSystem1984.GravitationalParameter;
Motion<Cartesian> initialConditions = new ModifiedKeplerianElements(17000000, 1.0 / 17200000.0, Trig.DegreesToRadians(23),
                                                                    0, 0, Trig.DegreesToRadians(5), earthGm).ToCartesian();

PropagationNewtonianPoint propagationPoint = CreatePropagatedNewtonianPoint(SatelliteMotionIdentification, initialConditions);
NumericalPropagatorDefinition basePropagator = CreateNumericalPropagator(propagationPoint);

double initialActualFuelMass = 5000;
double initialDryMass = 1000;
PropagationScalar fuelMassElement = ConfigureDefaultMassesAndReturnFuelElement(propagationPoint, basePropagator, initialActualFuelMass, initialDryMass);

ScalarStoppingCondition outOfFuelStoppingCondition = new ScalarStoppingCondition(fuelMassElement.IntegrationValue, 0.00000001, 0.000000001,
                                                                                 StopType.ThresholdDecreasing);
outOfFuelStoppingCondition.Enabled = StoppingConditionEnabled.Enabled;
ScalarFixed fuelFlow = new ScalarFixed(-0.005);
fuelMassElement.ScalarDerivative = fuelFlow;

The fuel flow code is similar to the previous example.

C#
PropagationScalar fuelMassScalar = new PropagationScalar(fuelMass); 
fuelMassScalar.Identification = "Fuel Mass";

AuxiliaryStateScalar dryMassScalar = new AuxiliaryStateScalar(dryMass);
dryMassScalar.Identification = "Dry Mass";
propagationPoint.Mass = fuelMassScalar.IntegrationValue + dryMassScalar.AuxiliaryScalar;

basePropagator.IntegrationElements.Add(fuelMassScalar);
basePropagator.AuxiliaryElements.Add(dryMassScalar);

Now we make our thrust force model. It is very similar to the previous examples; the only interesting difference is that we are multiplying our thrust vector by an instance of the switching scalar.

C#
// create the continuous thrust force model
ContinuousThrustForceModel thrust = new ContinuousThrustForceModel();
thrust.IntegrationAxes = propagationPoint.IntegrationFrame.Axes;

// use the constant thrust/isp thrust vector
double isp = 1000;
Vector thrustVector = ContinuousThrustForceModel.CreateIspThrustVector(isp,
                                                                       fuelFlow,
                                                                       propagationPoint.IntegrationFrame.Axes,
                                                                       new Cartesian(0, 0, 1)); // thrust along the negative Z
thrust.ThrustVector = thrustVector;

Vector velocityVector = new VectorVelocity(propagationPoint.IntegrationPoint, propagationPoint.IntegrationFrame);

ScalarSwitchingOnVelocityVector switchingScalar = new ScalarSwitchingOnVelocityVector(velocityVector);
thrust.ThrustVector = thrustVector * switchingScalar; // switch the thrust back and forth

propagationPoint.AppliedForces.Add(thrust);

Finally we create our segment, stopping conditions, and propagate.

C#
FiniteManeuverSegment segment = new FiniteManeuverSegment();
segment.PropagatorDefinition = basePropagator;

// a time condition just in case
segment.StoppingConditions.Add(new DurationStoppingCondition(Duration.FromDays(10.0)));

// don't forget the out of fuel stopping condition we made
segment.StoppingConditions.Add(outOfFuelStoppingCondition);

// don't keep going once we've hit our flat orbit
ScalarStoppingCondition inclinationStoppingCondition = new ScalarStoppingCondition(new ScalarModifiedKeplerianElement(earthGm,
                                                                                                                      propagationPoint.IntegrationPoint,
                                                                                                                      KeplerianElement.Inclination,
                                                                                                                      propagationPoint.IntegrationFrame),
                                                                                   0,
                                                                                   Trig.DegreesToRadians(0.05),
                                                                                   StopType.AnyThreshold);
segment.StoppingConditions.Add(inclinationStoppingCondition);

SegmentList list = new SegmentList();
list.Segments.Add(segment);

Note that because we are not trying to line up when our inclination is 0 with when the satellite crosses the equator, we won't get a final inclination that is exactly zero, but it will be very close.

Zero Inclination Example

SwitchableSegment

There will be times when you might want to change the segment you are propagating in a TargetedSegmentList>. For example, maybe you want to swap out a low fidelity propagate segment with a SegmentList containing a higher fidelity propagator. The SwitchableSegment construct coupled with a SwapSegmentOperator lets you perform this operation.

C#
TargetedSegmentList mcs = new TargetedSegmentList();

PropagateSegment propagateWithoutManeuver = CreateAndConfigurePropagateSegment();
FiniteManeuverSegment propagateWithManeuver = BasicFiniteManeuver();

SwitchableSegment overallManeuverSegment = new SwitchableSegment(propagateWithManeuver, propagateWithoutManeuver);
PropagateSegment propagateSomeMore = CreateAndConfigurePropagateSegment();

mcs.Segments.Add(overallManeuverSegment);
mcs.Segments.Add(propagateSomeMore);

TargetedSegmentListDifferentialCorrector firstDifferentialCorrector = CreateDifferentialCorrector1(propagateWithoutManeuver, propagateWithoutManeuver);

SwapSegmentOperator swapSegmentOperator = new SwapSegmentOperator(overallManeuverSegment);

TargetedSegmentListDifferentialCorrector secondDifferentialCorrector = CreateDifferentialCorrector2(propagateWithManeuver, propagateWithManeuver);

mcs.Operators.Add(firstDifferentialCorrector);
mcs.Operators.Add(swapSegmentOperator);
mcs.Operators.Add(secondDifferentialCorrector);

You will need to specify one of the segments as the primary segment. The primary segment determines how the final ephemeris for the SwitchableSegment will be reported, by determining the segment's ReferenceFrame and Axes used for the report. If you inspect the OriginalResults property, you will get the ephemeris in the frames and axes as defined in that segment. In a typical configuration, the PrimarySegment is the segment that the SwitchableSegment will get switched to, and the AlternateSegment is the segment that is initially propagated.

A more concrete example of the use of a SwitchableSegment is with the SeedFiniteManeuverOperator. This operator will configure several settings on a FiniteManeuverSegment based on an ImpulsiveManeuverSegment that was initially run.

C#
TargetedSegmentList mcs = new TargetedSegmentList();
PropagateSegment propToSomePoint = CreateAndConfigurePropagateSegment();

ImpulsiveManeuverSegment impulsiveManeuver = CreateFirstManeuver();

ImpulsiveManeuverInformation impulsiveManeuverInformation = new ImpulsiveManeuverInformation(SatelliteMotionIdentification, new Cartesian(0, 0, 100));
impulsiveManeuverInformation.Orientation = earth.InertialFrame.Axes;
impulsiveManeuver.Maneuver = impulsiveManeuverInformation;

durationStoppingCondition.Threshold = new ParameterizedValueDefinition<Duration>();

SwitchableSegment overallManeuverSegment = new SwitchableSegment(finiteManeuver, impulsiveManeuver);
PropagateSegment propagateSomeMore = CreateAndConfigurePropagateSegment();

mcs.Segments.Add(propToSomePoint);
mcs.Segments.Add(overallManeuverSegment);
mcs.Segments.Add(propagateSomeMore);

TargetedSegmentListDifferentialCorrector firstDifferentialCorrector = CreateDifferentialCorrector1(impulsiveManeuver, impulsiveManeuver);

SeedFiniteManeuverOperator seedManeuverOperator = new SeedFiniteManeuverOperator(overallManeuverSegment, SatelliteMotionIdentification);
seedManeuverOperator.FuelFlowRateScalar = fuelFlowRate;
seedManeuverOperator.StoppingConditionToUpdate = durationStoppingCondition;

TargetedSegmentListDifferentialCorrector secondDifferentialCorrector = CreateDifferentialCorrector2(finiteManeuver, finiteManeuver);

mcs.Operators.Add(firstDifferentialCorrector);
mcs.Operators.Add(seedManeuverOperator);
mcs.Operators.Add(secondDifferentialCorrector);

SegmentList

SegmentList is a container of multiple segments. It is a segment itself, so one SegmentList can contain another SegmentList. When propagated, it returns a SegmentResults that you may cast to a SegmentListResults in order to get additional information, such as the time interval of each segment and results of each individual segment. The adapters do not need to be set; they will be initialized from the nested segments. Remember that the order of the segments in Segments is important.

The following code sample demonstrates how to populate the Segments list and propagate the overall SegmentList:

C#
// make up a bunch of segments
NumericalInitialStateSegment initialSegment = ConfigureNumericalInitialStateSegment();
NumericalPropagatorSegment propagateSegment = ConfigureNumericalPropagatorSegment();
ImpulsiveManeuverSegment maneuverSegment = ConfigureImpulsiveManeuver();
NumericalPropagatorSegment finalPropagateSegment = ConfigureNumericalPropagatorSegment();
SegmentList someOtherSegmentList = new SegmentList();
someOtherSegmentList.Name = "Some_Other_Segment_List";

// create the SegmentList you will propagate
SegmentList mainSegmentList = new SegmentList();
mainSegmentList.Name = "Main_Segment_List";

// add the segments in order
mainSegmentList.Segments.Add(initialSegment);
mainSegmentList.Segments.Add(propagateSegment);

someOtherSegmentList.Segments.Add(maneuverSegment); // nest the maneuver in an inner SegmentList

mainSegmentList.Segments.Add(someOtherSegmentList); // go ahead and put one SegmentList in another
mainSegmentList.Segments.Add(finalPropagateSegment);

// get the propagator and propagate
SegmentListPropagator segmentListPropagator = mainSegmentList.GetSegmentListPropagator();
SegmentListResults segmentListResults = segmentListPropagator.PropagateSegmentList();

// SegmentListResults will recursively search for a specific segments results
SegmentResults maneuverResults = segmentListResults.GetResultsOfSegment(maneuverSegment);

TargetedSegmentList

TargetedSegmentList is a SegmentList that also has one or more TargetedSegmentListOperators. The segments included in the TargetedSegmentList will have some part of its segments modified by the operators. These modifications can change values of settings in the segments to solve for a particular trajectory, or turn some option on or off. See the Targeted Segment List Operators topic for more information.

Configuring a TargetedSegmentList is the same as configuring a normal SegmentList, but also requires that you configure at least one TargetedSegmentListOperator. See the Targeted Segment List Operators topic for examples to how to configure and use TargetedSegmentListOperators and TargetedSegmentList.

UpdateSegment

UpdateSegment allows you to directly edit the state from the previous segment. The adapters do not need to be set. Often editing the state is done with a callback that will modify a value in the state. For example, if you wanted to decrease the fuel mass, the following code sample demonstrates how to do so:

C#
UpdateSegment updateSegment = new UpdateSegment();

// we will vary the fuel mass to target a final overall mass
ParameterizedScalarVariable variable = new ParameterizedScalarVariable(100, 1, 0.1, updateSegment);

// configure the updater
SingleValueStateUpdater fuelMassUpdater =
    new SingleValueStateUpdater(variable.Value,
                                (state, updateValue) =>
                                {
                                    // update the state by subtracting the value of the update value from the fuel mass
                                    state.ModifyValue(fuelMassID, state.GetValue<double>(fuelMassID) - updateValue);
                                    return state;
                                });

// you can have as many updaters as you would like
updateSegment.Updates.Add(fuelMassUpdater);

// configure our overall segment list
TargetedSegmentList targetedSegmentList = new TargetedSegmentList();
targetedSegmentList.Segments.Add(initialStateSegment); // made earlier
targetedSegmentList.Segments.Add(updateSegment);

TargetedSegmentListDifferentialCorrector differentialCorrector = new TargetedSegmentListDifferentialCorrector();
// we want our overall mass to be 850 kg
DelegateBasedConstraint overallMassConstraint =
    new DelegateBasedConstraint(s => s.StateForNextSegment.GetValue<double>(fuelMassID) +
                                     s.StateForNextSegment.GetValue<double>(dryMassID),
                                updateSegment,
                                850,
                                0.1);

// finish configuring our differential corrector
differentialCorrector.Constraints.Add(overallMassConstraint);
differentialCorrector.Variables.Add(variable);

// add the operator
targetedSegmentList.Operators.Add(differentialCorrector);

// propagate
SegmentListPropagator propagator = targetedSegmentList.GetSegmentListPropagator();
SegmentListResults results = propagator.PropagateSegmentList();
SegmentResults updateSegmentResults = results.SegmentResults[1];
double finalMass = updateSegmentResults.StateForNextSegment.GetValue<double>(fuelMassID) +
                   updateSegmentResults.StateForNextSegment.GetValue<double>(dryMassID);
// will be 850

ReturnSegment

ReturnSegment is a segment that will end propagation of a specified SegmentList if enabled. This segment can also distinguish between running as part of normal propagation, or if it is being run as part of a TargetedSegmentListOperator and be enabled or disabled depending on which content it is being propagated.

The related ChangeReturnSegmentOperator type is a TargetedSegmentListOperator that can change the Behavior property of a ReturnSegment.

Generally, a ReturnSegment can end any SegmentList that it is in, however, there is one notable exception. If a ReturnSegment is in a TargetedSegmentList, it can not return out to a SegmentList that is outside of the TargetedSegmentList while the TargetedSegmentList is running a ChangeReturnSegmentOperator.

The following code sample demonstrates using a ReturnSegment:

C#
// define constants
string satelliteName = "Satellite";
EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth;

// make the segment list (create the differential corrector too)
TargetedSegmentList segmentList = CreateTargetedSegmentList();

// initial state
NumericalInitialStateSegment initialStateSegment = ConfigureNumericalInitialStateSegment();
ImpulsiveManeuverSegment firstManeuver = CreateFirstManeuver();

// make the propagation segment
// we will need the integration point to make the altitude stopping condition
PropagationNewtonianPoint propagationPoint = CreatePropagatedNewtonianPoint(satelliteName);
NumericalPropagatorSegment propagationSegment = new NumericalPropagatorSegment();
propagationSegment.PropagatorDefinition = CreateNumericalPropagator(propagationPoint);

// make a stopping condition
ScalarStoppingCondition altitudeStoppingCondition = new ScalarStoppingCondition(
    new ScalarCartographicElement(earth, propagationPoint.IntegrationPoint, CartographicElement.Height),
    420000000, // 42,000 kilometers
    1,         // stop within a meter
    StopType.AnyThreshold); 
propagationSegment.StoppingConditions.Add(altitudeStoppingCondition);

// if the satellite goes above 42 000 km, then we don't want to do the second maneuver
ReturnSegment stopIfAltitudeIsTooLow = new ReturnSegment(segmentList, ReturnSegmentBehavior.Enabled);
propagationSegment.SetStoppingConditionAutoSegment(altitudeStoppingCondition, stopIfAltitudeIsTooLow, 1);

// or our orbit might still be too low in which case we want to do another maneuver
StoppingCondition anotherStoppingCondition = CreateSomeOtherStoppingCondition();
propagationSegment.StoppingConditions.Add(anotherStoppingCondition);

ImpulsiveManeuverSegment impulsiveManeuver = CreateSecondManeuver();

// configure the segment list
segmentList.Segments.Add(initialStateSegment);
segmentList.Segments.Add(firstManeuver);
segmentList.Segments.Add(propagationSegment);
segmentList.Segments.Add(impulsiveManeuver);

StopSegment

StopSegment is a segment that will stop all propagation, if enabled. This can be very useful to use with an auto-sequence, configured by calling SetStoppingConditionAutoSegment, where you know that propagation should not continue if a particular StoppingCondition is satisfied.

If the StopSegment is enabled, propagation will stop the very first time the segment is propagated. This includes when being run as part of a TargetedSegmentListOperator.

The related ChangeStopSegmentOperator type is a TargetedSegmentListOperator that can change the StopEnabled property of a StopSegment.

The following code sample demonstrates using a StopSegment:

C#
// define constants
string satelliteName = "Satellite";
EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth;

// make the segment list
SegmentList segmentList = new SegmentList();

// initial state
NumericalInitialStateSegment initialStateSegment = ConfigureNumericalInitialStateSegment();

// make the propagation segment
// we will need the integration point to make the altitude stopping condition
PropagationNewtonianPoint propagationPoint = CreatePropagatedNewtonianPoint(satelliteName);
NumericalPropagatorSegment propagationSegment = new NumericalPropagatorSegment();
propagationSegment.PropagatorDefinition = CreateNumericalPropagator(propagationPoint);

// make a stopping condition
ScalarStoppingCondition altitudeStoppingCondition = new ScalarStoppingCondition(
    new ScalarCartographicElement(earth, propagationPoint.IntegrationPoint, CartographicElement.Height),
    100000, // 100 kilometers
    1,      // stop within a meter
    StopType.ThresholdDecreasing); // the satellite won't come back up
propagationSegment.StoppingConditions.Add(altitudeStoppingCondition);

// if the satellite goes below 100 km, then stop propagation
StopSegment stopIfAltitudeIsTooLow = new StopSegment(true);
propagationSegment.SetStoppingConditionAutoSegment(altitudeStoppingCondition, stopIfAltitudeIsTooLow, 1);

// or our orbit might not reenter in which case we want to continue propagating another segment.
StoppingCondition anotherStoppingCondition = CreateSomeOtherStoppingCondition();
propagationSegment.StoppingConditions.Add(anotherStoppingCondition);

// if we don't stop, this segment will propagate after the previous propagation segment finishes
NumericalPropagatorSegment someOtherPropagationSegment = ConfigureNumericalPropagatorSegment();

// configure the segment list
segmentList.Segments.Add(initialStateSegment);
segmentList.Segments.Add(propagationSegment);
segmentList.Segments.Add(someOtherPropagationSegment);