File: eclipse.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 (91 lines) | stat: -rw-r--r-- 2,826 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
/***********************************************/
/**
* @file eclipse.cpp
*
* @brief Shadowing of satellites by moon and Earth.
*
* @author Torsten Mayer-Guerr
* @date 2020-03-08
*
*/
/***********************************************/

#define DOCSTRING_Eclipse

#include "base/import.h"
#include "config/configRegister.h"
#include "classes/eclipse/eclipseConical.h"
#include "classes/eclipse/eclipseSOLAARS.h"
#include "classes/eclipse/eclipse.h"

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

GROOPS_REGISTER_CLASS(Eclipse, "eclipseType",
                      EclipseConical,
                      EclipseSOLAARS)

GROOPS_READCONFIG_CLASS(Eclipse, "eclipseType")

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

EclipsePtr Eclipse::create(Config &config, const std::string &name)
{
  try
  {
    EclipsePtr eclipse;
    std::string choice;
    readConfigChoice(config, name, choice, Config::MUSTSET, "", "Shadowing of satellites by moon and Earth");

    if(readConfigChoiceElement(config, "conical", choice, "Umbra and penumbra shadow model"))
      eclipse = EclipsePtr(new EclipseConical(config));
    if(readConfigChoiceElement(config, "SOLAARS", choice, "Penumbra with Oblateness and Lower Atmospheric Absorption, Refraction, and Scattering"))
      eclipse = EclipsePtr(new EclipseSOLAARS(config));
    endChoice(config);

    return eclipse;
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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

// For detailed information on this calculation, see Montenbruck and Gill (2000, pp. 80-83)
Double Eclipse::shadowScalingFactor(const Vector3d &posSat, const Vector3d &posSun, const Vector3d &posBody, const Double &radiusBody)
{
  try
  {
    const Double R_Sun       = 6.96342e8;
    const Double distSatSun  = (posSat-posSun).r();
    const Double distSatBody = (posSat-posBody).r();

    // Apparent radius of Sun (a),
    // apparent radius of occulting body (Earth, Moon) (b),
    // apparent separation of the centers of both bodies (c)
    const Double a = std::asin(R_Sun/distSatSun);
    const Double b = std::asin(radiusBody/distSatBody);
    const Double c = std::acos(inner(posBody-posSat, posSun-posSat)/(distSatBody*distSatSun));

    // Satellite is not in occulting body's (Earth, Moon) shadow
    if(a+b <= c)
      return 1.;

    // Satellite is in full occulting body's (Earth, Moon) shadow
    if(std::fabs(a-b) > c)
      return 0.;

    // Satellite is in partial occulting body's (Earth, Moon) shadow
    const Double x = (c*c+a*a-b*b)/(2*c);
    const Double y = std::sqrt(a*a-x*x);
    const Double A = a*a*std::acos(x/a)+b*b*std::acos((c-x)/b)-c*y; // Apparent visible area of the Sun
    return 1-A/(PI*a*a);
  }
  catch (std::exception& e)
  {
    GROOPS_RETHROW(e)
  }
}

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