Skip to content

This repository is created for the 111-2 Computational Astrophysics Final Project

Notifications You must be signed in to change notification settings

Anchewei/111-2-CA_final

 
 

Repository files navigation

Tree Algorithm For Gravity

Team Name

Happy Tree Friends

Collaborators

  • Meng-Yuan Ho (NTU)
  • Wei-An Chen (NTU)

Presentation

Happy tree

Introduction

In this project, we demonstrate a method to calculate the gravitational potential for N-body problem by building up an octree.

Requirement

  • GCC or any C++ compiler
  • OpenMP
  • Python3 (numpy, pytreegrav)

(back to top)

Installation

git clone https://github.com/willsonho2000/111-2-CA_final.git

(back to top)

Implementation

  1. First prepare your N particles' information, including position in (x, y, z), mass, and softenting. You can generate a random file using CreatePar.py.
python3 CreatePar.py Npar theta

where Npar is the number of particles and theta is the cell-opening criteria. Or, you can manually write a file (recommend: Particle.dat) in the following format.

Npar theta (first line)
pos_i[x] pos_i[y] pos_i[z] mass_i softening_i

Example:

5 6.9999999999999996e-01 
3.2950918101225513e-01 7.6783853139694935e-01 9.7080756233442167e-01 2.0000000000000001e-01 1.0000000000000000e-02
6.4971021323611811e-01 4.9397001999429380e-01 2.8806573895587062e-01 2.0000000000000001e-01 1.0000000000000000e-02
3.2013081665419896e-01 2.3045658135028713e-01 6.8419172781242443e-01 2.0000000000000001e-01 1.0000000000000000e-02
4.1274501434331423e-01 2.4184476920871267e-01 3.0606663461742345e-01 2.0000000000000001e-01 1.0000000000000000e-02
4.9719274486467258e-01 8.8379484672301611e-01 6.3428126058099021e-01 2.0000000000000001e-01 1.0000000000000000e-02
...

Note: The data should all be saved as double type.

Potential_tree_ref.dat, Potential_bruteforce_ref.dat, Accel_bruteforce_ref.dat and Accel_tree_ref.dat will be also generated as reference from pytreegrav.

  1. Edit Makefile, where mpicxx should be replaced by the compiler which the OpenMP is installed in.

  2. To compute the potential, you can simply type make to do it.

make

or

g++-12  octree.cpp treewalk.cpp main.cpp -fopenmp -o main.out
./main.out Particle.dat

Potential_tree.dat and Accel_tree.dat will be generated and the order is stored in the same (particle) as Particle.dat.

  1. Use CalError.py to compute and compare the errors.
python3 CalError.py

(back to top)

About

This repository is created for the 111-2 Computational Astrophysics Final Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 84.7%
  • Python 14.6%
  • Other 0.7%