GraviDy  1.0
Gravitational Dynamics N-body integrator
NbodySystem.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016
3  *
4  * Cristián Maureira-Fredes <cmaureirafredes@gmail.com>
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * 3. The name of the author may not be used to endorse or promote
20  * products derived from this software without specific prior written
21  * permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
24  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
27  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
31  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  */
36 #ifndef NBODYSYSTEM_HPP
37 #define NBODYSYSTEM_HPP
38 
39 #include <iterator>
40 #include <algorithm>
41 
42 #include "common.hpp"
43 #include "utils/OptionsParser.hpp"
44 #define MAXGPUS 4
45 
51 class NbodySystem {
52  public:
54  ~NbodySystem();
55 
57  std::vector<file_data> reader;
59 
60  // Configuration parameters
61  int gpus;
62  long long int iterations;
63  unsigned int n;
64  unsigned int snapshot_number;
65 
66  float eta;
67  float total_mass;
69 
70  double e2;
71  double snapshot_time;
72  bool resume;
73 
74  // General variables
76  float t_rlx;
77  float t_cr;
78  float r_virial;
79  float max_mass;
80  float r_hm;
81 
82  // Close encounter
83  double r_cl;
84  double dt_cl;
85  double r_core;
86 
87  // Heaviest star
88  double m_g;
89 
90  // Files
91  std::string input_filename;
92  std::string output_filename;
93  std::string resume_filename;
94  std::string snapshot_filename;
95 
96  /******************************** Host Particles arrays */
97 
98  unsigned int *h_id; // Array with index of the particles
99  unsigned int *h_move; // Array with index of the active particles
100  double *h_t; // Particle's time
101  double *h_dt; // Particle's timestep
102  double *h_ekin; // Kinetic energy
103  double *h_epot; // Potential Energy
104  double4 *h_r; // Position + Mass
105  double4 *h_v; // Velocity + Empty
106  double3 *h_a2; // 2nd acceleration derivative (from interpolation)
107  double3 *h_a3; // 3rd acceleration derivative (from interpolation)
108  Predictor *h_p; // Predicted position and velocities
109  Predictor *h_i; // Temporary array of the position and velocity of the
110  // active particle only
111 
112  Forces *h_f; // Struct with the acceleration and jerk
113  Forces *h_old; // Old forces (from previous step)
114  Forces *h_fout_tmp; // Temporary array for partial forces
115  Forces *h_fout_gpu[MAXGPUS]; // Temporary array for partial forces
116 
117  /******************************** Device Particles arrays */
118 
119  unsigned int *d_id[MAXGPUS];
120  unsigned int *d_move[MAXGPUS];
121  double *d_t[MAXGPUS];
122  double *d_dt[MAXGPUS];
123  double *d_ekin[MAXGPUS];
124  double *d_epot[MAXGPUS];
133 
134  /******************************** General functions of the system */
135  void read_input_file();
136  void copy_input_data();
137  void alloc_base_attributes(int rank);
138  void free_base_attributes();
139 };
140 #endif // NBODYSYSTEM_HPP
double4 * h_v
Definition: NbodySystem.hpp:105
void free_base_attributes()
Memory deallocation for the identification, positions, and velocities of the particles.
Definition: NbodySystem.cpp:220
This structure contains all the energy variables of the system.
Definition: common.hpp:151
float max_mass
Definition: NbodySystem.hpp:79
float t_cr
Definition: NbodySystem.hpp:77
unsigned int snapshot_number
Definition: NbodySystem.hpp:64
options ops
Definition: NbodySystem.hpp:58
unsigned int * h_move
Definition: NbodySystem.hpp:99
Predictor * h_i
Definition: NbodySystem.hpp:109
double3 * h_a2
Definition: NbodySystem.hpp:106
Predictor * h_p
Definition: NbodySystem.hpp:108
double3 * h_a3
Definition: NbodySystem.hpp:107
This structure contains the predicted information of a particle in some moment of the integration...
Definition: common.hpp:192
Options to handling printing options, like printing the snapshot on the screen instead of a file; pri...
Definition: common.hpp:175
NbodySystem(OptionsParser op)
Constructor.
Definition: NbodySystem.cpp:39
Class in charge of the general aspects of the N-body integrator.
Definition: NbodySystem.hpp:51
Forces * h_f
Definition: NbodySystem.hpp:112
double e2
Definition: NbodySystem.hpp:70
float integration_time
Definition: NbodySystem.hpp:68
Class in charge to handle all the command-line parameters.
Definition: OptionsParser.hpp:50
double r_cl
Definition: NbodySystem.hpp:83
double * h_ekin
Definition: NbodySystem.hpp:102
Forces * h_fout_gpu[MAXGPUS]
Definition: NbodySystem.hpp:115
float eta
Definition: NbodySystem.hpp:66
void read_input_file()
Method in charge of reading the input file.
Definition: NbodySystem.cpp:76
Forces * d_fout_tmp[MAXGPUS]
Definition: NbodySystem.hpp:131
unsigned int n
Definition: NbodySystem.hpp:63
Forces * d_fout[MAXGPUS]
Definition: NbodySystem.hpp:130
double dt_cl
Definition: NbodySystem.hpp:84
Forces * h_fout_tmp
Definition: NbodySystem.hpp:114
std::string snapshot_filename
Definition: NbodySystem.hpp:94
unsigned int * d_move[MAXGPUS]
Definition: NbodySystem.hpp:120
double * d_ekin[MAXGPUS]
Definition: NbodySystem.hpp:123
double r_core
Definition: NbodySystem.hpp:85
#define MAXGPUS
Definition: NbodySystem.hpp:44
double4 * d_v[MAXGPUS]
Definition: NbodySystem.hpp:126
double * d_epot[MAXGPUS]
Definition: NbodySystem.hpp:124
std::string resume_filename
Definition: NbodySystem.hpp:93
This structure contains different times of the internal integration process.
Definition: common.hpp:253
float total_mass
Definition: NbodySystem.hpp:67
double4 * h_r
Definition: NbodySystem.hpp:104
Forces * h_old
Definition: NbodySystem.hpp:113
Predictor * d_i[MAXGPUS]
Definition: NbodySystem.hpp:128
Forces * d_old[MAXGPUS]
Definition: NbodySystem.hpp:132
Energy en
Definition: NbodySystem.hpp:75
float r_virial
Definition: NbodySystem.hpp:78
double * d_dt[MAXGPUS]
Definition: NbodySystem.hpp:122
double * d_t[MAXGPUS]
Definition: NbodySystem.hpp:121
long long int iterations
Definition: NbodySystem.hpp:62
double snapshot_time
Definition: NbodySystem.hpp:71
Defining the «double3» structure based on the CUDA definition for the CPU version, which not include the CUDA headers.
Definition: common.hpp:74
std::string output_filename
Definition: NbodySystem.hpp:92
double * h_t
Definition: NbodySystem.hpp:100
void alloc_base_attributes(int rank)
Memory allocation for the identification, positions, and velocities of the particles.
Definition: NbodySystem.cpp:196
Predictor * d_p[MAXGPUS]
Definition: NbodySystem.hpp:127
~NbodySystem()
Destructor.
Definition: NbodySystem.cpp:68
double * h_epot
Definition: NbodySystem.hpp:103
Forces * d_f[MAXGPUS]
Definition: NbodySystem.hpp:129
unsigned int * h_id
Definition: NbodySystem.hpp:98
This structure contains the information of the Forces of a particle in some moment of the integration...
Definition: common.hpp:207
std::string input_filename
Definition: NbodySystem.hpp:91
int gpus
Definition: NbodySystem.hpp:61
unsigned int * d_id[MAXGPUS]
Definition: NbodySystem.hpp:119
double4 * d_r[MAXGPUS]
Definition: NbodySystem.hpp:125
bool resume
Definition: NbodySystem.hpp:72
Defining the «double4» structure based on the CUDA definition for the CPU version, which not include the CUDA headers.
Definition: common.hpp:67
void copy_input_data()
Initialization of the data readed from the Input/Snapshot file to the data structures that the code w...
Definition: NbodySystem.cpp:230
Gtime gtime
Definition: NbodySystem.hpp:56
float t_rlx
Definition: NbodySystem.hpp:76
double m_g
Definition: NbodySystem.hpp:88
double * h_dt
Definition: NbodySystem.hpp:101
float r_hm
Definition: NbodySystem.hpp:80
std::vector< file_data > reader
Definition: NbodySystem.hpp:57