Reference documentation for deal.II version Git 0491297983 2019-09-23 09:31:59 +0200
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
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  property_pool = &new_property_pool;
280  }
281 
282 
283 
284  template <int dim, int spacedim>
285  void
287  const ArrayView<const double> &new_properties)
288  {
289  Assert(property_pool != nullptr, ExcInternalError());
290 
293 
294  const ArrayView<double> old_properties =
296 
297  Assert(
298  new_properties.size() == old_properties.size(),
299  ExcMessage(
300  std::string(
301  "You are trying to assign properties with an incompatible length. ") +
302  "The particle has space to store " +
303  Utilities::to_string(old_properties.size()) + " properties, " +
304  "and this function tries to assign" +
305  Utilities::to_string(new_properties.size()) + " properties. " +
306  "This is not allowed."));
307 
308  if (old_properties.size() > 0)
309  std::copy(new_properties.begin(),
310  new_properties.end(),
311  old_properties.begin());
312  }
313 
314 
315 
316  template <int dim, int spacedim>
319  {
321 
323  }
324 
325 
326 
327  template <int dim, int spacedim>
328  const ArrayView<double>
330  {
331  Assert(property_pool != nullptr, ExcInternalError());
332 
333  // If this particle has no properties yet, allocate and initialize them.
335  {
337 
338  ArrayView<double> my_properties =
340 
341  std::fill(my_properties.begin(), my_properties.end(), 0.0);
342  }
343 
345  }
346 
347 
348 
349  template <int dim, int spacedim>
350  bool
352  {
353  return (property_pool != nullptr) &&
355  }
356 } // namespace Particles
357 
358 DEAL_II_NAMESPACE_CLOSE
359 
360 DEAL_II_NAMESPACE_OPEN
361 
362 #include "particle.inst"
363 
364 DEAL_II_NAMESPACE_CLOSE
PropertyPool::Handle properties
Definition: particle.h:372
Point< spacedim > location
Definition: particle.h:351
void set_property_pool(PropertyPool &property_pool)
Definition: particle.cc:277
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:489
types::particle_index get_id() const
Definition: particle.cc:268
void set_properties(const ArrayView< const double > &new_properties)
Definition: particle.cc:286
types::particle_index id
Definition: particle.h:361
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:329
void set_reference_location(const Point< dim > &new_reference_location)
Definition: particle.cc:250
Definition: point.h:110
std::string to_string(const number value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition: utilities.cc:392
std::size_t size() const
Definition: array_view.h:471
std::size_t serialized_size_in_bytes() const
Definition: particle.cc:214
unsigned int particle_index
Definition: particle.h:64
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1407
static const Handle invalid_handle
Definition: property_pool.h:54
const Point< dim > & get_reference_location() const
Definition: particle.cc:259
Point< dim > reference_location
Definition: particle.h:356
bool has_properties() const
Definition: particle.cc:351
iterator begin() const
Definition: array_view.h:480
void set_location(const Point< spacedim > &new_location)
Definition: particle.cc:232
PropertyPool * property_pool
Definition: particle.h:367
Handle allocate_properties_array()
static ::ExceptionBase & ExcInternalError()