15 Particles::ParticleHandler<dim> &particle_handler,
16 const Tensor<1, 3> &g,
18 std::vector<Tensor<1, 3>> &torque,
19 std::vector<Tensor<1, 3>> &force,
20 const std::vector<double> &MOI)
22 const Tensor<1, 3> half_dt_g = 0.5 * g * dt;
24 for (
auto particle = particle_handler.begin();
25 particle != particle_handler.end();
30 auto particle_properties = particle->get_properties();
31 auto particle_position = particle->get_location();
32 types::particle_index particle_id = particle->get_local_index();
34 Tensor<1, 3> &particle_torque = torque[particle_id];
35 Tensor<1, 3> &particle_force = force[particle_id];
37 const double half_dt_mass_inverse =
38 0.5 * dt / particle_properties[PropertiesIndex::mass];
39 const double half_dt_MOI_inverse = 0.5 * dt / MOI[particle_id];
43 for (
unsigned int d = 0; d < 3; ++d)
46 particle_properties[PropertiesIndex::v_x + d] +=
47 half_dt_g[d] + particle_force[d] * half_dt_mass_inverse;
50 particle_properties[PropertiesIndex::omega_x + d] +=
51 particle_torque[d] * half_dt_MOI_inverse;
56 for (
int d = 0; d < dim; ++d)
57 particle_position[d] +=
58 particle_properties[PropertiesIndex::v_x + d] * dt;
64 particle->set_location(particle_position);
71 Particles::ParticleHandler<dim> &particle_handler,
72 const Tensor<1, 3> &g,
74 std::vector<Tensor<1, 3>> &torque,
75 std::vector<Tensor<1, 3>> &force,
76 const std::vector<double> &MOI)
78 const Tensor<1, 3> half_dt_g = 0.5 * g * dt;
80 for (
auto &particle : particle_handler)
84 types::particle_index particle_id = particle.get_local_index();
86 auto particle_properties = particle.get_properties();
87 Tensor<1, 3> &particle_torque = torque[particle_id];
88 Tensor<1, 3> &particle_force = force[particle_id];
90 const double half_dt_mass_inverse =
91 0.5 * dt / particle_properties[PropertiesIndex::mass];
92 const double half_dt_MOI_inverse = 0.5 * dt / MOI[particle_id];
96 particle_properties[PropertiesIndex::v_x] +=
97 half_dt_g[0] + particle_force[0] * half_dt_mass_inverse;
98 particle_properties[PropertiesIndex::v_y] +=
99 half_dt_g[1] + particle_force[1] * half_dt_mass_inverse;
100 particle_properties[PropertiesIndex::v_z] +=
101 half_dt_g[2] + particle_force[2] * half_dt_mass_inverse;
104 particle_properties[PropertiesIndex::omega_x] +=
105 particle_torque[0] * half_dt_MOI_inverse;
106 particle_properties[PropertiesIndex::omega_y] +=
107 particle_torque[1] * half_dt_MOI_inverse;
108 particle_properties[PropertiesIndex::omega_z] +=
109 particle_torque[2] * half_dt_MOI_inverse;
113 particle_torque = 0.;
120 Particles::ParticleHandler<dim> &particle_handler,
121 const Tensor<1, 3> &g,
123 std::vector<Tensor<1, 3>> &torque,
124 std::vector<Tensor<1, 3>> &force,
125 const std::vector<double> &MOI,
126 const parallel::distributed::Triangulation<dim> &triangulation,
131 const bool use_default_function =
132 !action_manager->check_sparse_contacts_enabled() ||
133 action_manager->check_mobility_status_reset();
137 if (use_default_function)
143 const Tensor<1, 3> half_dt_g = 0.5 * g * dt;
151 for (
auto &cell : triangulation.active_cell_iterators())
153 if (!cell->is_locally_owned())
157 const unsigned int mobility_status =
158 cell_mobility_status_map.at(cell->active_cell_index());
162 auto particles_in_cell = particle_handler.particles_in_cell(cell);
164 if (particle_handler.n_particles_in_cell(cell) == 0)
167 if (mobility_status ==
170 for (
auto &particle : particles_in_cell)
172 types::particle_index particle_id = particle.get_local_index();
173 auto particle_properties = particle.get_properties();
175 Tensor<1, 3> &particle_torque = torque[particle_id];
176 Tensor<1, 3> &particle_force = force[particle_id];
178 const double half_dt_mass_inverse =
179 0.5 * dt / particle_properties[PropertiesIndex::mass];
180 const double half_dt_MOI_inverse = 0.5 * dt / MOI[particle_id];
182 for (
unsigned int d = 0; d < 3; ++d)
185 particle_properties[PropertiesIndex::v_x + d] +=
186 half_dt_g[d] + particle_force[d] * half_dt_mass_inverse;
189 particle_properties[PropertiesIndex::omega_x + d] +=
190 particle_torque[d] * half_dt_MOI_inverse;
195 particle_torque = 0.;
200 for (
auto &particle : particles_in_cell)
202 types::particle_index particle_id = particle.get_local_index();
205 force[particle_id] = 0.;
206 torque[particle_id] = 0.;
215 Particles::ParticleHandler<dim> &particle_handler,
216 const Tensor<1, 3> &g,
218 std::vector<Tensor<1, 3>> &torque,
219 std::vector<Tensor<1, 3>> &force,
220 const std::vector<double> &MOI)
222 Point<3> particle_position;
223 const Tensor<1, 3> dt_g = g * dt;
225 for (
auto &particle : particle_handler)
229 types::particle_index particle_id = particle.get_local_index();
231 auto particle_properties = particle.get_properties();
232 Tensor<1, 3> &particle_torque = torque[particle_id];
233 Tensor<1, 3> &particle_force = force[particle_id];
235 double dt_mass_inverse = dt / particle_properties[PropertiesIndex::mass];
236 double dt_MOI_inverse = dt / MOI[particle_id];
238 particle_position = [&] {
239 if constexpr (dim == 3)
241 return particle.get_location();
253 particle_properties[PropertiesIndex::v_x] +=
254 dt_g[0] + particle_force[0] * dt_mass_inverse;
255 particle_properties[PropertiesIndex::v_y] +=
256 dt_g[1] + particle_force[1] * dt_mass_inverse;
257 particle_properties[PropertiesIndex::v_z] +=
258 dt_g[2] + particle_force[2] * dt_mass_inverse;
262 particle_position[0] += particle_properties[PropertiesIndex::v_x] * dt;
263 particle_position[1] += particle_properties[PropertiesIndex::v_y] * dt;
264 particle_position[2] += particle_properties[PropertiesIndex::v_z] * dt;
267 particle_properties[PropertiesIndex::omega_x] +=
268 particle_torque[0] * dt_MOI_inverse;
269 particle_properties[PropertiesIndex::omega_y] +=
270 particle_torque[1] * dt_MOI_inverse;
271 particle_properties[PropertiesIndex::omega_z] +=
272 particle_torque[2] * dt_MOI_inverse;
279 if constexpr (dim == 3)
280 particle.set_location(particle_position);
282 if constexpr (dim == 2)
284 Point<2> position_2d;
285 position_2d[0] = particle_position[0];
286 position_2d[1] = particle_position[1];
287 particle.set_location(position_2d);
295 Particles::ParticleHandler<dim> &particle_handler,
296 const Tensor<1, 3> &g,
298 std::vector<Tensor<1, 3>> &torque,
299 std::vector<Tensor<1, 3>> &force,
300 const std::vector<double> &MOI,
301 const parallel::distributed::Triangulation<dim> &triangulation,
306 bool use_default_function =
307 !action_manager->check_sparse_contacts_enabled() ||
308 action_manager->check_mobility_status_reset();
312 if (use_default_function)
314 integrate(particle_handler, g, dt, torque, force, MOI);
329 sparse_contacts_object);
333 Point<3> particle_position;
334 const Tensor<1, 3> dt_g = g * dt;
337 auto &cell_mobility_status_map =
340 for (
auto &cell : triangulation.active_cell_iterators())
342 if (cell->is_locally_owned())
345 unsigned int mobility_status =
346 cell_mobility_status_map.at(cell->active_cell_index());
351 auto particles_in_cell = particle_handler.particles_in_cell(cell);
352 unsigned int n_particles_in_cell =
353 particle_handler.n_particles_in_cell(cell);
355 if (n_particles_in_cell > 0)
357 if (mobility_status ==
360 for (
auto &particle : particles_in_cell)
362 types::particle_index particle_id =
363 particle.get_local_index();
364 auto particle_properties = particle.get_properties();
366 Tensor<1, 3> &particle_torque = torque[particle_id];
367 Tensor<1, 3> &particle_force = force[particle_id];
369 double dt_mass_inverse =
370 dt / particle_properties[PropertiesIndex::mass];
371 double dt_MOI_inverse = dt / MOI[particle_id];
373 particle_position = [&] {
374 if constexpr (dim == 3)
376 return particle.get_location();
385 for (
unsigned int d = 0; d < 3; ++d)
388 particle_properties[PropertiesIndex::v_x + d] +=
389 dt_g[d] + particle_force[d] * dt_mass_inverse;
392 particle_position[d] +=
393 particle_properties[PropertiesIndex::v_x + d] *
397 particle_properties[PropertiesIndex::omega_x +
399 particle_torque[d] * dt_MOI_inverse;
403 particle_force = 0.0;
404 particle_torque = 0.0;
407 if constexpr (dim == 3)
408 particle.set_location(particle_position);
410 if constexpr (dim == 2)
412 Point<2> position_2d;
413 position_2d[0] = particle_position[0];
414 position_2d[1] = particle_position[1];
415 particle.set_location(position_2d);
421 for (
auto &particle : particles_in_cell)
423 types::particle_index particle_id =
424 particle.get_local_index();
427 force[particle_id] = 0.0;
428 torque[particle_id] = 0.0;
441 Particles::ParticleHandler<dim> &particle_handler,
442 const Tensor<1, 3> &g,
444 std::vector<Tensor<1, 3>> &torque,
445 std::vector<Tensor<1, 3>> &force,
446 const std::vector<double> &MOI,
447 const parallel::distributed::Triangulation<dim> &triangulation,
450 Point<3> particle_position;
451 const Tensor<1, 3> dt_g = g * dt;
454 auto cell_velocities_accelerations_map =
460 for (
auto &cell : triangulation.active_cell_iterators())
462 if (cell->is_locally_owned())
465 unsigned int mobility_status =
466 cell_mobility_status_map.at(cell->active_cell_index());
469 auto &[velocity_cell_average, acc_dt_cell_average] =
470 cell_velocities_accelerations_map[cell];
474 auto particles_in_cell = particle_handler.particles_in_cell(cell);
475 unsigned int n_particles_in_cell =
476 particle_handler.n_particles_in_cell(cell);
478 if (n_particles_in_cell > 0)
480 if (mobility_status ==
486 velocity_cell_average.clear();
487 acc_dt_cell_average.clear();
489 for (
auto &particle : particles_in_cell)
491 types::particle_index particle_id =
492 particle.get_local_index();
493 auto particle_properties = particle.get_properties();
495 Tensor<1, 3> &particle_torque = torque[particle_id];
496 Tensor<1, 3> &particle_force = force[particle_id];
498 double dt_mass_inverse =
499 dt / particle_properties[PropertiesIndex::mass];
500 double dt_MOI_inverse = dt / MOI[particle_id];
502 particle_position = [&] {
503 if constexpr (dim == 3)
505 return particle.get_location();
515 Tensor<1, 3> acc_dt_particle =
516 dt_g + particle_force * dt_mass_inverse;
517 acc_dt_cell_average += acc_dt_particle;
519 for (
unsigned int d = 0; d < 3; ++d)
522 particle_properties[PropertiesIndex::v_x + d] +=
526 velocity_cell_average[d] +=
527 particle_properties[PropertiesIndex::v_x + d];
530 particle_position[d] +=
531 particle_properties[PropertiesIndex::v_x + d] * dt;
534 particle_properties[PropertiesIndex::omega_x + d] +=
535 particle_torque[d] * dt_MOI_inverse;
539 particle_force = 0.0;
540 particle_torque = 0.0;
543 if constexpr (dim == 3)
544 particle.set_location(particle_position);
546 if constexpr (dim == 2)
548 Point<2> position_2d;
549 position_2d[0] = particle_position[0];
550 position_2d[1] = particle_position[1];
551 particle.set_location(position_2d);
556 acc_dt_cell_average /= n_particles_in_cell;
557 velocity_cell_average /= n_particles_in_cell;
559 else if (mobility_status ==
561 PropertiesIndex>::advected ||
566 for (
auto &particle : particles_in_cell)
568 types::particle_index particle_id =
569 particle.get_local_index();
571 particle_position = [&] {
572 if constexpr (dim == 3)
574 return particle.get_location();
583 velocity_cell_average += acc_dt_cell_average;
586 for (
unsigned int d = 0; d < 3; ++d)
588 particle_position[d] += velocity_cell_average[d] * dt;
592 force[particle_id] = 0.0;
593 torque[particle_id] = 0.0;
596 if constexpr (dim == 3)
597 particle.set_location(particle_position);
599 if constexpr (dim == 2)
601 Point<2> position_2d;
602 position_2d[0] = particle_position[0];
603 position_2d[1] = particle_position[1];
604 particle.set_location(position_2d);
611 for (
auto &particle : particles_in_cell)
613 types::particle_index particle_id =
614 particle.get_local_index();
617 force[particle_id] = 0.0;
618 torque[particle_id] = 0.0;
void integrate_with_advected_particles(Particles::ParticleHandler< dim > &particle_handler, const Tensor< 1, 3 > &body_force, const double time_step, std::vector< Tensor< 1, 3 > > &torque, std::vector< Tensor< 1, 3 > > &force, const std::vector< double > &MOI, const parallel::distributed::Triangulation< dim > &triangulation, AdaptiveSparseContacts< dim, PropertiesIndex > &sparse_contacts_object)
virtual void integrate_start(Particles::ParticleHandler< dim > &particle_handler, const Tensor< 1, 3 > &body_force, const double time_step, std::vector< Tensor< 1, 3 > > &torque, std::vector< Tensor< 1, 3 > > &force, const std::vector< double > &MOI) override
Integrate the opening half step of the Velocity Verlet scheme, which starts the staggering....
virtual void integrate_end(Particles::ParticleHandler< dim > &particle_handler, const Tensor< 1, 3 > &body_force, const double time_step, std::vector< Tensor< 1, 3 > > &torque, std::vector< Tensor< 1, 3 > > &force, const std::vector< double > &MOI) override
Integrate the closing half step of the Velocity Verlet scheme. The velocities are advanced by half a ...
virtual void integrate(Particles::ParticleHandler< dim > &particle_handler, const Tensor< 1, 3 > &body_force, const double time_step, std::vector< Tensor< 1, 3 > > &torque, std::vector< Tensor< 1, 3 > > &force, const std::vector< double > &MOI) override
Carry out a regular step of the Velocity Verlet scheme, that is, a full velocity step followed by a f...