25 template <
int dim,
int spacedim>
26 const typename PropertyPool<dim, spacedim>::Handle
27 PropertyPool<dim, spacedim>::invalid_handle =
static_cast<Handle
>(-1);
31 template <
int dim,
int spacedim>
33 const unsigned int n_properties_per_slot)
34 : n_properties(n_properties_per_slot)
39 template <
int dim,
int spacedim>
47 template <
int dim,
int spacedim>
53 const unsigned int n_open_handles =
54 properties.size() / n_properties - currently_available_handles.size();
57 ExcMessage(
"This property pool currently still holds " +
58 std::to_string(n_open_handles) +
59 " open handles to memory that was allocated "
60 "via allocate_properties_array() but that has "
61 "not been returned via "
62 "deregister_particle()."));
67 locations.shrink_to_fit();
69 reference_locations.clear();
70 reference_locations.shrink_to_fit();
76 properties.shrink_to_fit();
78 currently_available_handles.clear();
79 currently_available_handles.shrink_to_fit();
84 template <
int dim,
int spacedim>
88 Handle handle = invalid_handle;
89 if (currently_available_handles.size() > 0)
91 handle = currently_available_handles.back();
92 currently_available_handles.pop_back();
96 handle = locations.size();
98 locations.resize(locations.size() + 1);
99 reference_locations.resize(reference_locations.size() + 1);
100 ids.resize(ids.size() + 1);
101 properties.resize(properties.size() + n_properties);
109 for (
double &x : get_properties(handle))
117 template <
int dim,
int spacedim>
122 handle != invalid_handle,
124 "This handle is invalid and cannot be deallocated. This can happen if the "
125 "handle was deallocated already before calling this function."));
128 currently_available_handles.size() < locations.size(),
130 "Trying to deallocate a particle when none are allocated. This can happen if all "
131 "handles were deallocated already before calling this function."));
133 currently_available_handles.push_back(handle);
134 handle = invalid_handle;
139 if (currently_available_handles.size() == locations.size())
141 currently_available_handles.clear();
144 reference_locations.clear();
151 template <
int dim,
int spacedim>
155 locations.reserve(size);
156 reference_locations.reserve(size);
157 properties.reserve(size * n_properties);
163 template <
int dim,
int spacedim>
172 template <
int dim,
int spacedim>
176 Assert(locations.size() == reference_locations.size(),
177 ExcMessage(
"Number of registered locations is not equal to number "
178 "of registered reference locations."));
180 Assert(locations.size() == ids.size(),
181 ExcMessage(
"Number of registered locations is not equal to number "
182 "of registered ids."));
184 Assert(locations.size() * n_properties == properties.size(),
185 ExcMessage(
"Number of registered locations is not equal to number "
186 "of registered property slots."));
188 return locations.size() - currently_available_handles.size();
193 template <
int dim,
int spacedim>
196 const std::vector<Handle> &handles_to_sort)
198 std::vector<Point<spacedim>> sorted_locations;
199 std::vector<Point<dim>> sorted_reference_locations;
200 std::vector<types::particle_index> sorted_ids;
201 std::vector<double> sorted_properties;
203 sorted_locations.reserve(locations.size());
204 sorted_reference_locations.reserve(reference_locations.size());
205 sorted_ids.reserve(ids.size());
206 sorted_properties.reserve(properties.size());
208 for (
auto &handle : handles_to_sort)
210 Assert(handle != invalid_handle,
212 "Invalid handle detected during sorting particle memory."));
214 sorted_locations.push_back(locations[handle]);
215 sorted_reference_locations.push_back(reference_locations[handle]);
216 sorted_ids.push_back(ids[handle]);
218 for (
unsigned int j = 0; j < n_properties; ++j)
219 sorted_properties.push_back(properties[handle * n_properties + j]);
222 Assert(sorted_locations.size() ==
223 locations.size() - currently_available_handles.size(),
224 ExcMessage(
"Number of sorted property handles is not equal to "
225 "number of currently registered handles: " +
226 std::to_string(sorted_locations.size()) +
" vs " +
227 std::to_string(locations.size()) +
" - " +
228 std::to_string(currently_available_handles.size())));
230 locations = std::move(sorted_locations);
231 reference_locations = std::move(sorted_reference_locations);
232 ids = std::move(sorted_ids);
233 properties = std::move(sorted_properties);
235 currently_available_handles.clear();
unsigned int n_properties_per_slot() const
unsigned int n_registered_slots() const
void deregister_particle(Handle &handle)
void reserve(const std::size_t size)
PropertyPool(const unsigned int n_properties_per_slot)
void sort_memory_slots(const std::vector< Handle > &handles_to_sort)
Handle register_particle()
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
static const unsigned int invalid_unsigned_int