-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticle.h
More file actions
99 lines (82 loc) · 3.42 KB
/
Particle.h
File metadata and controls
99 lines (82 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// Created by lucy on 23/01/25.
//
#ifndef PARTICLE_H
#define PARTICLE_H
#include <memory>
using namespace std;
// forward declaration of Node class
class Node;
class Particle {
// Class to represent a particle in a 3D space
// The particle has a position, velocity, acceleration, mass, kinetic energy, and potential energy
public:
/*****************************************//**
* Constructor for the Particle class
* @param posX: Initial x position of the particle in parsecs
* @param posY: Initial y position of the particle in parsecs
* @param posZ: Initial z position of the particle in parsecs
* @param velX: Initial x velocity of the particle in km/s
* @param velY: Initial y velocity of the particle in km/s
* @param velZ: Initial z velocity of the particle in km/s
* @param accelX: Initial x acceleration of the particle in km/s^2
* @param accelY: Initial y acceleration of the particle in km/s^2
* @param accelZ: Initial z acceleration of the particle in km/s^2
* @param mass: Mass of the particle in Solar masses
******************************************/
Particle(
long double posX, long double posY, long double posZ,
long double velX, long double velY, long double velZ,
double accelX, double accelY, double accelZ,
double mass) :
posX(posX), posY(posY), posZ(posZ), velX(velX), velY(velY), velZ(velZ), accelX(accelX), accelY(accelY), accelZ(accelZ), mass(mass) {
// Constructor for the Particle class
// x, y, z: initial position of the particle
// vx, vy, vz: initial velocity of the particle
// accel: initial acceleration of the particle
// mass: mass of the particle
std::string id = "0"; // Default ID, can be set later
calculateKineticEnergy();
}
Particle() = default;
/** @brief Unique identifier for the particle */
std::string id;
/** @brief Position of the particle in Pc */
long double posX, posY, posZ;
/** @brief Velocity of the particle in km/s */
long double velX, velY, velZ;
/** @brief Acceleration of the particle in km/s^2 */
double accelX, accelY, accelZ;
/** @brief Mass of the particle in Solar masses */
double mass;
long double kineticEnergy;
long double potentialEnergy;
/** @brief Pointer to the node the particle is in */
Node *node = nullptr;
/**
* @brief Update the position and velocity of the particle using leapfrog integration: https://en.wikipedia.org/wiki/Leapfrog_integration
*/
void update(double deltaTime);
/**
* @brief Update the acceleration of the particle based on the forces acting on it
* @param accelX: Acceleration in the x direction (km/s^2)
* @param accelY: Acceleration in the y direction (km/s^2)
* @param accelZ: Acceleration in the z direction (km/s^2)
*/
void updateAcceleration(double accelX, double accelY, double accelZ);
/**
* @brief Calculate the kinetic energy of the particle
*/
void calculateKineticEnergy();
/**
* @brief Update the potential energy of the particle
* @param combinedPotential: Combined potential energy from all particles in the node
*/
void updatePotentialEnergy(double combinedPotential);
/**
* @brief Print the particle's properties
* This includes position, velocity, acceleration, mass, kinetic energy, and potential energy
*/
void printParticle() const;
};
#endif //PARTICLE_H