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

refactor: Use the built-in State method to extract coordinates #235

Merged
merged 4 commits into from
Oct 10, 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 @@ -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,
kyle-cochran marked this conversation as resolved.
Show resolved Hide resolved
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