COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
Cosmos::Physics Namespace Reference

Classes

class  ElectricalPropagator
 
class  GaussJacksonPositionPropagator
 
class  InertialAttitudePropagator
 
class  InertialPositionPropagator
 
class  IterativeAttitudePropagator
 
class  IterativePositionPropagator
 
class  LVLHAttitudePropagator
 
class  Propagator
 
class  State
 
class  Structure
 
class  ThermalPropagator
 

Functions

int32_t PhysCalc (locstruc *loc, physicsstruc *phys)
 
int32_t PhysSetup (physicsstruc *phys)
 
int32_t AttAccel (locstruc *loc, physicsstruc *phys)
 Attitude acceleration. More...
 
int32_t PosAccel (locstruc *loc, physicsstruc *phys)
 Position acceleration. More...
 
double Msis00Density (posstruc pos, float f107avg, float f107, float magidx)
 Calculate atmospheric density. More...
 
Vector GravityAccel (posstruc pos, uint16_t model, uint32_t degree)
 Spherical harmonic gravitational vector. More...
 
int32_t GravityParams (int16_t model)
 
double nplgndr (uint32_t l, uint32_t m, double x)
 Legendre polynomial. More...
 
double Nplgndr (uint32_t l, uint32_t m, double x)
 

Variables

static const uint8_t GravityPGM2000A = 1
 
static const uint8_t GravityEGM2008 = 2
 
static const uint8_t GravityPGM2000A_NORM = 3
 
static const uint8_t GravityEGM2008_NORM = 4
 
static const uint16_t maxdegree = 360
 Data structures for spherical harmonic expansion. More...
 
static double vc [maxdegree+1][maxdegree+1]
 
static double wc [maxdegree+1][maxdegree+1]
 
static double coef [maxdegree+1][maxdegree+1][2]
 
static double ftl [2 *maxdegree+1]
 
static double spmm [maxdegree+1]
 

Function Documentation

int32_t Cosmos::Physics::PhysCalc ( locstruc loc,
physicsstruc phys 
)

Calculate dynamic physical attributes Calculate various derived physical quantities that change, like heat, power generation, torque and drag

Parameters
locPointer to locstruc
physPointer to ::physstruc
Returns
Zero, or negative error.
1316  {
1317  Vector unitv = Quaternion(loc->att.geoc.s).irotate(Vector(loc->pos.geoc.v).normalize());
1318  Vector units = Quaternion(loc->att.icrf.s).irotate(Vector(loc->pos.icrf.s).normalize());
1319  Vector geov(loc->pos.geoc.v);
1320  double speed = geov.norm();
1321  double density;
1322  if (loc->pos.geod.s.h < 10000. || std::isnan(loc->pos.geod.s.h))
1323  density = 1.225;
1324  else
1325  density = 1000. * Msis00Density(loc->pos, 150., 150., 3.);
1326  double adrag = density * 1.1 * speed * speed;
1327 
1328  // External panel effects
1329  phys->powgen = 0.F;
1330  phys->adrag.clear();
1331  phys->atorque.clear();
1332  phys->rdrag.clear();
1333  phys->rtorque.clear();
1334  for (trianglestruc& triangle : phys->triangles)
1335  {
1336  if (triangle.external)
1337  {
1338  // Atmospheric effects
1339  double vdot = unitv.dot(triangle.normal);
1340  double ddrag = 0.;
1341  if (vdot > 0. && phys->mass > 0.F)
1342  {
1343  ddrag = adrag * vdot / phys->mass;
1344  }
1345  Vector dtorque = ddrag * triangle.twist;
1346  phys->atorque += dtorque;
1347  Vector da = ddrag * triangle.shove;
1348  phys->adrag += da;
1349 
1350  // Solar effects
1351  double sdot = units.dot(triangle.normal);
1352  if (loc->pos.sunradiance && sdot > 0)
1353  {
1354  ddrag = loc->pos.sunradiance * sdot / (3e8*phys->mass);
1355  dtorque = ddrag * triangle.twist;
1356  phys->rtorque += dtorque;
1357  da = ddrag * triangle.shove;
1358  phys->rdrag += da;
1359  }
1360  }
1361  }
1362  }
double Msis00Density(posstruc pos, float f107avg, float f107, float magidx)
Calculate atmospheric density.
Definition: physicsclass.cpp:1589
Vector twist
Contribution of triangle to angular forces.
Definition: jsondef.h:3286
qatt geoc
Definition: convertdef.h:828
Vector & clear(double x0=0., double y0=0., double z0=0., double w0=0.)
Clear.
Definition: vector.cpp:1693
double dot(Vector b)
Dot product.
Definition: vector.cpp:1684
Vector adrag
Definition: jsondef.h:3445
cartpos geoc
Definition: convertdef.h:739
float sunradiance
Watts per square meter per steradian.
Definition: convertdef.h:752
Vector shove
Contribution of triangle to linear forces.
Definition: jsondef.h:3284
rvector s
Location.
Definition: convertdef.h:163
Definition: jsondef.h:3275
uint8_t external
External facing sides.
Definition: jsondef.h:3278
attstruc att
attstruc for this time.
Definition: convertdef.h:883
Vector rtorque
Definition: jsondef.h:3439
qatt icrf
Definition: convertdef.h:830
Vector rdrag
Definition: jsondef.h:3446
double h
Height in meters.
Definition: vector.h:229
Vector atorque
Definition: jsondef.h:3438
Vector normal
outward facing normal
Definition: jsondef.h:3282
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
gvector s
Position vector.
Definition: convertdef.h:263
Vector & normalize(double size=1.)
Normalize.
Definition: vector.cpp:1706
float mass
Definition: jsondef.h:3425
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
float speed
Definition: netperf_send.cpp:40
geoidpos geod
Definition: convertdef.h:741
Vector Class.
Definition: vector.h:672
cartpos icrf
Definition: convertdef.h:736
Vector irotate(const Vector &v)
Indirectly rotate a ::Vector using a ::Quaternion.
Definition: vector.cpp:2473
vector< trianglestruc > triangles
Definition: jsondef.h:3452
float powgen
Definition: jsondef.h:3432
rvector v
Velocity.
Definition: convertdef.h:165
int32_t Cosmos::Physics::PhysSetup ( physicsstruc phys)

