Skip to content

Commit

Permalink
Merge pull request #21 from rahil-makadia/dev
Browse files Browse the repository at this point in the history
force calc updates for efficiency
  • Loading branch information
rahil-makadia authored Aug 20, 2023
2 parents 16c05f3 + 6767c89 commit 7fe4bd4
Show file tree
Hide file tree
Showing 22 changed files with 660 additions and 576 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ project(grss VERSION ${ver})
# TODO: add gprof profiling, iee standards for floats
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_compile_options(-std=c++11 -DLONGDOUBLE -O3 -fPIC -Werror -Wall -Wextra -pedantic -Wno-unused-but-set-variable -Wno-unused-result)
# if not clang, add -Wno-maybe-uninitialized
add_compile_options(-std=c++11 -DLONGDOUBLE -O2 -fPIC -Werror -Wall -Wextra -pedantic -Wno-unused-but-set-variable -Wno-unused-result)
# if not clang, add -Wno-maybe-uninitialized
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-maybe-uninitialized)
endif()
Expand Down
2 changes: 1 addition & 1 deletion grss/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.3
0.9.4
37 changes: 6 additions & 31 deletions include/force.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,11 @@

std::vector<real> get_state_der(const real &t, const std::vector<real> &xInteg,
propSimulation *propSim);
void force_newton(const std::vector<real> &posAll, std::vector<real> &xDotInteg,
const ForceParameters &forceParams,
const IntegrationParameters &integParams,
const Constants &consts);
void force_ppn_simple(const std::vector<real> &posAll,
const std::vector<real> &velAll,
std::vector<real> &xDotInteg,
const ForceParameters &forceParams,
const IntegrationParameters &integParams,
const Constants &consts);
void force_ppn_eih(const std::vector<real> &posAll,
const std::vector<real> &velAll,
std::vector<real> &xDotInteg,
const ForceParameters &forceParams,
const IntegrationParameters &integParams,
const Constants &consts);
void force_J2(const std::vector<real> &posAll, std::vector<real> &xDotInteg,
const ForceParameters &forceParams,
const IntegrationParameters &integParams,
const Constants &consts);
void force_nongrav(const std::vector<real> &posAll,
const std::vector<real> &velAll,
std::vector<real> &xDotInteg,
const ForceParameters &forceParams,
const IntegrationParameters &integParams,
const Constants &consts);
void force_thruster(const std::vector<real> &velAll,
std::vector<real> &xDotInteg,
const ForceParameters &forceParams,
const IntegrationParameters &integParams,
const Constants &consts);
void force_newton(const propSimulation *propSim, real *accInteg);
void force_ppn_simple(const propSimulation *propSim, real *accInteg);
void force_ppn_eih(const propSimulation *propSim, real *accInteg);
void force_J2(const propSimulation *propSim, real *accInteg);
void force_nongrav(const propSimulation *propSim, real *accInteg);
void force_thruster(const propSimulation *propSim, real *accInteg);

