Reference documentation for deal.II version Git a0b41b6d0f 2020-02-26 20:08:13 -0600
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
particle.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2019 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 #include <deal.II/base/signaling_nan.h>
17 
18 #include <deal.II/particles/particle.h>
19 
20 DEAL_II_NAMESPACE_OPEN
21 
22 namespace Particles
23 {
24  template <int dim, int spacedim>
26  : location(numbers::signaling_nan<Point<spacedim>>())
27  , reference_location(numbers::signaling_nan<Point<dim>>())
28  , id(0)
29  , property_pool(nullptr)
30  , properties(PropertyPool::invalid_handle)
31  {}
32 
33 
34 
35  template <int dim, int spacedim>
38  const types::particle_index id)
39  : location(location)
40  , reference_location(reference_location)
41  , id(id)
42  , property_pool(nullptr)
43  , properties(PropertyPool::invalid_handle)
44  {}
45 
46 
47 
48  template <int dim, int spacedim>
50  : location(particle.get_location())
52  , id(particle.get_id())
53  , property_pool(particle.property_pool)
54  , properties((particle.has_properties()) ?
55  property_pool->allocate_properties_array() :
56  PropertyPool::invalid_handle)
57  {
58  if (particle.has_properties())
59  {
60  const ArrayView<double> my_properties =
62  const ArrayView<const double> their_properties =
63  particle.get_properties();
64 
65  std::copy(their_properties.begin(),
66  their_properties.end(),
67  my_properties.begin());
68  }
69  }
70 
71 
72 
73  template <int dim, int spacedim>
75  PropertyPool *const new_property_pool)
76  {
77  const types::particle_index *id_data =
78  static_cast<const types::particle_index *>(data);
79  id = *id_data++;
80  const double *pdata = reinterpret_cast<const double *>(id_data);
81 
82  for (unsigned int i = 0; i < spacedim; ++i)
83  location(i) = *pdata++;
84 
85  for (unsigned int i = 0; i < dim; ++i)
86  reference_location(i) = *pdata++;
87 
88  property_pool = new_property_pool;
89  if (property_pool != nullptr)
91  else
93 
94  // See if there are properties to load
95  if (has_properties())
96  {
97  const ArrayView<double> particle_properties =
99  const unsigned int size = particle_properties.size();
100  for (unsigned int i = 0; i < size; ++i)
101  particle_properties[i] = *pdata++;
102  }
103 
104  data = static_cast<const void *>(pdata);
105  }
106 
107 
108 
109  template <int dim, int spacedim>
111  : location(std::move(particle.location))
112  , reference_location(std::move(particle.reference_location))
113  , id(std::move(particle.id))
114  , property_pool(std::move(particle.property_pool))
115  , properties(std::move(particle.properties))
116  {
117  particle.properties = PropertyPool::invalid_handle;
118  }
119 
120 
121 
122  template <int dim, int spacedim>
125  {
126  if (this != &particle)
127  {
128  location = particle.location;
130  id = particle.id;
131  property_pool = particle.property_pool;
132 
133  if (particle.has_properties())
134  {
136  const ArrayView<const double> their_properties =
137  particle.get_properties();
138  const ArrayView<double> my_properties =
140 
141  std::copy(their_properties.begin(),
142  their_properties.end(),
143  my_properties.begin());
144  }
145  else
147  }
148  return *this;
149  }
150 
151 
152 
153  template <int dim, int spacedim>
157  {
158  if (this != &particle)
159  {
160  location = particle.location;
161  reference_location = particle.reference_location;
162  id = particle.id;
163  property_pool = particle.property_pool;
164  properties = particle.properties;
165  particle.properties = PropertyPool::invalid_handle;
166  }
167  return *this;
168  }
169 
170 
171 
172  template <int dim, int spacedim>
174  {
177  }
178 
179 
180 
181  template <int dim, int spacedim>
182  void
184  {
185  types::particle_index *id_data = static_cast<types::particle_index *>(data);
186  *id_data = id;
187  ++id_data;
188  double *pdata = reinterpret_cast<double *>(id_data);
189 
190  // Write location data
191  for (unsigned int i = 0; i < spacedim; ++i, ++pdata)
192  *pdata = location(i);
193 
194  // Write reference location data
195  for (unsigned int i = 0; i < dim; ++i, ++pdata)
196  *pdata = reference_location(i);
197 
198  // Write property data
199  if (has_properties())
200  {
201  const ArrayView<double> particle_properties =
203  for (unsigned int i = 0; i < particle_properties.size(); ++i, ++pdata)
204  *pdata = particle_properties[i];
205  }
206 
207  data = static_cast<void *>(pdata);
208  }
209 
210 
211 
212  template <int dim, int spacedim>
213  std::size_t
215  {
216  std::size_t size = sizeof(types::particle_index) + sizeof(location) +
217  sizeof(reference_location);
218 
219  if (has_properties())
220  {
221  const ArrayView<double> particle_properties =
223  size += sizeof(double) * particle_properties.size();
224  }
225  return size;
226  }
227 
228 
229 
230  template <int dim, int spacedim>
231  void
233  {
234  location = new_loc;
235  }
236 
237 
238 
239  template <int dim, int spacedim>
240  const Point<spacedim> &
242  {
243  return location;
244  }
245 
246 
247 
248  template <int dim, int spacedim>
249  void
251  {
252  reference_location = new_loc;
253  }
254 
255 
256 
257  template <int dim, int spacedim>
258  const Point<dim> &
260  {
261  return reference_location;
262  }
263 
264 
265 
266  template <int dim, int spacedim>
269  {
270  return id;
271  }
272 
273 
274 
275  template <int dim, int spacedim>
276  void
278  {
279  id = new_id;
280  }
281 
282 
283 
284  template <int dim, int spacedim>
285  void
287  {
288  property_pool = &new_property_pool;
289  }
290 
291 
292 
293  template <int dim, int spacedim>
294  void
296  const ArrayView<const double> &new_properties)
297  {
298  Assert(property_pool != nullptr, ExcInternalError());
299 
302 
303  const ArrayView<double> old_properties =
305 
306  Assert(
307  new_properties.size() == old_properties.size(),
308  ExcMessage(
309  std::string(
310  "You are trying to assign properties with an incompatible length. ") +
311  "The particle has space to store " +
312  std::to_string(old_properties.size()) + " properties, " +
313  "and this function tries to assign" +
314  std::to_string(new_properties.size()) + " properties. " +
315  "This is not allowed."));
316 
317  if (old_properties.size() > 0)
318  std::copy(new_properties.begin(),
319  new_properties.end(),
320  old_properties.begin());
321  }
322 
323 
324 
325  template <int dim, int spacedim>
328  {
330 
332  }
333 
334 
335 
336  template <int dim, int spacedim>
337  const ArrayView<double>
339  {
340  Assert(property_pool != nullptr, ExcInternalError());
341 
342  // If this particle has no properties yet, allocate and initialize them.
344  {
346 
347  ArrayView<double> my_properties =
349 
350  std::fill(my_properties.begin(), my_properties.end(), 0.0);
351  }
352 
354  }
355 
356 
357 
358  template <int dim, int spacedim>
359  bool
361  {
362  return (property_pool != nullptr) &&
364  }
365 } // namespace Particles
366 
367 DEAL_II_NAMESPACE_CLOSE
368 
369 DEAL_II_NAMESPACE_OPEN
370 
371 #include "particle.inst"
372 
373 DEAL_II_NAMESPACE_CLOSE
PropertyPool::Handle properties
Definition: particle.h:382
Point< spacedim > location
Definition: particle.h:361
void set_property_pool(PropertyPool &property_pool)
Definition: particle.cc:286
Particle< dim, spacedim > & operator=(const Particle< dim, spacedim > &particle)
Definition: particle.cc:124
ArrayView< double > get_properties(const Handle handle)
void write_data(void *&data) const
Definition: particle.cc:183
iterator end() const
Definition: array_view.h:502
types::particle_index get_id() const
Definition: particle.cc:268
void set_properties(const ArrayView< const double > &new_properties)
Definition: particle.cc:295
types::particle_index id
Definition: particle.h:371
const Point< spacedim > & get_location() const
Definition: particle.cc:241
void deallocate_properties_array(const Handle handle)
const ArrayView< double > get_properties()
Definition: particle.cc:338
void set_reference_location(const Point< dim > &new_reference_location)
Definition: particle.cc:250
Definition: point.h:110
std::size_t size() const
Definition: array_view.h:484
std::size_t serialized_size_in_bytes() const
Definition: particle.cc:214
unsigned int particle_index
Definition: particle.h:66
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1411
static const Handle invalid_handle
Definition: property_pool.h:56
const Point< dim > & get_reference_location() const
Definition: particle.cc:259
Point< dim > reference_location
Definition: particle.h:366
bool has_properties() const
Definition: particle.cc:360
void set_id(const types::particle_index &new_id)
Definition: particle.cc:277
iterator begin() const
Definition: array_view.h:493
void set_location(const Point< spacedim > &new_location)
Definition: particle.cc:232
PropertyPool * property_pool
Definition: particle.h:377
Handle allocate_properties_array()
static ::ExceptionBase & ExcInternalError()