Line data Source code
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 21 66 : Packing<std::tuple<unsigned int, unsigned int, std::shared_ptr<DenseVector<Real>>>>::packable_size( 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 66 : total_size += std::get<2>(object)->size(); 32 : 33 66 : return total_size; 34 : } 35 : 36 : unsigned int 37 66 : Packing<std::tuple<unsigned int, unsigned int, std::shared_ptr<DenseVector<Real>>>>::packed_size( 38 : typename std::vector<Real>::const_iterator in) 39 : { 40 : unsigned int total_size = 0; 41 : 42 : // The size of the dense vector 43 66 : 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 66 : total_size += vector_size; 50 : 51 66 : return total_size; 52 : } 53 : 54 : template <> 55 : void 56 66 : Packing<std::tuple<unsigned int, unsigned int, std::shared_ptr<DenseVector<Real>>>>::pack( 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 66 : data_out = dense_vector->size(); 64 : 65 : // Encoding the global index and the variable index 66 66 : data_out = std::get<0>(object); 67 66 : data_out = std::get<1>(object); 68 : 69 : // Encoding the vector elements 70 : const auto & vector = dense_vector->get_values(); 71 2970 : for (std::size_t i = 0; i < dense_vector->size(); ++i) 72 : data_out = vector[i]; 73 66 : } 74 : 75 : template <> 76 : std::tuple<unsigned int, unsigned int, std::shared_ptr<DenseVector<Real>>> 77 66 : Packing<std::tuple<unsigned int, unsigned int, std::shared_ptr<DenseVector<Real>>>>::unpack( 78 : std::vector<Real>::const_iterator in, void *) 79 : { 80 : // Decoding the vector length 81 66 : const std::size_t data_size = *in++; 82 66 : 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 66 : std::get<0>(object) = *in++; 86 66 : std::get<1>(object) = *in++; 87 : 88 : // Decoding and filling the values in the vector. 89 : auto & dense_vector = std::get<2>(object); 90 66 : dense_vector = std::make_shared<DenseVector<Real>>(data_size); 91 : auto & vector_values = dense_vector->get_values(); 92 2970 : for (std::size_t i = 0; i < data_size; ++i) 93 2904 : vector_values[i] = *in++; 94 66 : return object; 95 : } 96 : 97 : } // namespace Parallel 98 : } // namespace libMesh