Skip to content
Open
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
2 changes: 1 addition & 1 deletion source/source_basis/module_ao/ORB_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void LCAO_Orbitals::read_orb_file(std::ofstream& ofs_in, // GlobalV::ofs_running
const int& my_rank)
{
ModuleBase::TITLE("LCAO_Orbitals", "read_orb_file");
char word[80];
std::string word;
std::string orb_label;
if (my_rank == 0)
{
Expand Down
7 changes: 7 additions & 0 deletions source/source_io/module_energy/nscf_fermi_surf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "source_io/module_parameter/parameter.h"
#include "source_base/global_variable.h"
#include "source_base/timer.h"
#include <fstream>
#include <stdexcept>
#include <string>

#ifdef __MPI
#include <mpi.h>
Expand All @@ -26,6 +29,10 @@ void ModuleIO::nscf_fermi_surface(const std::string &out_band_dir,
if(GlobalV::MY_RANK==0)
{
ofs.open(out_band_dir.c_str());
if (!ofs.is_open())
{
throw std::runtime_error("Failed to open file for writing: " + out_band_dir);
}
ofs << std::setprecision(6);
ofs.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void test_deepks<T>::set_parameters()
PARAM.input.cal_force = 1;

std::ifstream ifs("INPUT");
char word[80];
std::string word;
ifs >> word;
ifs >> PARAM.sys.gamma_only_local;
ifs.close();
Expand Down
4 changes: 2 additions & 2 deletions source/source_lcao/module_deepks/test/main_deepks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ int main(int argc, char** argv)
int calculate()
{
std::ifstream ifs("INPUT");
char word[80];
std::string word;
bool gamma_only_local;
ifs >> word;
ifs >> gamma_only_local;
Expand Down Expand Up @@ -94,4 +94,4 @@ void run_tests(test_deepks<T>& test)
}

template void run_tests(test_deepks<double>& test);
template void run_tests(test_deepks<std::complex<double>>& test);
template void run_tests(test_deepks<std::complex<double>>& test);
15 changes: 13 additions & 2 deletions source/source_lcao/module_operator_lcao/overlap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "source_lcao/module_operator_lcao/operator_lcao.h"
#include "source_lcao/module_rt/td_folding.h"
#include "source_lcao/module_rt/td_info.h"
#include <fstream>
#include <stdexcept>
#include <string>

#include <functional>
#include <vector>
Expand Down Expand Up @@ -438,11 +441,19 @@ void hamilt::Overlap<hamilt::OperatorLCAO<TK, TR>>::output_SR_async_csr(const in
if (istep <= 0)
{
ofs.open(filename);
}
if (!ofs.is_open())
{
throw std::runtime_error("Failed to open file for writing: " + filename);
}
}
else
{
ofs.open(filename, std::ios::app);
}
if (!ofs.is_open())
{
throw std::runtime_error("Failed to open file for writing: " + filename);
}
}

// Write header information
ofs << "IONIC_STEP: " << istep + 1 << std::endl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "source_lcao/module_ri/module_exx_symmetry/irreducible_sector.h"
#include "source_io/module_parameter/parameter.h"
#include <fstream>
#include <stdexcept>
#include <string>
namespace ModuleSymmetry
{
TC Irreducible_Sector::rotate_R(const Symmetry& symm,
Expand Down Expand Up @@ -148,8 +151,12 @@ namespace ModuleSymmetry
if(GlobalV::MY_RANK == 0)
{
std::ofstream ofs;
ofs.open(PARAM.globalv.global_out_dir + "irreducible_sector.txt");
for (auto& irap_irR : this->irreducible_sector_)
ofs.open(PARAM.globalv.global_out_dir + "irreducible_sector.txt");
if (!ofs.is_open())
{
throw std::runtime_error("Failed to open file for writing: " + PARAM.globalv.global_out_dir + "irreducible_sector.txt");
}
for (auto& irap_irR : this->irreducible_sector_)
{
for (auto& irR : irap_irR.second){ofs << "atompair (" << irap_irR.first.first << ", " << irap_irR.first.second << "), R = (" << irR[0] << ", " << irR[1] << ", " << irR[2] << ") \n";}
}
Expand Down
6 changes: 3 additions & 3 deletions source/source_lcao/module_ri/singular_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ double cal_massidda(const UnitCell& ucell,
= std::bind(&fq_massidda, ucell.tpiba, gaussian_abfs, qdiv, lambda, lmax);
double prefactor
= ModuleBase::TWO_PI * std::pow(lambda, -1.0 / qdiv) * ucell.omega / std::pow(ModuleBase::TWO_PI, 3);
double fq_int;
double fq_int;
if (qdiv == 2)
fq_int = prefactor * std::sqrt(ModuleBase::PI);
else if (qdiv == 1)
Expand All @@ -213,7 +213,7 @@ double cal_massidda(const UnitCell& ucell,
double val_extra_old = 0.5 * std::numeric_limits<double>::max();
double lammda_old = start_lambda;
double val_old = cal_chi(lammda_old);
double val_extra;
double val_extra = 0.0; //Initialize variables to avoid undefined behavior
for (size_t iter = 0; iter != niter; ++iter)
{
double lammda_new = lammda_old * 0.5;
Expand Down Expand Up @@ -300,4 +300,4 @@ double Iter_Integral(const ModuleBase::Matrix3& G,
}
} // namespace Singular_Value

#endif
#endif
16 changes: 14 additions & 2 deletions source/source_lcao/module_rt/td_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "source_estate/module_pot/H_TDDFT_pw.h"
#include "source_io/module_parameter/parameter.h"
#include <fstream>
#include <stdexcept>
#include <string>

bool TD_info::out_mat_R = false;
bool TD_info::out_vecpot = false;
Expand Down Expand Up @@ -72,13 +75,22 @@ void TD_info::output_cart_At(const std::string& out_dir)
if (istep == estep_shift)
{
ofs.open(out_file.c_str(), std::ofstream::out);
ofs << std::left << std::setw(8) << "#istep" << std::setw(15) << "A_x" << std::setw(15) << "A_y"
if (!ofs.is_open())
{
throw std::runtime_error("Failed to open file for writing: " + out_file);
}
ofs << std::left << std::setw(8) << "#istep" << std::setw(15) << "A_x" << std::setw(15) << "A_y"
<< std::setw(15) << "A_z" << std::endl;
}
else
{
ofs.open(out_file.c_str(), std::ofstream::app);
}
if (!ofs.is_open())
{
throw std::runtime_error("Failed to open file for writing: " + out_file);
}

}
// output the vector potential
ofs << std::left << std::setw(8) << istep;
// divide by 2.0 to get the atomic unit
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/wavefunc_in_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Wavefunc_in_pw::make_table_q(
}
int meshr=0;
double dr=0.0; // only used in uniform grid
char word[80]; // pengfei Li add 15-1-31
std::string word; // pengfei Li add 15-1-31
while (in.good())
{
in >> word;
Expand Down
12 changes: 6 additions & 6 deletions source/source_relax/ions_move_cg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void Ions_Move_CG::setup_cg_grad(double *grad,
{
ModuleBase::TITLE("Ions_Move_CG", "setup_cg_grad");
assert(Ions_Move_Basic::istep > 0);
double gamma;
double gamma = 0.0; //Initialize variables to avoid undefined behavior
double cg0_cg, cg0_cg0, cg0_g;

if (ncggrad % 10000 == 0 || flag == 2)
Expand Down Expand Up @@ -364,11 +364,11 @@ void Ions_Move_CG::Brent(double &fa,
double &best_x,
double &xpt)
{
double dmove;
double tmp;
double k2, k1, k0;
double xnew1, xnew2;
double ecalnew1, ecalnew2;
double dmove = 0.0;
double tmp = 0.0;
double k2 = 0.0, k1 = 0.0, k0 = 0.0;
double xnew1 = 0.0, xnew2 = 0.0;
double ecalnew1 = 0.0, ecalnew2 = 0.0; //Initialize variables to avoid undefined behavior

if ((fa * fb) > 0)
{
Expand Down