Reference documentation for deal.II version 9.3.2
\(\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\}}\)
property_pool.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2021 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_particles_property_pool_h
17 #define dealii_particles_property_pool_h
18 
19 #include <deal.II/base/config.h>
20 
22 #include <deal.II/base/point.h>
23 
24 
26 
27 namespace types
28 {
29  /* Type definitions */
30 
31 #ifdef DEAL_II_WITH_64BIT_INDICES
43  using particle_index = uint64_t;
44 
45 # ifdef DEAL_II_WITH_MPI
50 # define DEAL_II_PARTICLE_INDEX_MPI_TYPE MPI_UINT64_T
51 # endif
52 
53 #else
65  using particle_index = unsigned int;
66 
67 # ifdef DEAL_II_WITH_MPI
72 # define DEAL_II_PARTICLE_INDEX_MPI_TYPE MPI_UNSIGNED
73 # endif
74 #endif
75 } // namespace types
76 
77 namespace Particles
78 {
101  template <int dim, int spacedim = dim>
103  {
104  public:
110  using Handle = unsigned int;
111 
115  static const Handle invalid_handle;
116 
120  PropertyPool(const unsigned int n_properties_per_slot);
121 
127  ~PropertyPool();
128 
135  void
136  clear();
137 
143  Handle
145 
150  void
151  deregister_particle(Handle &handle);
152 
156  const Point<spacedim> &
157  get_location(const Handle handle) const;
158 
162  void
163  set_location(const Handle handle, const Point<spacedim> &new_location);
164 
169  const Point<dim> &
170  get_reference_location(const Handle handle) const;
171 
176  void
178  const Point<dim> &new_reference_location);
179 
185  get_id(const Handle handle) const;
186 
191  void
192  set_id(const Handle handle, const types::particle_index &new_id);
193 
199  get_properties(const Handle handle);
200 
205  void
206  reserve(const std::size_t size);
207 
211  unsigned int
212  n_properties_per_slot() const;
213 
214  private:
218  const unsigned int n_properties;
219 
225  std::vector<Point<spacedim>> locations;
226 
232  std::vector<Point<dim>> reference_locations;
233 
239  std::vector<types::particle_index> ids;
240 
246  std::vector<double> properties;
247 
255  std::vector<Handle> currently_available_handles;
256  };
257 
258 
259 
260  /* ---------------------- inline and template functions ------------------ */
261 
262  template <int dim, int spacedim>
263  inline const Point<spacedim> &
265  {
266  const std::vector<double>::size_type data_index =
267  (handle != invalid_handle) ? handle : 0;
268 
269  // Ideally we would need to assert that 'handle' has not been deallocated
270  // by searching through 'currently_available_handles'. However, this
271  // is expensive and this function is performance critical, so instead
272  // just check against the array range, and rely on the fact
273  // that handles are invalidated when handed over to
274  // deallocate_properties_array().
275  Assert(data_index <= locations.size() - 1,
276  ExcMessage("Invalid location handle. This can happen if the "
277  "handle was duplicated and then one copy was deallocated "
278  "before trying to access the properties."));
279 
280  return locations[data_index];
281  }
282 
283 
284 
285  template <int dim, int spacedim>
286  inline void
288  const Point<spacedim> &new_location)
289  {
290  const std::vector<double>::size_type data_index =
291  (handle != invalid_handle) ? handle : 0;
292 
293  // Ideally we would need to assert that 'handle' has not been deallocated
294  // by searching through 'currently_available_handles'. However, this
295  // is expensive and this function is performance critical, so instead
296  // just check against the array range, and rely on the fact
297  // that handles are invalidated when handed over to
298  // deallocate_properties_array().
299  Assert(data_index <= locations.size() - 1,
300  ExcMessage("Invalid location handle. This can happen if the "
301  "handle was duplicated and then one copy was deallocated "
302  "before trying to access the properties."));
303 
304  locations[data_index] = new_location;
305  }
306 
307 
308 
309  template <int dim, int spacedim>
310  inline const Point<dim> &
312  {
313  const std::vector<double>::size_type data_index =
314  (handle != invalid_handle) ? handle : 0;
315 
316  // Ideally we would need to assert that 'handle' has not been deallocated
317  // by searching through 'currently_available_handles'. However, this
318  // is expensive and this function is performance critical, so instead
319  // just check against the array range, and rely on the fact
320  // that handles are invalidated when handed over to
321  // deallocate_properties_array().
322  Assert(data_index <= reference_locations.size() - 1,
323  ExcMessage("Invalid location handle. This can happen if the "
324  "handle was duplicated and then one copy was deallocated "
325  "before trying to access the properties."));
326 
327  return reference_locations[data_index];
328  }
329 
330 
331 
332  template <int dim, int spacedim>
333  inline void
335  const Handle handle,
336  const Point<dim> &new_reference_location)
337  {
338  const std::vector<double>::size_type data_index =
339  (handle != invalid_handle) ? handle : 0;
340 
341  // Ideally we would need to assert that 'handle' has not been deallocated
342  // by searching through 'currently_available_handles'. However, this
343  // is expensive and this function is performance critical, so instead
344  // just check against the array range, and rely on the fact
345  // that handles are invalidated when handed over to
346  // deallocate_properties_array().
347  Assert(data_index <= reference_locations.size() - 1,
348  ExcMessage("Invalid location handle. This can happen if the "
349  "handle was duplicated and then one copy was deallocated "
350  "before trying to access the properties."));
351 
352  reference_locations[data_index] = new_reference_location;
353  }
354 
355 
356 
357  template <int dim, int spacedim>
358  inline types::particle_index
360  {
361  const std::vector<double>::size_type data_index =
362  (handle != invalid_handle) ? handle : 0;
363 
364  // Ideally we would need to assert that 'handle' has not been deallocated
365  // by searching through 'currently_available_handles'. However, this
366  // is expensive and this function is performance critical, so instead
367  // just check against the array range, and rely on the fact
368  // that handles are invalidated when handed over to
369  // deallocate_properties_array().
370  Assert(data_index <= ids.size() - 1,
371  ExcMessage("Invalid location handle. This can happen if the "
372  "handle was duplicated and then one copy was deallocated "
373  "before trying to access the properties."));
374 
375  return ids[data_index];
376  }
377 
378 
379 
380  template <int dim, int spacedim>
381  inline void
383  const types::particle_index &new_id)
384  {
385  const std::vector<double>::size_type data_index =
386  (handle != invalid_handle) ? handle : 0;
387 
388  // Ideally we would need to assert that 'handle' has not been deallocated
389  // by searching through 'currently_available_handles'. However, this
390  // is expensive and this function is performance critical, so instead
391  // just check against the array range, and rely on the fact
392  // that handles are invalidated when handed over to
393  // deallocate_properties_array().
394  Assert(data_index <= ids.size() - 1,
395  ExcMessage("Invalid location handle. This can happen if the "
396  "handle was duplicated and then one copy was deallocated "
397  "before trying to access the properties."));
398 
399  ids[data_index] = new_id;
400  }
401 
402 
403 
404  template <int dim, int spacedim>
405  inline ArrayView<double>
407  {
408  const std::vector<double>::size_type data_index =
409  (handle != invalid_handle) ? handle * n_properties : 0;
410 
411  // Ideally we would need to assert that 'handle' has not been deallocated
412  // by searching through 'currently_available_handles'. However, this
413  // is expensive and this function is performance critical, so instead
414  // just check against the array range, and rely on the fact
415  // that handles are invalidated when handed over to
416  // deallocate_properties_array().
417  Assert(data_index <= properties.size() - n_properties,
418  ExcMessage("Invalid property handle. This can happen if the "
419  "handle was duplicated and then one copy was deallocated "
420  "before trying to access the properties."));
421 
422  return ArrayView<double>(properties.data() + data_index, n_properties);
423  }
424 
425 
426 } // namespace Particles
427 
429 
430 #endif
const Point< spacedim > & get_location(const Handle handle) const
std::vector< Point< dim > > reference_locations
unsigned int n_properties_per_slot() const
ArrayView< double > get_properties(const Handle handle)
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
PropertyPool(const unsigned int n_properties_per_slot)
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:396
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:397
#define Assert(cond, exc)
Definition: exceptions.h:1465
static ::ExceptionBase & ExcMessage(std::string arg1)
types::global_dof_index size_type
Definition: cuda_kernels.h:45
Definition: types.h:32
unsigned int particle_index
Definition: property_pool.h:65