Loading...
Searching...
No Matches
base.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * Flavor — abstract interface for a Q3 calculation mode.
5 *
6 * A Flavor encapsulates a complete calculation workflow (SCF, NSCF, etc.)
7 * and returns its results as results.json's own struct, generated::Results.
8 */
9
10#include "io/input/data.hpp"
12#include "io/output/results.hpp"
15
16namespace q3 {
17
18class Flavor {
19 public:
20 virtual ~Flavor() = default;
21
22 /**
23 * Execute the calculation described by the input and return results,
24 * stamped with the provenance of the run that produced them, the material
25 * it ran on, and the band edges and gap its eigenvalues give.
26 *
27 * Not virtual, and the reason is the stamp. Provenance attached at the call
28 * sites instead would mean every present and future caller had to remember
29 * to attach it, and the one that forgot would emit a results file
30 * indistinguishable from an unattributable one. Here it is structural: a
31 * flavor cannot run without being attributed.
32 *
33 * Re-reading the pseudopotential files to identify them costs milliseconds
34 * against a calculation that has already finished, which is the right trade
35 * for a subclass never having to carry provenance plumbing of its own.
36 */
37 generated::Results run(const InputData& input) {
38 generated::Results results = run_calculation(input);
39 if (nlohmann::json provenance = build_provenance_json(input); !provenance.is_null()) {
40 results.provenance = std::move(provenance);
41 }
42 if (nlohmann::json material = build_material_json(input); !material.is_null()) {
43 results.structure = generated::ResultsStructure{std::move(material)};
44 }
45 add_band_edge_records(results);
46 return results;
47 }
48
49 protected:
50 /**
51 * Execute the calculation described by the input and return results.
52 *
53 * Implementations must be self-contained: they set up, run, and finalize
54 * the calculation entirely. The caller receives fully-populated results,
55 * minus what run() adds.
56 */
57 virtual generated::Results run_calculation(const InputData& input) = 0;
58};
59
60} // namespace q3
generated::Results run(const InputData &input)
Definition base.hpp:37
virtual ~Flavor()=default
virtual generated::Results run_calculation(const InputData &input)=0
nlohmann::json build_material_json(const InputData &input)
Definition init.hpp:73
void add_band_edge_records(generated::Results &results)
nlohmann::json build_provenance_json(const InputData &input)
Build the provenance block for a completed run, from the input it consumed.
Definition factory.hpp:44
Parsed input data — holds raw values read from input files.
Definition data.hpp:27