WSF
WsfDE_File.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2020 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFDEFILE_HPP
13#define WSFDEFILE_HPP
14
15// This class is based on the equivalent functionality from NOVAS.
16/*
17 Naval Observatory Vector Astrometry Software (NOVAS)
18 C Edition, Version 3.1
19
20 eph_manager.h: Header file for eph_manager.c
21
22 U. S. Naval Observatory
23 Astronomical Applications Dept.
24 Washington, DC
25 http://www.usno.navy.mil/USNO/astronomical-applications
26*/
27
28#include <array>
29#include <cstdint>
30#include <fstream>
31#include <stdexcept>
32#include <string>
33#include <vector>
34
35#include "UtVec3.hpp"
36
50{
51public:
52 explicit WsfDE_File(const std::string& aFileName);
53 ~WsfDE_File() = default;
54
56 enum class Body : int
57 {
59 cVENUS = 1,
60 cEARTH = 2,
61 cMARS = 3,
66 cPLUTO = 8,
67 cMOON = 9,
68 cSUN = 10,
71 };
72
81 struct Date
82 {
83 double mParts[2];
84 };
85
92 struct Workspace
93 {
95 {
96 // These Chebyshev polynomials are constant.
97 mPc[0] = 1.0;
98 mVc[0] = 0.0;
99 mVc[1] = 1.0;
100 }
101
102 int mNumP{2};
103 int mNumV{3};
104 std::array<double, 18> mPc{};
105 std::array<double, 18> mVc{};
106 double mTwoT{0.0};
107 };
108
109 void GetPlanetEphemeris(const Date& aEpoch,
110 Body aTarget,
111 Body aOrigin,
112 Workspace& aWorkspace,
113 UtVec3d& aPosition,
114 UtVec3d& aVelocity) const;
115
117 int GetDE_Num() const { return mDE_Num; }
118
120 double GetFileStartJD() const { return mInitialJD; }
121
123 double GetFileEndJD() const { return mFinalJD; }
124
126 const std::string& GetFileName() const { return mFileName; }
127
128 class Error : public std::runtime_error
129 {
130 public:
131 explicit Error(const std::string& aWhat)
132 : std::runtime_error(aWhat)
133 {
134 }
135 };
136
137private:
138 class Record
139 {
140 public:
141 explicit Record(int aRecordLength);
142 void Read(std::ifstream& aStream, int aRecordLength);
143 const double* Data(int aOffset) const;
144
145 private:
146 std::vector<double> mData;
147 };
148
149 const Record& GetRecord(int aRecordNumber) const;
150
151 void State(const Date& aTimeJD, Body aTarget, Workspace& aWorkspace, UtVec3d& aPosition, UtVec3d& aVelocity) const;
152 void Interpolate(const double* aBuffer,
153 double aInterpolationEpoch,
154 double aIntervalSpan,
155 int aNumCoeffPerComponent,
156 int aNumSetsCoeff,
157 Workspace& aWorkspace,
158 UtVec3d& aPosition,
159 UtVec3d& aVelocity) const;
160 Date PrepareEpoch(const Date& aEpoch) const;
161 int ComputeRecordNumber(const Date& aEpoch) const;
162 void ComputeInterpolationTimes(const Date& aEpoch, int aRecordNum, double& aInterpolationTime, double& aIntervalSpan) const;
163 void LoadAllRecords(std::ifstream& aFileStream);
164 static void Split(double aValue, double& aWhole, double& aFraction);
165
166 std::string mFileName{};
167 std::uint32_t mDE_Num{};
168 double mEM_Factor{1.0};
169 std::array<std::uint32_t, 12> mRecordOffset{};
170 std::array<std::uint32_t, 12> mNumCoeffPerComponent{};
171 std::array<std::uint32_t, 12> mNumSetsCoeff{};
172 double mInitialJD{0.0};
173 double mFinalJD{0.0};
174 double mRecordInterval{0.0};
175 int mRecordLength{0};
176 int mInitialRecordNum{};
177 int mFinalRecordNum{};
178 std::vector<Record> mRecords{};
179};
180
181#endif // WSFDEFILE_HPP
Error(const std::string &aWhat)
Definition WsfDE_File.hpp:131
void GetPlanetEphemeris(const Date &aEpoch, Body aTarget, Body aOrigin, Workspace &aWorkspace, UtVec3d &aPosition, UtVec3d &aVelocity) const
Definition WsfDE_File.cpp:199
int GetDE_Num() const
Return the number of the ephemeris.
Definition WsfDE_File.hpp:117
~WsfDE_File()=default
WsfDE_File(const std::string &aFileName)
Definition WsfDE_File.cpp:23
double GetFileStartJD() const
Return the Julian date of the earliest time in the ephemeris.
Definition WsfDE_File.hpp:120
double GetFileEndJD() const
Return the Julian date of the latest time in the ephemeris.
Definition WsfDE_File.hpp:123
const std::string & GetFileName() const
Return the name of the DE file this object represents.
Definition WsfDE_File.hpp:126
Body
The possible bodies that can be the target or center of the provided ephemeris.
Definition WsfDE_File.hpp:57
@ cEARTH
Definition WsfDE_File.hpp:60
@ cSUN
Definition WsfDE_File.hpp:68
@ cMERCURY
Definition WsfDE_File.hpp:58
@ cSOLAR_SYSTEM_BARYCENTER
Definition WsfDE_File.hpp:69
@ cMOON
Definition WsfDE_File.hpp:67
@ cURANUS
Definition WsfDE_File.hpp:64
@ cSATURN
Definition WsfDE_File.hpp:63
@ cEARTH_MOON_BARYCENTER
Definition WsfDE_File.hpp:70
@ cNEPTUNE
Definition WsfDE_File.hpp:65
@ cVENUS
Definition WsfDE_File.hpp:59
@ cJUPITER
Definition WsfDE_File.hpp:62
@ cPLUTO
Definition WsfDE_File.hpp:66
@ cMARS
Definition WsfDE_File.hpp:61
Template specialization for wsf::comm::Address. Allows usage of Address in std::unordered_map/set.
Definition WsfCommAddress.hpp:185
Definition WsfDE_File.hpp:82
double mParts[2]
Definition WsfDE_File.hpp:83
Definition WsfDE_File.hpp:93
int mNumP
Definition WsfDE_File.hpp:102
std::array< double, 18 > mVc
Position polynomial values at current interpolation time.
Definition WsfDE_File.hpp:105
std::array< double, 18 > mPc
Used to indicate which velocity polynomials need to be computed.
Definition WsfDE_File.hpp:104
Workspace()
Definition WsfDE_File.hpp:94
int mNumV
Used to indicate which position polynomials need to be computed.
Definition WsfDE_File.hpp:103
double mTwoT
Velocity polynomial values at current interpolation time.
Definition WsfDE_File.hpp:106
Copyrights Multiple, All Rights Reserved