Reference documentation for deal.II version GIT relicensing-822-gf1642d4ea5 2024-06-12 14:10:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
property_pool.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2017 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_particles_property_pool_h
16#define dealii_particles_property_pool_h
17
18#include <deal.II/base/config.h>
19
21#include <deal.II/base/point.h>
22
23
25
26namespace types
27{
28 /* Type definitions */
29
30#ifdef DEAL_II_WITH_64BIT_INDICES
42 using particle_index = std::uint64_t;
43
44# ifdef DEAL_II_WITH_MPI
49# define DEAL_II_PARTICLE_INDEX_MPI_TYPE MPI_UINT64_T
50# endif
51
52#else
64 using particle_index = unsigned int;
65
66# ifdef DEAL_II_WITH_MPI
71# define DEAL_II_PARTICLE_INDEX_MPI_TYPE MPI_UNSIGNED
72# endif
73#endif
74} // namespace types
75
76namespace Particles
77{
100 template <int dim, int spacedim = dim>
102 {
103 public:
109 using Handle = unsigned int;
110
114 static const Handle invalid_handle;
115
119 PropertyPool(const unsigned int n_properties_per_slot);
120
127
134 void
135 clear();
136
142 Handle
144
149 void
151
156 const Point<spacedim> &
157 get_location(const Handle handle) const;
158
164 get_location(const Handle handle);
165
169 void
171
176 const Point<dim> &
177 get_reference_location(const Handle handle) const;
178
183 void
186
192 get_id(const Handle handle) const;
193
198 void
200
206 get_properties(const Handle handle);
207
212 void
213 reserve(const std::size_t size);
214
218 unsigned int
219 n_properties_per_slot() const;
220
225 unsigned int
226 n_slots() const;
227
231 unsigned int
232 n_registered_slots() const;
233
242 void
243 sort_memory_slots(const std::vector<Handle> &handles_to_sort);
244
245 private:
249 const unsigned int n_properties;
250
256 std::vector<Point<spacedim>> locations;
257
263 std::vector<Point<dim>> reference_locations;
264
270 std::vector<types::particle_index> ids;
271
277 std::vector<double> properties;
278
286 std::vector<Handle> currently_available_handles;
287 };
288
289
290
291 /* ---------------------- inline and template functions ------------------ */
292
293 template <int dim, int spacedim>
294 inline const Point<spacedim> &
296 {
297 const std::vector<double>::size_type data_index =
298 (handle != invalid_handle) ? handle : 0;
299
300 // Ideally we would need to assert that 'handle' has not been deallocated
301 // by searching through 'currently_available_handles'. However, this
302 // is expensive and this function is performance critical, so instead
303 // just check against the array range, and rely on the fact
304 // that handles are invalidated when handed over to
305 // deallocate_properties_array().
306 Assert(data_index <= locations.size() - 1,
307 ExcMessage("Invalid location handle. This can happen if the "
308 "handle was duplicated and then one copy was deallocated "
309 "before trying to access the properties."));
310
311 return locations[data_index];
312 }
313
314
315
316 template <int dim, int spacedim>
317 inline Point<spacedim> &
319 {
320 const std::vector<double>::size_type data_index =
321 (handle != invalid_handle) ? handle : 0;
322
323 // Ideally we would need to assert that 'handle' has not been deallocated
324 // by searching through 'currently_available_handles'. However, this
325 // is expensive and this function is performance critical, so instead
326 // just check against the array range, and rely on the fact
327 // that handles are invalidated when handed over to
328 // deallocate_properties_array().
329 Assert(data_index <= locations.size() - 1,
330 ExcMessage("Invalid location handle. This can happen if the "
331 "handle was duplicated and then one copy was deallocated "
332 "before trying to access the properties."));
333
334 return locations[data_index];
335 }
336
337
338
339 template <int dim, int spacedim>
340 inline void
343 {
344 const std::vector<double>::size_type data_index =
345 (handle != invalid_handle) ? handle : 0;
346
347 // Ideally we would need to assert that 'handle' has not been deallocated
348 // by searching through 'currently_available_handles'. However, this
349 // is expensive and this function is performance critical, so instead
350 // just check against the array range, and rely on the fact
351 // that handles are invalidated when handed over to
352 // deallocate_properties_array().
353 Assert(data_index <= locations.size() - 1,
354 ExcMessage("Invalid location handle. This can happen if the "
355 "handle was duplicated and then one copy was deallocated "
356 "before trying to access the properties."));
357
358 locations[data_index] = new_location;
359 }
360
361
362
363 template <int dim, int spacedim>
364 inline const Point<dim> &
366 {
367 const std::vector<double>::size_type data_index =
368 (handle != invalid_handle) ? handle : 0;
369
370 // Ideally we would need to assert that 'handle' has not been deallocated
371 // by searching through 'currently_available_handles'. However, this
372 // is expensive and this function is performance critical, so instead
373 // just check against the array range, and rely on the fact
374 // that handles are invalidated when handed over to
375 // deallocate_properties_array().
376 Assert(data_index <= reference_locations.size() - 1,
377 ExcMessage("Invalid location handle. This can happen if the "
378 "handle was duplicated and then one copy was deallocated "
379 "before trying to access the properties."));
380
381 return reference_locations[data_index];
382 }
383
384
385
386 template <int dim, int spacedim>
387 inline void
389 const Handle handle,
391 {
392 const std::vector<double>::size_type data_index =
393 (handle != invalid_handle) ? handle : 0;
394
395 // Ideally we would need to assert that 'handle' has not been deallocated
396 // by searching through 'currently_available_handles'. However, this
397 // is expensive and this function is performance critical, so instead
398 // just check against the array range, and rely on the fact
399 // that handles are invalidated when handed over to
400 // deallocate_properties_array().
401 Assert(data_index <= reference_locations.size() - 1,
402 ExcMessage("Invalid location handle. This can happen if the "
403 "handle was duplicated and then one copy was deallocated "
404 "before trying to access the properties."));
405
406 reference_locations[data_index] = new_reference_location;
407 }
408
409
410
411 template <int dim, int spacedim>
414 {
415 const std::vector<double>::size_type data_index =
416 (handle != invalid_handle) ? handle : 0;
417
418 // Ideally we would need to assert that 'handle' has not been deallocated
419 // by searching through 'currently_available_handles'. However, this
420 // is expensive and this function is performance critical, so instead
421 // just check against the array range, and rely on the fact
422 // that handles are invalidated when handed over to
423 // deallocate_properties_array().
424 Assert(data_index <= ids.size() - 1,
425 ExcMessage("Invalid location handle. This can happen if the "
426 "handle was duplicated and then one copy was deallocated "
427 "before trying to access the properties."));
428
429 return ids[data_index];
430 }
431
432
433
434 template <int dim, int spacedim>
435 inline void
438 {
439 const std::vector<double>::size_type data_index =
440 (handle != invalid_handle) ? handle : 0;
441
442 // Ideally we would need to assert that 'handle' has not been deallocated
443 // by searching through 'currently_available_handles'. However, this
444 // is expensive and this function is performance critical, so instead
445 // just check against the array range, and rely on the fact
446 // that handles are invalidated when handed over to
447 // deallocate_properties_array().
448 Assert(data_index <= ids.size() - 1,
449 ExcMessage("Invalid location handle. This can happen if the "
450 "handle was duplicated and then one copy was deallocated "
451 "before trying to access the properties."));
452
453 ids[data_index] = new_id;
454 }
455
456
457
458 template <int dim, int spacedim>
459 inline ArrayView<double>
461 {
462 const std::vector<double>::size_type data_index =
463 (handle != invalid_handle) ? handle * n_properties : 0;
464
465 // Ideally we would need to assert that 'handle' has not been deallocated
466 // by searching through 'currently_available_handles'. However, this
467 // is expensive and this function is performance critical, so instead
468 // just check against the array range, and rely on the fact
469 // that handles are invalidated when handed over to
470 // deallocate_properties_array().
471 Assert(data_index <= properties.size() - n_properties,
472 ExcMessage("Invalid property handle. This can happen if the "
473 "handle was duplicated and then one copy was deallocated "
474 "before trying to access the properties."));
475
476 return ArrayView<double>(properties.data() + data_index, n_properties);
477 }
478
479
480
481 template <int dim, int spacedim>
482 inline unsigned int
484 {
485 return locations.size();
486 }
487
488
489} // namespace Particles
490
492
493#endif
const Point< spacedim > & get_location(const Handle handle) const
std::vector< Point< dim > > reference_locations
unsigned int n_properties_per_slot() const
unsigned int n_registered_slots() const
ArrayView< double > get_properties(const Handle handle)
unsigned int n_slots() const
const unsigned int n_properties
void deregister_particle(Handle &handle)
void set_id(const Handle handle, const types::particle_index &new_id)
types::particle_index get_id(const Handle handle) const
void set_reference_location(const Handle handle, const Point< dim > &new_reference_location)
void reserve(const std::size_t size)
void set_location(const Handle handle, const Point< spacedim > &new_location)
const Point< dim > & get_reference_location(const Handle handle) const
void sort_memory_slots(const std::vector< Handle > &handles_to_sort)
Point< spacedim > & get_location(const Handle handle)
std::vector< Point< spacedim > > locations
std::vector< types::particle_index > ids
static const Handle invalid_handle
std::vector< Handle > currently_available_handles
std::vector< double > properties
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
Definition types.h:32
unsigned int particle_index