Calculate static physical attributes Calculate various derived physical quantities, like Center of Mass and Moments of Inertia

Parameters
locPointer to locstruc
physPointer to ::physstruc
Returns
Zero, or negative error.
1370  {
1371  // Calculate Center of mass and internal area
1372  phys->area = 0.;
1373  phys->com.clear();
1374  phys->mass = 0.;
1375  for (trianglestruc triangle : phys->triangles)
1376  {
1377  if (triangle.external <= 1)
1378  {
1379  phys->area += triangle.area;
1380  }
1381  if (!triangle.external)
1382  {
1383  phys->area += triangle.area;
1384  }
1385  phys->com += triangle.com * triangle.mass;
1386  phys->mass += triangle.mass;
1387  }
1388  if (phys->mass == 0.F)
1389  {
1390  return GENERAL_ERROR_TOO_LOW;
1391  }
1392  phys->com /= phys->mass;
1393 
1394  // Calculate Principal Moments of Inertia WRT COM
1395  phys->moi.clear();
1396  for (trianglestruc triangle : phys->triangles)
1397  {
1398  phys->moi.x += (phys->com.x - triangle.com.x) * (phys->com.x - triangle.com.x) * triangle.mass;
1399  phys->moi.y += (phys->com.y - triangle.com.y) * (phys->com.y - triangle.com.y) * triangle.mass;
1400  phys->moi.z += (phys->com.z - triangle.com.z) * (phys->com.z - triangle.com.z) * triangle.mass;
1401  }
1402 
1403  return 0;
1404  }
Vector moi
Definition: jsondef.h:3448
float area
Definition: jsondef.h:3429
Vector & clear(double x0=0., double y0=0., double z0=0., double w0=0.)
Clear.
Definition: vector.cpp:1693
Vector com
Definition: jsondef.h:3449
#define GENERAL_ERROR_TOO_LOW
Definition: cosmos-errno.h:306
double y
Definition: vector.h:713
float mass
mass in Kg
Definition: jsondef.h:3303
float area
Area.
Definition: jsondef.h:3307
double z
Definition: vector.h:714
Definition: jsondef.h:3275
uint8_t external
External facing sides.
Definition: jsondef.h:3278
double x
Definition: vector.h:712
Vector com
center of mass
Definition: jsondef.h:3280
float mass
Definition: jsondef.h:3425
vector< trianglestruc > triangles
Definition: jsondef.h:3452
int32_t Cosmos::Physics::AttAccel ( locstruc loc,
physicsstruc phys 
)

