File: noiseOrbit.cpp

package info (click to toggle)
groops 0%2Bgit20250907%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 11,140 kB
  • sloc: cpp: 135,607; fortran: 1,603; makefile: 20
file content (105 lines) | stat: -rw-r--r-- 3,411 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/***********************************************/
/**
* @file noiseOrbit.cpp
*
* @brief Add white or colored noise to orbits positions and velocities.
*
* @author Torsten Mayer-Guerr
* @author Matthias Ellmer
* @date 2003-01-26
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
This program adds noise to simulated \file{satellite}{instrument}'s positions
and velocities generated by \program{SimulateOrbit} (along, cross, radial).
See \configClass{noiseGenerator}{noiseGeneratorType} for details on noise options.
)";

/***********************************************/

#include "programs/program.h"
#include "files/fileInstrument.h"
#include "classes/noiseGenerator/noiseGenerator.h"

/***** CLASS ***********************************/

/** @brief Add noise to orbit positions and velocities.
* @ingroup programsGroup */
class NoiseOrbit
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(NoiseOrbit, PARALLEL, "add noise to orbit positions and velocities", Simulation, Noise, Instrument)

/***********************************************/

void NoiseOrbit::run(Config &config, Parallel::CommunicatorPtr comm)
{
  try
  {
    FileName          inName, outName;
    NoiseGeneratorPtr noiseGeneratorPosition, noiseGeneratorVelocity;

    readConfig(config, "outputfileOrbit", outName,                Config::MUSTSET,  "", "");
    readConfig(config, "inputfileOrbit",  inName,                 Config::MUSTSET,  "", "");
    readConfig(config, "noisePosition",   noiseGeneratorPosition, Config::DEFAULT,  "", "along, cross, radial [m]");
    readConfig(config, "noiseVelocity",   noiseGeneratorVelocity, Config::DEFAULT,  "", "along, cross, radial [m/s]");
    if(isCreateSchema(config)) return;

    // Read satellite
    // -----------------
    logStatus<<"add noise to orbit data <"<<inName<<">"<<Log::endl;
    InstrumentFile  orbitFile(inName);
    std::vector<Arc> arcList(orbitFile.arcCount());

    Parallel::forEach(arcList, [&](UInt arcNo)
    {
      OrbitArc orbit  = orbitFile.readArc(arcNo);
      Matrix   epsPos = noiseGeneratorPosition->noise(orbit.size(), 3);
      Matrix   epsVel = noiseGeneratorVelocity->noise(orbit.size(), 3);

      for(UInt i=0; i<orbit.size(); i++)
      {
        // rotate into satellite system
        // ----------------------------
        Rotary3d rot;
        if(orbit.size()>1)
        {
          Vector3d x;
          if(i==0)
            x = orbit.at(i+1).position - orbit.at(i).position;
          else
            x = orbit.at(i).position - orbit.at(i-1).position;
          Vector3d z = normalize(orbit.at(i).position);
          Vector3d y = normalize(crossProduct(z, x));
          x = crossProduct(y, z);
          rot = Rotary3d(x,y);
        }

        orbit.at(i).position += rot.rotate(Vector3d(epsPos(i,0), epsPos(i,1), epsPos(i,2)));
        orbit.at(i).velocity += rot.rotate(Vector3d(epsVel(i,0), epsVel(i,1), epsVel(i,2)));
      }
      return orbit;
    }, comm);

    // Save
    // ----
    if(Parallel::isMaster(comm))
    {
      logStatus<<"write orbit data to file <"<<outName<<">"<<Log::endl;
      InstrumentFile::write(outName, arcList);
      Arc::printStatistics(arcList);
    }
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/