Skip to content

Commit

Permalink
refactor: Use the built-in State method to extract coordinates (#235)
Browse files Browse the repository at this point in the history
* chore: rebase conflicts

* feat: add bindings (and fix typo bug

* refactor: leverage State subsets extraction to simplify

* chore: remove artifact from rebase
  • Loading branch information
kyle-cochran authored Oct 10, 2023
1 parent 973343a commit 9b7810a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ class Propagator
mutable NumericalSolver numericalSolver_;

void registerDynamicsContext(const Shared<Dynamics>& aDynamicsSPtr);

NumericalSolver::StateVector extractCoordinatesFromState(const State& aState) const;
};

} // namespace trajectory
Expand Down
29 changes: 6 additions & 23 deletions src/OpenSpaceToolkit/Astrodynamics/Trajectory/Propagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ State Propagator::calculateStateAt(const State& aState, const Instant& anInstant

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

Expand All @@ -170,8 +170,8 @@ NumericalSolver::ConditionSolution Propagator::calculateStateToCondition(

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

Expand Down Expand Up @@ -212,8 +212,8 @@ Array<State> Propagator::calculateStatesAt(const State& aState, const Array<Inst

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

Expand Down Expand Up @@ -327,23 +327,6 @@ void Propagator::registerDynamicsContext(const Shared<Dynamics>& aDynamicsSPtr)
this->dynamicsContexts_.add({aDynamicsSPtr, readInfo, writeInfo});
}

NumericalSolver::StateVector Propagator::extractCoordinatesFromState(const State& aState) const
{
const State state = aState.inFrame(Propagator::IntegrationFrameSPtr);

Index offset = 0;
NumericalSolver::StateVector extractedStateVector = NumericalSolver::StateVector(this->getNumberOfCoordinates());

for (const Shared<const CoordinatesSubset>& subset : this->coordinatesBrokerSPtr_->getSubsets())
{
const Size subsetSize = subset->getSize();
extractedStateVector.segment(offset, subsetSize) = state.extractCoordinates(subset);
offset += subsetSize;
}

return extractedStateVector;
}

} // namespace trajectory
} // namespace astro
} // namespace ostk

0 comments on commit 9b7810a

Please sign in to comment.