MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
particlevector.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_PARTICLEVECTOR
13#define MFEM_PARTICLEVECTOR
14
15#include "ordering.hpp"
16#include "vector.hpp"
17
18namespace mfem
19{
20
21/** \brief ParticleVector carries vector data (of a given vector dimension) for
22 * an arbitrary number of particles. Data is stored contiguously in memory in
23 * an either
24 * byNODES (x0,x1,x2,...,xN,y0,y1,y2...yN,z0.....zN) or
25 * byVDIM (x0,y0,z0,...,xN,yN,zN) ordering,
26 * where N+1 is the number of particles.
27 * ParticleVector provides convenient methods for accessing and manipulating
28 * data for individual particles (e.g., \ref GetValues) or
29 * components across all particles (e.g., \ref GetComponents).
30 *
31 * Note that, since ParticleVector inherits from Vector, all Vector operations
32 * (e.g., device support) are available. We do recommend use of the
33 * methods \ref SetNumParticles and \ref SetVDim for manipulating container
34 * size, instead of \ref Vector::SetSize, to ensure consistency.
35 */
36class ParticleVector : public Vector
37{
38protected:
39
40 /// Vector dimension.
41 int vdim;
42
43 /// Ordering of Vector data in ParticleVector.
45
46 /// Re-allocate + copy memory. See Array::GrowSize.
47 void GrowSize(int min_num_vectors, bool keep_data);
48
49public:
50
51 using Vector::operator=;
52 using Vector::operator();
53
55
56 /// Initialize an empty ParticleVector of vdim \p vdim_ with
57 /// ordering \p ordering_.
58 ParticleVector(int vdim_, Ordering::Type ordering_);
59
60 /// Initialize a ParticleVector with \p num_particles vectors each of size
61 /// \p vdim_ ordered \p ordering_.
62 ParticleVector(int vdim_, Ordering::Type ordering_, int num_particles);
63
64 /// Initialize a ParticleVector of vdim \p vdim_ with ordering
65 /// \p ordering_ , initialized with copy of data in \p vec .
66 ParticleVector(int vdim_, Ordering::Type ordering_, const Vector &vec);
67
68 /// Get the Vector dimension of the ParticleVector.
69 int GetVDim() const { return vdim; }
70
71 /// Get the ordering of data in the ParticleVector.
73
74 /// Get the number of particle data in the ParticleVector.
75 int GetNumParticles() const { return Size()/vdim; }
76
77 /// Get a copy of particle \p i 's data.
78 void GetValues(int i, Vector &nvals) const;
79
80 /** @brief For `GetOrdering` == Ordering::byVDIM, set \p nref to refer to
81 * particle \p i 's data.
82 *
83 * @warning This method only works when ordering is Ordering::byVDIM, where
84 * an individual particle's data is stored contiguously in memory.
85 */
86 void GetValuesRef(int i, Vector &nref);
87
88 /// Get a copy of component \p vd for all particle vector data.
89 void GetComponents(int vd, Vector &comp);
90
91 /** @brief For `GetOrdering` == Ordering::byNODES, set \p nref to refer to
92 * component \p vd 's data.
93 *
94 * @warning This method only works when ordering is Ordering::byNODES,
95 * where an individual component of all particle data is stored
96 * contiguously in memory.
97 */
98 void GetComponentsRef(int vd, Vector &nref);
99
100 /// Set particle \p i 's data to \p nvals .
101 void SetValues(int i, const Vector &nvals);
102
103 /// Set component \p vd values for all particle data to \p comp .
104 void SetComponents(int vd, const Vector &comp);
105
106 /// Reference to particle \p i component \p comp value.
107 real_t& operator()(int i, int comp);
108
109 /// Const reference to particle \p i component \p comp value.
110 const real_t& operator()(int i, int comp) const;
111
112 /** @brief Remove particle data at \p indices.
113 *
114 * @details The ParticleVector is resized appropriately, with existing data maintained.
115 */
116 void DeleteParticles(const Array<int> &indices);
117
118 /** @brief Remove particle data at \p index.
119 *
120 * @details The ParticleVector is resized appropriately, with existing data maintained.
121 */
122 void DeleteParticle(const int index)
123 {
124 Array<int> indices({index});
125 DeleteParticles(indices);
126 }
127
128 /** @brief Set the vector dimension of the ParticleVector.
129 *
130 * @details If \p keep_data is true, existing particle data in the
131 * ParticleVector is maintained with an updated vector dimension \p vdim_ .
132 */
133 void SetVDim(int vdim_, bool keep_data=true);
134
135 /** @brief Set the ordering of the particle Vector data in ParticleVector.
136 *
137 * @details If \p keep_data is true, existing particle data in the
138 * ParticleVector is reordered to \p ordering_ .
139 */
140 void SetOrdering(Ordering::Type ordering_, bool keep_data=true);
141
142 /** @brief Set the number of particle Vector data to be held by the
143 * ParticleVector, keeping existing data.
144 *
145 * @details If \p keep_data is true, existing particle data in the
146 * ParticleVector is maintained with an ordering-mindful resize. If
147 * \p num_vectors * \ref GetVDim > \p Vector::Capacity , memory
148 * is re-allocated.
149 */
150 void SetNumParticles(int num_vectors, bool keep_data=true);
151
152};
153
154
155} // namespace mfem
156
157
158#endif // MFEM_PARTICLEVECTOR
The ordering method used when the number of unknowns per mesh node (vector dimension) is bigger than ...
Definition ordering.hpp:13
Type
Ordering methods:
Definition ordering.hpp:17
ParticleVector carries vector data (of a given vector dimension) for an arbitrary number of particles...
Ordering::Type ordering
Ordering of Vector data in ParticleVector.
void SetValues(int i, const Vector &nvals)
Set particle i 's data to nvals .
real_t & operator()(int i, int comp)
Reference to particle i component comp value.
void GetValues(int i, Vector &nvals) const
Get a copy of particle i 's data.
int vdim
Vector dimension.
int GetNumParticles() const
Get the number of particle data in the ParticleVector.
void DeleteParticles(const Array< int > &indices)
Remove particle data at indices.
void SetNumParticles(int num_vectors, bool keep_data=true)
Set the number of particle Vector data to be held by the ParticleVector, keeping existing data.
void SetOrdering(Ordering::Type ordering_, bool keep_data=true)
Set the ordering of the particle Vector data in ParticleVector.
int GetVDim() const
Get the Vector dimension of the ParticleVector.
void GetComponents(int vd, Vector &comp)
Get a copy of component vd for all particle vector data.
void SetVDim(int vdim_, bool keep_data=true)
Set the vector dimension of the ParticleVector.
void GetValuesRef(int i, Vector &nref)
For GetOrdering == Ordering::byVDIM, set nref to refer to particle i 's data.
Ordering::Type GetOrdering() const
Get the ordering of data in the ParticleVector.
void SetComponents(int vd, const Vector &comp)
Set component vd values for all particle data to comp .
void GetComponentsRef(int vd, Vector &nref)
For GetOrdering == Ordering::byNODES, set nref to refer to component vd 's data.
void DeleteParticle(const int index)
Remove particle data at index.
void GrowSize(int min_num_vectors, bool keep_data)
Re-allocate + copy memory. See Array::GrowSize.
Vector data type.
Definition vector.hpp:82
int Size() const
Returns the size of the vector.
Definition vector.hpp:234
int index(int i, int j, int nx, int ny)
Definition life.cpp:236
float real_t
Definition config.hpp:46