NetDEM v1.0
Loading...
Searching...
No Matches
particle.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "mini_map.hpp"
4#include "neigh_tuple.hpp"
5#include "shape.hpp"
6#include "shape_trimesh.hpp"
7#include <unordered_map>
8
9namespace netdem {
10
11class Wall;
12class ContactPP;
13class ContactPW;
14
15class Cell;
16class CellManager;
17class Domain;
18class DomainManager;
19class MPIManager;
20class DEMSolver;
21
22class NeighPofP;
23class NeighWofP;
24class NeighPofW;
25
26class Particle {
27public:
28 friend class Wall;
29 friend class Cell;
30 friend class Domain;
31 friend class MPIManager;
32 friend class DEMSolver;
33 friend class NeighPofP;
34 friend class NeighWofP;
35 friend class NeighPofW;
36
40 int id{0};
41
45 Shape *shape{nullptr};
46
50 Vec3d bound_min{0, 0, 0};
51
55 Vec3d bound_max{0, 0, 0};
56
60 double margin{0};
61
65 Vec3d bound_disp{0, 0, 0};
66
71
72protected:
77 double density{2650};
78
79public:
83 double mass{0.0};
84
89
93 double damp_viscous{0};
94
98 double damp_numerical{0};
99
103 Vec3d pos{0, 0, 0};
104
108 Vec4d quaternion{1, 0, 0, 0};
109
113 Vec3d vel{0, 0, 0};
114
118 Vec3d spin{0, 0, 0};
119
123 Vec3d vel_m0p5{0, 0, 0};
124
129
133 Vec3d force{0, 0, 0};
134
138 Vec3d moment{0, 0, 0};
139
144
149 bool enable_bound_aabb{false};
150
156
157protected:
162
168
174
180
186
190 bool is_on_edge{false};
191
195 bool need_send_out{false};
196
201
202public:
208
209protected:
215
216public:
220 Particle();
221
229 Particle(Shape *const shape);
230
237 virtual Particle *Clone() const;
238
243 virtual void Init();
244
251 virtual void SetShape(Shape *const shape);
252
258 virtual void SetDensity(double dens);
259
265 virtual double GetDensity() const;
266
272 virtual void SetMargin(double m);
273
279 virtual double GetMargin() const;
280
288 virtual void SetForce(double fx, double fy, double fz);
289
297 virtual void SetMoment(double mx, double my, double mz);
298
306 virtual void SetPosition(double pos_x, double pos_y, double pos_z);
307
317 virtual void SetRodrigues(double angle, double axis_x, double axis_y,
318 double axis_z);
319
328 virtual void SetQuaternion(double q_0, double q_1, double q_2, double q_3);
329
337 virtual void SetVelocity(double v_x, double v_y, double v_z);
338
346 virtual void SetSpin(double spin_x, double spin_y, double spin_z);
347
354 virtual Vec3d GetVelocity(Vec3d const &cnt_pos);
355
362 virtual void SetDynamicProperty(std::string const &key, double value);
363
370 virtual double GetDynamicProperty(std::string const &key);
371
377 virtual void AddForce(const Vec3d &force);
378
384 virtual void AddMoment(const Vec3d &moment);
385
391 virtual void AddForceAtomic(const Vec3d &f);
392
398 virtual void AddMomentAtomic(const Vec3d &m);
399
403 virtual void ClearForce();
404
408 virtual void ClearMoment();
409
416 virtual void ApplyContactForce(ContactPP const *cnt);
417
424 virtual void ApplyContactForce(ContactPW const *cnt);
425
429 virtual void UpdateContactForce();
430
437 virtual void UpdateMotion(double timestep);
438
444 virtual void UpdateBoundFast();
445
451 virtual void UpdateBound();
452
453protected:
457 void RemoveLinkedCell(int lookup_id);
458
462 void RemoveLinkedDomain(int lookup_id);
463
467 void RemoveLinkedParticle(int lookup_id);
468
472 void RemoveLinkedWall(int lookup_id);
473
477 void RemoveContactRefPP(int lookup_id);
478
482 void RemoveContactRefPW(int lookup_id);
483
484public:
488 void ClearLinkedCells();
489
493 void ClearLinkedDomains();
494
498 void ClearLinkedNeighs();
499
504
509
517 void UpdateLinkedDomains(DomainManager *const dm);
518
526 void UpdateLinkedCells(CellManager *const cm);
527
534 void UpdateLinkedNeighs(Domain *const domain);
535
542
551
557
563
569
575
579 NeighPofP *const GetLinkedParticle(int lookup_id);
580
584 NeighWofP *const GetLinkedWall(int lookup_id);
585
586protected:
590 NeighPofP *const GetLinkedContactRefPP(int lookup_id);
591
595 NeighWofP *const GetLinkedContactRefPW(int lookup_id);
596
597public:
601 virtual void UpdateSTLModel();
602
611 virtual STLModel GetSTLModel(int num_nodes = 200);
612
621 virtual STLModel *GetSTLModelInternal();
622
629 virtual void SaveAsVTK(std::string const &filename);
630
634 virtual void Print() const;
635
640 virtual ~Particle();
641
642public:
653
663 NeighWofP *LinkToWall(Wall *const w);
664
672 int LinkToCell(Cell *const cell);
673
681 int LinkToDomain(Domain *const domain);
682
683protected:
693 NeighPofP *BuildContactRefPP(Particle *const q, ContactPP *const cnt);
694
705 NeighWofP *BuildContactRefPW(Wall *const w, ContactPW *const cnt);
706
707public:
717 int FindLinkedParticle(Particle *const q);
718
727 int FindLinkedWall(Wall *const w);
728
729protected:
739 int FindContactRefPP(Particle *const q);
740
750 int FindContactRefPW(Wall *const w);
751};
752
753} // namespace netdem
A class representing a cell in a simulation grid.
Definition cell.hpp:19
A class responsible for managing cells in a simulation grid.
Definition cell_manager.hpp:16
A class representing a contact between two particles.
Definition contact_pp.hpp:20
A class representing a contact between a particle and a wall.
Definition contact_pw.hpp:22
A solver class for performing discrete element method (DEM) simulations.
Definition dem_solver.hpp:23
Class for managing the simulation domain and particles that belong to it.
Definition domain.hpp:24
A class that manages the domain and sub-domains for a DEM simulation.
Definition domain_manager.hpp:18
Manages the data exchange in a DEM simulation.
Definition mpi_manager.hpp:39
Definition mini_map.hpp:17
A class representing a particle in contact with another particle or wall.
Definition neigh_tuple.hpp:25
A class representing a particle in contact with a wall.
Definition neigh_tuple.hpp:175
A class representing a wall in contact with a particle.
Definition neigh_tuple.hpp:99
Definition particle.hpp:26
void ClearLinkedNeighs()
Clear the linked neighbors of the particle.
Definition particle.cpp:530
Vec3d bound_disp
The displacement of the particle's bounds for the linked list.
Definition particle.hpp:65
VecXT< NeighWofP > const & GetLinkedWalls()
Gets a vector of pointers to the walls that may be potentially overlapped this wall.
Definition particle.cpp:775
int LinkToDomain(Domain *const domain)
Create a link between this particle and the given domain and return the look up id.
Definition particle.cpp:942
virtual void ClearMoment()
Clear all moments applied to the particle.
Definition particle.cpp:180
virtual void SetQuaternion(double q_0, double q_1, double q_2, double q_3)
Sets the orientation of the particle using a quaternion.
Definition particle.cpp:103
NeighPofP * BuildContactRefPP(Particle *const q, ContactPP *const cnt)
Create a new contact lookup table entry for the given pair of particles q and cnt,...
Definition particle.cpp:953
virtual STLModel GetSTLModel(int num_nodes=200)
Get a copy of the particle's STL model as an object of type STLModel.
Definition particle.cpp:793
void ClearLinkedDomains()
Clear the linked domains of the particle.
Definition particle.cpp:521
MiniMap< std::string, double > dynamic_properties
Map of dynamic properties of the particle.
Definition particle.hpp:143
virtual void SetRodrigues(double angle, double axis_x, double axis_y, double axis_z)
Sets the orientation of the particle using a Rodrigues rotation vector.
Definition particle.cpp:95
VecXT< NeighPofP > linked_particle_list
List of linked particles used for narrow-phase contact detection with particles.
Definition particle.hpp:167
VecXT< NeighPofP > const & GetLinkedParticles()
Gets a vector of pointers to the particles that may be potentially overlapped this wall.
Definition particle.cpp:771
int LinkToCell(Cell *const cell)
Create a link between this particle and the given cell and return the look up id.
Definition particle.cpp:932
NeighPofP * LinkToParticle(Particle *const q)
Create a new neighbor tuple between this particle and the given particle q, and return the newly crea...
Definition particle.cpp:912
virtual void UpdateMotion(double timestep)
Update the motion of the particle based on the applied forces and moments over a time step.
Definition particle.cpp:245
virtual void UpdateBound()
Update the bounding box of the particle, which is useful for collision detection. The bounding box wi...
Definition particle.cpp:435
virtual void SetDensity(double dens)
Sets the density of the particle.
Definition particle.cpp:52
NeighWofP *const GetLinkedWall(int lookup_id)
Gets the neigh obj by look-up id.
Definition particle.cpp:781
int FindLinkedParticle(Particle *const q)
Find the index of the neighbor tuple belonging to this particle that is linked to the given particle ...
Definition particle.cpp:970
bool need_send_out
Flag indicating whether data needs to be sent out to linked domains.
Definition particle.hpp:195
void ClearContactRefTable()
Clear the look-up table for contacts between particles.
Definition particle.cpp:573
VecXT< NeighWofP > contact_pw_ref_table
Lookup table used to reconstruct reference of contact history with walls.
Definition particle.hpp:185
VecXT< std::pair< Cell *, int > > linked_cell_list
List of linked cells used for broad-phase contact detection.
Definition particle.hpp:161
virtual void ApplyContactForce(ContactPP const *cnt)
Apply a contact force to the particle when it is in contact with another particle.
Definition particle.cpp:186
virtual void SetDynamicProperty(std::string const &key, double value)
Set the value of a dynamic property identified by the given key.
Definition particle.cpp:136
bool is_on_edge
Flag indicating whether particle is on domain edge.
Definition particle.hpp:190
virtual void SetShape(Shape *const shape)
Sets the Shape object representing the particle's shape.
Definition particle.cpp:29
virtual void SetPosition(double pos_x, double pos_y, double pos_z)
Sets the position of the particle.
Definition particle.cpp:83
Particle()
Default constructor for the Particle class.
Definition particle.cpp:18
Vec4d quaternion
The quaternion of the particle.
Definition particle.hpp:108
STLModel stl_model
STLModel object used for intersection-based contact detection and resolution.
Definition particle.hpp:214
virtual double GetDensity() const
Gets the density of the particle.
Definition particle.cpp:62
virtual void Print() const
Print information about the particle to the console.
Definition particle.cpp:891
Vec3d vel_m0p5
The square root velocity of the particle for half-step integration.
Definition particle.hpp:123
bool need_update_linked_list
Flag indicating whether linked-list algorithm should be used for broad-phase contact detection.
Definition particle.hpp:155
void UpdateLinkedNeighs(Domain *const domain)
Update the linked neighbors of the particle based on the given domain.
Definition particle.cpp:643
NeighWofP * BuildContactRefPW(Wall *const w, ContactPW *const cnt)
Create a new contact lookup table entry for the given wall w and contact point cnt,...
Definition particle.cpp:962
VecXT< ContactPW * > GetContactPWs()
Get a vector of pointers to all contact points between particles and walls.
Definition particle.cpp:748
virtual void UpdateBoundFast()
Update the bounding box of the particle, which is useful for collision detection. Particle has a skin...
Definition particle.cpp:414
virtual Vec3d GetVelocity(Vec3d const &cnt_pos)
Get the current velocity of the particle at the given position.
Definition particle.cpp:132
virtual void SaveAsVTK(std::string const &filename)
Save the particle's current state to a VTK file with the given filename.
Definition particle.cpp:803
void UpdateLinkedCells(CellManager *const cm)
Update the linked cells of the particle based on the given cell manager.
Definition particle.cpp:616
virtual double GetDynamicProperty(std::string const &key)
Get the value of a dynamic property identified by the given key.
Definition particle.cpp:140
void RemoveLinkedWall(int lookup_id)
Reomve a linked neighbor by look-up id.
Definition particle.cpp:482
virtual void SetVelocity(double v_x, double v_y, double v_z)
Sets the velocity of the particle.
Definition particle.cpp:112
virtual void AddMoment(const Vec3d &moment)
Add a moment (torque) to the particle.
Definition particle.cpp:150
double margin
The margin of the particle's shape.
Definition particle.hpp:60
int FindContactRefPW(Wall *const w)
Find the index of the contact lookup table entry belonging to this particle that references the given...
Definition particle.cpp:997
Vec3d moi_principal
The principal moment of inertia of the particle.
Definition particle.hpp:88
void RemoveLinkedCell(int lookup_id)
Reomve a linked cell by look-up id.
Definition particle.cpp:452
virtual STLModel * GetSTLModelInternal()
Get a copy of the particle's STL model as an object of type STLModel.
Definition particle.cpp:801
void RemoveContactRefPP(int lookup_id)
Reomve a p-p contact by look-up id.
Definition particle.cpp:492
double damp_numerical
The numerical damping coefficient of the particle.
Definition particle.hpp:98
NeighPofP *const GetLinkedParticle(int lookup_id)
Gets the neigh obj by look-up id.
Definition particle.cpp:777
VecXT< NeighPofP > contact_pp_ref_table
Lookup table used to reconstruct reference of contact history with particles.
Definition particle.hpp:179
virtual void AddMomentAtomic(const Vec3d &m)
Add a moment (torque) to the particle atomically.
Definition particle.cpp:165
void BuildContactRefTable()
Build a look-up table for contacts between particles.
Definition particle.cpp:556
void RemoveLinkedParticle(int lookup_id)
Reomve a linked neighbor by look-up id.
Definition particle.cpp:472
Vec3d pos
The position of the particle.
Definition particle.hpp:103
Vec3d bound_max
The maximum bounds of the particle's shape.
Definition particle.hpp:55
VecXT< ContactPP * > GetContactPPs()
Get a vector of pointers to all contact points between particles.
Definition particle.cpp:733
virtual void SetMargin(double m)
Sets the margin of the particle.
Definition particle.cpp:64
Vec3d spin_principal
The principal spin axis of the particle.
Definition particle.hpp:128
double damp_viscous
The viscous damping coefficient of the particle.
Definition particle.hpp:93
VecXT< NeighWofP > linked_wall_list
List of linked walls used for narrow-phase contact detection with walls.
Definition particle.hpp:173
double density
The density of the particle. Please use SetDensity to change its value.
Definition particle.hpp:77
virtual void ClearForce()
Clear all forces applied to the particle.
Definition particle.cpp:174
double mass
The mass of the particle.
Definition particle.hpp:83
void RemoveLinkedDomain(int lookup_id)
Reomve a linked domain by look-up id.
Definition particle.cpp:462
virtual double GetMargin() const
Gets the margin of the particle.
Definition particle.cpp:69
virtual void SetMoment(double mx, double my, double mz)
Sets the moment acting on the particle.
Definition particle.cpp:77
virtual void AddForce(const Vec3d &force)
Add a force to the particle.
Definition particle.cpp:144
int FindLinkedWall(Wall *const w)
Find the index of the neighbor tuple belonging to this particle that is linked to the given wall w.
Definition particle.cpp:979
NeighWofP * LinkToWall(Wall *const w)
Create a new neighbor tuple between this particle and the given wall w, and return the newly created ...
Definition particle.cpp:922
Vec3d moment
The moment acting on the particle.
Definition particle.hpp:138
virtual void SetSpin(double spin_x, double spin_y, double spin_z)
Sets the angular velocity (spin) of the particle.
Definition particle.cpp:122
virtual Particle * Clone() const
Creates a new instance of the Particle class that is a copy of the current instance.
Definition particle.cpp:25
void RemoveContactRefPW(int lookup_id)
Reomve a p-w contact by look-up id.
Definition particle.cpp:502
Shape * shape
The shape of the particle.
Definition particle.hpp:45
Vec3d vel
The velocity of the particle.
Definition particle.hpp:113
int material_type
The material type of the particle.
Definition particle.hpp:70
virtual void UpdateContactForce()
Update the contact forces applied to the particle.
Definition particle.cpp:221
virtual ~Particle()
Destroy the particle object and free any resources it might be holding.
Definition particle.cpp:905
Vec3d bound_min
The minimum bounds of the particle's shape.
Definition particle.hpp:50
VecXT< std::pair< Cell *, int > > const & GetLinkedCells()
Gets a vector of pointers to the cells that may be potentially overlapped this wall.
Definition particle.cpp:767
bool enable_bound_aabb
Flag indicating whether bounding sphere should be used to approximate axis-aligned bounding box (AABB...
Definition particle.hpp:149
VecXT< std::pair< Domain *, int > > linked_domain_list
List of linked domains that overlap with the particle.
Definition particle.hpp:200
virtual void Init()
Initializes the particle by setting default values for all properties.
Definition particle.cpp:27
virtual void AddForceAtomic(const Vec3d &f)
Add a force to the particle atomically.
Definition particle.cpp:156
int FindContactRefPP(Particle *const q)
Find the index of the contact lookup table entry belonging to this particle that references the given...
Definition particle.cpp:988
Vec3d force
The force acting on the particle.
Definition particle.hpp:133
NeighWofP *const GetLinkedContactRefPW(int lookup_id)
Gets the neigh obj by look-up id.
Definition particle.cpp:789
void ClearLinkedCells()
Clear the linked cells of the particle.
Definition particle.cpp:512
VecXT< std::pair< Domain *, int > > const & GetLinkedDomains()
Gets a vector of pointers to the domains that may be potentially overlapped this wall.
Definition particle.cpp:763
virtual void UpdateSTLModel()
Update the geometry of the particle's STL model.
Definition particle.cpp:726
void UpdateLinkedDomains(DomainManager *const dm)
Update the linked domains of the particle based on the given domain manager.
Definition particle.cpp:601
virtual void SetForce(double fx, double fy, double fz)
Sets the force acting on the particle.
Definition particle.cpp:71
bool need_update_stl_model
Flag indicating whether STl model intersection-based contact detection and resolution is needed.
Definition particle.hpp:207
NeighPofP *const GetLinkedContactRefPP(int lookup_id)
Gets the neigh obj by look-up id.
Definition particle.cpp:785
Vec3d spin
The spin of the particle.
Definition particle.hpp:118
Class for working with STL models.
Definition stl_model.hpp:17
This class represents different types of shapes and performs various calculations on them.
Definition shape.hpp:15
A class representing a wall object in a physics simulation.
Definition wall.hpp:32
Definition bond_entry.hpp:7
std::vector< T > VecXT
Definition utils_macros.hpp:31
std::array< double, 3 > Vec3d
Definition utils_macros.hpp:18
std::array< double, 4 > Vec4d
Definition utils_macros.hpp:19