Attitude acceleration.

Calculate the torque forces on the specified satellite at the specified location/

Parameters
physicsPointer to structure specifying satellite.
locStructure specifying location.
1412  {
1413  // rvector ue, ta, tv;
1414  // rvector ttorque;
1415  Vector ue, ta, tv;
1416  Vector ttorque;
1417  rmatrix mom;
1418 
1419  att_extra(loc);
1420 
1421  ttorque = phys->ctorque;
1422 
1423  // Now calculate Gravity Gradient Torque
1424  // Unit vector towards earth, rotated into body frame
1425  // ue = irotate((loc->att.icrf.s),rv_smult(-1.,loc->pos.eci.s));
1426  // normalize_rv(ue);
1427  ue = Quaternion(loc->att.icrf.s).irotate(-1. * Vector(loc->pos.eci.s)).normalize();
1428 
1429  // phys->gtorque = rv_smult((3.*GM/pow(loc->pos.geos.s.r,3.)),rv_cross(ue,rv_mult(phys->moi,ue)));
1430  phys->gtorque = (3. * GM / pow(loc->pos.geos.s.r,3.)) * ue.cross(phys->moi * ue);
1431 
1432  // ttorque = rv_add(ttorque,phys->gtorque);
1433  ttorque += phys->gtorque;
1434 
1435  // Atmospheric and solar torque
1436  // ttorque = rv_add(ttorque,phys->atorque);
1437  // ttorque = rv_add(ttorque,phys->rtorque);
1438 
1439  // Torque from rotational effects
1440 
1441  // Moment of Inertia in Body frame
1442  mom = rm_diag(phys->moi.to_rv());
1443  // Attitude rate in Body frame
1444  tv = irotate(loc->att.icrf.s,loc->att.icrf.v);
1445 
1446  // Torque from cross product of angular velocity and angular momentum
1447  // phys->htorque = rv_smult(-1., rv_cross(tv,rv_add(rv_mmult(mom,tv),phys->hmomentum)));
1448  // ttorque = rv_add(ttorque,phys->htorque);
1449  phys->htorque = -1. * tv.cross(Vector(rv_mmult(mom, tv.to_rv())) + phys->hmomentum);
1450  ttorque += phys->htorque;
1451 
1452  // Convert torque into accelerations, doing math in Body frame
1453 
1454  // I x alpha = tau, so alpha = I inverse x tau
1455  // ta = rv_mmult(rm_inverse(mom),ttorque);
1456  ta = Vector(rv_mmult(rm_inverse(mom),ttorque.to_rv()));
1457 
1458  // Convert body frame acceleration back to other frames.
1459  loc->att.icrf.a = irotate(q_conjugate(loc->att.icrf.s), ta.to_rv());
1460  loc->att.topo.a = irotate(q_conjugate(loc->att.topo.s), ta.to_rv());
1461  loc->att.lvlh.a = irotate(q_conjugate(loc->att.lvlh.s), ta.to_rv());
1462  loc->att.geoc.a = irotate(q_conjugate(loc->att.geoc.s), ta.to_rv());
1463  loc->att.selc.a = irotate(q_conjugate(loc->att.selc.s), ta.to_rv());
1464  return 0;
1465  }
Vector moi
Definition: jsondef.h:3448
svector s
Position vector.
Definition: convertdef.h:318
qatt geoc
Definition: convertdef.h:828
Definition: eci2kep_test.cpp:33
Vector gtorque
Definition: jsondef.h:3440
spherpos geos
Definition: convertdef.h:743
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
quaternion q_conjugate(quaternion q)
Definition: vector.cpp:1010
Vector cross(Vector b)
Cross product.
Definition: vector.cpp:1667
rvector to_rv()
Convert from cvector.
Definition: vector.cpp:1638
qatt lvlh
Definition: convertdef.h:827
#define GM
SI Mass * Gravitational Constant for Earth.
Definition: convertdef.h:79
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
int32_t att_extra(locstruc *loc)
Calculate Extra attitude information.
Definition: convertlib.cpp:1572
rvector s
Location.
Definition: convertdef.h:163
attstruc att
attstruc for this time.
Definition: convertdef.h:883
rmatrix rm_inverse(rmatrix m)
Inverse of rmatrix.
Definition: matrix.cpp:897
Vector htorque
Definition: jsondef.h:3441
qatt selc
Definition: convertdef.h:829
3x3 element generic matrix
Definition: matrix.h:41
rmatrix rm_diag(rvector a)
Diagonal rmatrix Creates an rmatrix whose diagonal is filled with the supplied rvector.
Definition: matrix.cpp:97
qatt icrf
Definition: convertdef.h:830
Vector ctorque
Definition: jsondef.h:3443
Vector hmomentum
Definition: jsondef.h:3442
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
Vector & normalize(double size=1.)
Normalize.
Definition: vector.cpp:1706
qatt topo
Definition: convertdef.h:826
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
rvector irotate(quaternion q, rvector v)
Indirectly rotate a row vector using a quaternion.
Definition: mathlib.cpp:2308
cartpos eci
Definition: convertdef.h:737
double r
Radius in meters.
Definition: vector.h:174
Vector Class.
Definition: vector.h:672
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
Vector irotate(const Vector &v)
Indirectly rotate a ::Vector using a ::Quaternion.
Definition: vector.cpp:2473
int32_t Cosmos::Physics::PosAccel ( locstruc loc,
physicsstruc phys 
)

