Canoe
Comprehensive Atmosphere N' Ocean Engine
get_gravity.cpp
Go to the documentation of this file.
1 // C/C++ headers
2 #include <cmath>
3 #include <cstring>
4 #include <sstream>
5 #include <stdexcept>
6 
7 double GetGravity(char const *planet, double pclat) {
8  std::stringstream msg;
9  double g_new;
10 
11  if (strcmp(planet, "Jupiter") == 0) {
12  double grav = 23.3;
13  double S = sin(pclat * M_PI / 180.);
14  double SS = S * S;
15  double CS = S * sqrt(1 - SS);
16  double GR =
17  -grav +
18  SS * (-4.26594 +
19  SS * (0.47685 +
20  SS * (-0.100513 + SS * (0.0237067 - 0.00305515 * SS))));
21  double GTH =
22  CS * (-3.42313 +
23  SS * (0.119119 +
24  SS * (0.00533106 + SS * (-0.00647658 + SS * 0.000785945))));
25  g_new = sqrt(GR * GR + GTH * GTH);
26  } else if (strcmp(planet, "Saturn")) {
27  double S = sin(pclat * M_PI / 180.);
28  double SS = S * S;
29  double CS = S * sqrt(1 - SS);
30  double GR =
31  -9.06656 +
32  SS * (-3.59253 +
33  SS * (0.704538 +
34  SS * (-0.260158 + SS * (0.0923098 - SS * 0.0166287))));
35  double GTH =
36  CS * (-2.25384 +
37  SS * (.152112 +
38  SS * (-.0102391 + SS * (-.00714765 + SS * .000865634))));
39  g_new = sqrt(GR * GR + GTH * GTH);
40  } else {
41  msg << "### FATAL ERROR in planet_gravity" << std::endl
42  << "Name of the planet not recognized" << std::endl
43  << "Choose from [Jupiter|Saturn]" << std::endl;
44  throw std::runtime_error(msg.str().c_str());
45  }
46 
47  return g_new;
48 }
double GetGravity(char const *planet, double pclat)
Definition: get_gravity.cpp:7