Loading...
Searching...
No Matches
factory.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * Factory for DispersionCalculator implementations.
5 *
6 * Resolves the input's dispersion-correction name (InputData::
7 * dispersion_correction / YAML `model.dispersion`) to a concrete scheme,
8 * mirroring the mixing and smearing factories. "none" (or empty) resolves to
9 * NullDispersionCalculator so call sites need no branching; unknown names
10 * fail loudly rather than silently running without the correction the user
11 * asked for. Adding a scheme = one new class implementing
12 * DispersionCalculator + one case here.
13 */
14
15#include <memory>
16#include <stdexcept>
17#include <string>
18
23
24namespace q3 {
25
26[[nodiscard]] inline std::unique_ptr<DispersionCalculator>
27create_dispersion_calculator(const std::string& dispersion_correction,
28 const Crystal& crystal_structure) {
29 if (dispersion_correction.empty() || dispersion_correction == "none") {
30 return std::make_unique<NullDispersionCalculator>(crystal_structure);
31 }
32 if (dispersion_correction == "d3bj") {
33 return std::make_unique<D3BJDispersionCalculator>(crystal_structure);
34 }
35 throw std::runtime_error("Unknown dispersion correction '" + dispersion_correction +
36 "'. Supported: none, d3bj");
37}
38
39} // namespace q3
std::unique_ptr< DispersionCalculator > create_dispersion_calculator(const std::string &dispersion_correction, const Crystal &crystal_structure)
Definition factory.hpp:27