Skip to content
Draft
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
36 changes: 29 additions & 7 deletions src/OpenSpaceToolkit/Astrodynamics/Dynamics/Tabulated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,6 @@ VectorXd Tabulated::computeContribution(
const Instant& anInstant, [[maybe_unused]] const VectorXd& x, const Shared<const Frame>& aFrameSPtr
) const
{
// TBM: Convert this using the Maneuver class' conversion method. Also, find a way to check and vet whether or not
// the frame is local, or quasi-inertial
if (aFrameSPtr != frameSPtr_)
{
throw ostk::core::error::runtime::Wrong("Frame");
}

if (anInstant < instants_.accessFirst() || anInstant > instants_.accessLast())
{
return VectorXd::Zero(interpolators_.getSize());
Expand All @@ -190,6 +183,35 @@ VectorXd Tabulated::computeContribution(
contribution(i) = interpolators_[i]->evaluate(epoch);
}

// Transform the contribution to the desired frame if necessary
if (frameSPtr_ != aFrameSPtr)
{
if (!frameSPtr_->isQuasiInertial() && aFrameSPtr->isQuasiInertial())
{
// TBM: Replace with an actual proper logging mechanism
std::cout << "WARNING: This TabulatedDynamics has its contributions stored in a non quasi-inertial frame, "
"but they are being requested in a quasi-inertial frame. Ensure that the trajectory "
"used to generate the contributions with this TabulatedDynamics in the first place "
"is still valid, otherwise this may lead to inaccurate results."
"inaccurate results."
<< std::endl;
}

const Shared<CoordinateBroker> coordinatesBrokerSPtr = std::make_shared<CoordinateBroker>();

Index coordinateSubsetIndex = 0;
for (const auto& coordinateSubset : writeCoordinateSubsets_)
{
coordinateSubsetIndex = coordinatesBrokerSPtr->addSubset(coordinateSubset);

if (coordinateSubset->getSize() == 3)
{
contribution.segment(coordinateSubsetIndex, coordinateSubsetIndex + 3) =
coordinateSubset->inFrame(anInstant, contribution, frameSPtr_, aFrameSPtr, coordinatesBrokerSPtr);
}
}
}

return contribution;
}

Expand Down
42 changes: 36 additions & 6 deletions test/OpenSpaceToolkit/Astrodynamics/Dynamics/Tabulated.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,25 +355,54 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Dynamics_Tabulated, ComputeContribution)
defaultInterpolationType_,
};

// Wrong frame
// Same frame as contribution profile
{
EXPECT_THROW(
tabulated.computeContribution(defaultInstants_[0], x, Frame::ITRF()), ostk::core::error::runtime::Wrong
EXPECT_EQ(
tabulated.computeContribution(defaultInstants_[0], x, defaultFrameSPtr_), contributionProfile_.row(0)
);
}

// Different frame as contribution profile (contributions stored in quasi-inertial frame, but requested in
// non-quasi inertial)
{
EXPECT_NE(
tabulated.computeContribution(defaultInstants_[0], x, Frame::ITRF()), contributionProfile_.row(0)
);
}

// Different frame as contribution profile (contributions stored in non-quasi-inertial frame, but requested in
// quasi inertial, so expect a warning logged)
{
Tabulated tabulatedNonQuasiInertialFrame = {
defaultInstants_,
contributionProfile_,
defaultWriteCoordinateSubsets_,
Frame::ITRF(),
defaultInterpolationType_,
};

testing::internal::CaptureStdout();

const VectorXd computedContribution =
tabulatedNonQuasiInertialFrame.computeContribution(defaultInstants_[0], x, defaultFrameSPtr_);

EXPECT_FALSE(testing::internal::GetCapturedStdout().empty());

EXPECT_NE(computedContribution, contributionProfile_.row(0));
}

// Outside bounds
{
EXPECT_EQ(
tabulated.computeContribution(defaultInstants_[0] - Duration::Seconds(1.0), x, Frame::GCRF()),
tabulated.computeContribution(defaultInstants_[0] - Duration::Seconds(1.0), x, defaultFrameSPtr_),
VectorXd::Zero(3)
);
}

{
EXPECT_EQ(
tabulated.computeContribution(
defaultInstants_[defaultInstants_.getSize() - 1] + Duration::Seconds(1.0), x, Frame::GCRF()
defaultInstants_[defaultInstants_.getSize() - 1] + Duration::Seconds(1.0), x, defaultFrameSPtr_
),
VectorXd::Zero(3)
);
Expand Down Expand Up @@ -401,7 +430,8 @@ TEST_F(OpenSpaceToolkit_Astrodynamics_Dynamics_Tabulated, ComputeContribution)

for (Index i = 0; i < expectedInstants.getSize(); ++i)
{
const VectorXd computedContribution = tabulated.computeContribution(expectedInstants[i], x, Frame::GCRF());
const VectorXd computedContribution =
tabulated.computeContribution(expectedInstants[i], x, defaultFrameSPtr_);
const VectorXd expectedContribution = expectedProfile.row(i);

for (Index j = 0; j < (Index)computedContribution.size(); ++j)
Expand Down