Position acceleration.

Calculate the linear forces on the specified sattelite at the specified location/

Parameters
physPointer to structure specifying satellite.
locStructure specifying location.
1478  {
1479  int32_t iretn;
1480  double radius;
1481  Vector ctpos, da, tda;
1482  cartpos bodypos;
1483 
1484  radius = length_rv(loc->pos.eci.s);
1485 
1486  loc->pos.eci.a = rv_zero();
1487 
1488  // Earth gravity
1489  // Calculate Geocentric acceleration vector
1490 
1491  if (radius > REARTHM)
1492  {
1493  // Start with gravity vector in ITRS
1494 
1495  da = GravityAccel(loc->pos,GravityEGM2008_NORM,12);
1496 
1497  // Correct for earth rotation, polar motion, precession, nutation
1498 
1499  da = Matrix(loc->pos.extra.e2j) * da;
1500  }
1501  else
1502  {
1503  // Simple 2 body
1504  da = -GM/(radius*radius*radius) * Vector(loc->pos.eci.s);
1505  }
1506  loc->pos.eci.a = rv_add(loc->pos.eci.a, da.to_rv());
1507 
1508  // Sun gravity
1509  // Calculate Satellite to Sun vector
1510  ctpos = rv_sub(rv_smult(-1., loc->pos.extra.sun2earth.s), loc->pos.eci.s);
1511  radius = ctpos.norm();
1512  da = GSUN/(radius*radius*radius) * ctpos;
1513  loc->pos.eci.a = rv_add(loc->pos.eci.a, da.to_rv());
1514 
1515  // Adjust for acceleration of frame
1516  radius = length_rv(loc->pos.extra.sun2earth.s);
1517  da = rv_smult(GSUN/(radius*radius*radius), loc->pos.extra.sun2earth.s);
1518  tda = da;
1519  loc->pos.eci.a = rv_add(loc->pos.eci.a, da.to_rv());
1520 
1521  // Moon gravity
1522  // Calculate Satellite to Moon vector
1523  bodypos.s = rv_sub( loc->pos.extra.sun2earth.s, loc->pos.extra.sun2moon.s);
1524  ctpos = rv_sub(bodypos.s, loc->pos.eci.s);
1525  radius = ctpos.norm();
1526  da = GMOON/(radius*radius*radius) * ctpos;
1527  loc->pos.eci.a = rv_add(loc->pos.eci.a, da.to_rv());
1528 
1529  // Adjust for acceleration of frame due to moon
1530  radius = length_rv(bodypos.s);
1531  da = rv_smult(GMOON/(radius*radius*radius),bodypos.s);
1532  tda -= da;
1533  loc->pos.eci.a = rv_sub(loc->pos.eci.a, da.to_rv());
1534 
1535  /*
1536  // Jupiter gravity
1537  // Calculate Satellite to Jupiter vector
1538  jplpos(JPL_EARTH,JPL_JUPITER, loc->pos.extra.tt,(cartpos *)&bodypos);
1539  ctpos = rv_sub(bodypos.s, loc->pos.eci.s);
1540  radius = length_rv(ctpos);
1541 
1542  // Calculate acceleration
1543  da = rv_smult(GJUPITER/(radius*radius*radius),ctpos);
1544  // loc->pos.eci.a = rv_add( loc->pos.eci.a,da);
1545  */
1546 
1547 
1548  Quaternion iratt = Quaternion(loc->att.icrf.s).conjugate();
1549  if (phys->adrag.norm() > 0.)
1550  {
1551  da = iratt.irotate(phys->adrag);
1552  loc->pos.eci.a = rv_add(loc->pos.eci.a, da.to_rv());
1553  }
1554  // Solar drag
1555  if (phys->rdrag.norm() > 0.)
1556  {
1557  da = iratt.irotate(phys->rdrag);
1558  loc->pos.eci.a = rv_add(loc->pos.eci.a, da.to_rv());
1559  }
1560  // Fictitious drag
1561  if (phys->fdrag.norm() > 0.)
1562  {
1563  da = iratt.irotate(phys->fdrag);
1564  loc->pos.eci.a = rv_add(loc->pos.eci.a, da.to_rv());
1565  }
1566 
1567  loc->pos.eci.pass++;
1568  iretn = pos_eci(loc);
1569  if (iretn < 0)
1570  {
1571  return iretn;
1572  }
1573  if (std::isnan( loc->pos.eci.a.col[0]))
1574  {
1575  loc->pos.eci.a.col[0] = 0.;
1576  }
1577  return 0;
1578  }
Vector fdrag
Definition: jsondef.h:3444
cartpos sun2earth
Definition: convertdef.h:605
rvector rv_add(rvector a, rvector b)
Add two row vectors.
Definition: vector.cpp:299
Vector adrag
Definition: jsondef.h:3445
double norm()
Norm.
Definition: vector.cpp:1735
rvector a
Acceleration.
Definition: convertdef.h:167
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
Cartesian full position structure.
Definition: convertdef.h:158
double length_rv(rvector v)
Length of row vector.
Definition: vector.cpp:748
int iretn
Definition: rw_test.cpp:37
static const uint8_t GravityEGM2008_NORM
Definition: physicsclass.cpp:1470
rvector to_rv()
Convert from cvector.
Definition: vector.cpp:1638
cartpos sun2moon
Definition: convertdef.h:606
#define GM
SI Mass * Gravitational Constant for Earth.
Definition: convertdef.h:79
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
rvector s
Location.
Definition: convertdef.h:163
attstruc att
attstruc for this time.
Definition: convertdef.h:883
Definition: convertdef.h:568
qatt icrf
Definition: convertdef.h:830
Vector rdrag
Definition: jsondef.h:3446
int32_t pos_eci(locstruc *loc)
Set ECI position.
Definition: convertlib.cpp:258
extrapos extra
Definition: convertdef.h:744
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
Quaternion conjugate() const
Definition: vector.cpp:2099
#define GMOON
SI Mass * Gravitational Constant for Moon.
Definition: convertdef.h:81
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
#define REARTHM
SI Radius of Earth.
Definition: convertdef.h:60
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
double col[3]
Definition: vector.h:55
cartpos eci
Definition: convertdef.h:737
Definition: matrix.h:255
rmatrix e2j
Transform from Geocentric to ICRF.
Definition: convertdef.h:594
Vector Class.
Definition: vector.h:672
rvector rv_sub(rvector a, rvector b)
Subtract two vectors.
Definition: vector.cpp:315
Vector GravityAccel(posstruc pos, uint16_t model, uint32_t degree)
Spherical harmonic gravitational vector.
Definition: physicsclass.cpp:1650
#define GSUN
SI Mass * Gravitational Constant for Sun.
Definition: convertdef.h:83
double Cosmos::Physics::Msis00Density ( posstruc  pos,
float  f107avg,
float  f107,
float  magidx 
)

