www.mooseframework.org
RestartableDataIO.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "RestartableDataIO.h"
11 
12 #include "MooseApp.h"
13 
14 // 3 - Restart system rewrite
15 // 4 - Added advanced stateful restore
17 
19  : PerfGraphInterface(app.perfGraph(), "RestartableDataIO"),
20  libMesh::ParallelObject(app),
21  _data(&data)
22 {
23 }
24 
25 RestartableDataIO::RestartableDataIO(MooseApp & app, std::vector<RestartableDataMap> & data)
26  : PerfGraphInterface(app.perfGraph(), "RestartableDataIO"),
27  libMesh::ParallelObject(app),
28  _data(&data)
29 {
30 }
31 
34 {
35  mooseAssert(dataSize() > tid, "Invalid thread");
36 
37  if (std::holds_alternative<RestartableDataMap *>(_data))
38  return *std::get<RestartableDataMap *>(_data);
39  return (*std::get<std::vector<RestartableDataMap> *>(_data))[tid];
40 }
41 
42 std::size_t
44 {
45  return std::holds_alternative<RestartableDataMap *>(_data)
46  ? 1
47  : std::get<std::vector<RestartableDataMap> *>(_data)->size();
48 }
49 
50 const std::string &
52 {
53  static const std::string ext = ".rd";
54  return ext;
55 }
56 
57 const std::string &
59 {
60  static const std::string file = "data";
61  return file;
62 }
63 
64 const std::string &
66 {
67  static const std::string file = "header";
68  return file;
69 }
70 
71 std::filesystem::path
72 RestartableDataIO::restartableDataFolder(const std::filesystem::path & folder_base)
73 {
74  auto folder = folder_base;
75  folder += getRestartableExt();
76  return folder;
77 }
78 
79 std::filesystem::path
80 RestartableDataIO::restartableDataFile(const std::filesystem::path & folder_base)
81 {
82  return folder_base / restartableDataFile();
83 }
84 
85 std::filesystem::path
86 RestartableDataIO::restartableHeaderFile(const std::filesystem::path & folder_base)
87 {
88  return folder_base / restartableHeaderFile();
89 }
static const std::string & restartableDataFile()
const std::variant< RestartableDataMap *, std::vector< RestartableDataMap > * > _data
The data we wish to act on This is a variant so that we can act on threaded and non-threaded data...
static const unsigned int CURRENT_BACKUP_FILE_VERSION
The current version for the backup file.
std::size_t dataSize() const
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1147
static const std::string & restartableHeaderFile()
Base class for MOOSE-based applications.
Definition: MooseApp.h:73
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
RestartableDataMap & currentData(const THREAD_ID tid)
Storage for restartable data that is ordered based on insertion order.
static const std::string & getRestartableExt()
Interface for objects interacting with the PerfGraph.
static std::filesystem::path restartableDataFolder(const std::filesystem::path &folder_base)
RestartableDataIO(MooseApp &app, RestartableDataMap &data)
unsigned int THREAD_ID
Definition: MooseTypes.h:198