Loading...
Searching...
No Matches
factory.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * MixerFactory — creates charge-density mixer instances by name.
5 *
6 * Supported mixers:
7 * - "broyden" G-space quasi-Newton (default). Best for insulators and semiconductors.
8 * - "linear" Simple linear (plain) mixing in G-space. Unconditionally stable;
9 * recommended for metallic US systems where Broyden may diverge.
10 * - "anderson" Real-space Pulay/DIIS mixing.
11 *
12 * All mixers accept mixing_parameter and history_depth (unused for linear).
13 */
14
15#include <memory>
16#include <stdexcept>
17#include <string>
18
22
23namespace q3 {
24namespace MixerFactory {
25
26/// Create a charge density mixer by name ("broyden", "linear", or "anderson").
27inline std::unique_ptr<Mixer>
28create(const std::string& mode, Real mixing_parameter = 0.7, int history_depth = 8) {
29 if (mode == "broyden") {
30 return std::make_unique<BroydenMixer>(mixing_parameter, history_depth);
31 }
32 if (mode == "linear") {
33 return std::make_unique<LinearMixer>(mixing_parameter);
34 }
35 if (mode == "anderson") {
36 return std::make_unique<AndersonMixer>(mixing_parameter, history_depth);
37 }
38 throw std::runtime_error("Unknown mixer mode: '" + mode +
39 "'. Supported values: 'broyden', 'linear', 'anderson'.");
40}
41
42} // namespace MixerFactory
43} // namespace q3
std::unique_ptr< Mixer > create(const std::string &mode, Real mixing_parameter=0.7, int history_depth=8)
Create a charge density mixer by name ("broyden", "linear", or "anderson").
Definition factory.hpp:28
double Real