Loading [MathJax]/extensions/TeX/newcommand.js
 Reference documentation for deal.II version 9.3.3
\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\}}
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
property_pool.cc
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
18
20
22
23namespace Particles
24{
25 template <int dim, int spacedim>
27 PropertyPool<dim, spacedim>::invalid_handle = static_cast<Handle>(-1);
28
29
30
31 template <int dim, int spacedim>
33 const unsigned int n_properties_per_slot)
34 : n_properties(n_properties_per_slot)
35 {}
36
37
38
39 template <int dim, int spacedim>
41 {
42 clear();
43 }
44
45
46
47 template <int dim, int spacedim>
48 void
50 {
51 if (n_properties > 0)
52 {
53 const unsigned int n_open_handles =
54 properties.size() / n_properties - currently_available_handles.size();
55 (void)n_open_handles;
56 AssertThrow(n_open_handles == 0,
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 "deallocate_properties_array()."));
63 }
64
65 // Clear vectors and ensure deallocation of memory
66 locations.clear();
67 locations.shrink_to_fit();
68
69 reference_locations.clear();
70 reference_locations.shrink_to_fit();
71
72 ids.clear();
73 ids.shrink_to_fit();
74
75 properties.clear();
76 properties.shrink_to_fit();
77
78 currently_available_handles.clear();
79 currently_available_handles.shrink_to_fit();
80 }
81
82
83
84 template <int dim, int spacedim>
87 {
88 Handle handle = invalid_handle;
89 if (currently_available_handles.size() > 0)
90 {
91 handle = currently_available_handles.back();
92 currently_available_handles.pop_back();
93 }
94 else
95 {
96 handle = locations.size();
97
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);
102 }
103
104 // Then initialize whatever slot we have taken with invalid locations,
105 // but initialize properties with zero.
106 set_location(handle, numbers::signaling_nan<Point<spacedim>>());
107 set_reference_location(handle, numbers::signaling_nan<Point<dim>>());
108 set_id(handle, numbers::invalid_unsigned_int);
109 for (double &x : get_properties(handle))
110 x = 0;
111
112 return handle;
113 }
114
115
116
117 template <int dim, int spacedim>
118 void
121 Assert(
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."));
126 currently_available_handles.push_back(handle);
127 handle = invalid_handle;
128
129 // If this was the last handle, resize containers to 0.
130 // This guarantees that all future properties
131 // are allocated in a sorted way without requiring reallocation.
132 if (currently_available_handles.size() == locations.size())
133 {
134 currently_available_handles.clear();
135 properties.clear();
136 locations.clear();
137 reference_locations.clear();
138 ids.clear();
139 }
140 }
141
142
143
144 template <int dim, int spacedim>
145 void
147 {
148 locations.reserve(size);
149 reference_locations.reserve(size);
150 properties.reserve(size * n_properties);
151 ids.reserve(size);
152 }
153
154
155
156 template <int dim, int spacedim>
157 unsigned int
159 {
160 return n_properties;
161 }
162
163
164 // Instantiate the class for all reasonable template arguments
165 template class PropertyPool<1, 1>;
166 template class PropertyPool<1, 2>;
167 template class PropertyPool<1, 3>;
168 template class PropertyPool<2, 2>;
169 template class PropertyPool<2, 3>;
170 template class PropertyPool<3, 3>;
171} // namespace Particles
void reserve(const std::size_t size)
PropertyPool(const unsigned int n_properties_per_slot)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
#define Assert(cond, exc)
Definition: exceptions.h:1465
std::string to_string(const T &t)
Definition: patterns.h:2329
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Definition: exceptions.h:1575
static const unsigned int invalid_unsigned_int
Definition: types.h:196
T signaling_nan()