COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
physicslib.cpp File Reference
#include "physics/physicslib.h"
#include "support/timelib.h"
#include "support/datalib.h"
Include dependency graph for physicslib.cpp:

Macros

#define MAXDEGREE   360
 
#define ASTEP   1
 

Functions

rvector gravity_accel (posstruc pos, int model, uint32_t degree)
 Spherical harmonic gravitational vector. More...
 
rvector gravity_vector (svector pos, int model, uint32_t degree)
 
double gravity_potential (double lambda, double phi, double r, int model, uint32_t degree)
 
rvector gravity_accel2 (posstruc pos, int model, uint32_t degree)
 Calculates geocentric acceleration vector from chosen model. More...
 
int32_t gravity_params (int model)
 Gravitational model parameters. More...
 
double nplgndr (uint32_t l, uint32_t m, double x)
 Legendre polynomial. More...
 
svector groundstation (locstruc &satellite, locstruc &groundstation)
 Update Ground Station data. More...
 
void hardware_init_eci (cosmosstruc *cinfo, locstruc &loc)
 Initialize Hardware. More...
 
void simulate_hardware (cosmosstruc *cinfo, vector< locstruc > &locvec)
 Simulate Hardware data - multiple. More...
 
void simulate_hardware (cosmosstruc *cinfo, locstruc &loc)
 Simulate Hardware data - single. More...
 
void initialize_imu (uint16_t index, devspecstruc &devspec, locstruc &loc)
 Initialize IMU. More...
 
void simulate_imu (int index, cosmosstruc *cinfo, locstruc &loc)
 Simulate IMU. More...
 
void att_accel (physicsstruc &physics, locstruc &loc)
 Attitude acceleration. More...
 
int32_t pos_accel (physicsstruc &physics, locstruc &loc)
 Position acceleration. More...
 
double msis00_density (posstruc pos, float f107avg, float f107, float magidx)
 Calculate atmospheric density. More...
 
void orbit_init_tle (int32_t mode, double dt, double utc, cosmosstruc *cinfo)
 
void orbit_init_eci (int32_t mode, double dt, double utc, cartpos ipos, cosmosstruc *cinfo)
 
void orbit_init_shape (int32_t mode, double dt, double utc, double altitude, double angle, double hour, cosmosstruc *cinfo)
 
void propagate (cosmosstruc *cinfo, double utc)
 
void gauss_jackson_setup (gj_handle &gjh, uint32_t order, double utc, double &dt)
 Prepare for Gauss-Jackson integration. More...
 
void gauss_jackson_init_tle (gj_handle &gjh, uint32_t order, int32_t mode, double dt, double utc, cosmosstruc *cinfo, locstruc &loc)
 Initialize Gauss-Jackson orbit using Two Line Elements. More...
 
void gauss_jackson_init_eci (gj_handle &gjh, uint32_t order, int32_t mode, double dt, double utc, cartpos ipos, qatt iatt, physicsstruc &physics, locstruc &loc)
 Initialize Gauss-Jackson orbit using ECI state vector. More...
 
void gauss_jackson_init_stk (gj_handle &gjh, uint32_t order, int32_t mode, double dt, double utc, stkstruc &stk, physicsstruc &physics, locstruc &loc)
 
void gauss_jackson_init (gj_handle &gjh, uint32_t order, int32_t mode, double dt, double utc, double altitude, double angle, double hour, locstruc &iloc, physicsstruc &physics, locstruc &loc)
 
locstruc gauss_jackson_converge_orbit (gj_handle &gjh, physicsstruc &physics)
 
void gauss_jackson_converge_hardware (gj_handle &gjh, physicsstruc &physics)
 
vector< locstrucgauss_jackson_propagate (gj_handle &gjh, physicsstruc &physics, locstruc &loc, double tomjd)
 
int orbit_init (int32_t mode, double dt, double utc, string ofile, cosmosstruc *cinfo)
 Initialize orbit from orbital data. More...
 
int orbit_propagate (cosmosstruc *cinfo, double utc)
 Load TLE's from file. More...
 
int update_eci (cosmosstruc *cinfo, double utc, cartpos pos)
 
int32_t triangularize (cosmosstruc *cinfo)
 

Variables

static double ftl [2 *360+1]
 
static int cmodel = -1
 
static double coef [360+1][360+1][2]
 
static double spmm [360+1]
 
static double lastx = 10.
 
static uint16_t lastm = 65535
 
static double initialutc
 
static string orbitfile
 
static stkstruc stkhandle
 
static locstruc sloc [MAXGJORDER+2]
 
