Reference documentation for deal.II version 9.2.0
\(\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\}}\)
particle.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2020 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 
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>
37  const Point<dim> & reference_location,
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())
51  , reference_location(particle.get_reference_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 =
61  property_pool->get_properties(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)
90  properties = property_pool->allocate_properties_array();
91  else
92  properties = PropertyPool::invalid_handle;
93 
94  // See if there are properties to load
95  if (has_properties())
96  {
97  const ArrayView<double> particle_properties =
98  property_pool->get_properties(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;
129  reference_location = particle.reference_location;
130  id = particle.id;
131  property_pool = particle.property_pool;
132 
133  if (particle.has_properties())
134  {
135  properties = property_pool->allocate_properties_array();
136  const ArrayView<const double> their_properties =
137  particle.get_properties();
138  const ArrayView<double> my_properties =
139  property_pool->get_properties(properties);
140 
141  std::copy(their_properties.begin(),
142  their_properties.end(),
143  my_properties.begin());
144  }
145  else
146  properties = PropertyPool::invalid_handle;
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  {
175  if (property_pool != nullptr && properties != PropertyPool::invalid_handle)
176  property_pool->deallocate_properties_array(properties);
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 =
202  property_pool->get_properties(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 =
222  property_pool->get_properties(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 
300  if (properties == PropertyPool::invalid_handle)
301  properties = property_pool->allocate_properties_array();
302 
303  const ArrayView<double> old_properties =
304  property_pool->get_properties(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  {
329  Assert(has_properties(), ExcInternalError());
330 
331  return property_pool->get_properties(properties);
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.
343  if (properties == PropertyPool::invalid_handle)
344  {
345  properties = property_pool->allocate_properties_array();
346 
347  ArrayView<double> my_properties =
348  property_pool->get_properties(properties);
349 
350  std::fill(my_properties.begin(), my_properties.end(), 0.0);
351  }
352 
353  return property_pool->get_properties(properties);
354  }
355 
356 
357 
358  template <int dim, int spacedim>
359  bool
361  {
362  return (property_pool != nullptr) &&
363  (properties != PropertyPool::invalid_handle);
364  }
365 } // namespace Particles
366 
368 
370 
371 #include "particle.inst"
372 
ArrayView::begin
iterator begin() const
Definition: array_view.h:493
ArrayView::end
iterator end() const
Definition: array_view.h:502
Particles::Particle::id
types::particle_index id
Definition: particle.h:386
DataOutBase::write_data
void write_data(const std::vector< Patch< dim, spacedim >> &patches, unsigned int n_data_sets, const bool double_precision, StreamType &out)
Definition: data_out_base.cc:2485
ArrayView
Definition: array_view.h:77
Patterns::Tools::to_string
std::string to_string(const T &t)
Definition: patterns.h:2360
Particles::PropertyPool
Definition: property_pool.h:43
Particles
Definition: data_out.h:27
ArrayView::size
std::size_t size() const
Definition: array_view.h:484
Particles::Particle
Definition: particle.h:146
StandardExceptions::ExcMessage
static ::ExceptionBase & ExcMessage(std::string arg1)
double
Particles::Particle::properties
PropertyPool::Handle properties
Definition: particle.h:397
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
numbers::signaling_nan
T signaling_nan()
Definition: signaling_nan.h:229
types::particle_index
unsigned int particle_index
Definition: particle.h:69
numbers
Definition: numbers.h:207
unsigned int
StandardExceptions::ExcInternalError
static ::ExceptionBase & ExcInternalError()
Particles::PropertyPool::allocate_properties_array
Handle allocate_properties_array()
Definition: property_pool.cc:33
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
particle.h
Particles::Particle::location
Point< spacedim > location
Definition: particle.h:376
Point
Definition: point.h:111
signaling_nan.h
Particles::Particle::has_properties
bool has_properties() const
Definition: particle.cc:360
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
Particles::Particle::property_pool
PropertyPool * property_pool
Definition: particle.h:392
Particles::Particle::reference_location
Point< dim > reference_location
Definition: particle.h:381
Particles::Particle::get_properties
const ArrayView< double > get_properties()
Definition: particle.cc:327
internal::VectorOperations::copy
void copy(const T *begin, const T *end, U *dest)
Definition: vector_operations_internal.h:67
Particles::Particle::Particle
Particle()
Definition: particle.cc:25