![]() |
MFEM v4.9.0
Finite element discretization library
|
ParticleSet initializes and manages data associated with particles. More...
#include <particleset.hpp>
Public Types | |
| using | IDType = unsigned long long |
Public Member Functions | |
| ParticleSet (int num_particles, int dim, Ordering::Type coords_ordering=Ordering::byVDIM) | |
| Construct a serial ParticleSet. | |
| ParticleSet (int num_particles, int dim, const Array< int > &field_vdims, int num_tags, Ordering::Type all_ordering=Ordering::byVDIM) | |
| Construct a serial ParticleSet with specified fields and tags at construction. | |
| ParticleSet (int num_particles, int dim, const Array< int > &field_vdims, const Array< const char * > &field_names_, int num_tags, const Array< const char * > &tag_names_, Ordering::Type all_ordering=Ordering::byVDIM) | |
| Construct a serial ParticleSet with specified fields and tags at construction, with names. | |
| ParticleSet (int num_particles, int dim, Ordering::Type coords_ordering, const Array< int > &field_vdims, const Array< Ordering::Type > &field_orderings, const Array< const char * > &field_names_, int num_tags, const Array< const char * > &tag_names_) | |
| Comprehensive serial constructor of ParticleSet. | |
| ParticleSet (MPI_Comm comm_, int rank_num_particles, int dim, Ordering::Type coords_ordering=Ordering::byVDIM) | |
| Construct a parallel ParticleSet. | |
| ParticleSet (MPI_Comm comm_, int rank_num_particles, int dim, const Array< int > &field_vdims, int num_tags, Ordering::Type all_ordering=Ordering::byVDIM) | |
| Construct a parallel ParticleSet with specified fields and tags at construction. | |
| ParticleSet (MPI_Comm comm_, int rank_num_particles, int dim, const Array< int > &field_vdims, const Array< const char * > &field_names_, int num_tags, const Array< const char * > &tag_names_, Ordering::Type all_ordering=Ordering::byVDIM) | |
| Construct a parallel ParticleSet with specified fields and tags at construction, with names (for PrintCSV()). | |
| ParticleSet (MPI_Comm comm_, int rank_num_particles, int dim, Ordering::Type coords_ordering, const Array< int > &field_vdims, const Array< Ordering::Type > &field_orderings, const Array< const char * > &field_names_, int num_tags, const Array< const char * > &tag_names_) | |
| Comprehensive parallel constructor of ParticleSet. | |
| MPI_Comm | GetComm () const |
| Get the MPI communicator for this ParticleSet. | |
| IDType | GetGlobalNParticles () const |
| Get the global number of active particles across all ranks. | |
| int | GetDim () const |
| Get the spatial dimension. | |
| const Array< IDType > & | GetIDs () const |
| Get the global IDs of the active particles owned by this ParticleSet. | |
| int | AddField (int vdim, Ordering::Type field_ordering=Ordering::byVDIM, const char *field_name=nullptr) |
| Add a field to the ParticleSet. | |
| int | AddNamedField (int vdim, const char *field_name, Ordering::Type field_ordering=Ordering::byVDIM) |
| Add a field to the ParticleSet. | |
| int | AddTag (const char *tag_name=nullptr) |
| Add a tag to the ParticleSet. | |
| void | Reserve (int res) |
Reserve memory for res particles. | |
| int | GetNParticles () const |
| Get the number of active particles currently held by this ParticleSet. | |
| int | GetNFields () const |
| Get the number of fields registered to particles. | |
| const Array< int > | GetFieldVDims () const |
| Get an Array<int> of the field vector-dimensions registered to particles. | |
| int | FieldVDim (int f) const |
| Get Field vector-dimension. | |
| int | GetNTags () const |
| Get the number of tags registered to particles. | |
| void | AddParticle (const Particle &p) |
| Add a particle using Particle . | |
| void | AddParticles (int num_particles, Array< int > *new_indices=nullptr) |
Add num_particles particles, and optionally get the local indices of new particles in new_indices . | |
| void | RemoveParticles (const Array< int > &list) |
Remove particle data specified by list of particle indices. | |
| ParticleVector & | Coords () |
| Get a reference to the coordinates ParticleVector. | |
| const ParticleVector & | Coords () const |
| Get a const reference to the coordinates ParticleVector. | |
| ParticleVector & | Field (int f) |
Get a reference to field f 's ParticleVector. | |
| const ParticleVector & | Field (int f) const |
Get a const reference to field f 's ParticleVector. | |
| Array< int > & | Tag (int t) |
Get a reference to tag t 's Array<int>. | |
| const Array< int > & | Tag (int t) const |
Get a const reference to tag t 's Array<int>. | |
| Particle | GetParticle (int i) const |
Get new Particle object with copy of data associated with particle i . | |
| Particle | GetParticleRef (int i) |
Get Particle object whose members reference the actual data associated with particle i in this ParticleSet. | |
| bool | IsParticleRefValid () const |
| Determine if GetParticleRef is valid. | |
| void | SetParticle (int i, const Particle &p) |
Set data for particle at index i with data from provided particle p. | |
| void | PrintCSV (const char *fname, int precision=16) |
| Print all particle data to a comma-delimited CSV file. | |
| void | PrintCSV (const char *fname, const Array< int > &field_idxs, const Array< int > &tag_idxs, int precision=16) |
Print only particle field and tags given by field_idxs and tag_idxs respectively to a CSV file. | |
| void | Redistribute (const Array< unsigned int > &rank_list) |
Redistribute particle data to rank_list. | |
| ~ParticleSet () | |
| Destructor. | |
| ParticleSet (const ParticleSet &)=delete | |
| ParticleSet & | operator= (const ParticleSet &)=delete |
Protected Member Functions | |
| void | AddParticles (const Array< IDType > &new_ids, Array< int > *new_indices=nullptr) |
Add particles with global identifiers new_ids and optionally get the local indices of new particles in new_indices . | |
| void | UpdateID (int local_idx, IDType new_global_id) |
| Update global ID of a particle. | |
| Particle | CreateParticle () const |
| Create a Particle object with the same spatial dimension, number of fields and field vdims, and number of tags as this ParticleSet. | |
| void | WriteToFile (const char *fname, const std::stringstream &ss_header, const std::stringstream &ss_data) |
Write string in ss_header , followed by ss_data , to a single file; compatible in parallel. | |
| bool | IsValidParticle (const Particle &p) const |
| Check if a particle could belong in this ParticleSet by comparing field and tag dimension. | |
| ParticleSet (int id_stride_, IDType id_counter_, int num_particles, int dim, Ordering::Type coords_ordering, const Array< int > &field_vdims, const Array< Ordering::Type > &field_orderings, const Array< const char * > &field_names_, int num_tags, const Array< const char * > &tag_names_) | |
| Hidden main constructor of ParticleSet. | |
Protected Attributes | |
| const int | id_stride |
| Stride for IDs (used internally when new particles are added). | |
| IDType | id_counter |
| Current globally unique ID to be assigned to the next particle added. | |
| Array< IDType > | ids |
| Global unique IDs of particles owned by this rank. | |
| ParticleVector | coords |
| Spatial coordinates of particles owned by this rank. | |
| std::vector< std::unique_ptr< ParticleVector > > | fields |
| All particle fields for particles owned by this rank. | |
| std::vector< std::unique_ptr< Array< int > > > | tags |
| All particle tags for particles owned by this rank. | |
| std::vector< std::string > | field_names |
| Field names, to be written when PrintCSV() is called. | |
| std::vector< std::string > | tag_names |
| Tag names, to be written when PrintCSV() is called. | |
| MPI_Comm | comm |
| struct gslib::crystal * | cr = nullptr |
| struct gslib::comm * | gsl_comm = nullptr |
ParticleSet initializes and manages data associated with particles.
Particles are inherently initialized to have a position and an ID, and optionally can have any number of Vector (of arbitrary vdim) and scalar integer data in the form of fields and tags respectively. All particle data are internally stored in a Struct-of-Arrays fashion, as elaborated on below.
Following the example in the Particle class, we will use the particles below to illustrate the data layout for coords, ids, fields, tags, field_names, and tag_names. In each case, the name of the field and tag is enclosed in '...' for clarity. Additionally, we assume for this example that the particle coordinates and the 'vel' field are ordered byVDIM in their respective ParticleVector.
Definition at line 248 of file particleset.hpp.
| using mfem::ParticleSet::IDType = unsigned long long |
Definition at line 251 of file particleset.hpp.
|
protected |
Hidden main constructor of ParticleSet.
| [in] | id_stride_ | ID stride. |
| [in] | id_counter_ | Starting ID counter. |
| [in] | num_particles | Number of particles to initialize. |
| [in] | dim | Particle spatial dimension. |
| [in] | coords_ordering | Ordering of coordinates |
| [in] | field_vdims | Array of field vector dimensions |
| [in] | field_orderings | Array of field ordering types. |
| [in] | field_names_ | Array of field names. |
| [in] | num_tags | Number of tags to register. |
| [in] | tag_names_ | Array of tag names. |
Definition at line 525 of file particleset.cpp.
| mfem::ParticleSet::ParticleSet | ( | int | num_particles, |
| int | dim, | ||
| Ordering::Type | coords_ordering = Ordering::byVDIM ) |
Construct a serial ParticleSet.
| [in] | num_particles | Number of particles to initialize. |
| [in] | dim | Particle spatial dimension. |
| [in] | coords_ordering | Ordering of coordinates. |
Definition at line 582 of file particleset.cpp.
| mfem::ParticleSet::ParticleSet | ( | int | num_particles, |
| int | dim, | ||
| const Array< int > & | field_vdims, | ||
| int | num_tags, | ||
| Ordering::Type | all_ordering = Ordering::byVDIM ) |
Construct a serial ParticleSet with specified fields and tags at construction.
| [in] | num_particles | Number of particles to initialize. |
| [in] | dim | Particle spatial dimension. |
| [in] | field_vdims | Array of field vector dimensions. |
| [in] | num_tags | Number of tags to register. |
| [in] | all_ordering | (Optional) Ordering of coordinates and field ParticleVector. |
Definition at line 591 of file particleset.cpp.
| mfem::ParticleSet::ParticleSet | ( | int | num_particles, |
| int | dim, | ||
| const Array< int > & | field_vdims, | ||
| const Array< const char * > & | field_names_, | ||
| int | num_tags, | ||
| const Array< const char * > & | tag_names_, | ||
| Ordering::Type | all_ordering = Ordering::byVDIM ) |
Construct a serial ParticleSet with specified fields and tags at construction, with names.
| [in] | num_particles | Number of particles to initialize. |
| [in] | dim | Particle spatial dimension. |
| [in] | field_vdims | Array of field vector dimensions. |
| [in] | field_names_ | Array of field names. |
| [in] | num_tags | Number of tags to register. |
| [in] | tag_names_ | Array of tag names. |
| [in] | all_ordering | (Optional) Ordering of coordinates and field ParticleVector. |
Definition at line 601 of file particleset.cpp.
| mfem::ParticleSet::ParticleSet | ( | int | num_particles, |
| int | dim, | ||
| Ordering::Type | coords_ordering, | ||
| const Array< int > & | field_vdims, | ||
| const Array< Ordering::Type > & | field_orderings, | ||
| const Array< const char * > & | field_names_, | ||
| int | num_tags, | ||
| const Array< const char * > & | tag_names_ ) |
Comprehensive serial constructor of ParticleSet.
| [in] | num_particles | Number of particles to initialize. |
| [in] | dim | Particle spatial dimension. |
| [in] | coords_ordering | Ordering of coordinates. |
| [in] | field_vdims | Array of field vector dimensions. |
| [in] | field_orderings | Array of field ordering types. |
| [in] | field_names_ | Array of field names. |
| [in] | num_tags | Number of tags to register. |
| [in] | tag_names_ | Array of tag names. |
Definition at line 614 of file particleset.cpp.
| mfem::ParticleSet::ParticleSet | ( | MPI_Comm | comm_, |
| int | rank_num_particles, | ||
| int | dim, | ||
| Ordering::Type | coords_ordering = Ordering::byVDIM ) |
Construct a parallel ParticleSet.
| [in] | comm_ | MPI communicator. |
| [in] | rank_num_particles | Number of particles to initialize. |
| [in] | dim | Particle spatial dimension. |
| [in] | coords_ordering | (Optional) Ordering of coordinates. |
Definition at line 629 of file particleset.cpp.
| mfem::ParticleSet::ParticleSet | ( | MPI_Comm | comm_, |
| int | rank_num_particles, | ||
| int | dim, | ||
| const Array< int > & | field_vdims, | ||
| int | num_tags, | ||
| Ordering::Type | all_ordering = Ordering::byVDIM ) |
Construct a parallel ParticleSet with specified fields and tags at construction.
| [in] | comm_ | MPI communicator. |
| [in] | rank_num_particles | # of particles to initialize on this rank. |
| [in] | dim | Particle spatial dimension. |
| [in] | field_vdims | Array of field vector dimensions. |
| [in] | num_tags | Number of tags to register. |
| [in] | all_ordering | (Optional) Ordering of coordinates and field ParticleVector. |
Definition at line 638 of file particleset.cpp.
| mfem::ParticleSet::ParticleSet | ( | MPI_Comm | comm_, |
| int | rank_num_particles, | ||
| int | dim, | ||
| const Array< int > & | field_vdims, | ||
| const Array< const char * > & | field_names_, | ||
| int | num_tags, | ||
| const Array< const char * > & | tag_names_, | ||
| Ordering::Type | all_ordering = Ordering::byVDIM ) |
Construct a parallel ParticleSet with specified fields and tags at construction, with names (for PrintCSV()).
| [in] | comm_ | MPI communicator. |
| [in] | rank_num_particles | # of particles to initialize on this rank. |
| [in] | dim | Particle spatial dimension. |
| [in] | field_vdims | Array of field vector dimension. |
| [in] | field_names_ | Array of field names. |
| [in] | num_tags | Number of tags to register. |
| [in] | tag_names_ | Array of tag names. |
| [in] | all_ordering | (Optional) Ordering of coordinates and field ParticleVector. |
Definition at line 649 of file particleset.cpp.
| mfem::ParticleSet::ParticleSet | ( | MPI_Comm | comm_, |
| int | rank_num_particles, | ||
| int | dim, | ||
| Ordering::Type | coords_ordering, | ||
| const Array< int > & | field_vdims, | ||
| const Array< Ordering::Type > & | field_orderings, | ||
| const Array< const char * > & | field_names_, | ||
| int | num_tags, | ||
| const Array< const char * > & | tag_names_ ) |
Comprehensive parallel constructor of ParticleSet.
| [in] | comm_ | MPI communicator. |
| [in] | rank_num_particles | # of particles to initialize on this rank. |
| [in] | dim | Particle spatial dimension. |
| [in] | coords_ordering | Ordering of coordinates. |
| [in] | field_vdims | Array of field vector dimensions. |
| [in] | field_orderings | Array of field ordering types. |
| [in] | field_names_ | Array of field names. |
| [in] | num_tags | Number of tags to register. |
| [in] | tag_names_ | Array of tag names. |
Definition at line 662 of file particleset.cpp.
| mfem::ParticleSet::~ParticleSet | ( | ) |
Destructor.
Definition at line 933 of file particleset.cpp.
|
delete |
| int mfem::ParticleSet::AddField | ( | int | vdim, |
| Ordering::Type | field_ordering = Ordering::byVDIM, | ||
| const char * | field_name = nullptr ) |
Add a field to the ParticleSet.
| [in] | vdim | Vector dimension of the field. |
| [in] | field_ordering | (Optional) Ordering::Type of the field. |
| [in] | field_name | (Optional) Name of the field. |
Definition at line 698 of file particleset.cpp.
|
inline |
Add a field to the ParticleSet.
Same as AddField() but with different parameter order for convenience
Definition at line 558 of file particleset.hpp.
| void mfem::ParticleSet::AddParticle | ( | const Particle & | p | ) |
Add a particle using Particle .
Definition at line 726 of file particleset.cpp.
|
protected |
Add particles with global identifiers new_ids and optionally get the local indices of new particles in new_indices .
Note the data of new particles is uninitialized and must be set.
Definition at line 211 of file particleset.cpp.
| void mfem::ParticleSet::AddParticles | ( | int | num_particles, |
| Array< int > * | new_indices = nullptr ) |
Add num_particles particles, and optionally get the local indices of new particles in new_indices .
The data of new particles is uninitialized and must be set.
Definition at line 741 of file particleset.cpp.
| int mfem::ParticleSet::AddTag | ( | const char * | tag_name = nullptr | ) |
Add a tag to the ParticleSet.
| [in] | tag_name | (Optional) Name of the tag. |
Definition at line 713 of file particleset.cpp.
|
inline |
Get a reference to the coordinates ParticleVector.
Definition at line 606 of file particleset.hpp.
|
inline |
Get a const reference to the coordinates ParticleVector.
Definition at line 609 of file particleset.hpp.
|
protected |
Create a Particle object with the same spatial dimension, number of fields and field vdims, and number of tags as this ParticleSet.
Definition at line 469 of file particleset.cpp.
|
inline |
Get a reference to field f 's ParticleVector.
Definition at line 612 of file particleset.hpp.
|
inline |
Get a const reference to field f 's ParticleVector.
Definition at line 615 of file particleset.hpp.
|
inline |
Get Field vector-dimension.
Definition at line 586 of file particleset.hpp.
|
inline |
Get the MPI communicator for this ParticleSet.
Definition at line 531 of file particleset.hpp.
|
inline |
Get the spatial dimension.
Definition at line 537 of file particleset.hpp.
| const Array< int > mfem::ParticleSet::GetFieldVDims | ( | ) | const |
Get an Array<int> of the field vector-dimensions registered to particles.
Definition at line 201 of file particleset.cpp.
| ParticleSet::IDType mfem::ParticleSet::GetGlobalNParticles | ( | ) | const |
Get the global number of active particles across all ranks.
Definition at line 688 of file particleset.cpp.
Get the global IDs of the active particles owned by this ParticleSet.
Definition at line 540 of file particleset.hpp.
|
inline |
Get the number of fields registered to particles.
Definition at line 580 of file particleset.hpp.
|
inline |
Get the number of active particles currently held by this ParticleSet.
Definition at line 577 of file particleset.hpp.
|
inline |
Get the number of tags registered to particles.
Definition at line 589 of file particleset.hpp.
| Particle mfem::ParticleSet::GetParticle | ( | int | i | ) | const |
Get new Particle object with copy of data associated with particle i .
Definition at line 772 of file particleset.cpp.
| Particle mfem::ParticleSet::GetParticleRef | ( | int | i | ) |
Get Particle object whose members reference the actual data associated with particle i in this ParticleSet.
Definition at line 807 of file particleset.cpp.
| bool mfem::ParticleSet::IsParticleRefValid | ( | ) | const |
Determine if GetParticleRef is valid.
If coordinates and all fields are ordered byVDIM, then returns true. Otherwise, false.
Definition at line 791 of file particleset.cpp.
|
protected |
Check if a particle could belong in this ParticleSet by comparing field and tag dimension.
Definition at line 556 of file particleset.cpp.
|
delete |
| void mfem::ParticleSet::PrintCSV | ( | const char * | fname, |
| const Array< int > & | field_idxs, | ||
| const Array< int > & | tag_idxs, | ||
| int | precision = 16 ) |
Print only particle field and tags given by field_idxs and tag_idxs respectively to a CSV file.
Definition at line 863 of file particleset.cpp.
| void mfem::ParticleSet::PrintCSV | ( | const char * | fname, |
| int | precision = 16 ) |
Print all particle data to a comma-delimited CSV file.
The first row contains the header. We include the particle ID, owning rank (in parallel), coordinates, followed by all fields and tags.
The output can be visualized in Paraview by loading the csv files, and applying the "Table To Points" filter.
Definition at line 846 of file particleset.cpp.
| DO_NOT_DOCUMENT void mfem::ParticleSet::Redistribute | ( | const Array< unsigned int > & | rank_list | ) |
Redistribute particle data to rank_list.
| [in] | rank_list | Array of size GetNParticles() denoting ultimate destination of particle data. Index = this rank means no data is moved. |
Definition at line 436 of file particleset.cpp.
| void mfem::ParticleSet::RemoveParticles | ( | const Array< int > & | list | ) |
Remove particle data specified by list of particle indices.
Definition at line 753 of file particleset.cpp.
| void mfem::ParticleSet::Reserve | ( | int | res | ) |
Reserve memory for res particles.
Can help to avoid re-allocation for adding + removing particles.
Definition at line 182 of file particleset.cpp.
| void mfem::ParticleSet::SetParticle | ( | int | i, |
| const Particle & | p ) |
Set data for particle at index i with data from provided particle p.
Definition at line 828 of file particleset.cpp.
|
inline |
Get a reference to tag t 's Array<int>.
Definition at line 618 of file particleset.hpp.
|
inline |
Get a const reference to tag t 's Array<int>.
Definition at line 621 of file particleset.hpp.
|
inlineprotected |
Update global ID of a particle.
This method updates the global ID of the particle at given local index after Redistribute().
Definition at line 371 of file particleset.hpp.
|
protected |
Write string in ss_header , followed by ss_data , to a single file; compatible in parallel.
Definition at line 474 of file particleset.cpp.
|
protected |
Definition at line 335 of file particleset.hpp.
|
protected |
Spatial coordinates of particles owned by this rank.
For the sample_particleset_data, coords would be coords=(x0,y0,x1,y1,x2,y2) assuming coords ordering is byVDIM.
Definition at line 294 of file particleset.hpp.
|
protected |
Definition at line 339 of file particleset.hpp.
|
protected |
Field names, to be written when PrintCSV() is called.
For the sample_particleset_data, field_names would be field_names[0]='mass', field_names[1]='vel'.
Definition at line 316 of file particleset.hpp.
|
protected |
All particle fields for particles owned by this rank.
For the sample_particleset_data, fields would be *fields[0]=(m0,m1,m2), *fields[1]=(vx0,vy0,vx1,vy1,vx2,vy2) assuming fields[1] ordering is byVDIM.
Definition at line 302 of file particleset.hpp.
|
protected |
Definition at line 340 of file particleset.hpp.
|
protected |
Current globally unique ID to be assigned to the next particle added.
In parallel, this starts locally as the rank and increments with id_stride, ensuring a global unique identifier whenever a particle is added.
Definition at line 280 of file particleset.hpp.
|
protected |
Stride for IDs (used internally when new particles are added).
In parallel, this defaults to the number of MPI ranks.
Definition at line 273 of file particleset.hpp.
Global unique IDs of particles owned by this rank.
For the sample_particleset_data, ids would be ids[0]=id0, ids[1]=id1, ids[2]=id2.
Definition at line 287 of file particleset.hpp.
|
protected |
Tag names, to be written when PrintCSV() is called.
For the sample_particleset_data, tag_names would be tag_names[0]='type', tag_names[1]='color'.
Definition at line 323 of file particleset.hpp.
|
protected |
All particle tags for particles owned by this rank.
For the sample_particleset_data, tags would be *tags[0]=(t0,t1,t2), *tags[1]=(c0,c1,c2).
Definition at line 309 of file particleset.hpp.