Skip to content

Commit

Permalink
Add two methods (saveQuantumNumbers, saveEigenValues)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-otsuki committed Feb 26, 2018
1 parent c3a8d7c commit ca60974
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 32 deletions.
68 changes: 36 additions & 32 deletions c++/pomerol_ed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,6 @@ namespace pomerol2triqs {
std::cout << "Number of Blocks is " << states_class->NumberOfBlocks() << std::endl;
}

// Save quantum numbers and block size
if (verbose && !comm.rank()) { // TODO : enable no output
std::string filename("quantum_numbers.dat"); // TODO : specify externally
std::ofstream fout(filename);
fout << "# block_size quantum_numbers" << std::endl;
for (Pomerol::BlockNumber i=0; i<states_class->NumberOfBlocks(); i++)
fout << states_class->getBlockSize(i) << " " << states_class->getQuantumNumbers(i) << std::endl;
fout.close();
std::cout << "'" << filename << "'" << std::endl;
}

if (verbose && !comm.rank()) { std::cout << "\nPomerol: diagonalizing Hamiltonian" << std::endl; }
// Matrix representation of the Hamiltonian
matrix_h.reset(new Pomerol::Hamiltonian(index_info, *storage, *states_class));
Expand All @@ -147,27 +136,6 @@ namespace pomerol2triqs {
// Get ground state energy
if (verbose && !comm.rank()) { std::cout << "\nPomerol: ground state energy is " << matrix_h->getGroundEnergy() + gs_shift << std::endl; }

// Save all eigenvalues and corresponding quantum numbers
if (verbose && !comm.rank()) { // TODO : enable no output
// create a list of pairs of eigenvalue and quantum numers to sort
std::vector< std::pair<double, Pomerol::QuantumNumbers> > eigen;
for (Pomerol::BlockNumber i=0; i<states_class->NumberOfBlocks(); i++){
Pomerol::HamiltonianPart H_part = matrix_h->getPart(i);
for (Pomerol::InnerQuantumState j=0; j<H_part.getSize(); j++)
eigen.push_back( std::make_pair( H_part.getEigenValue(j), H_part.getQuantumNumbers() ) );
}
// sort eigenvalues in ascending order
std::sort(eigen.begin(), eigen.end());
// write into a file
std::string filename("eigenvalues.dat"); // TODO : specify externally
std::ofstream fout(filename);
fout << "# eigenvalues quantum_numbers" << std::endl;
for (auto e : eigen)
fout << e.first << " " << e.second << std::endl;
fout.close();
std::cout << "'" << filename << "'" << std::endl;
}

// Reset containers, we will compute them later if needed
rho.release();
ops_container.release();
Expand Down Expand Up @@ -222,6 +190,42 @@ namespace pomerol2triqs {
diagonalize_main(gs_shift);
}

void pomerol_ed::saveQuantumNumbers(const std::string &filename) {
if (!states_class) TRIQS_RUNTIME_ERROR << "saveQuantumNumbers: internal error!";

if (!comm.rank()) {
std::ofstream fout(filename);
fout << "# block_size quantum_numbers" << std::endl;
for (Pomerol::BlockNumber i=0; i<states_class->NumberOfBlocks(); i++)
fout << states_class->getBlockSize(i) << " " << states_class->getQuantumNumbers(i) << std::endl;
fout.close();
std::cout << "'" << filename << "'" << std::endl;
}
}

void pomerol_ed::saveEigenValues(const std::string &filename) {
if (!states_class || !matrix_h) TRIQS_RUNTIME_ERROR << "saveEigenValues: internal error!";

if (!comm.rank()) {
// create a list of pairs of eigenvalue and quantum numers to sort
std::vector< std::pair<double, Pomerol::QuantumNumbers> > eigen;
for (Pomerol::BlockNumber i=0; i<states_class->NumberOfBlocks(); i++){
Pomerol::HamiltonianPart H_part = matrix_h->getPart(i);
for (Pomerol::InnerQuantumState j=0; j<H_part.getSize(); j++)
eigen.push_back( std::make_pair( H_part.getEigenValue(j), H_part.getQuantumNumbers() ) );
}
// sort eigenvalues in ascending order
std::sort(eigen.begin(), eigen.end());
// write into a file
std::ofstream fout(filename);
fout << "# eigenvalues quantum_numbers" << std::endl;
for (auto e : eigen)
fout << e.first << " " << e.second << std::endl;
fout.close();
std::cout << "'" << filename << "'" << std::endl;
}
}

Pomerol::ParticleIndex pomerol_ed::lookup_pomerol_index(indices_t const &i) const {
auto it = index_converter.find(i);
if (it == index_converter.end()) return -1;
Expand Down
6 changes: 6 additions & 0 deletions c++/pomerol_ed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ namespace pomerol2triqs {
/// Diagonalize Hamiltonian using provided integrals of motion
void diagonalize(many_body_op_t const &hamiltonian, std::vector<many_body_op_t> const& integrals_of_motion);

/// Save quantum numbers and block size
void saveQuantumNumbers(const std::string &filename);

/// Save all eigenvalues and corresponding quantum numbers
void saveEigenValues(const std::string &filename);

/// Green's function in Matsubara frequencies
block_gf<imfreq> G_iw(gf_struct_t const &gf_struct, double beta, int n_iw);

Expand Down
4 changes: 4 additions & 0 deletions example/2band.atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
# Diagonalize H
ed.diagonalize(H)

# save data
ed.saveQuantumNumbers("quantum_numbers.dat")
ed.saveEigenValues("eigenvalues.dat")

# Compute G(i\omega)
G_iw = ed.G_iw(gf_struct, beta, n_iw)

Expand Down
6 changes: 6 additions & 0 deletions python/pomerol2triqs_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
c.add_method("""void diagonalize (many_body_op_t hamiltonian, std::vector<many_body_op_t> integrals_of_motion)""",
doc = """Diagonalize Hamiltonian using provided integrals of motion """)

c.add_method("""void saveQuantumNumbers (std::string filename)""",
doc = """Save quantum numbers and block size """)

c.add_method("""void saveEigenValues (std::string filename)""",
doc = """Save all eigenvalues and corresponding quantum numbers """)

c.add_method("""block_gf<imfreq> G_iw (gf_struct_t gf_struct, double beta, int n_iw)""",
doc = """Green\'s function in Matsubara frequencies """)

Expand Down

0 comments on commit ca60974

Please sign in to comment.