Skip to content

Commit 7be31be

Browse files
mohanchenabacus_fixer
andauthored
keep cleaning source_cell (#7684)
* keep cleaning source_cell * remove #ifdef LCAO in read_atom_species.cpp * add comments in the format of doxygen * update format --------- Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
1 parent 83c89c4 commit 7be31be

67 files changed

Lines changed: 1892 additions & 749 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ OBJS_CELL=atom_pseudo.o\
208208
cal_nelec_nband.o\
209209
read_pseudo.o\
210210
cal_wfc.o\
211+
cal_ux.o\
211212

212213
OBJS_DEEPKS=LCAO_deepks.o\
213214
deepks_basic.o\
@@ -248,7 +249,6 @@ OBJS_ELECSTAT=elecstate.o\
248249
H_Hartree_pw.o\
249250
H_TDDFT_pw.o\
250251
pot_xc.o\
251-
cal_ux.o\
252252
read_orb.o\
253253
setup_estate_pw.o\
254254
update_pot.o\

source/source_cell/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ add_library(
3636
cal_nelec_nband.cpp
3737
read_pseudo.cpp
3838
cal_wfc.cpp
39+
cal_ux.cpp
3940
)
4041

4142
if(ENABLE_COVERAGE)

source/source_cell/atom_pseudo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @file atom_pseudo.cpp
3+
* @brief Implementation of Atom_pseudo class.
4+
*/
15
#include "atom_pseudo.h"
26

37
Atom_pseudo::Atom_pseudo()

source/source_cell/atom_pseudo.h

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @file atom_pseudo.h
3+
* @brief Atom_pseudo class for atom pseudopotential data.
4+
*/
15
#ifndef ATOM_PSEUDO_H
26
#define ATOM_PSEUDO_H
37

@@ -6,24 +10,37 @@
610
#include "source_base/complexmatrix.h"
711
#include "pseudo.h"
812

9-
13+
/**
14+
* @brief Atom_pseudo class for atom pseudopotential data.
15+
*/
1016
class Atom_pseudo : public pseudo
1117
{
1218
public:
1319

1420
Atom_pseudo();
1521
~Atom_pseudo();
1622

17-
// mohan add 2021-05-07
18-
ModuleBase::ComplexArray d_so; //(:,:,:), spin-orbit case
19-
ModuleBase::matrix d_real; //(:,:), non-spin-orbit case
20-
int nproj;
21-
int nproj_soc; // dimension of D_ij^so
22-
std::vector<int> non_zero_count_soc = {0, 0, 0, 0};
23-
std::vector<std::vector<int>> index1_soc = {{}, {}, {}, {}};
24-
std::vector<std::vector<int>> index2_soc = {{}, {}, {}, {}};
23+
/// @brief spin-orbit coupling data (mohan add 2021-05-07)
24+
ModuleBase::ComplexArray d_so; ///< (:,:,:), spin-orbit case
25+
ModuleBase::matrix d_real; ///< (:,:), non-spin-orbit case
26+
int nproj; ///< number of projectors
27+
int nproj_soc; ///< dimension of D_ij^so
28+
29+
std::vector<int> non_zero_count_soc = {0, 0, 0, 0}; ///< non-zero count for SOC
30+
std::vector<std::vector<int>> index1_soc = {{}, {}, {}, {}}; ///< index1 for SOC
31+
std::vector<std::vector<int>> index2_soc = {{}, {}, {}, {}}; ///< index2 for SOC
2532

26-
void set_d_so( // mohan add 2021-05-07
33+
/**
34+
* @brief Set spin-orbit coupling matrix.
35+
*
36+
* @param d_so_in input complex matrix for SOC
37+
* @param nproj_in number of projectors
38+
* @param nproj_in_so number of projectors for SOC
39+
* @param has_so whether SOC is present
40+
* @param lspinorb whether spin-orbit is enabled
41+
* @param nspin number of spin states
42+
*/
43+
void set_d_so(
2744
ModuleBase::ComplexMatrix &d_so_in,
2845
const int &nproj_in,
2946
const int &nproj_in_so,
@@ -32,11 +49,28 @@ class Atom_pseudo : public pseudo
3249
const int nspin);
3350

3451

52+
/**
53+
* @brief Get spin-orbit coupling matrix.
54+
*
55+
* @param is spin index
56+
* @param p1 first projector index
57+
* @param p2 second projector index
58+
* @param tmp_d pointer to the matrix element (output)
59+
*/
3560
inline void get_d(const int& is, const int& p1, const int& p2, const std::complex<double>*& tmp_d)
3661
{
3762
tmp_d = &this->d_so(is, p1, p2);
3863
return;
3964
}
65+
66+
/**
67+
* @brief Get real coupling matrix.
68+
*
69+
* @param is spin index
70+
* @param p1 first projector index
71+
* @param p2 second projector index
72+
* @param tmp_d pointer to the matrix element (output)
73+
*/
4074
inline void get_d(const int& is, const int& p1, const int& p2, const double*& tmp_d)
4175
{
4276
tmp_d = &this->d_real(p1, p2);
@@ -45,7 +79,12 @@ class Atom_pseudo : public pseudo
4579

4680

4781
#ifdef __MPI
48-
void bcast_atom_pseudo(void); // for upf201
82+
/**
83+
* @brief Broadcast atom pseudopotential data.
84+
*
85+
* For UPF201 format.
86+
*/
87+
void bcast_atom_pseudo(void);
4988
#endif
5089

5190
};

source/source_cell/atom_spec.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @file atom_spec.cpp
3+
* @brief Implementation of Atom class.
4+
*/
15
#include "atom_spec.h"
26
#include "source_base/output.h"
37
#include <cstdlib>

source/source_cell/atom_spec.h

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,96 @@
1+
/**
2+
* @file atom_spec.h
3+
* @brief Atom class for storing atom information.
4+
*/
15
#ifndef ATOM_H
26
#define ATOM_H
37

48
#include "atom_pseudo.h"
9+
10+
/**
11+
* @brief Atom class for storing atom information.
12+
*/
513
class Atom
614
{
715
public:
8-
// constructor and destructor
16+
/**
17+
* @brief Constructor.
18+
*/
919
Atom();
20+
21+
/**
22+
* @brief Destructor.
23+
*/
1024
~Atom();
1125

12-
Atom_pseudo ncpp;
13-
double mass = 0.0; // the mass of atom
14-
std::vector<ModuleBase::Vector3<int>> mbl; // whether the atoms can move or not
15-
bool flag_empty_element = false; // whether is the empty element for bsse. Peize Lin add 2021.04.07
26+
Atom_pseudo ncpp; ///< pseudopotential for this atom type
27+
double mass = 0.0; ///< the mass of atom
28+
std::vector<ModuleBase::Vector3<int>> mbl; ///< whether the atoms can move or not
29+
bool flag_empty_element = false; ///< whether is the empty element for bsse (Peize Lin add 2021.04.07)
1630

17-
std::vector<int> iw2m; // use iw to find m
18-
std::vector<int> iw2n; // use iw to find n
19-
std::vector<int> iw2l; // use iw to find L
20-
std::vector<int> iw2_ylm;
21-
std::vector<bool> iw2_new;
22-
int nw = 0; // number of local orbitals (l,n,m) of this type
31+
std::vector<int> iw2m; ///< use iw to find m
32+
std::vector<int> iw2n; ///< use iw to find n
33+
std::vector<int> iw2l; ///< use iw to find L
34+
std::vector<int> iw2_ylm; ///< use iw to find ylm index
35+
std::vector<bool> iw2_new; ///< use iw to find new flag
36+
int nw = 0; ///< number of local orbitals (l,n,m) of this type
2337

38+
/**
39+
* @brief Set index arrays.
40+
*/
2441
void set_index();
2542

26-
int type = 0; // Index of atom type
27-
int na = 0; // Number of atoms in this type.
43+
int type = 0; ///< Index of atom type
44+
int na = 0; ///< Number of atoms in this type
2845

29-
int nwl = 0; // max L(Angular momentum) (for local basis)
30-
double Rcut = 0.0; // pengfei Li 16-2-29
31-
std::vector<int> l_nchi; // number of chi for each L
32-
int stapos_wf = 0; // start position of wave functions
46+
int nwl = 0; ///< max L(Angular momentum) (for local basis)
47+
double Rcut = 0.0; ///< cut-off radius (pengfei Li 16-2-29)
48+
std::vector<int> l_nchi; ///< number of chi for each L
49+
int stapos_wf = 0; ///< start position of wave functions
3350

3451
std::string label; ///< atomic symbol
35-
std::vector<ModuleBase::Vector3<double>> tau; // Cartesian coordinates of each atom in this type.
36-
std::vector<ModuleBase::Vector3<double>> dis; // direct displacements of each atom in this type in current step liuyu modift 2023-03-22
37-
std::vector<ModuleBase::Vector3<double>> taud; // Direct coordinates of each atom in this type.
38-
std::vector<ModuleBase::Vector3<int>> boundary_shift; // record for periodic boundary adjustment.
39-
std::vector<ModuleBase::Vector3<double>> vel; // velocities of each atom in this type.
40-
std::vector<ModuleBase::Vector3<double>> force; // force acting on each atom in this type.
41-
std::vector<ModuleBase::Vector3<double>> lambda; // Lagrange multiplier for each atom in this type. used in deltaspin
42-
std::vector<ModuleBase::Vector3<int>> constrain; // constrain for each atom in this type. used in deltaspin
43-
std::string label_orb; ///< atomic element symbol in the orbital file of lcao
44-
45-
std::vector<double> mag;
46-
std::vector<double> angle1; // spin angle, added by zhengdy-soc
47-
std::vector<double> angle2;
48-
std::vector<ModuleBase::Vector3<double>> m_loc_;
49-
// Coulomb potential v(r) = z/r
50-
// It is a local potentail, and has no non-local potential parts.
52+
std::vector<ModuleBase::Vector3<double>> tau; ///< Cartesian coordinates of each atom in this type
53+
std::vector<ModuleBase::Vector3<double>> dis; ///< direct displacements of each atom in this type in current step (liuyu modify 2023-03-22)
54+
std::vector<ModuleBase::Vector3<double>> taud; ///< Direct coordinates of each atom in this type
55+
std::vector<ModuleBase::Vector3<int>> boundary_shift; ///< record for periodic boundary adjustment
56+
std::vector<ModuleBase::Vector3<double>> vel; ///< velocities of each atom in this type
57+
std::vector<ModuleBase::Vector3<double>> force; ///< force acting on each atom in this type
58+
std::vector<ModuleBase::Vector3<double>> lambda; ///< Lagrange multiplier for each atom in this type, used in deltaspin
59+
std::vector<ModuleBase::Vector3<int>> constrain; ///< constrain for each atom in this type, used in deltaspin
60+
std::string label_orb; ///< atomic element symbol in the orbital file of lcao
61+
62+
std::vector<double> mag; ///< magnetic moment
63+
std::vector<double> angle1; ///< spin angle, added by zhengdy-soc
64+
std::vector<double> angle2; ///< spin angle, added by zhengdy-soc
65+
std::vector<ModuleBase::Vector3<double>> m_loc_; ///< local magnetic moment
66+
67+
/// @brief Coulomb potential v(r) = z/r
68+
/// It is a local potential, and has no non-local potential parts.
5169
bool coulomb_potential = false;
70+
71+
/**
72+
* @brief Print atom information.
73+
*
74+
* @param ofs output file stream
75+
*/
5276
void print_Atom(std::ofstream& ofs);
77+
78+
/**
79+
* @brief Update force.
80+
*
81+
* @param fcs force constant matrix
82+
*/
5383
void update_force(ModuleBase::matrix& fcs);
84+
5485
#ifdef __MPI
86+
/**
87+
* @brief Broadcast atom data.
88+
*/
5589
void bcast_atom();
90+
91+
/**
92+
* @brief Broadcast atom data (second version).
93+
*/
5694
void bcast_atom2();
5795
#endif
5896
};

source/source_cell/cal_atoms_info.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
1+
/**
2+
* @file cal_atoms_info.h
3+
* @brief CalAtomsInfo class for calculating atom information.
4+
*/
15
#ifndef CAL_ATOMS_INFO_H
26
#define CAL_ATOMS_INFO_H
37
#include "source_cell/cal_nelec_nband.h"
48
#include "source_base/global_function.h"
59

10+
/**
11+
* @brief Result struct for atom information calculation.
12+
*/
613
struct AtomsInfoResult
714
{
8-
int nlocal = 0;
9-
double nelec = 0.0;
10-
int nbands = 0;
11-
double nupdown = 0.0;
12-
bool use_uspp = false;
13-
int nbands_l = 0;
14-
bool ks_run = false;
15+
int nlocal = 0; ///< total number of local basis
16+
double nelec = 0.0; ///< total number of electrons
17+
int nbands = 0; ///< number of bands
18+
double nupdown = 0.0; ///< spin polarization
19+
bool use_uspp = false; ///< whether to use USPP
20+
int nbands_l = 0; ///< number of local bands
21+
bool ks_run = false; ///< whether to run KS solver
1522
};
1623

24+
/**
25+
* @brief CalAtomsInfo class for calculating atom information.
26+
*/
1727
class CalAtomsInfo
1828
{
1929
public:
30+
/**
31+
* @brief Default constructor.
32+
*/
2033
CalAtomsInfo(){};
34+
35+
/**
36+
* @brief Destructor.
37+
*/
2138
~CalAtomsInfo(){};
2239

2340
/**

source/source_cell/cal_nelec_nband.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @file cal_nelec_nband.cpp
3+
* @brief Implementation of electron and band calculation functions.
4+
*/
15
#include "cal_nelec_nband.h"
26
#include "source_base/constants.h"
37
#include "source_base/global_variable.h"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "cal_ux.h"
22

3-
namespace elecstate {
3+
namespace unitcell {
44

55
void cal_ux(UnitCell& ucell, const int nspin) {
66

@@ -78,7 +78,7 @@ void cal_ux(UnitCell& ucell, const int nspin) {
7878

7979
if (uxmod < absolute_mag_thr)
8080
{
81-
ModuleBase::WARNING_QUIT("elecstate::cal_ux", "wrong uxmod");
81+
ModuleBase::WARNING_QUIT("unitcell::cal_ux", "wrong uxmod");
8282
}
8383

8484
// reset the magnetism for each direction

source/source_cell/cal_ux.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @file cal_ux.h
3+
* @brief Functions for calculating ux and related operations.
4+
*/
5+
#ifndef CAL_UX_H
6+
#define CAL_UX_H
7+
8+
#include "source_cell/unitcell.h"
9+
10+
namespace unitcell {
11+
12+
/**
13+
* @brief Calculate ux for the unit cell.
14+
*
15+
* @param ucell unit cell [in/out]
16+
* @param nspin number of spin components [in]
17+
*/
18+
void cal_ux(UnitCell& ucell, const int nspin);
19+
20+
/**
21+
* @brief Judge if two vectors are parallel.
22+
*
23+
* @param a first vector [in]
24+
* @param b second vector [in]
25+
* @return true if vectors are parallel
26+
*/
27+
bool judge_parallel(double a[3], ModuleBase::Vector3<double> b);
28+
29+
}
30+
31+
#endif

0 commit comments

Comments
 (0)