Loading...
Searching...
No Matches
self_consistent_potential.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * BerkeleyGWSelfConsistentPotentialFile — writes BerkeleyGW's `VSC` file: the
5 * local Kohn-Sham potential, V_loc + V_H + V_xc, from which ParaBands builds
6 * the local part of the Hamiltonian it diagonalizes.
7 *
8 * Layout: BerkeleyGWFieldFile with the title "VSC-Complex" -- ParaBands reads
9 * it with BerkeleyGW's RHO/VXC routines (`MeanField/ParaBands/parabands.f90`),
10 * one field per spin, Rydberg, unscaled. ParaBands adds V_sc(G − G') to each
11 * matrix element (`ham_build_column_loc` in `MeanField/ParaBands/hamiltonian.f90`),
12 * so the convention needed is the plane-wave matrix element of the potential:
13 * with Q3's transform, whose G = 0 component is the cell average, that is the
14 * record's `self_consistent_potential_g` as it stands.
15 */
16
17#include <fstream>
18#include <stdexcept>
19#include <string>
20
21#include "io/logger.hpp"
24
25namespace q3 {
26
27/// Writes `VSC` from a mean-field record; see the file comment.
29 public:
31 : record_(record) {}
32 /// See BerkeleyGWChargeDensityFile: this holds a reference.
34
35 /// Writes the file, or throws -- before creating it -- when the record carries no potential.
36 void write_to_file(const std::string& file_path) const {
37 if (record_.self_consistent_potential_g.empty()) {
38 throw std::runtime_error(
39 "the mean-field record carries no self-consistent potential (a record read "
40 "back from mean-field.q3mf does not store it; export from the run itself)");
41 }
42
43 std::ofstream output_file(file_path, std::ios::binary);
44 if (!output_file.is_open()) {
45 throw std::runtime_error("cannot open " + file_path + " for writing");
46 }
47 BerkeleyGWFieldFile(record_, "VSC-Complex", record_.self_consistent_potential_g, 1.0)
48 .write(output_file);
49
50 log::info(" Wrote BerkeleyGW self-consistent potential file: {}", file_path);
51 }
52
53 private:
54 const MeanFieldRecord& record_;
55};
56
57} // namespace q3
One per-spin field on the charge-density G-set, in RHO's layout; see the file comment.
Definition field.hpp:32
void write(std::ofstream &output_file) const
Writes header, G-set and field to an open stream; throws if the field is not on the G-set.
Definition field.hpp:55
Writes VSC from a mean-field record; see the file comment.
BerkeleyGWSelfConsistentPotentialFile(const MeanFieldRecord &&)=delete
See BerkeleyGWChargeDensityFile: this holds a reference.
void write_to_file(const std::string &file_path) const
Writes the file, or throws – before creating it – when the record carries no potential.
BerkeleyGWSelfConsistentPotentialFile(const MeanFieldRecord &record)
void info(spdlog::format_string_t< Args... > fmt, Args &&... args)
Definition logger.hpp:183
std::vector< std::vector< Complex > > self_consistent_potential_g
Definition init.hpp:162