Skip to content
Merged
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
6 changes: 3 additions & 3 deletions source/source_cell/atom_pseudo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void Atom_pseudo::set_d_so(ModuleBase::ComplexMatrix& d_so_in,
else // zhengdy-soc
{
this->d_so.create(spin_dimension, nproj_soc + 1, nproj_soc + 1);
// std::cout << "lmax=" << lmax << std::endl;
// std::cout << "lmax=" << lmax << std::endl;

if (this->lmax > -1)
{
Expand All @@ -87,10 +87,10 @@ void Atom_pseudo::set_d_so(ModuleBase::ComplexMatrix& d_so_in,
if (fabs(this->d_so(is, L1, L2).real()) > 1.0e-8
|| fabs(this->d_so(is, L1, L2).imag()) > 1.0e-8)
{
// std::cout << "tt in atom is=" << is << " L1=" <<
// std::cout << "tt in atom is=" << is << " L1=" <<
//L1
//<< " L2="
// << L2 << " " << d_so(is, L1, L2) << std::endl;
// << L2 << " " << d_so(is, L1, L2) << std::endl;

this->index1_soc[is][non_zero_count_soc[is]] = L1;
this->index2_soc[is][non_zero_count_soc[is]] = L2;
Expand Down
66 changes: 33 additions & 33 deletions source/source_cell/atom_pseudo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,41 @@ class Atom_pseudo : public pseudo
{
public:

Atom_pseudo();
~Atom_pseudo();

// mohan add 2021-05-07
ModuleBase::ComplexArray d_so; //(:,:,:), spin-orbit case
ModuleBase::matrix d_real; //(:,:), non-spin-orbit case
int nproj;
int nproj_soc; // dimension of D_ij^so
std::vector<int> non_zero_count_soc = {0, 0, 0, 0};
std::vector<std::vector<int>> index1_soc = {{}, {}, {}, {}};
std::vector<std::vector<int>> index2_soc = {{}, {}, {}, {}};

void set_d_so( // mohan add 2021-05-07
ModuleBase::ComplexMatrix &d_so_in,
const int &nproj_in,
const int &nproj_in_so,
const bool has_so,
const bool lspinorb,
const int nspin);


inline void get_d(const int& is, const int& p1, const int& p2, const std::complex<double>*& tmp_d)
{
tmp_d = &this->d_so(is, p1, p2);
return;
}
inline void get_d(const int& is, const int& p1, const int& p2, const double*& tmp_d)
{
tmp_d = &this->d_real(p1, p2);
return;
}
Atom_pseudo();
~Atom_pseudo();

// mohan add 2021-05-07
ModuleBase::ComplexArray d_so; //(:,:,:), spin-orbit case
ModuleBase::matrix d_real; //(:,:), non-spin-orbit case
int nproj;
int nproj_soc; // dimension of D_ij^so
std::vector<int> non_zero_count_soc = {0, 0, 0, 0};
std::vector<std::vector<int>> index1_soc = {{}, {}, {}, {}};
std::vector<std::vector<int>> index2_soc = {{}, {}, {}, {}};

void set_d_so( // mohan add 2021-05-07
ModuleBase::ComplexMatrix &d_so_in,
const int &nproj_in,
const int &nproj_in_so,
const bool has_so,
const bool lspinorb,
const int nspin);


inline void get_d(const int& is, const int& p1, const int& p2, const std::complex<double>*& tmp_d)
{
tmp_d = &this->d_so(is, p1, p2);
return;
}
inline void get_d(const int& is, const int& p1, const int& p2, const double*& tmp_d)
{
tmp_d = &this->d_real(p1, p2);
return;
}

#ifdef __MPI
void bcast_atom_pseudo(void); // for upf201
void bcast_atom_pseudo(void); // for upf201
#endif

};
Expand Down
2 changes: 1 addition & 1 deletion source/source_cell/atom_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Atom
Atom_pseudo ncpp;
double mass = 0.0; // the mass of atom
std::vector<ModuleBase::Vector3<int>> mbl; // whether the atoms can move or not
bool flag_empty_element = false; // whether is the empty element for bsse. Peize Lin add 2021.04.07
bool flag_empty_element = false; // whether is the empty element for bsse. Peize Lin add 2021.04.07

std::vector<int> iw2m; // use iw to find m
std::vector<int> iw2n; // use iw to find n
Expand Down
8 changes: 4 additions & 4 deletions source/source_cell/cal_nelec_nband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ void cal_nbands(const int& nelec, const int& nlocal, const std::vector<double>&
}

double occupied_bands = static_cast<double>(nelec / ModuleBase::DEGSPIN);
if (lspinorb == 1)
{
occupied_bands = static_cast<double>(nelec);
}
if (lspinorb == 1)
{
occupied_bands = static_cast<double>(nelec);
}

if ((occupied_bands - std::floor(occupied_bands)) > 0.0)
{
Expand Down
32 changes: 16 additions & 16 deletions source/source_cell/k_vector_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ void kvec_c2d(K_Vectors& kv, const ModuleBase::Matrix3& latvec)
ModuleBase::Matrix3 RT = latvec.Transpose();
for (int i = 0; i < nks; i++)
{
// std::cout << " ik=" << i
// << " kvec.x=" << kvec_c[i].x
// << " kvec.y=" << kvec_c[i].y
// << " kvec.z=" << kvec_c[i].z << std::endl;
// std::cout << " ik=" << i
// << " kvec.x=" << kvec_c[i].x
// << " kvec.y=" << kvec_c[i].y
// << " kvec.z=" << kvec_c[i].z << std::endl;
// wrong! kvec_d[i] = RT * kvec_c[i];
// mohan fixed bug 2011-03-07
kv.kvec_d[i] = kv.kvec_c[i] * RT;
Expand Down Expand Up @@ -588,10 +588,10 @@ void kvec_ibz_kpoint(K_Vectors& kv,
ModuleBase::Vector3<double> kvec_rot;
ModuleBase::Vector3<double> kvec_rot_k;

// for(int i=0; i<nrotkm; i++)
// {
// out.printM3("rot matrix",kgmatrix[i]);
// }
// for(int i=0; i<nrotkm; i++)
// {
// out.printM3("rot matrix",kgmatrix[i]);
// }
auto restrict_kpt = [&symm](ModuleBase::Vector3<double>& kvec) {
// in (-0.5, 0.5]
kvec.x = fmod(kvec.x + 100.5 - 0.5 * symm.epsilon, 1) - 0.5 + 0.5 * symm.epsilon;
Expand Down Expand Up @@ -691,20 +691,20 @@ void kvec_ibz_kpoint(K_Vectors& kv,
}
else // mohan fix bug 2010-1-30
{
// std::cout << "\n\n already exist ! ";
// std::cout << "\n\n already exist ! ";

// std::cout << "\n kvec_rot = " << kvec_rot.x << " " << kvec_rot.y << " " << kvec_rot.z;
// std::cout << "\n kvec_d_ibz = " << kvec_d_ibz[exist_number].x
// << " " << kvec_d_ibz[exist_number].y
// << " " << kvec_d_ibz[exist_number].z;
// std::cout << "\n kvec_rot = " << kvec_rot.x << " " << kvec_rot.y << " " << kvec_rot.z;
// std::cout << "\n kvec_d_ibz = " << kvec_d_ibz[exist_number].x
// << " " << kvec_d_ibz[exist_number].y
// << " " << kvec_d_ibz[exist_number].z;

double kmol_new = kv.kvec_d[i].norm2();
double kmol_old = kvec_d_ibz[exist_number].norm2();

kv.ibz_index[i] = exist_number;

// std::cout << "\n kmol_new = " << kmol_new;
// std::cout << "\n kmol_old = " << kmol_old;
// std::cout << "\n kmol_new = " << kmol_new;
// std::cout << "\n kmol_old = " << kmol_old;

// why we need this step?
// because in pw_basis.cpp, while calculate ggwfc2,
Expand All @@ -718,7 +718,7 @@ void kvec_ibz_kpoint(K_Vectors& kv,
kvec_d_ibz[exist_number] = kv.kvec_d[i];
}
}
// BLOCK_HERE("check k point");
// BLOCK_HERE("check k point");
}

delete[] kkmatrix;
Expand Down
102 changes: 51 additions & 51 deletions source/source_cell/magnetism.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Magnetism::~Magnetism()
}

void Magnetism::compute_mag(const double& omega,
const int& nrxx,
const int& nxyz,
const double* const * rho,
const int& nspin,
const bool& two_fermi,
const double& nelec,
double* nelec_spin)
const int& nrxx,
const int& nxyz,
const double* const * rho,
const int& nspin,
const bool& two_fermi,
const double& nelec,
double* nelec_spin)
{
assert(omega>0.0);
assert(nxyz>0);
Expand All @@ -45,61 +45,61 @@ void Magnetism::compute_mag(const double& omega,
this->tot_mag *= fac;
this->abs_mag *= fac;

ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total magnetism (Bohr mag/cell)",this->tot_mag);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Absolute magnetism (Bohr mag/cell)",this->abs_mag);
//update number of electrons for each spin
//if TWO_EFERMI, no need to update
if(!two_fermi)
{
nelec_spin[0] = (nelec + this->tot_mag) / 2;
nelec_spin[1] = (nelec - this->tot_mag) / 2;
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Electron number for spin up", nelec_spin[0]);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Electron number for spin down", nelec_spin[1]);
}
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total magnetism (Bohr mag/cell)",this->tot_mag);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Absolute magnetism (Bohr mag/cell)",this->abs_mag);
//update number of electrons for each spin
//if TWO_EFERMI, no need to update
if(!two_fermi)
{
nelec_spin[0] = (nelec + this->tot_mag) / 2;
nelec_spin[1] = (nelec - this->tot_mag) / 2;
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Electron number for spin up", nelec_spin[0]);
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Electron number for spin down", nelec_spin[1]);
}
}

// noncolliear :
else if(nspin==4)
{
for(int i=0;i<3;i++)
{
this->tot_mag_nc[i] = 0.00;
}

this->abs_mag = 0.00;
for (int ir=0; ir<nrxx; ir++)
{
double diff = sqrt(pow(rho[1][ir], 2) + pow(rho[2][ir], 2) +pow(rho[3][ir], 2));
// noncolliear :
else if(nspin==4)
{
for(int i=0;i<3;i++)
{
this->tot_mag_nc[i] = 0.00;
}

this->abs_mag = 0.00;
for (int ir=0; ir<nrxx; ir++)
{
double diff = sqrt(pow(rho[1][ir], 2) + pow(rho[2][ir], 2) +pow(rho[3][ir], 2));

for(int i=0;i<3;i++)
{
this->tot_mag_nc[i] += rho[i+1][ir];
}
this->abs_mag += std::abs(diff);
}
for(int i=0;i<3;i++)
{
this->tot_mag_nc[i] += rho[i+1][ir];
}
this->abs_mag += std::abs(diff);
}
#ifdef __MPI
Parallel_Reduce::reduce_pool(this->tot_mag_nc, 3);
Parallel_Reduce::reduce_pool(this->abs_mag);
#endif
for(int i=0;i<3;i++)
{
this->tot_mag_nc[i] *= fac;
for(int i=0;i<3;i++)
{
this->tot_mag_nc[i] *= fac;
// mohan add 2025-06-21
if( std::abs(this->tot_mag_nc[i]) < 1.0e-16)
{
this->tot_mag_nc[i] = 0.0;
}
}
if( std::abs(this->tot_mag_nc[i]) < 1.0e-16)
{
this->tot_mag_nc[i] = 0.0;
}
}

this->abs_mag *= fac;
this->abs_mag *= fac;

// mohan update 2025-06-21
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total magnetism (Bohr mag/cell)",
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Total magnetism (Bohr mag/cell)",
this->tot_mag_nc[0], this->tot_mag_nc[1], this->tot_mag_nc[2]);

ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Absolute magnetism (Bohr mag/cell)",this->abs_mag);
}
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"Absolute magnetism (Bohr mag/cell)",this->abs_mag);
}

return;
}
Expand All @@ -112,8 +112,8 @@ bool Magnetism::judge_parallel(const double a[3], const ModuleBase::Vector3<doub
double cross=0.0;

cross = pow((a[1]*b.z-a[2]*b.y),2)
+ pow((a[2]*b.x-a[0]*b.z),2)
+ pow((a[0]*b.y-a[1]*b.x),2);
+ pow((a[2]*b.x-a[0]*b.z),2)
+ pow((a[0]*b.y-a[1]*b.x),2);

jp = (fabs(cross)<1e-6);
return jp;
Expand Down
18 changes: 9 additions & 9 deletions source/source_cell/magnetism.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ class Magnetism

double abs_mag;

void compute_mag(const double& omega,
const int& nrxx,
const int& nxyz,
const double* const * rho,
const int& nspin,
const bool& two_fermi,
const double& nelec,
double* nelec_spin);
void compute_mag(const double& omega,
const int& nrxx,
const int& nxyz,
const double* const * rho,
const int& nspin,
const bool& two_fermi,
const double& nelec,
double* nelec_spin);

double ux_[3]={0.0};

bool lsign_=false;
bool lsign_=false;

private:

Expand Down
16 changes: 8 additions & 8 deletions source/source_cell/module_neighbor/sltk_atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
/*** Constructors and destructor ***/
FAtom::FAtom()
{
x = 0.0;
y = 0.0;
z = 0.0;
type = 0;
natom = 0;
cell_x = 0;
cell_y = 0;
cell_z = 0;
x = 0.0;
y = 0.0;
z = 0.0;
type = 0;
natom = 0;
cell_x = 0;
cell_y = 0;
cell_z = 0;
}
Loading
Loading