https://mooseframework.inl.gov
VectorPacker.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "VectorPacker.h"
11 #include "SerializerGuard.h"
12 #include "libmesh/parallel_algebra.h"
13 #include "libmesh/parallel_sync.h"
14 
15 namespace libMesh
16 {
17 namespace Parallel
18 {
19 
20 unsigned int
22  const std::tuple<unsigned int, unsigned int, std::shared_ptr<DenseVector<Real>>> & object,
23  const void *)
24 {
25  unsigned int total_size = 0;
26 
27  // This package will contain a number for the global index, a number for the
28  // variable index and a number for the size of the DenseVector. Then it contains
29  // every item in the DenseVector as well.
30  total_size += 3;
31  total_size += std::get<2>(object)->size();
32 
33  return total_size;
34 }
35 
36 unsigned int
38  typename std::vector<Real>::const_iterator in)
39 {
40  unsigned int total_size = 0;
41 
42  // The size of the dense vector
43  const unsigned int vector_size = *in++;
44 
45  // Adding spaces for the vector size, global sample index and variable index.
46  total_size += 3;
47 
48  // Adding spaces for the elements of the vector.
49  total_size += vector_size;
50 
51  return total_size;
52 }
53 
54 template <>
55 void
57  const std::tuple<unsigned int, unsigned int, std::shared_ptr<DenseVector<Real>>> & object,
58  std::back_insert_iterator<std::vector<Real>> data_out,
59  const void *)
60 {
61  // Encoding the size of the vector
62  const auto & dense_vector = std::get<2>(object);
63  data_out = dense_vector->size();
64 
65  // Encoding the global index and the variable index
66  data_out = std::get<0>(object);
67  data_out = std::get<1>(object);
68 
69  // Encoding the vector elements
70  const auto & vector = dense_vector->get_values();
71  for (std::size_t i = 0; i < dense_vector->size(); ++i)
72  data_out = vector[i];
73 }
74 
75 template <>
76 std::tuple<unsigned int, unsigned int, std::shared_ptr<DenseVector<Real>>>
78  std::vector<Real>::const_iterator in, void *)
79 {
80  // Decoding the vector length
81  const std::size_t data_size = *in++;
82  std::tuple<unsigned int, unsigned int, std::shared_ptr<DenseVector<Real>>> object;
83 
84  // Decoding and filling the global sample index and variable index
85  std::get<0>(object) = *in++;
86  std::get<1>(object) = *in++;
87 
88  // Decoding and filling the values in the vector.
89  auto & dense_vector = std::get<2>(object);
90  dense_vector = std::make_shared<DenseVector<Real>>(data_size);
91  auto & vector_values = dense_vector->get_values();
92  for (std::size_t i = 0; i < data_size; ++i)
93  vector_values[i] = *in++;
94  return object;
95 }
96 
97 } // namespace Parallel
98 } // namespace libMesh
BufferType pack(const ValueType value)
Packs value into a value of type BufferType at a byte level, to be unpacked with the unpack() routine...
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
void unpack(const BufferType value_as_buffer_type, ValueType &value)
Unpacks value_as_buffer_type (which is packed with pack()) into value at a byte level.