Reference documentation for deal.II version 9.1.0-pre
particle.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2018 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/particles/particle.h>
17 
18 DEAL_II_NAMESPACE_OPEN
19 
20 namespace Particles
21 {
22  template <int dim, int spacedim>
24  : location()
25  , reference_location()
26  , id(0)
27  , property_pool(nullptr)
28  , properties(PropertyPool::invalid_handle)
29  {}
30 
31 
32 
33  template <int dim, int spacedim>
36  const types::particle_index id)
37  : location(location)
38  , reference_location(reference_location)
39  , id(id)
40  , property_pool(nullptr)
41  , properties(PropertyPool::invalid_handle)
42  {}
43 
44 
45 
46  template <int dim, int spacedim>
48  : location(particle.get_location())
50  , id(particle.get_id())
51  , property_pool(particle.property_pool)
52  , properties((particle.has_properties()) ?
53  property_pool->allocate_properties_array() :
54  PropertyPool::invalid_handle)
55  {
56  if (particle.has_properties())
57  {
58  const ArrayView<double> my_properties =
60  const ArrayView<const double> their_properties =
61  particle.get_properties();
62 
63  std::copy(their_properties.begin(),
64  their_properties.end(),
65  my_properties.begin());
66  }
67  }
68 
69 
70 
71  template <int dim, int spacedim>
73  PropertyPool *const new_property_pool)
74  {
75  const types::particle_index *id_data =
76  static_cast<const types::particle_index *>(data);
77  id = *id_data++;
78  const double *pdata = reinterpret_cast<const double *>(id_data);
79 
80  for (unsigned int i = 0; i < spacedim; ++i)
81  location(i) = *pdata++;
82 
83  for (unsigned int i = 0; i < dim; ++i)
84  reference_location(i) = *pdata++;
85 
86  property_pool = new_property_pool;
87  if (property_pool != nullptr)
89  else
91 
92  // See if there are properties to load
93  if (has_properties())
94  {
95  const ArrayView<double> particle_properties =
97  const unsigned int size = particle_properties.size();
98  for (unsigned int i = 0; i < size; ++i)
99  particle_properties[i] = *pdata++;
100  }
101 
102  data = static_cast<const void *>(pdata);
103  }
104 
105 
106 
107  template <int dim, int spacedim>
109  : location(std::move(particle.location))
110  , reference_location(std::move(particle.reference_location))
111  , id(std::move(particle.id))
112  , property_pool(std::move(particle.property_pool))
113  , properties(std::move(particle.properties))
114  {
115  particle.properties = PropertyPool::invalid_handle;
116  }
117 
118 
119 
120  template <int dim, int spacedim>
123  {
124  if (this != &particle)
125  {
126  location = particle.location;
128  id = particle.id;
129  property_pool = particle.property_pool;
130 
131  if (particle.has_properties())
132  {
134  const ArrayView<const double> their_properties =
135  particle.get_properties();
136  const ArrayView<double> my_properties =
138 
139  std::copy(their_properties.begin(),
140  their_properties.end(),
141  my_properties.begin());
142  }
143  else
145  }
146  return *this;
147  }
148 
149 
150 
151  template <int dim, int spacedim>
155  {
156  if (this != &particle)
157  {
158  location = particle.location;
159  reference_location = particle.reference_location;
160  id = particle.id;
161  property_pool = particle.property_pool;
162  properties = particle.properties;
163  particle.properties = PropertyPool::invalid_handle;
164  }
165  return *this;
166  }
167 
168 
169 
170  template <int dim, int spacedim>
172  {
175  }
176 
177 
178 
179  template <int dim, int spacedim>
180  void
182  {
183  types::particle_index *id_data = static_cast<types::particle_index *>(data);
184  *id_data = id;
185  ++id_data;
186  double *pdata = reinterpret_cast<double *>(id_data);
187 
188  // Write location data
189  for (unsigned int i = 0; i < spacedim; ++i, ++pdata)
190  *pdata = location(i);
191 
192  // Write reference location data
193  for (unsigned int i = 0; i < dim; ++i, ++pdata)
194  *pdata = reference_location(i);
195 
196  // Write property data
197  if (has_properties())
198  {
199  const ArrayView<double> particle_properties =
201  for (unsigned int i = 0; i < particle_properties.size(); ++i, ++pdata)
202  *pdata = particle_properties[i];
203  }
204 
205  data = static_cast<void *>(pdata);
206  }
207 
208 
209 
210  template <int dim, int spacedim>
211  std::size_t
213  {
214  std::size_t size = sizeof(types::particle_index) + sizeof(location) +
215  sizeof(reference_location);
216 
217  if (has_properties())
218  {
219  const ArrayView<double> particle_properties =
221  size += sizeof(double) * particle_properties.size();
222  }
223  return size;
224  }
225 
226 
227 
228  template <int dim, int spacedim>
229  void
231  {
232  location = new_loc;
233  }
234 
235 
236 
237  template <int dim, int spacedim>
238  const Point<spacedim> &
240  {
241  return location;
242  }
243 
244 
245 
246  template <int dim, int spacedim>
247  void
249  {
250  reference_location = new_loc;
251  }
252 
253 
254 
255  template <int dim, int spacedim>
256  const Point<dim> &
258  {
259  return reference_location;
260  }
261 
262 
263 
264  template <int dim, int spacedim>
267  {
268  return id;
269  }
270 
271 
272 
273  template <int dim, int spacedim>
274  void
276  {
277  property_pool = &new_property_pool;
278  }
279 
280 
281 
282  template <int dim, int spacedim>
283  void
285  const ArrayView<const double> &new_properties)
286  {
289 
290  const ArrayView<double> old_properties =
292 
293  Assert(
294  new_properties.size() == old_properties.size(),
295  ExcMessage(
296  std::string(
297  "You are trying to assign properties with an incompatible length. ") +
298  "The particle has space to store " +
299  Utilities::to_string(old_properties.size()) + " properties, " +
300  "and this function tries to assign" +
301  Utilities::to_string(new_properties.size()) + " properties. " +
302  "This is not allowed."));
303 
304  if (old_properties.size() > 0)
305  std::copy(new_properties.begin(),
306  new_properties.end(),
307  old_properties.begin());
308  }
309 
310 
311 
312  template <int dim, int spacedim>
315  {
316  Assert(property_pool != nullptr, ExcInternalError());
317 
319  }
320 
321 
322 
323  template <int dim, int spacedim>
324  const ArrayView<double>
326  {
327  Assert(property_pool != nullptr, ExcInternalError());
328 
330  }
331 
332 
333 
334  template <int dim, int spacedim>
335  bool
337  {
338  return (property_pool != nullptr) &&
340  }
341 } // namespace Particles
342 
343 DEAL_II_NAMESPACE_CLOSE
344 
345 DEAL_II_NAMESPACE_OPEN
346 
347 #include "particle.inst"
348 
349 DEAL_II_NAMESPACE_CLOSE
PropertyPool::Handle properties
Definition: particle.h:325
Point< spacedim > location
Definition: particle.h:304
std::size_t size() const
Definition: array_view.h:371
void set_property_pool(PropertyPool &property_pool)
Definition: particle.cc:275
Particle< dim, spacedim > & operator=(const Particle< dim, spacedim > &particle)
Definition: particle.cc:122
ArrayView< double > get_properties(const Handle handle)
types::particle_index get_id() const
Definition: particle.cc:266
iterator end() const
Definition: array_view.h:387
std::size_t serialized_size_in_bytes() const
Definition: particle.cc:212
void write_data(void *&data) const
Definition: particle.cc:181
unsigned long long int particle_index
Definition: particle.h:43
void set_properties(const ArrayView< const double > &new_properties)
Definition: particle.cc:284
types::particle_index id
Definition: particle.h:314
void deallocate_properties_array(const Handle handle)
iterator begin() const
Definition: array_view.h:378
STL namespace.
const ArrayView< double > get_properties()
Definition: particle.cc:325
void set_reference_location(const Point< dim > &new_reference_location)
Definition: particle.cc:248
std::string to_string(const number value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition: utilities.cc:105
static::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1227
static const Handle invalid_handle
Definition: property_pool.h:54
Point< dim > reference_location
Definition: particle.h:309
const Point< spacedim > & get_location() const
Definition: particle.cc:239
const Point< dim > & get_reference_location() const
Definition: particle.cc:257
void set_location(const Point< spacedim > &new_location)
Definition: particle.cc:230
bool has_properties() const
Definition: particle.cc:336
PropertyPool * property_pool
Definition: particle.h:320
Handle allocate_properties_array()
static::ExceptionBase & ExcInternalError()