Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions source/source_io/module_hs/cal_pLpR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,13 @@ ModuleIO::AngularMomentumCalculator::AngularMomentumCalculator(
const int rank)
{

// ofs_running
this->ofs_ = ptr_log;
if (this->ofs_ == nullptr)
{
this->fallback_ofs_.open("/dev/null");
this->ofs_ = &this->fallback_ofs_;
}

*ofs_ << "\n\n\n\n";
*ofs_ << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
*ofs_ << " | |" << std::endl;
Expand Down Expand Up @@ -259,7 +264,7 @@ void ModuleIO::AngularMomentumCalculator::kernel(
const char dir,
const int precision)
{
if (!ofs->is_open())
if (ofs == nullptr || !ofs->is_open())
{
return;
}
Expand Down Expand Up @@ -381,4 +386,4 @@ void ModuleIO::AngularMomentumCalculator::calculate(
this->kernel(&ofout, ucell, d, precision);
ofout.close();
}
}
}
6 changes: 4 additions & 2 deletions source/source_io/module_hs/cal_pLpR.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
#include <map>
#include <tuple>
#include <complex>
#include <fstream>
#include <memory>
#include "source_cell/unitcell.h"
#include "source_basis/module_nao/two_center_integrator.h"
Expand Down Expand Up @@ -218,8 +219,9 @@ namespace ModuleIO
const int rank = 0);

