Reference documentation for deal.II version 9.5.1
\(\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
particle.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
17
19
21
22namespace Particles
23{
24 template <int dim, int spacedim>
26 /* no properties: */ 0};
27
28
29 template <int dim, int spacedim>
31 : property_pool(&global_property_pool)
32 , property_pool_handle(property_pool->register_particle())
33 {}
34
35
36
37 template <int dim, int spacedim>
40 const types::particle_index id)
41 : property_pool(&global_property_pool)
42 , property_pool_handle(property_pool->register_particle())
43 {
46 set_id(id);
47 }
48
49
50
51 template <int dim, int spacedim>
53 : property_pool(particle.property_pool)
54 , property_pool_handle(property_pool->register_particle())
55 {
56 set_location(particle.get_location());
57 set_reference_location(particle.get_reference_location());
58 set_id(particle.get_id());
59
60 if (particle.has_properties())
61 {
63 particle.get_properties();
66
67 std::copy(their_properties.begin(),
70 }
71 }
72
73
74
75 template <int dim, int spacedim>
77 const void *& data,
79 : property_pool(new_property_pool != nullptr ? new_property_pool :
80 &global_property_pool)
81 , property_pool_handle(property_pool->register_particle())
82 {
84 static_cast<const types::particle_index *>(data);
85 set_id(*id_data++);
86 const double *pdata = reinterpret_cast<const double *>(id_data);
87
89 for (unsigned int i = 0; i < spacedim; ++i)
90 location(i) = *pdata++;
92
94 for (unsigned int i = 0; i < dim; ++i)
97
98 // See if there are properties to load
99 if (has_properties())
100 {
102 const unsigned int size = particle_properties.size();
103 for (unsigned int i = 0; i < size; ++i)
105 }
106
107 data = static_cast<const void *>(pdata);
108 }
109
110
111
112 template <int dim, int spacedim>
114 : property_pool(std::move(particle.property_pool))
115 , property_pool_handle(std::move(particle.property_pool_handle))
116 {
117 // There is no need to copy locations, properties, and id -- we simply
118 // inherit them from the object we move from.
119
120 // We stole the rhs's properties, so we need to invalidate
121 // the handle the rhs holds lest it releases the memory that
122 // we still reference here.
124 }
125
126
127
128 template <int dim, int spacedim>
131 {
132 if (this != &particle)
133 {
134 Assert(this->property_pool->n_properties_per_slot() ==
135 particle.property_pool->n_properties_per_slot(),
137
138 set_location(particle.get_location());
139 set_reference_location(particle.get_reference_location());
140 set_id(particle.get_id());
141
142 if (particle.has_properties())
143 {
145 particle.get_properties();
147 property_pool->get_properties(property_pool_handle);
148
149 std::copy(their_properties.begin(),
152 }
153 }
154
155 return *this;
156 }
157
158
159
160 template <int dim, int spacedim>
164 {
165 if (this != &particle)
166 {
167 // If we currently hold a handle, release the memory. (The only way a
168 // particle can end up not holding a valid handle is if it has been
169 // moved from.)
170 if (property_pool_handle != PropertyPool<dim, spacedim>::invalid_handle)
171 property_pool->deregister_particle(property_pool_handle);
172
173 property_pool = std::move(particle.property_pool);
174 property_pool_handle = std::move(particle.property_pool_handle);
175
176 // No need to copy locations, properties, and id -- we just get them
177 // by taking over the property pool handle.
178
179 // We stole the rhs's properties, so we need to invalidate
180 // the handle the rhs holds lest it releases the memory that
181 // we still reference here.
182 particle.property_pool_handle =
184 }
185 return *this;
186 }
187
188
189
190 template <int dim, int spacedim>
192 {
193 // If we still hold a handle, release the memory. The only way a
194 // particle can end up not holding a valid handle is if it has been
195 // moved from.
196 if (property_pool_handle != PropertyPool<dim, spacedim>::invalid_handle)
197 property_pool->deregister_particle(property_pool_handle);
198 }
199
200
201
202 template <int dim, int spacedim>
203 void
205 {
206 // If we still hold a handle, release the memory. The only way a
207 // particle can end up not holding a valid handle is if it has been
208 // moved from.
209 //
210 // deregister_particle() automatically invalidates its argument.
211 if (property_pool_handle != PropertyPool<dim, spacedim>::invalid_handle)
212 property_pool->deregister_particle(property_pool_handle);
213 }
214
215
216
217 template <int dim, int spacedim>
218 void *
220 void *data_pointer) const
221 {
223 static_cast<types::particle_index *>(data_pointer);
224 *id_data = get_id();
225 ++id_data;
226 double *pdata = reinterpret_cast<double *>(id_data);
227
228 // Write location
229 for (unsigned int i = 0; i < spacedim; ++i, ++pdata)
230 *pdata = get_location()[i];
231
232 // Write reference location
233 for (unsigned int i = 0; i < dim; ++i, ++pdata)
234 *pdata = get_reference_location()[i];
235
236 // Write properties
237 if (has_properties())
238 {
240 property_pool->get_properties(property_pool_handle);
241 for (unsigned int i = 0; i < particle_properties.size(); ++i, ++pdata)
243 }
244
245 return static_cast<void *>(pdata);
246 }
247
248
249
250 template <int dim, int spacedim>
251 const void *
253 const void *data_pointer)
254 {
256 static_cast<const types::particle_index *>(data_pointer);
257 set_id(*id_data++);
258 const double *pdata = reinterpret_cast<const double *>(id_data);
259
261 for (unsigned int i = 0; i < spacedim; ++i)
262 location(i) = *pdata++;
263 set_location(location);
264
266 for (unsigned int i = 0; i < dim; ++i)
268 set_reference_location(reference_location);
269
270 // See if there are properties to load
271 if (has_properties())
272 {
274 property_pool->get_properties(property_pool_handle);
275 const unsigned int size = particle_properties.size();
276 for (unsigned int i = 0; i < size; ++i)
278 }
279
280 return static_cast<const void *>(pdata);
281 }
282
283
284
285 template <int dim, int spacedim>
286 std::size_t
288 {
289 std::size_t size = sizeof(get_id()) + sizeof(get_location()) +
290 sizeof(get_reference_location());
291
292 if (has_properties())
293 {
295 property_pool->get_properties(property_pool_handle);
296 size += sizeof(double) * particle_properties.size();
297 }
298 return size;
299 }
300
301
302
303 template <int dim, int spacedim>
304 void
307 {
309 property_pool->get_properties(property_pool_handle);
310
313 "You are trying to assign properties with an incompatible length. "
314 "The particle has space to store " +
315 std::to_string(property_values.size()) +
316 " properties, but you are trying to assign " +
317 std::to_string(new_properties.size()) +
318 " properties. This is not allowed."));
319
320 if (property_values.size() > 0)
321 std::copy(new_properties.begin(),
324 }
325
326
327
328 template <int dim, int spacedim>
331 {
332 return property_pool->get_properties(property_pool_handle);
333 }
334} // namespace Particles
335
337
339
340#include "particle.inst"
341
iterator begin() const
Definition array_view.h:594
iterator end() const
Definition array_view.h:603
std::size_t size() const
Definition array_view.h:576
PropertyPool< dim, spacedim > * property_pool
Definition particle.h:453
bool has_properties() const
Definition particle.h:640
static PropertyPool< dim, spacedim > global_property_pool
Definition particle.h:447
void set_reference_location(const Point< dim > &new_reference_location)
Definition particle.h:542
std::size_t serialized_size_in_bytes() const
Definition particle.cc:287
Particle< dim, spacedim > & operator=(const Particle< dim, spacedim > &particle)
Definition particle.cc:130
const ArrayView< double > get_properties()
Definition particle.cc:330
void set_properties(const ArrayView< const double > &new_properties)
Definition particle.cc:305
const void * read_particle_data_from_memory(const void *data)
Definition particle.cc:252
void * write_particle_data_to_memory(void *data) const
Definition particle.cc:219
PropertyPool< dim, spacedim >::Handle property_pool_handle
Definition particle.h:458
void set_id(const types::particle_index &new_id)
Definition particle.h:569
void set_location(const Point< spacedim > &new_location)
Definition particle.h:524
ArrayView< double > get_properties(const Handle handle)
void deregister_particle(Handle &handle)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)