66#include " iers/iau.hpp"
77#include " iers/icgemio.hpp"
88#include " iers/relativity.hpp"
9+ #include " sysnsats/srp.hpp"
10+ #include " sysnsats/occultation.hpp"
911#include " integration_parameters.hpp"
1012#include " sp3.hpp"
1113#include " yaml-cpp/yaml.h"
1416
1517constexpr const double GM_Moon = /* 0.49028010560e13;*/ 4902.800076e9 ;
1618constexpr const double GM_Sun = /* 1.32712442076e20;*/ 132712440040.944e9 ;
19+ constexpr const double EVERY_SEC = 180e0 ;
1720
1821/* Compute relevant quaternions for the ITRS/GCRS transformation
1922 */
2023int prep_c2i (const dso::MjdEpoch &tai, dso::EopSeries &eops,
2124 Eigen::Quaterniond &q_c2tirs, Eigen::Quaterniond &q_tirs2i,
22- double *fargs, dso::EopRecord &eopr) noexcept {
25+ double *fargs, dso::EopRecord &eopr) noexcept
26+ {
2327
2428 /* epoch of request in TT */
2529 const auto tt = tai.tai2tt ();
@@ -31,7 +35,8 @@ int prep_c2i(const dso::MjdEpoch &tai, dso::EopSeries &eops,
3135 dso::xycip06a (tt, Xcip, Ycip, fargs);
3236
3337 /* interpolate EOPs */
34- if (dso::EopSeries::out_of_bounds (eops.interpolate (tt, eopr))) {
38+ if (dso::EopSeries::out_of_bounds (eops.interpolate (tt, eopr)))
39+ {
3540 fprintf (stderr, " Failed to interpolate: Epoch is out of bounds!\n " );
3641 return 1 ;
3742 }
@@ -96,7 +101,8 @@ int prep_c2i(const dso::MjdEpoch &tai, dso::EopSeries &eops,
96101
97102int deriv (double tsec, Eigen::Ref<const Eigen::VectorXd> y0,
98103 dso::IntegrationParameters *params,
99- Eigen::Ref<Eigen::VectorXd> yp) noexcept {
104+ Eigen::Ref<Eigen::VectorXd> yp) noexcept
105+ {
100106 /* epoch of request in TT */
101107 const auto tt =
102108 (params->t0 ().add_seconds (dso::FractionalSeconds (tsec))).tai2tt ();
@@ -111,14 +117,16 @@ int deriv(double tsec, Eigen::Ref<const Eigen::VectorXd> y0,
111117
112118 /* get Sun position & velocity in ICRF */
113119 Eigen::Matrix<double , 6 , 1 > rsun;
114- if (dso::planet_state (dso::Planet::SUN, tt, rsun)) {
120+ if (dso::planet_state (dso::Planet::SUN, tt, rsun))
121+ {
115122 fprintf (stderr, " ERROR Failed to compute Sun position!\n " );
116123 assert (1 == 2 );
117124 }
118125
119126 /* get Moon position in ICRF */
120127 Eigen::Matrix<double , 3 , 1 > rmoon;
121- if (dso::planet_pos (dso::Planet::MOON, tt, rmoon)) {
128+ if (dso::planet_pos (dso::Planet::MOON, tt, rmoon))
129+ {
122130 fprintf (stderr, " ERROR Failed to compute Moon position!\n " );
123131 assert (1 == 2 );
124132 }
@@ -143,7 +151,8 @@ int deriv(double tsec, Eigen::Ref<const Eigen::VectorXd> y0,
143151 auto acstokes{params->earth_gravity ()};
144152
145153 /* add Solid Earth Tides to SH coeffs */
146- if (params->solid_earth_tide ()) {
154+ if (params->solid_earth_tide ())
155+ {
147156 params->solid_earth_tide ()->stokes_coeffs (
148157 tt, tt.tt2ut1 (eopr.dut ()), q_tirs2i * (q_c2tirs * rmoon),
149158 q_tirs2i * (q_c2tirs * rsun.segment <3 >(0 )), fargs);
@@ -152,45 +161,52 @@ int deriv(double tsec, Eigen::Ref<const Eigen::VectorXd> y0,
152161 }
153162
154163 /* add Ocean Tides to SH coeffs */
155- if (params->ocean_tide ()) {
164+ if (params->ocean_tide ())
165+ {
156166 params->ocean_tide ()->stokes_coeffs (tt, tt.tt2ut1 (eopr.dut ()), fargs);
157167 acstokes += params->ocean_tide ()->stokes_coeffs ();
158168 }
159169
160170 /* add Pole Tide to SH coeffs */
161- if (params->pole_tide ()) {
171+ if (params->pole_tide ())
172+ {
162173 double dC21, dS21;
163174 params->pole_tide ()->stokes_coeffs (tt, eopr.xp (), eopr.yp (), dC21, dS21);
164175 acstokes.C (2 , 1 ) += dC21;
165176 acstokes.S (2 , 1 ) += dS21;
166177 }
167178
168179 /* add Ocean Pole Tide to SH coeffs */
169- if (params->ocean_pole_tide ()) {
170- if (params->ocean_pole_tide ()->stokes_coeffs (tt, eopr.xp (), eopr.yp ())) {
180+ if (params->ocean_pole_tide ())
181+ {
182+ if (params->ocean_pole_tide ()->stokes_coeffs (tt, eopr.xp (), eopr.yp ()))
183+ {
171184 fprintf (stderr, " ERROR Failed computing Stokes Coefficients\n " );
172185 return 1 ;
173186 }
174187 acstokes += params->ocean_pole_tide ()->stokes_coeffs ();
175188 }
176189
177190 /* add deAliasing to SH coeffs */
178- if (params->dealias ()) {
191+ if (params->dealias ())
192+ {
179193 /*
180194 TODO!! WARNING!! The dealias instance should have a function that appends
181195 the coefficients at a StokesCoeffs instance!
182196 */
183197 auto tempstokes{params->earth_gravity ()};
184198 if (params->dealias ()->coefficients_at (
185- dso::from_mjdepoch<dso::nanoseconds>(tt), tempstokes)) {
199+ dso::from_mjdepoch<dso::nanoseconds>(tt), tempstokes))
200+ {
186201 fprintf (stderr, " Failed interpolating dealiasing coefficients\n " );
187202 return 1 ;
188203 }
189204 acstokes += tempstokes;
190205 }
191206
192207 /* add atmospheric tides to SH coeffs */
193- if (params->atmospheric_tide ()) {
208+ if (params->atmospheric_tide ())
209+ {
194210 params->atmospheric_tide ()->stokes_coeffs (tt, tt.tt2ut1 (eopr.dut ()), fargs);
195211 acstokes += params->atmospheric_tide ()->stokes_coeffs ();
196212 }
@@ -201,7 +217,8 @@ int deriv(double tsec, Eigen::Ref<const Eigen::VectorXd> y0,
201217 itrs.segment <3 >(0 ), ai, gi,
202218 params->earth_gravity ().max_degree (),
203219 params->earth_gravity ().max_order (), -1 , -1 ,
204- &(params->tw ()), &(params->tm ()))) {
220+ &(params->tw ()), &(params->tm ())))
221+ {
205222 fprintf (stderr, " ERROR Failed computing acceleration/gradient\n " );
206223 return 1 ;
207224 }
@@ -215,15 +232,35 @@ int deriv(double tsec, Eigen::Ref<const Eigen::VectorXd> y0,
215232 ac += dso::iers2010_relativistic_acceleration (y0, rsun);
216233 }
217234
235+ /* Solar Radiation Pressure */
236+ if (params->matt )
237+ {
238+ const double of = dso::conical_occultation (y0.segment <3 >(0 ), rsun.segment <3 >(0 ));
239+ if (of>0e0 ) {
240+ /* get attitude */
241+ if (params->matt ->attitude_at (tt, *(params->mattdata )))
242+ {
243+ fprintf (stderr, " [ERROR] Failed getting attitude!\n " );
244+ return 9 ;
245+ /* compute SRP acceleration */
246+ ac += of * dso::solar_radiation_pressure (
247+ params->msatmm ->rotate_macromodel (params->mattdata ->quaternions (), params->mattdata ->angles ()),
248+ y0.segment <3 >(0 ), rsun.segment <3 >(0 ));
249+ }
250+ }
251+ }
252+
218253 /* form the derivative vector */
219254 yp.segment <3 >(0 ) = y0.segment <3 >(3 );
220255 yp.segment <3 >(3 ) = ac + q_c2tirs.conjugate () * (q_tirs2i.conjugate () * ai);
221256
222257 return 0 ;
223258}
224259
225- int main (int argc, char *argv[]) {
226- if (argc < 3 ) {
260+ int main (int argc, char *argv[])
261+ {
262+ if (argc < 3 )
263+ {
227264 fprintf (stderr, " Usage: %s [CONFIG] [SP3] \n " , argv[0 ]);
228265 return 1 ;
229266 }
@@ -233,9 +270,11 @@ int main(int argc, char *argv[]) {
233270
234271 /* choose satellite */
235272 dso::sp3::SatelliteId sv = sp3.sattellite_vector ()[0 ];
236- if (argc > 3 ) {
273+ if (argc > 3 )
274+ {
237275 /* check if the satellite is included in the Sp3 */
238- if (!sp3.has_sv (dso::sp3::SatelliteId (argv[3 ]))) {
276+ if (!sp3.has_sv (dso::sp3::SatelliteId (argv[3 ])))
277+ {
239278 fprintf (stderr, " Error. Satellite [%s] not included in sp3 file!\n " ,
240279 argv[3 ]);
241280 return 1 ;
@@ -245,7 +284,8 @@ int main(int argc, char *argv[]) {
245284
246285 /* get starting epoch in TT */
247286 auto start_t = sp3.start_epoch ();
248- if (!std::strcmp (sp3.time_sys (), " GPS" )) {
287+ if (!std::strcmp (sp3.time_sys (), " GPS" ))
288+ {
249289 start_t = start_t .gps2tai ();
250290 }
251291
@@ -267,21 +307,25 @@ int main(int argc, char *argv[]) {
267307 Eigen::Quaterniond q_c2tirs, q_tirs2i;
268308 Eigen::Vector3d omega;
269309 dso::MjdEpoch t0;
310+ dso::MjdEpoch tp;
270311 std::size_t it = 0 ;
271312 dso::Sp3DataBlock block;
272313 int sp3err = 0 ;
273314
274- while (!sp3err) {
315+ while (!sp3err)
316+ {
275317 /* get next record from sp3 */
276318 sp3err = sp3.get_next_data_block (sv, block);
277- if (sp3err > 0 ) {
319+ if (sp3err > 0 )
320+ {
278321 printf (" Something went wrong ....status = %3d\n " , sp3err);
279322 return 1 ;
280323 }
281324
282325 /* time of current block in TAI */
283326 auto block_tai = block.t ;
284- if (!std::strcmp (sp3.time_sys (), " GPS" )) {
327+ if (!std::strcmp (sp3.time_sys (), " GPS" ))
328+ {
285329 block_tai = block_tai.gps2tai ();
286330 }
287331
@@ -296,7 +340,8 @@ int main(int argc, char *argv[]) {
296340 y << block.state [0 ] * 1e3 , block.state [1 ] * 1e3 , block.state [2 ] * 1e3 ,
297341 block.state [4 ] * 1e-1 , block.state [5 ] * 1e-1 , block.state [6 ] * 1e-1 ;
298342
299- if (!it) {
343+ if (!it)
344+ {
300345 /* transform state to GCRS (from ITRS) */
301346 Eigen::VectorXd yc = Eigen::Matrix<double , 6 , 1 >::Zero ();
302347 yc.segment <3 >(0 ) =
@@ -306,16 +351,25 @@ int main(int argc, char *argv[]) {
306351 omega.cross (q_tirs2i.conjugate () * y.segment <3 >(0 )));
307352 y0 = yc;
308353 t0 = tai;
354+ tp = t0;
309355 params.t0 () = tai;
310- } else {
356+ }
357+ else if (tai.diff <dso::DateTimeDifferenceType::FractionalSeconds>(tp).seconds () >= EVERY_SEC)
358+ {
311359 /* seconds since initial epoch */
312360 dso::FractionalSeconds sec =
313361 tai.diff <dso::DateTimeDifferenceType::FractionalSeconds>(t0);
314362
315363 /* integrate from first SP3 record to here - setup initial conditions */
316364 params.t0 () = t0;
317365 Eigen::VectorXd yc = Eigen::Matrix<double , 6 , 1 >::Zero ();
318- if (dop853.integrate (0e0 , sec.seconds (), y0, yc)) {
366+ /* note: we are starting from the top here, so reload the attitude stream */
367+ if (params.matt ->reload ()) {
368+ fprintf (stderr, " ERROR. Failed reloading attitude stream!\n " );
369+ return -100 ;
370+ }
371+ if (dop853.integrate (0e0 , sec.seconds (), y0, yc))
372+ {
319373 fprintf (stderr, " ERROR. Integration failed! sec is %.3f\n " ,
320374 sec.seconds ());
321375 return 1 ;
@@ -331,12 +385,14 @@ int main(int argc, char *argv[]) {
331385 " %.9f %.3f %.3f %.3f %.6f %.6f %.6f %.3f %.3f %.3f %.6f %.6f %.6f\n " ,
332386 sec.seconds (), y (0 ), y (1 ), y (2 ), y (3 ), y (4 ), y (5 ), yi (0 ), yi (1 ),
333387 yi (2 ), yi (3 ), yi (4 ), yi (5 ));
388+
389+ tp = tai;
334390 }
335391
336392 ++it;
337- if (it > 1000 )
393+ if (it > 100 )
338394 break ;
339395 }
340396
341397 printf (" # Num of epochs parsed/used: %ld\n " , it);
342- }
398+ }
0 commit comments