#endif
4 changes: 2 additions & 2 deletions include/gr15.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const real cMat[8][8] = {
real get_initial_timestep(const real &t, const std::vector<real> &xInteg0,
propSimulation *propSim);
void compute_g_and_b(const std::vector<std::vector<real> > &AccIntegArr,
const size_t &hIdx, std::vector<std::vector<real> > &g,
const size_t &hIdx, real *g,
std::vector<std::vector<real> > &b, const size_t &dim);
void refine_b(std::vector<std::vector<real> > &b,
std::vector<std::vector<real> > &e, const real &dtRatio,
real *e, const real &dtRatio,
const size_t &dim, const size_t &timestepCounter);
void check_and_apply_events(propSimulation *propSim, const real &t,
real &tNextEvent, size_t &nextEventIdx,
Expand Down
11 changes: 8 additions & 3 deletions include/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ struct Body {
real poleRA = 0.0L;
real poleDec = 90.0L;
std::string name;
std::vector<real> pos;
std::vector<real> vel;
// std::vector<real> pos = {0.0L, 0.0L, 0.0L};
// std::vector<real> vel = {0.0L, 0.0L, 0.0L};
// std::vector<real> acc = {0.0L, 0.0L, 0.0L};
real pos[3], vel[3], acc[3];
bool isPPN = false;
bool isJ2 = false;
bool isNongrav = false;
Expand All @@ -39,6 +41,9 @@ class IntegBody : public Body {
bool isThrusting = false;
std::vector<std::vector<real>> covariance;
NongravParamaters ngParams;
bool propStm = false;
std::vector<real> stm;
size_t n2Derivs = 3;
// constructors
IntegBody(std::string DEkernelPath, std::string name, real t0, real mass,
real radius, std::vector<real> cometaryState,
Expand Down Expand Up @@ -147,7 +152,7 @@ class propSimulation {
std::vector<std::vector<real>>(),
bool adaptiveTimestep = true, real dt0 = 0.0L, real dtMax = 6.0L,
real dtMin = 5.0e-3L, real dtChangeFactor = 0.25L,
real tolInteg = 1.0e-6L, real tolPC = 1.0e-16L);
real tolInteg = 1.0e-9L, real tolPC = 1.0e-16L);

// getters
std::vector<real> get_sim_constants();
Expand Down
5 changes: 4 additions & 1 deletion include/spk.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ struct CacheItem {
double vx;
double vy;
double vz;
double ax;
double ay;
double az;
};

#define SPK_CACHE_ITEM_SIZE 32
Expand Down Expand Up @@ -59,5 +62,5 @@ int spk_free(struct spkInfo *pl);
int spk_calc(struct spkInfo *pl, double epoch, int m, double *x, double *y,
double *z, double *out_vx, double *out_vy, double *out_vz);
void get_spk_state(const int &spiceID, const double &t0_mjd, Ephemeris &ephem,
double state[6]);
double state[9]);
#endif
11 changes: 5 additions & 6 deletions include/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@ using std::tanh;
#include "SpiceUsr.h"
#include "spk.h"

#ifndef LONGDOUBLE
#define LONGDOUBLE // use long double instead of double
#endif

#ifndef real
#ifdef LONGDOUBLE
#define real long double
#else
#define real double
#endif
#endif
#define PI 3.141592653589793238462643383279502884197169399375105820974944
#define RAD2DEG 180.0 / PI
#define DEG2RAD PI / 180.0
Expand All @@ -57,6 +51,7 @@ struct IntegrationParameters {
size_t nInteg;
size_t nSpice;
size_t nTotal;
size_t n2Derivs;
real t0;
real tf;
real dt0;
Expand Down Expand Up @@ -130,9 +125,12 @@ void sort_vector_by_another(std::vector<std::vector<real>> &v,
const bool &ascending);
void vdot(const std::vector<real> &v1, const std::vector<real> &v2, real &dot);
void vnorm(const std::vector<real> &v, real &norm);
void vnorm(const real *v, const size_t &dim, real &norm);
void vunit(const std::vector<real> &v, std::vector<real> &unit);
void vunit(const real *v, const size_t &dim, real *unit);
void vcross(const std::vector<real> &v1, const std::vector<real> &v2,
std::vector<real> &cross);
void vcross(const real *v1, const real *v2, real *cross);
void vadd(const std::vector<real> &v1, const std::vector<real> &v2,
std::vector<real> &sum);
void vsub(const std::vector<real> &v1, const std::vector<real> &v2,
Expand All @@ -141,6 +139,7 @@ void vcmul(const std::vector<real> &v, const real &c, std::vector<real> &vc);
void vvmul(const std::vector<real> &v1, const std::vector<real> &v2,
std::vector<real> &v3);
void vabs_max(const std::vector<real> &v, real &max);
void vabs_max(const real *v, const size_t &dim, real &max);

void mat_vec_mul(const std::vector<std::vector<real>> &A,
const std::vector<real> &v, std::vector<real> &Av);
Expand Down
Loading

0 comments on commit 7fe4bd4

Please sign in to comment.