Skip to content

Commit f0ff82b

Browse files
Fix: Segment Fault of PAW (#5738)
* update version * Fix: segment fault of paw * [pre-commit.ci lite] apply automatic fixes * fix UTs * [pre-commit.ci lite] apply automatic fixes * fix UTs * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 0317913 commit f0ff82b

File tree

26 files changed

+105
-256
lines changed

26 files changed

+105
-256
lines changed

source/module_cell/atom_spec.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,13 @@
44

55
Atom::Atom()
66
{
7-
na = 0;
8-
label = "\0";
9-
label_orb = "\0";
10-
nw = 0;
11-
nwl = 0;
12-
Rcut = 0.0; // pengfei Li 16-2-29
13-
type = 0;
14-
stapos_wf = 0;
15-
mass = 0.0;
167
}
178

189
Atom::~Atom()
1910
{
2011
}
2112

22-
void Atom::set_index(void)
13+
void Atom::set_index()
2314
{
2415
assert(nw != 0);
2516
this->iw2l.resize(nw, 0);
@@ -84,7 +75,7 @@ void Atom::print_Atom(std::ofstream& ofs)
8475

8576
#include "module_base/parallel_common.h"
8677
#ifdef __MPI
87-
void Atom::bcast_atom(void)
78+
void Atom::bcast_atom()
8879
{
8980
Parallel_Common::bcast_int(type);
9081
Parallel_Common::bcast_int(na);

source/module_cell/atom_spec.h

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,62 @@
11
#ifndef ATOM_H
22
#define ATOM_H
33

4-
#include "atom_pseudo.h"
54
#include "../module_io/output.h"
5+
#include "atom_pseudo.h"
66
class Atom
77
{
8-
public:
9-
8+
public:
109
// constructor and destructor
1110
Atom();
1211
~Atom();
1312

1413
Atom_pseudo ncpp;
15-
double mass; // the mass of atom
14+
double mass = 0.0; // the mass of atom
1615
std::vector<ModuleBase::Vector3<int>> mbl; // whether the atoms can move or not
17-
bool flag_empty_element = false; // whether is the empty element for bsse. Peize Lin add 2021.04.07
16+
bool flag_empty_element = false; // whether is the empty element for bsse. Peize Lin add 2021.04.07
1817

1918
std::vector<int> iw2m; // use iw to find m
2019
std::vector<int> iw2n; // use iw to find n
2120
std::vector<int> iw2l; // use iw to find L
22-
std::vector<int> iw2_ylm;
23-
std::vector<bool> iw2_new;
24-
int nw; // number of local orbitals (l,n,m) of this type
21+
std::vector<int> iw2_ylm;
22+
std::vector<bool> iw2_new;
23+
int nw = 0; // number of local orbitals (l,n,m) of this type
2524

2625
void set_index(void);
2726

28-
int type; // Index of atom type
29-
int na; // Number of atoms in this type.
27+
int type = 0; // Index of atom type
28+
int na = 0; // Number of atoms in this type.
3029

31-
int nwl; // max L(Angular momentum) (for local basis)
32-
double Rcut; //pengfei Li 16-2-29
30+
int nwl = 0; // max L(Angular momentum) (for local basis)
31+
double Rcut = 0.0; // pengfei Li 16-2-29
3332
std::vector<int> l_nchi; // number of chi for each L
34-
int stapos_wf; // start position of wave functions
35-
36-
std::string label; // atomic symbol
37-
std::vector<ModuleBase::Vector3<double>> tau;// Cartesian coordinates of each atom in this type.
38-
std::vector<ModuleBase::Vector3<double>> dis;// direct displacements of each atom in this type in current step liuyu modift 2023-03-22
39-
std::vector<ModuleBase::Vector3<double>> taud;// Direct coordinates of each atom in this type.
40-
std::vector<ModuleBase::Vector3<double>> vel;// velocities of each atom in this type.
33+
int stapos_wf = 0; // start position of wave functions
34+
35+
std::string label = "\0"; // atomic symbol
36+
std::vector<ModuleBase::Vector3<double>> tau; // Cartesian coordinates of each atom in this type.
37+
std::vector<ModuleBase::Vector3<double>>
38+
dis; // direct displacements of each atom in this type in current step liuyu modift 2023-03-22
39+
std::vector<ModuleBase::Vector3<double>> taud; // Direct coordinates of each atom in this type.
40+
std::vector<ModuleBase::Vector3<double>> vel; // velocities of each atom in this type.
4141
std::vector<ModuleBase::Vector3<double>> force; // force acting on each atom in this type.
42-
std::vector<ModuleBase::Vector3<double>> lambda; // Lagrange multiplier for each atom in this type. used in deltaspin
42+
std::vector<ModuleBase::Vector3<double>>
43+
lambda; // Lagrange multiplier for each atom in this type. used in deltaspin
4344
std::vector<ModuleBase::Vector3<int>> constrain; // constrain for each atom in this type. used in deltaspin
44-
std::string label_orb; // atomic Element symbol in the orbital file of lcao
45+
std::string label_orb = "\0"; // atomic Element symbol in the orbital file of lcao
4546

46-
std::vector<double> mag;
47-
std::vector<double> angle1;//spin angle, added by zhengdy-soc
48-
std::vector<double> angle2;
47+
std::vector<double> mag;
48+
std::vector<double> angle1; // spin angle, added by zhengdy-soc
49+
std::vector<double> angle2;
4950
std::vector<ModuleBase::Vector3<double>> m_loc_;
5051
// Coulomb potential v(r) = z/r
5152
// It is a local potentail, and has no non-local potential parts.
5253
bool coulomb_potential = false;
53-
void print_Atom(std::ofstream &ofs);
54-
void update_force(ModuleBase::matrix &fcs);
54+
void print_Atom(std::ofstream& ofs);
55+
void update_force(ModuleBase::matrix& fcs);
5556
#ifdef __MPI
5657
void bcast_atom(void);
5758
void bcast_atom2(void);
5859
#endif
59-
6060
};
6161

62-
#endif //Atomspec
63-
62+
#endif // Atomspec

source/module_cell/test/support/mock_unitcell.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,14 @@
1010
*/
1111
void UnitCell::set_iat2iwt(const int& npol_in) {}
1212
UnitCell::UnitCell() {
13-
Coordinate = "Direct";
14-
latName = "none";
15-
lat0 = 0.0;
16-
lat0_angstrom = 0.0;
17-
18-
ntype = 0;
19-
nat = 0;
20-
namax = 0;
21-
nwmax = 0;
22-
23-
iat2it = nullptr;
24-
iat2ia = nullptr;
25-
iwt2iat = nullptr;
26-
iwt2iw = nullptr;
27-
2813
itia2iat.create(1, 1);
29-
lc = new int[3];
30-
31-
latvec = ModuleBase::Matrix3();
32-
latvec_supercell = ModuleBase::Matrix3();
33-
G = ModuleBase::Matrix3();
34-
GT = ModuleBase::Matrix3();
35-
GGT = ModuleBase::Matrix3();
36-
invGGT = ModuleBase::Matrix3();
37-
38-
tpiba = 0.0;
39-
tpiba2 = 0.0;
40-
omega = 0.0;
41-
42-
atom_label = new std::string[1];
43-
atom_mass = nullptr;
44-
pseudo_fn = new std::string[1];
45-
pseudo_type = new std::string[1];
46-
orbital_fn = new std::string[1];
47-
48-
set_atom_flag = false;
4914
}
5015
UnitCell::~UnitCell() {
5116
delete[] atom_label;
5217
delete[] atom_mass;
5318
delete[] pseudo_fn;
5419
delete[] pseudo_type;
5520
delete[] orbital_fn;
56-
delete[] iat2it;
57-
delete[] iat2ia;
58-
delete[] iwt2iat;
59-
delete[] iwt2iw;
60-
delete[] lc;
6121
if (set_atom_flag) {
6222
delete[] atoms;
6323
}

source/module_cell/unitcell.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,7 @@ UnitCell::UnitCell() {
3131
if (test_unitcell) {
3232
ModuleBase::TITLE("unitcell", "Constructor");
3333
}
34-
Coordinate = "Direct";
35-
latName = "none";
36-
lat0 = 0.0;
37-
lat0_angstrom = 0.0;
38-
39-
ntype = 0;
40-
nat = 0;
41-
namax = 0;
42-
nwmax = 0;
43-
44-
iat2it = nullptr;
45-
iat2ia = nullptr;
46-
iwt2iat = nullptr;
47-
iwt2iw = nullptr;
48-
4934
itia2iat.create(1, 1);
50-
lc = new int[3];
51-
52-
latvec = ModuleBase::Matrix3();
53-
latvec_supercell = ModuleBase::Matrix3();
54-
G = ModuleBase::Matrix3();
55-
GT = ModuleBase::Matrix3();
56-
GGT = ModuleBase::Matrix3();
57-
invGGT = ModuleBase::Matrix3();
58-
59-
tpiba = 0.0;
60-
tpiba2 = 0.0;
61-
omega = 0.0;
62-
63-
atom_label = new std::string[1];
64-
atom_mass = nullptr;
65-
pseudo_fn = new std::string[1];
66-
pseudo_type = new std::string[1];
67-
68-
set_atom_flag = false;
6935
}
7036

7137
UnitCell::~UnitCell() {
@@ -74,11 +40,6 @@ UnitCell::~UnitCell() {
7440
delete[] pseudo_fn;
7541
delete[] pseudo_type;
7642
delete[] orbital_fn;
77-
delete[] iat2it;
78-
delete[] iat2ia;
79-
delete[] iwt2iat;
80-
delete[] iwt2iw;
81-
delete[] lc;
8243
if (set_atom_flag) {
8344
delete[] atoms;
8445
}

source/module_cell/unitcell.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
// provide the basic information about unitcell.
1616
class UnitCell {
1717
public:
18-
Atom* atoms;
18+
Atom* atoms = nullptr;
1919

20-
bool set_atom_flag; // added on 2009-3-8 by mohan
21-
Magnetism magnet; // magnetism Yu Liu 2021-07-03
20+
bool set_atom_flag = false; // added on 2009-3-8 by mohan
21+
Magnetism magnet; // magnetism Yu Liu 2021-07-03
2222
std::vector<std::vector<double>> atom_mulliken; //[nat][nspin]
23-
int n_mag_at;
23+
int n_mag_at = 0;
2424

25+
Lattice lat;
2526
std::string& Coordinate = lat.Coordinate;
2627
std::string& latName = lat.latName;
2728
double& lat0 = lat.lat0;
@@ -31,7 +32,6 @@ class UnitCell {
3132
double& omega = lat.omega;
3233
int*& lc = lat.lc;
3334

34-
Lattice lat;
3535
ModuleBase::Matrix3& latvec = lat.latvec;
3636
ModuleBase::Vector3<double>&a1 = lat.a1, &a2 = lat.a2, &a3 = lat.a3;
3737
ModuleBase::Vector3<double>& latcenter = lat.latcenter;
@@ -181,15 +181,15 @@ class UnitCell {
181181
// nelec : total number of electrons
182182
// lmaxmax : revert from INPUT
183183
//============================================================
184-
int meshx;
185-
int natomwfc;
186-
int lmax;
187-
int nmax;
188-
int nmax_total; // mohan add 2009-09-10
189-
int lmax_ppwf;
190-
int lmaxmax; // liuyu 2021-07-04
191-
bool init_vel; // liuyu 2021-07-15
192-
// double nelec;
184+
int meshx = 0;
185+
int natomwfc = 0;
186+
int lmax = 0;
187+
int nmax = 0;
188+
int nmax_total = 0; // mohan add 2009-09-10
189+
int lmax_ppwf = 0;
190+
int lmaxmax = 0; // liuyu 2021-07-04
191+
bool init_vel = false; // liuyu 2021-07-15
192+
// double nelec;
193193

194194
private:
195195
ModuleBase::Matrix3 stress; // calculate stress on the cell
@@ -211,11 +211,11 @@ class UnitCell {
211211
void update_stress(ModuleBase::matrix& scs); // updates stress
212212
void update_force(ModuleBase::matrix& fcs); // updates force in Atom
213213

214-
double* atom_mass;
215-
std::string* atom_label;
216-
std::string* pseudo_fn;
217-
std::string* pseudo_type; // pseudopotential types for each elements,
218-
// sunliang added 2022-09-15.
214+
double* atom_mass = nullptr;
215+
std::string* atom_label = new std::string[1];
216+
std::string* pseudo_fn = new std::string[1];
217+
std::string* pseudo_type = new std::string[1]; // pseudopotential types for each elements,
218+
// sunliang added 2022-09-15.
219219
std::string* orbital_fn = nullptr; // filenames of orbitals, liuyu add 2022-10-19
220220
std::string
221221
descriptor_file; // filenames of descriptor_file, liuyu add 2023-04-06

source/module_cell/unitcell_data.h

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
#include "module_base/matrix3.h"
21
#include "module_base/intarray.h"
3-
/// @brief info of lattice
2+
#include "module_base/matrix3.h"
3+
/// @brief info of lattice
44
struct Lattice
55
{
6-
std::string Coordinate; // "Direct" or "Cartesian" or "Cartesian_angstrom"
7-
std::string latName; // Lattice name
8-
double lat0; // Lattice constant(bohr)(a.u.)
9-
double lat0_angstrom;// Lattice constant(angstrom)
10-
double tpiba;// 2*pi / lat0;
11-
double tpiba2; // tpiba ^ 2
12-
double omega;// the volume of the unit cell
13-
int* lc; // Change the lattice vectors or not
6+
std::string Coordinate = "Direct"; // "Direct" or "Cartesian" or "Cartesian_angstrom"
7+
std::string latName = "none"; // Lattice name
8+
double lat0 = 0.0; // Lattice constant(bohr)(a.u.)
9+
double lat0_angstrom = 0.0; // Lattice constant(angstrom)
10+
double tpiba = 0.0; // 2*pi / lat0;
11+
double tpiba2 = 0.0; // tpiba ^ 2
12+
double omega = 0.0; // the volume of the unit cell
13+
int* lc = new int[3]; // Change the lattice vectors or not
1414

15-
ModuleBase::Matrix3 latvec; // Unitcell lattice vectors
16-
ModuleBase::Vector3<double> a1, a2, a3; // Same as latvec, just at another form.
17-
ModuleBase::Vector3<double> latcenter; // (a1+a2+a3)/2 the center of vector
18-
ModuleBase::Matrix3 latvec_supercell; // Supercell lattice vectors
19-
ModuleBase::Matrix3 G; // reciprocal lattice vector (2pi*inv(R) )
20-
ModuleBase::Matrix3 GT; // traspose of G
21-
ModuleBase::Matrix3 GGT; // GGT = G*GT
22-
ModuleBase::Matrix3 invGGT; // inverse G
15+
ModuleBase::Matrix3 latvec = ModuleBase::Matrix3(); // Unitcell lattice vectors
16+
ModuleBase::Vector3<double> a1, a2, a3; // Same as latvec, just at another form.
17+
ModuleBase::Vector3<double> latcenter; // (a1+a2+a3)/2 the center of vector
18+
ModuleBase::Matrix3 latvec_supercell = ModuleBase::Matrix3(); // Supercell lattice vectors
19+
ModuleBase::Matrix3 G = ModuleBase::Matrix3(); // reciprocal lattice vector (2pi*inv(R) )
20+
ModuleBase::Matrix3 GT = ModuleBase::Matrix3(); // traspose of G
21+
ModuleBase::Matrix3 GGT = ModuleBase::Matrix3(); // GGT = G*GT
22+
ModuleBase::Matrix3 invGGT = ModuleBase::Matrix3(); // inverse G
23+
24+
~Lattice()
25+
{
26+
delete[] lc;
27+
}
2328
};
2429

2530
//========================================================
@@ -37,13 +42,21 @@ struct Lattice
3742
/// @brief usefull data and index maps
3843
struct Statistics
3944
{
40-
int ntype;// number of atom species in UnitCell
41-
int nat; // total number of atoms of all species in unitcell
42-
int* iat2it; //iat==>it, distinguish a atom belong to which type
43-
int* iat2ia; //iat==>ia
44-
int* iwt2iat; // iwt ==> iat.
45-
int* iwt2iw; // iwt ==> iw, Peize Lin add 2018-07-02
46-
ModuleBase::IntArray itia2iat;//(it, ia)==>iat, the index in nat, add 2009-3-2 by mohan
47-
int namax;// the max na among all atom species
48-
int nwmax;// the max nw among all atom species
45+
int ntype = 0; // number of atom species in UnitCell
46+
int nat = 0; // total number of atoms of all species in unitcell
47+
int* iat2it = nullptr; // iat==>it, distinguish a atom belong to which type
48+
int* iat2ia = nullptr; // iat==>ia
49+
int* iwt2iat = nullptr; // iwt ==> iat.
50+
int* iwt2iw = nullptr; // iwt ==> iw, Peize Lin add 2018-07-02
51+
ModuleBase::IntArray itia2iat; //(it, ia)==>iat, the index in nat, add 2009-3-2 by mohan
52+
int namax = 0; // the max na among all atom species
53+
int nwmax = 0; // the max nw among all atom species
54+
55+
~Statistics()
56+
{
57+
delete[] iat2it;
58+
delete[] iat2ia;
59+
delete[] iwt2iat;
60+
delete[] iwt2iw;
61+
}
4962
};

source/module_elecstate/module_dm/test/test_cal_dm_R.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ class DMTest : public testing::Test
7878
{
7979
delete paraV;
8080
delete[] ucell.atoms;
81-
delete[] ucell.iat2it;
82-
delete[] ucell.iat2ia;
8381
}
8482

8583
#ifdef __MPI

0 commit comments

Comments
 (0)