include/meltpooldg/particles/particle_accessor.hpp Source File

Developer Documentation: include/meltpooldg/particles/particle_accessor.hpp Source File
Developer Documentation
particle_accessor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <deal.II/particles/particle_accessor.h>
4#include <deal.II/particles/property_pool.h>
5
8
9#include <functional>
10
11namespace MeltPoolDG
12{
18 template <int dim, typename number>
20 {
21 public:
27 DEMParticleAccessor(dealii::Particles::ParticleAccessor<dim> &particle);
28
36 DEMParticleAccessor(dealii::Point<dim, number> &location,
37 dealii::ArrayView<number> properties,
38 dealii::types::particle_index particle_id);
39
47 dealii::Particles::PropertyPool<dim> &property_pool,
48 const typename dealii::Particles::PropertyPool<dim>::Handle handle) noexcept;
49
53 DEMParticleAccessor(const DEMParticleAccessor &other) noexcept = default;
54
58 DEMParticleAccessor(DEMParticleAccessor &&other) noexcept = default;
59
64 operator=(DEMParticleAccessor &&other) noexcept = default;
65
70 operator=(const DEMParticleAccessor &other) noexcept = default;
71
77 dealii::Point<dim, number> &
79
83 const dealii::Point<dim, number> &
84 get_location() const;
85
92 dealii::Tensor<1, dim, number>
93 linear_velocity() const;
94
101 number &
102 linear_velocity(const unsigned int dimension);
103
107 const number &
108 linear_velocity(const unsigned int dimension) const;
109
116 number &
117 linear_acceleration(const unsigned int dimension);
118
124 dealii::Tensor<1, axial_dim<dim>, number>
125 get_angular_velocity() const;
126
133 number &
134 angular_acceleration(const unsigned int dimension);
135
142 number &
143 angular_velocity(const unsigned int dimension);
144
148 const number &
149 angular_velocity(const unsigned int dimension) const;
150
156 dealii::Tensor<1, axial_dim<dim>, number>
157 angular_velocity() const;
158
165 number &
166 force(const unsigned int dimension);
167
171 const number &
172 force(const unsigned int dimension) const;
173
179 dealii::Tensor<1, dim, number>
180 force() const;
181
188 void
189 set_force(const dealii::Tensor<1, dim, number> &force);
190
197 void
198 add_force(const dealii::Tensor<1, dim, number> &force);
199
206 void
207 set_torque(const dealii::Tensor<1, axial_dim<dim>, number> &torque);
208
215 void
216 add_torque(const dealii::Tensor<1, axial_dim<dim>, number> &torque);
217
224 number &
225 torque(const unsigned int dimension);
226
230 const number &
231 torque(const unsigned int dimension) const;
232
238 dealii::Tensor<1, axial_dim<dim>, number>
239 torque() const;
240
246 dealii::types::particle_index
247 id() const;
248
254 dealii::types::particle_index
255 local_id() const;
256
262 number &
263 radius();
264
268 const number &
269 radius() const;
270
276 number &
277 mass();
278
282 const number &
283 mass() const;
284
290 number &
291 density();
292
296 const number &
297 density() const;
298
309 number &
311
315 const number &
316 get_property(const typename SphericalParticle<dim, number>::Properties property) const;
317
323 typename dealii::Triangulation<dim>::active_cell_iterator
324 get_surrounding_cell() const;
325
326 private:
328 std::reference_wrapper<dealii::Point<dim, number>> location;
329
331 dealii::ArrayView<number> properties;
332
335 typename dealii::Triangulation<dim>::active_cell_iterator surrounding_cell;
336
338 dealii::types::particle_index particle_id;
339
342 dealii::types::particle_index local_particle_id = dealii::numbers::invalid_unsigned_int;
343 };
344
345
346 template <int dim, typename number>
348 dealii::Particles::ParticleAccessor<dim> &particle)
349 : location(particle.get_location())
350 , properties(particle.get_properties())
351 , surrounding_cell(particle.get_surrounding_cell())
352 , particle_id(particle.get_id())
353 , local_particle_id(particle.get_local_index())
354 {}
355
356 template <int dim, typename number>
357 DEMParticleAccessor<dim, number>::DEMParticleAccessor(dealii::Point<dim, number> &location,
358 dealii::ArrayView<number> properties,
359 dealii::types::particle_index particle_id)
360 : location(location)
361 , properties(properties)
362 , particle_id(particle_id)
363 {}
364
365 template <int dim, typename number>
367 dealii::Particles::PropertyPool<dim> &property_pool,
368 const typename dealii::Particles::PropertyPool<dim>::Handle handle) noexcept
369 : location(property_pool.get_location(handle))
370 , properties(property_pool.get_properties(handle))
371 , particle_id(property_pool.get_id(handle))
372 {}
373
374 template <int dim, typename number>
375 dealii::Point<dim, number> &
377 {
378 return location;
379 }
380
381 template <int dim, typename number>
382 const dealii::Point<dim, number> &
384 {
385 return location;
386 }
387
388 template <int dim, typename number>
389 dealii::Tensor<1, dim, number>
391 {
392 Assert(!properties.empty(), dealii::ExcInternalError());
393 dealii::Tensor<1, dim, number> velocity;
394 for (int dimension = 0; dimension < dim; ++dimension)
395 velocity[dimension] =
397 return velocity;
398 }
399
400 template <int dim, typename number>
401 number &
403 {
404 AssertIndexRange(dimension, dim);
405 return properties[SphericalParticle<dim, number>::Properties::velocity + dimension];
406 }
407
408 template <int dim, typename number>
409 const number &
410 DEMParticleAccessor<dim, number>::linear_velocity(const unsigned int dimension) const
411 {
412 AssertIndexRange(dimension, dim);
413 return properties[SphericalParticle<dim, number>::Properties::velocity + dimension];
414 }
415
416
417 template <int dim, typename number>
418 number &
420 {
421 AssertIndexRange(dimension, dim);
423 }
424
425 template <int dim, typename number>
426 dealii::Tensor<1, axial_dim<dim>, number>
428 {
429 Assert(!properties.empty(), dealii::ExcInternalError());
430 dealii::Tensor<1, axial_dim<dim>, number> velocity;
431 for (int dimension = 0; dimension < axial_dim<dim>; ++dimension)
432 velocity[dimension] =
434 return velocity;
435 }
436
437 template <int dim, typename number>
438 number &
440 {
441 AssertIndexRange(dimension, axial_dim<dim>);
443 }
444
445 template <int dim, typename number>
446 const number &
447 DEMParticleAccessor<dim, number>::angular_velocity(const unsigned int dimension) const
448 {
449 AssertIndexRange(dimension, axial_dim<dim>);
451 }
452
453 template <int dim, typename number>
454 number &
456 {
457 AssertIndexRange(dimension, axial_dim<dim>);
459 }
460
461 template <int dim, typename number>
462 dealii::Tensor<1, axial_dim<dim>, number>
464 {
465 Assert(!properties.empty(), dealii::ExcInternalError());
466 dealii::Tensor<1, axial_dim<dim>, number> angular_velocity_vector;
467 for (int dimension = 0; dimension < axial_dim<dim>; ++dimension)
468 {
469 angular_velocity_vector[dimension] = angular_velocity(dimension);
470 }
471 return angular_velocity_vector;
472 }
473
474 template <int dim, typename number>
475 number &
476 DEMParticleAccessor<dim, number>::force(const unsigned int dimension)
477 {
478 AssertIndexRange(dimension, dim);
479 return properties[SphericalParticle<dim, number>::Properties::force + dimension];
480 }
481
482 template <int dim, typename number>
483 const number &
484 DEMParticleAccessor<dim, number>::force(const unsigned int dimension) const
485 {
486 AssertIndexRange(dimension, dim);
487 return properties[SphericalParticle<dim, number>::Properties::force + dimension];
488 }
489
490 template <int dim, typename number>
491 dealii::Tensor<1, dim, number>
493 {
494 dealii::Tensor<1, dim, number> force_vector;
495 for (unsigned int dimension = 0; dimension < dim; ++dimension)
496 force_vector[dimension] = force(dimension);
497 return force_vector;
498 }
499
500 template <int dim, typename number>
501 void
502 DEMParticleAccessor<dim, number>::set_force(const dealii::Tensor<1, dim, number> &force)
503 {
504 Assert(!properties.empty(), dealii::ExcInternalError());
505 for (int dimension = 0; dimension < dim; ++dimension)
506 properties[SphericalParticle<dim, number>::Properties::force + dimension] = force[dimension];
507 }
508
509 template <int dim, typename number>
510 void
511 DEMParticleAccessor<dim, number>::add_force(const dealii::Tensor<1, dim, number> &force)
512 {
513 Assert(!properties.empty(), dealii::ExcInternalError());
514 for (int dimension = 0; dimension < dim; ++dimension)
515 properties[SphericalParticle<dim, number>::Properties::force + dimension] += force[dimension];
516 }
517
518 template <int dim, typename number>
519 number &
520 DEMParticleAccessor<dim, number>::torque(const unsigned int dimension)
521 {
522 AssertIndexRange(dimension, axial_dim<dim>);
523 return properties[SphericalParticle<dim, number>::Properties::torque + dimension];
524 }
525
526 template <int dim, typename number>
527 const number &
528 DEMParticleAccessor<dim, number>::torque(const unsigned int dimension) const
529 {
530 AssertIndexRange(dimension, axial_dim<dim>);
531 return properties[SphericalParticle<dim, number>::Properties::torque + dimension];
532 }
533
534 template <int dim, typename number>
535 dealii::Tensor<1, axial_dim<dim>, number>
537 {
538 dealii::Tensor<1, axial_dim<dim>, number> torque_vector;
539 for (unsigned int dimension = 0; dimension < axial_dim<dim>; ++dimension)
540 torque_vector[dimension] = torque(dimension);
541 return torque_vector;
542 }
543
544 template <int dim, typename number>
545 void
547 const dealii::Tensor<1, axial_dim<dim>, number> &torque)
548 {
549 Assert(!properties.empty(), dealii::ExcInternalError());
550 for (int dimension = 0; dimension < axial_dim<dim>; ++dimension)
552 torque[dimension];
553 }
554
555 template <int dim, typename number>
556 void
558 const dealii::Tensor<1, axial_dim<dim>, number> &torque)
559 {
560 Assert(!properties.empty(), dealii::ExcInternalError());
561 for (int dimension = 0; dimension < axial_dim<dim>; ++dimension)
563 torque[dimension];
564 }
565
566 template <int dim, typename number>
567 dealii::types::particle_index
569 {
570 return particle_id;
571 }
572
573 template <int dim, typename number>
574 dealii::types::particle_index
576 {
577 Assert(local_particle_id != dealii::numbers::invalid_unsigned_int,
578 dealii::ExcMessage("The local particle ID is only valid for locally owned particles."));
579 return local_particle_id;
580 }
581
582 template <int dim, typename number>
583 number &
588
589 template <int dim, typename number>
590 const number &
595
596
597 template <int dim, typename number>
598 number &
603
604 template <int dim, typename number>
605 const number &
610
611 template <int dim, typename number>
612 number &
617
618 template <int dim, typename number>
619 const number &
624
625
626 template <int dim, typename number>
627 number &
629 const typename SphericalParticle<dim, number>::Properties property)
630 {
631 Assert(!properties.empty(), dealii::ExcInternalError());
632 return properties[property];
633 }
634
635 template <int dim, typename number>
636 const number &
638 const typename SphericalParticle<dim, number>::Properties property) const
639 {
640 Assert(!properties.empty(), dealii::ExcInternalError());
641 return properties[property];
642 }
643
644 template <int dim, typename number>
645 typename dealii::Triangulation<dim>::active_cell_iterator
647 {
648 Assert(surrounding_cell.state() == dealii::IteratorState::valid,
649 dealii::ExcMessage("The surrounding cell is only valid for locally owned particles."));
650 return surrounding_cell;
651 }
652} // namespace MeltPoolDG
Definition particle_accessor.hpp:20
dealii::types::particle_index local_id() const
Definition particle_accessor.hpp:575
number & angular_acceleration(const unsigned int dimension)
Definition particle_accessor.hpp:439
DEMParticleAccessor & operator=(const DEMParticleAccessor &other) noexcept=default
dealii::Tensor< 1, axial_dim< dim >, number > torque() const
Definition particle_accessor.hpp:536
dealii::types::particle_index local_particle_id
Definition particle_accessor.hpp:342
void add_force(const dealii::Tensor< 1, dim, number > &force)
Definition particle_accessor.hpp:511
number & radius()
Definition particle_accessor.hpp:584
DEMParticleAccessor(const DEMParticleAccessor &other) noexcept=default
dealii::Tensor< 1, axial_dim< dim >, number > get_angular_velocity() const
Definition particle_accessor.hpp:427
dealii::Point< dim, number > & get_location()
Definition particle_accessor.hpp:376
dealii::Tensor< 1, axial_dim< dim >, number > angular_velocity() const
Definition particle_accessor.hpp:463
number & mass()
Definition particle_accessor.hpp:599
dealii::ArrayView< number > properties
View to the particle properties (velocity, force etc.).
Definition particle_accessor.hpp:331
dealii::types::particle_index id() const
Definition particle_accessor.hpp:568
void set_torque(const dealii::Tensor< 1, axial_dim< dim >, number > &torque)
Definition particle_accessor.hpp:546
dealii::Tensor< 1, dim, number > force() const
Definition particle_accessor.hpp:492
dealii::Tensor< 1, dim, number > linear_velocity() const
Definition particle_accessor.hpp:390
dealii::types::particle_index particle_id
The global unique identifier of the particle.
Definition particle_accessor.hpp:338
number & density()
Definition particle_accessor.hpp:613
void add_torque(const dealii::Tensor< 1, axial_dim< dim >, number > &torque)
Definition particle_accessor.hpp:557
number & get_property(const typename SphericalParticle< dim, number >::Properties property)
Definition particle_accessor.hpp:628
void set_force(const dealii::Tensor< 1, dim, number > &force)
Definition particle_accessor.hpp:502
DEMParticleAccessor(dealii::Particles::ParticleAccessor< dim > &particle)
Definition particle_accessor.hpp:347
std::reference_wrapper< dealii::Point< dim, number > > location
Reference to the particle location.
Definition particle_accessor.hpp:328
dealii::Triangulation< dim >::active_cell_iterator get_surrounding_cell() const
Definition particle_accessor.hpp:646
dealii::Triangulation< dim >::active_cell_iterator surrounding_cell
Definition particle_accessor.hpp:335
number & linear_acceleration(const unsigned int dimension)
Definition particle_accessor.hpp:419
DEMParticleAccessor & operator=(DEMParticleAccessor &&other) noexcept=default
DEMParticleAccessor(DEMParticleAccessor &&other) noexcept=default
Class representing a finite-sized spherical particle, intended for use with the obstacle field class.
Definition particle.hpp:35
Properties
Enum to define the index of each property in the particle's property vector.
Definition particle.hpp:54
Interface for a general preconditioner.
Definition boundary_condition_functions.hpp:17