private:
std::ofstream fallback_ofs_;
// ofsrunning
std::ofstream* ofs_;
std::ofstream* ofs_ = nullptr;
// the two-center-integrator
std::unique_ptr<TwoCenterIntegrator> calculator_;
// the spherical bessel transformer
Expand All @@ -246,4 +248,4 @@ namespace ModuleIO
const char dir = 'x',
const int precision = 10);
};
} // namespace ModuleIO
} // namespace ModuleIO
4 changes: 2 additions & 2 deletions source/source_io/module_hs/write_HS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ void ModuleIO::save_mat(const int istep,
#else
if (app)
{
std::ofstream out_matrix(filename.c_str(), std::ofstream::app);
out_matrix.open(filename.c_str(), std::ofstream::app);
}
else
{
std::ofstream out_matrix(filename.c_str());
out_matrix.open(filename.c_str());
}

out_matrix << dim;
Expand Down
28 changes: 0 additions & 28 deletions source/source_io/module_hs/write_HS_R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,6 @@
#include "source_lcao/spar_st.h"
#include "write_HS_sparse.h"

namespace {
// Helper: Convert sparse map to HContainer
template <typename T>
hamilt::HContainer<T>* sparse_map_to_hcontainer(
const std::map<Abfs::Vector3_Order<int>, std::map<size_t, std::map<size_t, T>>>& sparse_map,
const Parallel_Orbitals& pv,
const int nbasis)
{
hamilt::HContainer<T>* hc = new hamilt::HContainer<T>(&pv);
hc->set_zero();

for (const auto& r_entry : sparse_map)
{
const auto& R = r_entry.first;
for (const auto& row_entry : r_entry.second)
{
const size_t row = row_entry.first;
for (const auto& col_entry : row_entry.second)
{
hc->set_value(R.x, R.y, R.z, row, col_entry.first, col_entry.second);
}
}
}

return hc;
}
} // anonymous namespace

// if 'binary=true', output binary file.
// The 'sparse_thr' is the accuracy of the sparse matrix.
// If the absolute value of the matrix element is less than or equal to the
Expand Down
10 changes: 6 additions & 4 deletions source/source_io/module_hs/write_HS_sparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "source_lcao/module_rt/td_info.h"
#include "single_R_io.h"

#include <algorithm>

void ModuleIO::save_dH_sparse(const int& istep,
const Parallel_Orbitals& pv,
Expand Down Expand Up @@ -421,16 +422,17 @@ void ModuleIO::save_sparse(
std::ofstream ofs;
if (!reduce || GlobalV::DRANK == 0) {
if (binary) {
int nlocal = PARAM.globalv.nlocal;
const int step = std::max(istep, 0);
const int nlocal = PARAM.globalv.nlocal;
if (PARAM.inp.calculation == "md" && PARAM.inp.out_app_flag
&& istep) {
ofs.open(sss.str().c_str(), std::ios::binary | std::ios::app);
} else {
ofs.open(sss.str().c_str(), std::ios::binary);
}
ofs.write(reinterpret_cast<char*>(0), sizeof(int));
ofs.write(reinterpret_cast<char*>(&nlocal), sizeof(int));
ofs.write(reinterpret_cast<char*>(&output_R_number), sizeof(int));
ofs.write(reinterpret_cast<const char*>(&step), sizeof(int));
ofs.write(reinterpret_cast<const char*>(&nlocal), sizeof(int));
ofs.write(reinterpret_cast<const char*>(&output_R_number), sizeof(int));
} else {
if (PARAM.inp.calculation == "md" && PARAM.inp.out_app_flag
&& istep) {
Expand Down
28 changes: 13 additions & 15 deletions source/source_io/module_hs/write_vxc_r.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ void write_Vxc_R(const int nspin,
double vtxc = 0.0;
// elecstate::PotXC* potxc(&rho_basis, &etxc, vtxc, nullptr);
// potxc.cal_v_eff(&chg, &ucell, vr_xc);
elecstate::Potential* potxc
= new elecstate::Potential(&rhod_basis, &rho_basis, &ucell, &vloc, &sf, &solvent, &etxc, &vtxc);
elecstate::Potential potxc(&rhod_basis, &rho_basis, &ucell, &vloc, &sf, &solvent, &etxc, &vtxc);
std::vector<std::string> compnents_list = {"xc"};
potxc->pot_register(compnents_list);
potxc->update_from_charge(&chg, &ucell);
potxc.pot_register(compnents_list);
potxc.update_from_charge(&chg, &ucell);

// 2. allocate H(R)
// (the number of hR: 1 for nspin=1, 4; 2 for nspin=2)
Expand Down Expand Up @@ -89,19 +88,18 @@ void write_Vxc_R(const int nspin,

// 3. calculate the Vxc(R)
hamilt::HS_Matrix_K<TK> vxc_k_ao(pv, 1); // only hk is needed, sk is skipped
std::vector<hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>*> vxcs_op_ao(nspin0);
for (int is = 0; is < nspin0; ++is)
{
vxcs_op_ao[is] = new hamilt::Veff<hamilt::OperatorLCAO<TK, TR>>(&vxc_k_ao,
kv.kvec_d,
potxc,
&vxcs_R_ao[is],
&ucell,
orb_cutoff,
&gd,
nspin);
vxcs_op_ao[is]->set_current_spin(is);
vxcs_op_ao[is]->contributeHR();
hamilt::Veff<hamilt::OperatorLCAO<TK, TR>> vxcs_op_ao(&vxc_k_ao,
kv.kvec_d,
&potxc,
&vxcs_R_ao[is],
&ucell,
orb_cutoff,
&gd,
nspin);
vxcs_op_ao.set_current_spin(is);
vxcs_op_ao.contributeHR();
#ifdef __EXX
if (GlobalC::exx_info.info_global.cal_exx)
{
Expand Down
17 changes: 17 additions & 0 deletions source/source_io/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,23 @@ AddTest(
../../source_basis/module_nao/real_gaunt_table.cpp
../../source_basis/module_nao/radial_collection.cpp
)

AddTest(
TARGET MODULE_IO_write_hs_r_compat_test
LIBS parameter base ${math_libs} device hcontainer
SOURCES
write_hs_r_compat_test.cpp
../module_hs/write_HS_R.cpp
../module_hs/write_HS_sparse.cpp
../module_hs/single_R_io.cpp
../module_dm/write_dmr.cpp
../module_output/ucell_io.cpp
../module_output/sparse_matrix.cpp
../module_output/csr_reader.cpp
../module_output/file_reader.cpp
../../source_basis/module_ao/parallel_orbitals.cpp
../../source_lcao/module_hcontainer/test/tmp_mocks.cpp
)
endif()

AddTest(
Expand Down
Loading
Loading