www.mooseframework.org
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
RestartableDataIO Class Reference

Class for doing restart. More...

#include <RestartableDataIO.h>

Inheritance diagram for RestartableDataIO:
[legend]

Public Member Functions

 RestartableDataIO (MooseApp &app, RestartableDataMap &data)
 
 RestartableDataIO (MooseApp &app, std::vector< RestartableDataMap > &data)
 
PerfGraphperfGraph ()
 Get the PerfGraph. More...
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static const std::string & getRestartableExt ()
 
static const std::string & restartableDataFile ()
 
static const std::string & restartableHeaderFile ()
 
static std::filesystem::path restartableDataFolder (const std::filesystem::path &folder_base)
 
static std::filesystem::path restartableDataFile (const std::filesystem::path &folder_base)
 
static std::filesystem::path restartableHeaderFile (const std::filesystem::path &folder_base)
 
static InputParameters validParams ()
 

Protected Types

typedef int COMPARE_HASH_CODE_TYPE
 The type to used for comparing hash codes (sanity checking) More...
 

Protected Member Functions

RestartableDataMapcurrentData (const THREAD_ID tid)
 
std::size_t dataSize () const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 Call to register a named section for timing. More...
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 Call to register a named section for timing. More...
 
std::string timedSectionName (const std::string &section_name) const
 

Protected Attributes

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. More...
 
MooseApp_pg_moose_app
 The MooseApp that owns the PerfGraph. More...
 
const std::string _prefix
 A prefix to use for all sections. More...
 
const Parallel::Communicator & _communicator
 

Static Protected Attributes

static const unsigned int CURRENT_BACKUP_FILE_VERSION = 4
 The current version for the backup file. More...
 

Detailed Description

Class for doing restart.

It takes care of writing and reading the restart files.

Definition at line 27 of file RestartableDataIO.h.

Member Typedef Documentation

◆ COMPARE_HASH_CODE_TYPE

The type to used for comparing hash codes (sanity checking)

Definition at line 84 of file RestartableDataIO.h.

Constructor & Destructor Documentation

◆ RestartableDataIO() [1/2]

RestartableDataIO::RestartableDataIO ( MooseApp app,
RestartableDataMap data 
)

Definition at line 18 of file RestartableDataIO.C.

19  : PerfGraphInterface(app.perfGraph(), "RestartableDataIO"),
21  _data(&data)
22 {
23 }
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...
PerfGraphInterface(const MooseObject *moose_object)
For objects that are MooseObjects with a default prefix of type()
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition: MooseApp.h:133

◆ RestartableDataIO() [2/2]

RestartableDataIO::RestartableDataIO ( MooseApp app,
std::vector< RestartableDataMap > &  data 
)

Definition at line 25 of file RestartableDataIO.C.

26  : PerfGraphInterface(app.perfGraph(), "RestartableDataIO"),
28  _data(&data)
29 {
30 }
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...
PerfGraphInterface(const MooseObject *moose_object)
For objects that are MooseObjects with a default prefix of type()
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition: MooseApp.h:133

Member Function Documentation

◆ currentData()

RestartableDataMap & RestartableDataIO::currentData ( const THREAD_ID  tid)
protected
Returns
The restartable data for thread tid

This exists so that we can support threaded and non-threaded data in _data

Definition at line 33 of file RestartableDataIO.C.

Referenced by RestartableDataReader::restore(), RestartableDataReader::restoreData(), and RestartableDataWriter::write().

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 }
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...
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

◆ dataSize()

std::size_t RestartableDataIO::dataSize ( ) const
protected
Returns
The size of _data

Definition at line 43 of file RestartableDataIO.C.

Referenced by currentData(), RestartableDataReader::readHeader(), RestartableDataReader::restore(), and RestartableDataWriter::write().

44 {
45  return std::holds_alternative<RestartableDataMap *>(_data)
46  ? 1
47  : std::get<std::vector<RestartableDataMap> *>(_data)->size();
48 }
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...
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

◆ getRestartableExt()

const std::string & RestartableDataIO::getRestartableExt ( )
static
Returns
The common extension for restartable data folders

Definition at line 51 of file RestartableDataIO.C.

Referenced by restartableDataFolder().

52 {
53  static const std::string ext = ".rd";
54  return ext;
55 }

◆ perfGraph()

PerfGraph & PerfGraphInterface::perfGraph ( )
inherited

Get the PerfGraph.

Definition at line 78 of file PerfGraphInterface.C.

Referenced by CommonOutputAction::act(), PerfGraphData::finalize(), and PerfGraphOutput::output().

79 {
80  return _pg_moose_app.perfGraph();
81 }
MooseApp & _pg_moose_app
The MooseApp that owns the PerfGraph.
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition: MooseApp.h:133

◆ registerTimedSection() [1/2]

PerfID PerfGraphInterface::registerTimedSection ( const std::string &  section_name,
const unsigned int  level 
) const
protectedinherited

Call to register a named section for timing.

Parameters
section_nameThe name of the code section to be timed
levelThe importance of the timer - lower is more important (0 will always come out)
Returns
The ID of the section - use when starting timing

