Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
dunedataio.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNEDATAIO_HH
5#define DUNEDATAIO_HH
6
7#ifdef HAVE_BOOST_SERIALIZATION
8
10#include <dune/istl/bvector.hh>
11
12#include <boost/serialization/split_free.hpp>
13
14/* supplies serialize functions for several Dune types in order to be able to use boost::serialization on them */
15namespace boost {
16namespace serialization {
17
18/* as we need not not do fundamentally different things in saving and loading we can supply only one function.
19 * mark the use of the operator & that works both ways, << or >> , depending on the type of Archive.
20 */
21template <class Archive, class T, int n>
22void serialize(Archive& ar, Dune::FieldVector<T,n>& fvec, [[maybe_unused]] const unsigned int version)
23{
24 for (int i=0; i<n; ++i)
25 ar & fvec[i];
26}
27
28/* For Dune::BlockVectors we need to store the size separately and treat it separately during loading. Thus we need
29 * two separate save() and load() functions later to be "unified" via boost::serialization::split_free (see below)
30 */
31template <class Archive, class BlockType>
32void save(Archive& ar, const Dune::BlockVector<BlockType>& vec, [[maybe_unused]] const unsigned int version)
33{
34 size_t size = vec.size();
35 ar << size;
36 for (size_t i=0; i<vec.size(); ++i)
37 ar << vec[i];
38}
39
40template <class Archive, class BlockType>
41void load(Archive& ar, Dune::BlockVector<BlockType>& vec, [[maybe_unused]] const unsigned int version)
42{
43 size_t size;
44 ar >> size;
45 vec.resize(size);
46 for (size_t i=0; i<size; ++i)
47 ar >> vec[i];
48}
49
50template<class Archive, class BlockType>
51void serialize(Archive& ar, Dune::BlockVector<BlockType>& vec, const unsigned int version)
52{
53 boost::serialization::split_free(ar, vec, version);
54}
55
56}} // ends of namespaces serialization and boost
57
58#else
59#warning dunedataio.hh was included but boost_serialization was not found !
60#endif
61
62#endif
63
int size() const
void resize(size_type size)