88namespace nbody {
99
1010ParticleSystem::ParticleSystem ()
11- : particle_count_(0 ), dt_(0 .001f ), G_(1 .0f ), softening_(0 .01f ),
12- simulation_time_ (0 .0f ), force_method_(ForceMethod::DIRECT_N2),
13- is_paused_(false ), is_initialized_(false ) {}
14-
15- ParticleSystem::~ParticleSystem () { freeMemory (); }
11+ : particle_count_(0 ),
12+ dt_ (0 .001f ),
13+ G_(1 .0f ),
14+ softening_(0 .01f ),
15+ simulation_time_(0 .0f ),
16+ force_method_(ForceMethod::DIRECT_N2),
17+ is_paused_(false ),
18+ is_initialized_(false ) {}
19+
20+ ParticleSystem::~ParticleSystem () {
21+ freeMemory ();
22+ }
1623
1724void ParticleSystem::allocateMemory (size_t count) {
1825 particle_count_ = count;
@@ -28,7 +35,7 @@ void ParticleSystem::freeMemory() {
2835 }
2936}
3037
31- void ParticleSystem::initialize (const SimulationConfig & config) {
38+ void ParticleSystem::initialize (const SimulationConfig& config) {
3239 validateSimulationConfig (config);
3340 validateResourceRequirements (config.particle_count );
3441
@@ -90,8 +97,7 @@ void ParticleSystem::initialize(const SimulationConfig &config) {
9097 }
9198}
9299
93- void ParticleSystem::initializeWithDistribution (size_t particle_count,
94- InitDistribution dist) {
100+ void ParticleSystem::initializeWithDistribution (size_t particle_count, InitDistribution dist) {
95101 SimulationConfig config;
96102 config.particle_count = particle_count;
97103 config.init_distribution = dist;
@@ -165,7 +171,7 @@ void ParticleSystem::setBarnesHutTheta(float theta) {
165171 validateTheta (theta);
166172 config_.barnes_hut_theta = theta;
167173 if (force_method_ == ForceMethod::BARNES_HUT) {
168- auto * bh = dynamic_cast <BarnesHutCalculator *>(force_calculator_.get ());
174+ auto * bh = dynamic_cast <BarnesHutCalculator*>(force_calculator_.get ());
169175 if (bh)
170176 bh->setTheta (theta);
171177 }
@@ -178,7 +184,7 @@ void ParticleSystem::setSpatialHashCellSize(float size) {
178184
179185 config_.spatial_hash_cell_size = size;
180186 if (force_method_ == ForceMethod::SPATIAL_HASH) {
181- auto * sh = dynamic_cast <SpatialHashCalculator *>(force_calculator_.get ());
187+ auto * sh = dynamic_cast <SpatialHashCalculator*>(force_calculator_.get ());
182188 if (sh)
183189 sh->setCellSize (size);
184190 }
@@ -191,13 +197,13 @@ void ParticleSystem::setSpatialHashCutoff(float cutoff) {
191197
192198 config_.spatial_hash_cutoff = cutoff;
193199 if (force_method_ == ForceMethod::SPATIAL_HASH) {
194- auto * sh = dynamic_cast <SpatialHashCalculator *>(force_calculator_.get ());
200+ auto * sh = dynamic_cast <SpatialHashCalculator*>(force_calculator_.get ());
195201 if (sh)
196202 sh->setCutoffRadius (cutoff);
197203 }
198204}
199205
200- void ParticleSystem::copyToHost (ParticleData & h_particles) const {
206+ void ParticleSystem::copyToHost (ParticleData& h_particles) const {
201207 ParticleDataManager::copyToHost (h_particles, d_particles_);
202208}
203209
@@ -228,7 +234,7 @@ SimulationState ParticleSystem::getState() const {
228234 return state;
229235}
230236
231- void ParticleSystem::setState (const SimulationState & state) {
237+ void ParticleSystem::setState (const SimulationState& state) {
232238 SimulationConfig config = config_;
233239 config.particle_count = state.particle_count ;
234240 config.dt = state.dt ;
@@ -282,12 +288,12 @@ void ParticleSystem::setState(const SimulationState &state) {
282288 }
283289}
284290
285- void ParticleSystem::saveState (const std::string & filename) const {
291+ void ParticleSystem::saveState (const std::string& filename) const {
286292 SimulationState state = getState ();
287293 Serializer::save (filename, state);
288294}
289295
290- void ParticleSystem::loadState (const std::string & filename) {
296+ void ParticleSystem::loadState (const std::string& filename) {
291297 SimulationState state = Serializer::load (filename);
292298 setState (state);
293299}
@@ -319,7 +325,8 @@ void ParticleSystem::initializeInterop() {
319325void ParticleSystem::updateInteropBuffer () {
320326 if (interop_ && is_initialized_) {
321327 interop_->updatePositions (&d_particles_);
328+ interop_->updateVelocities (&d_particles_);
322329 }
323330}
324331
325- } // namespace nbody
332+ } // namespace nbody
0 commit comments