Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: make the propagator maintain the frame and size of the input State #246

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <OpenSpaceToolkit/Astrodynamics/Trajectory/Orbit/Model.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Trajectory/State.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Trajectory/State/NumericalSolver.hpp>
#include <OpenSpaceToolkit/Astrodynamics/Trajectory/StateBuilder.hpp>

namespace ostk
{
Expand All @@ -55,6 +56,7 @@ using ostk::physics::time::Instant;
using ostk::astro::trajectory::state::NumericalSolver;
using ostk::astro::EventCondition;
using ostk::astro::trajectory::State;
using ostk::astro::trajectory::StateBuilder;
using ostk::astro::Dynamics;
using ostk::astro::flight::system::SatelliteSystem;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ using ostk::physics::units::Time;

static const Derived::Unit GravitationalParameterSIUnit =
Derived::Unit::GravitationalParameter(Length::Unit::Meter, Time::Unit::Second);
static const Shared<const Frame> gcrfSPtr = Frame::GCRF();

Propagated::Propagated(const Propagator& aPropagator, const State& aState)
: Model(),
Expand Down Expand Up @@ -140,6 +139,9 @@ Array<State> Propagated::calculateStatesAt(const Array<Instant>& anInstantArray)
}
}

// Builder for output states based on cached array
StateBuilder outputStateBuilder = {this->cachedStateArray_.accessFirst()};

Array<State> allStates = Array<State>::Empty();

// Maintain counter separately so as to only iterate once through instant array
Expand Down Expand Up @@ -213,12 +215,12 @@ Array<State> Propagated::calculateStatesAt(const Array<Instant>& anInstantArray)
(forwardStates[k].accessCoordinates() * forwardWeight +
backwardStates[k].accessCoordinates() * backwardWeight);

averagedStates.add({
instants[k],
coordinates,
gcrfSPtr,
propagator_.accessCoordinatesBroker(),
});
averagedStates.add(
outputStateBuilder.build(
instants[k],
coordinates
)
);
}

allStates.add(averagedStates);
Expand Down
65 changes: 38 additions & 27 deletions src/OpenSpaceToolkit/Astrodynamics/Trajectory/Propagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,21 @@ State Propagator::calculateStateAt(const State& aState, const Instant& anInstant
throw ostk::core::error::runtime::Undefined("Propagator");
}

const State state = {
aState.accessInstant(),
aState.inFrame(Propagator::IntegrationFrameSPtr).extractCoordinates(this->coordinatesBrokerSPtr_->getSubsets()),
Propagator::IntegrationFrameSPtr,
this->coordinatesBrokerSPtr_,
};
const StateBuilder solverStateBuilder = {Propagator::IntegrationFrameSPtr, coordinatesBrokerSPtr_};

const State solverInputState = solverStateBuilder.reduce(aState.inFrame(Propagator::IntegrationFrameSPtr));

return numericalSolver_.integrateTime(
state,
const State solverOutputState = numericalSolver_.integrateTime(
solverInputState,
anInstant,
Dynamics::GetSystemOfEquations(this->dynamicsContexts_, state.accessInstant(), Propagator::IntegrationFrameSPtr)
Dynamics::GetSystemOfEquations(
this->dynamicsContexts_, solverInputState.accessInstant(), Propagator::IntegrationFrameSPtr
)
);

const StateBuilder outputStateBuilder = {aState};

return outputStateBuilder.expand(solverOutputState.inFrame(aState.accessFrame()), aState);
}

NumericalSolver::ConditionSolution Propagator::calculateStateToCondition(
Expand All @@ -168,20 +171,21 @@ NumericalSolver::ConditionSolution Propagator::calculateStateToCondition(

const Instant startInstant = aState.getInstant();

const State state = {
aState.accessInstant(),
aState.inFrame(Propagator::IntegrationFrameSPtr).extractCoordinates(this->coordinatesBrokerSPtr_->getSubsets()),
Propagator::IntegrationFrameSPtr,
this->coordinatesBrokerSPtr_,
};
const StateBuilder solverStateBuilder = {Propagator::IntegrationFrameSPtr, coordinatesBrokerSPtr_};

const State solverInputState = solverStateBuilder.reduce(aState.inFrame(Propagator::IntegrationFrameSPtr));

const NumericalSolver::ConditionSolution conditionSolution = numericalSolver_.integrateTime(
state,
NumericalSolver::ConditionSolution conditionSolution = numericalSolver_.integrateTime(
solverInputState,
anInstant,
Dynamics::GetSystemOfEquations(this->dynamicsContexts_, startInstant, Propagator::IntegrationFrameSPtr),
anEventCondition
);

const StateBuilder outputStateBuilder = {aState};

conditionSolution.state = outputStateBuilder.expand(conditionSolution.state.inFrame(aState.accessFrame()), aState);

return conditionSolution;
}

Expand Down Expand Up @@ -210,20 +214,19 @@ Array<State> Propagator::calculateStatesAt(const State& aState, const Array<Inst
}
}

const State state = {
aState.accessInstant(),
aState.inFrame(Propagator::IntegrationFrameSPtr).extractCoordinates(this->coordinatesBrokerSPtr_->getSubsets()),
Propagator::IntegrationFrameSPtr,
this->coordinatesBrokerSPtr_,
};
const StateBuilder solverStateBuilder = {Propagator::IntegrationFrameSPtr, coordinatesBrokerSPtr_};

const State solverInputState = solverStateBuilder.reduce(aState.inFrame(Propagator::IntegrationFrameSPtr));

const Instant startInstant = state.accessInstant();
const Instant startInstant = solverInputState.accessInstant();

Array<Instant> forwardInstants;
forwardInstants.reserve(anInstantArray.getSize());
Array<Instant> backwardInstants;
backwardInstants.reserve(anInstantArray.getSize());

const StateBuilder outputStateBuilder(aState);

for (const Instant& anInstant : anInstantArray)
{
if (anInstant <= startInstant)
Expand All @@ -241,7 +244,7 @@ Array<State> Propagator::calculateStatesAt(const State& aState, const Array<Inst
if (!forwardInstants.isEmpty())
{
forwardPropagatedStates = numericalSolver_.integrateTime(
state,
solverInputState,
forwardInstants,
Dynamics::GetSystemOfEquations(this->dynamicsContexts_, startInstant, Propagator::IntegrationFrameSPtr)
);
Expand All @@ -254,15 +257,23 @@ Array<State> Propagator::calculateStatesAt(const State& aState, const Array<Inst
std::reverse(backwardInstants.begin(), backwardInstants.end());

backwardPropagatedStates = numericalSolver_.integrateTime(
state,
solverInputState,
backwardInstants,
Dynamics::GetSystemOfEquations(this->dynamicsContexts_, startInstant, Propagator::IntegrationFrameSPtr)
);

std::reverse(backwardPropagatedStates.begin(), backwardPropagatedStates.end());
}

return backwardPropagatedStates + forwardPropagatedStates;
Array<State> outputStates;
outputStates.reserve(backwardPropagatedStates.getSize() + forwardPropagatedStates.getSize());

for (const State& solverOutputState : backwardPropagatedStates + forwardPropagatedStates)
{
outputStates.add(outputStateBuilder.expand(solverOutputState.inFrame(aState.accessFrame()), aState));
}

return outputStates;
}

void Propagator::print(std::ostream& anOutputStream, bool displayDecorator) const
Expand Down
Loading