Calculate atmospheric density.

Calculate atmospheric density at indicated Latitute/Longitude/Altitude using the NRLMSISE-00 atmospheric model.

Parameters
posStructure indicating position
f107avgAverage 10.7 cm solar flux
f107Current 10.7 cm solar flux
magidxAp daily geomagnetic index
Returns
Density in kg/m3
1590  {
1591  struct nrlmsise_output output;
1592  struct nrlmsise_input input;
1593  struct nrlmsise_flags flags = {
1594  {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
1595  {0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.},
1596  {0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.}};
1597  int year, month;
1598  double day, doy;
1599  static double lastmjd = 0.;
1600  static double lastdensity = 0.;
1601  static double lastperiod = 0.;
1602 
1603  if (lastperiod != 0.)
1604  {
1605  if (fabs(lastperiod) > (pos.extra.utc-lastmjd))
1606  {
1607  return (lastdensity*(1.+(.001*(pos.extra.utc-lastmjd)/lastperiod)));
1608  }
1609  }
1610 
1611  mjd2ymd(pos.extra.utc,year,month,day,doy);
1612  input.doy = static_cast <int32_t>(doy);
1613  input.g_lat = pos.geod.s.lat*180./DPI;
1614  input.g_long = pos.geod.s.lon*180./DPI;
1615  input.alt = pos.geod.s.h / 1000.;
1616  input.sec = (doy - input.doy)*86400.;;
1617  input.lst = input.sec / 3600. + input.g_long / 15.;
1618  input.f107A = f107avg;
1619  input.f107 = f107;
1620  input.ap = magidx;
1621  gtd7d(&input,&flags,&output);
1622 
1623  if (lastdensity != 0. && lastdensity != output.d[5])
1624  lastperiod = (pos.extra.utc-lastmjd)*.001*output.d[5]/(output.d[5]-lastdensity);
1625  lastmjd = pos.extra.utc;
1626  lastdensity = output.d[5];
1627  return((double)output.d[5]);
1628  }
string output
Definition: agent-2-0.cpp:56
double utc
Coordinated Universal Time.
Definition: convertdef.h:582
void gtd7d(struct nrlmsise_input *input, struct nrlmsise_flags *flags, struct nrlmsise_output *output)
Definition: nrlmsise-00.cpp:1097
Definition: nrlmsise-00.h:172
int32_t mjd2ymd(double mjd, int32_t &year, int32_t &month, double &day)
MJD to Year, Month, and Decimal Day (overloaded)
Definition: timelib.cpp:217
double h
Height in meters.
Definition: vector.h:229
extrapos extra
Definition: convertdef.h:744
double lon
Longitude in radians.
Definition: vector.h:227
gvector s
Position vector.
Definition: convertdef.h:263
double lat
Latitude in radians.
Definition: vector.h:225
geoidpos geod
Definition: convertdef.h:741
const double DPI
Double precision PI.
Definition: math/constants.h:14
Definition: nrlmsise-00.h:132
Definition: nrlmsise-00.h:72
Vector Cosmos::Physics::GravityAccel ( posstruc  pos,
uint16_t  model,
uint32_t  degree 
)

Spherical harmonic gravitational vector.

Calculates a spherical harmonic expansion of the chosen model of indicated order and degree for the requested position. The result is returned as a geocentric vector calculated at the epoch.

Parameters
posa posstruc providing the position at the epoch
modelModel to use for coefficients
degreeOrder and degree to calculate
Returns
A ::Vector pointing toward the earth
See also
pgm2000a_coef.txt
1651  {
1652  uint32_t il, im;
1653  double tmult;
1654  double ratio, rratio, xratio, yratio, zratio;
1655  Vector accel;
1656  double fr;
1657 
1658  // Zero out vc and wc
1659  memset(vc,0,sizeof(vc));
1660  memset(wc,0,sizeof(wc));
1661 
1662  // Load Params
1664 
1665  // Calculate cartesian Legendre terms
1666  vc[0][0] = REARTHM/pos.geos.s.r;
1667  wc[0][0] = 0.;
1668  ratio = vc[0][0] / pos.geos.s.r;
1669  rratio = REARTHM * ratio;
1670  xratio = pos.geoc.s.col[0] * ratio;
1671  yratio = pos.geoc.s.col[1] * ratio;
1672  zratio = pos.geoc.s.col[2] * ratio;
1673  vc[1][0] = zratio * vc[0][0];
1674  wc[1][0] = 0.;
1675  for (il=2; il<=degree+1; il++)
1676  {
1677  vc[il][0] = (2*il-1)*zratio * vc[il-1][0] / il - (il-1) * rratio * vc[il-2][0] / il;
1678  wc[il][0] = 0.;
1679  }
1680  for (im=1; im<=degree+1; im++)
1681  {
1682  vc[im][im] = (2*im-1) * (xratio * vc[im-1][im-1] - yratio * wc[im-1][im-1]);
1683  wc[im][im] = (2*im-1) * (xratio * wc[im-1][im-1] + yratio * vc[im-1][im-1]);
1684  if (im <= degree)
1685  {
1686  vc[im+1][im] = (2*im+1) * zratio * vc[im][im];
1687  wc[im+1][im] = (2*im+1) * zratio * wc[im][im];
1688  }
1689  for (il=im+2; il<=degree+1; il++)
1690  {
1691  vc[il][im] = (2*il-1) * zratio * vc[il-1][im] / (il-im) - (il+im-1) * rratio * vc[il-2][im] / (il-im);
1692  wc[il][im] = (2*il-1) * zratio * wc[il-1][im] / (il-im) - (il+im-1) * rratio * wc[il-2][im] / (il-im);
1693  }
1694  }
1695 
1696  // dr = dlon = dlat = 0.;
1697 
1698  accel.clear();
1699  for (im=0; im<=degree; im++)
1700  {
1701  for (il=im; il<=degree; il++)
1702  {
1703  if (im == 0)
1704  {
1705  accel[0] -= coef[il][0][0] * vc[il+1][1];
1706  accel[1] -= coef[il][0][0] * wc[il+1][1];
1707  accel[2] -= (il+1) * (coef[il][0][0] * vc[il+1][0]);
1708  }
1709  else
1710  {
1711  fr = ftl[il-im+2] / ftl[il-im];
1712  accel[0] -= .5 * (coef[il][im][0] * vc[il+1][im+1] + coef[il][im][1] * wc[il+1][im+1] - fr * (coef[il][im][0] * vc[il+1][im-1] + coef[il][im][1] * wc[il+1][im-1]));
1713  accel[1] -= .5 * (coef[il][im][0] * wc[il+1][im+1] - coef[il][im][1] * vc[il+1][im+1] + fr * (coef[il][im][0] * wc[il+1][im-1] - coef[il][im][1] * vc[il+1][im-1]));
1714  accel[2] -= (il-im+1) * (coef[il][im][0] * vc[il+1][im] + coef[il][im][1] * wc[il+1][im]);
1715  }
1716  }
1717  }
1718  tmult = GM / (REARTHM*REARTHM);
1719  accel[0] *= tmult;
1720  accel[2] *= tmult;
1721  accel[1] *= tmult;
1722 
1723  return (accel);
1724  }
svector s
Position vector.
Definition: convertdef.h:318
static double wc[360+1][360+1]
Definition: physicslib.cpp:52
static double vc[360+1][360+1]
Data structures for spherical harmonic expansion.
Definition: physicslib.cpp:52
Vector & clear(double x0=0., double y0=0., double z0=0., double w0=0.)
Clear.
Definition: vector.cpp:1693
spherpos geos
Definition: convertdef.h:743
cartpos geoc
Definition: convertdef.h:739
#define GM
SI Mass * Gravitational Constant for Earth.
Definition: convertdef.h:79
rvector s
Location.
Definition: convertdef.h:163
static uint16_t model
Definition: add_radio.cpp:19
static double coef[360+1][360+1][2]
Definition: physicslib.cpp:39
int32_t GravityParams(int16_t model)
Definition: physicsclass.cpp:1726
#define REARTHM
SI Radius of Earth.
Definition: convertdef.h:60
double col[3]
Definition: vector.h:55
double r
Radius in meters.
Definition: vector.h:174
Vector Class.
Definition: vector.h:672
static double ftl[2 *360+1]
Definition: physicslib.cpp:37
int32_t Cosmos::Physics::GravityParams ( int16_t  model)
1727  {
1728  static int16_t cmodel = -1;
1729 
1730  int32_t iretn = 0;
1731  uint32_t il, im;
1732  double norm;
1733  uint32_t dil, dim;
1734  double dummy1, dummy2;
1735 
1736  // Calculate factorial
1737  if (ftl[0] == 0.)
1738  {
1739  ftl[0] = 1.;
1740  for (il=1; il<2*maxdegree+1; il++)
1741  {
1742  ftl[il] = il * ftl[il-1];
1743  }
1744  }
1745 
1746  // Load Coefficients
1747  if (cmodel != model)
1748  {
1749  coef[0][0][0] = 1.;
1750  coef[0][0][1] = 0.;
1751  coef[1][0][0] = coef[1][0][1] = 0.;
1752  coef[1][1][0] = coef[1][1][1] = 0.;
1753  string fname;
1754  FILE *fi;
1755  switch (model)
1756  {
1757  case GravityEGM2008:
1758  case GravityEGM2008_NORM:
1759  fname = get_cosmosresources();
1760  if (fname.empty())
1761  {
1762  return GENERAL_ERROR_EMPTY;
1763  }
1764  fname += "/general/egm2008_coef.txt";
1765  fi = fopen(fname.c_str(),"r");
1766 
1767  if (fi==nullptr)
1768  {
1769  cout << "could not load file " << fname << endl;
1770  return iretn;
1771  }
1772 
1773  for (il=2; il<101; il++)
1774  {
1775  for (im=0; im<= il; im++)
1776  {
1777  iretn = fscanf(fi,"%u %u %lf %lf\n",&dil,&dim,&coef[il][im][0],&coef[il][im][1]);
1778  if (iretn && model == GravityEGM2008_NORM)
1779  {
1780  norm = sqrt(ftl[il+im]/((2-(im==0?1:0))*(2*il+1)*ftl[il-im]));
1781  coef[il][im][0] /= norm;
1782  coef[il][im][1] /= norm;
1783  }
1784  }
1785  }
1786  fclose(fi);
1787  cmodel = model;
1788  break;
1789  case GravityPGM2000A:
1790  case GravityPGM2000A_NORM:
1791  default:
1792  iretn = get_cosmosresources(fname);
1793  if (iretn < 0)
1794  {
1795  return iretn;
1796  }
1797  fname += "/general/pgm2000a_coef.txt";
1798  fi = fopen(fname.c_str(),"r");
1799  for (il=2; il<361; il++)
1800  {
1801  for (im=0; im<= il; im++)
1802  {
1803  iretn = fscanf(fi,"%u %u %lf %lf %lf %lf\n",&dil,&dim,&coef[il][im][0],&coef[il][im][1],&dummy1,&dummy2);
1804  if (iretn && model == GravityPGM2000A_NORM)
1805  {
1806  norm = sqrt(ftl[il+im]/((2-(il==im?1:0))*(2*il+1)*ftl[il-im]));
1807  coef[il][im][0] /= norm;
1808  coef[il][im][1] /= norm;
1809  }
1810  }
1811  }
1812  fclose(fi);
1813  cmodel = model;
1814  break;
1815  }
1816  }
1817  return 0;
1818  }
int iretn
Definition: rw_test.cpp:37
static const uint8_t GravityEGM2008_NORM
Definition: physicsclass.cpp:1470
static const uint8_t GravityPGM2000A_NORM
Definition: physicsclass.cpp:1469
string get_cosmosresources(bool create_flag)
Return COSMOS Resources Directory.
Definition: datalib.cpp:1337
static uint16_t model
Definition: add_radio.cpp:19
static int cmodel
Definition: physicslib.cpp:38
static char fname[100]
Definition: geomag.cpp:89
static double coef[360+1][360+1][2]
Definition: physicslib.cpp:39
static const uint8_t GravityEGM2008
Definition: physicsclass.cpp:1468
static const uint8_t GravityPGM2000A
Definition: physicsclass.cpp:1467
static const uint16_t maxdegree
Data structures for spherical harmonic expansion.
Definition: physicsclass.cpp:1633
#define GENERAL_ERROR_EMPTY
Definition: cosmos-errno.h:288
static double ftl[2 *360+1]
Definition: physicslib.cpp:37
double Cosmos::Physics::Nplgndr ( uint32_t  l,
uint32_t  m,
double  x 
)

Variable Documentation

const uint8_t Cosmos::Physics::GravityPGM2000A = 1
static
const uint8_t Cosmos::Physics::GravityEGM2008 = 2
static
const uint8_t Cosmos::Physics::GravityPGM2000A_NORM = 3
static
const uint8_t Cosmos::Physics::GravityEGM2008_NORM = 4
static
const uint16_t Cosmos::Physics::maxdegree = 360
static

Data structures for spherical harmonic expansion.

Coefficients for real and imaginary components of expansion. Of order and rank maxdegree

double Cosmos::Physics::vc[maxdegree+1][maxdegree+1]
static
double Cosmos::Physics::wc[maxdegree+1][maxdegree+1]
static
double Cosmos::Physics::coef[maxdegree+1][maxdegree+1][2]
static
double Cosmos::Physics::ftl[2 *maxdegree+1]
static
double Cosmos::Physics::spmm[maxdegree+1]
static