Getting started

Prerequisite

SpaceHub is written in morden-ish C++ standard c++17. The lowest compiler versions for different operating systems are listed below.

Operating SystemCompilerLowest Version requiredVersion recommended
LinuxGCC710
Linux/MacOSIntel C++19.0119.01
MacOSClang48
MacOSApple Clangsupportsupport
WindowsMSVC19.1419.14
WindowsGCC via CygWin/MinGw79 if support
  • For Linux/MacOS user, check the version of your C++ compiler in terminal,

    > g++ -v

    or check the version of the intel++ via,

    > icpc -v

    If your compiler version does not satisfy the lowest version required by SpaceHub, you need to update/install the new compiler.

    You can install the new GCC from scratch by executing the following commands by sequence,

    > wget https://ftp.gnu.org/gnu/gcc/gcc-10.3.0/gcc-10.3.0.tar.xz
    > tar xf gcc-10.3.0.tar.xz
    > cd gcc-10.3.0
    > ./contrib/download_prerequisites
    > mkdir build
    > cd build
    > ../configure --prefix=$HOME/GCC-10.3.0 --enable-languages=c,c++ --disable-multilib
    > make -j 8
    > make install

    after the installation, add the new g++ executable to your environment variable PATH by adding the following lines into your .bashrc(Linux)/.bash_profile(MacOS) under your home directory ~,

    export PATH=$PATH:$HOME/GCC-10.3.0/bin
    export LD_LIBRARY_PATH=$HOME/GCC-10.3.0/lib
    export LD_LIBRARY_PATH=$HOME/GCC-10.3.0/lib64

    and source it(for Linux)

    > source ~/.bashrc

    or(for MacOS)

    > source ~/.bash_profile

    then, check the GCC version again via

    > g++ -v
  • For Windows user, if you have installed Microsoft Visual Studio, check the version of your MSVC in cmd terminal,

    path_to_your_installed_dir\Microsoft Visual Studio xxx\VC > cl

    or just open your Microsoft Visual Studio, check the version information through about or help.

    If your MSVC does not satisfy the lowest version required by SpaceHub, update Microsoft Visual Studio to the newest version. If Microsoft Visual Studio is too heavy for you, you can also install the GCC on Windows via CygWin or MinGw.

Install

SpaceHub is a header only library. No installation is required, you only need #include"path_to_spacehub/src/spaceHub.hpp" in your application code to use the SpaceHub.

  • For Linux/MacOS user, open the terminal and cd to a place where you want to install the SpaceHub,

    > git clone https://github.com/YihanWangAstro/SpaceHub.git

    That's it.

  • For Windows user, download the repository of SpaceHub and unpack it.

Demo

Here is a very simple example to integrate a (sun-earth-moon) system. For more information we recommend to read tutorial carefully.

// main.cpp
#include"PATH_TO_SPACEHUB/src/spaceHub.hpp"
using namespace hub;
using namespace unit;
using Solver = methods::DefaultMethod<>;
using Particle = Solver::Particle;
int main(){
  // create three particles. particles are rest at origin.
  Particle sun{1 * Ms}, earth{1 * Me}, moon{1* Mmoon};

  // create a Kepler orbit of (moon mass, earth mass) with a = 268782 km, e = 0.055 and i = 1.543 degree.
  auto moon_orbit = orbit::Elliptic{earth.mass, moon.mass, 268782 * km, 0.055, 1.543 * deg, 0.0, 0.0, 0.0};

  // move the moon to the moon orbit
  orbit::move_particles(moon_orbit, moon);

  // create a Kepler orbit of (moon mass + earth mass, solar mass) a = 1 au, e = 0.016 and i = 7.155 degree.
  auto earth_orbit = orbit::Elliptic{sun.mass, earth.mass + moon.mass, 1 * AU, 0.016, 7.155 * deg, 0.0, 0.0, 0.0};

  // move the centre of mass of the moon and earth to the earth orbit.
  orbit::move_particles(earth_orbit, earth, moon);

  // move the three objects to the centre of mass reference frame
  orbit::move_to_COM_frame(sun, earth, moon);

  // Initialize the system with the three particles and set the time = 0.
  Solver sim{0, sun, earth, moon};

  Solver::RunArgs args;

  // add a default output printer
  args.add_operation(callback::DefaultWriter("solar.dat"));

  args.add_stop_condition(100 * year);

  // run simulation with arguments.
  sim.run(args);

  return 0;
}

compile it with

> g++ -std=c++17 -O3 -o test main.cpp

and run

> ./test

Enjoy!