MADNESS 0.10.1
DFRestart.h
Go to the documentation of this file.
1/// \file DFRestart.h
2/// \brief Format version for DFdriver restart archives, and its validation.
3
4#ifndef MADNESS_APPS_DIRAC_DFRESTART_H_INCLUDED
5#define MADNESS_APPS_DIRAC_DFRESTART_H_INCLUDED
6
8
9namespace madness {
10
11/// Format version for DFdriver restart archives.
12///
13/// Earlier archives carry no version field, and this code rejects them. The read
14/// goes through the type cookie that the BinaryFstream archives write.
15///
16/// Current Version:
17/// 0) DF restart format version (unsigned int)
18/// 1) Total energy (double)
19/// 2) Krestricted (boolean)
20/// 3) closed_shell (boolean)
21/// 4) number of occupied orbitals (unsigned int)
22/// 5) orbital energies (vector of doubles)
23/// 6) box size (double)
24/// 7) wavelet order (int)
25/// 8) molecule (molecule)
26/// 9) occupied orbitals as complex functions
27///
28/// \note v1 introduced format version
29inline constexpr unsigned int DF_RESTART_VERSION = 1;
30
31/// Writes the current DF restart format version as the first datum in the archive.
32template <typename Archive>
33void write_df_restart_version(const Archive& ar) {
34 const unsigned int version = DF_RESTART_VERSION;
35 ar & version;
36}
37
38/// Returns the format version, or 0 for an unversioned archive.
39///
40/// Reads from a *local* archive, so the caller decides which rank reads.
41template <typename Archive>
42unsigned int read_df_restart_version(const Archive& ar) {
43 unsigned int version = 0;
44 try {
45 ar & version;
46 } catch (const MadnessException&) {
47 // Type cookie mismatch: the first datum is a double, so the archive
48 // has no version. The archive prints its own message to stderr
49 // before it throws. The what() of that exception points at a stack
50 // buffer, and this code must not read it.
51 return 0;
52 }
53 return version;
54}
55
56/// Throws unless \c version is a DF restart format this build can read.
57inline void require_supported_df_restart(const unsigned int version) {
58 MADNESS_CHECK_THROW(version != 0,
59 "unversioned DF restart archive! start from a moldft archive or "
60 "rerun with the older DFdriver");
62 "unsupported DF restart archive version! DF restart archive was written"
63 " by a newer DFdriver; use that DFdriver or start from a moldft "
64 "archive");
65}
66
67} // namespace madness
68
69#endif
Base class for exceptions thrown in MADNESS.
Definition madness_exception.h:66
Defines madness::MadnessException for exception handling.
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
constexpr unsigned int DF_RESTART_VERSION
Definition DFRestart.h:29
unsigned int read_df_restart_version(const Archive &ar)
Definition DFRestart.h:42
void require_supported_df_restart(const unsigned int version)
Throws unless version is a DF restart format this build can read.
Definition DFRestart.h:57
void write_df_restart_version(const Archive &ar)
Writes the current DF restart format version as the first datum in the archive.
Definition DFRestart.h:33