AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
BackupWriter.hpp
1#pragma once
2
3#include <string>
4#include <memory>
5#include <utility>
6
7#include <dune/grid/common/backuprestore.hh>
8#include <dune/grid/common/capabilities.hh>
9
10#include <amdis/BackupRestore.hpp>
11#include <amdis/Initfile.hpp>
12#include <amdis/Output.hpp>
13#include <amdis/common/Filesystem.hpp>
14#include <amdis/io/FileWriterBase.hpp>
15
16namespace AMDiS
17{
18 template <class SystemVector>
20 : public FileWriterBase
21 {
22 using GlobalBasis = typename SystemVector::GlobalBasis;
23 using GridView = typename GlobalBasis::GridView;
24 using Grid = typename GridView::Grid;
25
26 public:
28 BackupWriter(std::string const& name, std::shared_ptr<SystemVector> systemVector)
29 : FileWriterBase(name)
30 , systemVector_(std::move(systemVector))
31 {
32 Parameters::get(name + "->animation", animation_);
33 }
34
36 void write(AdaptInfo& adaptInfo, bool force) override
37 {
38 std::string filename = filesystem::path({this->dir(), this->filename()}).string();
39
40 if (animation_)
41 filename += "_" + std::to_string(adaptInfo.timestepNumber());
42
43 if (this->doWrite(adaptInfo) || force) {
44 GridView const& gridView = systemVector_->basis().gridView();
45 backupGrid(gridView, filename + ".grid",
46 bool_t<Dune::Capabilities::hasBackupRestoreFacilities<Grid>::v>{});
47 systemVector_->backup(filename + ".solution");
48
49 msg("Backup written to files '{}' and '{}'.", filename + ".grid", filename + ".solution");
50 }
51 }
52
53
54 private:
55
56 template <class G = Grid,
57 class = decltype(Dune::BackupRestoreFacility<G>::backup(std::declval<G>(), std::string("")))>
58 void backupGrid(GridView const& gv, std::string filename, std::true_type)
59 {
60 Dune::BackupRestoreFacility<Grid>::backup(gv.grid(), filename);
61 }
62
63 template <bool B, class G = Grid, class GV = GridView,
64 class = decltype(BackupRestoreByGridFactory<G>::backup(std::declval<GV>(), std::string("")))>
65 void backupGrid(GridView const& gv, std::string filename, bool_t<B>)
66 {
67 warning("Falling back to backup of gridview.");
69 }
70
71 private:
72 std::shared_ptr<SystemVector> systemVector_;
73
75 bool animation_ = false;
76 };
77
78} // end namespace AMDiS
Holds adapt parameters and infos about the problem.
Definition: AdaptInfo.hpp:26
int timestepNumber() const
Returns timestepNumber_.
Definition: AdaptInfo.hpp:255
static void backup(GridView const &gv, std::string const &filename)
Write a hierarchic grid to disk.
Definition: BackupRestore.hpp:123
Definition: BackupWriter.hpp:21
void write(AdaptInfo &adaptInfo, bool force) override
Implements FileWriterBase::write.
Definition: BackupWriter.hpp:36
BackupWriter(std::string const &name, std::shared_ptr< SystemVector > systemVector)
Constructor.
Definition: BackupWriter.hpp:28
Base class for filewriters.
Definition: FileWriterBase.hpp:39
bool doWrite(AdaptInfo &adaptInfo) const
Return whether to write the current timestep or not.
Definition: FileWriterBase.cpp:24
typename PreBasis::GridView GridView
The grid view that the FE space is defined on.
Definition: GlobalBasis.hpp:57
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
Definition: Filesystem.hpp:13
constexpr bool GlobalBasis
A Dune::Functions::GlobalBasis type.
Definition: Concepts.hpp:189