id
int64 0
877k
| file_name
stringlengths 3
109
| file_path
stringlengths 13
185
| content
stringlengths 31
9.38M
| size
int64 31
9.38M
| language
stringclasses 1
value | extension
stringclasses 11
values | total_lines
int64 1
340k
| avg_line_length
float64 2.18
149k
| max_line_length
int64 7
2.22M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 6
66
| repo_stars
int64 94
47.3k
| repo_forks
int64 0
12k
| repo_open_issues
int64 0
3.4k
| repo_license
stringclasses 11
values | repo_extraction_date
stringclasses 197
values | exact_duplicates_redpajama
bool 2
classes | near_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 2
classes | exact_duplicates_stackv2
bool 1
class | exact_duplicates_stackv1
bool 2
classes | near_duplicates_githubcode
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_stackv2
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1,535,635
|
algo.hpp
|
rokzitko_nrgljubljana/c++/algo.hpp
|
#ifndef _algo_hpp_
#define _algo_hpp_
#include <string>
#include <memory>
#include <list>
#include <functional> // std::function
#include <fmt/format.h>
#include "traits.hpp"
#include "params.hpp"
#include "eigen.hpp"
#include "operators.hpp"
#include "invar.hpp"
#include "step.hpp"
#include "stats.hpp"
namespace NRG {
// Wrapper class for NRG spectral-function algorithms
template<scalar S, typename t_coef = coef_traits<S>, typename Matrix = Matrix_traits<S>>
class Algo {
private:
public:
const Params &P;
Algo() = delete;
Algo(const Algo&) = delete;
explicit Algo(const Params &P) : P(P) {}
virtual ~Algo() {}
virtual void begin(const Step &) = 0;
virtual void calc(const Step &, const Eigen<S> &, const Eigen<S> &, const Matrix &, const Matrix &,
const t_coef, const Invar &, const Invar &, const DensMatElements<S> &, const Stats<S> &stats) = 0;
virtual void end(const Step &) = 0;
virtual std::string rho_type() { return ""; } // what rho type is required
};
using FactorFnc = std::function<double(const Invar &, const Invar &)>;
using CheckFnc = std::function<bool(const Invar &, const Invar &, int)>;
// All information about calculating a spectral function: pointers to the operator data, raw spectral data
// acccumulators, algorithm, etc.
template <scalar S>
class BaseSpectrum {
public:
const MatrixElements<S> &op1, &op2;
int spin{}; // -1 or +1, or 0 where irrelevant
using spAlgo = std::shared_ptr<Algo<S>>;
spAlgo algo; // Algo_FDM, Algo_DMNRG,...
FactorFnc ff;
CheckFnc cf;
BaseSpectrum(const MatrixElements<S> &op1, const MatrixElements<S> &op2, const int spin, spAlgo algo, FactorFnc ff, CheckFnc cf) :
op1(op1), op2(op2), spin(spin), algo(algo), ff(ff), cf(cf) {}
// Calculate (finite temperature) spectral function 1/Pi Im << op1^\dag(t) op2(0) >>. Required spin direction is
// determined by 'SPIN'. For SPIN=0 both spin direction are equivalent. For QSZ, we need to differentiate the two.
void calc(const Step &step, const DiagInfo<S> &diag,
const DensMatElements<S> &rho, const DensMatElements<S> &rhoFDM, const Stats<S> &stats, const Symmetry<S> *Sym, const Params &P) {
algo->begin(step);
const auto & rho_here = algo->rho_type() == "rhoFDM" ? rhoFDM : rho;
// Strategy: we loop through all subspace pairs and check whether they have non-zero irreducible matrix elements.
for(const auto &[Ii, diagi]: diag)
for(const auto &[Ij, diagj]: diag) {
const Twoinvar II {Ij,Ii};
if (op1.count(II) && op2.count(II) && cf(Ij, Ii, spin) && Sym->project_subspace(Ii, P.project) && Sym->project_subspace(Ij, P.project))
algo->calc(step, diagi, diagj, op1.at(II), op2.at(II), ff(Ii, Ij), Ii, Ij, rho_here, stats); // stats.Zft needed
}
algo->end(step);
}
};
template <scalar S> using speclist = std::list<BaseSpectrum<S>>;
inline auto spec_fn(const std::string &name, const std::string &prefix, const std::string &algoname, const bool save = true) {
if (save) fmt::print("Spectrum: {} {} {}\n", name, prefix, algoname); // Don't show if it's not going to be saved
return prefix + "_" + algoname + "_dens_" + name; // no suffix (.dat vs. .bin)
}
} // namespace
#include "algo_FT.hpp"
#include "algo_DMNRG.hpp"
#include "algo_FDM.hpp"
#include "algo_CFS.hpp"
#endif
| 3,388
|
C++
|
.h
| 73
| 42.90411
| 144
| 0.671506
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,636
|
eigen.hpp
|
rokzitko_nrgljubljana/c++/eigen.hpp
|
#ifndef _eigen_hpp_
#define _eigen_hpp_
#include <vector>
#include <string>
#include <limits> // quiet_NaN
#include <stdexcept>
#include <boost/range/adaptor/map.hpp>
#include <range/v3/all.hpp>
#include "basicio.hpp"
#include "portabil.hpp"
#include "traits.hpp"
#include "invar.hpp"
#include "params.hpp"
#include "step.hpp"
#include "h5.hpp"
#include "numerics.hpp"
#include <fmt/format.h>
namespace NRG {
// Storage container for eigenvalues. Vector v contains the raw eigenvalues as computed in the Hamiltonian
// diagonalisation. If scale, shift, T_shift and/or GS_energy parameters are defined, then one has also access to various
// derived quantities. 'Relative' means in the units of the current NRG shell. 'Absolute' means in the units of
// half-bandwidth (or some other general scale). abs_T is the total energy of the state. abs_G is the total energy
// of the state referenced to the absolute many-body ground state of the whole system. 'Corrected' means the eigenvalue
// corrected for the floating-point round-off errors by fixing the small splittings.
template<scalar S, typename t_eigen = eigen_traits<S>>
class Values {
private:
std::vector<t_eigen> v;
double scale = std::numeric_limits<double>::quiet_NaN();
double shift = std::numeric_limits<double>::quiet_NaN();
double T_shift = std::numeric_limits<double>::quiet_NaN();
double abs_GS_energy = std::numeric_limits<double>::quiet_NaN();
std::vector<t_eigen> corrected;
public:
void resize(const size_t size) { v.resize(size); }
[[nodiscard]] auto raw(const size_t i) const { return v[i]; }
[[nodiscard]] auto rel(const size_t i) const { return v[i]; }
[[nodiscard]] auto abs(const size_t i) const { assert(std::isfinite(scale)); return rel(i) * scale; }
[[nodiscard]] auto rel_zero(const size_t i) const { assert(std::isfinite(shift)); return rel(i)-shift; } // shift subtracted
[[nodiscard]] auto abs_zero(const size_t i) const { return (rel(i)-shift) * scale; }
[[nodiscard]] auto abs_T(const size_t i) const { assert(std::isfinite(T_shift)); return abs_zero(i) + T_shift; } // T_shift added
[[nodiscard]] auto abs_G(const size_t i) const { assert(std::isfinite(abs_GS_energy)); return abs_T(i) - abs_GS_energy; } // abs_GS_energy subtracted
[[nodiscard]] auto corr(const size_t i) const { return corrected[i]; }
[[nodiscard]] auto size() const noexcept { return v.size(); }
[[nodiscard]] auto lowest_rel() const { return v.front(); }
[[nodiscard]] auto highest_corr() const { return corrected.back(); }
[[nodiscard]] const auto & all_rel() const noexcept { return v; }
[[nodiscard]] auto all_rel_zero() const noexcept {
assert(v.size() == 0 || std::isfinite(shift));
return ranges::views::transform(v, [this](const auto x){ return x-shift; });
}
[[nodiscard]] auto all_abs_zero() const noexcept {
assert(v.size() == 0 || (std::isfinite(shift) && std::isfinite(scale)));
return ranges::views::transform(v, [this](const auto x){ return (x-shift) * scale; });
}
[[nodiscard]] auto all_abs_T() const noexcept {
assert(v.size() == 0 || (std::isfinite(shift) && std::isfinite(scale) && std::isfinite(T_shift)));
return ranges::views::transform(v, [this](const auto x){ return (x-shift) * scale + T_shift; });
}
[[nodiscard]] auto all_abs_G() const noexcept {
assert(v.size() == 0 || (std::isfinite(shift) && std::isfinite(scale) && std::isfinite(T_shift) && std::isfinite(abs_GS_energy)));
return ranges::views::transform(v, [this](const auto x){ return (x-shift) * scale + T_shift - abs_GS_energy; });
}
[[nodiscard]] const auto & all_corr() const noexcept {
return corrected;
}
void set(std::vector<t_eigen> in) { v = std::move(in); }
void set_scale(const double scale_) { scale = scale_; }
void set_shift(const double shift_) { shift = shift_; }
void set_T_shift(const double T_shift_) { T_shift = T_shift_; }
void set_abs_GS_energy(const double abs_GS_energy_) { abs_GS_energy = abs_GS_energy_; }
void set_corr(std::vector<t_eigen> in) { corrected = std::move(in); }
[[nodiscard]] auto has_abs() const noexcept { return std::isfinite(scale); }
[[nodiscard]] auto has_zero() const noexcept { return std::isfinite(shift); }
[[nodiscard]] auto has_abs_zero() const noexcept { return has_abs() && has_zero(); }
[[nodiscard]] auto has_abs_T() const noexcept { return has_abs_zero() && std::isfinite(T_shift); }
[[nodiscard]] auto has_abs_G() const noexcept { return has_abs_T() && std::isfinite(abs_GS_energy); }
[[nodiscard]] auto has_corr() const noexcept { return corrected.size() > 0; }
void save(boost::archive::binary_oarchive &oa) const {
oa << v << scale << shift << T_shift << abs_GS_energy << corrected;
}
void load(boost::archive::binary_iarchive &ia) {
ia >> v >> scale >> shift >> T_shift >> abs_GS_energy >> corrected;
}
void h5save(H5Easy::File &fd, const std::string &name) const {
h5_dump_vector(fd, name + "/value_orig", all_rel());
if (has_zero()) h5_dump_vector(fd, name + "/value_zero", all_rel_zero() | ranges::to_vector);
if (has_abs_zero()) h5_dump_vector(fd, name + "/absenergy_zero", all_abs_zero() | ranges::to_vector);
if (has_abs_T()) h5_dump_vector(fd, name + "/absenergy", all_abs_T() | ranges::to_vector);
if (has_abs_G()) h5_dump_vector(fd, name + "/absenergyG", all_abs_G() | ranges::to_vector);
if (has_corr()) h5_dump_vector(fd, name + "/value_corr", all_corr());
}
};
template <scalar S, typename t_matel = matel_traits<S>, typename Matrix = Matrix_traits<S>>
class Vectors {
private:
Matrix m;
public:
[[nodiscard]] auto M() const noexcept { return size1(m); }
[[nodiscard]] auto dim() const noexcept { return size2(m); }
void set(Matrix m_) {
m = std::move(m_);
assert(is_unitary<S>(m));
assert(M() <= dim());
}
[[nodiscard]] const auto & get() const noexcept { return m; }
[[nodiscard]] const auto & operator()() const noexcept { return m; }
void standard_basis(const size_t size) { m = id_matrix<t_matel>(size); }
auto submatrix_const(const std::pair<size_t,size_t> &r1, const std::pair<size_t,size_t> &r2) const {
return NRG::submatrix_const(m, r1, r2);
}
void resize(const size_t new_size1, const size_t new_size2) {
m.resize(new_size1, new_size2); // non-conserving resize
}
void shrink() {
const auto d = dim();
resize(0, d); // Shrink to zero size, but keep the information about the dimensionality!!
assert(M() == 0 && dim() == d);
}
void save(boost::archive::binary_oarchive &oa) const {
NRG::save(oa, m);
}
void load(boost::archive::binary_iarchive &ia) {
m = NRG::load<S>(ia);
}
void h5save(H5Easy::File &fd, const std::string &name) const {
h5_dump_matrix(fd, name + "/matrix", m);
}
};
// Eigenvectors separated according to the invariant subspace from which they originate.
// Required for using efficient BLAS routines when performing recalculations of the matrix elements.
template <scalar S, typename Matrix = Matrix_traits<S>>
class Blocks {
private:
std::vector<Matrix> blocks;
public:
void resize(const size_t nr) {
blocks.resize(nr);
}
void set(const size_t i, Matrix m) {
assert(i < blocks.size());
blocks[i] = std::move(m);
}
[[nodiscard]] bool is_unitary() const noexcept {
return NRG::is_unitary_blocks<S>(blocks);
}
const Matrix & get(const size_t i) const {
assert(i < blocks.size());
return blocks[i];
}
const Matrix & operator()(const size_t i) const { // 1-based MMA index, called from recalc_f()
assert(1 <= i && i <= blocks.size());
return blocks[i-1];
}
void truncate(const size_t nr) {
for (auto &i : blocks) {
assert(nr <= nrvec(i));
NRG::resize(i, nr, dim(i)); // conserving matrix resize
}
}
void save(boost::archive::binary_oarchive &oa) const {
oa << blocks.size();
for (const auto &b: blocks) NRG::save(oa, b);
}
void load(boost::archive::binary_iarchive &ia) {
resize(read_one<size_t>(ia));
for (auto &b: blocks) b = NRG::load<S>(ia);
}
void clear() { ranges::fill(blocks, Matrix()); }
};
// Result of a diagonalisation: eigenvalues and eigenvectors
template <scalar S, typename RVector = RVector_traits<S>, typename Matrix = Matrix_traits<S>>
struct RawEigen {
public:
RVector val;
Matrix vec;
RawEigen() = default;
RawEigen(const size_t M, const size_t dim) {
assert(M <= dim);
val.resize(M);
vec.resize(M, dim); // non-conserving matrix resize
}
[[nodiscard]] auto getnrcomputed() const noexcept { assert(val.size() == nrvec(vec)); return val.size(); } // nr eigenvalue/eigenvector pairs
[[nodiscard]] auto getdim() const noexcept { return dim(vec); } // matrix dimension (length of eigenvectors)
void dump_eigenvalues(const size_t max_nr = std::numeric_limits<size_t>::max(), std::ostream &F = std::cout) const {
F << "eig= " << std::setprecision(std::numeric_limits<double>::max_digits10);
ranges::for_each_n(val.begin(), std::min(val.size(), max_nr), [&F](const double x) { F << x << ' '; });
F << std::endl;
}
void check_diag() const { NRG::check_diag<S>(val, vec); }
};
// High-level representation of eigenvalues/eigenvectors
template <scalar S, typename Matrix = Matrix_traits<S>, typename t_eigen = eigen_traits<S>>
class Eigen {
public:
Values<S> values; // eigenvalues
Vectors<S> vectors; // eigenvectors
Blocks<S> U; // eigenvectors in blocks
Eigen() = default;
explicit Eigen(const size_t M, const size_t dim) {
assert(M <= dim);
values.resize(M);
vectors.resize(M, dim); // non-conserving matrix-resize
}
explicit Eigen(RawEigen<S> && raw, const Step &step) {
values.set(std::move(raw.val));
vectors.set(std::move(raw.vec));
last = step.last();
}
// Called when building DiagInfo from 'data' file.
explicit Eigen(const std::vector<t_eigen> &v, const double scale, const bool last_step) {
diagonal(v);
values.set_corr(v); // required for matrix construction in the first step!
values.set_shift(0.0); // required in the first step!
values.set_scale(scale);
last = last_step;
}
[[nodiscard]] auto getnrcomputed() const noexcept { return values.size(); } // number of computed eigenpairs
[[nodiscard]] auto getdim() const noexcept { return vectors.dim(); } // valid also after the split_in_blocks_Eigen() call
private:
long nrpost = -1; // number of eigenpairs after truncation (-1: keep all)
long nrstored = -1; // number of eigenpairs currently held in store
bool last = false; // eigenspectrum from the last step of the NRG iteration
[[nodiscard]] auto getnrpost() const noexcept { return nrpost == -1 ? getnrcomputed() : nrpost; } // number of states after truncation
[[nodiscard]] auto boundary() const noexcept { return last ? 0ul : getnrkept(); } // for FDM
public:
[[nodiscard]] auto getnrall() const noexcept { return getnrcomputed(); } // all = all computed
[[nodiscard]] auto getnrkept() const noexcept { return getnrpost(); } // # of kept states
[[nodiscard]] auto getnrdiscarded() const noexcept { return getnrcomputed()-getnrpost(); } // # of discarded states
[[nodiscard]] auto getnrstored() const noexcept { return nrstored == -1 ? values.size() : nrstored; } // number of stored states
[[nodiscard]] auto all() const noexcept { return range0(getnrcomputed()); } // iterator over all states
[[nodiscard]] auto kept() const noexcept { return range0(getnrpost()); } // iterator over kept states
[[nodiscard]] auto discarded() const noexcept { return boost::irange(getnrpost(), getnrcomputed()); } // iterator over discarded states
[[nodiscard]] auto stored() const noexcept { return range0(getnrstored()); } // iterator over all stored states
// Ranges for FDM algorithm with different semantics of D/K states for the last step
[[nodiscard]] auto Drange() const noexcept { return boost::irange(boundary(), getnrall()); }
[[nodiscard]] auto Krange() const noexcept { return boost::irange(0ul, boundary()); }
[[nodiscard]] auto value_corr_kept() const noexcept { return ranges::subrange(values.all_corr().begin(), values.all_corr().begin() + getnrkept()); }
[[nodiscard]] auto value_corr_msr() const noexcept { return ranges::subrange(values.all_corr().begin(), values.all_corr().begin() + getnrstored()); } // range used in measurements (all or kept, depending on the moment of call)
// Truncate to nrpost states.
void truncate_prepare(const size_t nrpost_) {
nrpost = nrpost_;
assert(nrpost <= getnrcomputed());
}
void truncate_perform() {
nrstored = nrpost;
U.truncate(nrpost);
}
// Initialize the data structures with eigenvalues 'v'. The eigenvectors form an identity matrix. This is used to
// represent the spectral decomposition in the eigenbasis itself.
void diagonal(const std::vector<t_eigen> &v) {
values.set(v);
vectors.standard_basis(v.size());
}
void subtract_Egs(const t_eigen Egs) {
values.set_shift(Egs);
}
void subtract_GS_energy(const t_eigen GS_energy) {
values.set_abs_GS_energy(GS_energy);
}
[[nodiscard]] auto diagonal_exp(const double factor) const noexcept { // produce a diagonal matrix with exp(-factor*E) diagonal elements, used in init_rho()
const auto dim = getnrstored();
auto m = zero_matrix<S>(dim);
for (const auto i: range0(dim))
m(i, i) = exp(-values.corr(i) * factor); // corrected eigenvalues!
return m;
}
template<typename F>
[[nodiscard]] auto trace(F fnc, const double factor) const noexcept { // Tr[fnc(factor*E) exp(-factor*E)]
return ranges::accumulate(values.all_rel_zero(), 0.0, {}, [fnc, factor](const auto x) { return fnc(factor*x) * exp(-factor*x); });
}
void clear_eigenvectors() {
vectors.shrink();
U.clear();
}
void save(boost::archive::binary_oarchive &oa) const {
values.save(oa);
vectors.save(oa);
oa << nrpost << nrstored << last;
}
void load(boost::archive::binary_iarchive &ia) {
values.load(ia);
vectors.load(ia);
ia >> nrpost >> nrstored >> last;
}
void h5save(H5Easy::File &fd, const std::string &name, const bool save_vectors = true) const {
values.h5save(fd, name);
if (save_vectors) vectors.h5save(fd, name);
h5_dump_scalar(fd, name + "/nrkept", getnrkept());
}
};
// Full information after diagonalizations (eigenspectra in all subspaces)
template <scalar S, typename Matrix = Matrix_traits<S>, typename t_eigen = eigen_traits<S>>
class DiagInfo : public std::map<Invar, Eigen<S>> {
public:
explicit DiagInfo() = default;
DiagInfo(std::istream &fdata, const size_t nsubs, const Params &P) {
skip_comments(fdata);
for ([[maybe_unused]] const auto i : range1(nsubs)) {
const auto I = read_one<Invar>(fdata);
auto energies = read_std_vector<t_eigen>(fdata);
if (!(P.data_has_rescaled_energies || P.absolute))
for (auto &x : energies) x /= P.SCALE(P.Ninit); // rescale to the suitable energy scale
(*this)[I] = Eigen<S>(energies, P.absolute ? 1.0 : P.SCALE(P.Ninit), P.ZBW());
}
my_assert(this->size() == nsubs);
}
[[nodiscard]] auto subspaces() const noexcept { return *this | boost::adaptors::map_keys; }
[[nodiscard]] auto eigs() const noexcept { return *this | boost::adaptors::map_values; }
[[nodiscard]] auto eigs() noexcept { return *this | boost::adaptors::map_values; }
[[nodiscard]] auto find_groundstate() const {
const auto [Iground, eig] = *ranges::min_element(*this, {}, [](const auto &a) { return a.second.values.lowest_rel(); });
const auto Egs = eig.values.lowest_rel();
return Egs;
}
void subtract_Egs(const t_eigen Egs) {
ranges::for_each(eigs(), [Egs](auto &eig) { eig.subtract_Egs(Egs); });
}
t_eigen Egs_subtraction() {
const auto Egs = find_groundstate();
subtract_Egs(Egs);
return Egs;
}
void subtract_GS_energy(const t_eigen GS_energy) {
ranges::for_each(eigs(), [GS_energy](auto &eig) { eig.subtract_GS_energy(GS_energy); });
}
[[nodiscard]] std::vector<t_eigen> sorted_energies_rel_zero() const {
std::vector<t_eigen> energies;
for (const auto &eig: eigs())
energies.insert(energies.end(), eig.values.all_rel_zero().begin(), eig.values.all_rel_zero().end());
return energies | ranges::move | ranges::actions::sort;
}
[[nodiscard]] std::vector<t_eigen> sorted_energies_corr() const {
std::vector<t_eigen> energies;
for (const auto &eig: eigs())
energies.insert(energies.end(), eig.values.all_corr().begin(), eig.values.all_corr().end());
return energies | ranges::move | ranges::actions::sort;
}
void dump_energies(std::ostream &F) const {
for (const auto &[I, eig]: *this)
F << "Subspace: " << I << std::endl << eig.values.all_rel() << std::endl;
}
void truncate_perform() {
ranges::for_each(eigs(), &Eigen<S>::truncate_perform); // Truncate subspace to appropriate size
}
[[nodiscard]] auto size_subspace(const Invar &I) const {
const auto f = this->find(I);
return f != this->cend() ? f->second.getnrstored() : 0;
}
[[nodiscard]] auto subs(const Invar &I1, const Invar &I2) const {
return std::make_pair(this->at(I1), this->at(I2));
}
[[nodiscard]] auto dims(const Invar &I1, const Invar &I2) const { // Determines matrix sizes for operators (# stored)
return std::make_pair(size_subspace(I1), size_subspace(I2));
}
void clear_eigenvectors() {
ranges::for_each(eigs(), &Eigen<S>::clear_eigenvectors);
}
// Total number of states (symmetry taken into account)
template <typename MF>
[[nodiscard]] auto count_states(MF && mult) const noexcept {
return ranges::accumulate(*this, 0, {}, [mult](const auto &x) { const auto &[I, eig] = x; return mult(I)*eig.getnrstored(); });
}
[[nodiscard]] auto count_subspaces() const noexcept { // Count non-empty subspaces
return ranges::count_if(eigs(), [](const auto &eig) { return eig.getnrstored()>0; });
}
template<typename F, typename M>
[[nodiscard]] auto trace(F fnc, const double factor, M mult) const noexcept { // Tr[fnc(factor*E) exp(-factor*E)]
return ranges::accumulate(*this, 0.0, {}, [fnc, factor, mult](const auto &x) { const auto &[I, eig] = x; return mult(I) * eig.trace(fnc, factor); });
}
template <typename MF>
void states_report(MF && mult) const {
fmt::print("Number of invariant subspaces: {}\n", count_subspaces());
for (const auto &[I, eig]: *this)
if (eig.getnrstored())
fmt::print("({}) {} states: {}\n", I.str(), eig.getnrstored(), eig.values.all_rel());
fmt::print("Number of states (multiplicity taken into account): {}\n\n", count_states(mult));
}
void save(const size_t N, const Params &P) const {
const std::string fn = P.workdir->unitaryfn(N);
std::ofstream MATRIXF(fn, std::ios::binary | std::ios::out);
if (!MATRIXF) throw std::runtime_error(fmt::format("Can't open file {} for writing.", fn));
boost::archive::binary_oarchive oa(MATRIXF);
oa << this->size();
for(const auto &[I, eig]: *this) {
oa << I;
eig.save(oa);
if (MATRIXF.bad()) throw std::runtime_error(fmt::format("Error writing {}", fn)); // Check after each write.
}
}
void load(const size_t N, const Params &P, const bool remove_files = false) {
const std::string fn = P.workdir->unitaryfn(N);
std::ifstream MATRIXF(fn, std::ios::binary | std::ios::in);
if (!MATRIXF) throw std::runtime_error(fmt::format("Can't open file {} for reading", fn));
boost::archive::binary_iarchive ia(MATRIXF);
const auto nr = read_one<size_t>(ia); // Number of subspaces
for ([[maybe_unused]] const auto cnt : range0(nr)) {
const auto inv = read_one<Invar>(ia);
(*this)[inv].load(ia);
if (MATRIXF.bad()) throw std::runtime_error(fmt::format("Error reading {}", fn));
}
if (remove_files) NRG::remove(fn);
}
void h5save(H5Easy::File &fd, const std::string &name, const bool save_vectors = true) const {
for (const auto &[I, eig]: *this) eig.h5save(fd, name + "/" + I.name(), save_vectors);
}
explicit DiagInfo(const size_t N, const Params &P, const bool remove_files = false) {
load(N, P, remove_files);
} // called from do_diag()
};
} // namespace
#endif
| 20,666
|
C++
|
.h
| 412
| 45.961165
| 228
| 0.652866
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,637
|
numerics.hpp
|
rokzitko_nrgljubljana/c++/numerics.hpp
|
// numerics.h - Miscelaneous numerical routines
// Copyright (C) 2005-2024 Rok Zitko
// This header should be included in all other headers where vector/matrix
// objects are manipulated.
#ifndef _numerics_hpp_
#define _numerics_hpp_
#include <concepts>
#include <complex>
#include <iomanip>
#include <vector>
#include <fstream>
#include <stdexcept>
#include <range/v3/all.hpp>
#include <boost/io/ios_state.hpp>
#include <boost/math/special_functions/sign.hpp>
#include "traits.hpp"
#include <Eigen/Dense>
// Serialization support (used for storing to files and for MPI)
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/complex.hpp>
#include <fmt/format.h>
#include "portabil.hpp"
#include "misc.hpp"
#include "traits.hpp"
namespace NRG {
template <typename T>
std::complex<T> operator*(const std::integral auto &a, const std::complex<T> &b)
{
return std::complex<T>(a*b.real(), a*b.imag());
}
template <typename T>
std::complex<T> operator*(const std::complex<T> &b, const std::integral auto &a)
{
return std::complex<T>(a*b.real(), a*b.imag());
}
template <typename T>
std::complex<T> operator/(const std::integral auto &a, const std::complex<T> &b)
{
return a*(1.0/b);
}
template <typename T>
std::complex<T> operator-(const std::integral auto &a, const std::complex<T> &b)
{
return std::complex<T>(a-b.real(), -b.imag());
}
template <typename T>
std::complex<T> operator-(const std::complex<T> &b, const std::integral auto &a)
{
return std::complex<T>(b.real()-a, b.imag());
}
template <typename T>
std::complex<T> operator+(const std::integral auto &a, const std::complex<T> &b)
{
return std::complex<T>(a+b.real(), -b.imag());
}
template <typename T>
std::complex<T> operator+(const std::complex<T> &b, const std::integral auto &a)
{
return std::complex<T>(b.real()+a, b.imag());
}
template <typename T>
using complex_array_const_ref_t = const T(&)[2];
template<typename T>
complex_array_const_ref_t<T> reim(const std::complex<T>& z) {
return reinterpret_cast<const T(&)[2]>(z);
}
template<typename U, typename V>
V sum2(const std::vector<std::pair<U,V>> &v) { // sum second elements of a vector of pairs
return ranges::accumulate(v, V{}, {}, [](const auto el) { return el.second; }); // XXX
}
// XXX: conj() is constexpr in C++20
[[nodiscard]] inline std::complex<double> conj_me(const std::complex<double> &z) { return conj(z); } // conjugation
[[nodiscard]] inline double conj_me(const double x) { return x; } // no op
template<scalar S, typename Matrix = Matrix_traits<S>>
auto empty_matrix() { return Matrix(); }
// Accumulator abstraction: automatically initialized to 0, result checked for finiteness.
template <scalar T> class generic_bucket {
private:
T value{};
public:
generic_bucket() = default;
// Can be constructured from a STL vector of pairs, by summing the second elements.
template <scalar T1>
explicit generic_bucket(std::vector<std::pair<T1, T>> v) {
for (const auto &i : v) value += i.second;
}
inline constexpr T operator+=(T x) { return value += x; }
[[nodiscard]] inline constexpr operator T() const { return value; }
};
using bucket = generic_bucket<double>;
template <typename T>
inline constexpr bool is_odd(const T n) { return n & 1; } // must return bool
template <typename T>
inline constexpr bool is_even(const T n) { return !is_odd(n); } // must return bool
inline int my_fcmp(const double x, const double y, const double small_epsilon, const double rel_epsilon) {
if (x == 0.0 && y == 0.0) return 0.0; // evidently equal
if (std::abs(x) < small_epsilon && std::abs(y) < small_epsilon) return 0; // If both x and y are small, we ASSUME them to be equivalent
if (std::abs(x-y) < rel_epsilon * (std::abs(x)+std::abs(y))) return 0;
return boost::math::sign(x-y);
}
inline int my_fcmp(const double x, const double y, const double epsilon) { return my_fcmp(x, y, epsilon, epsilon); }
// Test if two numbers are equal to within numerical errors. (Use this for comparing values that are expected to be
// of order 1.)
inline auto num_equal(const double a, const double b, const double check_precision = 1.e-12) {
return my_fcmp(a, b, check_precision) == 0;
}
inline auto num_equal(const std::complex<double> &a, const std::complex<double> &b, const double check_precision = 1.e-12) {
return (my_fcmp(a.real(), b.real(), check_precision) == 0) && (my_fcmp(a.imag(), b.imag(), check_precision) == 0);
}
inline auto are_conjugate(const double a, const double b) { return num_equal(a, b); }
inline auto are_conjugate(const std::complex<double> &a, const std::complex<double> &b) { return num_equal(a.real(), b.real()) && num_equal(a.imag(), -b.imag()); }
template<matrix M> auto frobenius_norm(const M &m) { // Frobenius norm (without taking the final square root!)
double sum{};
for (auto i = 0; i < size1(m); i++)
for (auto j = 0; j < size2(m); j++) sum += pow(abs(m(i, j)),2);
return sum;
}
template<matrix M> bool is_square(const M &m) { return size1(m) == size2(m); }
// Is m upper triangular? In the lower triangle, all elements must be 0.
template<matrix M> auto is_matrix_upper(const M &m) {
if (!is_square(m)) return false;
for (auto i = 1; i < size1(m); i++)
for (auto j = 0; j < i; j++) // j < i
if (!num_equal(m(i, j), 0.0)) return false;
return true;
}
// (-1)^n
inline constexpr auto psgn(const std::integral auto n) { return n % 2 == 0 ? 1.0 : -1.0; }
// Dump a matrix with full numerical precision. The columns are aligned for easier inspection. Expect large output!
template<matrix M> inline void dump_matrix(const M &m, std::ostream &F = std::cout,
const int header_width = 7, const int column_width = 23) {
boost::io::ios_base_all_saver ofs(F);
F << std::setprecision(std::numeric_limits<double>::max_digits10);
F << fmt::format("Matrix: {}x{}\n", size1(m), size2(m));
for (auto r1 = 0; r1 < size1(m); r1++) {
F << std::setw(header_width) << r1 << ":";
for (auto r2 = 0; r2 < size2(m); r2++) F << std::setw(column_width) << m(r1, r2) << " ";
F << std::endl;
}
}
template<matrix M> inline void dump_diagonal_matrix(const M &m, const size_t max_nr, std::ostream &F = std::cout) {
for (const auto r : range0(std::min(size1(m), max_nr))) F << m(r,r) << ' ';
F << std::endl;
}
// Chop numerical noise
template <scalar T> inline constexpr T chop(const T x, const double xlimit = 1.e-8) { return std::abs(x) < xlimit ? 0.0 : x; }
// Powers, such as (-1)^n, appear in the coupling coefficients.
inline constexpr double Power(const double i, const double nn) { return std::pow(i, nn); }
inline constexpr double Abs(const double x) { return abs(x); }
// Check if the value x is real [for complex number calculations].
constexpr inline auto is_real([[maybe_unused]] const double x) { return true; }
constexpr inline auto is_real(const std::complex<double> z, const double check_real_tolerance = 1e-8) {
return abs(z.imag()) <= check_real_tolerance;
}
// Check if x is real and return the real part, i.e. x.real().
constexpr inline auto real_part_with_check(double x) { return x; }
constexpr inline auto real_part_with_check(std::complex<double> z) {
if (!is_real(z)) std::cout << "Warning: expected real number, but got " << z << std::endl;
return z.real();
}
template <matrix M> auto trace_real(const M &m) {
assert(is_square(m));
return ranges::accumulate(range0(size1(m)), 0.0, {}, [&m](const auto i){ return real_part_with_check(m(i, i)); });
}
inline auto csqrt(const std::complex<double> z) { return std::sqrt(z); } // sqrt() not constexpr for complex (C++17)
template<matrix R> // 2D matrix or matrix view
auto finite_size(const R &m) { return size1(m) && size2(m); }
// 'v' is any 1D range we can iterate over
template<typename R, matrix M>
auto trace_exp(R && v, const M &m, const double factor) { // Tr[exp(-factor*v) m]
assert(v.size() == size1(m) && v.size() == size2(m));
return ranges::accumulate(range0(v.size()), typename M::value_type{}, {}, [&v, &m, factor](const auto i){ return exp(-factor * v[i]) * m(i, i); });
}
// 'values' is any 1D range we can iterate over
template<typename R>
auto sum_of_exp(R && values, const double factor) // sum exp(-factor*x)
{
return ranges::accumulate(values, 0.0, {}, [factor](const auto &x){ return exp(-factor*x); });
}
template<matrix M>
auto trace_contract(const M &A, const M &B, const size_t range) // Tr[AB]
{
typename M::value_type sum{};
for (const auto i : range0(range))
for (const auto j : range0(range))
sum += A(i, j) * B(j, i);
return sum;
}
#include "numerics_Eigen.hpp"
template<scalar S>
[[nodiscard]] auto zero_matrix(const size_t size) {
return NRG::zero_matrix<S>(size, size);
}
template<matrix M>
[[nodiscard]] auto trim_matrix(const M &mat, const size_t new_size1, const size_t new_size2) {
const auto old_size1 = size1(mat);
const auto old_size2 = size2(mat);
if (old_size1 == 0 || old_size2 == 0) return mat; // trimming not necessary
assert(new_size1 <= old_size1 && new_size2 <= old_size2);
if (new_size1 == old_size1 && new_size2 == old_size2) return mat; // trimming not necessary
const auto sub = submatrix_const(mat, {0, new_size1}, {0, new_size2});
M new_mat = sub;
return new_mat;
}
template<matrix M, matrix N>
bool has_lesseq_rows(const M &A, const N &B) {
return size1(A) <= size1(B) && size2(A) == size2(B);
}
// M = A*B, size of A is adapted to the size of B
template<matrix M>
auto prod_fit_left(const M &A, const M &B) {
using T = typename M::value_type;
assert(size1(B) <= size2(A));
if (size1(A) == 0 || size2(B) == 0) return empty_matrix<T>();
const auto Asub = submatrix_const(A, {0, size1(A)}, {0, size1(B)});
return matrix_prod<T>(Asub, B);
}
// M = A*B, size of B is adapted to the size of A
template<matrix M>
auto prod_fit_right(const M &A, const M &B) {
using T = typename M::value_type;
assert(size1(B) >= size2(A));
if (size1(A) == 0 || size2(B) == 0) return empty_matrix<T>();
const auto Bsub = submatrix_const(B, {0, size2(A)}, {0, size2(B)});
return matrix_prod<T>(A, Bsub);
}
template<matrix M>
auto prod_fit(const M &A, const M &B) {
return size1(B) <= size2(A) ? prod_fit_left(A, B) : prod_fit_right(A, B);
}
// M = A^\dag*B, size of A is adapted to the size of B
template<matrix M>
inline auto prod_adj_fit_left(const M &A, const M &B) {
using T = typename M::value_type;
assert(size1(B) <= size1(A));
if (size2(A) == 0 || size2(B) == 0) return empty_matrix<T>();
const auto Asub = submatrix_const(A, {0, size1(B)}, {0, size2(A)});
return matrix_adj_prod<T>(Asub, B);
}
inline constexpr double WEIGHT_TOL = 1e-8; // where to switch to l'Hospital rule form
// weight=(exp(-beta Em)-exp(-beta En))/(beta En-beta Em). NOTE: arguments En, Em are order omega_N, while beta is
// order 1/omega_N, thus the combinations betaEn and betaEm are order 1. Also En>0, Em>0, since these are excitation
// energies !
inline auto chit_weight(const double En, const double Em, const double beta) {
const auto betaEn = beta * En;
const auto betaEm = beta * Em;
const auto x = betaEn - betaEm;
if (abs(x) > WEIGHT_TOL) {
// If one of {betaEm,betaEn} is small, one of exp() will have a value around 1, the other around 0, thus the
// overall result will be approximately +-1/x.
return (exp(-betaEm) - exp(-betaEn)) / x;
} else {
// Special case for Em~En. In this case, we are integrating a constant over tau\in{0,\beta}, and dividing this by
// beta we get 1. What remains is the Boltzmann weight exp(-betaEm).
return exp(-betaEm);
}
}
// Note: with dsyevr I have experienced orthogonality between eigenvectors below 1e-12. We thus use a more conservative
// epsilon for orthogonality tests of 1e-10.
// Addendum (2021): with dysevr, orthogonality can even go below 1e-10. Is it even safe to go beyond this point??
template <scalar S, typename Matrix = Matrix_traits<S>>
bool is_unitary(const Matrix &vec,
const double NORMALIZATION_EPSILON = 1e-12,
const double ORTHOGONALITY_EPSILON = 1e-10) {
const auto M = nrvec(vec);
const auto d = dim(vec);
// Check normalization
for (const auto r : range0(M)) {
S sumabs{};
for (const auto j : range0(d)) sumabs += conj_me(vec(r, j)) * vec(r, j);
if (!num_equal(abs(sumabs), 1.0, NORMALIZATION_EPSILON)) {
std::cout << "is_unitary() r=" << r << " : sumabs=" << sumabs << std::endl;
return false;
}
}
// Check orthogonality
for (const auto r1 : range0(M)) {
for (const auto r2 : boost::irange(r1 + 1, M)) {
S skpdt{};
for (const auto j : range0(d)) skpdt += conj_me(vec(r1, j)) * vec(r2, j);
if (!num_equal(abs(skpdt), 0.0, ORTHOGONALITY_EPSILON)) {
std::cout << "is_unitary() r1=" << r1 << " r2=" << r2 << " : skpdt=" << skpdt << std::endl;
return false;
}
}
}
return true;
}
template <scalar S, typename Matrix = Matrix_traits<S>>
bool is_unitary_blocks(const std::vector<Matrix> &U,
const double NORMALIZATION_EPSILON = 1e-12,
const double ORTHOGONALITY_EPSILON = 1e-10) {
assert(U.size() > 0);
const auto M = nrvec(U[0]);
// Check normalization
for (const auto r : range0(M)) {
S sumabs{};
for (const auto i : range0(U.size())) {
const auto d = dim(U[i]);
assert(M == nrvec(U[i]));
for (const auto j : range0(d)) sumabs += conj_me(U[i](r, j)) * U[i](r, j);
}
if (!num_equal(abs(sumabs), 1.0, NORMALIZATION_EPSILON)) return false;
}
// Check orthogonality
for (const auto r1 : range0(M)) {
for (const auto r2 : boost::irange(r1 + 1, M)) {
S skpdt{};
for (const auto i : range0(U.size())) {
const auto d = dim(U[i]);
for (const auto j : range0(d)) skpdt += conj_me(U[i](r1, j)) * U[i](r2, j);
}
if (!num_equal(abs(skpdt), 0.0, ORTHOGONALITY_EPSILON)) return false;
}
}
return true;
}
template <scalar S, typename RVector = RVector_traits<S>, typename Matrix = Matrix_traits<S>>
void check_diag(const RVector &val, const Matrix &vec) {
assert(val.size() == nrvec(vec));
for (const auto v: val) assert_isfinite(v);
assert(is_unitary<S>(vec));
}
} // namespace
#endif
| 14,404
|
C++
|
.h
| 327
| 41.122324
| 163
| 0.661434
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,638
|
io.hpp
|
rokzitko_nrgljubljana/c++/io.hpp
|
// io.hpp - input/output low-level routines
// Copyright (C) 2009-2024 Rok Zitko
#ifndef _io_hpp_
#define _io_hpp_
#include <string>
#include <fstream>
#include <iostream>
#include <complex>
#include "params.hpp"
#include "numerics.hpp"// reim
#include <fmt/format.h>
#include <fmt/color.h>
#include <fmt/ranges.h>
namespace NRG {
template <typename... Args>
auto color_print(bool enable_color, const fmt::text_style& ts, fmt::format_string<Args...> format_str, Args&&... args) {
return enable_color ? fmt::print(stdout, ts, format_str, std::forward<Args>(args)...)
: fmt::print(stdout, fmt::text_style{}, format_str, std::forward<Args>(args)...);
}
using namespace fmt::literals;
template <typename T>
inline std::string formatted_output(const T x, const Params &P) {
return fmt::format("{x:>{width}}", "x"_a=x, "width"_a=int(P.width_custom));
}
inline std::string formatted_output(const double x, const Params &P) {
return fmt::format("{x:>{width}.{prec}}", "x"_a=x, "prec"_a=int(P.prec_custom), "width"_a=int(P.width_custom));
}
inline std::string formatted_output(const std::complex<double> z, const Params &P) { // XXX
return fmt::format("{x:>{width}.{prec}}", "x"_a=z.real(), "prec"_a=int(P.prec_custom), "width"_a=int(P.width_custom));
}
inline void outputxy(std::ostream &F, const double x, const std::complex<double> z, const bool imagpart, const double clip_tol_imag = 1e-10) {
const auto [r, i] = reim(z);
F << x << " " << r;
if (imagpart) F << " " << (abs(i)>abs(r)*clip_tol_imag ? i : 0);
F << std::endl;
}
template <matrix M> std::ostream &operator<<(std::ostream &os, const M &m) {
for (auto r1 = 0; r1 < size1(m); r1++) {
for (auto r2 = 0; r2 < size2(m); r2++)
os << m(r1, r2) << ' ';
os << std::endl;
}
return os;
}
// Read dim1 x dim2 matrix from stream. Use function next_value to extract consecutive values. 'gen' generates the matrix.
template<typename GEN, typename FNC>
auto read_matrix_data(GEN && generate_matrix, FNC && next_value, const size_t dim1, const size_t dim2, const bool check_is_finite = true) {
auto M = generate_matrix(dim1, dim2);
for (auto i = 0; i < dim1; i++) {
for (auto j = 0; j < dim2; j++) {
const auto x = next_value();
if (check_is_finite && !std::isfinite(x)) throw std::runtime_error("Non-finite number detected.");
M(i, j) = x;
}
}
return M;
}
// Read a matrix from stream (text)
template<typename GEN>
auto read_matrix_text(GEN && generate_matrix, const std::string &filename, const bool verbose = false) {
auto F = safe_open_for_reading(filename, false);
const auto [dim1, dim2] = get_dims(F);
if (verbose) std::cout << filename << " [" << dim1 << " x " << dim2 << "]" << std::endl;
F.clear();
F.seekg (0, std::ios::beg);
return read_matrix_data(generate_matrix, [&F]() { return read_one<double>(F); }, dim1, dim2);
}
// Read a matrix from stream (binary). Format: two unit32_t for matrix size, followed by
// dim1 x dim2 double values.
template<typename GEN>
auto read_matrix_bin(GEN && generate_matrix, const std::string &filename, const bool verbose = false) {
auto F = safe_open_for_reading(filename, true);
uint32_t dim1, dim2;
F.read((char *)&dim1, sizeof(uint32_t));
F.read((char *)&dim2, sizeof(uint32_t));
if (verbose) std::cout << filename << " [" << dim1 << " x " << dim2 << "]" << std::endl;
return read_matrix_data(generate_matrix, [&F]() { double x; F.read((char *)&x, sizeof(double)); return x; }, dim1, dim2);
}
inline auto read_matrix(const std::string &filename, const bool bin = false, const bool verbose = false, const bool veryverbose = false) {
auto M = bin ? read_matrix_bin(generate_matrix<double>, filename, verbose)
: read_matrix_text(generate_matrix<double>, filename, verbose);
if (veryverbose) std::cout << M << std::endl;
return M;
}
template<matrix M>
inline void save_matrix(const std::string &filename, const M &m, const bool verbose = false,
const double chop_tol = 1e-14, const int output_prec = 18)
{
if (verbose) std::cout << "Saving result to " << filename << std::endl;
auto F = safe_open(filename);
F << std::setprecision(output_prec);
for (auto i = 0; i < size1(m); i++) {
for (auto j = 0; j < size2(m); j++) {
const auto val = m(i, j);
F << (std::abs(val) > chop_tol ? val : 0.0) << (j != size2(m) - 1 ? " " : "");
}
F << std::endl;
}
F.close();
}
} // namespace
#endif
| 4,476
|
C++
|
.h
| 102
| 40.823529
| 142
| 0.642332
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,639
|
coef.hpp
|
rokzitko_nrgljubljana/c++/coef.hpp
|
#ifndef _coef_hpp_
#define _coef_hpp_
#include <vector>
#include <fstream>
#include "traits.hpp"
#include "params.hpp"
#include "numerics.hpp" // read_vector
namespace NRG {
// Table of Wilson chain coefficients
template <scalar S, typename t_coef = coef_traits<S>>
class coef_table {
private:
using t_coef_v = std::vector<t_coef>;
t_coef_v table;
public:
using t_ndx = typename t_coef_v::size_type;
// Read values from a stream f
void read_values(std::istream &f) {
table = read_std_vector<t_coef>(f, true); // true means the number given is max index, thus len=#+1
}
[[nodiscard]] auto coef(const t_ndx n) const {
my_assert(n < table.size());
return table[n];
}
// Index of the last coefficient still included in the table
[[nodiscard]] auto max() const {
my_assert(table.size() >= 1);
return table.size()-1;
}
void set(const t_ndx n, const t_coef val) {
if (n+1 > table.size()) table.resize(n+1);
table[n] = val;
}
};
// Read matrices into a std::vector. First value to be read, 'nr', is either vector dimension or
// the value of maximum index. This is followed by the matrix dimensions 'size1' and 'size2'.
template <scalar S> auto read_matrix_table(std::istream &F, const bool nr_is_max_index = false) {
const auto nr = read_one<size_t>(F);
const auto len = nr_is_max_index ? nr+1 : nr;
assert(len >= 1);
const auto size1 = read_one<size_t>(F);
const auto size2 = read_one<size_t>(F);
assert(size1 == size2);
using t_matrix = Matrix_traits<S>;
std::vector<t_matrix> vec(len);
for (auto j = 0; j < len; j++)
vec[j] = read_matrix<S>(F, size1, size2);
if (F.fail()) throw std::runtime_error("read_std_vector() error. Input file is corrupted.");
return vec;
}
#ifdef CHAIN_COEF
// PROPOSED NEW DATA STRUCTURE
// Table of Wilson chain coefficients in matrix form, one element per shell.
// The meaning of the internal matrix dimensions depends on the symmetry type,
// it can be channel/orbital, spin, Nambu particle/hole degree of freedom, etc.,
// or a combination of several of those. The implementation of each symmetry type
// should provide an appropriate view adapter for the Wilson chain matrices.
template <scalar S, typename t_coef = coef_traits<S>, typename t_matrix = Matrix_traits<S>>
class chain_coef {
private:
using t_coef_matrix_v = std::vector<t_matrix>;
t_coef_matrix_v matrix_table;
public:
using t_ndx = typename t_coef_matrix_v::size_type;
// Read values from a stream f.
void read(std::istream &f) {
matrix_table = read_matrix_table<t_coef>(f, true); // true means the number given is max index, thus len=#+1
}
[[nodiscard]] auto coef(const t_ndx n) const {
my_assert(n < matrix_table.size());
return matrix_table[n];
}
[[nodiscard]] auto size() const {
my_assert(matrix_table.size() > 0);
return matrix_table[0].size1();
}
};
#endif
// One table of discretization coefficients for each channel
template <scalar S, typename t_coef = coef_traits<S>>
class set_of_coef_tables {
private:
using t_coef_vv = std::vector<coef_table<S>>;
t_coef_vv tabs;
public:
using t_ndx = typename coef_table<S>::t_ndx;
using t_ch = typename t_coef_vv::size_type;
[[nodiscard]] auto nr_tabs() const { return tabs.size(); }
void read(std::istream &fdata, const t_ch coefchannels) {
tabs.resize(coefchannels);
for (auto &i : tabs) i.read_values(fdata);
}
[[nodiscard]] auto operator()(const t_ndx N, const t_ch alpha) const {
my_assert(alpha < tabs.size());
return tabs[alpha].coef(N);
}
[[nodiscard]] auto max(const t_ch alpha) const {
my_assert(alpha < tabs.size());
return tabs[alpha].max();
}
void set(const t_ndx N, const t_ch alpha, const t_coef val) { // used in tridiag.hpp
my_assert(alpha < tabs.size());
tabs[alpha].set(N, val);
}
};
template <scalar S>
class Coef {
private:
const Params &P;
public:
explicit Coef(const Params &P) : P(P) {}
// NEW INTERFACE
#ifdef CHAIN_COEF
chain_coef<S> eps; // f^dag_N f_N+1 terms
chain_coef<S> t; // f^dag_N f_N terms
#endif
// OLD INTERFACE
using t_ndx = typename set_of_coef_tables<S>::t_ndx;
using t_ch = typename set_of_coef_tables<S>::t_ch;
set_of_coef_tables<S> xi; // f^dag_N f_N+1 terms
set_of_coef_tables<S> zeta; // f^dag_N f_N terms
// channel-mixing chains
set_of_coef_tables<S> xiR;
set_of_coef_tables<S> zetaR;
// superconducting chains
set_of_coef_tables<S> delta; // f^dag_up,N f^dag_down,N terms
set_of_coef_tables<S> kappa; // f^dag_N f^dag_down,N+1 terms
// star-representation coefficients
set_of_coef_tables<S> ep, em; // e_n coefficients
set_of_coef_tables<S> u0p, u0m; // u_{0,m} coefficients
// Support for spin-polarized conduction bands. See also P.polarized. Hack: the total number of channels is
// doubled, the index runs from 0...2*P.channels-1. Numbers 0...P.channels-1 correspond to spin up, while
// P.channels...2*P.channels-1 correspond to spin down. Compare P.channels and P.coefchannels (which reflects the
// same convention in initial.m, i.e. CHANNELS vs. COEFCHANNELS).
[[nodiscard]] auto xiUP (const t_ndx N, const t_ch ch) const { return xi (N, ch); }
[[nodiscard]] auto xiDOWN (const t_ndx N, const t_ch ch) const { return xi (N, ch + P.channels); }
[[nodiscard]] auto zetaUP (const t_ndx N, const t_ch ch) const { return zeta(N, ch); }
[[nodiscard]] auto zetaDOWN(const t_ndx N, const t_ch ch) const { return zeta(N, ch + P.channels); }
// Support for conduction bands with full 2x2 matrix structure, a generalization of P.polarized. The total number
// of "channels" is here multiplied by 4, i.e., the index runs from 0 to 4*P.channels-1. Numbers
// 2*P.channels...3*P.channels-1 correspond to UP/DO, 3*P.channels...4*P.channels-1 correspond to DO/UP.
[[nodiscard]] auto xiUPDO (const t_ndx N, const t_ch ch) const { return xi (N, ch + 2 * P.channels); }
[[nodiscard]] auto xiDOUP (const t_ndx N, const t_ch ch) const { return xi (N, ch + 3 * P.channels); }
[[nodiscard]] auto zetaUPDO(const t_ndx N, const t_ch ch) const { return zeta(N, ch + 2 * P.channels); }
[[nodiscard]] auto zetaDOUP(const t_ndx N, const t_ch ch) const { return zeta(N, ch + 3 * P.channels); }
};
} // namespace
#endif
| 6,269
|
C++
|
.h
| 148
| 39.587838
| 115
| 0.684806
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,641
|
diag_openmp.hpp
|
rokzitko_nrgljubljana/c++/diag_openmp.hpp
|
#ifndef _diag_openmp_hpp_
#define _diag_openmp_hpp_
#include "traits.hpp"
#include "step.hpp"
#include "operators.hpp"
#include "coef.hpp"
#include "eigen.hpp"
#include "output.hpp"
#include "invar.hpp"
#include "params.hpp"
#include "symmetry.hpp"
#include "diagengine.hpp"
namespace NRG {
template<scalar S>
class DiagOpenMP : public DiagEngine<S> {
public:
DiagInfo<S> diagonalisations(const Step &step, const Opch<S> &opch, const Coef<S> &coef, const DiagInfo<S> &diagprev, const Output<S> &output,
const std::vector<Invar> &tasks, const DiagParams &DP, const Symmetry<S> *Sym, const Params &P) {
DiagInfo<S> diagnew;
const auto nr = tasks.size();
size_t itask = 0;
// cppcheck-suppress unreadVariable symbolName=nth
const int nth = P.diagth; // NOLINT
#pragma omp parallel for schedule(dynamic) num_threads(nth)
for (itask = 0; itask < nr; itask++) {
const Invar I = tasks[itask];
auto h = hamiltonian(step, I, opch, coef, diagprev, output, Sym, P); // non-const, consumed by diagonalise()
const int thid = omp_get_thread_num();
#pragma omp critical
{ nrglog('(', "[OpenMP] Diagonalizing " << I << " dim=" << dim(h) << " (task " << itask + 1 << "/" << nr << ", thread " << thid << ")"); }
auto e = diagonalise(h, DP, -1); // -1 = not using MPI
#pragma omp critical
{ diagnew[I] = Eigen(std::move(e), step); }
}
return diagnew;
}
};
}
#endif
| 1,472
|
C++
|
.h
| 39
| 33.538462
| 145
| 0.639356
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,642
|
mk_sym.hpp
|
rokzitko_nrgljubljana/c++/mk_sym.hpp
|
#ifndef _mk_sym_hpp_
#define _mk_sym_hpp_
#include <memory>
#include <string>
#include <stdexcept>
#include "params.hpp"
#include "symmetry.hpp"
#include "outfield.hpp"
#include "sym-QS.hpp"
#include "sym-QSZ.hpp"
#ifdef NRG_SYM_MORE
#include "sym-ISO.hpp"
#include "sym-ISOSZ.hpp"
#include "sym-SPSU2.hpp"
#include "sym-SPU1.hpp"
#endif
#ifdef NRG_SYM_ALL
#include "sym-DBLQSZ.hpp"
#include "sym-DBLSU2.hpp"
#include "sym-DBLISOSZ.hpp"
#include "sym-ISOLR.hpp"
#include "sym-ISOSZLR.hpp"
#include "sym-NONE.hpp"
#include "sym-P.hpp"
#include "sym-PP.hpp"
#include "sym-SL.hpp"
#include "sym-SL3.hpp"
#include "sym-SPSU2LR.hpp"
#include "sym-SPSU2T.hpp"
#include "sym-SPU1LR.hpp"
#include "sym-SU2.hpp"
#include "sym-QSLR.hpp"
#include "sym-QST.hpp"
#include "sym-QSTZ.hpp"
#include "sym-QSZTZ.hpp"
#include "sym-QSZLR.hpp"
#include "sym-QJ.hpp"
#include "sym-U1.hpp"
#include "sym-SPSU2C3.hpp"
#include "sym-QSC3.hpp"
#endif
namespace NRG {
template<scalar S>
auto get(const std::string &sym_string, const Params &P)
{
if (sym_string == "QS") return mk_QS<S>(P);
if (sym_string == "QSZ") return mk_QSZ<S>(P);
#ifdef NRG_SYM_MORE
if (sym_string == "ISO") return mk_ISO<S>(P);
if (sym_string == "ISO2") return mk_ISO2<S>(P);
if (sym_string == "ISOSZ") return mk_ISOSZ<S>(P);
if (sym_string == "SPSU2") return mk_SPSU2<S>(P);
if (sym_string == "SPU1") return mk_SPU1<S>(P);
#endif
#ifdef NRG_SYM_ALL
if (sym_string == "DBLQSZ") return mk_DBLQSZ<S>(P);
if (sym_string == "DBLSU2") return mk_DBLSU2<S>(P);
if (sym_string == "DBLISOSZ") return mk_DBLISOSZ<S>(P);
if (sym_string == "ISOLR") return mk_ISOLR<S>(P);
if (sym_string == "ISO2LR") return mk_ISO2LR<S>(P);
if (sym_string == "ISOSZLR") return mk_ISOSZLR<S>(P);
if (sym_string == "NONE") return mk_NONE<S>(P);
if (sym_string == "P") return mk_P<S>(P);
if (sym_string == "PP") return mk_PP<S>(P);
if (sym_string == "SL") return mk_SL<S>(P);
if (sym_string == "SL3") return mk_SL3<S>(P);
if (sym_string == "SPSU2LR") return mk_SPSU2LR<S>(P);
if (sym_string == "SPSU2T") return mk_SPSU2T<S>(P);
if (sym_string == "SPU1LR") return mk_SPU1LR<S>(P);
if (sym_string == "SU2") return mk_SU2<S>(P);
if (sym_string == "QSLR") return mk_QSLR<S>(P);
if (sym_string == "QST") return mk_QST<S>(P);
if (sym_string == "QSTZ") return mk_QSTZ<S>(P);
if (sym_string == "QSZTZ") return mk_QSZTZ<S>(P);
if (sym_string == "QSZLR") return mk_QSZLR<S>(P);
if (sym_string == "QJ") return mk_QJ<S>(P);
if (sym_string == "U1") return mk_U1<S>(P);
if constexpr (std::is_same_v<S, std::complex<double>>) {
if (sym_string == "SPSU2C3") return mk_SPSU2C3<S>(P);
if (sym_string == "QSC3") return mk_QSC3<S>(P);
}
#endif
throw std::runtime_error("Unknown symmetry " + sym_string);
}
// Called immediately after parsing the information about the number of channels from the data file. This ensures
// that Invar can be parsed correctly.
template <scalar S>
std::shared_ptr<Symmetry<S>> set_symmetry(Params &P, const std::string &sym_string, const size_t channels) {
P.symtype = sym_string;
P.set_channels_and_combs(channels);
std::cout << "\nSYMMETRY TYPE: " << sym_string << std::endl;
auto Sym = get<S>(sym_string, P);
Sym->load();
Sym->erase_first();
return Sym;
}
} // namespace
#endif
| 3,305
|
C++
|
.h
| 98
| 31.734694
| 113
| 0.667188
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,643
|
subspaces.hpp
|
rokzitko_nrgljubljana/c++/subspaces.hpp
|
#ifndef _subspaces_hpp_
#define _subspaces_hpp_
#include <memory>
#include <vector>
#include <range/v3/all.hpp>
#include "eigen.hpp"
#include "invar.hpp"
#include "h5.hpp"
namespace NRG {
template<scalar S> class Symmetry;
// Dimensions of the invariant subspaces |r,1>, |r,2>, |r,3>, etc.
class SubspaceDimensions {
private:
std::vector<size_t> dims;
std::vector<Invar> ancestors;
public:
SubspaceDimensions() = default;
template<scalar S>
SubspaceDimensions(const Invar &I, const InvarVec &ancestors, const DiagInfo<S> &diagprev,
const Symmetry<S> *Sym, const bool ignore_inequality = false);
[[nodiscard]] auto combs() const { return dims.size(); } // number of subspaces
[[nodiscard]] auto rmax(const size_t i) const { // subspace dimension
my_assert(i < combs());
return dims[i];
}
[[nodiscard]] auto operator[](const size_t i) const { return rmax(i); }
[[nodiscard]] auto exists(const size_t i) const {
my_assert(i < combs());
return dims[i] > 0;
}
[[nodiscard]] auto offset(const size_t i) const { // offset in the Hamiltonian matrix
my_assert(i < combs());
return ranges::accumulate(std::begin(dims), std::begin(dims) + i, size_t{0});
}
[[nodiscard]] auto chunk(const size_t i1) const {
return std::make_pair(offset(i1-1), rmax(i1-1));
}
[[nodiscard]] auto view(const size_t i) const { // index range in the Hamiltonian matrix // XXX: rename to range
return boost::irange(offset(i), offset(i)+rmax(i));
}
[[nodiscard]] auto view_mma(const size_t i) const {
return view(i-1); // Mathematica uses 1-based indexing
}
[[nodiscard]] auto part(const size_t i) const {
return std::make_pair(offset(i), offset(i)+rmax(i));
}
[[nodiscard]] auto part_mma(const size_t i1) const {
return part(i1-1); // Mathematica uses 1-based indexing
}
[[nodiscard]] auto total() const { return ranges::accumulate(dims, 0); } // total number of states
// *** Mathematica interfacing: i1,j1 are 1-based
[[nodiscard]] bool offdiag_contributes(const size_t i1, const size_t j1) const { // i,j are 1-based (Mathematica interface)
my_assert(1 <= i1 && i1 <= combs() && 1 <= j1 && j1 <= combs());
my_assert(i1 != j1);
return exists(i1-1) && exists(j1-1); // shift by 1
}
[[nodiscard]] Invar ancestor(const size_t i) const { return ancestors[i]; }
void dump(std::ostream &F = std::cout) const {
my_assert(dims.size() == ancestors.size());
for (int i = 0; i < dims.size(); i++)
F << "[" << ancestors[i] << "] total=" << dims[i] << std::endl;
}
void h5save(H5Easy::File &fd, const std::string &name) const {
std::vector<std::string> ancestor_names;
for (const auto i : range0(combs()))
if (dims[i]) ancestor_names.push_back(ancestors[i].name()); // only true ancestors with dim>0
H5Easy::dump(fd, name + "/ancestors", ancestor_names);
}
private:
friend std::ostream &operator<<(std::ostream &os, const SubspaceDimensions &rmax) {
for (const auto &x : rmax.dims) os << x << ' ';
return os;
}
template <class Archive> void serialize(Archive &ar, const unsigned int version) { ar &dims; }
friend class boost::serialization::access;
};
class SubspaceStructure : public std::map<Invar, SubspaceDimensions> {
public:
SubspaceStructure() = default;
template<scalar S> SubspaceStructure(const DiagInfo<S> &, const Symmetry<S> *);
void dump(std::ostream &F = std::cout) const {
for(const auto &[I, rm]: *this)
F << "rmaxvals(" << I << ")=" << rm << " total=" << rm.total() << std::endl;
}
[[nodiscard]] auto at_or_null(const Invar &I) const {
const auto i = this->find(I);
return i == this->cend() ? SubspaceDimensions() : i->second;
}
void h5save(H5Easy::File &fd, const std::string &name) const {
for (const auto &[I, rm]: *this)
rm.h5save(fd, name + "/" + I.name());
}
};
// List of invariant subspaces in which diagonalisations need to be performed
class TaskList {
private:
std::vector<std::pair<size_t, Invar>> tasks_with_sizes;
std::vector<Invar> tasks;
public:
void stats(std::ostream &F) {
auto nr = tasks_with_sizes.size();
auto min_size = tasks_with_sizes.back().first;
auto max_size = tasks_with_sizes.front().first;
F << "Stats: nr=" << nr << " min=" << min_size << " max=" << max_size << std::endl;
}
explicit TaskList(const SubspaceStructure &structure, std::ostream &F = std::cout) {
for (const auto &[I, rm] : structure)
if (rm.total())
tasks_with_sizes.emplace_back(rm.total(), I);
ranges::sort(tasks_with_sizes, std::greater<>()); // sort in the *decreasing* order!
stats(F);
tasks = tasks_with_sizes | ranges::views::transform( [](const auto &p) { return p.second; } ) | ranges::to<std::vector>();
}
[[nodiscard]] std::vector<Invar> get() const { return tasks; }
};
} // namespace
#endif
| 4,983
|
C++
|
.h
| 117
| 38.136752
| 127
| 0.637768
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,644
|
matsubara.hpp
|
rokzitko_nrgljubljana/c++/matsubara.hpp
|
#ifndef _matsubara_hpp_
#define _matsubara_hpp_
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include "traits.hpp"
namespace NRG {
enum class gf_type { bosonic, fermionic }; // req'd in matsubara.h
// Sign factor in GFs for bosonic/fermionic operators
inline constexpr auto S_BOSONIC = +1;
inline constexpr auto S_FERMIONIC = -1;
inline int gf_sign(const gf_type gt) { return gt == gf_type::bosonic ? S_BOSONIC : S_FERMIONIC; }
// Note: range limited to short numbers.
[[nodiscard]] inline auto ww(const short n, const gf_type mt, const double T)
{
switch (mt) {
case gf_type::bosonic: return T * M_PI * (2 * n);
case gf_type::fermionic: return T * M_PI * (2 * n + 1);
default: my_assert_not_reached();
}
}
[[nodiscard]] inline auto wb(const short n, const double T) { return T * M_PI * (2 * n); }
[[nodiscard]] inline auto wf(const short n, const double T) { return T * M_PI * (2 * n + 1); }
template<scalar S, typename t_weight = weight_traits<S>>
class Matsubara {
private:
using t_temp = typename traits<S>::t_temp;
using matsgf = std::vector<std::pair<t_temp, t_weight>>;
matsgf v;
gf_type mt;
t_temp T;
public:
Matsubara() = delete;
Matsubara(const size_t mats, const gf_type mt, const t_temp T) : mt(mt), T(T) {
my_assert(mt == gf_type::bosonic || mt == gf_type::fermionic);
for (const auto n: range0(mats)) v.emplace_back(ww(n, mt, T), 0);
}
void add(const size_t n, const t_weight &w) { v[n].second += w; }
void merge(const Matsubara &m2) {
my_assert(v.size() == m2.v.size());
for (const auto n: range0(v.size())) {
my_assert(v[n].first == m2.v[n].first);
v[n].second += m2.v[n].second;
}
}
template <typename T> void save(T && F, const int prec) const {
F << std::setprecision(prec); // prec_xy
for (const auto &[e, w] : v) outputxy(F, e, w, true);
}
};
} // namespace NRG
#endif // _matsubara_hpp_
| 1,953
|
C++
|
.h
| 53
| 33.698113
| 97
| 0.642706
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,645
|
mp.hpp
|
rokzitko_nrgljubljana/c++/mp.hpp
|
// Copyright (C) 2020 Rok Zitko
#ifndef _mp_hpp_
#define _mp_hpp_
#include <gmp.h>
#include <vector>
namespace NRG {
// Wrapper class for arbitrary precision numbers
class my_mpf {
private:
mpf_t val{};
public:
my_mpf() { mpf_init(val); }
// Copy constructor is mandatory!
my_mpf(const my_mpf &x) {
mpf_init(val);
mpf_set(val, x.val);
}
my_mpf(my_mpf && x) = delete;
my_mpf & operator=(const my_mpf & x) = delete;
my_mpf & operator=(my_mpf && x) = delete;
~my_mpf() { mpf_clear(val); }
inline operator mpf_t &() { return val; }
};
using vmpf = std::vector<my_mpf>;
} // namespace NRG
#endif
| 631
|
C++
|
.h
| 26
| 21.730769
| 48
| 0.644891
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,646
|
algo_CFS.hpp
|
rokzitko_nrgljubljana/c++/algo_CFS.hpp
|
#ifndef _algo_CFS_hpp_
#define _algo_CFS_hpp_
#include "traits.hpp"
#include "algo.hpp"
#include "spectrum.hpp"
namespace NRG {
// Cf. Peters, Pruschke, Anders, Phys. Rev. B 74, 245113 (2006).
// Based on the implementation by Markus Greger.
template<scalar S, typename Matrix = Matrix_traits<S>, typename t_coef = coef_traits<S>, typename t_eigen = eigen_traits<S>>
class Algo_CFSls : virtual public Algo<S> {
private:
inline static const std::string algoname = "CFSls";
SpectrumRealFreq<S> spec;
const int sign; // 1 for bosons, -1 for fermions
const bool save; // if true, save spectral function to a file in destructor
protected:
using CB = ChainBinning<S>;
std::unique_ptr<CB> cb;
public:
using Algo<S>::P;
Algo_CFSls(const std::string &name, const std::string &prefix, const gf_type gt, const Params &P, const bool save = true)
: Algo<S>(P), spec(name, algoname, spec_fn(name, prefix, algoname, save), P), sign(gf_sign(gt)), save(save) {}
void begin(const Step &) override { cb = std::make_unique<CB>(P); }
void calc(const Step &step, const Eigen<S> &diagIp, const Eigen<S> &diagI1, const Matrix &op1, const Matrix &op2,
t_coef factor, [[maybe_unused]] const Invar &Ip, [[maybe_unused]] const Invar &I1, const DensMatElements<S> &rho, const Stats<S> &stats) override
{
// Convention: k-loops over retained states, l-loop over discarded states.
if (step.last()) {
// i-term, Eq. (11).
const auto term1 = [&diagI1, &diagIp, Z=stats.Zft, &op1, &op2, T = P.T.value(), this](const auto r1, const auto rp) {
const auto E1 = diagI1.values.abs_zero(r1);
const auto Ep = diagIp.values.abs_zero(rp);
const auto weight = conj_me(op1(r1, rp)) * op2(r1, rp) * exp(-E1/T) * (-sign)/Z;
return std::make_pair(E1-Ep, weight);
};
for (const auto r1: diagI1.kept())
for (const auto rp: diagIp.kept())
cb->add(term1(r1, rp), factor);
} else {
// iii-term, Eq. (16), positive frequency excitations
const auto op2_rho = prod_fit_left(op2, rho.at(Ip));
const auto term3 = [&diagI1, &diagIp, &op1, &op2_rho, this](const auto rl, const auto rk) {
const auto El = diagI1.values.abs_zero(rl);
const auto Ek = diagIp.values.abs_zero(rk);
const auto weight = conj_me(op1(rl, rk)) * op2_rho(rl, rk) * (-sign);
return std::make_pair(El-Ek, weight);
};
for (const auto rl: diagI1.discarded())
for (const auto rk: diagIp.kept())
cb->add(term3(rl, rk), factor);
}
}
void end([[maybe_unused]] const Step &step) override {
spec.mergeCFS(*cb.get());
cb.reset();
}
~Algo_CFSls() { if (save) spec.save(); }
std::string rho_type() override { return "rho"; }
};
template<scalar S, typename Matrix = Matrix_traits<S>, typename t_coef = coef_traits<S>, typename t_eigen = eigen_traits<S>>
class Algo_CFSgt : virtual public Algo<S> {
private:
inline static const std::string algoname = "CFSgt";
SpectrumRealFreq<S> spec;
const int sign; // 1 for bosons, -1 for fermions
const bool save;
protected:
using CB = ChainBinning<S>;
std::unique_ptr<CB> cb;
public:
using Algo<S>::P;
Algo_CFSgt(const std::string &name, const std::string &prefix, const gf_type gt, const Params &P, const bool save = true)
: Algo<S>(P), spec(name, algoname, spec_fn(name, prefix, algoname, save), P), sign(gf_sign(gt)), save(save) {}
void begin(const Step &) override { cb = std::make_unique<CB>(P); }
void calc(const Step &step, const Eigen<S> &diagIp, const Eigen<S> &diagI1, const Matrix &op1, const Matrix &op2,
t_coef factor, [[maybe_unused]] const Invar &Ip, [[maybe_unused]] const Invar &I1, const DensMatElements<S> &rho, const Stats<S> &stats) override
{
// Convention: k-loops over retained states, l-loop over discarded states.
if (step.last()) {
// i-term, Eq. (11).
const auto term1 = [&diagI1, &diagIp, Z=stats.Zft, &op1, &op2, T = P.T.value()](const auto r1, const auto rp) {
const auto E1 = diagI1.values.abs_zero(r1);
const auto Ep = diagIp.values.abs_zero(rp);
const auto weight = conj_me(op1(r1, rp)) * op2(r1, rp) * exp(-Ep/T)/Z;
return std::make_pair(E1-Ep, weight);
};
for (const auto r1: diagI1.kept())
for (const auto rp: diagIp.kept())
cb->add(term1(r1, rp), factor);
} else {
// ii-term, Eq. (15), negative frequency excitations
const auto op1_rho = prod_adj_fit_left(op1, rho.at(I1));
const auto term2 = [&diagI1, &diagIp, &op1_rho, &op2](const auto rk, const auto rl) {
const auto Ek = diagI1.values.abs_zero(rk);
const auto El = diagIp.values.abs_zero(rl);
const auto weight = op1_rho(rl, rk) * op2(rk, rl);
return std::make_pair(Ek-El, weight);
};
for (const auto rk: diagI1.kept())
for (const auto rl: diagIp.discarded())
cb->add(term2(rk, rl), factor);
}
}
void end([[maybe_unused]] const Step &step) override {
spec.mergeCFS(*cb.get());
cb.reset();
}
~Algo_CFSgt() { if (save) spec.save(); }
std::string rho_type() override { return "rho"; }
};
template<scalar S, typename Matrix = Matrix_traits<S>, typename t_coef = coef_traits<S>, typename t_eigen = eigen_traits<S>>
class Algo_CFS : public Algo_CFSls<S>, public Algo_CFSgt<S> {
private:
inline static const std::string algoname2 = "CFS";
SpectrumRealFreq<S> spec_tot;
public:
using Algo<S>::P;
Algo_CFS(const std::string &name, const std::string &prefix, const gf_type gt, const Params &P) :
Algo<S>(P), Algo_CFSls<S>(name, prefix, gt, P, false), Algo_CFSgt<S>(name, prefix, gt, P, false), spec_tot(name, algoname2, spec_fn(name, prefix, algoname2), P) {}
void begin(const Step &step) override {
Algo_CFSgt<S>::begin(step);
Algo_CFSls<S>::begin(step);
}
void calc(const Step &step, const Eigen<S> &diagIp, const Eigen<S> &diagI1, const Matrix &op1, const Matrix &op2,
t_coef factor, const Invar &Ip, const Invar &I1, const DensMatElements<S> &rho, const Stats<S> &stats) override
{
Algo_CFSgt<S>::calc(step, diagIp, diagI1, op1, op2, factor, Ip, I1, rho, stats);
Algo_CFSls<S>::calc(step, diagIp, diagI1, op1, op2, factor, Ip, I1, rho, stats);
}
void end([[maybe_unused]] const Step &step) override {
spec_tot.mergeCFS(*Algo_CFSgt<S>::cb.get());
spec_tot.mergeCFS(*Algo_CFSls<S>::cb.get());
Algo_CFSgt<S>::cb.reset();
Algo_CFSls<S>::cb.reset();
}
~Algo_CFS() { spec_tot.save(); }
std::string rho_type() override { return "rho"; }
};
} // namespace
#endif
| 6,770
|
C++
|
.h
| 140
| 42.657143
| 168
| 0.628964
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,647
|
nrg-lib.hpp
|
rokzitko_nrgljubljana/c++/nrg-lib.hpp
|
#ifndef _nrg_lib_hpp_
#define _nrg_lib_hpp_
// This header is included for both executable and library.
#define NRG_COMMON
#include <memory>
#include <string>
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include "workdir.hpp"
namespace NRG {
void print_about_message();
void run_nrg_master(const std::string &workdir);
void run_nrg_master(boost::mpi::environment &mpienv, boost::mpi::communicator &mpiw, std::unique_ptr<Workdir> workdir);
void run_nrg_slave(boost::mpi::environment &mpienv, boost::mpi::communicator &mpiw);
} // namespace
#endif
| 585
|
C++
|
.h
| 16
| 35.0625
| 119
| 0.771836
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,648
|
diag.hpp
|
rokzitko_nrgljubljana/c++/diag.hpp
|
// diag.h - Diagonalisation code
// Copyright (C) 2009-2020 Rok Zitko
#ifndef _diag_hpp_
#define _diag_hpp_
#include <type_traits> // is_same_v
#include <complex>
#include <vector>
#include <memory>
#include <iostream>
#include <iomanip> // std::setprecision
#include <stdexcept>
#include "traits.hpp"
#include "params.hpp"
#include "eigen.hpp"
#include "time_mem.hpp"
#include "debug.hpp" // nrglogdp
#include "numerics.hpp" // is_matrix_upper
#include <fmt/format.h>
#define LAPACK_COMPLEX_STRUCTURE
#include "lapack.h"
namespace NRG {
// Handle complex-type conversions (used in copy_vec)
[[nodiscard]] inline auto to_matel(const double x) { return x; }
[[nodiscard]] inline auto to_matel(const lapack_complex_double &z) { return std::complex<double>(z.real, z.imag); }
template<vector SV, vector DV> requires std::is_convertible_v<typename SV::value_type, typename DV::value_type>
void copy_val(const SV &source, DV &dest, const size_t M) {
using S = typename SV::value_type;
my_assert(source.size() >= M);
if (std::adjacent_find(source.begin(), source.begin() + M, std::greater<S>()) != source.begin() + M)
std::cout << "WARNING: Values are not in ascending order. Bug in LAPACK dsyev* routines." << std::endl;
dest.resize(M);
std::copy_n(source.begin(), M, dest.begin());
}
template<typename U, matrix MM> // U may be _lapack_complex_double
void copy_vec(U* eigenvectors, MM & diagvectors, const size_t dim, const size_t M)
{
diagvectors.resize(M, dim);
for (const auto r : range0(M))
for (const auto j : range0(dim)) diagvectors(r, j) = to_matel(eigenvectors[dim * r + j]);
// this works correctly for both row-order and column-order storage types (diagvectors)
}
template<scalar S, vector V, typename U>
auto copy_results(const V &eigenvalues, U* eigenvectors, const char jobz, const size_t dim, const size_t M)
{
RawEigen<S> d(M, dim);
copy_val(eigenvalues, d.val, M);
if (jobz == 'V') copy_vec(eigenvectors, d.vec, dim, M);
my_assert(d.val.size() == nrvec(d.vec));
return d;
}
// Perform diagonalisation: wrappers for LAPACK. jobz: 'N' for values only, 'V' for values and vectors
template<real_matrix RM>
auto diagonalise_dsyev(RM &m, const char jobz = 'V') {
if (!is_row_ordered(m)) m = NRG::trans(m);
const auto dim = int(size1(m));
auto ham = data(m);
std::vector<double> eigenvalues(dim); // eigenvalues on exit
char UPLO = 'L'; // lower triangle of a is stored
int NN = dim; // the order of the matrix
int LDA = dim; // the leading dimension of the array a
int INFO = 0; // 0 on successful exit
int LWORK0 = -1; // length of the WORK array
double WORK0 = 0; // on exit: optimal WORK size
// Step 1: determine optimal LWORK
LAPACK_dsyev(&jobz, &UPLO, &NN, ham, &LDA, eigenvalues.data(), &WORK0, &LWORK0, &INFO);
my_assert(INFO == 0);
int LWORK = int(WORK0);
std::vector<double> WORK(LWORK);
// Step 2: perform the diagonalisation
LAPACK_dsyev(&jobz, &UPLO, &NN, ham, &LDA, eigenvalues.data(), WORK.data(), &LWORK, &INFO);
if (INFO != 0) throw std::runtime_error(fmt::format("dsyev failed. INFO={}", INFO));
return copy_results<double>(eigenvalues, ham, jobz, dim, dim);
}
template<real_matrix RM>
auto diagonalise_dsyevd(RM &m, const char jobz = 'V')
{
if (!is_row_ordered(m)) m = NRG::trans(m);
const auto dim = int(size1(m));
auto ham = data(m);
std::vector<double> eigenvalues(dim);
char UPLO = 'L';
int NN = dim;
int LDA = dim;
int INFO = 0;
int LWORK = -1;
int LIWORK = -1;
double WORK0 = 0; // on exit: optimal WORK size
int IWORK0 = 0; // on exit: optimal IWORK size
LAPACK_dsyevd(&jobz, &UPLO, &NN, ham, &LDA, eigenvalues.data(), &WORK0, &LWORK, &IWORK0, &LIWORK, &INFO);
my_assert(INFO == 0);
LWORK = int(WORK0);
LIWORK = IWORK0;
std::vector<double> WORK(LWORK);
std::vector<int> IWORK(LIWORK);
LAPACK_dsyevd(&jobz, &UPLO, &NN, ham, &LDA, eigenvalues.data(), WORK.data(), &LWORK, IWORK.data(), &LIWORK, &INFO);
if (INFO != 0) {
// dsyevd sometimes fails to converge (INFO>0). In such cases we do not trigger
// an error but return 0, to permit error recovery.
if (INFO > 0)
return RawEigen<double>();
else
throw std::runtime_error(fmt::format("dsyev failed. INFO={}", INFO));
}
return copy_results<double>(eigenvalues, ham, jobz, dim, dim);
}
template<real_matrix RM>
auto diagonalise_dsyevr(RM &m, const double ratio = 1.0, const char jobz = 'V') {
if (!is_row_ordered(m)) m = NRG::trans(m);
const auto dim = int(size1(m));
// M is the number of the eigenvalues that we will attempt to
// calculate using dsyevr.
auto M = dim;
char RANGE = 'A'; // 'A'=all, 'V'=interval, 'I'=part
if (ratio != 1.0) {
M = ceil(ratio * M); // round up
M = std::clamp<int>(M, 1, dim); // at least 1, at most dim
RANGE = 'I';
}
auto ham = data(m);
std::vector<double> eigenvalues(dim); // eigenvalues on exit
char UPLO = 'L'; // lower triangle of a is stored
int NN = dim; // the order of the matrix
int LDA = dim; // the leading dimension of the array a
int INFO = 0; // 0 on successful exit
double VL = 0; // value range; not referenced if RANGE != 'V'
double VU = 0;
int IL = 1; // index range
int IU = M;
double ABSTOL = 0;
// If ABSTOL=0, EPS*|T| where |T| is the 1-norm of the tridiagonal
// matrix obtained by reducing m to tridiagonal form.
int MM{}; // total number of eigenvalues found
int LDZ = dim;
std::vector<int> ISUPPZ(2 * M);
// The support of the eigenvectors in Z, i.e., the indices
// indicating the nonzero elements in Z. The i-th eigenvector is
// nonzero only in elements ISUPPZ( 2*i-1 ) through ISUPPZ(2*i).
std::vector<double> Z(LDZ * M); // eigenvectors
int LWORK0 = -1;
int LIWORK0 = -1;
double WORK0 = 0; // on exit: optimal WORK size
int IWORK0 = 0; // on exist: optimal IWORK size
// Step 1: determine optimal LWORK and LIWORK
LAPACK_dsyevr(&jobz, &RANGE, &UPLO, &NN, ham, &LDA, &VL, &VU, &IL, &IU, &ABSTOL, &MM, eigenvalues.data(), Z.data(), &LDZ, ISUPPZ.data(), &WORK0, &LWORK0,
&IWORK0, &LIWORK0, &INFO);
my_assert(INFO == 0);
int LWORK = int(WORK0);
int LIWORK = IWORK0;
std::vector<double> WORK(LWORK);
std::vector<int> IWORK(LIWORK);
// Step 2: perform the diagonalisation
LAPACK_dsyevr(&jobz, &RANGE, &UPLO, &NN, ham, &LDA, &VL, &VU, &IL, &IU, &ABSTOL, &MM, eigenvalues.data(), Z.data(), &LDZ, ISUPPZ.data(), WORK.data(),
&LWORK, IWORK.data(), &LIWORK, &INFO);
if (INFO != 0) throw std::runtime_error(fmt::format("dsyev failed. INFO={}", INFO));
if (MM != int(M)) {
std::cout << "dsyevr computed " << MM << "/" << M << std::endl;
M = MM;
my_assert(M > 0); // at least one
}
return copy_results<double>(eigenvalues, Z.data(), jobz, dim, M);
}
template<complex_matrix CM>
auto diagonalise_zheev(CM &m, const char jobz = 'V') {
if (!is_row_ordered(m)) m = NRG::trans(m);
const auto dim = int(size1(m));
auto ham = reinterpret_cast<lapack_complex_double*>(data(m));
std::vector<double> eigenvalues(dim); // eigenvalues on exit
char UPLO = 'L'; // lower triangle of a is stored
int NN = dim; // the order of the matrix
int LDA = dim; // the leading dimension of the array a
int INFO = 0; // 0 on successful exit
int LWORK0 = -1; // length of the WORK array (-1 == query!)
lapack_complex_double WORK0;
int RWORKdim = std::max(1, 3 * dim - 2);
std::vector<double> RWORK(RWORKdim);
// Step 1: determine optimal LWORK
LAPACK_zheev(&jobz, &UPLO, &NN, ham, &LDA, eigenvalues.data(), &WORK0, &LWORK0, RWORK.data(), &INFO);
my_assert(INFO == 0);
int LWORK = int(WORK0.real);
std::vector<lapack_complex_double> WORK(LWORK);
// Step 2: perform the diagonalisation
LAPACK_zheev(&jobz, &UPLO, &NN, ham, &LDA, eigenvalues.data(), WORK.data(), &LWORK, RWORK.data(), &INFO);
if (INFO != 0) throw std::runtime_error(fmt::format("dsyev failed. INFO={}", INFO));
return copy_results<std::complex<double>>(eigenvalues, ham, jobz, dim, dim);
}
template<complex_matrix CM>
auto diagonalise_zheevr(CM &m, const double ratio = 1.0, const char jobz = 'V') {
if (!is_row_ordered(m)) m = NRG::trans(m);
const auto dim = int(size1(m));
// M is the number of the eigenvalues that we will attempt to
// calculate using zheevr.
auto M = dim;
char RANGE = 'A'; // 'A'=all, 'V'=interval, 'I'=part
if (ratio != 1.0) {
M = ceil(ratio * M); // round up
M = std::clamp<int>(M, 1, dim); // at least 1, at most dim
RANGE = 'I';
}
auto ham = reinterpret_cast<lapack_complex_double*>(data(m));
std::vector<double> eigenvalues(dim); // eigenvalues on exit
char UPLO = 'L'; // lower triangle of a is stored
int NN = dim; // the order of the matrix
int LDA = dim; // the leading dimension of the array a
int INFO = 0; // 0 on successful exit
double VL = 0; // value range; not referenced if RANGE != 'V'
double VU = 0;
int IL = 1; // index range
int IU = M;
double ABSTOL = 0;
// If ABSTOL=0, EPS*|T| where |T| is the 1-norm of the tridiagonal
// matrix obtained by reducing m to tridiagonal form.
int MM = 0; // total number of eigenvalues found
int LDZ = dim;
std::vector<int> ISUPPZ(2 * M);
// The support of the eigenvectors in Z, i.e., the indices indicating the nonzero elements in Z. The i-th
// eigenvector is nonzero only in elements ISUPPZ( 2*i-1 ) through ISUPPZ(2*i).
std::vector<lapack_complex_double> Z(LDZ * M); // eigenvectors
int LWORK0 = -1; // length of the WORK array (-1 == query!)
lapack_complex_double WORK0;
int LRWORK0 = -1; // query
double RWORK0 = 0; // on exit: optimal RWORK size
int LIWORK0 = -1; // query
int IWORK0 = 0; // on exit: optimal IWORK size
// Step 1: determine optimal LWORK, LRWORK, and LIWORK
LAPACK_zheevr(&jobz, &RANGE, &UPLO, &NN, ham, &LDA, &VL, &VU, &IL, &IU, &ABSTOL, &MM, eigenvalues.data(), Z.data(), &LDZ, ISUPPZ.data(), &WORK0, &LWORK0,
&RWORK0, &LRWORK0, &IWORK0, &LIWORK0, &INFO);
my_assert(INFO == 0);
int LWORK = int(WORK0.real);
std::vector<lapack_complex_double> WORK(LWORK);
int LRWORK = int(RWORK0);
std::vector<double> RWORK(LRWORK);
int LIWORK = IWORK0;
std::vector<int> IWORK(LIWORK);
// Step 2: perform the diagonalisation
LAPACK_zheevr(&jobz, &RANGE, &UPLO, &NN, ham, &LDA, &VL, &VU, &IL, &IU, &ABSTOL, &MM, eigenvalues.data(), Z.data(), &LDZ, ISUPPZ.data(), WORK.data(), &LWORK,
RWORK.data(), &LRWORK, IWORK.data(), &LIWORK, &INFO);
if (INFO != 0) throw std::runtime_error(fmt::format("zheevr failed. INFO={}", INFO));
if (MM != int(M)) {
std::cout << "zheevr computed " << MM << "/" << M << std::endl;
M = MM;
my_assert(M > 0); // at least one
}
return copy_results<std::complex<double>>(eigenvalues, Z.data(), jobz, dim, M);
}
// Wrapper for the diagonalization of the Hamiltonian matrix. The number of eigenpairs returned does NOT need to be
// equal to the dimension of the matrix h. Matrix m is destroyed in the process, thus no const attribute!
template<matrix M> auto diagonalise(M &m, const DiagParams &DP, const int myrank) {
using S = typename M::value_type;
const std::string rank_string = myrank >= 0 ? " [rank=" + std::to_string(myrank) + "]" : "";
mpilog("diagonalise " << size1(m) << "x" << size2(m) << " " << DP.diag << " " << DP.diagratio);
nrglogdp('@', "diagonalise() - size(m)=" << size1(m) << rank_string);
Timing timer;
my_assert(is_matrix_upper(m));
RawEigen<S> d;
if constexpr (std::is_same_v<S, double>) {
if (DP.diag == "dsyev"s || DP.diag == "default"s) d = diagonalise_dsyev(m);
if (DP.diag == "dsyevd"s) {
d = diagonalise_dsyevd(m);
if (d.getnrcomputed() == 0) {
std::cout << "dsyevd failed, falling back to dsyev" << std::endl;
d = diagonalise_dsyev(m);
}
}
if (DP.diag == "dsyevr"s) d = diagonalise_dsyevr(m, DP.diagratio);
}
if constexpr (std::is_same_v<S, std::complex<double>>) {
if (DP.diag == "zheev"s || DP.diag == "default"s) d = diagonalise_zheev(m);
if (DP.diag == "zheevr"s) d = diagonalise_zheevr(m, DP.diagratio);
}
const auto nr_computed = d.getnrcomputed();
my_assert(nr_computed > 0); // zero computed eigenvalues signals serious failure
my_assert(has_lesseq_rows(d.vec, m)); // sanity check
if (DP.logletter('e'))
d.dump_eigenvalues();
nrglogdp('A', "LAPACK, dim=" << dim(m) << " M=" << nr_computed << rank_string);
nrglogdp('t', "Elapsed: " << std::setprecision(3) << timer.total_in_seconds() << rank_string);
assert(check_diag()); // only in debug mode!
return d;
}
} // namespace
#endif
| 12,959
|
C++
|
.h
| 281
| 42.975089
| 159
| 0.63594
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,649
|
outfield.hpp
|
rokzitko_nrgljubljana/c++/outfield.hpp
|
// outfield.cc - Code for flexible formatted output
// Copyright (C) 2009-2020 Rok Zitko
#ifndef _outfield_hpp_
#define _outfield_hpp_
#include <vector>
#include <string>
#include <fstream>
#include <optional>
#include <stdexcept>
#include <fmt/format.h>
#include "params.hpp"
namespace NRG {
class Outfield {
private:
std::string desc;
std::string value{};
int prec, width;
public:
explicit Outfield(const std::string &desc, const unsigned int prec, const unsigned int width) : desc(desc), prec(prec), width(width) {}
template<typename T> void set_value(const T x) {
value = fmt::format("{:>{}.{}}", x, prec, width); // https://fmt.dev/latest/syntax.html
}
void put_header(std::ostream &F) const { F << std::setw(width) << desc << " "; }
void put_value(std::ostream &F) const { F << std::setw(width) << value << " "; }
[[nodiscard]] auto get_desc() const { return desc; }
};
class Allfields : std::vector<Outfield> {
private:
unsigned int prec, width;
public:
void add(const std::string &desc, const int position = -1) {
if (position == -1) {
this->emplace_back(desc, prec, width);
} else {
my_assert(position < this->size());
this->insert(this->begin() + position, Outfield(desc, prec, width));
}
}
void add(const Allfields &more, const int position = -1) {
if (position != -1) my_assert(position < this->size());
this->insert(position == -1 ? this->end() : this->begin() + position, more.begin(), more.end());
}
Allfields(const std::vector<std::string> &fields, const size_t prec, const size_t width) : prec(prec), width(width) {
for(const auto &desc : fields) add(desc);
}
void add(const std::vector<std::string> &more, const int position = -1) {
Allfields more_fields(more, prec, width);
this->add(more_fields, position);
}
void save_header(std::ostream &O) const {
O << '#';
for (const auto &f : *this) f.put_header(O);
O << std::endl;
}
void save_values(std::ostream &O) const {
O << ' ';
for (const auto &f : *this) f.put_value(O);
O << std::endl;
}
template<typename T> void set(const std::string &desc, const T &x) {
for(auto &f : *this)
if (f.get_desc() == desc) {
f.set_value(x);
return;
}
throw std::runtime_error("Invalid field " + desc);
}
};
class TD_generic {
private:
std::string filename;
std::optional<std::ofstream> O;
public:
Allfields allfields;
TD_generic(const Params &P, const std::string &filename, const std::vector<std::string> &fields) : filename(filename), allfields(fields, P.prec_td, P.width_td) {}
template<typename T> void set(const std::string &desc, const T &x) { allfields.set(desc,x); }
void save_values() {
if (!O) {
O.emplace(filename);
allfields.save_header(O.value());
}
allfields.save_values(O.value());
}
};
// Setup output fields that will appear in the file "td". Additional elements are defined in sym* files.
class TD : public TD_generic {
public:
TD(const Params &P, const std::string &filename) : TD_generic(P, filename, {"T", "<E>", "<E^2>", "C", "F", "S"}) {}
};
class TD_FDM : public TD_generic {
public:
TD_FDM(const Params &P, const std::string &filename) : TD_generic(P, filename, {"T", "E_fdm", "C_fdm", "F_fdm", "S_fdm"}) {}
};
} // namespace
#endif
| 3,423
|
C++
|
.h
| 95
| 31.736842
| 164
| 0.625754
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,650
|
time_mem.hpp
|
rokzitko_nrgljubljana/c++/time_mem.hpp
|
#ifndef _time_mem_hpp_
#define _time_mem_hpp_
#include <algorithm>
#include <utility>
#include <chrono>
#include <map>
#include <string>
#include "io.hpp"
#include "portabil.hpp"
#include "basicio.hpp"
#include <fmt/format.h>
namespace NRG {
// Warning: not thread safe!
class Timing {
private:
using tp = std::chrono::steady_clock::time_point;
using dp = std::chrono::duration<double>;
const tp start_time; // time when Timing object constructed
tp timer; // start time for timing sections
bool running{}; // currently timing a section
std::map<std::string, dp> t; // accumulators
public:
Timing() : start_time(std::chrono::steady_clock::now()) {}
[[nodiscard]] tp now() const {
return std::chrono::steady_clock::now();
}
void start() {
my_assert(!running);
running = true;
timer = now();
}
dp stop() {
my_assert(running);
running = false;
tp end = now();
return end - timer;
}
void add(const std::string &timer) {
t[timer] += stop();
}
[[nodiscard]] dp total() const {
const tp end_time = now();
return end_time - start_time;
}
[[nodiscard]] auto total_in_seconds() const {
return total().count();
}
void report(const double non_negligible_ratio = 0.01) const {
const auto T_WIDTH = 12;
const auto t_all = total();
std::cout << std::endl << "Timing report" << std::endl;
std::cout << std::setw(T_WIDTH) << "All"
<< ": " << prec3(t_all.count()) << " s" << std::endl;
dp t_sum{};
for (const auto &[name, val] : t) {
if (val/t_all > non_negligible_ratio) {
std::cout << std::setw(T_WIDTH) << name << ": " << prec3(val.count()) << " s" << std::endl;
t_sum += val;
}
}
std::cout << std::setw(T_WIDTH) << "Other" << ": " << prec3((t_all-t_sum).count()) << " s" << std::endl;
}
};
// Higher-level timing code: time a section for as long as the object is in scope.
class TimeScope {
private:
Timing &timer;
const std::string timer_name;
public:
TimeScope(Timing &timer, const std::string &timer_name) : timer(timer), timer_name(timer_name) { timer.start(); }
TimeScope(const TimeScope &) = delete;
TimeScope(TimeScope &&) = delete;
TimeScope & operator=(const TimeScope &) = delete;
TimeScope & operator=(TimeScope &&) = delete;
~TimeScope() { timer.add(timer_name); }
};
class MemoryStats {
private:
mutable long peakusage{};
public:
auto used() const {
const auto memused = memoryused();
peakusage = std::max<long>(peakusage, memused);
return memused;
}
void report() const {
#ifdef HAS_MEMORY_USAGE
fmt::print("\nPeak usage: {} MB\n", peakusage / 1024); // NOLINT
#endif
}
};
class MemTime {
private:
MemoryStats ms;
Timing tm;
public:
void brief_report() const {
#ifdef HAS_MEMORY_USAGE
std::cout << "Memory used: " << long(ms.used() / 1024) << " MB "; // NOLINT
#endif
std::cout << "Time elapsed: " << prec3(tm.total_in_seconds()) << " s" << std::endl;
}
void report() const {
ms.report();
tm.report();
}
auto time_it(const std::string &name) {
return TimeScope(tm, name); // measures time when this object exists in a given scope (assign to variable!)
}
};
} // namespace
#endif
| 3,362
|
C++
|
.h
| 112
| 26.098214
| 116
| 0.607837
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,651
|
algo_DMNRG.hpp
|
rokzitko_nrgljubljana/c++/algo_DMNRG.hpp
|
#ifndef _algo_DMNRG_hpp_
#define _algo_DMNRG_hpp_
#include <complex>
#include <tuple>
#include "traits.hpp"
#include "algo.hpp"
#include "spectrum.hpp"
namespace NRG {
using namespace std::complex_literals;
// OPTIMIZATION NOTE: the inner loop should involve the last index.
template<scalar S, typename Matrix = Matrix_traits<S>, typename t_coef = coef_traits<S>, typename t_eigen = eigen_traits<S>, typename t_weight = weight_traits<S>>
class Algo_DMNRG : public Algo<S> {
private:
inline static const std::string algoname = "DMNRG";
SpectrumRealFreq<S> spec;
const int sign; // 1 for bosons, -1 for fermions
using CB = ChainBinning<S>;
std::unique_ptr<CB> cb;
public:
using Algo<S>::P;
Algo_DMNRG(const std::string &name, const std::string &prefix, const gf_type gt, const Params &P) :
Algo<S>(P), spec(name, algoname, spec_fn(name, prefix, algoname), P), sign(gf_sign(gt)) {}
void begin(const Step &) override { cb = std::make_unique<CB>(P); }
void calc(const Step &step, const Eigen<S> &diagIp, const Eigen<S> &diagI1, const Matrix &op1, const Matrix &op2,
t_coef factor, const Invar &Ip, const Invar &I1, const DensMatElements<S> &rho, [[maybe_unused]] const Stats<S> &stats) override
{
const auto weights = [Emin = step.scale() * P.getEmin(), Emax = step.scale() * P.getEmax(), &rhoNIp = rho.at(Ip), &rhoNI1 = rho.at(I1), &diagIp, &diagI1, &op1, &op2](const auto rm, const auto rj) {
const auto Em = diagIp.values.abs_zero(rm);
const auto Ej = diagI1.values.abs_zero(rj);
const auto energy = Ej-Em;
if (abs(energy) < Emin || abs(energy) > Emax) return std::make_tuple(energy, t_weight{}, t_weight{}); // does not contribute
t_weight sumA{};
for (const auto ri: diagIp.kept()) sumA += op2(rj, ri) * rhoNIp(rm, ri); // rm <-> ri, rho symmetric
const auto weightA = sumA * conj_me(op1(rj, rm));
t_weight sumB{};
for (const auto ri: diagI1.kept()) sumB += conj_me(op1(ri, rm)) * rhoNI1(rj, ri); // non-optimal
const auto weightB = sumB * op2(rj, rm);
return std::make_tuple(energy, weightA, weightB);
};
const auto term = [&weights, this](const auto rm, const auto rj) {
const auto [energy, weightA, weightB] = weights(rm, rj);
return std::make_pair(energy, weightA + (-sign) * weightB);
};
for (const auto rm: diagIp.kept())
for (const auto rj: diagI1.kept())
cb->add(term(rm, rj), factor);
}
void end([[maybe_unused]] const Step &step) override {
spec.mergeNN2(*cb.get(), step);
cb.reset();
}
~Algo_DMNRG() { spec.save(); }
std::string rho_type() override { return "rho"; }
};
template<scalar S, typename Matrix = Matrix_traits<S>, typename t_coef = coef_traits<S>, typename t_eigen = eigen_traits<S>, typename t_weight = weight_traits<S>>
class Algo_DMNRGmats : public Algo<S> {
private:
inline static const std::string algoname = "DMNRGmats";
GFMatsubara<S> gf;
const int sign;
const gf_type gt;
using CM = ChainMatsubara<S>;
std::unique_ptr<CM> cm;
public:
using Algo<S>::P;
Algo_DMNRGmats(const std::string &name, const std::string &prefix, const gf_type gt, const Params &P) :
Algo<S>(P), gf(name, algoname, spec_fn(name, prefix, algoname), gt, P), sign(gf_sign(gt)), gt(gt) {}
void begin(const Step &) override { cm = std::make_unique<CM>(P, gt); }
void calc([[maybe_unused]] const Step &step, const Eigen<S> &diagIp, const Eigen<S> &diagI1, const Matrix &op1, const Matrix &op2,
t_coef factor, [[maybe_unused]] const Invar &Ip, [[maybe_unused]] const Invar &I1, const DensMatElements<S> &rho, [[maybe_unused]] const Stats<S> &stats) override
{
const auto weights = [&rhoNIp = rho.at(Ip), &rhoNI1 = rho.at(I1), &diagIp, &diagI1, &op1, &op2](const auto rm, const auto rj) {
const auto Em = diagIp.values.abs_zero(rm);
const auto Ej = diagI1.values.abs_zero(rj);
t_weight sumA{};
for (const auto ri: diagIp.kept()) sumA += op2(rj, ri) * rhoNIp(rm, ri); // rm <-> ri, rho symmetric
const auto weightA = sumA * conj_me(op1(rj, rm));
t_weight sumB{};
for (const auto ri: diagI1.kept()) sumB += conj_me(op1(ri, rm)) * rhoNI1(rj, ri); // non-optimal
const auto weightB = sumB * op2(rj, rm);
return std::make_tuple(Ej-Em, weightA, weightB);
};
const auto term = [&weights, this](const auto rm, const auto rj, const auto n) {
const auto [energy, weightA, weightB] = weights(rm, rj);
if (gt == gf_type::fermionic || n>0 || abs(energy) > WEIGHT_TOL) // [[likely]]
return (weightA + (-sign) * weightB) / (ww(n, gt, P.T)*1i - energy);
else // bosonic w=0 && Em=Ej case
return -weightA / t_weight(P.T);
};
for (const auto rm: diagIp.kept())
for (const auto rj: diagI1.kept())
for (size_t n = 0; n < P.mats; n++)
cm->add(n, factor * term(rm, rj, n));
}
void end([[maybe_unused]] const Step &step) override {
gf.merge(*cm.get());
cm.reset();
}
~Algo_DMNRGmats() { gf.save(); }
std::string rho_type() override { return "rho"; }
};
} // namespace
#endif
| 5,222
|
C++
|
.h
| 103
| 45.07767
| 202
| 0.627666
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,652
|
operators.hpp
|
rokzitko_nrgljubljana/c++/operators.hpp
|
#ifndef _operators_hpp_
#define _operators_hpp_
#include <map>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <stdexcept>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/range/adaptor/map.hpp>
#include <range/v3/all.hpp>
#include "invar.hpp"
#include "misc.hpp"
#include "traits.hpp"
#include "eigen.hpp"
#include "params.hpp"
#include "h5.hpp"
#include "numerics.hpp"// read_matrix
namespace NRG {
template<scalar S, typename t_matel = matel_traits<S>, typename Matrix = Matrix_traits<S>>
class MatrixElements : public std::map<Twoinvar, Matrix> {
public:
MatrixElements() = default;
MatrixElements(std::istream &fdata, const DiagInfo<S> &diag) {
const auto nf = read_one<size_t>(fdata); // Number of I1 x I2 combinations
for ([[maybe_unused]] const auto i : range0(nf)) {
const auto I1 = read_one<Invar>(fdata);
const auto I2 = read_one<Invar>(fdata);
if (const auto it1 = diag.find(I1), it2 = diag.find(I2); it1 != diag.end() && it2 != diag.end())
(*this)[{I1, I2}] = read_matrix<t_matel>(fdata, it1->second.getnrstored(), it2->second.getnrstored()); // YYY
else
throw std::runtime_error("Corrupted input file.");
}
my_assert(this->size() == nf);
}
// We trim the matrices containing the irreducible matrix elements of the operators to the sizes that are actually
// required in the next iterations. This saves memory and leads to better cache usage in recalc_general()
// recalculations. Note: this is only needed for strategy=all; copying is avoided for strategy=kept.
void trim(const DiagInfo<S> &diag) {
for (auto &[II, mat] : *this) {
const auto &[I1, I2] = II;
const auto &[dim1, dim2] = diag.dims(I1, I2); // Target matrix dimensions
mat = trim_matrix(mat, dim1, dim2);
}
}
std::ostream &insertor(std::ostream &os) const {
for (const auto &[II, mat] : *this)
os << "----" << II << "----" << std::endl << mat << std::endl;
return os;
}
friend std::ostream &operator<<(std::ostream &os, const MatrixElements<S> &m) { return m.insertor(os); }
friend void dump_diagonal_op(const std::string &name, const MatrixElements<S> &m, const size_t max_nr, std::ostream &F) {
F << "Diagonal matrix elements of operator " << name << std::endl;
for (const auto &[II, mat] : m) {
const auto & [I1, I2] = II;
if (I1 == I2) {
F << I1 << ": ";
dump_diagonal_matrix(mat, max_nr, F);
}
}
}
void h5save(H5Easy::File &fd, const std::string &name) const {
for (const auto &[II, mat] : *this) {
const auto &[I1, I2] = II;
h5_dump_matrix(fd, name + "/" + I1.name() + "/" + I2.name() + "/matrix", mat);
}
}
};
template<scalar S, typename Matrix = Matrix_traits<S>>
class DensMatElements : public std::map<Invar, Matrix> {
public:
template <typename MF>
auto trace(MF mult) const {
return ranges::accumulate(*this, 0.0, {},
[mult](const auto z) { const auto &[I, mat] = z; return mult(I) * trace_real(mat); });
}
void save(const size_t N, const Params &P, const std::string &prefix) const {
const auto fn = P.workdir->rhofn(N, prefix);
std::ofstream MATRIXF(fn, std::ios::binary | std::ios::out);
if (!MATRIXF) throw std::runtime_error(fmt::format("Can't open file {} for writing.", fn));
boost::archive::binary_oarchive oa(MATRIXF);
oa << this->size();
for (const auto &[I, mat] : *this) {
oa << I;
NRG::save(oa, mat);
if (MATRIXF.bad()) throw std::runtime_error(fmt::format("Error writing {}", fn)); // Check each time
}
MATRIXF.close();
}
void load(const size_t N, const Params &P, const std::string &prefix, const bool remove_files) {
const auto fn = P.workdir->rhofn(N, prefix);
std::ifstream MATRIXF(fn, std::ios::binary | std::ios::in);
if (!MATRIXF) throw std::runtime_error(fmt::format("Can't open file {} for reading", fn));
boost::archive::binary_iarchive ia(MATRIXF);
const auto nr = read_one<size_t>(ia);
for ([[maybe_unused]] const auto cnt : range0(nr)) {
const auto inv = read_one<Invar>(ia);
(*this)[inv] = NRG::load<S>(ia);
if (MATRIXF.bad()) throw std::runtime_error(fmt::format("Error reading {}", fn)); // Check each time
}
MATRIXF.close();
if (remove_files)
if (NRG::remove(fn)) throw std::runtime_error(fmt::format("Error removing {}", fn));
}
};
// Map of operator matrices
template <scalar S>
struct CustomOp : public std::map<std::string, MatrixElements<S>> {
void trim(const DiagInfo<S> &diag) {
for (auto &op : *this | boost::adaptors::map_values) op.trim(diag);
}
void h5save(H5Easy::File &fd, const std::string &name) const {
for (const auto &[n, op] : *this) op.h5save(fd, name + "/" + n);
}
};
// Vector containing irreducible matrix elements of f operators.
template<scalar S>
using OpchChannel = std::vector<MatrixElements<S>>;
// Each channel contains P.perchannel OpchChannel matrices.
template<scalar S>
class Opch : public std::vector<OpchChannel<S>> {
public:
Opch() = default;
explicit Opch(const Params &P) {
this->resize(P.channels);
for (auto &oc: *this) {
oc.resize(P.perchannel);
for (auto &o: oc)
o.clear(); // set all matrix elements to zero
}
}
explicit Opch(std::istream &fdata, const DiagInfo<S> &diag, const Params &P) {
skip_comments(fdata);
this->resize(P.channels);
for (auto &oc : *this) {
oc.resize(P.perchannel);
for (auto &o : oc) {
[[maybe_unused]] const auto ch = read_one<char>(fdata);
[[maybe_unused]] const auto iread = read_one<size_t>(fdata);
[[maybe_unused]] const auto jread = read_one<size_t>(fdata);
my_assert(ch == 'f');
o = MatrixElements<S>(fdata, diag);
}
}
}
void dump(std::ostream &F = std::cout) {
F << std::endl;
for (const auto &&[i, ch] : *this | ranges::views::enumerate)
for (const auto &&[j, mat] : ch | ranges::views::enumerate)
F << fmt::format("<f> dump, i={} j={}\n", i, j) << mat << std::endl;
F << std::endl;
}
};
// Object of class Operators cotains full information about matrix representations when entering stage N of the NRG
// iteration.
template<scalar S>
class Operators {
public:
Opch<S> opch; // f operators (channels)
CustomOp<S> ops; // singlet operators (even parity)
CustomOp<S> opsp; // singlet operators (odd parity)
CustomOp<S> opsg; // singlet operators [global op]
CustomOp<S> opd; // doublet operators (spectral functions)
CustomOp<S> opt; // triplet operators (dynamical spin susceptibility)
CustomOp<S> opq; // quadruplet operators (spectral functions for J=3/2)
CustomOp<S> opot; // orbital triplet operators
void dump_diagonal(const size_t max_nr, std::ostream &F = std::cout) const {
if (max_nr) {
for (const auto &[name, m] : ops) dump_diagonal_op(name, m, max_nr, F);
for (const auto &[name, m] : opsg) dump_diagonal_op(name, m, max_nr, F);
}
}
void trim_matrices(const DiagInfo<S> &diag) {
ops.trim(diag);
opsp.trim(diag);
opsg.trim(diag);
opd.trim(diag);
opt.trim(diag);
opq.trim(diag);
opot.trim(diag);
}
void h5save(H5Easy::File &fd, const std::string &name) const {
ops.h5save(fd, name + "/s");
opsp.h5save(fd, name + "/sp");
opsg.h5save(fd, name + "/sg");
opd.h5save(fd, name + "/d");
opt.h5save(fd, name + "/t");
opq.h5save(fd, name + "/q");
opot.h5save(fd, name + "/ot");
}
};
} // namespace
#endif
| 7,797
|
C++
|
.h
| 194
| 35.134021
| 124
| 0.623979
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,653
|
oprecalc.hpp
|
rokzitko_nrgljubljana/c++/oprecalc.hpp
|
#ifndef _oprecalc_hpp_
#define _oprecalc_hpp_
#include <string>
#include <set>
#include <memory>
#include "time_mem.hpp"
#include "operators.hpp"
#include "symmetry.hpp"
#include "step.hpp"
#include "params.hpp"
#include "algo.hpp"
#include "stats.hpp"
#include <fmt/format.h>
namespace NRG {
template<scalar S>
class Oprecalc {
private:
RUNTYPE runtype;
std::shared_ptr<Symmetry<S>> Sym;
MemTime &mt; // ref!
const Params &P;
public:
// Operators required to calculate expectation values and spectral densities
struct Ops : public std::set<std::pair<std::string,std::string>> {
void report(std::ostream &F = std::cout) {
F << std::endl << "Computing the following operators:" << std::endl;
for (const auto &[type, name]: *this) fmt::print("{} {}\n", name, type);
}
// Singlet operators are always recomputed in the first NRG run, so that we can calculate the expectation values.
[[nodiscard]] bool do_s(const std::string &name, const Params &P, const Step &step) {
if (step.nrg()) return true; // for computing <O>
if (step.dmnrg() && P.fdmexpv && step.N() <= P.fdmexpvn) return true; // for computing <O> using FDM algorithm
return this->count({"s", name});
}
[[nodiscard]] bool do_g(const std::string &name, const Params &P, const Step &step) {
if (step.nrg()) return true; // for computing <O>
if (step.dmnrg() && P.fdmexpv && step.N() <= P.fdmexpvn) return true; // for computing <O> using FDM algorithm
return this->count({"g", name});
}
};
Ops ops;
// Spectral densities
struct SL : public speclist<S> {
void calc(const Step &step, const DiagInfo<S> &diag, DensMatElements<S> &rho, DensMatElements<S> &rhoFDM,
const Stats<S> &stats, MemTime &mt, const Symmetry<S> *Sym, const Params &P) {
const auto section_timing = mt.time_it("spec");
for (auto &i : *this) i.calc(step, diag, rho, rhoFDM, stats, Sym, P);
}
};
SL sl;
// Wrapper routine for recalculations
template <typename RecalcFnc>
MatrixElements<S> recalc(const std::string &name, const MatrixElements<S> &mold, RecalcFnc recalc_fnc, const std::string &tip,
const Step &step, const DiagInfo<S> &diag) {
nrglog('0', "\n#### Recalculate " << tip << " " << name);
auto mnew = recalc_fnc(diag, mold);
if (tip == "g") Sym->recalc_global(step, diag, name, mnew);
return mnew;
}
template <typename ... Args>
MatrixElements<S> recalc_or_clear(const bool selected, Args&& ... args) {
return selected ? recalc(std::forward<Args>(args)...) : MatrixElements<S>();
}
// Recalculate operator matrix representations
void recalculate_operators(Operators<S> &a, const Step &step, const DiagInfo<S> &diag, const Params &P) {
nrglog('@', "recalculate_operators()");
const auto section_timing = mt.time_it("recalc");
for (auto &[name, m] : a.ops)
m = recalc_or_clear(ops.do_s(name, P, step), name, m, [this](const auto &... pr) { return Sym->recalc_singlet(pr..., 1); }, "s", step, diag);
for (auto &[name, m] : a.opsp)
m = recalc_or_clear(ops.count({"p", name}), name, m, [this](const auto &... pr) { return Sym->recalc_singlet(pr..., -1); }, "p", step, diag);
for (auto &[name, m] : a.opsg)
m = recalc_or_clear(ops.do_g(name, P, step), name, m, [this](const auto &... pr) { return Sym->recalc_singlet(pr..., 1); }, "g", step, diag);
for (auto &[name, m] : a.opd)
m = recalc_or_clear(ops.count({"d", name}), name, m, [this](const auto &... pr) { return Sym->recalc_doublet(pr...); }, "d", step, diag);
for (auto &[name, m] : a.opt)
m = recalc_or_clear(ops.count({"t", name}), name, m, [this](const auto &... pr) { return Sym->recalc_triplet(pr...); }, "t", step, diag);
for (auto &[name, m] : a.opot)
m = recalc_or_clear(ops.count({"ot", name}), name, m, [this](const auto &... pr) { return Sym->recalc_orb_triplet(pr...); }, "ot", step, diag);
for (auto &[name, m] : a.opq)
m = recalc_or_clear(ops.count({"q", name}), name, m, [this](const auto &... pr) { return Sym->recalc_quadruplet(pr...); }, "q", step, diag);
}
// Establish the data structures for storing spectral information [and prepare output files].
template<typename A, typename M>
[[nodiscard]] bool prepare_spec_algo(std::string prefix, const Params &P, FactorFnc ff, CheckFnc cf, M && op1, M && op2, int spin,
std::string name, const gf_type gt) {
BaseSpectrum<S> spec(std::forward<M>(op1), std::forward<M>(op2), spin, std::make_shared<A>(name, prefix, gt, P), ff, cf);
sl.push_back(spec);
return true; // recalculation of operators required
}
template<typename ... Args>
[[nodiscard]] bool prepare_spec(std::string prefix, Args && ... args) {
bool b = false;
if (prefix == "gt") {
if (runtype == RUNTYPE::NRG) b |= prepare_spec_algo<Algo_GT<S,0>>(prefix, P, std::forward<Args>(args)...);
return b;
}
if (prefix == "i1t") {
if (runtype == RUNTYPE::NRG) b |= prepare_spec_algo<Algo_GT<S,1>>(prefix, P, std::forward<Args>(args)...);
return b;
}
if (prefix == "i2t") {
if (runtype == RUNTYPE::NRG) b |= prepare_spec_algo<Algo_GT<S,2>>(prefix, P, std::forward<Args>(args)...);
return b;
}
if (prefix == "chit") {
if (runtype == RUNTYPE::NRG) b |= prepare_spec_algo<Algo_CHIT<S>>(prefix, P, std::forward<Args>(args)...);
return b;
}
// If we did not return from this funciton by this point, what we are computing is the spectral function. There are
// several possibilities in this case, all of which may be enabled at the same time.
if (runtype == RUNTYPE::NRG) {
if (P.finite) b |= prepare_spec_algo<Algo_FT<S>> (prefix, P, std::forward<Args>(args)...);
if (P.finitemats) b |= prepare_spec_algo<Algo_FTmats<S>>(prefix, P, std::forward<Args>(args)...);
}
if (runtype == RUNTYPE::DMNRG) {
if (P.dmnrg) b |= prepare_spec_algo<Algo_DMNRG<S>>(prefix, P, std::forward<Args>(args)...);
if (P.dmnrgmats) b |= prepare_spec_algo<Algo_DMNRGmats<S>>(prefix, P, std::forward<Args>(args)...);
if (P.cfs) b |= prepare_spec_algo<Algo_CFS<S>>(prefix, P, std::forward<Args>(args)...);
if (P.cfsgt) b |= prepare_spec_algo<Algo_CFSgt<S>>(prefix, P, std::forward<Args>(args)...);
if (P.cfsls) b |= prepare_spec_algo<Algo_CFSls<S>>(prefix, P, std::forward<Args>(args)...);
if (P.fdm) b |= prepare_spec_algo<Algo_FDM<S>>(prefix, P, std::forward<Args>(args)...);
if (P.fdmgt) b |= prepare_spec_algo<Algo_FDMgt<S>>(prefix, P, std::forward<Args>(args)...);
if (P.fdmls) b |= prepare_spec_algo<Algo_FDMls<S>>(prefix, P, std::forward<Args>(args)...);
if (P.fdmmats) b |= prepare_spec_algo<Algo_FDMmats<S>>(prefix, P, std::forward<Args>(args)...);
}
return b;
}
// Construct the suffix of the filename for spectral density files: 'A_?-A_?'.
// If SPIN == 1 or SPIN == -1, '-u' or '-d' is appended to the string.
[[nodiscard]] auto sdname(const std::string &a, const std::string &b, const int spin) {
return a + "-" + b + (spin == 0 ? "" : (spin == 1 ? "-u" : "-d"));
}
void loopover(const CustomOp<S> &set1, const CustomOp<S> &set2,
const string_token &stringtoken, FactorFnc ff, CheckFnc cf,
const std::string &prefix,
const std::string &type1, const std::string &type2, const gf_type gt, const int spin) {
for (const auto &[name1, op1] : set1) {
for (const auto &[name2, op2] : set2) {
if (const auto name = sdname(name1, name2, spin); stringtoken.find(name)) {
if (prepare_spec(prefix, ff, cf, op1, op2, spin, name, gt)) {
ops.insert({type1, name1});
ops.insert({type2, name2});
}
}
}
}
}
// Reset lists of operators which need to be iterated
Oprecalc(const RUNTYPE &runtype, const Operators<S> &a, std::shared_ptr<Symmetry<S>> Sym, MemTime &mt, const Params &P) :
runtype(runtype), Sym(Sym), mt(mt), P(P)
{
std::cout << std::endl << "Computing the following spectra:" << std::endl;
// Correlators (singlet operators of all kinds)
string_token sts(P.specs);
loopover(a.ops, a.ops, sts, Sym->CorrelatorFactorFnc(), Sym->TrivialCheckSpinFnc(), "corr", "s", "s", gf_type::bosonic, 0);
loopover(a.opsp, a.opsp, sts, Sym->CorrelatorFactorFnc(), Sym->TrivialCheckSpinFnc(), "corr", "p", "p", gf_type::bosonic, 0);
loopover(a.opsg, a.opsg, sts, Sym->CorrelatorFactorFnc(), Sym->TrivialCheckSpinFnc(), "corr", "g", "g", gf_type::bosonic, 0);
loopover(a.ops, a.opsg, sts, Sym->CorrelatorFactorFnc(), Sym->TrivialCheckSpinFnc(), "corr", "s", "g", gf_type::bosonic, 0);
loopover(a.opsg, a.ops, sts, Sym->CorrelatorFactorFnc(), Sym->TrivialCheckSpinFnc(), "corr", "g", "s", gf_type::bosonic, 0);
// Global susceptibilities (global singlet operators)
string_token stchit(P.specchit);
loopover(a.ops, a.ops, stchit, Sym->CorrelatorFactorFnc(), Sym->TrivialCheckSpinFnc(), "chit", "s", "s", gf_type::bosonic, 0);
loopover(a.ops, a.opsg, stchit, Sym->CorrelatorFactorFnc(), Sym->TrivialCheckSpinFnc(), "chit", "s", "g", gf_type::bosonic, 0);
loopover(a.opsg, a.ops, stchit, Sym->CorrelatorFactorFnc(), Sym->TrivialCheckSpinFnc(), "chit", "g", "s", gf_type::bosonic, 0);
loopover(a.opsg, a.opsg, stchit, Sym->CorrelatorFactorFnc(), Sym->TrivialCheckSpinFnc(), "chit", "g", "g", gf_type::bosonic, 0);
// Dynamic spin susceptibilities (triplet operators)
string_token stt(P.spect);
loopover(a.opt, a.opt, stt, Sym->SpinSuscFactorFnc(), Sym->TrivialCheckSpinFnc(), "spin", "t", "t", gf_type::bosonic, 0);
string_token stot(P.specot);
loopover(a.opot, a.opot, stot, Sym->OrbSuscFactorFnc(), Sym->TrivialCheckSpinFnc(), "orbspin", "ot", "ot", gf_type::bosonic, 0);
const auto varmin = Sym->isfield() ? -1 : 0;
const auto varmax = Sym->isfield() ? +1 : 0;
// Spectral functions (doublet operators)
string_token std(P.specd);
for (int SPIN = varmin; SPIN <= varmax; SPIN += 2)
loopover(a.opd, a.opd, std, Sym->SpecdensFactorFnc(), Sym->SpecdensCheckSpinFnc(), "spec", "d", "d", gf_type::fermionic, SPIN);
string_token stgt(P.specgt);
for (int SPIN = varmin; SPIN <= varmax; SPIN += 2)
loopover(a.opd, a.opd, stgt, Sym->SpecdensFactorFnc(), Sym->SpecdensCheckSpinFnc(), "gt", "d", "d", gf_type::fermionic, SPIN);
string_token sti1t(P.speci1t);
for (int SPIN = varmin; SPIN <= varmax; SPIN += 2)
loopover(a.opd, a.opd, sti1t, Sym->SpecdensFactorFnc(), Sym->SpecdensCheckSpinFnc(),"i1t", "d", "d", gf_type::fermionic, SPIN);
string_token sti2t(P.speci2t);
for (int SPIN = varmin; SPIN <= varmax; SPIN += 2)
loopover(a.opd, a.opd, sti2t, Sym->SpecdensFactorFnc(), Sym->SpecdensCheckSpinFnc(), "i2t", "d", "d", gf_type::fermionic, SPIN);
// Spectral functions (quadruplet operators)
string_token stq(P.specq);
loopover(a.opq, a.opq, stq, Sym->SpecdensquadFactorFnc(), Sym->TrivialCheckSpinFnc(), "specq", "q", "q", gf_type::fermionic, 0);
ops.report();
}
};
// Recalculate irreducible matrix elements for Wilson chains.
template<scalar S>
void recalc_irreducible(const Step &step, const DiagInfo<S> &diag, Opch<S> &opch,
const Symmetry<S> *Sym, MemTime &mt, const Params &P) {
const auto section_timing = mt.time_it("recalc f");
if (!P.substeps) {
opch = Sym->recalc_irreduc(step, diag);
} else {
const auto [N, M] = step.NM();
for (const auto i: range0(size_t(P.channels)))
if (i == M) {
opch[i] = Sym->recalc_irreduc_substeps(step, diag, i);
} else {
for (const auto j: range0(size_t(P.perchannel)))
opch[i][j] = Sym->recalc_doublet(diag, opch[i][j]);
}
}
}
} // namespace
#endif
| 12,268
|
C++
|
.h
| 212
| 51.273585
| 152
| 0.605449
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,654
|
core.hpp
|
rokzitko_nrgljubljana/c++/core.hpp
|
#ifndef _core_hpp_
#define _core_hpp_
#include <cstddef>
#include <set>
#include <algorithm>
#include <omp.h>
#include <range/v3/all.hpp>
#include "constants.hpp"
#include "traits.hpp"
#include "invar.hpp"
#include "eigen.hpp"
#include "operators.hpp"
#include "subspaces.hpp"
#include "store.hpp"
#include "step.hpp"
#include "stats.hpp"
#include "spectral.hpp"
#include "coef.hpp"
#include "tridiag.hpp"
#include "diag.hpp"
#include "symmetry.hpp"
#include "matrix.hpp"
#include "recalc.hpp"
#include "read-input.hpp"
#include "spectrum.hpp"
#include "algo.hpp"
#include "dmnrg.hpp"
#include "splitting.hpp"
#include "output.hpp"
#include "oprecalc.hpp"
#include "measurements.hpp"
#include "truncation.hpp"
#include "diag_mpi.hpp"
#include "diag_openmp.hpp"
#include "diag_serial.hpp"
#include "h5.hpp"
#include "io.hpp"
#include <fmt/format.h>
#include <fmt/color.h>
namespace NRG {
// Determine the ranges of index r
template<scalar S>
SubspaceDimensions::SubspaceDimensions(const Invar &I, const InvarVec &ancestors, const DiagInfo<S> &diagprev,
const Symmetry<S> *Sym, const bool ignore_inequality) : ancestors(ancestors) {
for (const auto &[i, anc] : ancestors | ranges::views::enumerate) {
const bool coupled = Sym->triangle_inequality(I, anc, Sym->QN_subspace(i));
dims.push_back(coupled || ignore_inequality? diagprev.size_subspace(anc) : 0);
}
// The triangle inequality test here is *required*. There are cases where a candidate subspace exists (as generated
// from the In vector as one of the "combinations"), but it is actually decoupled from space I, because the
// triangle inequality is not satisfied. [Set ignore_inequality=true to disable the check for testing purposes.]
}
// Determine the structure of matrices in the new NRG shell
template<scalar S>
SubspaceStructure::SubspaceStructure(const DiagInfo<S> &diagprev, const Symmetry<S> *Sym) {
for (const auto &I : new_subspaces(diagprev, Sym))
(*this)[I] = SubspaceDimensions{I, Sym->ancestors(I), diagprev, Sym};
}
// Subspaces for the new iteration
template<scalar S>
auto new_subspaces(const DiagInfo<S> &diagprev, const Symmetry<S> *Sym) {
std::set<Invar> subspaces;
for (const auto &I : diagprev.subspaces()) {
const auto all = Sym->new_subspaces(I);
const auto non_empty = all | ranges::views::filter([Sym](const auto &In) { return Sym->Invar_allowed(In); }) | ranges::to<std::vector>();
std::copy(non_empty.begin(), non_empty.end(), std::inserter(subspaces, subspaces.end()));
}
return subspaces;
}
template<scalar S>
auto hamiltonian(const Step &step, const Invar &I, const Opch<S> &opch, const Coef<S> &coef,
const DiagInfo<S> &diagprev, const Output<S> &output, const Symmetry<S> *Sym, const Params &P) {
const auto anc = Sym->ancestors(I);
const SubspaceDimensions rm{I, anc, diagprev, Sym};
auto h = zero_matrix<S>(rm.total());
for (const auto i : Sym->combs()) {
const auto range = rm.view(i);
for (const auto & [n, r] : range | ranges::views::enumerate)
h(r,r) = P.nrg_step_scale_factor() * diagprev.at(anc[i]).values.corr(n); // H_{N+1}=\lambda^{1/2} H_N+\xi_N (hopping terms)
}
Sym->make_matrix(h, step, rm, I, anc, opch, coef); // Symmetry-type-specific matrix initialization steps
if (P.logletter('m')) dump_matrix(h);
if (P.h5raw && (P.h5all || (P.h5last && step.last())) && P.h5ham)
h5_dump_matrix(*output.h5raw, std::to_string(step.ndx()+1) + "/hamiltonian/" + I.name() + "/matrix", h);
return h;
}
template<scalar S>
auto do_diag(const Step &step, const Operators<S> &operators, const Coef<S> &coef, Stats<S> &stats, const DiagInfo<S> &diagprev,
const Output<S> &output, const TaskList &tasklist, const Symmetry<S> *Sym, DiagEngine<S> *eng, MemTime &mt, const Params &P) {
step.infostring();
Sym->show_coefficients(step, coef);
double diagratio = P.diagratio; // non-const
DiagInfo<S> diag;
while (true) {
try {
if (step.nrg()) {
if (!(P.resume && P.laststored.has_value() && step.ndx() <= P.laststored.value())) {
const auto section_timing = mt.time_it("diag");
diag = eng->diagonalisations(step, operators.opch, coef, diagprev, output, tasklist.get(), DiagParams(P, diagratio), Sym, P); // compute in first run
} else {
diag = DiagInfo<S>(step.ndx(), P, false); // or read from disk
}
}
if (step.dmnrg()) {
diag = DiagInfo<S>(step.ndx(), P, P.removefiles); // read from disk in second run
diag.subtract_GS_energy(stats.GS_energy);
}
stats.Egs = diag.Egs_subtraction();
Clusters<S> clusters(diag, P.fixeps);
truncate_prepare(step, diag, Sym->multfnc(), P);
break;
}
catch (NotEnough &e) {
color_print(P.pretty_out, fmt::emphasis::bold | fg(fmt::color::yellow), "Insufficient number of states computed.\n");
if (!(step.nrg() && P.restart)) break;
diagratio = std::min(diagratio * P.restartfactor, 1.0);
color_print(P.pretty_out, fmt::emphasis::bold | fg(fmt::color::yellow), "\nRestarting this iteration step. diagratio={}\n\n", diagratio);
}
}
return diag;
}
// Absolute energies. Must be called in the first NRG run after stats.total_energy has been updated, but before
// store_transformations().
template<scalar S>
void calc_abs_energies(const Step &step, DiagInfo<S> &diag, const Stats<S> &stats) {
for (auto &eig : diag.eigs()) {
eig.values.set_scale(step.scale());
eig.values.set_T_shift(stats.total_energy);
}
}
// Operator sumrules
template<scalar S, typename F>
auto norm(const MatrixElements<S> &m, const Symmetry<S> *Sym, F factor_fnc, const int SPIN) {
weight_traits<S> sum{};
for (const auto &[II, mat] : m) {
const auto & [I1, Ip] = II;
if (!Sym->check_SPIN(I1, Ip, SPIN)) continue;
sum += factor_fnc(Ip, I1) * frobenius_norm(mat);
}
return 2.0 * sum.real(); // Factor 2: Tr[d d^\dag + d^\dag d] = 2 \sum_{i,j} A_{i,j}^2 !!
}
template<scalar S>
void operator_sumrules(const Operators<S> &a, const Symmetry<S> *Sym) {
// We check sum rules wrt some given spin (+1/2, by convention). For non-spin-polarized calculations, this is
// irrelevant (0).
const int SPIN = Sym->isfield() ? 1 : 0;
for (const auto &[name, m] : a.opd)
std::cout << "norm[" << name << "]=" << norm(m, Sym, Sym->SpecdensFactorFnc(), SPIN) << std::endl;
for (const auto &[name, m] : a.opq)
std::cout << "norm[" << name << "]=" << norm(m, Sym, Sym->SpecdensquadFactorFnc(), 0) << std::endl;
for (const auto && [i, ch] : a.opch | ranges::views::enumerate)
for (const auto && [j, m] : ch | ranges::views::enumerate)
std::cout << "norm[f," << i << "," << j << "]=" << norm(m, Sym, Sym->SpecdensFactorFnc(), SPIN) << std::endl;
}
// Store information about subspaces and states for the DM algorithms
template<scalar S>
void store_states(const Step &step, Store<S> &store, Store<S> &store_all, const DiagInfo<S> &diag_in, const SubspaceStructure &substruct,
const Symmetry<S> *Sym, const Params &P) {
store_all[step.ndx()] = Subs(diag_in, substruct, step.last());
if (P.project == ""s) {
store[step.ndx()] = Subs(diag_in, substruct, step.last());
} else {
const auto diag = Sym->project(diag_in, P.project);
// We need 'substruct' to obtain information about the structure (rmax values) of the ancestor spaces.
store[step.ndx()] = Subs(diag, substruct, step.last());
}
}
// Perform processing after a successful NRG step. Also called from doZBW() as a final step.
template<scalar S>
void after_diag(const Step &step, Operators<S> &operators, Stats<S> &stats, DiagInfo<S> &diag, Output<S> &output,
const SubspaceStructure &substruct, Store<S> &store, Store<S> &store_all, Oprecalc<S> &oprecalc, const Symmetry<S> *Sym,
MemTime &mt, const Params &P) {
nrglog('@', "after_diag()");
stats.update(step);
if (step.nrg()) {
calc_abs_energies(step, diag, stats); // only in the first run, in the second one the data is loaded from file!
if (P.dm && !(P.resume && P.laststored.has_value() && step.ndx() <= P.laststored.value()))
diag.save(step.ndx(), P);
perform_basic_measurements(step, diag, Sym, stats, output, P); // Measurements are performed before the truncation!
}
if (P.h5raw && (P.h5all || (P.h5last && step.last())))
diag.h5save(*output.h5raw, std::to_string(step.ndx()+1) + "/eigen/", P.h5vectors);
if (!P.ZBW()) {
split_in_blocks(diag, substruct);
if (P.h5raw && (P.h5all || (P.h5last && step.last())) && P.h5U)
h5save_blocks(*output.h5raw, std::to_string(step.ndx()+1) + "/U/", diag, substruct);
}
if (P.do_recalc_all(step.get_runtype())) { // Either ...
oprecalc.recalculate_operators(operators, step, diag, P);
calculate_spectral_and_expv(step, stats, output, oprecalc, diag, operators, store_all, mt, Sym, P);
}
if (!P.ZBW()) {
nrglog('@', "truncate_perform()");
diag.truncate_perform(); // Actual truncation occurs at this point
}
store_states(step, store, store_all, diag, substruct, Sym, P);
if (!step.last()) {
nrglog('@', "recalc_irreducible()");
recalc_irreducible(step, diag, operators.opch, Sym, mt, P);
if (P.dump_f) operators.opch.dump();
}
if (P.do_recalc_kept(step.get_runtype())) { // ... or ...
oprecalc.recalculate_operators(operators, step, diag, P);
calculate_spectral_and_expv(step, stats, output, oprecalc, diag, operators, store_all, mt, Sym, P);
}
if (P.do_recalc_none()) // ... or this
calculate_spectral_and_expv(step, stats, output, oprecalc, diag, operators, store_all, mt, Sym, P);
if (P.checksumrules) operator_sumrules(operators, Sym);
if (P.h5raw && (P.h5all || (P.h5last && step.last())) && P.h5ops)
operators.h5save(*output.h5raw, std::to_string(step.ndx()+1));
}
// Perform one iteration step
template<scalar S>
auto iterate(const Step &step, Operators<S> &operators, const Coef<S> &coef, Stats<S> &stats, const DiagInfo<S> &diagprev,
Output<S> &output, Store<S> &store, Store<S> &store_all, Oprecalc<S> &oprecalc, const Symmetry<S> *Sym, DiagEngine<S> *eng, MemTime &mt, const Params &P) {
SubspaceStructure substruct{diagprev, Sym};
TaskList tasklist{substruct};
if (P.h5raw && (P.h5all || (P.h5last && step.last())) && P.h5struct)
substruct.h5save(*output.h5raw, std::to_string(step.ndx()+1) + "/structure");
auto diag = do_diag(step, operators, coef, stats, diagprev, output, tasklist, Sym, eng, mt, P);
after_diag(step, operators, stats, diag, output, substruct, store, store_all, oprecalc, Sym, mt, P);
operators.trim_matrices(diag);
diag.clear_eigenvectors();
mt.brief_report();
return diag;
}
// Perform calculations with quantities from 'data' file
template<scalar S>
void docalc0(Step &step, const Operators<S> &operators, const DiagInfo<S> &diag0, Stats<S> &stats, Output<S> &output,
Oprecalc<S> &oprecalc, const Symmetry<S> *Sym, MemTime &mt, const Params &P) {
step.set(P.Ninit - 1); // in the usual case with Ninit=0, this will result in N=-1
std::cout << std::endl << "Before NRG iteration";
std::cout << " (N=" << step.N() << ")" << std::endl;
perform_basic_measurements(step, diag0, Sym, stats, output, P);
Store<S> empty_st(0, 0);
calculate_spectral_and_expv(step, stats, output, oprecalc, diag0, operators, empty_st, mt, Sym, P);
if (P.checksumrules) operator_sumrules(operators, Sym);
}
// doZBW() takes the place of iterate() called from main_loop() in the case of zero-bandwidth calculation.
// It replaces do_diag() and calls after_diag() as the last step.
template<scalar S>
auto nrg_ZBW(Step &step, Operators<S> &operators, Stats<S> &stats, const DiagInfo<S> &diag0, Output<S> &output,
Store<S> &store, Store<S> &store_all, Oprecalc<S> &oprecalc, const Symmetry<S> *Sym, MemTime &mt, const Params &P) {
std::cout << std::endl << "Zero bandwidth calculation" << std::endl;
step.set_ZBW();
// --- begin do_diag() equivalent
DiagInfo<S> diag;
if (step.nrg())
diag = diag0;
if (step.dmnrg()) {
diag = DiagInfo<S>(step.ndx(), P, P.removefiles);
diag.subtract_GS_energy(stats.GS_energy);
}
stats.Egs = diag.Egs_subtraction();
truncate_prepare(step, diag, Sym->multfnc(), P); // determine # of kept and discarded states
// --- end do_diag() equivalent
SubspaceStructure substruct{};
after_diag(step, operators, stats, diag, output, substruct, store, store_all, oprecalc, Sym, mt, P);
return diag;
}
template<scalar S>
auto nrg_loop(Step &step, Operators<S> &operators, const Coef<S> &coef, Stats<S> &stats, const DiagInfo<S> &diag0,
Output<S> &output, Store<S> &store, Store<S> &store_all, Oprecalc<S> &oprecalc, const Symmetry<S> *Sym, DiagEngine<S> *eng, MemTime &mt, const Params &P) {
auto diag = diag0;
for (step.init(); !step.end(); step.next())
diag = iterate(step, operators, coef, stats, diag, output, store, store_all, oprecalc, Sym, eng, mt, P);
step.set(step.lastndx());
return diag;
}
} // namespace
#endif
| 13,118
|
C++
|
.h
| 271
| 44.693727
| 169
| 0.666407
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,655
|
h5.hpp
|
rokzitko_nrgljubljana/c++/h5.hpp
|
#ifndef _h5_hpp_
#define _h5_hpp_
#include <iostream>
#include <vector>
#include <string>
#include <complex>
#include <type_traits>
#include "traits.hpp"
#define H5_USE_EIGEN
#include <highfive/highfive.hpp>
#include <highfive/eigen.hpp>
#include <highfive/H5Easy.hpp>
namespace NRG {
template<typename T>
void h5_dump_scalar(H5Easy::File &file, const std::string &path, const T x) {
if constexpr (std::is_same<T, bool>::value) {
std::vector<int> vec = {x ? 1 : 0}; // workaround for bool
H5Easy::dump(file, path, vec);
} else {
std::vector<T> vec = {x};
H5Easy::dump(file, path, vec);
}
}
template<typename T>
void h5_dump_vector(H5Easy::File &file, const std::string &path, const std::vector<T> &vec) {
H5Easy::dump(file, path, vec);
}
template <real_Eigen_matrix REM>
void h5_dump_matrix(H5Easy::File &file, const std::string &path, const REM &m) {
H5Easy::dump(file, path, m);
}
template <complex_Eigen_matrix CEM>
void h5_dump_matrix(H5Easy::File &file, const std::string &path, const CEM &m) {
EigenMatrix<double> mr = m.real();
h5_dump_matrix(file, path, mr);
EigenMatrix<double> mi = m.imag();
h5_dump_matrix(file, path + "-imag", mi);
}
}
#endif
| 1,265
|
C++
|
.h
| 40
| 27.875
| 96
| 0.658176
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,656
|
matrix.hpp
|
rokzitko_nrgljubljana/c++/matrix.hpp
|
// matrix.cc - Symmetry dependent code for Hamiltonian matrix generation
// Copyright (C) 2009-2020 Rok Zitko
#ifndef _matrix_hpp_
#define _matrix_hpp_
#include <stdexcept>
#include "invar.hpp"
#include "eigen.hpp"
#include "symmetry.hpp"
#include "step.hpp"
#include "operators.hpp"
#include "subspaces.hpp"
#include <fmt/format.h>
namespace NRG {
// +++ Construct an offdiagonal part of the Hamiltonian. +++
// We test if the block (i,j) exists at all. If not, factor is not evaluated. This prevents divisions by zero.
#define offdiag_function(step, i, j, ch, fnr, factor, h, qq, In, opch) \
{ if (qq.offdiag_contributes(i, j)) this->offdiag_function_impl(step, i, j, ch, fnr, factor, h, qq, In, opch); }
// i,j - indexes of the out-of-diagonal matrix block that we are constructing
// ch,fnr - channel and extra index to locate the correct block of the <||f||> matrix (irreducible matrix elements)
// h - matrix being built
// qq - matrix dimensions data (to determine the position in the matrix)
// In - In[i] and In[j] are the invariant subspaces of required <||f||> matrix elements
// factor - the coefficient which multiplies the irreducible matrix elements. This coefficient takes into account
// the multiplicities.
// NOTE: the offdiagonal part depends on xi(N), while zeta(N) affect the diagonal part of the Hamiltonian matrix!
template<scalar S>
void Symmetry<S>::offdiag_function_impl(const Step &step, const size_t i, const size_t j,
const size_t ch, // channel number
const size_t fnr, // extra index for <||f||>, usually 0
const t_coef factor, // may be complex (in principle)
Matrix &h, const SubspaceDimensions &qq, const InvarVec &In, const Opch<S> &opch) const
{
my_assert(1 <= i && i <= qq.combs() && 1 <= j && j <= qq.combs());
if (!my_isfinite(factor))
throw std::runtime_error(fmt::format("offdiag_function(): factor not finite {} {} {} {}", i, j, ch, fnr));
if (const auto f = opch[ch][fnr].find({In[i-1], In[j-1]}); f != opch[ch][fnr].cend()) { // < In[i] r | f^\dag | In[j] r' >
const Matrix & mat = f->second;
my_assert(qq.rmax(i-1) == size1(mat) && qq.rmax(j-1) == size2(mat));
const auto factor_scaled = factor / step.scale();
// We are building the upper triangular part of the Hermitian Hamiltonian. Thus usually i < j. If not, we must
// conjugate transpose the contribution!
const bool conj_transpose = i > j;
if (conj_transpose) {
auto hsub = submatrix(h, qq.part_mma(j), qq.part_mma(i));
hsub += conj_me(factor_scaled) * herm(mat);
} else {
auto hsub = submatrix(h, qq.part_mma(i), qq.part_mma(j));
hsub += factor_scaled * mat;
}
} else
throw std::runtime_error(fmt::format("offdiag_function(): matrix not found {} {} {} {}", i, j, ch, fnr));
}
// +++ Shift the diagonal matrix elements by the number of electrons multiplied by the required constant(s) zeta. +++
//
// 'number' is the number of electrons for channel 'ch' in invariant subspaces indexed by 'i'. Note that 'number' is
// a floating point number: this is required, for example, in the LR symmetric basis sets.
//
// NOTE: for problems where a given invariant subspace does not correspond to a fixed number of added electrons, a
// generalized routine should be used.
template<scalar S>
void Symmetry<S>::diag_function_impl(const Step &step, const size_t i, const double number, const t_coef sc_zeta,
Matrix &h, const SubspaceDimensions &qq, const double f) const
{
my_assert(1 <= i && i <= qq.combs());
// For convenience we subtract the average site occupancy. XXX: how does this affect the total energy??
const auto avgoccup = (double)P.spin / 2; // multiplicity divided by 2
// Energy shift of the diagonal matrix elements in the NRG Hamiltonian.
for (const auto j: qq.view_mma(i)) h(j, j) += sc_zeta * (number - f*avgoccup) / step.scale();
}
template<scalar S>
void Symmetry<S>::diag_function(const Step &step, const size_t i, const double number, const t_coef sc_zeta,
Matrix &h, const SubspaceDimensions &qq) const
{
diag_function_impl(step, i, number, sc_zeta, h, qq, 1);
}
template<scalar S>
void Symmetry<S>::diag_function_half(const Step &step, const size_t i, const double number, const t_coef sc_zeta,
Matrix &h, const SubspaceDimensions &qq) const
{
diag_function_impl(step, i, number, sc_zeta, h, qq, 0.5);
}
// +++ Shift the offdiagonal matrix elements by factor. +++
template<scalar S>
void Symmetry<S>::diag_offdiag_function(const Step &step, const size_t i, const size_t j, const t_coef factor,
Matrix &h, const SubspaceDimensions &qq) const
{
my_assert(1 <= i && i <= qq.combs() && 1 <= j && j <= qq.combs());
if (i > j) return; // only upper triangular part
const auto begin1 = qq.offset(i-1);
const auto size1 = qq.rmax(i-1);
const auto begin2 = qq.offset(j-1);
const auto size2 = qq.rmax(j-1);
const auto contributes = (size1 > 0) && (size2 > 0);
if (!contributes) return;
my_assert(size1 == size2);
const t_coef factor_scaled = factor / step.scale();
for (const auto l: range0(size1)) h(begin1 + l, begin2 + l) += factor_scaled;
}
} // namespace NRG
#endif // _matrix_cc_
| 5,496
|
C++
|
.h
| 100
| 49.2
| 132
| 0.647092
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,657
|
stats.hpp
|
rokzitko_nrgljubljana/c++/stats.hpp
|
#ifndef _stats_hpp_
#define _stats_hpp_
#include <string>
#include <map>
#include <vector>
#include "constants.hpp"
#include "traits.hpp"
#include "outfield.hpp"
#include "mp.hpp"
#include "step.hpp"
namespace NRG {
// Structure for storing various statistical quantities calculated during the iteration
template<scalar S, typename t_eigen = eigen_traits<S>, typename t_expv = expv_traits<S>>
class Stats {
private:
const Params &P;
public:
t_eigen Egs{};
// ** Thermodynamic quantities
double Z{};
double Zft{}; // grand-canonical partition function (at shell n)
double Zgt{}; // grand-canonical partition function for computing G(T)
double Zchit{}; // grand-canonical partition function for computing chi(T)
TD td;
// ** Expectation values
std::map<std::string, t_expv> expv; // expectation values of custom operators
std::map<std::string, t_expv> fdmexpv; // Expectation values computed using the FDM algorithm
// ** Energies
// "total_energy" is the total energy of the ground state at the current iteration. This is the sum of all the
// zero state energies (eigenvalue shifts converted to absolute energies) for all the iteration steps so far.
t_eigen total_energy{};
// GS_energy is the energy of the ground states in absolute units. It is equal to the value of the variable
// "total_energy" at the end of the iteration.
t_eigen GS_energy{};
std::vector<double> rel_Egs; // Values of 'Egs' for all NRG steps.
std::vector<double> abs_Egs; // Values of 'Egs' (multiplied by the scale, i.e. in absolute scale) for all NRG steps.
std::vector<double> energy_offsets; // Values of "total_energy" for all NRG steps.
// ** Containers related to the FDM-NRG approach
// Consult A. Weichselbaum, J. von Delft, PRL 99, 076402 (2007).
vmpf ZnDG; // Z_n^D=\sum_s^D exp(-beta E^n_s), sum over **discarded** states at shell n
vmpf ZnDN; // Z'_n^D=Z_n^D exp(beta E^n_0)=\sum_s^D exp[-beta(E^n_s-E^n_0)]
std::vector<double> ZnDNd; //
std::vector<double> wn; // Weights w_n. They sum to 1.
std::vector<double> wnfactor; // wn/ZnDG
double ZZG{}; // grand-canonical partition function with energies referred to the ground state energy
double Z_fdm{}; // grand-canonical partition function (full-shell) at temperature T
double F_fdm{}; // free-energy at temperature T
double E_fdm{}; // energy at temperature T
double C_fdm{}; // heat capacity at temperature T
double S_fdm{}; // entropy at temperature T
TD_FDM td_fdm;
explicit Stats(const Params &_P, const std::vector<std::string> &td_fields, const double GS_energy_0,
const std::string &filename_td = "td"s, const std::string &filename_tdfdm = "tdfdm"s) :
P(_P), td(P, filename_td), total_energy(GS_energy_0), rel_Egs(MAX_NDX), abs_Egs(MAX_NDX), energy_offsets(MAX_NDX),
ZnDG(MAX_NDX), ZnDN(MAX_NDX), ZnDNd(MAX_NDX), wn(MAX_NDX), wnfactor(MAX_NDX), td_fdm(P, filename_tdfdm) {
td.allfields.add(td_fields, 1);
}
void update(const Step &step) {
total_energy += Egs * step.scale(); // stats.Egs has already been initialized
std::cout << "Total energy=" << HIGHPREC(total_energy) << " Egs=" << HIGHPREC(Egs) << std::endl;
rel_Egs[step.ndx()] = Egs;
abs_Egs[step.ndx()] = Egs * step.scale();
energy_offsets[step.ndx()] = total_energy;
}
// Called after first run
void h5save_nrg(H5Easy::File &fd) const {
h5_dump_scalar(fd, "stats/GS_energy", GS_energy);
for (Step step(P); !step.end(); step.next()) {
const auto ndx = step.ndx(); // 0-based!
const auto prefix = "stats/" + std::to_string(ndx+1); // 1-based!
h5_dump_scalar(fd, prefix + "/energyscale", step.energyscale());
h5_dump_scalar(fd, prefix + "/scale", step.scale());
h5_dump_scalar(fd, prefix + "/Teff", step.Teff());
h5_dump_scalar(fd, prefix + "/rel_Egs", rel_Egs[ndx]);
h5_dump_scalar(fd, prefix + "/abs_Egs", rel_Egs[ndx]);
h5_dump_scalar(fd, prefix + "/energy_offset", energy_offsets[ndx]);
}
for (const auto &[name, value]: expv)
h5_dump_scalar(fd, "expv/" + name, value);
h5_dump_scalar(fd, "total_energy", total_energy);
}
// Called after second run
void h5save_dmnrg(H5Easy::File &fd) const {
if (P.fdm) {
h5_dump_scalar(fd, "fdm/Z", Z_fdm);
h5_dump_scalar(fd, "fdm/F", F_fdm);
h5_dump_scalar(fd, "fdm/E", E_fdm);
h5_dump_scalar(fd, "fdm/C", C_fdm);
h5_dump_scalar(fd, "fdm/S", S_fdm);
if (P.fdmexpv)
for (const auto &[name, value]: fdmexpv)
h5_dump_scalar(fd, "fdm/expv/" + name, value);
}
}
};
} // namespace
#endif
| 4,850
|
C++
|
.h
| 97
| 45.185567
| 126
| 0.635021
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,658
|
bins.hpp
|
rokzitko_nrgljubljana/c++/bins.hpp
|
// bins.h - Binning of the spectral data
// Copyright (C) 2009-2020 Rok Zitko
#ifndef _bins_hpp_
#define _bins_hpp_
#include <cmath>
#include <range/v3/all.hpp>
#include "portabil.hpp"
#include "traits.hpp"
#include "spectral.hpp"
#include "params.hpp"
#include "numerics.hpp"
namespace NRG {
// Binned spectral peaks. P.bins defines the number of bins per energy decade. The lowest and highest energies are
// defined by the zero-th and last NRG energy scale.
// bins[i].first is the energy of the representative point (it is NOT an interval boundary!). Thus bins[i].second
// represents the spectral weight at energy bins[i].first. This implies that when the spectral weight is collected
// [see function add()], the weight of a delta peak with energy between two consecutive representative points is
// divided between the two points proportionally with respect to the energies of the points. This also implies that
// during broadening, we may consider "bins" as delta peaks, rather than as interval representations (true bins). In
// other words, what we are doing here is coarse graining rather than binning!
template<scalar S>
class Bins {
private:
using t_weight = weight_traits<S>;
double emin{}, emax{};
double log10emin{}, log10emax{}; // base-10 log of the limits
void setlimits();
inline void add_std(const double energy, const t_weight weight);
inline void add_acc(const double energy, const t_weight weight);
void loggrid_std(); // standard NRG logarithmic mesh for spec. funcions
void loggrid_acc(); // log grid with shifted accumulation point
void loggrid();
const Params &P;
// These control the energy range of the bins. This is the shift in the (10-base) exponent of the top-most and
// bottom-most bins.
inline static const double max_bin_shift = 2.0;
inline static const double min_bin_shift = 2.0;
inline static const double base = 10;
inline static const double discarded_weight_warn_limit = 1e-8;
public:
Spikes<S> bins; // Note: Spikes is vector of (t_eigen,t_weight) pairs // XXX: make private
operator const Spikes<S> &() const { return bins; }
operator Spikes<S> &() { return bins; }
// auto & get() { return bins; }
explicit Bins(const Params &P) : P(P) { loggrid(); } // default: logarithmic grid
inline void add(const double energy, const t_weight weight);
void merge(const Bins<S> &b);
void trim();
auto total_weight() const { return bins.sum_weights(); }
};
template<scalar S>
void Bins<S>::setlimits() {
// NOTE: this will silently discard spectral peaks far outside the conduction band!!
emax = (P.emax > 0 ? P.emax : P.SCALE(0) * pow(base, max_bin_shift));
emin = (P.emin > 0 ? P.emin : P.last_step_scale() / pow(base, min_bin_shift));
// Trick: use ceil/floor to obtain uniform binning grids for different values of the twist parameter z!
log10emin = floor(log10(emin));
log10emax = ceil(log10(emax));
}
template<scalar S>
void Bins<S>::loggrid() {
my_assert(P.bins > 0);
setlimits();
if (P.accumulation > 0.0)
loggrid_acc();
else
loggrid_std();
}
template<scalar S>
void Bins<S>::loggrid_acc() {
const double a = P.accumulation;
my_assert(a > 0.0);
bins.resize(0);
for (auto e = emin; e <= emax; e *= pow(base, 1.0 / P.bins))
bins.emplace_back((emax - a) / emax * e + a, 0);
if (P.linstep > 0)
for (auto e = a; e > 0.0; e -= P.linstep) bins.emplace_back(e, 0);
bins.emplace_back(DBL_MIN, 0); // add zero point
ranges::sort(bins, sortfirst());
my_assert(bins.size() >= 2);
}
template<scalar S>
void Bins<S>::loggrid_std() {
const auto nrbins = (size_t)((log10emax - log10emin) * P.bins + 1.0);
bins.resize(nrbins); // Note: Spikes is a vector type!
for (const auto i : range0(nrbins)) bins[i] = { pow(base, log10emin + (double)i / P.bins), 0 };
}
// Unbiased assignment of the spectral weight to bins.
template<scalar S>
inline void Bins<S>::add(const double energy, const t_weight weight) {
if (abs(weight) < P.discard_immediately * energy) return;
if (P.accumulation > 0.0)
add_acc(energy, weight);
else
add_std(energy, weight);
}
template<scalar S>
inline void Bins<S>::add_std(const double energy, const t_weight weight) {
// Important: if 'energy' is lower than the lower limit of the first interval, the weight is assigned to the first
// bin. This is especially relevant for collecting the omega=0 data in bosonic correlators. (rz, 25 Oct 2012)
if (energy < emin) { // handle this special case separately (for reasons of efficiency)
bins[0].second += weight;
return;
}
const double log10e = log10(energy);
const double x = (log10e - log10emin) * P.bins;
const double int_part = floor(x);
if (int_part < 0) {
bins.front().second += weight;
} else if (const auto index = size_t(int_part) ; index >= bins.size() - 1) {
bins.back().second += weight;
} else {
const double rem = x - int_part;
bins[index].second += (1.0 - rem) * weight;
bins[index + 1].second += rem * weight;
}
}
template<scalar S>
inline void Bins<S>::add_acc(const double energy, const t_weight weight) {
for (const auto i: range0(bins.size()-1)) {
auto &[e1, w1] = bins[i]; // non-const
auto &[e2, w2] = bins[i+1]; // non-const
my_assert(e1 < e2);
if (e1 < energy && energy < e2) {
const auto dx = e2 - e1;
const auto reldist = (energy - e1) / dx;
w1 += (1.0 - reldist) * weight;
w2 += reldist * weight;
return;
}
}
// Note: if no suitable interval is found, the weight is discarded!
}
// Merge two bins. They need to agree in the representative energies
// (first element of the pairs).
template<scalar S>
void Bins<S>::merge(const Bins<S> &b) {
my_assert(bins.size() == b.bins.size());
for (const auto i: range0(bins.size())) {
auto &[e1, w1] = bins[i];
const auto &[e2, w2] = b.bins[i];
my_assert(e1 == e2);
w1 += w2;
}
}
// Only keep bins which are "heavy" enough.
template<scalar S>
void Bins<S>::trim() {
Spikes<S> orig{};
orig.swap(bins);
bucket discarded_weight_abs;
// nr-1, because we need to compute the energy interval size 'ewidth'
for (const auto i: range0(orig.size()-1)) {
const auto [e, w] = orig[i];
const auto e_next = orig[i+1].first;
my_assert(e_next > e); // increasing!
const auto e_width = e_next - e;
if (abs(w) >= P.discard_trim * e_width)
bins.push_back(orig[i]);
else
discarded_weight_abs += abs(w);
}
// Always keep the last one.. This ensures that we keep information about the energy range on which the
// calculations has been performed.
bins.push_back(orig.back());
if (discarded_weight_abs > discarded_weight_warn_limit) std::cout << "WARNING: we are probably discarding too much weight!" << std::endl;
}
template<scalar S, typename t_weight = weight_traits<S>>
class Temp : public Spikes<S> {
private:
const Params &P;
public:
explicit Temp(const Params &P) : P(P) {}
void add_value(const double energy, const t_weight &weight) {
for (auto & [e, w] : *this) {
if (e == energy) {
w += weight;
return;
}
}
// or else
this->emplace_back(energy, weight);
}
};
} // namespace
#endif // _bins_hpp_
| 7,265
|
C++
|
.h
| 186
| 35.806452
| 139
| 0.674175
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,659
|
measurements.hpp
|
rokzitko_nrgljubljana/c++/measurements.hpp
|
#ifndef _measurements_hpp_
#define _measurements_hpp_
#include "step.hpp"
#include "eigen.hpp"
#include "operators.hpp"
#include "symmetry.hpp"
#include "traits.hpp"
#include "output.hpp"
#include "store.hpp"
#include "time_mem.hpp"
#include "oprecalc.hpp"
namespace NRG {
// note: t_expv = t_matel, thus the return type is OK
template<scalar S, typename MF, typename t_matel = matel_traits<S>>
auto calc_trace_singlet(const DiagInfo<S> &diag, const MatrixElements<S> &m, MF mult, const double factor) {
return ranges::accumulate(diag, S{}, {}, [&m, &mult, factor](const auto &x){
const auto [I, eig] = x; return mult(I) * trace_exp(eig.value_corr_msr(), m.at({I,I}), factor); });
}
// Measure thermodynamic expectation values of singlet operators
template<scalar S, typename MF>
void measure_singlet(const double factor, Stats<S> &stats, const Operators<S> &a, MF mult, const DiagInfo<S> &diag, const Params &P) {
const auto Z = ranges::accumulate(diag, 0.0, {}, [mult, factor](const auto &d) { const auto &[I, eig] = d;
return mult(I) * sum_of_exp(eig.value_corr_msr(), factor); });
nrglog('Z', "Z_expv=" << Z);
for (const auto &[name, m] : a.ops) stats.expv[name] = calc_trace_singlet(diag, m, mult, factor) / Z;
for (const auto &[name, m] : a.opsg) stats.expv[name] = calc_trace_singlet(diag, m, mult, factor) / Z;
}
template<scalar S, typename MF, typename t_matel = matel_traits<S>>
auto calc_trace_fdm_kept(const size_t ndx, const MatrixElements<S> &n, const DensMatElements<S> &rhoFDM,
const Store<S> &store_all, MF mult) {
return ranges::accumulate(rhoFDM, t_matel{}, {}, [&n, &s = store_all[ndx], mult](const auto &x) { const auto [I, rhoI] = x;
return mult(I) * trace_contract(rhoI, n.at({I,I}), s.at(I).kept()); }); // over kept states ONLY
}
template<scalar S, typename MF>
void measure_singlet_fdm(const size_t ndx, Stats<S> &stats, const Operators<S> &a, MF mult,
const DensMatElements<S> &rhoFDM, const Store<S> &store_all) {
for (const auto &[name, m] : a.ops) stats.fdmexpv[name] = calc_trace_fdm_kept(ndx, m, rhoFDM, store_all, mult);
for (const auto &[name, m] : a.opsg) stats.fdmexpv[name] = calc_trace_fdm_kept(ndx, m, rhoFDM, store_all, mult);
}
// Calculate grand canonical partition function at current NRG energy shell. This is not the same as the true
// partition function of the full problem! Instead this is the Z_N that is used to initialize the density matrix,
// i.e. rho = 1/Z_N \sum_{l} exp{-beta E_l} |l;N> <l;N|. grand_canonical_Z() is also used to calculate stats.Zft,
// that is used to compute the spectral function with the conventional approach, as well as stats.Zgt for G(T)
// calculations, stats.Zchit for chi(T) calculations.
template<scalar S, typename MF>
auto grand_canonical_Z(const double factor, const DiagInfo<S> &diag, MF mult) {
return ranges::accumulate(diag, 0.0, {}, [factor,mult](const auto &x) { const auto &[I, eig] = x;
return mult(I) * sum_of_exp(eig.value_corr_kept(), factor); }); // over kept states ONLY
}
// Calculate partial statistical sums, ZnD*, and the grand canonical Z (stats.ZZG), computed with respect to absolute
// energies. calc_ZnD() must be called before the second NRG run.
template<scalar S>
void calc_ZnD(const Store<S> &store, Stats<S> &stats, const Symmetry<S> *Sym, const Params &P) {
const auto T = P.T;
mpf_set_default_prec(400); // this is the number of bits, not decimal digits!
for (const auto N : store.Nall()) {
my_mpf ZnDG, ZnDN; // arbitrary-precision accumulators to avoid precision loss
mpf_set_d(ZnDG, 0.0);
mpf_set_d(ZnDN, 0.0);
for (const auto &[I, ds] : store[N])
for (const auto i : ds.all()) {
my_mpf g, n;
mpf_set_d(g, Sym->mult(I) * exp(-ds.eig.values.abs_G(i)/T)); // abs_G >= 0.0
mpf_set_d(n, Sym->mult(I) * exp(-ds.eig.values.abs_zero(i)/T)); // abs_zero >= 0.0
mpf_add(ZnDG, ZnDG, g);
mpf_add(ZnDN, ZnDN, n);
}
mpf_set(stats.ZnDG[N], ZnDG);
mpf_set(stats.ZnDN[N], ZnDN);
stats.ZnDNd[N] = mpf_get_d(stats.ZnDN[N]);
}
// Note: for ZBW, Nlen=Nmax+1. For Ninit=Nmax=0, index 0 will thus be included here.
my_mpf ZZG;
mpf_set_d(ZZG, 0.0);
for (const auto N : store.Nall()) {
my_mpf a;
mpf_set(a, stats.ZnDG[N]);
my_mpf b;
mpf_set_d(b, Sym->nr_combs());
mpf_pow_ui(b, b, store.Nend - N - 1);
my_mpf c;
mpf_mul(c, a, b);
mpf_add(ZZG, ZZG, c);
}
stats.ZZG = mpf_get_d(ZZG);
nrglog('Z', "ZZG=" << HIGHPREC(stats.ZZG));
for (const auto N : store.Nall()) {
const double w = std::pow(Sym->nr_combs(), store.Nend - N - 1) / stats.ZZG; // ZZZ
stats.wnfactor[N] = w; // These ratios enter the terms for the spectral function.
stats.wn[N] = w * mpf_get_d(stats.ZnDG[N]); // This is w_n defined after Eq. (8) in the WvD paper.
}
const auto sumwn = ranges::accumulate(stats.wn, 0.0);
nrglog('Z', "sumwn=" << sumwn << " sumwn-1=" << sumwn - 1.0);
my_assert(num_equal(sumwn, 1.0)); // Check the sum-rule.
}
template<scalar S>
void report_ZnD(Stats<S> &stats, const Params &P) {
for (const auto N : P.Nall())
std::cout << "ZG[" << N << "]=" << HIGHPREC(mpf_get_d(stats.ZnDG[N])) << std::endl;
for (const auto N : P.Nall())
std::cout << "ZN[" << N << "]=" << HIGHPREC(mpf_get_d(stats.ZnDN[N])) << std::endl;
for (const auto N : P.Nall())
std::cout << "w[" << N << "]=" << HIGHPREC(stats.wn[N]) << std::endl;
for (const auto N : P.Nall())
std::cout << "wfactor[" << N << "]=" << HIGHPREC(stats.wnfactor[N]) << std::endl;
}
// TO DO: use Boost.Multiprecision instead of low-level GMP calls
// https://www.boost.org/doc/libs/1_72_0/libs/multiprecision/doc/html/index.html
template<scalar S>
void fdm_thermodynamics(const Store<S> &store, Stats<S> &stats, const Symmetry<S> *Sym, const double T)
{
stats.Z_fdm = stats.ZZG*exp(-stats.GS_energy/T); // this is the true partition function
stats.F_fdm = -log(stats.ZZG)*T+stats.GS_energy; // F = -k_B*T*log(Z)
// We use multiple precision arithmetics to ensure sufficient accuracy in the calculation of
// the variance of energy and thus the heat capacity.
my_mpf E, E2;
mpf_set_d(E, 0.0);
mpf_set_d(E2, 0.0);
for (const auto N : store.Nall())
if (stats.wn[N] > 1e-16)
for (const auto &[I, ds] : store[N])
for (const auto i : ds.all()) {
my_mpf weight;
mpf_set_d(weight, stats.wn[N] * Sym->mult(I) * exp(-ds.eig.values.abs_zero(i)/T));
mpf_div(weight, weight, stats.ZnDN[N]);
my_mpf e;
mpf_set_d(e, ds.eig.values.abs_T(i));
my_mpf e2;
mpf_mul(e2, e, e);
mpf_mul(e, e, weight);
mpf_mul(e2, e2, weight);
mpf_add(E, E, e);
mpf_add(E2, E2, e2);
}
stats.E_fdm = mpf_get_d(E);
my_mpf sqrE;
mpf_mul(sqrE, E, E);
my_mpf varE;
mpf_sub(varE, E2, sqrE);
stats.C_fdm = mpf_get_d(varE)/pow(T,2);
stats.S_fdm = (stats.E_fdm-stats.F_fdm)/T;
std::cout << std::endl;
std::cout << "Z_fdm=" << HIGHPREC(stats.Z_fdm) << std::endl;
std::cout << "F_fdm=" << HIGHPREC(stats.F_fdm) << std::endl;
std::cout << "E_fdm=" << HIGHPREC(stats.E_fdm) << std::endl;
std::cout << "C_fdm=" << HIGHPREC(stats.C_fdm) << std::endl;
std::cout << "S_fdm=" << HIGHPREC(stats.S_fdm) << std::endl;
std::cout << std::endl;
stats.td_fdm.set("T", T);
stats.td_fdm.set("F_fdm", stats.F_fdm);
stats.td_fdm.set("E_fdm", stats.E_fdm);
stats.td_fdm.set("C_fdm", stats.C_fdm);
stats.td_fdm.set("S_fdm", stats.S_fdm);
stats.td_fdm.save_values();
}
// We calculate thermodynamic quantities before truncation to make better use of the available states. Here we
// compute quantities which are defined for all symmetry types. Other calculations are performed by calculate_TD
// member functions defined in symmetry.h
template<scalar S>
void calculate_TD(const Step &step, const DiagInfo<S> &diag, Stats<S> &stats,
const Symmetry<S> *Sym, const Params &P, const double additional_factor = 1.0) {
// Rescale factor for energies. The energies are expressed in units of omega_N, thus we need to appropriately
// rescale them to calculate the Boltzmann weights at the temperature scale Teff (Teff=scale/betabar).
const auto rescale_factor = step.TD_factor() * additional_factor;
const auto Z = diag.trace([]([[maybe_unused]] double x) { return 1; }, rescale_factor, Sym->multfnc()); // partition function
const auto E = diag.trace([](double x) { return x; }, rescale_factor, Sym->multfnc()); // Tr[beta H]
const auto E2 = diag.trace([](double x) { return pow(x,2); }, rescale_factor, Sym->multfnc()); // Tr[(beta H)^2]
stats.Z = Z;
nrglog('Z', "Z_td=" << stats.Z);
stats.td.set("T", step.Teff());
stats.td.set("<E>", E/Z); // beta <H>
stats.td.set("<E^2>", E2/Z); // beta^2 <H^2>
stats.td.set("C", E2/Z - pow(E/Z,2)); // C/k_B=beta^2(<H^2>-<H>^2)
stats.td.set("F", -log(Z)); // F/(k_B T)=-ln(Z)
stats.td.set("S", E/Z+log(Z)); // S/k_B=beta<H>+ln(Z)
Sym->calculate_TD(step, diag, stats, rescale_factor); // symmetry-specific calculation routine
stats.td.save_values();
}
template<scalar S, typename MF>
void calc_Z(const Step &step, Stats<S> &stats, const DiagInfo<S> &diag, MF mult, const Params &P) {
stats.Zft = grand_canonical_Z(step.scT(), diag, mult);
nrglog('Z', "Z_ft=" << stats.Zft);
if (std::string(P.specgt) != "" || std::string(P.speci1t) != "" || std::string(P.speci2t) != "")
stats.Zgt = grand_canonical_Z(1.0/P.gtp, diag, mult); // exp(-x*gtp)
if (std::string(P.specchit) != "")
stats.Zchit = grand_canonical_Z(1.0/P.chitp, diag, mult); // exp(-x*chitp)
}
template<scalar S>
void calculate_spectral_and_expv_impl(const Step &step, Stats<S> &stats, Output<S> &output, Oprecalc<S> &oprecalc,
const DiagInfo<S> &diag, // projected!
const Operators<S> &operators,
const Store<S> &store_all, MemTime &mt,
const Symmetry<S> *Sym, const Params &P) {
// Load the density matrices
DensMatElements<S> rho, rhoFDM;
if (step.dmnrg()) {
if (P.need_rho()) {
rho.load(step.ndx(), P, fn_rho, P.removefiles);
check_trace_rho(rho, Sym->multfnc()); // Check if Tr[rho]=1, i.e. the normalization
}
if (P.need_rhoFDM())
rhoFDM.load(step.ndx(), P, fn_rhoFDM, P.removefiles);
}
// Calculate all spectral functions
calc_Z(step, stats, diag, Sym->multfnc(), P); // required for FT and CFS approaches
oprecalc.sl.calc(step, diag, rho, rhoFDM, stats, mt, Sym, P);
// Calculate all expectation values
if (step.nrg()) {
const auto section_timing = mt.time_it("singlet");
measure_singlet(step.TD_factor(), stats, operators, Sym->multfnc(), diag, P);
output.custom->field_values(step.Teff());
operators.dump_diagonal(P.dumpdiagonal);
}
if (step.dmnrg() && P.fdmexpv && step.N() == P.fdmexpvn) {
const auto section_timing = mt.time_it("singlet fdm");
measure_singlet_fdm(step.N(), stats, operators, Sym->multfnc(), rhoFDM, store_all); // store_all required here!
output.customfdm->field_values(P.T);
}
}
template<scalar S>
void calculate_spectral_and_expv(const Step &step, Stats<S> &stats, Output<S> &output, Oprecalc<S> &oprecalc,
const DiagInfo<S> &diag_in, const Operators<S> &operators,
const Store<S> &store_all,
MemTime &mt, const Symmetry<S> *Sym, const Params &P) {
if (P.project == ""s) {
calculate_spectral_and_expv_impl(step, stats, output, oprecalc, diag_in, operators, store_all, mt, Sym, P);
} else {
auto diag = Sym->project(diag_in, P.project);
calculate_spectral_and_expv_impl(step, stats, output, oprecalc, diag, operators, store_all, mt, Sym, P);
}
}
// Perform calculations of physical quantities. Called prior to NRG iteration (if calc0=true) and after each NRG
// step.
template<scalar S>
void perform_basic_measurements_impl(const Step &step,
const DiagInfo<S> &diag, // projected!
const Symmetry<S> *Sym,
Stats<S> &stats,
Output<S> &output,
const Params &P) {
output.dump_energies(step.ndx(), diag); // "energies.nrg"
output.annotated.dump(step, diag, stats, Sym->multfnc()); // "annotated.dat"
calculate_TD(step, diag, stats, Sym, P); // "td"
}
template<scalar S>
void perform_basic_measurements(const Step &step, const DiagInfo<S> &diag_in, const Symmetry<S> *Sym,
Stats<S> &stats, Output<S> &output, const Params &P) {
if (P.project == ""s) {
perform_basic_measurements_impl(step, diag_in, Sym, stats, output, P);
} else {
auto diag = Sym->project(diag_in, P.project);
perform_basic_measurements_impl(step, diag, Sym, stats, output, P);
}
}
} // namespace
#endif
| 13,275
|
C++
|
.h
| 256
| 46.183594
| 134
| 0.618557
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,660
|
splitting.hpp
|
rokzitko_nrgljubljana/c++/splitting.hpp
|
// Code for correcting floating-point roundoff errors
// Rok Zitko, rok.zitko@ijs.si
#ifndef _splitting_hpp_
#define _splitting_hpp_
#include <iostream>
#include <unordered_map>
#include "portabil.hpp"
#include "traits.hpp"
#include "eigen.hpp"
namespace NRG {
template<typename T>
inline void cluster_show(const T &i0, const T &i1) {
std::cout << "[";
for (auto j = i0; j != i1; ++j) { std::cout << HIGHPREC(*j) << " "; }
std::cout << "]" << std::endl;
}
// Returns true if not all the states have the same energy.
template<typename T>
inline bool cluster_splitting(const T &i0, const T &i1) {
my_assert(i0 != i1); // non-empty set
// We need to compare all distinct pairs.
for (auto i = i0; i != i1; ++i)
for (auto j = i + 1; j != i1; ++j)
if (*i != *j) return true;
return false;
}
template<scalar S, typename t_eigen = eigen_traits<S>>
class Clusters {
public:
std::unordered_map<t_eigen, t_eigen> cluster_mapping;
// Fix splittings of eigenvalues.
void fix_it(DiagInfo<S> &diag) {
for(auto &[I, eig]: diag) {
auto v = eig.values.all_rel_zero() | ranges::to_vector;
for (auto &r : v)
if (auto m = cluster_mapping.find(r); m != cluster_mapping.cend())
r = m->second;
eig.values.set_corr(std::move(v));
}
}
// Find clusters of values which differ by at most 'epsilon'
Clusters(DiagInfo<S> &diag, const double epsilon, bool fix = true) {
const auto energies = diag.sorted_energies_rel_zero();
my_assert(energies.size());
auto e0 = energies.front(); // energy of the lower boundary of the cluster, [e0:e1]
auto i0 = energies.cbegin(); // iterator to the lower boundary of the cluster, [i0:i1]
int size = 1; // number of states in the current cluster
for (auto i = energies.begin(); i != energies.end(); ++i) {
if ((*i - e0) < epsilon) { // in the cluster
size++;
} else { // end of cluster detected
auto i1 = i;
if (size > 1) { // is this a real cluster?
if (cluster_splitting(i0, i1)) { // are the states actually split?
auto replace_with = *i0; // use the lowest eigenvalue of the cluster
for (auto j = (i0 + 1); j != i1; ++j) // skip 1st
if (*j != *i0) cluster_mapping.insert({*j, replace_with});
}
}
e0 = *i;
i0 = i;
size = 1;
}
}
if (fix) fix_it(diag);
}
};
} // namespace
#endif
| 2,514
|
C++
|
.h
| 69
| 31.15942
| 91
| 0.588428
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,661
|
symmetry.hpp
|
rokzitko_nrgljubljana/c++/symmetry.hpp
|
// symmetry.cc - Classes representing various symmetry types
// Copyright (C) 2009-2020 Rok Zitko
#ifndef _symmetry_hpp_
#define _symmetry_hpp_
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <limits>
#include "operators.hpp"
#include "params.hpp"
#include "traits.hpp"
#include "operators.hpp"
#include "invar.hpp"
#include "step.hpp"
#include "eigen.hpp"
#include "subspaces.hpp"
#include "stats.hpp"
#include "coef.hpp"
namespace NRG {
using cmpl = std::complex<double>;
// Check if the triangle inequality is satisfied (i.e. if Clebsch-Gordan coefficient can be different from zero).
// This is important, for example, for triplet operators, which are zero when evaluated between two singlet states.
// Arguments ss1, ss2, ss3 are spin multiplicities. Returns true if the inequality is satisfied, false otherwise.
inline auto su2_triangle_inequality(const int ss1, const int ss2, const int ss3) {
return (abs(ss1-ss2) <= ss3-1) && (abs(ss2-ss3) <= ss1-1) && (abs(ss3-ss1) <= ss2-1);
}
inline auto u1_equality(const int q1, const int q2, const int q3) { return q1 == q2 + q3; } // Equality for U(1) symmetry
inline auto z2_equality(const int p1, const int p2, const int p3) { return p1 == p2 * p3; }
inline auto c3_equality(const int p1, const int p2, const int p3) { return p1 == (p2+p3) % 3; } // C_3 quantum number: Equality modulo 3
template<scalar S>
struct Recalc_f {
size_t i1; // subspace indexes
size_t ip;
coef_traits<S> factor;
};
// Structure which holds subspace information and factor for each of nonzero irreducible matrix elements. cf.
// Hofstetter PhD p. 120. <Q+1 S+-1/2 .. i1 ||f^\dag|| Q S .. ip>_N = factor < IN1 .. ||f^\dag|| INp ..>_{N_1}
template<scalar S>
struct Recalc {
size_t i1{}; // combination of states
size_t ip{};
Invar IN1; // subspace in N-1 stage
Invar INp;
coef_traits<S> factor{}; // additional multiplicative factor
};
template<scalar S>
class Symmetry {
protected:
const Params &P;
const std::vector<std::string> td_fields;
// In and QN contain information about how the invariant subspaces at consecutive iteration steps are combined. In
// is the array of quantum number DIFFERENCES used in the construction of the basis. QN is the array of the
// conserved quantum numbers corresponding to the states being added. For example, in case of SU(2) symmetry, In
// will include S_z, while QN will include S. In other words, QN involves those quantum numbers that we need to
// retain in the calculation, while In involves those quantum numbers that "drop out" of the problem due to the
// symmetry.
std::vector<Invar> In, QN;
const Invar InvarSinglet; // QNs for singlet operator
const Invar Invar_f; // QNs for f operator
public:
virtual void load() = 0; // load In, QN
void erase_first() { // drop the first element in In, QN to convert to 0-based vectors; call after load()
In.erase(In.begin());
QN.erase(QN.begin());
}
template<typename T>
Symmetry(const Params &P_, const T td_fields_, const Invar & InvarSinglet = {}, const Invar & Invar_f = {}) :
P(P_), td_fields(td_fields_.begin(), td_fields_.end()), In(P.combs+1), QN(P.combs+1), InvarSinglet(InvarSinglet), Invar_f(Invar_f) {}
Symmetry(const Symmetry &) = delete;
Symmetry(Symmetry &&) = delete;
Symmetry &operator=(const Symmetry &) = delete;
Symmetry &operator=(Symmetry &&) = delete;
virtual ~Symmetry() {}
auto input_subspaces() const { return In; }
auto QN_subspace(const size_t i) const { my_assert(i < P.combs); return QN[i]; }
auto ancestor(const Invar &I, const size_t i) const {
my_assert(i < P.combs);
const auto input = input_subspaces();
Invar anc = I;
anc.combine(input[i]);
return anc; // I.combine(input[i]) == input[i].combine(I)
}
[[nodiscard]] size_t nr_combs() const {
my_assert(P.combs == In.size());
my_assert(P.combs == QN.size());
return P.combs;
}
auto combs() const { return range0(nr_combs()); }
auto ancestors(const Invar &I) const {
auto input = input_subspaces();
for (const auto i: combs())
input[i].combine(I); // In is the list of differences wrt I
return input;
}
auto new_subspaces(const Invar &I) const {
auto input = input_subspaces();
for (const auto i: combs()) {
input[i].inverse();
input[i].combine(I);
}
return input;
}
auto get_td_fields() const { return td_fields; }
// For some symmetry types with two-channels we distinguish between even and odd parity with respect to the
// channel-interchange operation.
virtual bool islr() const { return false; }
// Ditto for 3 channels: C_3 symmetry.
virtual bool isc3() const { return false; }
// For some symmetry types, we may distinguish between spin-up and spin-down quantities (in particular spin-up and
// spin-down spectral functions).
virtual bool isfield() const { return false; }
// Multiplicity of the states in the invariant subspace
[[nodiscard]] virtual size_t mult(const Invar &) const { return 1; };
auto multfnc() const { return [this](const Invar &I) { return this->mult(I); }; }
auto calculate_Z(const Invar &I, const Eigen<S> &eig, const double rescale_factor) const {
return mult(I) * ranges::accumulate(eig.value_corr_msr(), 0.0, {}, [rf=rescale_factor](const auto &x) { return exp(-rf*x); });
}
// Does the combination of subspaces I1 and I2 contribute to the spectral function corresponding to spin SPIN?
[[nodiscard]] virtual bool check_SPIN([[maybe_unused]] const Invar &I1, [[maybe_unused]] const Invar &I2, [[maybe_unused]] const int &SPIN) const { return true; }
// Is the triangle inequality satisfied (i.e. can Clebsch-Gordan coefficient be different from zero)?
[[nodiscard]] virtual bool triangle_inequality([[maybe_unused]] const Invar &I1, [[maybe_unused]] const Invar &I2, [[maybe_unused]] const Invar &I3) const { return true; }
// Is an invariant subspace with given quantum numbers allowed?
[[nodiscard]] virtual bool Invar_allowed([[maybe_unused]] const Invar &I) const { return true; }
// Project the states before taking measurements. String p defines what kind of projection is performed.
virtual bool project_subspace([[maybe_unused]] const Invar &I, [[maybe_unused]] const std::string &p) const {
return true; // by default retain all (i.e., no projection)
}
virtual DiagInfo<S> project(const DiagInfo<S> &diag, const std::string &p) const {
my_assert(p != ""s); // for performance reasons, this should never be called if the projection is not specified explicitly
DiagInfo<S> proj;
if (p == "trivial"s) {
proj = diag; // no projection
} else {
for (const auto &[I, eig]: diag) if (project_subspace(I, p)) proj[I] = eig;
}
return proj;
}
using Matrix = Matrix_traits<S>;
using t_matel = matel_traits<S>;
using t_coef = coef_traits<S>;
void offdiag_function_impl(const Step &step, const size_t i, const size_t j, const size_t ch, const size_t fnr, const t_coef factor,
Matrix &h, const SubspaceDimensions &qq, const InvarVec &In, const Opch<S> &opch) const;
void diag_function_impl(const Step &step, const size_t i, const double number, const t_coef sc_zeta,
Matrix &h, const SubspaceDimensions &qq, const double f) const;
void diag_function(const Step &step, const size_t i, const double number, const t_coef sc_zeta,
Matrix &h, const SubspaceDimensions &qq) const;
void diag_function_half(const Step &step, const size_t i, const double number, const t_coef sc_zeta,
Matrix &h, const SubspaceDimensions &qq) const;
void diag_offdiag_function(const Step &step, const size_t i, const size_t j, const t_coef factor,
Matrix &h, const SubspaceDimensions &qq) const;
virtual void make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In,
const Opch<S> &opch, const Coef<S> &coef) const = 0;
// Called from recalc_dynamicsusceptibility(). This is the factor due
// to the spin degeneracy when calculating the trace of Sz.Sz.
[[nodiscard]] virtual double dynamicsusceptibility_factor([[maybe_unused]] const Invar &Ip, [[maybe_unused]] const Invar &I1) const { return 1.0; }
// Called from recalc_dynamic_orb_susceptibility(). This is the factor due
// to the orbital moment degeneracy when calculating the trace of Tz.Tz.
[[nodiscard]] virtual double dynamic_orb_susceptibility_factor([[maybe_unused]] const Invar &Ip, [[maybe_unused]] const Invar &I1) const { return 1.0; }
// Called from calc_specdens().
// See spectral_density_clebschgordan.nb and DMNRG_clebschgordan.nb.
[[nodiscard]] virtual double specdens_factor([[maybe_unused]] const Invar &Ip, [[maybe_unused]] const Invar &I1) const { return 1.0; }
[[nodiscard]] virtual double specdensquad_factor([[maybe_unused]] const Invar &Ip, [[maybe_unused]] const Invar &I1) const { return 1.0; }
virtual void calculate_TD(const Step &step, const DiagInfo<S> &diag, Stats<S> &stats, const double factor) const = 0;
virtual Opch<S> recalc_irreduc([[maybe_unused]] const Step &step, [[maybe_unused]] const DiagInfo<S> &diag) const { my_assert_not_reached(); }
virtual OpchChannel<S> recalc_irreduc_substeps([[maybe_unused]] const Step &step, [[maybe_unused]] const DiagInfo<S> &diag,
[[maybe_unused]] int M) const { my_assert_not_reached(); }
virtual MatrixElements<S> recalc_doublet([[maybe_unused]] const DiagInfo<S> &diag,
[[maybe_unused]] const MatrixElements<S> &cold) const { my_assert_not_reached(); }
virtual MatrixElements<S> recalc_triplet([[maybe_unused]] const DiagInfo<S> &diag,
[[maybe_unused]] const MatrixElements<S> &cold) const { my_assert_not_reached(); }
virtual MatrixElements<S> recalc_orb_triplet([[maybe_unused]] const DiagInfo<S> &diag,
[[maybe_unused]] const MatrixElements<S> &cold) const { my_assert_not_reached(); }
virtual MatrixElements<S> recalc_quadruplet([[maybe_unused]] const DiagInfo<S> &diag,
[[maybe_unused]] const MatrixElements<S> &cold) const { my_assert_not_reached(); }
virtual void recalc_global([[maybe_unused]] const Step &step, [[maybe_unused]] const DiagInfo<S> &diag, [[maybe_unused]] std::string name,
[[maybe_unused]] MatrixElements<S> &cnew) const { my_assert_not_reached(); }
// Recalculates irreducible matrix elements of a singlet operator, as well as odd-parity spin-singlet operator (for
// parity -1). Generic implementation, valid for all symmetry types.
MatrixElements<S> recalc_singlet(const DiagInfo<S> &diag, const MatrixElements<S> &nold, const int parity) const {
MatrixElements<S> nnew;
my_assert(islr() ? parity == 1 || parity == -1 : parity == 1);
for (const auto &I : diag.subspaces()) {
const Invar I1 = I;
const Invar Ip = parity == -1 ? I.InvertParity() : I;
std::vector<Recalc<S>> recalc_table;
for (const auto i: combs()) {
const auto anc = ancestor(I, i);
recalc_table.push_back({i+1, i+1, anc, parity == -1 ? anc.InvertParity() : anc, 1.0});
}
const auto Iop = parity == -1 ? InvarSinglet.InvertParity() : InvarSinglet;
nnew[Twoinvar(I1,Ip)] = recalc_general(diag, nold, I1, Ip, recalc_table, Iop);
}
return nnew;
}
virtual void show_coefficients(const Step &step, const Coef<S> &coef) const {
std::cout << std::setprecision(std::numeric_limits<double>::max_digits10);
if (!P.substeps) {
for (size_t i = 0; i < P.coefchannels; i++) {
const auto N = step.N();
std::cout << "[" << i + 1 << "]"
<< " xi(" << N << ")=" << coef.xi(N, i) << " xi_scaled(" << N << ")=" << coef.xi(N, i)/step.scale()
<< " zeta(" << N+1 << ")=" << coef.zeta(N+1, i) << std::endl;
}
} else {
const auto [N, M] = step.NM();
for (auto i = 0; i < P.coeffactor; i++) {
const auto index = M + P.channels * i;
std::cout << "[" << index << "]"
<< " xi(" << N << ")=" << coef.xi(N, index) << " zeta(" << N+1 << ")=" << coef.zeta(N+1, index) << std::endl;
}
}
}
// only overriden for symtypes QST and SPSU2T
virtual bool recalc_f_coupled([[maybe_unused]] const Invar &I1, [[maybe_unused]] const Invar &I2, [[maybe_unused]] const Invar &If) const { return true; } // used in recalc_f()
template<typename T>
auto recalc_f(const DiagInfo<S> &diag, const Invar &I1, const Invar &Ip, const T &table) const;
template<typename T>
auto recalc_general(const DiagInfo<S> &diag, const MatrixElements<S> &cold,
const Invar &I1, const Invar &Ip, const T &table, const Invar &Iop) const;
void recalc1_global(const DiagInfo<S> &diag, const Invar &I,
Matrix &m, const size_t i1, const size_t ip, const t_coef value) const;
auto CorrelatorFactorFnc() const { return [this]([[maybe_unused]] const Invar &Ip, const Invar &I1) { return this->mult(I1); }; }
auto SpecdensFactorFnc() const { return [this](const Invar &Ip, const Invar &I1) { return this->specdens_factor(Ip, I1); }; }
auto SpecdensquadFactorFnc() const { return [this](const Invar &Ip, const Invar &I1) { return this->specdensquad_factor(Ip, I1); }; }
auto SpinSuscFactorFnc() const { return [this](const Invar &Ip, const Invar &I1) { return this->dynamicsusceptibility_factor(Ip, I1); }; }
auto OrbSuscFactorFnc() const { return [this](const Invar &Ip, const Invar &I1) { return this->dynamic_orb_susceptibility_factor(Ip, I1); }; }
auto TrivialCheckSpinFnc() const { return []([[maybe_unused]] const Invar &Ip, [[maybe_unused]] const Invar &I1, [[maybe_unused]] int SPIN) { return true; }; }
auto SpecdensCheckSpinFnc() const { return [this](const Invar &I1, const Invar &Ip, int SPIN) { return this->check_SPIN(I1, Ip, SPIN); }; }
};
// Add DECL declaration in each symmetry class
#define DECL \
void make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, \
const Opch<SC> &opch, const Coef<SC> &coef) const override; \
Opch<SC> recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const override
// Optional declaration
#define HAS_SUBSTEPS OpchChannel<SC> recalc_irreduc_substeps(const Step &step, const DiagInfo<SC> &diag, int M) const override
#define HAS_DOUBLET MatrixElements<SC> recalc_doublet(const DiagInfo<SC> &diag, \
const MatrixElements<SC> &cold) const override
#define HAS_TRIPLET MatrixElements<SC> recalc_triplet(const DiagInfo<SC> &diag, \
const MatrixElements<SC> &cold) const override
#define HAS_ORB_TRIPLET MatrixElements<SC> recalc_orb_triplet(const DiagInfo<SC> &diag, \
const MatrixElements<SC> &cold) const override
#define HAS_QUADRUPLET MatrixElements<SC> recalc_quadruplet(const DiagInfo<SC> &diag, \
const MatrixElements<SC> &cold) const override
#define HAS_GLOBAL void recalc_global(const Step &step, const DiagInfo<SC> &diag, \
std::string name, MatrixElements<SC> &cnew) const override
template<scalar S>
class SymField : public Symmetry<S> {
public:
template<typename ... Args> explicit SymField(Args && ... args) : Symmetry<S>(std::forward<Args>(args)...) {}
bool isfield() const final override { return true; }
};
template<scalar S>
class SymLR : public Symmetry<S> {
public:
template<typename ... Args> explicit SymLR(Args && ... args) : Symmetry<S>(std::forward<Args>(args)...) {}
bool islr() const final override { return true; }
};
template<scalar S>
class SymC3 : public Symmetry<S> {
public:
template<typename ... Args> explicit SymC3(Args && ... args) : Symmetry<S>(std::forward<Args>(args)...) {}
bool isc3() const final override { return true; }
};
template<scalar S>
class SymFieldLR : public Symmetry<S> {
public:
template<typename ... Args> explicit SymFieldLR(Args && ... args) : Symmetry<S>(std::forward<Args>(args)...) {}
bool isfield() const final override { return true; }
bool islr() const final override { return true; }
};
// Helper functions
inline void check_abs_diff(const Invar &Ip, const Invar &I1, const std::string &what, const int diff) {
const auto a = Ip.get(what);
const auto b = I1.get(what);
my_assert(abs(b - a) == diff);
}
inline void check_diff(const Invar &Ip, const Invar &I1, const std::string &what, const int diff) {
const auto a = Ip.get(what);
const auto b = I1.get(what);
my_assert(b - a == diff);
}
} // namespace
#endif
| 17,374
|
C++
|
.h
| 285
| 54.403509
| 179
| 0.650032
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,662
|
tridiag.hpp
|
rokzitko_nrgljubljana/c++/tridiag.hpp
|
// tridiag.h - Tridiagonalisation code
// Copyright (C) 2009-2020 Rok Zitko
#ifndef _tridiag_hpp_
#define _tridiag_hpp_
#include "mp.hpp"
#include "coef.hpp"
#include "params.hpp"
namespace NRG {
template<scalar S>
class Tridiag {
public:
Tridiag(Coef<S> &coef, const size_t Nmax, const Params &P) : Nmax(Nmax), P(P) {
my_assert(P.coefchannels >= 1);
for (unsigned int alpha = 0; alpha < P.coefchannels; alpha++) tridiag_ch(alpha, coef);
}
private:
size_t Nmax;
const Params &P;
void tridiag_ch(const size_t alpha, Coef<S> &coef);
};
// Fix normalization of u_{n,m}, v_{n,m} to 1. IMPORTANT: pass by reference!
inline void fix_norm(vmpf &up, vmpf &um, const unsigned int mMAX) {
// Constants
my_mpf mpZERO, mpONE;
mpf_set_str(mpONE, "1.e0", 10);
my_mpf sum, temp, tempsq;
mpf_set(sum, mpZERO);
for (unsigned int m = 0; m <= mMAX; m++) {
mpf_mul(tempsq, up[m], up[m]);
mpf_add(sum, sum, tempsq);
mpf_mul(tempsq, um[m], um[m]);
mpf_add(sum, sum, tempsq);
}
mpf_sqrt(temp, sum);
for (unsigned int m = 0; m <= mMAX; m++) {
mpf_div(up[m], up[m], temp);
mpf_div(um[m], um[m], temp);
}
}
// Tridiagonalisation of the discretization coefficients. Multiple precision arithmetics library GMP is required.
template<scalar S>
void Tridiag<S>::tridiag_ch(const size_t alpha, Coef<S> &coef) {
std::cout << "Tridiagonalisation, ch=" << alpha << ".";
std::cout << " Using GMP version " << gmp_version << std::endl;
const unsigned int mMAX = coef.em.max(alpha);
std::cout << "mMAX=" << mMAX << std::endl;
my_assert(coef.ep.max(alpha) == mMAX);
my_assert(coef.u0p.max(alpha) == mMAX);
my_assert(coef.u0m.max(alpha) == mMAX);
mpf_set_default_prec(P.preccpp);
std::cout << "Using precision of " << P.preccpp << " digits." << std::endl;
// Constants
my_mpf mpZERO;
// Temporary MP variables
my_mpf temp, tempsq, sum;
my_mpf mpxi; // xi
my_mpf xi2; // xi^2
my_mpf mpzeta; // zeta
my_mpf xi_prev, xi2_prev; // values in previous iteration
vmpf up(mMAX + 1);
vmpf up_prev(mMAX + 1);
vmpf up_prev2(mMAX + 1);
vmpf um(mMAX + 1);
vmpf um_prev(mMAX + 1);
vmpf um_prev2(mMAX + 1);
vmpf ep1(mMAX + 1);
vmpf em1(mMAX + 1);
vmpf ep2(mMAX + 1);
vmpf em2(mMAX + 1);
for (unsigned int m = 0; m <= mMAX; m++) {
// Only real parameters are supported in this code [8.10.2009]
mpf_set_d(up_prev[m], real_part_with_check(coef.u0p(m, alpha)));
mpf_set_d(um_prev[m], real_part_with_check(coef.u0m(m, alpha)));
mpf_set_d(ep1[m], real_part_with_check(coef.ep(m, alpha)));
mpf_set_d(em1[m], real_part_with_check(coef.em(m, alpha)));
mpf_mul(ep2[m], ep1[m], ep1[m]);
mpf_mul(em2[m], em1[m], em1[m]);
}
fix_norm(up_prev, um_prev, mMAX);
for (unsigned int n = 0; n <= Nmax; n++) {
// Calculate zeta_n, xi2_n and xi_n
mpf_set(mpzeta, mpZERO);
mpf_set(xi2, mpZERO);
for (unsigned int m = 0; m <= mMAX; m++) {
// up_prev = u^+_{n,m}
mpf_mul(tempsq, up_prev[m], up_prev[m]);
mpf_mul(temp, tempsq, ep2[m]);
mpf_add(xi2, xi2, temp);
mpf_mul(temp, tempsq, ep1[m]);
mpf_add(mpzeta, mpzeta, temp);
// um_prev = u^-_{n,m}
mpf_mul(tempsq, um_prev[m], um_prev[m]);
mpf_mul(temp, tempsq, em2[m]);
mpf_add(xi2, xi2, temp);
mpf_mul(temp, tempsq, em1[m]);
mpf_sub(mpzeta, mpzeta, temp);
}
// subtract xi^2_{n-1}
mpf_sub(xi2, xi2, xi2_prev);
// subtract zeta^2_n
mpf_mul(tempsq, mpzeta, mpzeta);
mpf_sub(xi2, xi2, tempsq);
mpf_sqrt(mpxi, xi2);
// compute u_{n+1,m}, v_{n+1,m}
for (unsigned int m = 0; m <= mMAX; m++) {
// zeta=zeta_n
mpf_sub(temp, ep1[m], mpzeta);
// up_prev[m]=u_{n,m}
mpf_mul(up[m], temp, up_prev[m]);
// xi_prev=xi_{n-1}, up_prev2=u_{n-1,m}
mpf_mul(temp, xi_prev, up_prev2[m]);
mpf_sub(up[m], up[m], temp);
// xi=xi_n
mpf_div(up[m], up[m], mpxi);
mpf_neg(temp, em1[m]);
mpf_sub(temp, temp, mpzeta);
mpf_mul(um[m], temp, um_prev[m]);
mpf_mul(temp, xi_prev, um_prev2[m]);
mpf_sub(um[m], um[m], temp);
mpf_div(um[m], um[m], mpxi);
}
fix_norm(up, um, mMAX);
// Recalculate xi, xi2
mpf_set(sum, mpZERO);
for (unsigned int m = 0; m <= mMAX; m++) {
mpf_mul(temp, up[m], up_prev[m]);
mpf_mul(temp, temp, ep1[m]);
mpf_add(sum, sum, temp);
mpf_mul(temp, um[m], um_prev[m]);
mpf_mul(temp, temp, em1[m]);
mpf_sub(sum, sum, temp);
}
mpf_set(mpxi, sum);
mpf_mul(xi2, mpxi, mpxi);
// Save results
double dxi = mpf_get_d(mpxi);
double dzeta = mpf_get_d(mpzeta);
double coef_xi = dxi * P.bandrescale;
double coef_zeta = dzeta * P.bandrescale;
coef.xi.set(n, alpha, coef_xi);
coef.zeta.set(n, alpha, coef_zeta);
std::cout << " xi(" << n << ")=" << HIGHPREC(dxi) << std::endl;
std::cout << "zeta(" << n << ")=" << HIGHPREC(dzeta) << std::endl;
// Store results from previous iteration
mpf_set(xi_prev, mpxi);
mpf_set(xi2_prev, xi2);
for (unsigned int m = 0; m <= mMAX; m++) {
mpf_set(um_prev2[m], um_prev[m]);
mpf_set(up_prev2[m], up_prev[m]);
mpf_set(um_prev[m], um[m]);
mpf_set(up_prev[m], up[m]);
}
}
}
} // namespace
#endif // _tridiag_hpp_
| 5,364
|
C++
|
.h
| 156
| 29.762821
| 113
| 0.588235
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,663
|
dmnrg.hpp
|
rokzitko_nrgljubljana/c++/dmnrg.hpp
|
// dmnrg.h - Density-matrix NRG
// Copyright (C) 2009-2021 Rok Zitko
#ifndef _dmnrg_hpp_
#define _dmnrg_hpp_
#include <memory>
#include <fstream>
#include <iomanip>
#include <stdexcept>
#include <string>
#include <cmath>
#include "operators.hpp"
#include "symmetry.hpp"
#include "step.hpp"
#include "eigen.hpp"
#include "params.hpp"
#include "invar.hpp"
#include "traits.hpp"
#include "store.hpp"
#include "time_mem.hpp"
#include "stats.hpp"
#include "numerics.hpp"
#include <fmt/format.h>
namespace NRG {
// Check if the trace of the density matrix equals 'ref_value'.
template<scalar S, typename MF>
void check_trace_rho(const DensMatElements<S> &m, MF mult, const double ref_value = 1.0) {
const auto tr = m.trace(mult);
if (!num_equal(tr, ref_value))
throw std::runtime_error(fmt::format("check_trace_rho() failed, tr={}, ref_value={}", tr, ref_value));
}
// Calculate rho_N, the density matrix at the last NRG iteration. It is
// normalized to 1. Note: in CFS approach, we consider all states in the
// last iteration to be "discarded".
// For the details on the full Fock space approach see:
// F. B. Anders, A. Schiller, Phys. Rev. Lett. 95, 196801 (2005).
// F. B. Anders, A. Schiller, Phys. Rev. B 74, 245113 (2006).
// R. Peters, Th. Pruschke, F. B. Anders, Phys. Rev. B 74, 245114 (2006).
template<scalar S, typename MF>
auto init_rho_impl(const Step &step, const DiagInfo<S> &diag, MF mult) {
DensMatElements<S> rho;
for (const auto &[I, eig]: diag)
rho[I] = eig.diagonal_exp(step.scT()) / grand_canonical_Z(step.scT(), diag, mult);
// NOTE: diagonal_exp() and grand_canonical_Z() both use the round-off-error corrected eigenvalues.
check_trace_rho(rho, mult);
return rho;
}
template<scalar S>
auto init_rho(const Step &step, const DiagInfo<S> &diag_in, const Symmetry<S> *Sym, const Params &P) {
if (P.project == ""s) {
return init_rho_impl(step, diag_in, Sym->multfnc());
} else {
const auto diag = Sym->project(diag_in, P.project);
return init_rho_impl(step, diag, Sym->multfnc());
}
}
// Calculation of the contribution from subspace I1 of rhoN (density matrix at iteration N) to rhoNEW (density matrix
// at iteration N-1)
template<scalar S, typename Matrix = Matrix_traits<S>, typename t_coef = coef_traits<S>>
void cdmI(const size_t i, // Subspace index
const Invar &I1, // Quantum numbers corresponding to subspace i
const Matrix &rhoN, // rho^N
const Eigen<S> &diagI1, // contains U_{I1}
Matrix &rhoNEW, // rho^{N-1}
const size_t N,
const t_coef factor, // multiplicative factor that accounts for multiplicity
const Store<S> &store_all,
const Params &P)
{
my_assert(i < P.combs);
nrglog('D', "cdmI i=" << i << " I1=" << I1 << " factor=" << factor);
// Range of indexes r and r' in matrix C^{QS,N}_{r,r'}, cf. Eq. (3.55) in my dissertation.
const auto dim = size2(rhoNEW);
// number of states taken into account in the density-matrix at *current* (Nth) stage (in subspace I1)
const auto nromega = size2(rhoN);
if (nromega == 0 || dim == 0) return; // continue only if connection exists
// rmax (info[I1].rmax[i]) is the range of r in U^N_I1(omega|ri), only those states that we actually kept..
const auto rmax = store_all[N].at(I1).rmax.rmax(i);
if (rmax == 0) return; // rmax can be zero in the case a subspace has been completely truncated
my_assert(rmax == dim); // Otherwise, rmax must equal dim
// Check range of omega: do the dimensions of C^N_I1(omega omega') and U^N_I1(omega|r1) match?
my_assert(nromega <= diagI1.getnrstored());
const auto U = diagI1.vectors.submatrix_const({0, nromega}, store_all[N].at(I1).rmax.part(i)); // YYY: Ublock ??
rotate<S>(rhoNEW, factor, U, rhoN);
}
// Calculation of the shell-N REDUCED DENSITY MATRICES: Calculate rho at previous iteration (N-1) from rho
// at the current iteration (N, rho)
template<scalar S>
auto calc_densitymatrix_iterN(const DiagInfo<S> &diag, const DensMatElements<S> &rho,
const size_t N, const Store<S> &store_all, const Symmetry<S> *Sym, const Params &P) {
nrglog('D', "calc_densitymatrix_iterN N=" << N);
DensMatElements<S> rhoPrev;
for (const auto &[I, dimsub] : store_all[N - 1]) { // loop over all subspaces at *previous* iteration
const auto dim = dimsub.kept();
rhoPrev[I] = zero_matrix<S>(dim);
if (dim == 0) continue;
const auto ns = Sym->new_subspaces(I);
for (const auto &[i, sub] : ns | ranges::views::enumerate) {
const auto x = rho.find(sub);
const auto y = diag.find(sub);
if (x != rho.end() && y != diag.end())
cdmI(i, sub, x->second, y->second, rhoPrev[I], N, double(Sym->mult(sub)) / double(Sym->mult(I)), store_all, P);
}
}
return rhoPrev;
}
// Returns true if all the required density matrices are already saved on the disk.
inline bool already_computed(const std::string &prefix, const Params &P) {
for (auto N = P.Nmax - 1; N > P.Ninit; N--) {
const std::string fn = P.workdir->rhofn(N-1, prefix); // note the minus 1
if (!file_exists(fn)) {
std::cout << fn << " not found. Computing." << std::endl;
return false;
}
}
return true;
}
// calc_densitymatrix() is called prior to starting the NRG procedure for the second time. Here we calculate the
// shell-N density matrices for all iteration steps.
template<scalar S>
void calc_densitymatrix(DensMatElements<S> &rho, const Store<S> &store_all, const Symmetry<S> *Sym,
MemTime &mt, const Params &P, const std::string filename = fn_rho) {
if (P.resume && already_computed(filename, P)) return;
check_trace_rho(rho, Sym->multfnc()); // Must be 1.
if (P.ZBW()) return;
const auto section_timing = mt.time_it("DM");
for (size_t N = P.Nmax - 1; N > P.Ninit; N--) {
std::cout << "[DM] " << N << std::endl;
const DiagInfo<S> diag_loaded(N, P);
auto rhoPrev = calc_densitymatrix_iterN(diag_loaded, rho, N, store_all, Sym, P); // need store_all for backiteration!
check_trace_rho(rhoPrev, Sym->multfnc()); // Make sure rho is normalized to 1.
rhoPrev.save(N-1, P, filename);
rho.swap(rhoPrev);
}
}
// ****************** Calculation of the FULL REDUCED DENSITY MATIRICES
// Calculate rho(N), the shell-N density matrix, computed using
// the discarded states at shell N.
// Must be called AFTER calc_ZnD().
// Called fron nrg.cc immediately after the first NRG run (with N=Nmax-1),
// and also from calc_fulldensity_iterN (with lower N).
// A. Weichselbaum, J. von Delft, Phys. Rev. Lett. 99, 076402 (2007)
// T. A. Costi, V. Zlatic, Phys. Rev. B 81, 235127 (2010)
// H. Zhang, X. C. Xie, Q. Sun, Phys. Rev. B 82, 075111 (2010)
template<scalar S, typename MF>
DensMatElements<S> init_rho_FDM(const size_t N, const Store<S> &store, const Stats<S> &stats,
MF mult, const double T) {
DensMatElements<S> rhoFDM;
for (const auto &[I, ds] : store[N]) {
rhoFDM[I] = zero_matrix<S>(ds.max());
if (stats.ZnDNd[N] != 0.0)
for (const auto i: ds.all())
rhoFDM[I](i, i) = exp(-ds.eig.values.abs_zero(i) / T) * stats.wn[N] / stats.ZnDNd[N];
}
if (stats.wn[N] != 0.0) { // note: wn \propto ZnDNd, so this is the same condition as above
// Trace should be equal to the total weight of the shell-N contribution to the FDM.
const auto tr = rhoFDM.trace(mult);
const auto diff = (tr - stats.wn[N]) / stats.wn[N]; // relative error
if (!num_equal(diff, 0.0, 1e-8)) my_assert(stats.wn[N] < 1e-12); // OK if small enough overall
}
return rhoFDM;
}
template<scalar S>
auto calc_fulldensitymatrix_iterN(const Step &step, // only required for step::last()
const DiagInfo<S> &diag,
const DensMatElements<S> &rhoFDM, // input
const size_t N, const Store<S> &store, const Store<S> &store_all, const Stats<S> &stats,
const Symmetry<S> *Sym, const Params &P) {
nrglog('D', "calc_fulldensitymatrix_iterN N=" << N);
DensMatElements<S> rhoDD;
DensMatElements<S> rhoFDMPrev;
if (!step.last(N))
rhoDD = init_rho_FDM(N, store, stats, Sym->multfnc(), P.T); // store here!
for (const auto &[I, ds] : store_all[N - 1]) { // loop over all subspaces at *previous* iteration, hence store_all here
const auto subs = Sym->new_subspaces(I);
const auto dim = ds.kept();
rhoFDMPrev[I] = zero_matrix<S>(dim);
if (!dim) continue;
for (const auto i : Sym->combs()) {
const auto sub = subs[i];
// DM construction for non-Abelian symmetries: must include the ratio of multiplicities as a coefficient.
const auto coef = double(Sym->mult(sub)) / double(Sym->mult(I));
// Contribution from the KK sector.
const auto x1 = rhoFDM.find(sub);
const auto y = diag.find(sub);
if (x1 != rhoFDM.end() && y != diag.end())
cdmI(i, sub, x1->second, y->second, rhoFDMPrev[I], N, coef, store_all, P);
// Contribution from the DD sector. rhoDD -> rhoFDMPrev
if (!step.last(N))
if (const auto x2 = rhoDD.find(sub); x2 !=rhoDD.end() && y != diag.end())
cdmI(i, sub, x2->second, y->second, rhoFDMPrev[I], N, coef, store_all, P);
// (Exception: for the N-1 iteration, the rhoPrev is already initialized with the DD sector of the last iteration.) }
} // over combinations
} // over subspaces
return rhoFDMPrev;
}
template<scalar S>
void calc_fulldensitymatrix(const Step &step, DensMatElements<S> &rhoFDM, const Store<S> &store, const Store<S> &store_all, const Stats<S> &stats,
const Symmetry<S> *Sym, MemTime &mt, const Params &P, const std::string &filename = fn_rhoFDM) {
if (P.resume && already_computed(filename, P)) return;
if (P.ZBW()) return;
const auto section_timing = mt.time_it("FDM");
for (size_t N = P.Nmax - 1; N > P.Ninit; N--) {
std::cout << "[FDM] " << N << std::endl;
const DiagInfo<S> diag_loaded(N, P); // = load_and_project(N, Sym, P);
auto rhoFDMPrev = calc_fulldensitymatrix_iterN(step, diag_loaded, rhoFDM, N, store, store_all, stats, Sym, P);
const auto tr = rhoFDMPrev.trace(Sym->multfnc());
const auto expected = std::accumulate(stats.wn.begin() + N, stats.wn.begin() + P.Nmax, 0.0);
const auto diff = (tr - expected) / expected;
nrglog('w', "tr[rhoFDM(" << N << ")]=" << tr << " sum(wn)=" << expected << " diff=" << diff);
my_assert(num_equal(diff, 0.0));
rhoFDMPrev.save(N-1, P, filename);
rhoFDM.swap(rhoFDMPrev);
}
}
} // namespace
#endif
| 10,687
|
C++
|
.h
| 216
| 44.893519
| 146
| 0.644408
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,664
|
store.hpp
|
rokzitko_nrgljubljana/c++/store.hpp
|
#ifndef _store_hpp_
#define _store_hpp_
#include <vector>
#include <map>
#include <iostream>
#include <fstream>
#include <string>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/map.hpp>
#include "invar.hpp"
#include "eigen.hpp"
#include "subspaces.hpp"
#include "h5.hpp"
namespace NRG {
// Container for all information which needs to be gathered in each invariant subspace.
// Required for the density-matrix construction.
template<scalar S>
struct Sub {
Eigen<S> eig;
SubspaceDimensions rmax;
bool is_last = false;
[[nodiscard]] auto kept() const { return eig.getnrkept(); }
[[nodiscard]] auto total() const { return eig.getdim(); }
[[nodiscard]] auto min() const { return is_last ? 0 : kept(); } // min(), max() return the range of D states to be summed over in FDM
[[nodiscard]] auto max() const { return total(); }
[[nodiscard]] auto all() const { return boost::irange(min(), max()); }
void h5save(H5Easy::File &fd, const std::string &name) const {
h5_dump_scalar(fd, name + "/kept", kept());
h5_dump_scalar(fd, name + "/total", total());
h5_dump_scalar(fd, name + "/min", min());
h5_dump_scalar(fd, name + "/max", max());
}
};
template<scalar S>
class Subs : public std::map<Invar, Sub<S>> {
public:
Subs() = default;
Subs(const DiagInfo<S> &diag, const SubspaceStructure &substruct, const bool last) {
for (const auto &[I, eig]: diag)
(*this)[I] = { eig, substruct.at_or_null(I), last };
}
void h5save(H5Easy::File &fd, const std::string &name) const {
const std::vector<int> dummy = {1};
for (const auto &I : *this | boost::adaptors::map_keys)
H5Easy::dump(fd, name+"/list/" + I.name(), dummy);
for (const auto &[I, sub]: *this)
sub.h5save(fd, name + "/data/" + I.name());
}
};
template<scalar S>
class Store : public std::vector<Subs<S>> {
public:
const size_t Nbegin, Nend; // range of valid indexes
Store(const size_t Nbegin, const size_t Nend) : Nbegin(Nbegin), Nend(Nend) { this->resize(Nend ? Nend : 1); } // at least 1 for ZBW
auto Nall() const { return boost::irange(Nbegin, Nend); }
void dump_abs_G(std::ostream &F) const {
for (const auto N : Nall()) {
F << std::endl << "===== Iteration number: " << N+1 << std::endl; // mind the shift by 1
for (const auto &[I, ds]: this->at(N))
F << "Subspace: " << I << std::endl << (ds.eig.values.all_abs_G() | ranges::to_vector) << std::endl;
}
}
void dump_all_absolute_energies(const std::string &filename = "absolute_energies.dat"s) {
std::ofstream F(filename);
this->dump_abs_G(F);
}
// Save a dump of all subspaces, with dimension info, etc.
void dump_subspaces(const std::string &filename = "subspaces.dat"s) const {
std::ofstream O(filename);
for (const auto N : Nall()) {
O << "Iteration " << N << std::endl;
O << "len_dm=" << this->at(N).size() << std::endl;
for (const auto &[I, sub] : this->at(N))
O << "I=" << I << " kept=" << sub.kept() << " total=" << sub.total() << std::endl;
O << std::endl;
}
}
void shift_abs_energies(const double GS_energy) {
for (const auto N : Nall())
for (auto &ds : this->at(N) | boost::adaptors::map_values)
ds.eig.subtract_GS_energy(GS_energy);
}
void h5save(H5Easy::File &fd, const std::string &name) const {
const std::vector range = {Nbegin, Nend};
H5Easy::dump(fd, name + "/range", range);
for (const auto N : Nall())
this->at(N).h5save(fd, name + "/" + std::to_string(N+1)); // note the shift by 1
}
};
} // namespace
#endif
| 3,628
|
C++
|
.h
| 91
| 35.758242
| 135
| 0.618197
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,665
|
misc.hpp
|
rokzitko_nrgljubljana/c++/misc.hpp
|
// misc.h - Miscelaneous functions
// Copyright (C) 2005-2022 Rok Zitko
#ifndef _misc_hpp_
#define _misc_hpp_
#include <stdexcept>
#include <string>
#include <iterator>
#include <optional>
#include <deque>
#include <vector>
#include <set>
#include <map>
#include <fstream>
#include <iostream>
#include <sstream>
#include <cstring> // stdcasecmp
#include <exception>
#include <cstdio> // stdout
#include <unistd.h> // isatyy
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/map.hpp>
#include <fmt/format.h>
#include "basicio.hpp"
#include "portabil.hpp"
#include <Eigen/Dense>
namespace NRG {
inline bool is_stdout_redirected() {
return !isatty(fileno(stdout));
}
inline auto file_exists(const char *fileName) {
std::ifstream file(fileName);
return file.good();
}
inline auto contains(const std::string &str, const char c) {
return str.find(c) != std::string::npos;
}
// x raised to the power of n
template<typename T, typename N>
constexpr inline auto intpow(const T x, const N n) {
assert(n >= 0);
T res = 1;
for (N i = 1; i <= n; i++) res *= x;
return res;
}
template<typename T> auto get_back(T &d) { // usually T is list or deque
if (d.empty()) throw std::runtime_error("Error: List empty! File: "s + (std::string)__FILE__ + " Line: "s + std::to_string(__LINE__));
auto i = d.back();
d.pop_back();
return i;
}
template<typename T> auto get_front(T &d) {
if (d.empty()) throw std::runtime_error("Error: List empty! File: "s + (std::string)__FILE__ + " Line: "s + std::to_string(__LINE__));
auto i = d.front();
d.pop_front();
return i;
}
// switch statement with three cases
template <typename T, typename T1>
inline T switch3(const T1 x0, const T1 x1, const T y1, const T1 x2, const T y2, const T1 x3, const T y3) {
if (x0 == x1) return y1;
if (x0 == x2) return y2;
if (x0 == x3) return y3;
throw std::runtime_error("Error: No match! File: "s + (std::string)__FILE__ + " Line: "s + std::to_string(__LINE__));
}
// Get next line from stream F, skipping empty lines and comments.
inline std::optional<std::string> nextline(std::istream &F) {
std::string line;
while (F) {
std::getline(F, line);
if (!F) return std::nullopt; // bail out
if (line.length() == 0) continue; // skip empty lines
if (line[0] == '#') continue; // skip comment lines
return line;
}
return std::nullopt; // error
}
inline std::string strip_trailing_whitespace(const std::string &in) {
auto s(in);
auto it = s.rbegin();
while (it != s.rend() && std::isspace(*it)) {
s.erase(--it.base());
it = s.rbegin();
}
return s;
}
// Parse a block of "keyword=value" lines.
inline auto parse_block(std::istream &F) {
std::map<std::string, std::string> parsed_params;
while (F) {
if (const auto l = nextline(F)) {
const auto line = l.value();
if (line[0] == '[') // new block, we're done!
break;
const auto pos_eq = line.find_first_of('=');
if (pos_eq == std::string::npos) // not found
continue;
const auto keyword = line.substr(0, pos_eq);
// Important: Strip trailing whitespace to avoid hard-to-detect problems!
const auto value = strip_trailing_whitespace(line.substr(pos_eq+1));
if (parsed_params.count(keyword))
throw std::runtime_error("Duplicate keyword: " + keyword);
parsed_params[keyword] = value;
}
}
return parsed_params;
}
// Locate block [name] in a file stream. Returns true if succeessful.
inline bool find_block(std::istream &F, const std::string &s) {
std::string target = "[" + s + "]";
F.clear();
F.seekg(0, std::ios::beg);
while (F) {
if (auto l = nextline(F))
if(target.compare(l.value()) == 0) { return true; }
}
return false;
}
// Parse the [param] block of an input file.
inline auto parser(const std::string &filename, const std::string &block) {
auto F = safe_open_for_reading(filename);
if (!find_block(F, block))
throw std::runtime_error(fmt::format("Block {} not found in input file {}.", block, filename));
return parse_block(F);
}
// Simple tokenizer class
class string_token {
private:
std::istringstream iss;
std::set<std::string> l;
public:
explicit string_token(const std::string &s) : iss(s),
l(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>()) {};
[[nodiscard]] auto find(const std::string &x) const { return l.count(x) != 0; }
};
// Skip comment lines in the input stream 'f'.
inline void skip_comments(std::istream &f, const bool output = false, std::ostream &OUT = std::cout) {
while (f) {
const auto ch = f.peek();
// skip white space and line breaks
if (ch == ' ' || ch == '\t' || ch == '\n') {
f.ignore();
continue;
}
// break the loop if a non-comment like found
if (ch != '#') break;
f.ignore(); // ignore '#'
std::string line;
std::getline(f, line);
if (output) OUT << ">> " << line << std::endl;
}
}
// Sort according to the first component of the pair. Second component is ignored (unlike in the default sort
// function).
struct sortfirst {
template <typename T1, typename T2> constexpr bool operator()(const std::pair<T1, T2> &xy1, const std::pair<T1, T2> &xy2) { return xy1.first < xy2.first; }
};
template<typename T> auto range0(const T b) { return boost::irange(T{0}, b); }
template<typename T> auto range1(const T b) { return boost::irange(T{1}, b+1); }
// Returns true if the data file contains complex values
inline bool complex_data(const std::string &filename = "data") {
std::ifstream F(filename);
if (!F) throw std::runtime_error("Can't load initial data.");
std::string l;
std::getline(F, l);
std::getline(F, l);
std::getline(F, l); // third line
const auto pos = l.find("COMPLEX");
return pos != std::string::npos;
}
template<typename K, typename V>
auto vector_of_keys(const std::map<K,V> &container)
{
std::vector<K> keys;
for (const auto &k: container | boost::adaptors::map_keys)
keys.push_back(k);
return keys;
}
inline double atof(const std::string &s) { return std::atof(s.c_str()); }
inline int atoi(const std::string &s) { return std::atoi(s.c_str()); }
// Read data from stream F.
template <typename T1, typename T2>
std::vector<std::pair<T1, T2>> readtable(const std::string &filename, const bool verbose = false)
{
auto F = safe_open_for_reading(filename);
std::vector<std::pair<T1, T2>> v;
while (F)
{
skip_comments(F);
const auto x = read_one<T1>(F);
const auto y = read_one<T2>(F);
if (F.fail()) break;
assert(std::isfinite(x) && std::isfinite(y));
v.push_back(std::make_pair(x, y));
}
if (verbose) std::cout << v.size() << " lines read." << std::endl;
return v;
}
template <typename T1, typename T2>
void writetable(const std::vector<std::pair<T1, T2>> &re, std::string filename, const int output_precision = 16) {
auto F = safe_open(filename);
F << std::setprecision(output_precision);
for (const auto & [x, y] : re) F << x << " " << y << std::endl;
}
inline std::vector<std::string> split (const std::string &s, char delim) {
std::vector<std::string> result;
std::stringstream ss (s);
std::string item;
while (getline (ss, item, delim)) {
result.push_back (item);
}
return result;
}
} // namespace
#endif
| 7,363
|
C++
|
.h
| 214
| 31.369159
| 157
| 0.649803
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,666
|
sym-QSZLR-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QSZLR-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryQSZLR : public SymFieldLR<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryQSZLR(const Params &P) : SymFieldLR<SC>(P, std::vector{"<Sz^2>", "<Sz>", "<Q>", "<Q^2>"}, Invar(0,0,1)) {
initInvar({
{"Q", additive}, // charge
{"SSZ", additive}, // spin projection
{"P", multiplicative} // parity
});
}
bool check_SPIN(const Invar &I1, const Invar &Ip, const int &SPIN) const override {
// The spin projection of the operator is defined by the difference
// in Sz of both the invariant subspaces.
const int ssz1 = I1.get("SSZ");
const int sszp = Ip.get("SSZ");
const int sszop = ssz1 - sszp;
return sszop == SPIN;
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("Q"), I2.get("Q"), I3.get("Q")) && u1_equality(I1.get("SSZ"), I2.get("SSZ"), I3.get("SSZ"))
&& z2_equality(I1.get("P"), I2.get("P"), I3.get("P"));
}
void load() override {
my_assert(P.channels == 2);
#include "qszlr/qszlr-2ch-In2.dat"
#include "qszlr/qszlr-2ch-QN.dat"
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ, trSZ2, trQ, trQ2; // Tr[S_z], Tr[(S_z)^2], etc.
for (const auto &[I, eig]: diag) {
const int ssz = I.get("SSZ");
const int q = I.get("Q");
const double sumZ = this->calculate_Z(I, eig, factor);
trSZ += sumZ * SZ(ssz);
trSZ2 += sumZ * pow(SZ(ssz),2);
trQ += sumZ * q;
trQ2 += sumZ * pow(q,2);
}
stats.td.set("<Sz^2>", trSZ2 / stats.Z);
stats.td.set("<Sz>", trSZ / stats.Z);
stats.td.set("<Q>", trQ / stats.Z);
stats.td.set("<Q^2>", trQ2 / stats.Z);
}
DECL;
};
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryQSZLR<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
#include "qszlr/qszlr-2ch-offdiag.dat"
#include "qszlr/qszlr-2ch-diag.dat"
}
}
#include "nrg-recalc-QSZLR.hpp"
| 2,574
|
C++
|
.h
| 63
| 36.746032
| 182
| 0.62585
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,667
|
sym-P-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-P-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryP : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryP(const Params &P) : Symmetry<SC>(P, std::vector<std::string>{}, Invar(1)) {
initInvar({
{"P", multiplicative} // fermion parity
});
}
void load() override {
switch (P.channels) {
case 1:
#include "p/p-1ch-In2.dat"
#include "p/p-1ch-QN.dat"
break;
case 2:
#include "p/p-2ch-In2.dat"
#include "p/p-2ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void make_matrix_polarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const;
void make_matrix_nonpolarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const;
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {};
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override { return z2_equality(I1.get("P"), I2.get("P"), I3.get("P")); }
DECL;
HAS_DOUBLET;
HAS_GLOBAL;
};
#undef OFFDIAG_CR_DO
#undef OFFDIAG_CR_UP
#undef OFFDIAG_AN_DO
#undef OFFDIAG_AN_UP
#define OFFDIAG_CR_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_CR_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 1, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_AN_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 2, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_AN_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 3, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef ISOSPINX
#define ISOSPINX(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * 2.0 * coef.delta(step.N() + 1, ch), h, qq)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryP<SC>::make_matrix_nonpolarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 1:
#include "p/p-1ch-offdiag-CR-UP.dat"
#include "p/p-1ch-offdiag-CR-DO.dat"
#include "p/p-1ch-offdiag-AN-UP.dat"
#include "p/p-1ch-offdiag-AN-DO.dat"
#include "p/p-1ch-diag.dat"
#include "p/p-1ch-Ixtot.dat"
break;
case 2:
#include "p/p-2ch-offdiag-CR-UP.dat"
#include "p/p-2ch-offdiag-CR-DO.dat"
#include "p/p-2ch-offdiag-AN-UP.dat"
#include "p/p-2ch-offdiag-AN-DO.dat"
#include "p/p-2ch-diag.dat"
#include "p/p-2ch-Ixtot.dat"
break;
default: my_assert_not_reached();
}
}
#undef OFFDIAG_CR_DO
#undef OFFDIAG_CR_UP
#undef OFFDIAG_AN_DO
#undef OFFDIAG_AN_UP
#define OFFDIAG_CR_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.xiDOWN(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_CR_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 1, t_matel(factor) * coef.xiUP(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_AN_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 2, t_matel(factor) * coef.xiDOWN(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_AN_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 3, t_matel(factor) * coef.xiUP(step.N(), ch), h, qq, In, opch)
#undef ISOSPINX
#define ISOSPINX(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * 2.0 * coef.delta(step.N() + 1, ch), h, qq)
#undef DIAG_UP
#define DIAG_UP(i, j, ch, number) this->diag_function(step, i, number, coef.zetaUP(step.N() + 1, ch), h, qq)
#undef DIAG_DOWN
#define DIAG_DOWN(i, j, ch, number) this->diag_function(step, i, number, coef.zetaDOWN(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryP<SC>::make_matrix_polarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 1:
#include "p/p-1ch-offdiag-CR-UP.dat"
#include "p/p-1ch-offdiag-CR-DO.dat"
#include "p/p-1ch-offdiag-AN-UP.dat"
#include "p/p-1ch-offdiag-AN-DO.dat"
#include "p/p-1ch-diag-UP.dat"
#include "p/p-1ch-diag-DOWN.dat"
#include "p/p-1ch-Ixtot.dat"
break;
case 2:
#include "p/p-2ch-offdiag-CR-UP.dat"
#include "p/p-2ch-offdiag-CR-DO.dat"
#include "p/p-2ch-offdiag-AN-UP.dat"
#include "p/p-2ch-offdiag-AN-DO.dat"
#include "p/p-2ch-diag-UP.dat"
#include "p/p-2ch-diag-DOWN.dat"
#include "p/p-2ch-Ixtot.dat"
break;
default: my_assert_not_reached();
}
}
template<typename SC>
void SymmetryP<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
if (P.polarized) {
make_matrix_polarized(h, step, qq, I, In, opch, coef);
} else {
make_matrix_nonpolarized(h, step, qq, I, In, opch, coef);
}
}
}
#include "nrg-recalc-P.hpp"
| 5,264
|
C++
|
.h
| 118
| 41.974576
| 191
| 0.681171
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,668
|
sym-SU2.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SU2.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_SU2(const Params &P);
}
| 96
|
C++
|
.h
| 4
| 22.5
| 53
| 0.744444
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,669
|
sym-SPU1LR-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SPU1LR-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetrySPU1LR : public SymFieldLR<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetrySPU1LR(const Params &P) : SymFieldLR<SC>(P, std::vector{"<Sz^2>", "<Sz>"}, Invar(0,1)) {
initInvar({
{"SSZ", additive}, // spin projection
{"P", multiplicative} // parity
});
}
bool check_SPIN(const Invar &I1, const Invar &Ip, const int &SPIN) const override {
// The spin projection of the operator is defined by the difference
// in Sz of both the invariant subspaces.
int ssz1 = I1.get("SSZ");
int sszp = Ip.get("SSZ");
int sszop = ssz1 - sszp;
return sszop == SPIN;
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("SSZ"), I2.get("SSZ"), I3.get("SSZ")) && z2_equality(I1.get("P"), I2.get("P"), I3.get("P"));
}
void load() override {
switch (P.channels) {
case 1:
#include "spu1lr/spu1lr-1ch-In2.dat"
#include "spu1lr/spu1lr-1ch-QN.dat"
break;
case 2:
#include "spu1lr/spu1lr-2ch-In2.dat"
#include "spu1lr/spu1lr-2ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ, trSZ2; // Tr[S_z], Tr[S_z^2]
for (const auto &[I, eig]: diag) {
const int ssz = I.get("SSZ");
const double sumZ = this->calculate_Z(I, eig, factor);
trSZ += sumZ * SZ(ssz);
trSZ2 += sumZ * pow(SZ(ssz),2);
}
stats.td.set("<Sz^2>", trSZ2 / stats.Z);
stats.td.set("<Sz>", trSZ / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
HAS_GLOBAL;
};
#undef ISOSPINX
#define ISOSPINX(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * 2.0 * coef.delta(step.N() + 1, ch), h, qq)
#undef ANOMALOUS
#define ANOMALOUS(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.kappa(step.N(), ch), h, qq, In, opch)
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetrySPU1LR<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 1:
#include "spu1lr/spu1lr-1ch-offdiag.dat"
#include "spu1lr/spu1lr-1ch-anomalous.dat"
#include "spu1lr/spu1lr-1ch-diag.dat"
#include "spu1lr/spu1lr-1ch-isospinx.dat"
break;
case 2:
#include "spu1lr/spu1lr-2ch-diag.dat"
#include "spu1lr/spu1lr-2ch-offdiag.dat"
#include "spu1lr/spu1lr-2ch-anomalous.dat"
#include "spu1lr/spu1lr-2ch-isospinx.dat"
break;
default: my_assert_not_reached();
}
}
}
#include "nrg-recalc-SPU1LR.hpp"
| 3,138
|
C++
|
.h
| 84
| 33.630952
| 183
| 0.660526
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,670
|
sym-SL3.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SL3.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_SL3(const Params &P);
}
| 96
|
C++
|
.h
| 4
| 22.5
| 53
| 0.744444
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,671
|
sym-QSZLR.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QSZLR.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_QSZLR(const Params &P);
}
| 98
|
C++
|
.h
| 4
| 23
| 55
| 0.75
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,672
|
sym-DBLISOSZ-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-DBLISOSZ-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryDBLISOSZ : public SymField<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryDBLISOSZ(const Params &P) : SymField<SC>(P, std::vector{"<Sz^2>", "<Sz>", "<Q1^2>", "<Q2^2>"}, Invar(1, 1, 0)) {
initInvar({
{"II1", additive}, // isospin 1
{"II2", additive}, // isospin 2
{"SSZ", additive} // spin projection
});
}
bool check_SPIN(const Invar &I1, const Invar &Ip, const int &SPIN) const override {
// The spin projection of the operator is defined by the difference
// in Sz of both the invariant subspaces.
int ssz1 = I1.get("SSZ");
int sszp = Ip.get("SSZ");
int sszop = ssz1 - sszp;
return sszop == SPIN;
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return su2_triangle_inequality(I1.get("II1"), I2.get("II1"), I3.get("II1"))
&& su2_triangle_inequality(I1.get("II2"), I2.get("II2"), I3.get("II2")) && u1_equality(I1.get("SSZ"), I2.get("SSZ"), I3.get("SSZ"));
}
// Multiplicity of the I=(II1,II2) subspace = (2I1+1)(2I2+1) = II1 II2.
size_t mult(const Invar &I) const override { return I.get("II1") * I.get("II2"); }
// We always must have I1 >= 0 and I2 >= 0.
bool Invar_allowed(const Invar &I) const override { return (I.get("II1") > 0) && (I.get("II2") > 0); }
// This function supports isospin doublets with respect to either first or the
// second isospin quantum number. Since the doublet operators are either doublets
// with respect to one or another, this function should always return a non-zero
// value!
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
check_abs_diff(Ip, I1, "SSZ", 1);
const int ii1p = Ip.get("II1");
const int ii11 = I1.get("II1");
const int ii2p = Ip.get("II2");
const int ii21 = I1.get("II2");
if (abs(ii11 - ii1p) == 1) {
const double isofactor1 = (ii11 == ii1p + 1 ? ISO(ii1p) + 1.0 : ISO(ii1p));
my_assert(ii2p == ii21);
my_assert(ii2p >= 1);
const double isofactor2 = ii2p; // multiplicity wrt 2nd isospin quantum number
return isofactor1 * isofactor2;
}
if (abs(ii21 - ii2p) == 1) {
const double isofactor1 = (ii21 == ii2p + 1 ? ISO(ii2p) + 1.0 : ISO(ii2p));
my_assert(ii1p == ii11);
my_assert(ii1p >= 1);
const double isofactor2 = ii1p;
return isofactor1 * isofactor2;
}
my_assert_not_reached();
}
void load() override {
switch (P.channels) {
case 2:
#include "dblisosz/dblisosz-2ch-In2.dat"
#include "dblisosz/dblisosz-2ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
auto trSZ = 0.0, trSZ2 = 0.0; // Tr[S_z], Tr[S_z^2]
auto trIZ12 = 0.0; // Tr[I1_z^2]
auto trIZ22 = 0.0; // Tr[I2_z^2]
for (const auto &[I, eig]: diag) {
const int ii1 = I.get("II1");
const int ii2 = I.get("II2");
const int ssz = I.get("SSZ");
const auto sumZ = this->calculate_Z(I, eig, factor);
trSZ += sumZ * SZ(ssz);
trSZ2 += sumZ * pow(SZ(ssz),2); // isospin multiplicity contained in sumZ
trIZ12 += sumZ * (ii1 * ii1 - 1) / 12.;
trIZ22 += sumZ * (ii2 * ii2 - 1) / 12.;
}
stats.td.set("<Sz>", trSZ / stats.Z);
stats.td.set("<Sz^2>", trSZ2 / stats.Z);
stats.td.set("<Q1^2>", (4 * trIZ12) / stats.Z);
stats.td.set("<Q2^2>", (4 * trIZ22) / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_GLOBAL; // HAS_TRIPLET;
};
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
template<typename SC>
void SymmetryDBLISOSZ<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 2:
#include "dblisosz/dblisosz-2ch-offdiag.dat"
break;
default: my_assert_not_reached();
}
}
}
#include "nrg-recalc-DBLISOSZ.hpp"
| 4,319
|
C++
|
.h
| 104
| 36.788462
| 185
| 0.621519
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,673
|
nrg-recalc-ISO.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-ISO.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-ISO.cc.m4, not nrg-recalc-ISO.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Feb 2006
// This file pertains to (I,S) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetryISO<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii1 = I1.get("II");
int ss1 = I1.get("SS");
Invar Ip;
Ip = Invar(ii1 - 1, ss1 + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso/iso-1ch-doubletmp.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-1ch-doubletmp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso/iso-2ch-doubletmp.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-2ch-doubletmp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1-1, ss1-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso/iso-1ch-doubletmm.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-1ch-doubletmm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso/iso-2ch-doubletmm.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-2ch-doubletmm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1+1, ss1+1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso/iso-1ch-doubletpp.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-1ch-doubletpp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso/iso-2ch-doubletpp.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-2ch-doubletpp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1+1, ss1-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso/iso-1ch-doubletpm.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-1ch-doubletpm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso/iso-2ch-doubletpm.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-2ch-doubletpm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
default: my_assert_not_reached();
};
}
return cnew;
}
template<typename SC>
Opch<SC> SymmetryISO<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
Invar I1;
// NOTE: ii,ss only couples to ii+-1,ss+-1 in general, even for
// several channels.
int iip = Ip.get("II");
int ssp = Ip.get("SS");
// NN is index n of f_n, the last site in the chain prior to adding
// the new site (f_{n+1}).
int NN = step.getnn();
I1 = Invar(iip + 1, ssp + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-1ch-spinup-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-1ch-spinup-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-2ch-spinup-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-2ch-spinup-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-2ch-spinup-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-2ch-spinup-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 3: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spinup-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spinup-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spinup-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spinup-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spinup-isoupc.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spinup-isoupc.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
}; } break;
default: my_assert_not_reached();
};
I1 = Invar(iip+1, ssp-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-1ch-spindown-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-1ch-spindown-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-2ch-spindown-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-2ch-spindown-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-2ch-spindown-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-2ch-spindown-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 3: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spindown-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spindown-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spindown-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spindown-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spindown-isoupc.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spindown-isoupc.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
}; } break;
default: my_assert_not_reached();
};
I1 = Invar(iip-1, ssp+1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-1ch-spinup-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-1ch-spinup-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-2ch-spinup-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-2ch-spinup-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-2ch-spinup-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-2ch-spinup-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 3: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spinup-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spinup-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spinup-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spinup-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spinup-isodownc.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spinup-isodownc.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
}; } break;
default: my_assert_not_reached();
};
I1 = Invar(iip-1, ssp-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-1ch-spindown-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-1ch-spindown-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-2ch-spindown-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-2ch-spindown-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-2ch-spindown-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-2ch-spindown-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 3: { {
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spindown-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spindown-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spindown-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spindown-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso/iso-3ch-spindown-isodownc.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso/iso-3ch-spindown-isodownc.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
}; } break;
default: my_assert_not_reached();
};
}
return opch;
}
template<typename SC>
MatrixElements<SC> SymmetryISO<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii1 = I1.get("II");
int ss1 = I1.get("SS");
Invar Ip;
Ip = Invar(ii1, ss1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso/iso-1ch-triplets.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-1ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso/iso-2ch-triplets.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-2ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1, ss1+2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso/iso-1ch-tripletp.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-1ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso/iso-2ch-tripletp.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-2ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1, ss1-2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso/iso-1ch-tripletm.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-1ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso/iso-2ch-tripletm.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso/iso-2ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
default: my_assert_not_reached();
};
}
return cnew;
}
}
| 20,547
|
C++
|
.h
| 545
| 33.546789
| 116
| 0.582795
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,674
|
sym-QS.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QS.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_QS(const Params &P);
}
| 95
|
C++
|
.h
| 4
| 22.25
| 52
| 0.741573
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,675
|
sym-QST.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QST.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_QST(const Params &P);
}
| 96
|
C++
|
.h
| 4
| 22.5
| 53
| 0.744444
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,676
|
sym-ISOLR.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-ISOLR.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_ISOLR(const Params &P);
template <typename S>
std::unique_ptr<Symmetry<S>> mk_ISO2LR(const Params &P);
}
| 178
|
C++
|
.h
| 6
| 28.166667
| 56
| 0.751479
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,677
|
sym-DBLSU2-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-DBLSU2-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryDBLSU2 : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryDBLSU2(const Params &P) : Symmetry<SC>(P, std::vector{"<Q1^2>", "<Q2^2>"}, Invar(1, 1)) {
initInvar({
{"II1", additive}, // isospin 1
{"II2", additive}, // isospin 2
});
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return su2_triangle_inequality(I1.get("II1"), I2.get("II1"), I3.get("II1"))
&& su2_triangle_inequality(I1.get("II2"), I2.get("II2"), I3.get("II2"));
}
// Multiplicity of the I=(II1,II2) subspace = (2I1+1)(2I2+1) = II1 II2.
size_t mult(const Invar &I) const override { return I.get("II1") * I.get("II2"); }
// We always must have I1 >= 0 and I2 >= 0.
bool Invar_allowed(const Invar &I) const override { return (I.get("II1") > 0) && (I.get("II2") > 0); }
// TO DO: support for the doublets wrt the second quantum number
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
const int ii1p = Ip.get("II1");
const int ii11 = I1.get("II1");
my_assert(abs(ii11 - ii1p) == 1);
const double isofactor = (ii11 == ii1p + 1 ? ISO(ii1p) + 1.0 : ISO(ii1p));
return isofactor;
}
void load() override {
switch (P.channels) {
case 2:
#include "dblsu2/dblsu2-2ch-In2.dat"
#include "dblsu2/dblsu2-2ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trIZ12; // Tr[I1_z^2]
bucket trIZ22; // Tr[I2_z^2]
for (const auto &[I, eig]: diag) {
const int ii1 = I.get("II1");
const int ii2 = I.get("II2");
const double sumZ = this->calculate_Z(I, eig, factor);
trIZ12 += sumZ * (ii1 * ii1 - 1) / 12.;
trIZ22 += sumZ * (ii2 * ii2 - 1) / 12.;
}
stats.td.set("<Q1^2>", (4 * trIZ12) / stats.Z);
stats.td.set("<Q2^2>", (4 * trIZ22) / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_GLOBAL;
};
// see sym-SU2.cc
#undef OFFDIAG_1
#define OFFDIAG_1(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef OFFDIAG_2
#define OFFDIAG_2(i, j, ch, factor) offdiag_function(step, i, j, ch, 1, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
template<typename SC>
void SymmetryDBLSU2<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 2:
#include "dblsu2/dblsu2-2ch-offdiag-1.dat"
#include "dblsu2/dblsu2-2ch-offdiag-2.dat"
break;
default: my_assert_not_reached();
}
}
}
#include "nrg-recalc-DBLSU2.hpp"
| 2,972
|
C++
|
.h
| 75
| 35.613333
| 183
| 0.634755
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,678
|
nrg-recalc-QSZLR.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-QSZLR.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-QSZLR.cc.m4, not nrg-recalc-QSZLR.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, June 2006
// This file pertains to (Q,Sz,P) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
Opch<SC> SymmetryQSZLR<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int qp = Ip.get("Q");
int sszp = Ip.get("SSZ");
int pp = Ip.get("P");
// NOTE: q,ssz only couples to q+1,ssz+-1 in general, even for
// several channels.
// ****** CASE I: SAME PARITY ******
Invar I1;
I1 = Invar(qp + 1, sszp + 1, pp);
{
nrglog('f', "RECALC_F(fn=" << "qszlr/qszlr-2ch-spinupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qszlr/qszlr-2ch-spinupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qszlr/qszlr-2ch-spinupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qszlr/qszlr-2ch-spinupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, sszp - 1, pp);
{
nrglog('f', "RECALC_F(fn=" << "qszlr/qszlr-2ch-spindowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qszlr/qszlr-2ch-spindowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qszlr/qszlr-2ch-spindownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qszlr/qszlr-2ch-spindownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
// ****** CASE II: DIFFERENT PARITY ******
I1 = Invar(qp + 1, sszp + 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "qszlr/qszlr-2ch-spinupdiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qszlr/qszlr-2ch-spinupdiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qszlr/qszlr-2ch-spinupdiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qszlr/qszlr-2ch-spinupdiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, sszp - 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "qszlr/qszlr-2ch-spindowndiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qszlr/qszlr-2ch-spindowndiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qszlr/qszlr-2ch-spindowndiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qszlr/qszlr-2ch-spindowndiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
}
| 4,778
|
C++
|
.h
| 125
| 34.096
| 94
| 0.587192
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,679
|
sym-P.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-P.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_P(const Params &P);
}
| 94
|
C++
|
.h
| 4
| 22
| 51
| 0.738636
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,680
|
nrg-recalc-QST.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-QST.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-QST.cc.m4, not nrg-recalc-QST.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Aug 2015
// This file pertains to (Q,S,T) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
// Recalculate matrix elements of a doublet tensor operator
template<typename SC>
MatrixElements<SC> SymmetryQST<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int ss1 = I1.get("SS");
int t1 = I1.get("T");
double T = t1; // trick!
double S = (ss1 - 1.) / 2.;
Invar Ip;
// Two different lengths: D_3CH_a and D_3CH_b
// Invar(1,2,1) is correct. 1 = add charge, 2 = doublet,
// 1 = triplet (because working with abs orbital momentum QNs)
Ip = Invar(q1 - 1, ss1 + 1, t1 - 1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-doubletp-1.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-doubletp-1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
Ip = Invar(q1 - 1, ss1 - 1, t1 - 1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-doubletm-1.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-doubletm-1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
Ip = Invar(q1 - 1, ss1 + 1, t1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-doubletp0.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-doubletp0.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
Ip = Invar(q1 - 1, ss1 - 1, t1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-doubletm0.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-doubletm0.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
Ip = Invar(q1 - 1, ss1 + 1, t1 + 1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-doubletp+1.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-doubletp+1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
Ip = Invar(q1 - 1, ss1 - 1, t1 + 1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-doubletm+1.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-doubletm+1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
}
return cnew;
}
// ch=1 <-> Tz=+1
// ch=2 <-> Tz=0
// ch=3 <-> Tz=-1
// Driver routine for recalc_f()
template<typename SC>
Opch<SC> SymmetryQST<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int qp = Ip.get("Q");
int ssp = Ip.get("SS");
int tp = Ip.get("T");
double T = tp; // trick!
Invar I1;
// The different files just correspond to contributions computed
// for various d[CR,sz,tz] operators.
// Check: there should not be any lines with equal subspaces
// indexes in different files!! That's indeed the case for the
// generated files for symtype=QST.
I1 = Invar(qp + 1, ssp + 1, tp + 1);
{
nrglog('f', "RECALC_F(fn=" << "qst/qst-spinup+1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qst/qst-spinup+1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp + 1, tp);
{
nrglog('f', "RECALC_F(fn=" << "qst/qst-spinup0.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qst/qst-spinup0.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp + 1, tp - 1);
{
nrglog('f', "RECALC_F(fn=" << "qst/qst-spinup-1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qst/qst-spinup-1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, tp + 1);
{
nrglog('f', "RECALC_F(fn=" << "qst/qst-spindo+1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qst/qst-spindo+1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, tp);
{
nrglog('f', "RECALC_F(fn=" << "qst/qst-spindo0.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qst/qst-spindo0.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, tp - 1);
{
nrglog('f', "RECALC_F(fn=" << "qst/qst-spindo-1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qst/qst-spindo-1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
// Recalculate matrix elements of a triplet tenzor operator
template<typename SC>
MatrixElements<SC> SymmetryQST<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int ss1 = I1.get("SS");
int t1 = I1.get("T");
double S = (ss1 - 1.) / 2.;
double T = t1; // trick!
Invar Ip;
Ip = Invar(q1, ss1, t1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-triplets.dat" << ", Iop=" << Invar(0, 3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, 0));
}
}
};
Ip = Invar(q1, ss1 + 2, t1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-tripletp.dat" << ", Iop=" << Invar(0, 3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, 0));
}
}
};
Ip = Invar(q1, ss1 - 2, t1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-tripletm.dat" << ", Iop=" << Invar(0, 3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, 0));
}
}
};
}
return cnew;
}
// Recalculate matrix elements of an orbital triplet tenzor operator
template<typename SC>
MatrixElements<SC> SymmetryQST<SC>::recalc_orb_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int ss1 = I1.get("SS");
int t1 = I1.get("T");
double S = (ss1 - 1.) / 2.;
double T = t1; // trick!
Invar Ip;
// 0 = chargeless
// 1 = spin singlet (deg=2S+1=1)
// 1 = spin triplet (T=1)
Ip = Invar(q1, ss1, t1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-orb-triplets.dat" << ", Iop=" << Invar(0, 1, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-orb-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 1, 1));
}
}
};
Ip = Invar(q1, ss1, t1 + 1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-orb-tripletp.dat" << ", Iop=" << Invar(0, 1, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-orb-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 1, 1));
}
}
};
Ip = Invar(q1, ss1, t1 - 1);
{
nrglog('f', "RECALC(fn=" << "qst/qst-orb-tripletm.dat" << ", Iop=" << Invar(0, 1, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qst/qst-orb-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 1, 1));
}
}
};
}
return cnew;
}
}
| 11,334
|
C++
|
.h
| 313
| 32.102236
| 120
| 0.577834
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,681
|
sym-DBLSU2.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-DBLSU2.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_DBLSU2(const Params &P);
}
| 99
|
C++
|
.h
| 4
| 23.25
| 56
| 0.752688
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,682
|
sym-PP.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-PP.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_PP(const Params &P);
}
| 95
|
C++
|
.h
| 4
| 22.25
| 52
| 0.741573
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,683
|
nrg-recalc-QJ.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-QJ.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-QJ.cc.m4, not nrg-recalc-QJ.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Mar 2016
// This file pertains to (Q,J) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
// Recalculate matrix elements of a doublet tensor operator
template<typename SC>
MatrixElements<SC> SymmetryQJ<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int jj1 = I1.get("JJ");
Invar Ip;
Ip = Invar(q1 - 1, jj1 + 1);
{
nrglog('f', "RECALC(fn=" << "qj/qj-doubletp.dat" << ", Iop=" << Invar(1, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qj/qj-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2));
}
}
};
Ip = Invar(q1 - 1, jj1 - 1);
{
nrglog('f', "RECALC(fn=" << "qj/qj-doubletm.dat" << ", Iop=" << Invar(1, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qj/qj-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2));
}
}
};
}
return cnew;
}
#undef If
#define If(cond, a, b) (cond ? a : b)
// Recalculate matrix elements of a quadruplet tensor operator
template<typename SC>
MatrixElements<SC> SymmetryQJ<SC>::recalc_quadruplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int jj1 = I1.get("JJ");
// double J = (jj1-1.0)/2.0;
Invar Ip;
Ip = Invar(q1 - 1, jj1 + 3);
{
nrglog('f', "RECALC(fn=" << "qj/qj-quad1.dat" << ", Iop=" << Invar(1, 4) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qj/qj-quad1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 4));
}
}
};
Ip = Invar(q1 - 1, jj1 + 1);
{
nrglog('f', "RECALC(fn=" << "qj/qj-quad2.dat" << ", Iop=" << Invar(1, 4) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qj/qj-quad2.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 4));
}
}
};
Ip = Invar(q1 - 1, jj1 - 1);
{
nrglog('f', "RECALC(fn=" << "qj/qj-quad3.dat" << ", Iop=" << Invar(1, 4) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qj/qj-quad3.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 4));
}
}
};
Ip = Invar(q1 - 1, jj1 - 3);
{
nrglog('f', "RECALC(fn=" << "qj/qj-quad4.dat" << ", Iop=" << Invar(1, 4) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qj/qj-quad4.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 4));
}
}
};
}
return cnew;
}
template<typename SC>
Opch<SC> SymmetryQJ<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int qp = Ip.get("Q");
int jjp = Ip.get("JJ");
double j = J(jjp);
Invar I1;
I1 = Invar(qp + 1, jjp + 3);
{
nrglog('f', "RECALC_F(fn=" << "qj/qj-spin_j3_2-jz3_2.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qj/qj-spin_j3_2-jz3_2.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, jjp + 1);
{
nrglog('f', "RECALC_F(fn=" << "qj/qj-spin_j1_2-jz1_2.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qj/qj-spin_j1_2-jz1_2.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qj/qj-spin_j3_2-jz1_2.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qj/qj-spin_j3_2-jz1_2.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, jjp - 1);
{
nrglog('f', "RECALC_F(fn=" << "qj/qj-spin_j1_2-jz-1_2.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qj/qj-spin_j1_2-jz-1_2.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qj/qj-spin_j3_2-jz-1_2.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qj/qj-spin_j3_2-jz-1_2.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, jjp - 3);
{
nrglog('f', "RECALC_F(fn=" << "qj/qj-spin_j3_2-jz-3_2.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qj/qj-spin_j3_2-jz-3_2.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
}
| 7,080
|
C++
|
.h
| 200
| 31.395
| 118
| 0.577378
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,684
|
nrg-recalc-ISO2LR.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-ISO2LR.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-ISOLR.cc.m4, not nrg-recalc-ISOLR.cc !!!
// Quantum number dependent recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Feb 2006, June 2006, Nov 2007, May 2008
// This file pertains to (I,S,P) subspaces
// Version for EVEN number of impurities
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
double sign(double x) {
if (x > 0.0) return +1.0;
if (x < 0.0) return -1.0;
my_assert_not_reached();
}
// (ISOLR): 8 calls of recalc_f() are necessary: different parities are also possible!
template<typename SC>
Opch<SC> SymmetryISO2LR<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
Invar I1;
// NOTE: ii,ss only couples to ii+-1,ss+-1 in general, even for
// several channels.
int iip = Ip.get("II");
int ssp = Ip.get("SS");
// IMPORTANT NEW ELEMENT: the parity is important here!!
int pp = Ip.get("P");
// nn is index n of f_n, the last site in the chain prior to adding
// the new site (f_{n+1}).
int NN = step.getnn();
// Both parities yield non-zero <I+-1/2, S+-1/2, P| a^\mu_\nu
// |I,S,P'>. Coefficients *DO* depend on P,P', or more accurately,
// on whether or not P and P' are the same.
//
// Observation: due to reflection symmetry, the coefficient for 'a' and
// 'b' (2 channels) are either all the same or differ in sign.
// ****** CASE I: SAME PARITY ******
I1 = Invar(iip + 1, ssp + 1, pp);
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spinup-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spinup-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spinup-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spinup-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip + 1, ssp - 1, pp);
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spindown-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spindown-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spindown-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spindown-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip - 1, ssp + 1, pp);
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spinup-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spinup-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spinup-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spinup-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip - 1, ssp - 1, pp);
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spindown-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spindown-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spindown-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spindown-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
// ****** CASE II: DIFFERENT PARITY ******
I1 = Invar(iip + 1, ssp + 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spinup-isoupdiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spinup-isoupdiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spinup-isoupdiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spinup-isoupdiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip + 1, ssp - 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spindown-isoupdiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spindown-isoupdiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spindown-isoupdiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spindown-isoupdiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip - 1, ssp + 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spinup-isodowndiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spinup-isodowndiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spinup-isodowndiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spinup-isodowndiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip - 1, ssp - 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spindown-isodowndiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spindown-isodowndiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2lr/iso2lr-2ch-spindown-isodowndiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-spindown-isodowndiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
// Recalculate matrix elements of a doublet tensor operator [EVEN PARITY]
template<typename SC>
MatrixElements<SC> SymmetryISO2LR<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii1 = I1.get("II");
int ss1 = I1.get("SS");
int p1 = I1.get("P");
Invar Ip;
Ip = Invar(ii1 - 1, ss1 + 1, p1);
{
nrglog('f', "RECALC(fn=" << "iso2lr/iso2lr-2ch-doubletmp.dat" << ", Iop=" << Invar(2, 2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-doubletmp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2, +1));
}
}
};
Ip = Invar(ii1 - 1, ss1 - 1, p1);
{
nrglog('f', "RECALC(fn=" << "iso2lr/iso2lr-2ch-doubletmm.dat" << ", Iop=" << Invar(2, 2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-doubletmm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2, +1));
}
}
};
Ip = Invar(ii1 + 1, ss1 + 1, p1);
{
nrglog('f', "RECALC(fn=" << "iso2lr/iso2lr-2ch-doubletpp.dat" << ", Iop=" << Invar(2, 2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-doubletpp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2, +1));
}
}
};
Ip = Invar(ii1 + 1, ss1 - 1, p1);
{
nrglog('f', "RECALC(fn=" << "iso2lr/iso2lr-2ch-doubletpm.dat" << ", Iop=" << Invar(2, 2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-doubletpm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2, +1));
}
}
};
}
return cnew;
}
// Recalculate matrix elements of a triplet tensor operator [EVEN PARITY]
template<typename SC>
MatrixElements<SC> SymmetryISO2LR<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii1 = I1.get("II");
int ss1 = I1.get("SS");
int p1 = I1.get("P");
Invar Ip;
Ip = Invar(ii1, ss1, p1);
{
nrglog('f', "RECALC(fn=" << "iso2lr/iso2lr-2ch-triplets.dat" << ", Iop=" << Invar(1, 3, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3, +1));
}
}
};
Ip = Invar(ii1, ss1 + 2, p1);
{
nrglog('f', "RECALC(fn=" << "iso2lr/iso2lr-2ch-tripletp.dat" << ", Iop=" << Invar(1, 3, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3, +1));
}
}
};
Ip = Invar(ii1, ss1 - 2, p1);
{
nrglog('f', "RECALC(fn=" << "iso2lr/iso2lr-2ch-tripletm.dat" << ", Iop=" << Invar(1, 3, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2lr/iso2lr-2ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3, +1));
}
}
};
}
return cnew;
}
}
| 14,075
|
C++
|
.h
| 357
| 35.294118
| 119
| 0.595917
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,685
|
nrg-recalc-DBLSU2.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-DBLSU2.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-DBLSU2.cc.m4, not nrg-recalc-DBLSU2.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Dec 2009
// This file pertains to (I1,I2) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetryDBLSU2<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii11 = I1.get("II1");
int ii21 = I1.get("II2");
Invar Ip;
Ip = Invar(ii11 - 1, ii21);
{
nrglog('f', "RECALC(fn=" << "dblsu2/dblsu2-2ch-doubletm0.dat" << ", Iop=" << Invar(2, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-doubletm0.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 0));
}
}
};
Ip = Invar(ii11 + 1, ii21);
{
nrglog('f', "RECALC(fn=" << "dblsu2/dblsu2-2ch-doubletp0.dat" << ", Iop=" << Invar(2, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-doubletp0.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 0));
}
}
};
Ip = Invar(ii11, ii21 - 1);
{
nrglog('f', "RECALC(fn=" << "dblsu2/dblsu2-2ch-doublet0m.dat" << ", Iop=" << Invar(0, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-doublet0m.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 2));
}
}
};
Ip = Invar(ii11, ii21 + 1);
{
nrglog('f', "RECALC(fn=" << "dblsu2/dblsu2-2ch-doublet0p.dat" << ", Iop=" << Invar(0, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-doublet0p.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 2));
}
}
};
}
return cnew;
}
template<typename SC>
Opch<SC> SymmetryDBLSU2<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
Invar I1;
int ii1p = Ip.get("II1");
int ii2p = Ip.get("II2");
// NN is index n of f_n, the last site in the chain prior to adding
// the new site (f_{n+1}).
int NN = step.getnn();
// RECALC_F_TAB_... (filename, channel_number, matrix_number, array_length)
// type 1: [f^dag_UP, f_DO]
// type 2: [f^dag_DO, f_UP]
I1 = Invar(ii1p + 1, ii2p);
{
nrglog('f', "RECALC_F(fn=" << "dblsu2/dblsu2-2ch-type1-isoup-a.dat" << ", ch=" << 0 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-type1-isoup-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "dblsu2/dblsu2-2ch-type2-isoup-a.dat" << ", ch=" << 0 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-type2-isoup-a.dat"
};
opch[0][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ii1p, ii2p + 1);
{
nrglog('f', "RECALC_F(fn=" << "dblsu2/dblsu2-2ch-type1-isoup-b.dat" << ", ch=" << 1 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-type1-isoup-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "dblsu2/dblsu2-2ch-type2-isoup-b.dat" << ", ch=" << 1 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-type2-isoup-b.dat"
};
opch[1][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ii1p - 1, ii2p);
{
nrglog('f', "RECALC_F(fn=" << "dblsu2/dblsu2-2ch-type1-isodown-a.dat" << ", ch=" << 0 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-type1-isodown-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "dblsu2/dblsu2-2ch-type2-isodown-a.dat" << ", ch=" << 0 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-type2-isodown-a.dat"
};
opch[0][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ii1p, ii2p - 1);
{
nrglog('f', "RECALC_F(fn=" << "dblsu2/dblsu2-2ch-type1-isodown-b.dat" << ", ch=" << 1 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-type1-isodown-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "dblsu2/dblsu2-2ch-type2-isodown-b.dat" << ", ch=" << 1 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblsu2/dblsu2-2ch-type2-isodown-b.dat"
};
opch[1][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
#undef SPINX
#define SPINX(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef SPINZ
#define SPINZ(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef SPINY
#define SPINY(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef Complex
#define Complex(x, y) cmpl(x, y)
template<typename SC>
void SymmetryDBLSU2<SC>::recalc_global(const Step &step, const DiagInfo<SC> &diag, const std::string name, MatrixElements<SC> &cnew) const {
if (name == "SZtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II{I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "dblsu2/dblsu2-2ch-spinz.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if constexpr (std::is_same_v<SC, std::complex<double>>) {
if (name == "SYtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II{I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "dblsu2/dblsu2-2ch-spiny.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
}
if (name == "SXtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II{I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "dblsu2/dblsu2-2ch-spinx.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
my_assert_not_reached();
}
}
| 8,766
|
C++
|
.h
| 241
| 32.070539
| 140
| 0.590663
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,686
|
sym-SPSU2LR-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SPSU2LR-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetrySPSU2LR : public SymLR<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetrySPSU2LR(const Params &P) : SymLR<SC>(P, std::vector{"<Sz^2>"}, Invar(0,1)) {
initInvar({
{"SS", additive}, // spin
{"P", multiplicative} // parity
});
}
size_t mult(const Invar &I) const override { return I.get("SS"); }
bool Invar_allowed(const Invar &I) const override { return I.get("SS") > 0; }
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return su2_triangle_inequality(I1.get("SS"), I2.get("SS"), I3.get("SS")) && z2_equality(I1.get("P"), I2.get("P"), I3.get("P"));
}
void load() override {
my_assert(P.channels == 2);
#include "spsu2lr/spsu2lr-2ch-In2.dat"
#include "spsu2lr/spsu2lr-2ch-QN.dat"
}
double dynamicsusceptibility_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 0);
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
my_assert((abs(ss1 - ssp) == 2 || ss1 == ssp));
return switch3(ss1, ssp + 2, 1. + (ssp - 1) / 3., ssp, ssp / 3., ssp - 2, (-2. + ssp) / 3.);
}
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 1);
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
return (ss1 == ssp + 1 ? S(ssp) + 1.0 : S(ssp));
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ2; // Tr[S_z^2]
for (const auto &[I, eig]: diag) {
const int ss = I.get("SS");
const double sumZ = this->calculate_Z(I, eig, factor);
trSZ2 += sumZ * (ss * ss - 1) / 12.;
}
stats.td.set("<Sz^2>", trSZ2 / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
};
#undef ISOSPINX
#define ISOSPINX(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * 2.0 * coef.delta(step.N() + 1, ch), h, qq)
#undef ANOMALOUS
#define ANOMALOUS(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.kappa(step.N(), ch), h, qq, In, opch)
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetrySPSU2LR<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
my_assert(P.channels == 2);
int ss = I.get("SS");
#include "spsu2lr/spsu2lr-2ch-diag.dat"
#include "spsu2lr/spsu2lr-2ch-offdiag.dat"
#include "spsu2lr/spsu2lr-2ch-anomalous.dat"
#include "spsu2lr/spsu2lr-2ch-isospinx.dat"
}
}
#include "nrg-recalc-SPSU2LR.hpp"
| 3,041
|
C++
|
.h
| 71
| 39.323944
| 184
| 0.645107
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,687
|
sym-SU2-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SU2-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetrySU2 : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetrySU2(const Params &P) : Symmetry<SC>(P, std::vector{"<Q^2>"}, Invar(1)) {
initInvar({
{"II", additive} // isospin
});
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return su2_triangle_inequality(I1.get("II"), I2.get("II"), I3.get("II"));
}
// Multiplicity of the I=(II) subspace = (2I+1) = II.
size_t mult(const Invar &I) const override {
return I.get("II"); // isospin multiplicity
}
// We always must have I >= 0.
bool Invar_allowed(const Invar &I) const override { return I.get("II") > 0; }
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
const int iip = Ip.get("II");
const int ii1 = I1.get("II");
my_assert(abs(ii1 - iip) == 1);
const double isofactor = (ii1 == iip + 1 ? ISO(iip) + 1.0 : ISO(iip));
return isofactor;
}
void load() override {
switch (P.channels) {
case 1:
#include "su2/su2-1ch-In2.dat"
#include "su2/su2-1ch-QN.dat"
break;
case 2:
#include "su2/su2-2ch-In2.dat"
#include "su2/su2-2ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trIZ2; // Tr[I_z^2]
for (const auto &[I, eig]: diag) {
const int ii = I.get("II");
const double sumZ = this->calculate_Z(I, eig, factor);
trIZ2 += sumZ * (ii * ii - 1) / 12.;
}
stats.td.set("<Q^2>", (4 * trIZ2) / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_GLOBAL;
};
// For SU2, the <||f||> depend on the "type"!
// OFFDIAG_1 corresponds to the first combination, OFFDIAG_2 to the
// second combination of operators. Each of them has contributions
// in each channel.
#undef OFFDIAG_1
#define OFFDIAG_1(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef OFFDIAG_2
#define OFFDIAG_2(i, j, ch, factor) offdiag_function(step, i, j, ch, 1, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
template<typename SC>
void SymmetrySU2<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ii = I.get("II");
int NN = step.getnn();
switch (P.channels) {
case 1:
#include "su2/su2-1ch-offdiag-1.dat"
#include "su2/su2-1ch-offdiag-2.dat"
break;
case 2:
#include "su2/su2-2ch-offdiag-1.dat"
#include "su2/su2-2ch-offdiag-2.dat"
break;
default: my_assert_not_reached();
}
}
}
#include "nrg-recalc-SU2.hpp"
| 2,931
|
C++
|
.h
| 83
| 31.542169
| 180
| 0.645025
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,688
|
sym-ISO.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-ISO.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_ISO(const Params &P);
template <typename S>
std::unique_ptr<Symmetry<S>> mk_ISO2(const Params &P);
}
| 174
|
C++
|
.h
| 6
| 27.5
| 54
| 0.745455
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,689
|
sym-SPSU2T.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SPSU2T.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_SPSU2T(const Params &P);
}
| 99
|
C++
|
.h
| 4
| 23.25
| 56
| 0.752688
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,690
|
sym-QST-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QST-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryQST : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryQST(const Params &P) : Symmetry<SC>(P, std::vector{"<Sz^2>", "<Tz^2>", "<Q>", "<Q^2>"}, Invar(0,1,0), Invar(1,2,1)) {
initInvar({
{"Q", additive}, // charge
{"SS", additive}, // spin
{"T", additive} // angular momentum
});
}
// Multiplicity of the (Q,SS,T) subspace is (2S+1 = SS) times (2T+1).
size_t mult(const Invar &I) const override { return I.get("SS") * (2 * I.get("T") + 1); }
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("Q"), I2.get("Q"), I3.get("Q")) && su2_triangle_inequality(I1.get("SS"), I2.get("SS"), I3.get("SS"))
&& su2_triangle_inequality(2 * I1.get("T") + 1, 2 * I2.get("T") + 1, 2 * I3.get("T") + 1);
}
bool Invar_allowed(const Invar &I) const override {
const bool spin_ok = I.get("SS") > 0;
const bool angmom_ok = I.get("T") >= 0;
return spin_ok && angmom_ok;
}
void load() override {
my_assert(!P.substeps);
my_assert(P.channels == 3);
#include "qst/qst-In2.dat"
#include "qst/qst-QN.dat"
} // load
// Same as for SYMTYPE=QS, because spin operators are angular momentum singlets.
double dynamicsusceptibility_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 0);
check_diff(Ip, I1, "T", 0);
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
my_assert((abs(ss1 - ssp) == 2 || ss1 == ssp));
return switch3(ss1, ssp + 2, 1. + (ssp - 1) / 3., ssp, ssp / 3., ssp - 2, (-2. + ssp) / 3.);
}
double dynamic_orb_susceptibility_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 0);
check_diff(Ip, I1, "SS", 0);
const int tp = Ip.get("T");
const int t1 = I1.get("T");
int ttp = 2 * tp + 1;
int tt1 = 2 * t1 + 1;
my_assert((abs(tt1 - ttp) == 2 || tt1 == ttp));
return switch3(tt1, ttp + 2, 1. + (ttp - 1) / 3., ttp, ttp / 3., ttp - 2, (-2. + ttp) / 3.);
}
// Creation operator is a spin-doublet, angular-momentum-triplet !
// See clebsch_gordan_qst.nb
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 1);
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
my_assert(abs(ss1 - ssp) == 1);
double spinfactor = (ss1 == ssp + 1 ? S(ssp) + 1.0 : S(ssp));
const int tp = Ip.get("T");
const int t1 = I1.get("T");
const int ttp = 2 * tp + 1;
const int tt1 = 2 * t1 + 1;
my_assert(abs(ttp - tt1) == 2 || ttp == tt1);
double angmomfactor;
if (tt1 == 1 && ttp == 1) {
angmomfactor = 0; // special case, two singlets don't couple
} else {
angmomfactor = switch3(tt1, ttp + 2, 1. + (ttp - 1) / 3., ttp, ttp / 3., ttp - 2, (-2. + ttp) / 3.);
}
return spinfactor * angmomfactor;
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ, trTZ, trQ, trQ2; // Tr[S_z^2], Tr[T_z^2], Tr[Q], Tr[Q^2]
for (const auto &[I, eig]: diag) {
const int q = I.get("Q");
const int ss = I.get("SS");
const int t = I.get("T");
const double sumZ = this->calculate_Z(I, eig, factor);
trQ += sumZ * q;
trQ2 += sumZ * q * q;
trSZ += sumZ * (ss * ss - 1) / 12.; // [(2S+1)(2S+1)-1]/12=S(S+1)/3
trTZ += sumZ * t * (t + 1) / 3.;
}
stats.td.set("<Sz^2>", trSZ / stats.Z);
stats.td.set("<Tz^2>", trTZ / stats.Z);
stats.td.set("<Q>", trQ / stats.Z);
stats.td.set("<Q^2>", trQ2 / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
HAS_ORB_TRIPLET;
bool recalc_f_coupled(const Invar &I1, const Invar &I2, const Invar &If) const override {
return triangle_inequality(I1, I2, If);
}
};
bool qst_exception(const unsigned int i, const unsigned int j, const Invar &I) {
// In these cases the subspace exists, but taking the T=2 or T=1
// limit shows that the coefficient is actually zero, so there is
// no contribution. (Directly computed factor is nan.)
// This exception handling is added to avoid false positives
// in error detection assertions.
int T = I.get("T");
if (i == 9 && j == 34 && T == 2) return true;
if (i == 17 && j == 23 && T == 1) return true;
if (i == 52 && j == 58 && T == 1) return true;
return false;
}
#define offdiag_qst(i, j, ch, fnr, factor0, h, qq, In, I, opch) \
{ \
const bool contributes = qq.offdiag_contributes(i, j); \
if (contributes) { \
t_matel factor; \
if (qst_exception(i, j, I)) { \
factor = 0; \
} else { \
factor = factor0; \
} \
this->offdiag_function_impl(step, i, j, ch, fnr, factor, h, qq, In, opch); \
} \
};
// We take the coefficients of the first channel (indexed as 0), because all three set are exactly the same due to
// orbital symmetry.
#undef OFFDIAG
#define OFFDIAG(i, j, factor0) offdiag_qst(i, j, 0, 0, t_matel(factor0) * coef.xi(step.N(), 0), h, qq, In, I, opch)
#undef DIAG
#define DIAG(i, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, 0), h, qq)
template<typename SC>
void SymmetryQST<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ss = I.get("SS");
int t = I.get("T");
double T = t; // crucially important to use floating point!
my_assert(!P.substeps);
my_assert(P.channels == 3);
#include "qst/qst-offdiag.dat"
#include "qst/qst-diag.dat"
}
}
#include "nrg-recalc-QST.hpp"
| 7,311
|
C++
|
.h
| 142
| 47.267606
| 180
| 0.475245
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,691
|
sym-QSLR-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QSLR-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryQSLR : public SymLR<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryQSLR(const Params &P) : SymLR<SC>(P, std::vector{"<Sz^2>", "<Q>", "<Q^2>"}, Invar(0,1,1)) {
initInvar({
{"Q", additive}, // charge
{"SS", additive}, // spin
{"P", multiplicative} // parity
});
}
// Multiplicity of the I=(Q,SS,P) subspace = 2S+1 = SS.
size_t mult(const Invar &I) const override {
return I.get("SS"); // spin multiplicity
}
bool Invar_allowed(const Invar &I) const override { return I.get("SS") > 0; }
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("Q"), I2.get("Q"), I3.get("Q")) && su2_triangle_inequality(I1.get("SS"), I2.get("SS"), I3.get("SS"))
&& z2_equality(I1.get("P"), I2.get("P"), I3.get("P"));
}
void load() override {
my_assert(P.channels == 2);
#include "qslr/qslr-2ch-In2.dat"
#include "qslr/qslr-2ch-QN.dat"
}
double dynamicsusceptibility_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 0);
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
my_assert((abs(ss1 - ssp) == 2 || ss1 == ssp));
return switch3(ss1, ssp + 2, 1. + (ssp - 1) / 3., ssp, ssp / 3., ssp - 2, (-2. + ssp) / 3.);
}
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 1);
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
return (ss1 == ssp + 1 ? S(ssp) + 1.0 : S(ssp));
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ, trQ, trQ2; // Tr[S_z^2], Tr[Q], Tr[Q^2]
for (const auto &[I, eig]: diag) {
const int ss = I.get("SS");
const int q = I.get("Q");
const double sumZ = this->calculate_Z(I, eig, factor);
trQ += sumZ * q;
trQ2 += sumZ * q * q;
trSZ += sumZ * (ss * ss - 1) / 12.;
}
stats.td.set("<Sz^2>", trSZ / stats.Z);
stats.td.set("<Q>", trQ / stats.Z);
stats.td.set("<Q^2>", trQ2 / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
};
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryQSLR<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ss = I.get("SS");
#include "qslr/qslr-2ch-diag.dat"
#include "qslr/qslr-2ch-offdiag.dat"
}
}
#include "nrg-recalc-QSLR.hpp"
| 2,982
|
C++
|
.h
| 74
| 36.297297
| 181
| 0.609191
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,692
|
nrg-recalc-SPSU2C3.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-SPSU2C3.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-SPSU2C3.cc.m4, not nrg-recalc-SPSU2C3.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Oct 2015
// This file pertains to (S,P) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
#define xRECALC_F_TAB(a, b, c) 0;
template<typename SC>
Opch<SC> SymmetrySPSU2C3<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
if constexpr (std::is_same_v<SC, std::complex<double>>) {
// CONVENTION: primed indeces are on the right side (ket)
for(const auto &[Ip, eig]: diag) {
int ssp = Ip.get("SS");
int p = Ip.get("P");
Invar I1;
// TRICK: ensure we are evaluating the expressions in the complex plane
#undef Power
#define Power(x, y) pow(cmpl(x), cmpl(y))
#undef sqrt
#define sqrt(x) csqrt(x)
I1 = Invar(ssp + 1, (p + 0) % 3);
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spinup0-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spinup0-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spinup0-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spinup0-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spinup0-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spinup0-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp - 1, (p + 0) % 3);
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spindown0-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spindown0-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spindown0-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spindown0-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spindown0-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spindown0-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp + 1, (p + 1) % 3);
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spinup1-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spinup1-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spinup1-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spinup1-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spinup1-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spinup1-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp - 1, (p + 1) % 3);
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spindown1-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spindown1-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spindown1-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spindown1-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spindown1-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spindown1-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp + 1, (p + 2) % 3);
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spinup2-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spinup2-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spinup2-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spinup2-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spinup2-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spinup2-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp - 1, (p + 2) % 3);
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spindown2-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spindown2-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spindown2-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spindown2-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2c3/spsu2c3-spindown2-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2c3/spsu2c3-spindown2-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
#undef sqrt
#undef Power
}
}
return opch;
}
}
| 9,728
|
C++
|
.h
| 253
| 34.391304
| 96
| 0.587811
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,693
|
sym-DBLQSZ.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-DBLQSZ.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_DBLQSZ(const Params &P);
}
| 99
|
C++
|
.h
| 4
| 23.25
| 56
| 0.752688
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,694
|
nrg-recalc-QSLR.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-QSLR.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-QSLR.cc.m4, not nrg-recalc-QSLR.cc !!!
// Quantum number dependent recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Feb 2006, June 2006, Aug 2006
// This file pertains to (Q,S,P) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
Opch<SC> SymmetryQSLR<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int qp = Ip.get("Q");
int ssp = Ip.get("SS");
Invar I1;
// NOTE: q,ss only couples to q+1,ss+-1 in general, even for
// several channels.
// IMPORTANT NEW ELEMENT: the parity is important here!!
int lrp = Ip.get("P");
// Both parities yield non-zero <Q+1, S+-1/2, P| a^\dag_\nu
// |Q,S,P'>. Coefficients *DO* depend on P,P', or more
// accurately, on whether or not P and P' are the same.
//
// Observation: due to reflection symmetry, the coefficient for 'a' and
// 'b' (2 channels) are either all the same or differ in sign.
// ****** CASE I: SAME PARITY ******
I1 = Invar(qp + 1, ssp + 1, lrp);
{
nrglog('f', "RECALC_F(fn=" << "qslr/qslr-2ch-spinupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qslr/qslr-2ch-spinupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qslr/qslr-2ch-spinupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qslr/qslr-2ch-spinupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, lrp);
{
nrglog('f', "RECALC_F(fn=" << "qslr/qslr-2ch-spindowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qslr/qslr-2ch-spindowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qslr/qslr-2ch-spindownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qslr/qslr-2ch-spindownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
// ****** CASE II: DIFFERENT PARITY ******
I1 = Invar(qp + 1, ssp + 1, -lrp);
{
nrglog('f', "RECALC_F(fn=" << "qslr/qslr-2ch-spinupdiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qslr/qslr-2ch-spinupdiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qslr/qslr-2ch-spinupdiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qslr/qslr-2ch-spinupdiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, -lrp);
{
nrglog('f', "RECALC_F(fn=" << "qslr/qslr-2ch-spindowndiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qslr/qslr-2ch-spindowndiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qslr/qslr-2ch-spindowndiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qslr/qslr-2ch-spindowndiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
// Recalculate matrix elements of a doublet tensor operator [EVEN PARITY]
template<typename SC>
MatrixElements<SC> SymmetryQSLR<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int ss1 = I1.get("SS");
int p1 = I1.get("P");
Invar Ip;
Ip = Invar(q1 - 1, ss1 + 1, p1);
{
nrglog('f', "RECALC(fn=" << "qslr/qslr-2ch-doubletp.dat" << ", Iop=" << Invar(1, 2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qslr/qslr-2ch-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, +1));
}
}
};
Ip = Invar(q1 - 1, ss1 - 1, p1);
{
nrglog('f', "RECALC(fn=" << "qslr/qslr-2ch-doubletm.dat" << ", Iop=" << Invar(1, 2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qslr/qslr-2ch-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, +1));
}
}
};
}
return cnew;
}
// Recalculate matrix elements of a triplet tenzor operator [EVEN PARITY]
template<typename SC>
MatrixElements<SC> SymmetryQSLR<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int ss1 = I1.get("SS");
int p1 = I1.get("P");
Invar Ip;
Ip = Invar(q1, ss1, p1);
{
nrglog('f', "RECALC(fn=" << "qslr/qslr-2ch-triplets.dat" << ", Iop=" << Invar(0, 3, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qslr/qslr-2ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, +1));
}
}
};
Ip = Invar(q1, ss1 + 2, p1);
{
nrglog('f', "RECALC(fn=" << "qslr/qslr-2ch-tripletp.dat" << ", Iop=" << Invar(0, 3, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qslr/qslr-2ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, +1));
}
}
};
Ip = Invar(q1, ss1 - 2, p1);
{
nrglog('f', "RECALC(fn=" << "qslr/qslr-2ch-tripletm.dat" << ", Iop=" << Invar(0, 3, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qslr/qslr-2ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, +1));
}
}
};
}
return cnew;
}
}
| 8,367
|
C++
|
.h
| 221
| 33.755656
| 117
| 0.590674
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,695
|
sym-SL3-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SL3-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetrySL3 : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetrySL3(const Params &P) : Symmetry<SC>(P, std::vector{"<Q1>", "<Q1^2>", "<sQ1^2>", "<Q2>", "<Q2^2>", "<sQ2^2>", "<Q3>", "<Q3^2>", "<sQ3^2>"}, Invar(0,0,0)) {
initInvar({
{"Q1", additive}, // charge in channel 1
{"Q2", additive}, // charge in channel 2
{"Q3", additive} // charge in channel 3
});
}
void load() override {
switch (P.channels) {
case 3:
#include "sl3/sl3-3ch-In2.dat"
#include "sl3/sl3-3ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trQ1, trQ12; // Tr[Q], Tr[Q^2]
bucket trQ2, trQ22;
bucket trQ3, trQ32;
for (const auto &[I, eig]: diag) {
const int q1 = I.get("Q1");
const int q2 = I.get("Q2");
const int q3 = I.get("Q3");
const double sumZ = this->calculate_Z(I, eig, factor);
trQ1 += sumZ * q1;
trQ12 += sumZ * q1 * q1;
trQ2 += sumZ * q2;
trQ22 += sumZ * q2 * q2;
trQ3 += sumZ * q3;
trQ32 += sumZ * q3 * q3;
}
stats.td.set("<Q1>", trQ1 / stats.Z);
stats.td.set("<Q1^2>", trQ12 / stats.Z);
stats.td.set("<sQ1^2>", (trQ12 / stats.Z) - pow(trQ1 / stats.Z, 2));
stats.td.set("<Q2>", trQ2 / stats.Z);
stats.td.set("<Q2^2>", trQ22 / stats.Z);
stats.td.set("<sQ2^2>", (trQ22 / stats.Z) - pow(trQ2 / stats.Z, 2));
stats.td.set("<Q3>", trQ3 / stats.Z);
stats.td.set("<Q3^2>", trQ32 / stats.Z);
stats.td.set("<sQ3^2>", (trQ32 / stats.Z) - pow(trQ3 / stats.Z, 2));
}
DECL;
HAS_DOUBLET;
HAS_GLOBAL;
};
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetrySL3<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 3:
#include "sl3/sl3-3ch-offdiag.dat"
#include "sl3/sl3-3ch-diag.dat"
break;
default: my_assert_not_reached();
}
}
}
#include "nrg-recalc-SL3.hpp"
| 2,603
|
C++
|
.h
| 72
| 31.75
| 180
| 0.595399
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,696
|
nrg-recalc-ISOSZ.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-ISOSZ.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-ISO.cc.m4, not nrg-recalc-ISO.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Feb 2006, Jan 2009
// This file pertains to (I,S) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetryISOSZ<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii1 = I1.get("II");
int ssz1 = I1.get("SSZ");
Invar Ip;
Ip = Invar(ii1 - 1, ssz1 + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-1ch-doubletmp.dat" << ", Iop=" << Invar(2, -1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-1ch-doubletmp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, -1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-2ch-doubletmp.dat" << ", Iop=" << Invar(2, -1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-2ch-doubletmp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, -1));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1-1, ssz1-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-1ch-doubletmm.dat" << ", Iop=" << Invar(2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-1ch-doubletmm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, +1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-2ch-doubletmm.dat" << ", Iop=" << Invar(2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-2ch-doubletmm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, +1));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1+1, ssz1+1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-1ch-doubletpp.dat" << ", Iop=" << Invar(2, -1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-1ch-doubletpp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, -1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-2ch-doubletpp.dat" << ", Iop=" << Invar(2, -1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-2ch-doubletpp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, -1));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1+1, ssz1-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-1ch-doubletpm.dat" << ", Iop=" << Invar(2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-1ch-doubletpm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, +1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-2ch-doubletpm.dat" << ", Iop=" << Invar(2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-2ch-doubletpm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, +1));
}
}
} } break;
default: my_assert_not_reached();
};
}
return cnew;
}
// (ISOSZ): Four calls of recalc_f() are necessary for each channel.
template<typename SC>
Opch<SC> SymmetryISOSZ<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
Invar I1;
// NOTE: ii,ss only couples to ii+-1,ss+-1 in general, even for
// several channels.
int iip = Ip.get("II");
int sszp = Ip.get("SSZ");
// NN is index n of f_n, the last site in the chain prior to adding
// the new site (f_{n+1}).
int NN = step.getnn();
I1 = Invar(iip + 1, sszp + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-1ch-spinup-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-1ch-spinup-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-2ch-spinup-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-2ch-spinup-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-2ch-spinup-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-2ch-spinup-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
I1 = Invar(iip+1, sszp-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-1ch-spindown-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-1ch-spindown-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-2ch-spindown-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-2ch-spindown-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-2ch-spindown-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-2ch-spindown-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
I1 = Invar(iip-1, sszp+1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-1ch-spinup-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-1ch-spinup-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-2ch-spinup-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-2ch-spinup-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-2ch-spinup-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-2ch-spinup-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
I1 = Invar(iip-1, sszp-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-1ch-spindown-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-1ch-spindown-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-2ch-spindown-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-2ch-spindown-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isosz/isosz-2ch-spindown-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isosz/isosz-2ch-spindown-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
}
return opch;
}
template<typename SC>
MatrixElements<SC> SymmetryISOSZ<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii1 = I1.get("II");
int ssz1 = I1.get("SSZ");
Invar Ip;
Ip = Invar(ii1, ssz1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-1ch-triplets.dat" << ", Iop=" << Invar(1, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-1ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 0));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-2ch-triplets.dat" << ", Iop=" << Invar(1, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-2ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 0));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1, ssz1+2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-1ch-tripletp.dat" << ", Iop=" << Invar(1, -2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-1ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, -2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-2ch-tripletp.dat" << ", Iop=" << Invar(1, -2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-2ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, -2));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1, ssz1-2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-1ch-tripletm.dat" << ", Iop=" << Invar(1, +2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-1ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, +2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "isosz/isosz-2ch-tripletm.dat" << ", Iop=" << Invar(1, +2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isosz/isosz-2ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, +2));
}
}
} } break;
default: my_assert_not_reached();
};
}
return cnew;
}
#undef SPINZ
#define SPINZ(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
template<typename SC>
void SymmetryISOSZ<SC>::recalc_global(const Step &step, const DiagInfo<SC> &diag, const std::string name, MatrixElements<SC> &cnew) const {
if (name == "SZtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II{I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "isosz/isosz-1ch-spinz.dat"
break;
case 2:
#include "isosz/isosz-2ch-spinz.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
my_assert_not_reached();
}
}
| 15,728
|
C++
|
.h
| 424
| 32.997642
| 139
| 0.593539
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,697
|
sym-QSZ-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QSZ-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryQSZ : public SymField<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryQSZ(const Params &P) : SymField<SC>(P, std::vector{"<Sz^2>", "<Sz>", "<Q>", "<Q^2>"}, Invar(0,0), Invar(1,2)) {
initInvar({
{"Q", additive}, // charge
{"SSZ", additive} // spin projection
});
}
bool check_SPIN(const Invar &I1, const Invar &Ip, const int &SPIN) const override {
// The spin projection of the operator is defined by the difference in Sz of both the invariant subspaces.
int ssz1 = I1.get("SSZ");
int sszp = Ip.get("SSZ");
int sszop = ssz1 - sszp;
return sszop == SPIN;
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("Q"), I2.get("Q"), I3.get("Q")) && u1_equality(I1.get("SSZ"), I2.get("SSZ"), I3.get("SSZ"));
}
void load() override {
if (!P.substeps) {
switch (P.channels) {
case 1:
#include "qsz/qsz-1ch-In2.dat"
#include "qsz/qsz-1ch-QN.dat"
break;
case 2:
#include "qsz/qsz-2ch-In2.dat"
#include "qsz/qsz-2ch-QN.dat"
break;
case 3:
#include "qsz/qsz-3ch-In2.dat"
#include "qsz/qsz-3ch-QN.dat"
break;
default: my_assert_not_reached();
} // switch
} else {
#include "qsz/qsz-1ch-In2.dat"
#include "qsz/qsz-1ch-QN.dat"
} // if
}
void make_matrix_polarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In,
const Opch<SC> &opch, const Coef<SC> &coef) const;
void make_matrix_nonpolarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In,
const Opch<SC> &opch, const Coef<SC> &coef) const;
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ, trSZ2, trQ, trQ2; // Tr[S_z], Tr[(S_z)^2], etc.
for (const auto &[I, eig]: diag) {
const int ssz = I.get("SSZ");
const int q = I.get("Q");
const double sumZ = this->calculate_Z(I, eig, factor);
trSZ += sumZ * SZ(ssz);
trSZ2 += sumZ * pow(SZ(ssz),2);
trQ += sumZ * q;
trQ2 += sumZ * pow(q,2);
}
stats.td.set("<Sz^2>", trSZ2 / stats.Z);
stats.td.set("<Sz>", trSZ / stats.Z);
stats.td.set("<Q>", trQ / stats.Z);
stats.td.set("<Q^2>", trQ2 / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
HAS_GLOBAL;
HAS_SUBSTEPS;
void show_coefficients(const Step &, const Coef<SC> &) const override;
};
// *** Helper macros for make_matrix() members in matrix.cc
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
/* i - subspace index
ch - channel (0 or 1)
number - number of electrons added in channel 'ch' in subspace 'i' */
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
// Note ch indexes the <||f||> matrix which is used to construct the Hamiltonian matrix in the new step, i.e., the
// f_{N} from the f^\dag_{N_1} f_{N} hopping term.
#undef OFFDIAG_MIX
#define OFFDIAG_MIX(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.xiR(step.N(), ch), h, qq, In, opch)
#undef RUNGHOP
#define RUNGHOP(i, j, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * coef.zetaR(step.N() + 1, 0), h, qq)
// "non-polarized" here means that the coefficients xi do not depend on spin. Note, however, that there is support
// for a global magnetic field, cf. P.globalB.
template<typename SC>
void SymmetryQSZ<SC>::make_matrix_nonpolarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In,
const Opch<SC> &opch, const Coef<SC> &coef) const {
if (!P.substeps) {
switch (P.channels) {
case 1:
#include "qsz/qsz-1ch-offdiag.dat"
#include "qsz/qsz-1ch-diag.dat"
break;
case 2:
#include "qsz/qsz-2ch-offdiag.dat"
#include "qsz/qsz-2ch-diag.dat"
if (P.rungs) {
#include "qsz/qsz-2ch-offdiag-mix.dat"
#include "qsz/qsz-2ch-runghop.dat"
}
break;
case 3:
#include "qsz/qsz-3ch-offdiag.dat"
#include "qsz/qsz-3ch-diag.dat"
break;
default: my_assert_not_reached();
}
} else {
my_assert(P.coeffactor == 1);
const auto [N, M] = step.NM();
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, M, 0, t_matel(factor0) * coef.xi(N, M), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(N + 1, M), h, qq)
#include "qsz/qsz-1ch-offdiag.dat"
#include "qsz/qsz-1ch-diag.dat"
if (P.rungs) my_assert_not_reached();
}
}
#define OFFDIAG_UP(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xiUP(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_DOWN(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xiDOWN(step.N(), ch), h, qq, In, opch)
#define DIAG_UP(i, j, ch, number) this->diag_function_half(step, i, number, coef.zetaUP(step.N() + 1, ch), h, qq)
#define DIAG_DOWN(i, j, ch, number) this->diag_function_half(step, i, number, coef.zetaDOWN(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryQSZ<SC>::make_matrix_polarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In,
const Opch<SC> &opch, const Coef<SC> &coef) const {
my_assert(!P.substeps); // not implemented!
switch (P.channels) {
case 1:
#include "qsz/qsz-1ch-offdiag-UP.dat"
#include "qsz/qsz-1ch-offdiag-DOWN.dat"
#include "qsz/qsz-1ch-diag-UP.dat"
#include "qsz/qsz-1ch-diag-DOWN.dat"
break;
case 2:
#include "qsz/qsz-2ch-offdiag-UP.dat"
#include "qsz/qsz-2ch-offdiag-DOWN.dat"
#include "qsz/qsz-2ch-diag-UP.dat"
#include "qsz/qsz-2ch-diag-DOWN.dat"
if (P.rungs) {
//#include "qsz/qsz-2ch-offdiag-mix-UP.dat"
//#include "qsz/qsz-2ch-offdiag-mix-DOWN.dat"
//#include "qsz/qsz-2ch-runghop-UP.dat"
//#include "qsz/qsz-2ch-runghop-DOWN.dat"
my_assert_not_reached();
}
break;
case 3:
#include "qsz/qsz-3ch-offdiag-UP.dat"
#include "qsz/qsz-3ch-offdiag-DOWN.dat"
#include "qsz/qsz-3ch-diag-UP.dat"
#include "qsz/qsz-3ch-diag-DOWN.dat"
break;
default: my_assert_not_reached();
}
}
template<typename SC>
void SymmetryQSZ<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In,
const Opch<SC> &opch, const Coef<SC> &coef) const {
if (P.polarized)
make_matrix_polarized(h, step, qq, I, In, opch, coef);
else
make_matrix_nonpolarized(h, step, qq, I, In, opch, coef);
}
template<typename SC>
void SymmetryQSZ<SC>::show_coefficients(const Step &step, const Coef<SC> &coef) const {
Symmetry<SC>::show_coefficients(step, coef);
if (P.rungs)
for (unsigned int i = 0; i < P.channels; i++) {
std::cout << "[" << i + 1 << "]"
<< " xi_rung(" << step.N() << ")=" << coef.xiR(step.N(), i) << " zeta_rung(" << step.N() + 1 << ")=" << coef.zetaR(step.N() + 1, i) << std::endl;
}
}
}
#include "nrg-recalc-QSZ.hpp"
| 7,621
|
C++
|
.h
| 182
| 36.730769
| 153
| 0.626417
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,698
|
sym-QSTZ-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QSTZ-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryQSTZ : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryQSTZ(const Params &P) : Symmetry<SC>(P, std::vector{"<Sz^2>", "<Tz^2>", "<Q>", "<Q^2>"}, Invar(0,1,0), Invar(1,2,1)) {
initInvar({
{"Q", additive}, // charge
{"SS", additive}, // spin
{"TZ", additive} // angular momentum
});
}
// Multiplicity of the (Q,SS,TZ) subspace is (2S+1 = SS).
size_t mult(const Invar &I) const override { return I.get("SS"); }
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("Q"), I2.get("Q"), I3.get("Q")) && su2_triangle_inequality(I1.get("SS"), I2.get("SS"), I3.get("SS"))
&& u1_equality(I1.get("TZ"), I2.get("TZ"), I3.get("TZ"));
}
bool Invar_allowed(const Invar &I) const override { return I.get("SS") > 0; }
void load() override {
my_assert(!P.substeps);
my_assert(P.channels == 3);
#include "qstz/qstz-In2.dat"
#include "qstz/qstz-QN.dat"
} // load
// Same as for SYMTYPE=QS, because spin operators are angular momentum singlets.
double dynamicsusceptibility_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 0);
check_diff(Ip, I1, "TZ", 0);
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
my_assert((abs(ss1 - ssp) == 2 || ss1 == ssp));
return switch3(ss1, ssp + 2, 1. + (ssp - 1) / 3., ssp, ssp / 3., ssp - 2, (-2. + ssp) / 3.);
}
// Creation operator is a spin-doublet, angular-momentum-triplet !
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 1);
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
my_assert(abs(ss1 - ssp) == 1);
return (ss1 == ssp + 1 ? S(ssp) + 1.0 : S(ssp));
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ2, trTZ2, trQ, trQ2; // Tr[S_z^2], Tr[T_z^2], Tr[Q], Tr[Q^2]
for (const auto &[I, eig]: diag) {
const int q = I.get("Q");
const int ss = I.get("SS");
const int tz = I.get("TZ");
const double sumZ = this->calculate_Z(I, eig, factor);
trQ += sumZ * q;
trQ2 += sumZ * q * q;
trSZ2 += sumZ * (ss * ss - 1) / 12.; // [(2S+1)(2S+1)-1]/12=S(S+1)/3
trTZ2 += sumZ * tz * tz;
}
stats.td.set("<Sz^2>", trSZ2 / stats.Z);
stats.td.set("<Tz^2>", trTZ2 / stats.Z);
stats.td.set("<Q>", trQ / stats.Z);
stats.td.set("<Q^2>", trQ2 / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
};
// We take the coefficients of the first channel (indexed as 0),
// because all three set are exactly the same due to orbital
// symmetry. [XXXX True for QST, for QSTZ we could relax this approx.]
#undef OFFDIAG
#define OFFDIAG(i, j, factor0) offdiag_function(step, i, j, 0, 0, t_matel(factor0) * coef.xi(step.N(), 0), h, qq, In, opch)
#undef DIAG
#define DIAG(i, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, 0), h, qq)
template<typename SC>
void SymmetryQSTZ<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ss = I.get("SS");
my_assert(!P.substeps);
my_assert(P.channels == 3);
#include "qstz/qstz-offdiag.dat"
#include "qstz/qstz-diag.dat"
}
}
#include "nrg-recalc-QSTZ.hpp"
| 3,636
|
C++
|
.h
| 85
| 38.8
| 181
| 0.61793
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,699
|
sym-NONE-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-NONE-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryNONE : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryNONE(const Params &P) : Symmetry<SC>(P, std::vector<std::string>{}, Invar(0)) {
initInvar({
{"x", additive} // dummy quantum number
});
}
void load() override {
switch (P.channels) {
case 1:
#include "none/none-1ch-In2.dat"
#include "none/none-1ch-QN.dat"
break;
case 2:
#include "none/none-2ch-In2.dat"
#include "none/none-2ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void make_matrix_polarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const;
void make_matrix_nonpolarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const;
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {};
DECL;
HAS_DOUBLET;
HAS_GLOBAL;
};
#undef OFFDIAG_CR_DO
#undef OFFDIAG_CR_UP
#define OFFDIAG_CR_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_CR_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 1, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef ISOSPINX
#define ISOSPINX(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * 2.0 * coef.delta(step.N() + 1, ch), h, qq)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryNONE<SC>::make_matrix_nonpolarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 1:
#include "none/none-1ch-offdiag-CR-UP.dat"
#include "none/none-1ch-offdiag-CR-DO.dat"
#include "none/none-1ch-diag.dat"
#include "none/none-1ch-Ixtot.dat"
break;
case 2:
#include "none/none-2ch-offdiag-CR-UP.dat"
#include "none/none-2ch-offdiag-CR-DO.dat"
#include "none/none-2ch-diag.dat"
#include "none/none-2ch-Ixtot.dat"
break;
default: my_assert_not_reached();
}
}
#undef OFFDIAG_CR_DO
#undef OFFDIAG_CR_UP
#define OFFDIAG_CR_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.xiDOWN(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_CR_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 1, t_matel(factor) * coef.xiUP(step.N(), ch), h, qq, In, opch)
#undef ISOSPINX
#define ISOSPINX(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * 2.0 * coef.delta(step.N() + 1, ch), h, qq)
#undef DIAG_UP
#define DIAG_UP(i, j, ch, number) this->diag_function(step, i, number, coef.zetaUP(step.N() + 1, ch), h, qq)
#undef DIAG_DOWN
#define DIAG_DOWN(i, j, ch, number) this->diag_function(step, i, number, coef.zetaDOWN(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryNONE<SC>::make_matrix_polarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 1:
#include "none/none-1ch-offdiag-CR-UP.dat"
#include "none/none-1ch-offdiag-CR-DO.dat"
#include "none/none-1ch-diag-UP.dat"
#include "none/none-1ch-diag-DOWN.dat"
#include "none/none-1ch-Ixtot.dat"
break;
case 2:
#include "none/none-2ch-offdiag-CR-UP.dat"
#include "none/none-2ch-offdiag-CR-DO.dat"
#include "none/none-2ch-diag-UP.dat"
#include "none/none-2ch-diag-DOWN.dat"
#include "none/none-2ch-Ixtot.dat"
break;
default: my_assert_not_reached();
}
}
template<typename SC>
void SymmetryNONE<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
if (P.polarized)
make_matrix_polarized(h, step, qq, I, In, opch, coef);
else
make_matrix_nonpolarized(h, step, qq, I, In, opch, coef);
}
}
#include "nrg-recalc-NONE.hpp"
| 4,320
|
C++
|
.h
| 100
| 40.37
| 194
| 0.693698
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,700
|
nrg-recalc-U1.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-U1.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-U1.cc.m4, not nrg-recalc-U1.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, June 2006, Oct 2012
// This file pertains to (Q) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
// Recalculate matrix elements of a doublet tensor operator
template<typename SC>
MatrixElements<SC> SymmetryU1<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
Invar Ip = Invar(q1 - 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "u1/u1-1ch-doublet.dat" << ", Iop=" << Invar(1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "u1/u1-1ch-doublet.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "u1/u1-2ch-doublet.dat" << ", Iop=" << Invar(1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "u1/u1-2ch-doublet.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1));
}
}
} } break;
case 3: { {
nrglog('f', "RECALC(fn=" << "u1/u1-3ch-doublet.dat" << ", Iop=" << Invar(1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "u1/u1-3ch-doublet.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1));
}
}
} } break;
default: my_assert_not_reached();
};
}
return cnew;
}
// Driver routine for recalc_f()
template<typename SC>
Opch<SC> SymmetryU1<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int qp = Ip.get("Q");
Invar I1 = Invar(qp + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "u1/u1-1ch-a-DO.dat" << ", ch=" << 0 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-1ch-a-DO.dat"
};
opch[0][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "u1/u1-1ch-a-UP.dat" << ", ch=" << 0 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-1ch-a-UP.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "u1/u1-2ch-a-DO.dat" << ", ch=" << 0 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-2ch-a-DO.dat"
};
opch[0][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "u1/u1-2ch-b-DO.dat" << ", ch=" << 1 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-2ch-b-DO.dat"
};
opch[1][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "u1/u1-2ch-a-UP.dat" << ", ch=" << 0 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-2ch-a-UP.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "u1/u1-2ch-b-UP.dat" << ", ch=" << 1 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-2ch-b-UP.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 3: { {
nrglog('f', "RECALC_F(fn=" << "u1/u1-3ch-a-DO.dat" << ", ch=" << 0 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-3ch-a-DO.dat"
};
opch[0][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "u1/u1-3ch-b-DO.dat" << ", ch=" << 1 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-3ch-b-DO.dat"
};
opch[1][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "u1/u1-3ch-c-DO.dat" << ", ch=" << 2 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-3ch-c-DO.dat"
};
opch[2][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "u1/u1-3ch-a-UP.dat" << ", ch=" << 0 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-3ch-a-UP.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "u1/u1-3ch-b-UP.dat" << ", ch=" << 1 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-3ch-b-UP.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "u1/u1-3ch-c-UP.dat" << ", ch=" << 2 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "u1/u1-3ch-c-UP.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
}; } break;
default: my_assert_not_reached();
};
}
return opch;
}
#undef SPINX
#define SPINX(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef SPINY
#define SPINY(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef SPINZ
#define SPINZ(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
template<typename SC>
void SymmetryU1<SC>::recalc_global(const Step &step, const DiagInfo<SC> &diag, const std::string name, MatrixElements<SC> &cnew) const {
if (name == "SZtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "u1/u1-1ch-spinz.dat"
break;
case 2:
#include "u1/u1-2ch-spinz.dat"
break;
case 3:
#include "u1/u1-3ch-spinz.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if constexpr (std::is_same_v<SC, std::complex<double>>) {
#undef Complex
#define Complex(x, y) cmpl(x, y)
if (name == "SYtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "u1/u1-1ch-spiny.dat"
break;
case 2:
#include "u1/u1-2ch-spiny.dat"
break;
case 3:
#include "u1/u1-3ch-spiny.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
}
if (name == "SXtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "u1/u1-1ch-spinx.dat"
break;
case 2:
#include "u1/u1-2ch-spinx.dat"
break;
case 3:
#include "u1/u1-3ch-spinx.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
my_assert_not_reached();
}
}
| 9,986
|
C++
|
.h
| 287
| 30.299652
| 136
| 0.56345
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,701
|
sym-SPSU2LR.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SPSU2LR.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_SPSU2LR(const Params &P);
}
| 100
|
C++
|
.h
| 4
| 23.5
| 57
| 0.755319
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,702
|
sym-SPSU2.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SPSU2.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_SPSU2(const Params &P);
}
| 98
|
C++
|
.h
| 4
| 23
| 55
| 0.75
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,703
|
sym-PP-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-PP-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryPP : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryPP(const Params &P) : Symmetry<SC>(P, std::vector<std::string>{}, Invar(1,1)) {
initInvar({
{"Pa", multiplicative}, // fermion parity in channel a
{"Pb", multiplicative} // fermion parity in channel b
});
}
void load() override {
switch (P.channels) {
case 2:
#include "pp/pp-2ch-In2.dat"
#include "pp/pp-2ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void make_matrix_polarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const;
void make_matrix_nonpolarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const;
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {};
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return z2_equality(I1.get("Pa"), I2.get("Pa"), I3.get("Pa")) && z2_equality(I1.get("Pb"), I2.get("Pb"), I3.get("Pb"));
}
DECL;
HAS_GLOBAL;
};
#undef OFFDIAG_CR_DO
#undef OFFDIAG_CR_UP
#undef OFFDIAG_AN_DO
#undef OFFDIAG_AN_UP
#define OFFDIAG_CR_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_CR_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 1, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_AN_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 2, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_AN_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 3, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef ISOSPINX
#define ISOSPINX(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * 2.0 * coef.delta(step.N() + 1, ch), h, qq)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryPP<SC>::make_matrix_nonpolarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 2:
#include "pp/pp-2ch-offdiag-CR-UP.dat"
#include "pp/pp-2ch-offdiag-CR-DO.dat"
#include "pp/pp-2ch-offdiag-AN-UP.dat"
#include "pp/pp-2ch-offdiag-AN-DO.dat"
#include "pp/pp-2ch-diag.dat"
#include "pp/pp-2ch-Ixtot.dat"
break;
default: my_assert_not_reached();
}
}
#undef OFFDIAG_CR_DO
#undef OFFDIAG_CR_UP
#undef OFFDIAG_AN_DO
#undef OFFDIAG_AN_UP
#define OFFDIAG_CR_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.xiDOWN(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_CR_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 1, t_matel(factor) * coef.xiUP(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_AN_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 2, t_matel(factor) * coef.xiDOWN(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_AN_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 3, t_matel(factor) * coef.xiUP(step.N(), ch), h, qq, In, opch)
#undef ISOSPINX
#define ISOSPINX(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * 2.0 * coef.delta(step.N() + 1, ch), h, qq)
#undef DIAG_UP
#define DIAG_UP(i, j, ch, number) this->diag_function(step, i, number, coef.zetaUP(step.N() + 1, ch), h, qq)
#undef DIAG_DOWN
#define DIAG_DOWN(i, j, ch, number) this->diag_function(step, i, number, coef.zetaDOWN(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryPP<SC>::make_matrix_polarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 2:
#include "pp/pp-2ch-offdiag-CR-UP.dat"
#include "pp/pp-2ch-offdiag-CR-DO.dat"
#include "pp/pp-2ch-offdiag-AN-UP.dat"
#include "pp/pp-2ch-offdiag-AN-DO.dat"
#include "pp/pp-2ch-diag-UP.dat"
#include "pp/pp-2ch-diag-DOWN.dat"
#include "pp/pp-2ch-Ixtot.dat"
break;
default: my_assert_not_reached();
}
}
template<typename SC>
void SymmetryPP<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
if (P.polarized)
make_matrix_polarized(h, step, qq, I, In, opch, coef);
else
make_matrix_nonpolarized(h, step, qq, I, In, opch, coef);
}
}
#include "nrg-recalc-PP.hpp"
| 4,834
|
C++
|
.h
| 98
| 46.693878
| 192
| 0.68333
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,704
|
sym-DBLQSZ-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-DBLQSZ-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryDBLQSZ : public SymField<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryDBLQSZ(const Params &P) : SymField<SC>(P, std::vector{"<Sz^2>", "<Sz>", "<Q1>", "<Q1^2>", "<Q2>", "<Q2^2>"}, Invar(0, 0, 0)) {
initInvar({
{"Q1", additive}, // charge 1
{"Q2", additive}, // charge 2
{"SSZ", additive} // spin projection
});
}
bool check_SPIN(const Invar &I1, const Invar &Ip, const int &SPIN) const override {
// The spin projection of the operator is defined by the difference
// in Sz of both the invariant subspaces.
int ssz1 = I1.get("SSZ");
int sszp = Ip.get("SSZ");
int sszop = ssz1 - sszp;
return sszop == SPIN;
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("Q1"), I2.get("Q1"), I3.get("Q1"))
&& u1_equality(I1.get("Q2"), I2.get("Q2"), I3.get("Q2"))
&& u1_equality(I1.get("SSZ"), I2.get("SSZ"), I3.get("SSZ"));
}
void load() override {
switch (P.channels) {
case 2:
#include "dblqsz/dblqsz-2ch-In2.dat"
#include "dblqsz/dblqsz-2ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
auto trSZ = 0.0, trSZ2 = 0.0; // Tr[S_z], Tr[S_z^2]
auto trQ1 = 0.0, trQ12 = 0.0; // Tr[Q_1], Tr[Q_1^2]
auto trQ2 = 0.0, trQ22 = 0.0; // Tr[Q_2], Tr[Q_2^2]
for (const auto &[I, eig]: diag) {
const int q1 = I.get("Q1");
const int q2 = I.get("Q2");
const int ssz = I.get("SSZ");
const auto sumZ = this->calculate_Z(I, eig, factor);
trSZ += sumZ * SZ(ssz);
trSZ2 += sumZ * pow(SZ(ssz),2);
trQ1 += sumZ * q1;
trQ12 += sumZ * pow(q1, 2);
trQ2 += sumZ * q2;
trQ22 += sumZ * pow(q2, 2);
}
stats.td.set("<Sz>", trSZ / stats.Z);
stats.td.set("<Sz^2>", trSZ2 / stats.Z);
stats.td.set("<Q1>", trQ1 / stats.Z);
stats.td.set("<Q1^2>", trQ12 / stats.Z);
stats.td.set("<Q2>", trQ2 / stats.Z);
stats.td.set("<Q2^2>", trQ22 / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_GLOBAL;
};
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryDBLQSZ<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 2:
#include "dblqsz/dblqsz-2ch-offdiag.dat"
#include "dblqsz/dblqsz-2ch-diag.dat"
break;
default: my_assert_not_reached();
}
}
}
#include "nrg-recalc-DBLQSZ.hpp"
| 3,094
|
C++
|
.h
| 82
| 33.097561
| 183
| 0.602667
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,705
|
sym-QSLR.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QSLR.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_QSLR(const Params &P);
}
| 97
|
C++
|
.h
| 4
| 22.75
| 54
| 0.747253
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,706
|
nrg-recalc-SPSU2.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-SPSU2.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-SPSU2.cc.m4, not nrg-recalc-SPSU2.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Feb 2006, Dec 2007
// This file pertains to (S) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetrySPSU2<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
if (!P.substeps) {
for(const auto &[I1, eig]: diag) {
int ss1 = I1.get("SS");
Invar Ip;
Ip = Invar(ss1 + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-1ch-doubletp.dat" << ", Iop=" << Invar(2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-2ch-doubletp.dat" << ", Iop=" << Invar(2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-2ch-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2));
}
}
} } break;
case 3: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-3ch-doubletp.dat" << ", Iop=" << Invar(2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-3ch-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ss1-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-1ch-doubletm.dat" << ", Iop=" << Invar(2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-2ch-doubletm.dat" << ", Iop=" << Invar(2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-2ch-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2));
}
}
} } break;
case 3: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-3ch-doubletm.dat" << ", Iop=" << Invar(2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-3ch-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2));
}
}
} } break;
default: my_assert_not_reached();
};
}
} else {
for(const auto &[I1, eig]: diag) {
int ss1 = I1.get("SS");
Invar Ip;
Ip = Invar(ss1 + 1);
{
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-1ch-doubletp.dat" << ", Iop=" << Invar(2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2));
}
}
};
Ip = Invar(ss1 - 1);
{
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-1ch-doubletm.dat" << ", Iop=" << Invar(2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2));
}
}
};
}
}
return cnew;
}
template<typename SC>
Opch<SC> SymmetrySPSU2<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
my_assert(!P.substeps);
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int ssp = Ip.get("SS");
Invar I1;
I1 = Invar(ssp + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-1ch-spinupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-spinupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-2ch-spinupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-2ch-spinupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-2ch-spinupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-2ch-spinupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 3: { {
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-3ch-spinupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-3ch-spinupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-3ch-spinupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-3ch-spinupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-3ch-spinupc.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-3ch-spinupc.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
I1 = Invar(ssp-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-1ch-spindowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-spindowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-2ch-spindowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-2ch-spindowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-2ch-spindownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-2ch-spindownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 3: { {
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-3ch-spindowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-3ch-spindowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-3ch-spindownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-3ch-spindownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-3ch-spindownc.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-3ch-spindownc.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
// Note: for 3ch cases, the lengths in the three channels are not the same!
// The same thing occurs for all SU(2)_spin cases, for instance for symtype=QS.
// RZ, oct 2015
}
return opch;
}
template<typename SC>
OpchChannel<SC> SymmetrySPSU2<SC>::recalc_irreduc_substeps(const Step &step, const DiagInfo<SC> &diag, const int M) const {
my_assert(P.substeps);
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int ssp = Ip.get("SS");
Invar I1;
I1 = Invar(ssp + 1);
{
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-1ch-spinupa.dat" << ", ch=" << M << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-spinupa.dat"
};
opch[M][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp - 1);
{
nrglog('f', "RECALC_F(fn=" << "spsu2/spsu2-1ch-spindowna.dat" << ", ch=" << M << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-spindowna.dat"
};
opch[M][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch[M];
}
template<typename SC>
MatrixElements<SC> SymmetrySPSU2<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
if (!P.substeps) {
for(const auto &[I1, eig]: diag) {
int ss1 = I1.get("SS");
Invar Ip;
Ip = Invar(ss1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-1ch-triplets.dat" << ", Iop=" << Invar(3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-2ch-triplets.dat" << ", Iop=" << Invar(3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-2ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3));
}
}
} } break;
case 3: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-3ch-triplets.dat" << ", Iop=" << Invar(3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-3ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ss1+2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-1ch-tripletp.dat" << ", Iop=" << Invar(3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-2ch-tripletp.dat" << ", Iop=" << Invar(3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-2ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3));
}
}
} } break;
case 3: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-3ch-tripletp.dat" << ", Iop=" << Invar(3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-3ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ss1-2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-1ch-tripletm.dat" << ", Iop=" << Invar(3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-1ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spsu2/spsu2-2ch-tripletm.dat" << ", Iop=" << Invar(3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2/spsu2-2ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3));
}
}
} } break;
default: my_assert_not_reached();
};
}
} else my_assert_not_reached();
return cnew;
}
#undef CHARGE
#define CHARGE(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef QDIFF
#define QDIFF(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef Q1
#define Q1(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef Q2
#define Q2(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef ISOSPINZ
#define ISOSPINZ(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
// NOTE: the transverse components of the isospin depend on the site
// index! This is taken into account by appropriately multiplying 'value'
// by (-1)^N.
#undef ISOSPINX
#define ISOSPINX(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *psgn(step.getnn() + 1))
#undef ISOSPINP
#define ISOSPINP(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *psgn(step.getnn() + 1))
#undef ISOSPINM
#define ISOSPINM(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *psgn(step.getnn() + 1))
template<typename SC>
void SymmetrySPSU2<SC>::recalc_global(const Step &step, const DiagInfo<SC> &diag, const std::string name, MatrixElements<SC> &cnew) const {
// NOTE: none of these are implemented for substeps==true.
if (name == "Qtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spsu2/spsu2-1ch-Qtot.dat"
break;
case 2:
#include "spsu2/spsu2-2ch-Qtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Qdiff") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "spsu2/spsu2-2ch-qdiff.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Q1") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "spsu2/spsu2-2ch-q1.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Q2") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "spsu2/spsu2-2ch-q2.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Iztot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spsu2/spsu2-1ch-Iztot.dat"
break;
case 2:
#include "spsu2/spsu2-2ch-Iztot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Ixtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spsu2/spsu2-1ch-Ixtot.dat"
break;
case 2:
#include "spsu2/spsu2-2ch-Ixtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Iptot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spsu2/spsu2-1ch-Iptot.dat"
break;
case 2:
#include "spsu2/spsu2-2ch-Iptot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Imtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spsu2/spsu2-1ch-Imtot.dat"
break;
case 2:
#include "spsu2/spsu2-2ch-Imtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
my_assert_not_reached();
}
}
| 20,624
|
C++
|
.h
| 595
| 30.203361
| 139
| 0.587001
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,707
|
nrg-recalc-ISOSZLR.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-ISOSZLR.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-ISOSZLR.cc.m4, not nrg-recalc-ISOSZLR.cc !!!
// Quantum number dependent recalculation routines
// Rok Zitko, rok.zitko@ijs.si, June 2009
// This file pertains to (I,Sz,P) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
Opch<SC> SymmetryISOSZLR<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
Invar I1;
int iip = Ip.get("II");
int sszp = Ip.get("SSZ");
int pp = Ip.get("P");
// nn is index n of f_n, the last site in the chain prior to adding
// the new site (f_{n+1}).
int NN = step.getnn();
// ****** CASE I: SAME PARITY ******
I1 = Invar(iip + 1, sszp + 1, pp);
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spinup-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spinup-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spinup-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spinup-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip + 1, sszp - 1, pp);
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spindown-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spindown-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spindown-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spindown-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip - 1, sszp + 1, pp);
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spinup-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spinup-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spinup-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spinup-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip - 1, sszp - 1, pp);
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spindown-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spindown-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spindown-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spindown-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
// ****** CASE II: DIFFERENT PARITY ******
I1 = Invar(iip + 1, sszp + 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spinup-isoupdiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spinup-isoupdiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spinup-isoupdiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spinup-isoupdiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip + 1, sszp - 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spindown-isoupdiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spindown-isoupdiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spindown-isoupdiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spindown-isoupdiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip - 1, sszp + 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spinup-isodowndiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spinup-isodowndiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spinup-isodowndiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spinup-isodowndiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(iip - 1, sszp - 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spindown-isodowndiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spindown-isodowndiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "isoszlr/isoszlr-2ch-spindown-isodowndiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-spindown-isodowndiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
// Recalculate matrix elements of a doublet tensor operator [EVEN PARITY]
template<typename SC>
MatrixElements<SC> SymmetryISOSZLR<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii1 = I1.get("II");
int ssz1 = I1.get("SSZ");
int p1 = I1.get("P");
Invar Ip;
Ip = Invar(ii1 - 1, ssz1 + 1, p1);
{
nrglog('f', "RECALC(fn=" << "isoszlr/isoszlr-2ch-doubletmp.dat" << ", Iop=" << Invar(2, -1, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-doubletmp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, -1, +1));
}
}
};
Ip = Invar(ii1 - 1, ssz1 - 1, p1);
{
nrglog('f', "RECALC(fn=" << "isoszlr/isoszlr-2ch-doubletmm.dat" << ", Iop=" << Invar(2, +1, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-doubletmm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, +1, +1));
}
}
};
Ip = Invar(ii1 + 1, ssz1 + 1, p1);
{
nrglog('f', "RECALC(fn=" << "isoszlr/isoszlr-2ch-doubletpp.dat" << ", Iop=" << Invar(2, -1, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-doubletpp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, -1, +1));
}
}
};
Ip = Invar(ii1 + 1, ssz1 - 1, p1);
{
nrglog('f', "RECALC(fn=" << "isoszlr/isoszlr-2ch-doubletpm.dat" << ", Iop=" << Invar(2, +1, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-doubletpm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, +1, +1));
}
}
};
}
return cnew;
}
// Recalculate matrix elements of a triplet tensor operator [EVEN PARITY]
template<typename SC>
MatrixElements<SC> SymmetryISOSZLR<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii1 = I1.get("II");
int ssz1 = I1.get("SSZ");
int p1 = I1.get("P");
Invar Ip;
Ip = Invar(ii1, ssz1, p1);
{
nrglog('f', "RECALC(fn=" << "isoszlr/isoszlr-2ch-triplets.dat" << ", Iop=" << Invar(1, 0, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 0, +1));
}
}
};
Ip = Invar(ii1, ssz1 + 2, p1);
{
nrglog('f', "RECALC(fn=" << "isoszlr/isoszlr-2ch-tripletp.dat" << ", Iop=" << Invar(1, -2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, -2, +1));
}
}
};
Ip = Invar(ii1, ssz1 - 2, p1);
{
nrglog('f', "RECALC(fn=" << "isoszlr/isoszlr-2ch-tripletm.dat" << ", Iop=" << Invar(1, +2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "isoszlr/isoszlr-2ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, +2, +1));
}
}
};
}
return cnew;
}
}
| 13,461
|
C++
|
.h
| 341
| 35.334311
| 120
| 0.595105
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,708
|
nrg-recalc-SPU1.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-SPU1.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-SPSU2.cc.m4, not nrg-recalc-SPSU2.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Dec 2008.
// This file pertains to (S) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetrySPU1<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
if (!P.substeps) {
for(const auto &[I1, eig]: diag) {
int ssz1 = I1.get("SSZ");
Invar Ip;
Ip = Invar(ssz1 + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spu1/spu1-1ch-doubletp.dat" << ", Iop=" << Invar(-1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-1ch-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(-1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spu1/spu1-2ch-doubletp.dat" << ", Iop=" << Invar(-1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-2ch-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(-1));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ssz1-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spu1/spu1-1ch-doubletm.dat" << ", Iop=" << Invar(+1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-1ch-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(+1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spu1/spu1-2ch-doubletm.dat" << ", Iop=" << Invar(+1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-2ch-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(+1));
}
}
} } break;
default: my_assert_not_reached();
};
}
} else {
for(const auto &[I1, eig]: diag) {
int ssz1 = I1.get("SSZ");
Invar Ip;
Ip = Invar(ssz1 + 1);
{
nrglog('f', "RECALC(fn=" << "spu1/spu1-1ch-doubletp.dat" << ", Iop=" << Invar(-1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-1ch-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(-1));
}
}
};
Ip = Invar(ssz1 - 1);
{
nrglog('f', "RECALC(fn=" << "spu1/spu1-1ch-doubletm.dat" << ", Iop=" << Invar(+1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-1ch-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(+1));
}
}
};
}
}
return cnew;
}
template<typename SC>
Opch<SC> SymmetrySPU1<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
my_assert(!P.substeps);
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int sszp = Ip.get("SSZ");
Invar I1;
I1 = Invar(sszp + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "spu1/spu1-1ch-spinupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1/spu1-1ch-spinupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "spu1/spu1-2ch-spinupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1/spu1-2ch-spinupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spu1/spu1-2ch-spinupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1/spu1-2ch-spinupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
I1 = Invar(sszp-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "spu1/spu1-1ch-spindowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1/spu1-1ch-spindowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "spu1/spu1-2ch-spindowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1/spu1-2ch-spindowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spu1/spu1-2ch-spindownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1/spu1-2ch-spindownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
}
return opch;
}
template<typename SC>
OpchChannel<SC> SymmetrySPU1<SC>::recalc_irreduc_substeps(const Step &step, const DiagInfo<SC> &diag, const int M) const {
my_assert(P.substeps);
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int sszp = Ip.get("SSZ");
Invar I1;
I1 = Invar(sszp + 1);
{
nrglog('f', "RECALC_F(fn=" << "spu1/spu1-1ch-spinupa.dat" << ", ch=" << M << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1/spu1-1ch-spinupa.dat"
};
opch[M][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(sszp - 1);
{
nrglog('f', "RECALC_F(fn=" << "spu1/spu1-1ch-spindowna.dat" << ", ch=" << M << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1/spu1-1ch-spindowna.dat"
};
opch[M][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch[M];
}
template<typename SC>
MatrixElements<SC> SymmetrySPU1<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
if (!P.substeps) {
for(const auto &[I1, eig]: diag) {
int ssz1 = I1.get("SSZ");
Invar Ip;
Ip = Invar(ssz1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spu1/spu1-1ch-triplets.dat" << ", Iop=" << Invar(0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-1ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spu1/spu1-2ch-triplets.dat" << ", Iop=" << Invar(0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-2ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ssz1+2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spu1/spu1-1ch-tripletp.dat" << ", Iop=" << Invar(-2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-1ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(-2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spu1/spu1-2ch-tripletp.dat" << ", Iop=" << Invar(-2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-2ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(-2));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ssz1-2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spu1/spu1-1ch-tripletm.dat" << ", Iop=" << Invar(+2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-1ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(+2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spu1/spu1-2ch-tripletm.dat" << ", Iop=" << Invar(+2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-2ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(+2));
}
}
} } break;
default: my_assert_not_reached();
};
}
} else {
for(const auto &[I1, eig]: diag) {
int ssz1 = I1.get("SSZ");
Invar Ip;
Ip = Invar(ssz1);
{
nrglog('f', "RECALC(fn=" << "spu1/spu1-1ch-triplets.dat" << ", Iop=" << Invar(0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-1ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0));
}
}
};
Ip = Invar(ssz1 + 2);
{
nrglog('f', "RECALC(fn=" << "spu1/spu1-1ch-tripletp.dat" << ", Iop=" << Invar(-2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-1ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(-2));
}
}
};
Ip = Invar(ssz1 - 2);
{
nrglog('f', "RECALC(fn=" << "spu1/spu1-1ch-tripletm.dat" << ", Iop=" << Invar(+2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1/spu1-1ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(+2));
}
}
};
}
}
return cnew;
}
#undef CHARGE
#define CHARGE(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef ISOSPINZ
#define ISOSPINZ(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
// NOTE: the transverse components of the isospin depend on the site
// index! This is taken into account by appropriately multiplying 'value'
// by (-1)^N.
#undef ISOSPINX
#define ISOSPINX(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *psgn(step.getnn() + 1))
#undef ISOSPINP
#define ISOSPINP(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *psgn(step.getnn() + 1))
#undef ISOSPINM
#define ISOSPINM(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *psgn(step.getnn() + 1))
// 2-channel only
#undef QDIFF
#define QDIFF(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef Q1
#define Q1(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef Q2
#define Q2(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef Q1UP
#define Q1UP(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef Q2UP
#define Q2UP(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef Q1DO
#define Q1DO(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef Q2DO
#define Q2DO(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
template<typename SC>
void SymmetrySPU1<SC>::recalc_global(const Step &step, const DiagInfo<SC> &diag, const std::string name, MatrixElements<SC> &cnew) const {
if (name == "Qtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spu1/spu1-1ch-Qtot.dat"
break;
case 2:
#include "spu1/spu1-2ch-Qtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Iztot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spu1/spu1-1ch-Iztot.dat"
break;
case 2:
#include "spu1/spu1-2ch-Iztot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Ixtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spu1/spu1-1ch-Ixtot.dat"
break;
case 2:
#include "spu1/spu1-2ch-Ixtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Iptot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spu1/spu1-1ch-Iptot.dat"
break;
case 2:
#include "spu1/spu1-2ch-Iptot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Imtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spu1/spu1-1ch-Imtot.dat"
break;
case 2:
#include "spu1/spu1-2ch-Imtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Qdiff") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "spu1/spu1-2ch-qdiff.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Q1") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "spu1/spu1-2ch-q1.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Q2") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "spu1/spu1-2ch-q2.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Q1UP") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "spu1/spu1-2ch-q1up.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Q2UP") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "spu1/spu1-2ch-q2up.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Q1DO") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "spu1/spu1-2ch-q1do.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Q2DO") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "spu1/spu1-2ch-q2do.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
my_assert_not_reached();
}
// XXX: use m4 macros rather than C++ macros
#undef Q1
#undef Q2
#undef Q3
}
| 18,779
|
C++
|
.h
| 580
| 27.756897
| 138
| 0.579812
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,709
|
sym-SL.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SL.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_SL(const Params &P);
}
| 95
|
C++
|
.h
| 4
| 22.25
| 52
| 0.741573
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,710
|
sym-SL-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SL-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetrySL : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetrySL(const Params &P) : Symmetry<SC>(P, std::vector{"<Q>", "<Q^2>", "<sQ^2>"}, Invar(0)) {
initInvar({
{"Q", additive} // charge
});
}
void load() override {
switch (P.channels) {
case 1:
#include "sl/sl-1ch-In2.dat"
#include "sl/sl-1ch-QN.dat"
break;
case 2:
#include "sl/sl-2ch-In2.dat"
#include "sl/sl-2ch-QN.dat"
break;
case 3:
#include "sl/sl-3ch-In2.dat"
#include "sl/sl-3ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trQ, trQ2; // Tr[Q], Tr[Q^2]
for (const auto &[I, eig]: diag) {
const int q = I.get("Q");
const double sumZ = this->calculate_Z(I, eig, factor);
trQ += sumZ * q;
trQ2 += sumZ * q * q;
}
stats.td.set("<Q>", trQ / stats.Z);
stats.td.set("<Q^2>", trQ2 / stats.Z);
// charge fluctuations -> susceptibility
stats.td.set("<sQ^2>", (trQ2 / stats.Z) - pow(trQ / stats.Z, 2));
}
DECL;
HAS_DOUBLET;
HAS_GLOBAL;
};
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetrySL<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 1:
#include "sl/sl-1ch-offdiag.dat"
#include "sl/sl-1ch-diag.dat"
break;
case 2:
#include "sl/sl-2ch-offdiag.dat"
#include "sl/sl-2ch-diag.dat"
break;
case 3:
#include "sl/sl-3ch-offdiag.dat"
#include "sl/sl-3ch-diag.dat"
break;
default: my_assert_not_reached();
}
}
}
#include "nrg-recalc-SL.hpp"
| 2,232
|
C++
|
.h
| 73
| 26.643836
| 179
| 0.628611
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,711
|
sym-QSZTZ.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QSZTZ.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_QSZTZ(const Params &P);
}
| 98
|
C++
|
.h
| 4
| 23
| 55
| 0.75
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,712
|
sym-QSZTZ-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QSZTZ-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryQSZTZ : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryQSZTZ(const Params &P) : Symmetry<SC>(P, std::vector{"<Sz>", "<Sz^2>", "<Tz>", "<Tz^2>", "<Q>", "<Q^2>"}, Invar(0,0,0), Invar(1,2,1)) {
initInvar({
{"Q", additive}, // charge
{"SZ", additive}, // spin
{"TZ", additive} // angular momentum
});
}
size_t mult(const Invar &I) const override { return 1; }
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("Q"), I2.get("Q"), I3.get("Q")) && u1_equality(I1.get("SZ"), I2.get("SZ"), I3.get("SZ"))
&& u1_equality(I1.get("TZ"), I2.get("TZ"), I3.get("TZ"));
}
bool Invar_allowed(const Invar &I) const override { return true; }
void load() override {
my_assert(!P.substeps);
my_assert(P.channels == 3);
#include "qsztz/qsztz-In2.dat"
#include "qsztz/qsztz-QN.dat"
} // load
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ, trSZ2, trTZ, trTZ2, trQ, trQ2;
for (const auto &[I, eig]: diag) {
const int q = I.get("Q");
const int ssz = I.get("SZ");
const int tz = I.get("TZ");
const double sumZ = this->calculate_Z(I, eig, factor);
trQ += sumZ * q;
trQ2 += sumZ * q * q;
trSZ += sumZ * (ssz - 1) / 2.;
trSZ2 += sumZ * pow((ssz - 1) / 2., 2);
trTZ += sumZ * tz;
trTZ2 += sumZ * tz * tz;
}
stats.td.set("<Sz>", trSZ / stats.Z);
stats.td.set("<Sz^2>", trSZ2 / stats.Z);
stats.td.set("<Tz>", trTZ / stats.Z);
stats.td.set("<Tz^2>", trTZ2 / stats.Z);
stats.td.set("<Q>", trQ / stats.Z);
stats.td.set("<Q^2>", trQ2 / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
};
// We take the coefficients of the first channel (indexed as 0), because all three set are exactly the same due to
// orbital symmetry. [Can be generalized for symmetry-broken cases if the need arises.]
#undef OFFDIAG
#define OFFDIAG(i, j, factor0) offdiag_function(step, i, j, 0, 0, t_matel(factor0) * coef.xi(step.N(), 0), h, qq, In, opch)
#undef DIAG
#define DIAG(i, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, 0), h, qq)
template<typename SC>
void SymmetryQSZTZ<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
my_assert(!P.substeps);
my_assert(P.channels == 3);
#include "qsztz/qsztz-offdiag.dat"
#include "qsztz/qsztz-diag.dat"
}
}
#include "nrg-recalc-QSZTZ.hpp"
| 2,841
|
C++
|
.h
| 69
| 37.217391
| 182
| 0.623283
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,713
|
nrg-recalc-SPU1LR.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-SPU1LR.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-SPU1LR.cc.m4, not nrg-recalc-SPU1LR.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, May 2010
// This file pertains to (SZ,P) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetrySPU1LR<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ssz1 = I1.get("SSZ");
int p1 = I1.get("P");
Invar Ip;
Ip = Invar(ssz1 + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spu1lr/spu1lr-1ch-doubletp.dat" << ", Iop=" << Invar(-1, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1lr/spu1lr-1ch-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(-1, 1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spu1lr/spu1lr-2ch-doubletp.dat" << ", Iop=" << Invar(-1, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-doubletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(-1, 1));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ssz1-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spu1lr/spu1lr-1ch-doubletm.dat" << ", Iop=" << Invar(+1, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1lr/spu1lr-1ch-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(+1, 1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spu1lr/spu1lr-2ch-doubletm.dat" << ", Iop=" << Invar(+1, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-doubletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(+1, 1));
}
}
} } break;
default: my_assert_not_reached();
};
}
return cnew;
}
template<typename SC>
Opch<SC> SymmetrySPU1LR<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int sszp = Ip.get("SSZ");
int pp = Ip.get("P");
Invar I1;
// CASE I: SAME PARITY
I1 = Invar(sszp + 1, pp);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "spu1lr/spu1lr-1ch-spinupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1lr/spu1lr-1ch-spinupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "spu1lr/spu1lr-2ch-spinupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-spinupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spu1lr/spu1lr-2ch-spinupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-spinupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
I1 = Invar(sszp-1, pp);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "spu1lr/spu1lr-1ch-spindowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1lr/spu1lr-1ch-spindowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "spu1lr/spu1lr-2ch-spindowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-spindowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spu1lr/spu1lr-2ch-spindownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-spindownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
// CASE II: OPPOSITE PARITY
if (P.channels == 2) {
I1 = Invar(sszp + 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "spu1lr/spu1lr-2ch-spinupdiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-spinupdiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spu1lr/spu1lr-2ch-spinupdiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-spinupdiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(sszp - 1, -pp);
{
nrglog('f', "RECALC_F(fn=" << "spu1lr/spu1lr-2ch-spindowndiffa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-spindowndiffa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "spu1lr/spu1lr-2ch-spindowndiffb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-spindowndiffb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
}
return opch;
}
template<typename SC>
MatrixElements<SC> SymmetrySPU1LR<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ssz1 = I1.get("SSZ");
int p1 = I1.get("P");
Invar Ip;
Ip = Invar(ssz1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spu1lr/spu1lr-1ch-triplets.dat" << ", Iop=" << Invar(0, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1lr/spu1lr-1ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spu1lr/spu1lr-2ch-triplets.dat" << ", Iop=" << Invar(0, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 1));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ssz1+2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spu1lr/spu1lr-1ch-tripletp.dat" << ", Iop=" << Invar(-2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1lr/spu1lr-1ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(-2, 1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spu1lr/spu1lr-2ch-tripletp.dat" << ", Iop=" << Invar(-2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(-2, 1));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ssz1-2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "spu1lr/spu1lr-1ch-tripletm.dat" << ", Iop=" << Invar(+2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1lr/spu1lr-1ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(+2, 1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "spu1lr/spu1lr-2ch-tripletm.dat" << ", Iop=" << Invar(+2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spu1lr/spu1lr-2ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(+2, 1));
}
}
} } break;
default: my_assert_not_reached();
};
}
return cnew;
}
#undef CHARGE
#define CHARGE(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef ISOSPINZ
#define ISOSPINZ(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
// NOTE: the transverse components of the isospin depend on the site
// index! This is taken into account by appropriately multiplying 'value'
// by (-1)^N.
#undef ISOSPINX
#define ISOSPINX(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *psgn(step.getnn() + 1))
#undef ISOSPINP
#define ISOSPINP(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *psgn(step.getnn() + 1))
#undef ISOSPINM
#define ISOSPINM(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *psgn(step.getnn() + 1))
template<typename SC>
void SymmetrySPU1LR<SC>::recalc_global(const Step &step, const DiagInfo<SC> &diag, const std::string name, MatrixElements<SC> &cnew) const {
if (name == "Qtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spu1lr/spu1lr-1ch-Qtot.dat"
break;
case 2:
#include "spu1lr/spu1lr-2ch-Qtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Iztot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spu1lr/spu1lr-1ch-Iztot.dat"
break;
case 2:
#include "spu1lr/spu1lr-2ch-Iztot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Ixtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spu1lr/spu1lr-1ch-Ixtot.dat"
break;
case 2:
#include "spu1lr/spu1lr-2ch-Ixtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Iptot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spu1lr/spu1lr-1ch-Iptot.dat"
break;
case 2:
#include "spu1lr/spu1lr-2ch-Iptot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Imtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 1:
#include "spu1lr/spu1lr-1ch-Imtot.dat"
break;
case 2:
#include "spu1lr/spu1lr-2ch-Imtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
my_assert_not_reached();
}
}
| 14,407
|
C++
|
.h
| 411
| 30.654501
| 140
| 0.59174
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,714
|
nrg-recalc-SL.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-SL.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-SL.cc.m4, not nrg-recalc-SL.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, June 2006, Nov 2007
// This file pertains to the spinless-fermions code.
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetrySL<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold)const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
Invar Ip = Invar(q1 - 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "sl/sl-1ch-doublet.dat" << ", Iop=" << Invar(1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "sl/sl-1ch-doublet.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "sl/sl-2ch-doublet.dat" << ", Iop=" << Invar(1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "sl/sl-2ch-doublet.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1));
}
}
} } break;
case 3: { {
nrglog('f', "RECALC(fn=" << "sl/sl-3ch-doublet.dat" << ", Iop=" << Invar(1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "sl/sl-3ch-doublet.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1));
}
}
} } break;
default: my_assert_not_reached();
};
}
return cnew;
}
template<typename SC>
Opch<SC> SymmetrySL<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int qp = Ip.get("Q");
Invar I1 = Invar(qp + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "sl/sl-1ch-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "sl/sl-1ch-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "sl/sl-2ch-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "sl/sl-2ch-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "sl/sl-2ch-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "sl/sl-2ch-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 3: { {
nrglog('f', "RECALC_F(fn=" << "sl/sl-3ch-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "sl/sl-3ch-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "sl/sl-3ch-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "sl/sl-3ch-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "sl/sl-3ch-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "sl/sl-3ch-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
}
return opch;
}
#undef QDIFF
#define QDIFF(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef QTOT
#define QTOT(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef N1
#define N1(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef N2
#define N2(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef N3
#define N3(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
template<typename SC>
void SymmetrySL<SC>::recalc_global(const Step &step, const DiagInfo<SC> &diag, const std::string name, MatrixElements<SC> &cnew) const {
if (name == "Qdiff") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "sl/sl-2ch-qdiff.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Qtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "sl/sl-2ch-qtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "N1") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 3:
#include "sl/sl-3ch-N1.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "N2") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 3:
#include "sl/sl-3ch-N2.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "N3") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 3:
#include "sl/sl-3ch-N3.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
my_assert_not_reached();
}
}
| 7,223
|
C++
|
.h
| 221
| 28.217195
| 136
| 0.574648
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,715
|
sym-U1-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-U1-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryU1 : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryU1(const Params &P) : Symmetry<SC>(P, std::vector{"<Q>","<Q^2>"}, Invar(0)) {
initInvar({
{"Q", additive} // charge
});
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override { return u1_equality(I1.get("Q"), I2.get("Q"), I3.get("Q")); }
void load() override {
switch (P.channels) {
case 1:
#include "u1/u1-1ch-In2.dat"
#include "u1/u1-1ch-QN.dat"
break;
case 2:
#include "u1/u1-2ch-In2.dat"
#include "u1/u1-2ch-QN.dat"
break;
case 3:
#include "u1/u1-3ch-In2.dat"
#include "u1/u1-3ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trQ, trQ2; // Tr[Q], Tr[Q^2]
for (const auto &[I, eig]: diag) {
const int q = I.get("Q");
const double sumZ = this->calculate_Z(I, eig, factor);
trQ += sumZ * q;
trQ2 += sumZ * q * q;
}
stats.td.set("<Q>", trQ / stats.Z);
stats.td.set("<Q^2>", trQ2 / stats.Z);
}
void make_matrix_pol2x2(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const;
void make_matrix_polarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const;
void make_matrix_nonpolarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const;
DECL;
HAS_DOUBLET;
HAS_GLOBAL;
};
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
#undef OFFDIAG_UP
#undef OFFDIAG_DO
#undef OFFDIAG_UPDO
#undef OFFDIAG_DOUP
#undef DIAG_UP
#undef DIAG_DOWN
#undef DIAG_DOUP
#define OFFDIAG_UP(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xiUP(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_DO(i, j, ch, factor0) offdiag_function(step, i, j, ch, 1, t_matel(factor0) * coef.xiDOWN(step.N(), ch), h, qq, In, opch)
// UPDO -> <f> from previous site for spin UP (index fnr=0)
#define OFFDIAG_UPDO(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xiUPDO(step.N(), ch), h, qq, In, opch)
// DOUP -> <f> from previous site for spin DO (index fnr=1)
#define OFFDIAG_DOUP(i, j, ch, factor0) offdiag_function(step, i, j, ch, 1, t_matel(factor0) * coef.xiDOUP(step.N(), ch), h, qq, In, opch)
// Note the _half !!
#define DIAG_UP(i, j, ch, number) this->diag_function_half(step, i, number, coef.zetaUP(step.N() + 1, ch), h, qq)
#define DIAG_DOWN(i, j, ch, number) this->diag_function_half(step, i, number, coef.zetaDOWN(step.N() + 1, ch), h, qq)
// Compare with ISOSPINX for symtype=SPSU2 case
// See also coefnew/u1/u1.m
#define DIAG_DOUP(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * coef.zetaDOUP(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryU1<SC>::make_matrix_polarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 1:
#include "u1/u1-1ch-offdiag-UP.dat"
#include "u1/u1-1ch-offdiag-DO.dat"
#include "u1/u1-1ch-diag-UP.dat"
#include "u1/u1-1ch-diag-DOWN.dat"
break;
case 2:
#include "u1/u1-2ch-offdiag-UP.dat"
#include "u1/u1-2ch-offdiag-DO.dat"
#include "u1/u1-2ch-diag-UP.dat"
#include "u1/u1-2ch-diag-DOWN.dat"
break;
case 3:
#include "u1/u1-3ch-offdiag-UP.dat"
#include "u1/u1-3ch-offdiag-DO.dat"
#include "u1/u1-3ch-diag-UP.dat"
#include "u1/u1-3ch-diag-DOWN.dat"
break;
default: my_assert_not_reached();
}
}
// Full 2x2 spin matrix structure. Added 10.9.2012
template<typename SC>
void SymmetryU1<SC>::make_matrix_pol2x2(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 1:
#include "u1/u1-1ch-offdiag-UP.dat"
#include "u1/u1-1ch-offdiag-DO.dat"
#include "u1/u1-1ch-offdiag-UPDO.dat"
#include "u1/u1-1ch-offdiag-DOUP.dat"
#include "u1/u1-1ch-diag-UP.dat"
#include "u1/u1-1ch-diag-DOWN.dat"
#include "u1/u1-1ch-diag-DOUP.dat"
break;
case 2:
#include "u1/u1-2ch-offdiag-UP.dat"
#include "u1/u1-2ch-offdiag-DO.dat"
#include "u1/u1-2ch-offdiag-UPDO.dat"
#include "u1/u1-2ch-offdiag-DOUP.dat"
#include "u1/u1-2ch-diag-UP.dat"
#include "u1/u1-2ch-diag-DOWN.dat"
#include "u1/u1-2ch-diag-DOUP.dat"
break;
case 3:
#include "u1/u1-3ch-offdiag-UP.dat"
#include "u1/u1-3ch-offdiag-DO.dat"
#include "u1/u1-3ch-offdiag-UPDO.dat"
#include "u1/u1-3ch-offdiag-DOUP.dat"
#include "u1/u1-3ch-diag-UP.dat"
#include "u1/u1-3ch-diag-DOWN.dat"
#include "u1/u1-3ch-diag-DOUP.dat"
break;
default: my_assert_not_reached();
}
}
#undef OFFDIAG_DO
#undef OFFDIAG_UP
#define OFFDIAG_DO(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
#define OFFDIAG_UP(i, j, ch, factor) offdiag_function(step, i, j, ch, 1, t_matel(factor) * coef.xi(step.N(), ch), h, qq, In, opch)
template<typename SC>
void SymmetryU1<SC>::make_matrix_nonpolarized(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
switch (P.channels) {
case 1:
#include "u1/u1-1ch-offdiag-UP.dat"
#include "u1/u1-1ch-offdiag-DO.dat"
#include "u1/u1-1ch-diag.dat"
break;
case 2:
#include "u1/u1-2ch-offdiag-UP.dat"
#include "u1/u1-2ch-offdiag-DO.dat"
#include "u1/u1-2ch-diag.dat"
break;
case 3:
#include "u1/u1-3ch-offdiag-UP.dat"
#include "u1/u1-3ch-offdiag-DO.dat"
#include "u1/u1-3ch-diag.dat"
break;
default: my_assert_not_reached();
}
}
template<typename SC>
void SymmetryU1<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
if (P.pol2x2) {
make_matrix_pol2x2(h, step, qq, I, In, opch, coef);
} else if (P.polarized) {
make_matrix_polarized(h, step, qq, I, In, opch, coef);
} else {
make_matrix_nonpolarized(h, step, qq, I, In, opch, coef);
}
}
}
#include "nrg-recalc-U1.hpp"
| 6,711
|
C++
|
.h
| 167
| 37.263473
| 192
| 0.679755
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,716
|
sym-QJ-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QJ-impl.hpp
|
#include <boost/math/special_functions/factorials.hpp>
namespace NRG {
template<typename SC>
class SymmetryQJ : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryQJ(const Params &P) : Symmetry<SC>(P, std::vector{"<Jz^2>", "<Q>", "<Q^2>"}, Invar(0,1), Invar(1,4)) {
initInvar({
{"Q", additive}, // charge
{"JJ", additive} // total angular momentum
});
}
// Multiplicity of the (Q,JJ) subspace is 2J+1 = JJ.
size_t mult(const Invar &I) const override { return I.get("JJ"); }
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("Q"), I2.get("Q"), I3.get("Q")) && su2_triangle_inequality(I1.get("JJ"), I2.get("JJ"), I3.get("JJ"));
}
bool Invar_allowed(const Invar &I) const override {
const bool spin_ok = I.get("JJ") > 0;
return spin_ok;
}
void load() override {
#include "qj/qj-In2.dat"
#include "qj/qj-QN.dat"
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trJZ2, trQ, trQ2; // Tr[J_z^2], Tr[Q], Tr[Q^2]
for (const auto &[I, eig]: diag) {
const int jj = I.get("JJ");
const int q = I.get("Q");
const double sumZ = this->calculate_Z(I, eig, factor);
trQ += sumZ * q;
trQ2 += sumZ * q * q;
trJZ2 += sumZ * (jj * jj - 1) / 12.;
}
stats.td.set("<Jz^2>", trJZ2 / stats.Z);
stats.td.set("<Q>", trQ / stats.Z);
stats.td.set("<Q^2>", trQ2 / stats.Z);
}
// ClebschGordan[ket (p), op, bra (1)]
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 1);
const int jjp = Ip.get("JJ");
const int jj1 = I1.get("JJ");
my_assert(abs(jj1 - jjp) == 1);
return (jj1 == jjp + 1 ? S(jjp) + 1.0 : S(jjp));
}
// See cg_factors_doublet_triplet_quadruplet.nb
double specdensquad_factor(const Invar &Ip, const Invar &I1) const override {
check_diff(Ip, I1, "Q", 1);
const int jjp = Ip.get("JJ");
const int jj1 = I1.get("JJ");
my_assert(abs(jj1 - jjp) == 1 || abs(jj1 - jjp) == 3);
if (jj1 == jjp + 3) return S(jjp) / 2.0 + 1.0;
if (jj1 == jjp + 1) {
my_assert(jjp >= 2); // singlet in kvadruplet se ne moreta sklopiti v dublet
return S(jjp) / 2.0 + 0.5;
}
if (jj1 == jjp - 1) {
my_assert(jjp >= 2); // trikotniska
return S(jjp) / 2.0;
}
if (jj1 == jjp - 3) {
my_assert(jjp >= 4); // trikotniska
return S(jjp) / 2.0 - 0.5;
}
my_assert_not_reached();
return 0;
}
void offdiag_function_QJ(const Step &step, const unsigned int i, const unsigned int j, const unsigned int ch, const unsigned int fnr, const t_matel factor, Matrix &h, const SubspaceDimensions &qq,
const InvarVec &In, const Opch<SC> &opch) const
{
const Invar Iop = ch == 0 ? Invar(1, 2) : Invar(1, 4);
const Invar I1 = In[i];
const Invar I2 = In[j];
const bool triangle = triangle_inequality(I1, I2, Iop); // I1 = I2+Iop
if (triangle) { offdiag_function(step, i, j, ch, fnr, factor, h, qq, In, opch); }
}
HAS_DOUBLET;
HAS_QUADRUPLET;
DECL;
};
double Factorial(const double x) { return boost::math::factorial<double>(round(x)); }
// *** Helper macros for make_matrix() members in matrix.cc
// Jndx = 0 for doublet, Jndx = 1 for quadruplet
#undef OFFDIAG
#define OFFDIAG(i, j, Jndx, factor0) offdiag_function_QJ(step, i, j, Jndx, 0, t_matel(factor0) * coef.xi(step.N(), 0), h, qq, In, opch)
#undef DIAG
#define DIAG(i, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, 0), h, qq)
inline double J(int JJ) {
return (JJ - 1.0) / 2.0; // JJ=2J+1
}
template<typename SC>
void SymmetryQJ<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int jj = I.get("JJ");
#include "qj/qj-offdiag.dat"
#include "qj/qj-diag.dat"
}
}
#include "nrg-recalc-QJ.hpp"
| 4,230
|
C++
|
.h
| 105
| 35.933333
| 199
| 0.613005
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,717
|
sym-ISOSZLR-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-ISOSZLR-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryISOSZLR : public SymFieldLR<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryISOSZLR(const Params &P) : SymFieldLR<SC>(P, std::vector{"<Sz^2>", "<Sz>", "<Q^2>"}, Invar(1,0,1)) {
initInvar({
{"II", additive}, // isospin
{"SSZ", additive}, // spin projection
{"P", multiplicative} // parity
});
}
// Multiplicity of the I=(II,SSZ) subspace = (2I+1) = II.
size_t mult(const Invar &I) const override { return I.get("II"); }
bool check_SPIN(const Invar &I1, const Invar &Ip, const int &SPIN) const override {
// The spin projection of the operator is defined by the difference
// in Sz of both the invariant subspaces.
int ssz1 = I1.get("SSZ");
int sszp = Ip.get("SSZ");
int sszop = ssz1 - sszp;
return sszop == SPIN;
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("SSZ"), I2.get("SSZ"), I3.get("SSZ")) && su2_triangle_inequality(I1.get("II"), I2.get("II"), I3.get("II"))
&& z2_equality(I1.get("P"), I2.get("P"), I3.get("P"));
}
void load() override {
my_assert(P.channels == 2);
#include "isoszlr/isoszlr-2ch-In2.dat"
#include "isoszlr/isoszlr-2ch-QN.dat"
}
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
check_abs_diff(Ip, I1, "SSZ", 1);
const int iip = Ip.get("II");
const int ii1 = I1.get("II");
const double isofactor = (ii1 == iip + 1 ? ISO(iip) + 1.0 : ISO(iip));
return isofactor;
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ, trSZ2, trIZ2; // Tr[S_z], Tr[S_z^2], Tr[I_z^2]
for (const auto &[I, eig]: diag) {
const int ii = I.get("II");
const int ssz = I.get("SSZ");
const double sumZ = this->calculate_Z(I, eig, factor);
trSZ += sumZ * SZ(ssz);
trSZ2 += sumZ * pow(SZ(ssz),2); // isospin multiplicity contained in sumZ
trIZ2 += sumZ * (ii * ii - 1) / 12.; // spin multiplicity contained in sumZ
}
stats.td.set("<Sz>", trSZ / stats.Z);
stats.td.set("<Sz^2>", trSZ2 / stats.Z);
stats.td.set("<Q^2>", (4 * trIZ2) / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
};
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
template<typename SC>
void SymmetryISOSZLR<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ii = I.get("II");
#include "isoszlr/isoszlr-2ch-offdiag.dat"
}
}
#include "nrg-recalc-ISOSZLR.hpp"
| 2,937
|
C++
|
.h
| 70
| 37.914286
| 184
| 0.631726
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,718
|
sym-NONE.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-NONE.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_NONE(const Params &P);
}
| 97
|
C++
|
.h
| 4
| 22.75
| 54
| 0.747253
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,719
|
sym-SPSU2-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SPSU2-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetrySPSU2 : public Symmetry<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetrySPSU2(const Params &P) : Symmetry<SC>(P, std::vector{"<Sz^2>"}, Invar(1)) {
initInvar({
{"SS", additive} // spin
});
}
// Multiplicity of the I=(SS) subspace = 2S+1 = SS.
size_t mult(const Invar &I) const override { return I.get("SS"); }
bool Invar_allowed(const Invar &I) const override { return I.get("SS") > 0; }
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return su2_triangle_inequality(I1.get("SS"), I2.get("SS"), I3.get("SS"));
}
void load() override {
if (!P.substeps) {
switch (P.channels) {
case 1:
#include "spsu2/spsu2-1ch-In2.dat"
#include "spsu2/spsu2-1ch-QN.dat"
break;
case 2:
#include "spsu2/spsu2-2ch-In2.dat"
#include "spsu2/spsu2-2ch-QN.dat"
break;
case 3:
#include "spsu2/spsu2-3ch-In2.dat"
#include "spsu2/spsu2-3ch-QN.dat"
break;
default: my_assert_not_reached();
}
} else {
#include "spsu2/spsu2-1ch-In2.dat"
#include "spsu2/spsu2-1ch-QN.dat"
}
}
double dynamicsusceptibility_factor(const Invar &Ip, const Invar &I1) const override {
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
my_assert(abs(ss1 - ssp) == 2 || ss1 == ssp);
return switch3(ss1, ssp + 2, 1. + (ssp - 1) / 3., ssp, ssp / 3., ssp - 2, (-2. + ssp) / 3.);
}
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
my_assert(abs(ss1 - ssp) == 1);
return (ss1 == ssp + 1 ? S(ssp) + 1.0 : S(ssp));
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ; // Tr[S_z^2]
for (const auto &[I, eig]: diag) {
const int ss = I.get("SS");
const double sumZ = this->calculate_Z(I, eig, factor);
trSZ += sumZ * (ss * ss - 1) / 12.;
}
stats.td.set("<Sz^2>", trSZ / stats.Z);
}
bool project_subspace(const Invar &I, const std::string &p) const override {
if (p == ""s || p == "trivial"s) {
return true;
} else if (p == "even"s) { // even particule number is half-interger spin, SS=1,3,5,...
return is_odd(I.get("SS"));
} else if (p == "odd"s) { // odd particle number is integer spin, SS=2,4,...
return is_even(I.get("SS"));
} else throw std::runtime_error(fmt::format("Unknown projection type {} for symmetry SPSU2.", p));
}
void show_coefficients(const Step &step, const Coef<SC> &coef) const override {
Symmetry<SC>::show_coefficients(step, coef);
if (!P.substeps) {
for (size_t i = 0; i < P.coefchannels; i++) {
const auto N = step.N();
std::cout << "[" << i + 1 << "]"
<< " Delta(" << N+1 << ")=" << coef.delta(N+1, i) << " kappa(" << N << ")=" << coef.kappa(N, i) << std::endl;
}
} else {
const auto [N, M] = step.NM();
for (auto i = 0; i < P.coeffactor; i++) {
const auto index = M + P.channels * i;
std::cout << "[" << index << "]"
<< " Delta(" << N+1 << ")=" << coef.delta(N+1, index) << " kappa(" << N << ")=" << coef.kappa(N, index) << std::endl;
}
}
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
HAS_GLOBAL;
HAS_SUBSTEPS;
};
// NOTE: the additional factor of 2 for coef.delta is due to the fact that the isospin is in fact defined as 1/2 of
// the (d^\dag d^\dag + d d) pairing operator.
template<typename SC>
void SymmetrySPSU2<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ss = I.get("SS");
if (!P.substeps) {
// conjugate the coefficient, to bring it in line with the standard convention for superconducting phases (only relevant for complex-valued parameters)
#undef ISOSPINX
#define ISOSPINX(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * 2.0 * conj_me( coef.delta(step.N() + 1, ch) ), h, qq)
#undef ANOMALOUS
#define ANOMALOUS(i, j, ch, factor) offdiag_function(step, i, j, ch, 0, t_matel(factor) * coef.kappa(step.N(), ch), h, qq, In, opch)
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
switch (P.channels) {
case 1:
#include "spsu2/spsu2-1ch-offdiag.dat"
#include "spsu2/spsu2-1ch-anomalous.dat"
#include "spsu2/spsu2-1ch-diag.dat"
#include "spsu2/spsu2-1ch-isospinx.dat"
break;
case 2:
#include "spsu2/spsu2-2ch-diag.dat"
#include "spsu2/spsu2-2ch-offdiag.dat"
#include "spsu2/spsu2-2ch-anomalous.dat"
#include "spsu2/spsu2-2ch-isospinx.dat"
break;
case 3:
#include "spsu2/spsu2-3ch-diag.dat"
#include "spsu2/spsu2-3ch-offdiag.dat"
#include "spsu2/spsu2-3ch-anomalous.dat"
#include "spsu2/spsu2-3ch-isospinx.dat"
break;
default: my_assert_not_reached();
}
} else {
my_assert(P.coeffactor == 1);
const auto [Ntrue, M] = step.NM();
#undef ISOSPINX
#define ISOSPINX(i, j, ch, factor) this->diag_offdiag_function(step, i, j, t_matel(factor) * 2.0 * conj_me( coef.delta(Ntrue + 1, M) ), h, qq)
#undef ANOMALOUS
#define ANOMALOUS(i, j, ch, factor) offdiag_function(step, i, j, M, 0, t_matel(factor) * coef.kappa(Ntrue, M), h, qq, In, opch)
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, M, 0, t_matel(factor0) * coef.xi(Ntrue, M), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(Ntrue + 1, M), h, qq)
#include "spsu2/spsu2-1ch-offdiag.dat"
#include "spsu2/spsu2-1ch-anomalous.dat"
#include "spsu2/spsu2-1ch-diag.dat"
#include "spsu2/spsu2-1ch-isospinx.dat"
}
}
}
#include "nrg-recalc-SPSU2.hpp"
| 6,191
|
C++
|
.h
| 151
| 36.821192
| 182
| 0.630098
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,720
|
nrg-recalc-QSTZ.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-QSTZ.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-QSTZ.cc.m4, not nrg-recalc-QSTZ.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Feb 2016
// This file pertains to (Q,S,Tz) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetryQSTZ<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int ss1 = I1.get("SS");
int tz1 = I1.get("TZ");
Invar Ip;
// Two different lengths: D_3CH_a and D_3CH_b
// Invar(1,2,+-1,0) is correct. 1 = add charge, 2 = doublet,
// 1 = triplet (because working with abs orbital momentum QNs)
Ip = Invar(q1 - 1, ss1 + 1, tz1 - 1);
{
nrglog('f', "RECALC(fn=" << "qstz/qstz-doubletp-1.dat" << ", Iop=" << Invar(1, 2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qstz/qstz-doubletp-1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, +1));
}
}
};
Ip = Invar(q1 - 1, ss1 - 1, tz1 - 1);
{
nrglog('f', "RECALC(fn=" << "qstz/qstz-doubletm-1.dat" << ", Iop=" << Invar(1, 2, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qstz/qstz-doubletm-1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, +1));
}
}
};
Ip = Invar(q1 - 1, ss1 + 1, tz1);
{
nrglog('f', "RECALC(fn=" << "qstz/qstz-doubletp0.dat" << ", Iop=" << Invar(1, 2, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qstz/qstz-doubletp0.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 0));
}
}
};
Ip = Invar(q1 - 1, ss1 - 1, tz1);
{
nrglog('f', "RECALC(fn=" << "qstz/qstz-doubletm0.dat" << ", Iop=" << Invar(1, 2, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qstz/qstz-doubletm0.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 0));
}
}
};
Ip = Invar(q1 - 1, ss1 + 1, tz1 + 1);
{
nrglog('f', "RECALC(fn=" << "qstz/qstz-doubletp+1.dat" << ", Iop=" << Invar(1, 2, -1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qstz/qstz-doubletp+1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, -1));
}
}
};
Ip = Invar(q1 - 1, ss1 - 1, tz1 + 1);
{
nrglog('f', "RECALC(fn=" << "qstz/qstz-doubletm+1.dat" << ", Iop=" << Invar(1, 2, -1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qstz/qstz-doubletm+1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, -1));
}
}
};
}
return cnew;
}
// ch=1 <-> Tz=+1
// ch=2 <-> Tz=0
// ch=3 <-> Tz=-1
template<typename SC>
Opch<SC> SymmetryQSTZ<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int qp = Ip.get("Q");
int ssp = Ip.get("SS");
int tzp = Ip.get("TZ");
Invar I1;
// The different files just correspond to contributions computed
// for various d[CR,sz,tz] operators.
// Check: there should not be any lines with equal subspaces
// indexes in different files!! That's indeed the case for the
// generated files for symtype=QST.
I1 = Invar(qp + 1, ssp + 1, tzp + 1);
{
nrglog('f', "RECALC_F(fn=" << "qstz/qstz-spinup+1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qstz/qstz-spinup+1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp + 1, tzp);
{
nrglog('f', "RECALC_F(fn=" << "qstz/qstz-spinup0.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qstz/qstz-spinup0.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp + 1, tzp - 1);
{
nrglog('f', "RECALC_F(fn=" << "qstz/qstz-spinup-1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qstz/qstz-spinup-1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, tzp + 1);
{
nrglog('f', "RECALC_F(fn=" << "qstz/qstz-spindo+1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qstz/qstz-spindo+1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, tzp);
{
nrglog('f', "RECALC_F(fn=" << "qstz/qstz-spindo0.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qstz/qstz-spindo0.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, tzp - 1);
{
nrglog('f', "RECALC_F(fn=" << "qstz/qstz-spindo-1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qstz/qstz-spindo-1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
template<typename SC>
MatrixElements<SC> SymmetryQSTZ<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int ss1 = I1.get("SS");
int tz1 = I1.get("TZ");
Invar Ip;
Ip = Invar(q1, ss1, tz1);
{
nrglog('f', "RECALC(fn=" << "qstz/qstz-triplets.dat" << ", Iop=" << Invar(0, 3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qstz/qstz-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, 0));
}
}
};
Ip = Invar(q1, ss1 + 2, tz1);
{
nrglog('f', "RECALC(fn=" << "qstz/qstz-tripletp.dat" << ", Iop=" << Invar(0, 3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qstz/qstz-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, 0));
}
}
};
Ip = Invar(q1, ss1 - 2, tz1);
{
nrglog('f', "RECALC(fn=" << "qstz/qstz-tripletm.dat" << ", Iop=" << Invar(0, 3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qstz/qstz-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, 0));
}
}
};
}
return cnew;
}
}
| 9,146
|
C++
|
.h
| 249
| 32.606426
| 117
| 0.579126
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,721
|
nrg-recalc-PP.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-PP.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-PP.cc.m4, not nrg-recalc-PP.cc !!!
// Quantum number dependent recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Aug 2017
// This file pertains to the case with only fermion number parities
// (one per channel).
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
Opch<SC> SymmetryPP<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int pa = Ip.get("Pa");
int pb = Ip.get("Pb");
{
Invar I1 = Invar(-pa, pb);
{
nrglog('f', "RECALC_F(fn=" << "pp/pp-2ch-a-CR-DO.dat" << ", ch=" << 0 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "pp/pp-2ch-a-CR-DO.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "pp/pp-2ch-a-CR-UP.dat" << ", ch=" << 0 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "pp/pp-2ch-a-CR-UP.dat"
};
opch[0][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "pp/pp-2ch-a-AN-DO.dat" << ", ch=" << 0 << ", n=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "pp/pp-2ch-a-AN-DO.dat"
};
opch[0][2][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "pp/pp-2ch-a-AN-UP.dat" << ", ch=" << 0 << ", n=" << 3 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "pp/pp-2ch-a-AN-UP.dat"
};
opch[0][3][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
{
Invar I1 = Invar(pa, -pb);
{
nrglog('f', "RECALC_F(fn=" << "pp/pp-2ch-b-CR-DO.dat" << ", ch=" << 1 << ", n=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "pp/pp-2ch-b-CR-DO.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "pp/pp-2ch-b-CR-UP.dat" << ", ch=" << 1 << ", n=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "pp/pp-2ch-b-CR-UP.dat"
};
opch[1][1][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "pp/pp-2ch-b-AN-DO.dat" << ", ch=" << 1 << ", n=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "pp/pp-2ch-b-AN-DO.dat"
};
opch[1][2][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "pp/pp-2ch-b-AN-UP.dat" << ", ch=" << 1 << ", n=" << 3 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "pp/pp-2ch-b-AN-UP.dat"
};
opch[1][3][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
}
return opch;
}
#undef SPINX
#define SPINX(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef SPINZ
#define SPINZ(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
// Isospin operator need an appropriate phase factor (bipartite sublattice index)
#define USEISOFACTOR
#if defined(USEISOFACTOR)
#define ISOFACTOR psgn(step.getnn() + 1)
#else
#define ISOFACTOR 1
#endif
#undef SPINY
#define SPINY(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef ISOSPINY
#define ISOSPINY(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value * std::complex<double>(ISOFACTOR))
#undef Complex
#define Complex(x, y) cmpl(x, y)
#undef CHARGE
#define CHARGE(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef ISOSPINZ
#define ISOSPINZ(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
#undef ISOSPINX
#define ISOSPINX(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *ISOFACTOR)
#undef ISOSPINP
#define ISOSPINP(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *ISOFACTOR)
#undef ISOSPINM
#define ISOSPINM(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value *ISOFACTOR)
template<typename SC>
void SymmetryPP<SC>::recalc_global(const Step &step, const DiagInfo<SC> &diag, const std::string name, MatrixElements<SC> &cnew) const {
if (name == "SZtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "pp/pp-2ch-spinz.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if constexpr (std::is_same_v<SC, std::complex<double>>) {
if (name == "SYtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "pp/pp-2ch-spiny.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
}
if (name == "SXtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "pp/pp-2ch-spinx.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Qtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "pp/pp-2ch-Qtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Iztot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "pp/pp-2ch-Iztot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Ixtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "pp/pp-2ch-Ixtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if constexpr (std::is_same_v<SC, std::complex<double>>) {
if (name == "Iytot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "pp/pp-2ch-Iytot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
}
if (name == "Iptot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "pp/pp-2ch-Iptot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
if (name == "Imtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II = {I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "pp/pp-2ch-Imtot.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
my_assert_not_reached();
}
}
| 8,764
|
C++
|
.h
| 274
| 27.270073
| 136
| 0.569008
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,722
|
nrg-recalc-SPSU2T.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-SPSU2T.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-SPSU2T.cc.m4, not nrg-recalc-SPSU2T.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Aug 2015
// This file pertains to (S,T) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetrySPSU2T<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ss1 = I1.get("SS");
int t1 = I1.get("T");
double T = t1; // trick!
Invar Ip;
// Two different lengths: D_3CH_a and D_3CH_b
Ip = Invar(ss1 + 1, t1 - 1);
{
nrglog('f', "RECALC(fn=" << "spsu2t/spsu2t-doubletp-1.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2t/spsu2t-doubletp-1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
Ip = Invar(ss1 - 1, t1 - 1);
{
nrglog('f', "RECALC(fn=" << "spsu2t/spsu2t-doubletm-1.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2t/spsu2t-doubletm-1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
Ip = Invar(ss1 + 1, t1);
{
nrglog('f', "RECALC(fn=" << "spsu2t/spsu2t-doubletp0.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2t/spsu2t-doubletp0.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
Ip = Invar(ss1 - 1, t1);
{
nrglog('f', "RECALC(fn=" << "spsu2t/spsu2t-doubletm0.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2t/spsu2t-doubletm0.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
Ip = Invar(ss1 + 1, t1 + 1);
{
nrglog('f', "RECALC(fn=" << "spsu2t/spsu2t-doubletp+1.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2t/spsu2t-doubletp+1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
Ip = Invar(ss1 - 1, t1 + 1);
{
nrglog('f', "RECALC(fn=" << "spsu2t/spsu2t-doubletm+1.dat" << ", Iop=" << Invar(1, 2, 1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2t/spsu2t-doubletm+1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 2, 1));
}
}
};
}
return cnew;
}
// ch=1 <-> Tz=+1
// ch=2 <-> Tz=0
// ch=3 <-> Tz=-1
template<typename SC>
Opch<SC> SymmetrySPSU2T<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int ssp = Ip.get("SS");
int tp = Ip.get("T");
double T = tp; // trick!
Invar I1;
// The different files just correspond to contributions computed
// for various d[CR,sz,tz] operators.
// Check: there should not be any lines with equal subspaces
// indexes in different files!! That's indeed the case for the
// generated files for symtype=SPSU2T.
I1 = Invar(ssp + 1, tp + 1);
{
nrglog('f', "RECALC_F(fn=" << "spsu2t/spsu2t-spinup+1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2t/spsu2t-spinup+1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp + 1, tp);
{
nrglog('f', "RECALC_F(fn=" << "spsu2t/spsu2t-spinup0.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2t/spsu2t-spinup0.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp + 1, tp - 1);
{
nrglog('f', "RECALC_F(fn=" << "spsu2t/spsu2t-spinup-1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2t/spsu2t-spinup-1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp - 1, tp + 1);
{
nrglog('f', "RECALC_F(fn=" << "spsu2t/spsu2t-spindo+1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2t/spsu2t-spindo+1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp - 1, tp);
{
nrglog('f', "RECALC_F(fn=" << "spsu2t/spsu2t-spindo0.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2t/spsu2t-spindo0.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(ssp - 1, tp - 1);
{
nrglog('f', "RECALC_F(fn=" << "spsu2t/spsu2t-spindo-1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "spsu2t/spsu2t-spindo-1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
template<typename SC>
MatrixElements<SC> SymmetrySPSU2T<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ss1 = I1.get("SS");
int t1 = I1.get("T");
double T = t1; // trick!
Invar Ip;
Ip = Invar(ss1, t1);
{
nrglog('f', "RECALC(fn=" << "spsu2t/spsu2t-triplets.dat" << ", Iop=" << Invar(3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2t/spsu2t-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3, 0));
}
}
};
Ip = Invar(ss1 + 2, t1);
{
nrglog('f', "RECALC(fn=" << "spsu2t/spsu2t-tripletp.dat" << ", Iop=" << Invar(3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2t/spsu2t-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3, 0));
}
}
};
Ip = Invar(ss1 - 2, t1);
{
nrglog('f', "RECALC(fn=" << "spsu2t/spsu2t-tripletm.dat" << ", Iop=" << Invar(3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "spsu2t/spsu2t-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(3, 0));
}
}
};
}
return cnew;
}
}
| 8,994
|
C++
|
.h
| 247
| 32.299595
| 119
| 0.587661
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,723
|
sym-DBLISOSZ.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-DBLISOSZ.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_DBLISOSZ(const Params &P);
}
| 101
|
C++
|
.h
| 4
| 23.75
| 58
| 0.757895
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,724
|
nrg-recalc-ISO2.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-ISO2.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-ISO2.cc.m4, not nrg-recalc-ISO2.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Feb 2006, May 2008
// This file pertains to (I,S) subspaces
// Version for EVEN number of impurities.
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetryISO2<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii1 = I1.get("II");
int ss1 = I1.get("SS");
Invar Ip;
Ip = Invar(ii1 - 1, ss1 + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-1ch-doubletmp.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-1ch-doubletmp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-2ch-doubletmp.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-2ch-doubletmp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1-1, ss1-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-1ch-doubletmm.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-1ch-doubletmm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-2ch-doubletmm.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-2ch-doubletmm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1+1, ss1+1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-1ch-doubletpp.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-1ch-doubletpp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-2ch-doubletpp.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-2ch-doubletpp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1+1, ss1-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-1ch-doubletpm.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-1ch-doubletpm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-2ch-doubletpm.dat" << ", Iop=" << Invar(2, 2) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-2ch-doubletpm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(2, 2));
}
}
} } break;
default: my_assert_not_reached();
};
}
return cnew;
}
template<typename SC>
Opch<SC> SymmetryISO2<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
Invar I1;
// NOTE: ii,ss only couples to ii+-1,ss+-1 in general, even for
// several channels.
int iip = Ip.get("II");
int ssp = Ip.get("SS");
// NN is index n of f_n, the last site in the chain prior to adding
// the new site (f_{n+1}).
int NN = step.getnn();
I1 = Invar(iip + 1, ssp + 1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-1ch-spinup-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-1ch-spinup-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-2ch-spinup-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-2ch-spinup-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-2ch-spinup-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-2ch-spinup-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
I1 = Invar(iip+1, ssp-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-1ch-spindown-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-1ch-spindown-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-2ch-spindown-isoupa.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-2ch-spindown-isoupa.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-2ch-spindown-isoupb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-2ch-spindown-isoupb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
I1 = Invar(iip-1, ssp+1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-1ch-spinup-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-1ch-spinup-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-2ch-spinup-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-2ch-spinup-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-2ch-spinup-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-2ch-spinup-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
I1 = Invar(iip-1, ssp-1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-1ch-spindown-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-1ch-spindown-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
case 2: { {
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-2ch-spindown-isodowna.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-2ch-spindown-isodowna.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "iso2/iso2-2ch-spindown-isodownb.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "iso2/iso2-2ch-spindown-isodownb.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
} } break;
default: my_assert_not_reached();
};
}
return opch;
}
template<typename SC>
MatrixElements<SC> SymmetryISO2<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int ii1 = I1.get("II");
int ss1 = I1.get("SS");
Invar Ip;
Ip = Invar(ii1, ss1);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-1ch-triplets.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-1ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-2ch-triplets.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-2ch-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1, ss1+2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-1ch-tripletp.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-1ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-2ch-tripletp.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-2ch-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
default: my_assert_not_reached();
};
Ip = Invar(ii1, ss1-2);
switch (P.channels) {
case 1: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-1ch-tripletm.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-1ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
case 2: { {
nrglog('f', "RECALC(fn=" << "iso2/iso2-2ch-tripletm.dat" << ", Iop=" << Invar(1, 3) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "iso2/iso2-2ch-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 3));
}
}
} } break;
default: my_assert_not_reached();
};
}
return cnew;
}
}
| 14,893
|
C++
|
.h
| 402
| 33.002488
| 117
| 0.589815
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,725
|
nrg-recalc-QSZTZ.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-QSZTZ.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-QSZTZ.cc.m4, not nrg-recalc-QSZTZ.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Mar 2016
// This file pertains to (Q,Sz,Tz) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetryQSZTZ<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int ssz1 = I1.get("SZ");
int tz1 = I1.get("TZ");
Invar Ip;
// Invar(1,2,+-1,0) is correct. 1 = add charge, 2 = doublet,
// 1 = triplet (because working with abs orbital momentum QNs)
Ip = Invar(q1 - 1, ssz1 + 1, tz1 - 1);
{
nrglog('f', "RECALC(fn=" << "qsztz/qsztz-doubletp-1.dat" << ", Iop=" << Invar(1, -1, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qsztz/qsztz-doubletp-1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, -1, +1));
}
}
};
Ip = Invar(q1 - 1, ssz1 - 1, tz1 - 1);
{
nrglog('f', "RECALC(fn=" << "qsztz/qsztz-doubletm-1.dat" << ", Iop=" << Invar(1, +1, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qsztz/qsztz-doubletm-1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, +1, +1));
}
}
};
Ip = Invar(q1 - 1, ssz1 + 1, tz1);
{
nrglog('f', "RECALC(fn=" << "qsztz/qsztz-doubletp0.dat" << ", Iop=" << Invar(1, -1, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qsztz/qsztz-doubletp0.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, -1, 0));
}
}
};
Ip = Invar(q1 - 1, ssz1 - 1, tz1);
{
nrglog('f', "RECALC(fn=" << "qsztz/qsztz-doubletm0.dat" << ", Iop=" << Invar(1, +1, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qsztz/qsztz-doubletm0.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, +1, 0));
}
}
};
Ip = Invar(q1 - 1, ssz1 + 1, tz1 + 1);
{
nrglog('f', "RECALC(fn=" << "qsztz/qsztz-doubletp+1.dat" << ", Iop=" << Invar(1, -1, -1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qsztz/qsztz-doubletp+1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, -1, -1));
}
}
};
Ip = Invar(q1 - 1, ssz1 - 1, tz1 + 1);
{
nrglog('f', "RECALC(fn=" << "qsztz/qsztz-doubletm+1.dat" << ", Iop=" << Invar(1, +1, -1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qsztz/qsztz-doubletm+1.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, +1, -1));
}
}
};
}
return cnew;
}
// ch=1 <-> Tz=+1
// ch=2 <-> Tz=0
// ch=3 <-> Tz=-1
template<typename SC>
Opch<SC> SymmetryQSZTZ<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
int qp = Ip.get("Q");
int sszp = Ip.get("SZ");
int tzp = Ip.get("TZ");
Invar I1;
I1 = Invar(qp + 1, sszp + 1, tzp + 1);
{
nrglog('f', "RECALC_F(fn=" << "qsztz/qsztz-spinup+1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsztz/qsztz-spinup+1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, sszp + 1, tzp);
{
nrglog('f', "RECALC_F(fn=" << "qsztz/qsztz-spinup0.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsztz/qsztz-spinup0.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, sszp + 1, tzp - 1);
{
nrglog('f', "RECALC_F(fn=" << "qsztz/qsztz-spinup-1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsztz/qsztz-spinup-1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, sszp - 1, tzp + 1);
{
nrglog('f', "RECALC_F(fn=" << "qsztz/qsztz-spindo+1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsztz/qsztz-spindo+1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, sszp - 1, tzp);
{
nrglog('f', "RECALC_F(fn=" << "qsztz/qsztz-spindo0.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsztz/qsztz-spindo0.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, sszp - 1, tzp - 1);
{
nrglog('f', "RECALC_F(fn=" << "qsztz/qsztz-spindo-1.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsztz/qsztz-spindo-1.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
template<typename SC>
MatrixElements<SC> SymmetryQSZTZ<SC>::recalc_triplet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q1 = I1.get("Q");
int ssz1 = I1.get("SZ");
int tz1 = I1.get("TZ");
Invar Ip;
Ip = Invar(q1, ssz1, tz1);
{
nrglog('f', "RECALC(fn=" << "qsztz/qsztz-triplets.dat" << ", Iop=" << Invar(0, 3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qsztz/qsztz-triplets.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, 0));
}
}
};
Ip = Invar(q1, ssz1 + 2, tz1);
{
nrglog('f', "RECALC(fn=" << "qsztz/qsztz-tripletp.dat" << ", Iop=" << Invar(0, 3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qsztz/qsztz-tripletp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, 0));
}
}
};
Ip = Invar(q1, ssz1 - 2, tz1);
{
nrglog('f', "RECALC(fn=" << "qsztz/qsztz-tripletm.dat" << ", Iop=" << Invar(0, 3, 0) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "qsztz/qsztz-tripletm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 3, 0));
}
}
};
}
return cnew;
}
}
| 8,905
|
C++
|
.h
| 243
| 32.547325
| 118
| 0.577561
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,726
|
sym-ISOSZ-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-ISOSZ-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryISOSZ : public SymField<SC> {
private:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryISOSZ(const Params &P) : SymField<SC>(P, std::vector{"<Sz^2>", "<Sz>", "<Q^2>"}, Invar(1,0)) {
initInvar({
{"II", additive}, // isospin
{"SSZ", additive} // spin projection
});
}
// Multiplicity of the I=(II,SSZ) subspace = (2I+1) = II.
size_t mult(const Invar &I) const override {
return I.get("II"); // isospin multiplicity
}
bool check_SPIN(const Invar &I1, const Invar &Ip, const int &SPIN) const override {
// The spin projection of the operator is defined by the difference
// in Sz of both the invariant subspaces.
int ssz1 = I1.get("SSZ");
int sszp = Ip.get("SSZ");
int sszop = ssz1 - sszp;
return sszop == SPIN;
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return u1_equality(I1.get("SSZ"), I2.get("SSZ"), I3.get("SSZ")) && su2_triangle_inequality(I1.get("II"), I2.get("II"), I3.get("II"));
}
// We always must have I >= 0.
bool Invar_allowed(const Invar &I) const override { return I.get("II") > 0; }
void load() override {
switch (P.channels) {
case 1:
#include "isosz/isosz-1ch-In2.dat"
#include "isosz/isosz-1ch-QN.dat"
break;
case 2:
#include "isosz/isosz-2ch-In2.dat"
#include "isosz/isosz-2ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
check_abs_diff(Ip, I1, "SSZ", 1);
const int iip = Ip.get("II");
const int ii1 = I1.get("II");
const double isofactor = (ii1 == iip + 1 ? ISO(iip) + 1.0 : ISO(iip));
return isofactor;
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ, trSZ2, trIZ2; // Tr[S_z], Tr[S_z^2], Tr[I_z^2]
for (const auto &[I, eig]: diag) {
const int ii = I.get("II");
const int ssz = I.get("SSZ");
const double sumZ = this->calculate_Z(I, eig, factor);
trSZ += sumZ * SZ(ssz);
trSZ2 += sumZ * pow(SZ(ssz),2); // isospin multiplicity contained in sumZ
trIZ2 += sumZ * (ii * ii - 1) / 12.; // spin multiplicity contained in sumZ
}
stats.td.set("<Sz>", trSZ / stats.Z);
stats.td.set("<Sz^2>", trSZ2 / stats.Z);
stats.td.set("<Q^2>", (4 * trIZ2) / stats.Z);
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
HAS_GLOBAL;
};
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
template<typename SC>
void SymmetryISOSZ<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ii = I.get("II");
int NN = step.getnn();
switch (P.channels) {
case 1:
#include "isosz/isosz-1ch-offdiag.dat"
break;
case 2:
#include "isosz/isosz-2ch-offdiag.dat"
break;
default: my_assert_not_reached();
}
}
}
#include "nrg-recalc-ISOSZ.hpp"
| 3,311
|
C++
|
.h
| 90
| 32.666667
| 182
| 0.631415
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,727
|
sym-QSC3.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QSC3.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_QSC3(const Params &P);
}
| 97
|
C++
|
.h
| 4
| 22.75
| 54
| 0.747253
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,728
|
sym-ISO-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-ISO-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryISOcommon : public Symmetry<SC> {
protected:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
SymmetryISOcommon(const Params &P) : Symmetry<SC>(P, std::vector{"<Sz^2>", "<Q^2>"}, Invar(1, 1), Invar(2, 2)) {
initInvar({
{"II", additive}, // isospin
{"SS", additive} // spin
});
}
// Multiplicity of the I=(II,SS) subspace = (2I+1)(2S+1) = II SS.
size_t mult(const Invar &I) const override {
int mi = I.get("II"); // isospin multiplicity
int ms = I.get("SS"); // spin multiplicity
return mi * ms;
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return su2_triangle_inequality(I1.get("SS"), I2.get("SS"), I3.get("SS")) && su2_triangle_inequality(I1.get("II"), I2.get("II"), I3.get("II"));
}
// We always must have S >= 0 and I >= 0.
bool Invar_allowed(const Invar &I) const override {
const bool isospin_ok = I.get("II") > 0;
const bool spin_ok = I.get("SS") > 0;
return isospin_ok && spin_ok;
}
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
my_assert(abs(ss1 - ssp) == 1);
const int iip = Ip.get("II");
const int ii1 = I1.get("II");
my_assert(abs(ii1 - iip) == 1);
const double spinfactor = (ss1 == ssp + 1 ? S(ssp) + 1.0 : S(ssp));
const double isofactor = (ii1 == iip + 1 ? ISO(iip) + 1.0 : ISO(iip));
return spinfactor * isofactor;
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ, trIZ; // Tr[S_z^2], Tr[I_z^2]
for (const auto &[I, eig]: diag) {
const int ii = I.get("II");
const int ss = I.get("SS");
const double sumZ = this->calculate_Z(I, eig, factor);
trSZ += sumZ * (ss * ss - 1) / 12.; // isospin multiplicity contained in sumZ
trIZ += sumZ * (ii * ii - 1) / 12.; // spin multiplicity contained in sumZ
}
stats.td.set("<Sz^2>", trSZ / stats.Z);
stats.td.set("<Q^2>", (4 * trIZ) / stats.Z);
}
};
template<typename SC>
class SymmetryISO : public SymmetryISOcommon<SC> {
private:
using SymmetryISOcommon<SC>::P;
using SymmetryISOcommon<SC>::In;
using SymmetryISOcommon<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryISO(const Params &P) : SymmetryISOcommon<SC>(P) {}
void load() override {
switch (P.channels) {
case 1:
#include "iso/iso-1ch-In2.dat"
#include "iso/iso-1ch-QN.dat"
break;
case 2:
#include "iso/iso-2ch-In2.dat"
#include "iso/iso-2ch-QN.dat"
break;
case 3:
#include "iso/iso-3ch-In2.dat"
#include "iso/iso-3ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
};
template<typename SC>
class SymmetryISO2 : public SymmetryISOcommon<SC> {
private:
using SymmetryISOcommon<SC>::P;
using SymmetryISOcommon<SC>::In;
using SymmetryISOcommon<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryISO2(const Params &P) : SymmetryISOcommon<SC>(P) {}
void load() override {
switch (P.channels) {
case 1:
#include "iso2/iso2-1ch-In2.dat"
#include "iso2/iso2-1ch-QN.dat"
break;
case 2:
#include "iso2/iso2-2ch-In2.dat"
#include "iso2/iso2-2ch-QN.dat"
break;
default: my_assert_not_reached();
}
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
};
#undef OFFDIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
#undef DIAG
#define DIAG(i, ch, number) this->diag_function(step, i, number, coef.zeta(step.N() + 1, ch), h, qq)
template<typename SC>
void SymmetryISO<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ss = I.get("SS");
int ii = I.get("II");
// nn is the index of the last site in the chain, while nn+1 is the
// index of the site that is being added to the chain in this
// iteration. This is consistent with the definition in
// isospin-1ch-automatic.nb.
int NN = step.getnn();
switch (P.channels) {
case 1:
#include "iso/iso-1ch-offdiag.dat"
break;
case 2:
#include "iso/iso-2ch-offdiag.dat"
break;
case 3:
#include "iso/iso-3ch-offdiag.dat"
break;
default: my_assert_not_reached();
}
}
template<typename SC>
void SymmetryISO2<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ss = I.get("SS");
int ii = I.get("II");
int NN = step.getnn();
switch (P.channels) {
case 1:
#include "iso2/iso2-1ch-offdiag.dat"
break;
case 2:
#include "iso2/iso2-2ch-offdiag.dat"
break;
default: my_assert_not_reached();
}
}
}
#include "nrg-recalc-ISO.hpp"
#include "nrg-recalc-ISO2.hpp"
| 5,219
|
C++
|
.h
| 155
| 29.774194
| 181
| 0.644841
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,729
|
sym-ISOLR-impl.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-ISOLR-impl.hpp
|
namespace NRG {
template<typename SC>
class SymmetryISOLRcommon : public SymLR<SC> {
protected:
using Symmetry<SC>::P;
using Symmetry<SC>::In;
using Symmetry<SC>::QN;
public:
SymmetryISOLRcommon(const Params &P) : SymLR<SC>(P, std::vector{"<Sz^2>", "<Q^2>"}, Invar(1,1,1)) {
initInvar({
{"II", additive}, // isospin
{"SS", additive}, // spin
{"P", multiplicative} // parity
});
}
// Multiplicity of the I=(II,SS,P) subspace = (2I+1)(2S+1) = II SS.
size_t mult(const Invar &I) const override {
int mi = I.get("II"); // isospin multiplicity
int ms = I.get("SS"); // spin multiplicity
return mi * ms;
}
// We always must have S >= 0 and I >= 0.
bool Invar_allowed(const Invar &I) const override {
const bool isospin_ok = I.get("II") > 0;
const bool spin_ok = I.get("SS") > 0;
return isospin_ok && spin_ok;
}
bool triangle_inequality(const Invar &I1, const Invar &I2, const Invar &I3) const override {
return su2_triangle_inequality(I1.get("II"), I2.get("II"), I3.get("II")) && su2_triangle_inequality(I1.get("SS"), I2.get("SS"), I3.get("SS"))
&& z2_equality(I1.get("P"), I2.get("P"), I3.get("P"));
}
double specdens_factor(const Invar &Ip, const Invar &I1) const override {
const int ssp = Ip.get("SS");
const int ss1 = I1.get("SS");
my_assert(abs(ss1 - ssp) == 1);
const int iip = Ip.get("II");
const int ii1 = I1.get("II");
my_assert(abs(ii1 - iip) == 1);
const double spinfactor = (ss1 == ssp + 1 ? S(ssp) + 1.0 : S(ssp));
const double isofactor = (ii1 == iip + 1 ? ISO(iip) + 1.0 : ISO(iip));
return spinfactor * isofactor;
}
void calculate_TD(const Step &step, const DiagInfo<SC> &diag, Stats<SC> &stats, const double factor) const override {
bucket trSZ, trIZ; // Tr[S_z^2], Tr[I_z^2]
for (const auto &[I, eig]: diag) {
const int ii = I.get("II");
const int ss = I.get("SS");
const double sumZ = this->calculate_Z(I, eig, factor);
trSZ += sumZ * (ss * ss - 1) / 12.; // isospin multiplicity contained in sumZ
trIZ += sumZ * (ii * ii - 1) / 12.; // spin multiplicity contained in sumZ
}
stats.td.set("<Sz^2>", trSZ / stats.Z);
stats.td.set("<Q^2>", (4 * trIZ) / stats.Z);
}
};
template<typename SC>
class SymmetryISOLR : public SymmetryISOLRcommon<SC> {
private:
using SymmetryISOLRcommon<SC>::P;
using SymmetryISOLRcommon<SC>::In;
using SymmetryISOLRcommon<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryISOLR(const Params &P) : SymmetryISOLRcommon<SC>(P) {}
void load() override {
my_assert(P.channels == 2);
#include "isolr/isolr-2ch-In2.dat"
#include "isolr/isolr-2ch-QN.dat"
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
};
template<typename SC>
class SymmetryISO2LR : public SymmetryISOLRcommon<SC> {
private:
using SymmetryISOLRcommon<SC>::P;
using SymmetryISOLRcommon<SC>::In;
using SymmetryISOLRcommon<SC>::QN;
public:
using Matrix = typename traits<SC>::Matrix;
using t_matel = typename traits<SC>::t_matel;
SymmetryISO2LR(const Params &P) : SymmetryISOLRcommon<SC>(P) {}
void load() override {
my_assert(P.channels == 2);
#include "iso2lr/iso2lr-2ch-In2.dat"
#include "iso2lr/iso2lr-2ch-QN.dat"
}
DECL;
HAS_DOUBLET;
HAS_TRIPLET;
};
// *** Helper macros for make_matrix() members in matrix.cc
#undef OFFIAG
#define OFFDIAG(i, j, ch, factor0) offdiag_function(step, i, j, ch, 0, t_matel(factor0) * coef.xi(step.N(), ch), h, qq, In, opch)
template<typename SC>
void SymmetryISOLR<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ss = I.get("SS");
int ii = I.get("II");
#include "isolr/isolr-2ch-offdiag.dat"
}
template<typename SC>
void SymmetryISO2LR<SC>::make_matrix(Matrix &h, const Step &step, const SubspaceDimensions &qq, const Invar &I, const InvarVec &In, const Opch<SC> &opch, const Coef<SC> &coef) const {
int ss = I.get("SS");
int ii = I.get("II");
#include "iso2lr/iso2lr-2ch-offdiag.dat"
}
}
#include "nrg-recalc-ISOLR.hpp"
#include "nrg-recalc-ISO2LR.hpp"
| 4,260
|
C++
|
.h
| 111
| 34.801802
| 183
| 0.651753
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,730
|
sym-U1.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-U1.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_U1(const Params &P);
}
| 95
|
C++
|
.h
| 4
| 22.25
| 52
| 0.741573
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,731
|
sym-SPSU2C3.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SPSU2C3.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_SPSU2C3(const Params &P);
}
| 100
|
C++
|
.h
| 4
| 23.5
| 57
| 0.755319
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,732
|
sym-QSTZ.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-QSTZ.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_QSTZ(const Params &P);
}
| 97
|
C++
|
.h
| 4
| 22.75
| 54
| 0.747253
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,733
|
nrg-recalc-QSC3.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-QSC3.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-QSC3.cc.m4, not nrg-recalc-QSC3.cc !!!
// Quantum number dependent recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Oct 2015
// This file pertains to (Q,S,P) subspaces, P modulo 3
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
#define xRECALC_F_TAB(a, b, c) 0;
// Driver routine for recalc_f()
template<typename SC>
Opch<SC> SymmetryQSC3<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
if constexpr (std::is_same_v<SC, std::complex<double>>) {
for(const auto &[Ip, eig]: diag) {
int qp = Ip.get("Q");
int ssp = Ip.get("SS");
int p = Ip.get("P");
Invar I1;
// TRICK: ensure we are evaluating the expressions in the complex plane
#undef Power
#define Power(x, y) pow(cmpl(x), cmpl(y))
#undef sqrt
#define sqrt(x) csqrt(x)
I1 = Invar(qp + 1, ssp + 1, (p + 0) % 3);
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spinup0-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spinup0-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spinup0-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spinup0-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spinup0-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spinup0-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, (p + 0) % 3);
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spindown0-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spindown0-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spindown0-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spindown0-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spindown0-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spindown0-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp + 1, (p + 1) % 3);
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spinup1-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spinup1-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spinup1-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spinup1-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spinup1-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spinup1-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, (p + 1) % 3);
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spindown1-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spindown1-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spindown1-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spindown1-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spindown1-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spindown1-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp + 1, (p + 2) % 3);
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spinup2-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spinup2-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spinup2-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spinup2-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spinup2-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spinup2-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(qp + 1, ssp - 1, (p + 2) % 3);
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spindown2-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spindown2-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spindown2-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spindown2-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
{
nrglog('f', "RECALC_F(fn=" << "qsc3/qsc3-spindown2-c.dat" << ", ch=" << 2 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "qsc3/qsc3-spindown2-c.dat"
};
opch[2][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
#undef Power
#undef sqrt
}
}
return opch;
}
}
| 9,561
|
C++
|
.h
| 254
| 33.598425
| 93
| 0.575944
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,734
|
sym-SPU1LR.hpp
|
rokzitko_nrgljubljana/c++/symmetry/sym-SPU1LR.hpp
|
namespace NRG {
template <typename S>
std::unique_ptr<Symmetry<S>> mk_SPU1LR(const Params &P);
}
| 99
|
C++
|
.h
| 4
| 23.25
| 56
| 0.752688
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
1,535,735
|
nrg-recalc-DBLQSZ.hpp
|
rokzitko_nrgljubljana/c++/symmetry/nrg-recalc-DBLQSZ.hpp
|
namespace NRG {
// *** WARNING!!! Modify nrg-recalc-DBLQSZ.cc.m4, not nrg-recalc-DBLQSZ.cc !!!
// Quantum number dependant recalculation routines
// Rok Zitko, rok.zitko@ijs.si, Mar 2022
// This file pertains to (Q1,Q2,Sz) subspaces
namespace NRG {
// m4 macros for nrg-recalc-*.cc files
// Rok Zitko, rok.zitko@ijs.si, 2007-2020
}
template<typename SC>
MatrixElements<SC> SymmetryDBLQSZ<SC>::recalc_doublet(const DiagInfo<SC> &diag, const MatrixElements<SC> &cold) const {
MatrixElements<SC> cnew;
for(const auto &[I1, eig]: diag) {
int q11 = I1.get("Q1");
int q21 = I1.get("Q2");
int ssz1 = I1.get("SSZ");
Invar Ip;
Ip = Invar(q11 - 1, q21, ssz1 + 1);
{
nrglog('f', "RECALC(fn=" << "dblqsz/dblqsz-2ch-doubletm0p.dat" << ", Iop=" << Invar(1, 0, -1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "dblqsz/dblqsz-2ch-doubletm0p.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 0, -1));
}
}
};
Ip = Invar(q11 - 1, q21, ssz1 - 1);
{
nrglog('f', "RECALC(fn=" << "dblqsz/dblqsz-2ch-doubletm0m.dat" << ", Iop=" << Invar(1, 0, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "dblqsz/dblqsz-2ch-doubletm0m.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(1, 0, +1));
}
}
};
Ip = Invar(q11, q21 - 1, ssz1 + 1);
{
nrglog('f', "RECALC(fn=" << "dblqsz/dblqsz-2ch-doublet0mp.dat" << ", Iop=" << Invar(0, 1, -1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "dblqsz/dblqsz-2ch-doublet0mp.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 1, -1));
}
}
};
Ip = Invar(q11, q21 - 1, ssz1 - 1);
{
nrglog('f', "RECALC(fn=" << "dblqsz/dblqsz-2ch-doublet0mm.dat" << ", Iop=" << Invar(0, 1, +1) << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc<SC>> recalc_table = {
#include "dblqsz/dblqsz-2ch-doublet0mm.dat"
};
cnew[II] = this->recalc_general(diag, cold, I1, Ip, recalc_table, Invar(0, 1, +1));
}
}
};
}
return cnew;
}
template<typename SC>
Opch<SC> SymmetryDBLQSZ<SC>::recalc_irreduc(const Step &step, const DiagInfo<SC> &diag) const {
Opch<SC> opch(P);
for(const auto &[Ip, eig]: diag) {
Invar I1;
int q1p = Ip.get("Q1");
int q2p = Ip.get("Q2");
int sszp = Ip.get("SSZ");
I1 = Invar(q1p + 1, q2p, sszp + 1);
{
nrglog('f', "RECALC_F(fn=" << "dblqsz/dblqsz-2ch-spinup-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblqsz/dblqsz-2ch-spinup-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(q1p + 1, q2p, sszp - 1);
{
nrglog('f', "RECALC_F(fn=" << "dblqsz/dblqsz-2ch-spindown-a.dat" << ", ch=" << 0 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblqsz/dblqsz-2ch-spindown-a.dat"
};
opch[0][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(q1p, q2p + 1, sszp + 1);
{
nrglog('f', "RECALC_F(fn=" << "dblqsz/dblqsz-2ch-spinup-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblqsz/dblqsz-2ch-spinup-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
I1 = Invar(q1p, q2p + 1, sszp - 1);
{
nrglog('f', "RECALC_F(fn=" << "dblqsz/dblqsz-2ch-spindown-b.dat" << ", ch=" << 1 << ")");
auto II = Twoinvar(I1, Ip);
if (diag.count(I1) && diag.count(Ip) && this->recalc_f_coupled(I1, Ip, this->Invar_f)) {
if (diag.at(I1).getnrstored() && diag.at(Ip).getnrstored()) {
std::initializer_list<Recalc_f<SC>> recalc_table = {
#include "dblqsz/dblqsz-2ch-spindown-b.dat"
};
opch[1][0][II] = this->recalc_f(diag, I1, Ip, recalc_table);
}
}
};
}
return opch;
}
#undef SPINZ
#define SPINZ(i1, ip, ch, value) this->recalc1_global(diag, I1, cn, i1, ip, value)
template<typename SC>
void SymmetryDBLQSZ<SC>::recalc_global(const Step &step, const DiagInfo<SC> &diag, const std::string name, MatrixElements<SC> &cnew) const {
if (name == "SZtot") {
for(const auto &[I1, eig]: diag) {
const Twoinvar II{I1, I1};
Matrix &cn = cnew[II];
switch (P.channels) {
case 2:
#include "dblqsz/dblqsz-2ch-spinz.dat"
break;
default: my_assert_not_reached();
}
}
return;
}
my_assert_not_reached();
}
}
| 5,654
|
C++
|
.h
| 155
| 32.329032
| 140
| 0.596668
|
rokzitko/nrgljubljana
| 31
| 8
| 4
|
GPL-3.0
|
9/20/2024, 10:44:18 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.