68 lines
2 KiB
Go
68 lines
2 KiB
Go
package engine
|
|
|
|
// Profile is an ordered chain of propagators executed sequentially. Each
|
|
// propagator picks up where the previous one finished.
|
|
type Profile struct {
|
|
// Stages are run in order. For Direction=Reverse they are still
|
|
// iterated from index 0 onwards but each propagator integrates with
|
|
// negative dt.
|
|
Stages []*Propagator
|
|
|
|
// Direction controls the sign of dt across the profile.
|
|
Direction Direction
|
|
|
|
// Globals are constraints evaluated alongside each stage's local
|
|
// Constraints. Useful for profile-wide bounds like "stop after N hours".
|
|
Globals []Constraint
|
|
}
|
|
|
|
// Run executes the profile from the given launch point. Returns one
|
|
// Result per executed stage, including any Fallback chains that were
|
|
// activated. The supplied EventSink is shared across stages and aggregates
|
|
// non-fatal observations.
|
|
//
|
|
// events may be nil; pass NewEventSink() to capture observations.
|
|
func (p *Profile) Run(t0 float64, launch State, events *EventSink) []Result {
|
|
if p.Direction == 0 {
|
|
p.Direction = Forward
|
|
}
|
|
|
|
results := make([]Result, 0, len(p.Stages))
|
|
t, s := t0, launch
|
|
|
|
for i := 0; i < len(p.Stages); i++ {
|
|
stage := p.Stages[i]
|
|
ctx := StageContext{
|
|
ProfileStart: t0,
|
|
PropagatorStart: t,
|
|
Launch: launch,
|
|
PropagatorState: s,
|
|
Direction: p.Direction,
|
|
}
|
|
res := stage.run(ctx, t, s, p.Globals, events)
|
|
results = append(results, res)
|
|
|
|
last := res.Points[len(res.Points)-1]
|
|
t = last.Time
|
|
s = State{Lat: last.Lat, Lng: last.Lng, Altitude: last.Altitude}
|
|
|
|
// Follow Fallback chains until none remains.
|
|
for res.Outcome == OutcomeFallback && stage.Fallback != nil {
|
|
stage = stage.Fallback
|
|
ctx = StageContext{
|
|
ProfileStart: t0,
|
|
PropagatorStart: t,
|
|
Launch: launch,
|
|
PropagatorState: s,
|
|
Direction: p.Direction,
|
|
}
|
|
res = stage.run(ctx, t, s, p.Globals, events)
|
|
results = append(results, res)
|
|
last = res.Points[len(res.Points)-1]
|
|
t = last.Time
|
|
s = State{Lat: last.Lat, Lng: last.Lng, Altitude: last.Altitude}
|
|
}
|
|
}
|
|
|
|
return results
|
|
}
|