AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
DOFVector.inc.hpp
1#pragma once
2
3#include <cassert>
4#include <cstdint>
5#include <fstream>
6#include <string>
7#include <vector>
8
9#include <amdis/operations/Assigner.hpp>
10
11namespace AMDiS {
12
13template <class GB, class T, class Traits>
15backup(std::string const& filename)
16{
17 std::ofstream out(filename, std::ios::binary);
18
19 std::int64_t numElements = this->basis().gridView().size(0);
20 out.write((char*)&numElements, sizeof(std::int64_t));
21
22 auto localView = this->basis().localView();
23 std::vector<value_type> data;
24 for (auto const& element : elements(this->basis().gridView()))
25 {
26 localView.bind(element);
27 this->gather(localView, data);
28
29 std::uint64_t len = data.size();
30 out.write((char*)&len, sizeof(std::uint64_t));
31 out.write((char*)data.data(), len*sizeof(value_type));
32
33 localView.unbind();
34 }
35}
36
37
38template <class GB, class T, class Traits>
40restore(std::string const& filename)
41{
42 std::ifstream in(filename, std::ios::binary);
43
44 std::int64_t numElements = 0;
45 in.read((char*)&numElements, sizeof(std::int64_t));
46 assert(numElements == this->basis().gridView().size(0));
47
48 // assume the order of element traversal is not changed
49 auto localView = this->basis().localView();
50 std::vector<value_type> data;
51 this->init(this->basis(), true);
52 for (auto const& element : elements(this->basis().gridView()))
53 {
54 std::uint64_t len = 0;
55 in.read((char*)&len, sizeof(std::uint64_t));
56 data.resize(len);
57
58 in.read((char*)data.data(), len*sizeof(value_type));
59
60 localView.bind(element);
61 this->scatter(localView, data, Assigner::assign{});
62 localView.unbind();
63 }
64 this->finish();
65}
66
67} // end namespace AMDiS
void restore(std::string const &filename)
Read backup data from file.
Definition: DOFVector.inc.hpp:40
void backup(std::string const &filename)
Write DOFVector to file.
Definition: DOFVector.inc.hpp:15
T value_type
The type of the elements of the DOFVector.
Definition: DOFVector.hpp:60
Definition: Assigner.hpp:8