static double vc [360+1][360+1]
 Data structures for spherical harmonic expansion. More...
 
static double wc [360+1][360+1]
 

Macro Definition Documentation

#define MAXDEGREE   360
#define ASTEP   1

Function Documentation

void gauss_jackson_init_tle ( gj_handle gjh,
uint32_t  order,
int32_t  mode,
double  dt,
double  utc,
cosmosstruc cinfo,
locstruc loc 
)

Initialize Gauss-Jackson orbit using Two Line Elements.

Initializes Gauss-Jackson structures using starting time and position from a Two Line Element set.

Parameters
gjhReference to Gauss-Jackson variables.
orderthe order at which the integration will be performed (must be even)
modeType of physical modelling. Zero is direct.
dtStep size in seconds
utcInitial step time as UTC in Modified Julian Days
cinfoReference to cosmosstruc to use.
locInitial location.
2362 {
2363  uint32_t i;
2364 
2365  cinfo->node.phys.dt = dt;
2366  cinfo->node.phys.mode = mode;
2367  gauss_jackson_setup(gjh, order, utc, cinfo->node.phys.dt);
2368  cinfo->node.phys.dtj = cinfo->node.phys.dt/86400.;
2369 
2370  utc -= (order/2.)*dt/86400.;
2371  pos_clear(loc);
2372  lines2eci(utc,cinfo->tle,loc.pos.eci);
2373  loc.pos.eci.pass++;
2374  pos_eci(&loc);
2375 
2376  // Initial attitude
2377  cinfo->node.phys.ftorque = rv_zero();
2378  switch (cinfo->node.phys.mode)
2379  {
2380  case 0:
2381  // loc.att.icrf.utc = loc.utc;
2382  // loc.att.icrf.s = q_eye();
2383  loc.att.icrf.a = rv_zero();
2384  // att_icrf(&loc);
2385  // break;
2386  case 1:
2387  loc.att.lvlh.utc = loc.utc;
2388  loc.att.lvlh.s = q_eye();
2389  loc.att.lvlh.v = rv_zero();
2390  att_lvlh2icrf(&loc);
2391  break;
2392  case 2:
2393  loc.att.lvlh.utc = loc.utc;
2394  loc.att.lvlh.s = q_change_around_y(-DPI2);
2395  loc.att.lvlh.v = rv_zero();
2396  att_lvlh2icrf(&loc);
2397  break;
2398  case 3:
2399  case 4:
2400  case 5:
2401  case 6:
2402  case 7:
2403  case 8:
2404  case 9:
2405  case 10:
2406  case 11:
2407  case 12:
2408  loc.att.icrf.s = q_drotate_between_rv(cinfo->faces[abs(cinfo->pieces[cinfo->node.phys.mode-2].face_idx[0])].normal.to_rv(),rv_smult(-1.,loc.pos.icrf.s));
2409  loc.att.icrf.v = rv_zero();
2410  att_icrf2lvlh(&loc);
2411  break;
2412  }
2413 
2414 
2415  pos_accel(cinfo->node.phys, loc);
2416  // Initialize hardware
2417  hardware_init_eci(cinfo, loc);
2418  att_accel(cinfo->node.phys, loc);
2419  // groundstations(cinfo,&loc);
2420 
2421  gjh.step[gjh.order2].sloc = loc;
2422 
2423  // Position at t0-dt
2424  for (i=gjh.order2-1; i<gjh.order2; --i)
2425  {
2426  gjh.step[i].sloc = gjh.step[i+1].sloc;
2427  gjh.step[i].sloc.utc -= dt / 86400.;
2428  lines2eci(gjh.step[i].sloc.utc,cinfo->tle,gjh.step[i].sloc.pos.eci);
2429  gjh.step[i].sloc.pos.eci.pass++;
2430  pos_eci(&gjh.step[i].sloc);
2431 
2432  gjh.step[i].sloc.att.lvlh = gjh.step[i+1].sloc.att.lvlh;
2433  att_lvlh2icrf(&gjh.step[i].sloc);
2434 
2435  pos_accel(cinfo->node.phys, gjh.step[i].sloc);
2436  // Initialize hardware
2437  hardware_init_eci(cinfo,gjh.step[i].sloc);
2438  att_accel(cinfo->node.phys, gjh.step[i].sloc);
2439  }
2440 
2441  for (i=gjh.order2+1; i<=gjh.order; i++)
2442  {
2443  gjh.step[i].sloc = gjh.step[i-1].sloc;
2444  gjh.step[i].sloc.utc += dt / 86400.;
2445  lines2eci(gjh.step[i].sloc.utc,cinfo->tle,gjh.step[i].sloc.pos.eci);
2446  gjh.step[i].sloc.pos.eci.pass++;
2447  pos_eci(&gjh.step[i].sloc);
2448 
2449  gjh.step[i].sloc.att.lvlh = gjh.step[i-1].sloc.att.lvlh;
2450  att_lvlh2icrf(&gjh.step[i].sloc);
2451 
2452  pos_accel(cinfo->node.phys, gjh.step[i].sloc);
2453  // Initialize hardware
2454  hardware_init_eci(cinfo,gjh.step[i].sloc);
2455  att_accel(cinfo->node.phys, gjh.step[i].sloc);
2456  }
2457 
2458  loc = gauss_jackson_converge_orbit(gjh, cinfo->node.phys);
2460 
2461  cinfo->node.phys.utc = loc.utc;
2462 
2463  cinfo->timestamp = currentmjd();
2464 }
double timestamp
Timestamp for last change to data.
Definition: jsondef.h:4202
vector< facestruc > faces
Vector of all faces in node.
Definition: jsondef.h:4229
vector< tlestruc > tle
Array of Two Line Elements.
Definition: jsondef.h:4259
ElapsedTime dt
Definition: agent_file3.cpp:183
int i
Definition: rw_test.cpp:37
rvector a
2nd derivative: Alpha - acceleration
Definition: convertdef.h:483
uint32_t pass
pass indicator: allows synchronization with other attitude and position values.
Definition: convertdef.h:170
Vector ftorque
Definition: jsondef.h:3437
double utc
Master time for location, in Modified Julian Day.
Definition: convertdef.h:879
int32_t att_lvlh2icrf(locstruc *loc)
Convert LVLH attitude to ICRF attitude.
Definition: convertlib.cpp:2035
const double DPI2
Double precision PI/2.
Definition: math/constants.h:18
qatt lvlh
Definition: convertdef.h:827
rvector v
1st derivative: Omega - angular velocity
Definition: convertdef.h:481
rvector rv_smult(double a, rvector b)
Multiply row vector by scalar.
Definition: vector.cpp:266
quaternion q_change_around_y(double angle)
Rotation quaternion for Y axis.
Definition: vector.cpp:1435
nodestruc node
Structure for summary information in node.
Definition: jsondef.h:4220
double utc
Definition: convertdef.h:477
int32_t pos_clear(locstruc *loc)
Initialize posstruc.
Definition: convertlib.cpp:77
rvector s
Location.
Definition: convertdef.h:163
quaternion q_drotate_between_rv(rvector from, rvector to)
Create rotation quaternion from 2 row vectors.
Definition: mathlib.cpp:81
attstruc att
attstruc for this time.
Definition: convertdef.h:883
locstruc gauss_jackson_converge_orbit(gj_handle &gjh, physicsstruc &physics)
Definition: physicslib.cpp:2761
void att_accel(physicsstruc &physics, locstruc &loc)
Attitude acceleration.
Definition: physicslib.cpp:1493
qatt icrf
Definition: convertdef.h:830
int32_t pos_eci(locstruc *loc)
Set ECI position.
Definition: convertlib.cpp:258
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
uint32_t order
Definition: physicsdef.h:109
double currentmjd(double offset)
Current UTC in Modified Julian Days.
Definition: timelib.cpp:65
posstruc pos
posstruc for this time.
Definition: convertdef.h:881
uint32_t order2
Definition: physicsdef.h:110
void hardware_init_eci(cosmosstruc *cinfo, locstruc &loc)
Initialize Hardware.
Definition: physicslib.cpp:877
quaternion s
0th derivative: Quaternion
Definition: convertdef.h:479
int32_t att_icrf2lvlh(locstruc *loc)
Definition: convertlib.cpp:1822
vector< piecestruc > pieces
Vector of all pieces in node.
Definition: jsondef.h:4232
double dt
Time step in seconds.
Definition: jsondef.h:3414
void gauss_jackson_converge_hardware(gj_handle &gjh, physicsstruc &physics)
Definition: physicslib.cpp:2862
cartpos eci
Definition: convertdef.h:737
vector< gjstruc > step
Definition: physicsdef.h:111
quaternion q_eye()
Identity quaternion.
Definition: vector.cpp:1310
int32_t mode
Definition: jsondef.h:3436
cartpos icrf
Definition: convertdef.h:736
double utc
Simulated starting time in MJD.
Definition: jsondef.h:3418
int lines2eci(double utc, vector< tlestruc >lines, cartpos &eci)
Return position from TLE set.
Definition: convertlib.cpp:3155
double dtj
Time step in Julian days.
Definition: jsondef.h:3416
physicsstruc phys
Definition: jsondef.h:3597
void gauss_jackson_setup(gj_handle &gjh, uint32_t order, double utc, double &dt)
Prepare for Gauss-Jackson integration.
Definition: physicslib.cpp:2219
int32_t pos_accel(physicsstruc &physics, locstruc &loc)
Position acceleration.
Definition: physicslib.cpp:1553
int32_t triangularize ( cosmosstruc cinfo)
3494 {
3495  cinfo->node.phys.triangles.clear();
3496 
3497  // Initialize with existing faces broken into triangles
3498  for (uint16_t i=0; i<cinfo->pieces.size(); ++i)
3499  {
3500  for (uint16_t j=0; j<cinfo->pieces[i].face_cnt; ++j)
3501  {
3502  facestruc tface = cinfo->faces[cinfo->pieces[i].face_idx[j]];
3503  cinfo->node.phys.vertices.push_back(tface.com);
3504  cinfo->node.phys.vertices.push_back(cinfo->vertexs[tface.vertex_idx[tface.vertex_cnt-1]]);
3505  for (uint16_t k=0; k<tface.vertex_cnt; ++k)
3506  {
3507  cinfo->node.phys.vertices.push_back(cinfo->vertexs[tface.vertex_idx[k]]);
3508  trianglestruc ttriangle;
3509  ttriangle.pidx = j;
3510  ttriangle.normal = tface.normal;
3511 
3512  ttriangle.tidx[0] = cinfo->node.phys.vertices.size() - (k+2);
3513  ttriangle.tidx[1] = cinfo->node.phys.vertices.size() - 2;
3514  ttriangle.tidx[2] = cinfo->node.phys.vertices.size() - 1;
3515 
3516  ttriangle.com = cinfo->node.phys.vertices[ttriangle.tidx[0]].cross(cinfo->node.phys.vertices[ttriangle.tidx[1]]);
3517  ttriangle.area = cinfo->node.phys.vertices[ttriangle.tidx[0]].area(cinfo->node.phys.vertices[ttriangle.tidx[1]]);
3518  ttriangle.heat = cinfo->pieces[i].heat * ttriangle.area / cinfo->pieces[i].area;
3519 
3520  cinfo->node.phys.triangles.push_back(ttriangle);
3521  }
3522  }
3523  }
3524 
3525  // Loop, breaking triangles into ever smaller triangles, until we are below required resolution (5mm squared)
3526  bool modified = true;
3527  while (modified)
3528  {
3529  modified = false;
3530  for (size_t i=0; i<cinfo->node.phys.triangles.size(); ++i)
3531  {
3532  trianglestruc tface = cinfo->node.phys.triangles[i];
3533  if (tface.area > 2.5e-5)
3534  {
3535  cinfo->node.phys.vertices.push_back(tface.com);
3536  trianglestruc ttriangle = tface;
3537  ttriangle.tidx[0] = cinfo->node.phys.vertices.size() - 1;
3538 
3539  ttriangle.tidx[1] = tface.tidx[2];
3540  ttriangle.tidx[2] = tface.tidx[0];
3541  ttriangle.com = cinfo->node.phys.vertices[ttriangle.tidx[0]].cross(cinfo->node.phys.vertices[ttriangle.tidx[1]]);
3542  ttriangle.area = cinfo->node.phys.vertices[ttriangle.tidx[0]].area(cinfo->node.phys.vertices[ttriangle.tidx[1]]);
3543  ttriangle.heat = tface.heat * ttriangle.area / tface.area;
3544  cinfo->node.phys.triangles.push_back(ttriangle);
3545 
3546  ttriangle.tidx[1] = tface.tidx[0];
3547  ttriangle.tidx[2] = tface.tidx[1];
3548  ttriangle.com = cinfo->node.phys.vertices[ttriangle.tidx[0]].cross(cinfo->node.phys.vertices[ttriangle.tidx[1]]);
3549  ttriangle.area = cinfo->node.phys.vertices[ttriangle.tidx[0]].area(cinfo->node.phys.vertices[ttriangle.tidx[1]]);
3550  ttriangle.heat = tface.heat * ttriangle.area / tface.area;
3551  cinfo->node.phys.triangles.push_back(ttriangle);
3552 
3553  ttriangle.tidx[1] = tface.tidx[1];
3554  ttriangle.tidx[2] = tface.tidx[2];
3555  ttriangle.com = cinfo->node.phys.vertices[ttriangle.tidx[0]].cross(cinfo->node.phys.vertices[ttriangle.tidx[1]]);
3556  ttriangle.area = cinfo->node.phys.vertices[ttriangle.tidx[0]].area(cinfo->node.phys.vertices[ttriangle.tidx[1]]);
3557  ttriangle.heat = tface.heat * ttriangle.area / tface.area;
3558  cinfo->node.phys.triangles.push_back(ttriangle);
3559 
3560  modified = true;
3561  }
3562  }
3563  }
3564 
3565  // For each triangle, identify what is in its field of view in 10 degree resolution grid
3566  for (size_t i=0; i<cinfo->node.phys.triangles.size(); ++i)
3567  {
3568  trianglestruc tface = cinfo->node.phys.triangles[i];
3569  if (cinfo->node.phys.triangles[i].triangleindex.empty())
3570  {
3571  cinfo->node.phys.triangles[i].triangleindex.resize(9);
3572  for (size_t j=0; j<9; ++j)
3573  {
3574  float cel = cos(RADOF(90.-(10.*j+5.)));
3575  cinfo->node.phys.triangles[i].triangleindex[j].resize((int)(cel*18+.5));
3576  }
3577  }
3578 
3579  for (size_t j=0; j<cinfo->node.phys.triangles.size(); ++j)
3580  {
3581  if (j != i)
3582  {
3583  double sep = cinfo->node.phys.triangles[i].com.separation(cinfo->node.phys.triangles[j].com);
3584  if (sep > DPI2)
3585  {
3586  float az;
3587  float el;
3588  Vector topo;
3589  body2topo(cinfo->node.phys.triangles[i].com, cinfo->node.phys.triangles[j].com, topo);
3590  topo2azel(topo, az, el);
3591  float alt = (int16_t)((DPI2 - el) / 9.) + RADOF(.5);
3592  uint16_t rowi = 9 * alt / DPI2;
3593  uint16_t coli = 9 * cos(alt) * az / DPI2;
3594  if (cinfo->node.phys.triangles[i].triangleindex[rowi][coli])
3595  {
3596  cinfo->node.phys.triangles[i].triangleindex[rowi][coli] = j;
3597  }
3598  else
3599  {
3600 
3601  }
3602  }
3603  }
3604  }
3605  }
3606 
3607  return cinfo->node.phys.triangles.size();
3608 }
vector< facestruc > faces
Vector of all faces in node.
Definition: jsondef.h:4229
uint16_t tidx[3]
Definition: jsondef.h:3289
vector< Vector > vertices
Definition: jsondef.h:3451
int i
Definition: rw_test.cpp:37
vector< vertexstruc > vertexs
Vector of all vertexs in node.
Definition: jsondef.h:4223
Vector normal
Definition: jsondef.h:1404
const double DPI2
Double precision PI/2.
Definition: math/constants.h:18
uint16_t vertex_cnt
Definition: jsondef.h:1401
float area
Area.
Definition: jsondef.h:3307
nodestruc node
Structure for summary information in node.
Definition: jsondef.h:4220
Definition: jsondef.h:3275
Face structure: information on each face of a piece.
Definition: jsondef.h:1399
Vector com
Definition: jsondef.h:1403
Vector com
center of mass
Definition: jsondef.h:3280
Vector normal
outward facing normal
Definition: jsondef.h:3282
uint16_t pidx
Index to parent piece.
Definition: jsondef.h:3288
int32_t body2topo(Vector source, Vector target, Vector &topo)
Body Centric to Topocentric.
Definition: convertlib.cpp:3080
vector< piecestruc > pieces
Vector of all pieces in node.
Definition: jsondef.h:4232
vector< uint16_t > vertex_idx
Definition: jsondef.h:1402
float heat
Energy content in Joules.
Definition: jsondef.h:3291
int32_t topo2azel(rvector tpos, float &az, float &el)
Definition: convertlib.cpp:3129
Vector Class.
Definition: vector.h:672
physicsstruc phys
Definition: jsondef.h:3597
vector< trianglestruc > triangles
Definition: jsondef.h:3452
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29

Variable Documentation

double ftl[2 *360+1]
static
int cmodel = -1
static
double coef[360+1][360+1][2]
static
double spmm[360+1]
static
double lastx = 10.
static
uint16_t lastm = 65535
static
double initialutc
static
string orbitfile
static
stkstruc stkhandle
static
locstruc sloc[MAXGJORDER+2]
static
double vc[360+1][360+1]
static

Data structures for spherical harmonic expansion.

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

double wc[360+1][360+1]
static