Definition at line 53 of file PerfGraphInterface.C.

55 {
56  const auto timed_section_name = timedSectionName(section_name);
57  if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
58  return moose::internal::getPerfGraphRegistry().registerSection(timed_section_name, level);
59  else
60  return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
61 }
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
std::string timedSectionName(const std::string &section_name) const
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.

◆ registerTimedSection() [2/2]

PerfID PerfGraphInterface::registerTimedSection ( const std::string &  section_name,
const unsigned int  level,
const std::string &  live_message,
const bool  print_dots = true 
) const
protectedinherited

Call to register a named section for timing.

Parameters
section_nameThe name of the code section to be timed
levelThe importance of the timer - lower is more important (0 will always come out)
live_messageThe message to be printed to the screen during execution
print_dotsWhether or not progress dots should be printed for this section
Returns
The ID of the section - use when starting timing

Definition at line 64 of file PerfGraphInterface.C.

68 {
69  const auto timed_section_name = timedSectionName(section_name);
70  if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
72  timedSectionName(section_name), level, live_message, print_dots);
73  else
74  return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
75 }
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
std::string timedSectionName(const std::string &section_name) const
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.

◆ restartableDataFile() [1/2]

const std::string & RestartableDataIO::restartableDataFile ( )
static
Returns
The filename for the restartable data

Definition at line 58 of file RestartableDataIO.C.

Referenced by RestartableDataReader::isAvailable(), restartableDataFile(), RestartableDataReader::setInput(), and RestartableDataWriter::write().

59 {
60  static const std::string file = "data";
61  return file;
62 }

◆ restartableDataFile() [2/2]

std::filesystem::path RestartableDataIO::restartableDataFile ( const std::filesystem::path &  folder_base)
static
Returns
The path to the restartable data file with base folder_base

Does not append .rd to the folder base

Definition at line 80 of file RestartableDataIO.C.

81 {
82  return folder_base / restartableDataFile();
83 }
static const std::string & restartableDataFile()

◆ restartableDataFolder()

std::filesystem::path RestartableDataIO::restartableDataFolder ( const std::filesystem::path &  folder_base)
static
Returns
The path to the restartable data folder with base folder_base

This just appends .rd

Definition at line 72 of file RestartableDataIO.C.

Referenced by MooseApp::metaDataFolderBase(), and MooseApp::restartFolderBase().

73 {
74  auto folder = folder_base;
75  folder += getRestartableExt();
76  return folder;
77 }
static const std::string & getRestartableExt()

◆ restartableHeaderFile() [1/2]

const std::string & RestartableDataIO::restartableHeaderFile ( )
static
Returns
The filename for the restartable header

Definition at line 65 of file RestartableDataIO.C.

Referenced by restartableHeaderFile(), RestartableDataReader::setInput(), and RestartableDataWriter::write().

66 {
67  static const std::string file = "header";
68  return file;
69 }

◆ restartableHeaderFile() [2/2]

std::filesystem::path RestartableDataIO::restartableHeaderFile ( const std::filesystem::path &  folder_base)
static
Returns
The path to the restartable header file with base folder_base

Does not append .rd to the folder base

Definition at line 86 of file RestartableDataIO.C.

87 {
88  return folder_base / restartableHeaderFile();
89 }
static const std::string & restartableHeaderFile()

◆ timedSectionName()

std::string PerfGraphInterface::timedSectionName ( const std::string &  section_name) const
protectedinherited
Returns
The name of the timed section with the name section_name.

Optionally adds a prefix if one is defined.

Definition at line 47 of file PerfGraphInterface.C.

Referenced by PerfGraphInterface::registerTimedSection().

48 {
49  return _prefix.empty() ? "" : (_prefix + "::") + section_name;
50 }
const std::string _prefix
A prefix to use for all sections.

◆ validParams()

InputParameters PerfGraphInterface::validParams ( )
staticinherited

Definition at line 16 of file PerfGraphInterface.C.

17 {
19  return params;
20 }
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters emptyInputParameters()

Member Data Documentation

◆ _data

const std::variant<RestartableDataMap *, std::vector<RestartableDataMap> *> RestartableDataIO::_data
protected

The data we wish to act on This is a variant so that we can act on threaded and non-threaded data.

Definition at line 79 of file RestartableDataIO.h.

Referenced by currentData(), and dataSize().

◆ _pg_moose_app

MooseApp& PerfGraphInterface::_pg_moose_app
protectedinherited

The MooseApp that owns the PerfGraph.

Definition at line 124 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::perfGraph().

◆ _prefix

const std::string PerfGraphInterface::_prefix
protectedinherited

A prefix to use for all sections.

Definition at line 127 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::timedSectionName().

◆ CURRENT_BACKUP_FILE_VERSION

const unsigned int RestartableDataIO::CURRENT_BACKUP_FILE_VERSION = 4
staticprotected

The current version for the backup file.

Definition at line 82 of file RestartableDataIO.h.

Referenced by RestartableDataReader::readHeader(), and RestartableDataWriter::write().


The documentation for this class was generated from the following files: