Skip to content

Commit

Permalink
Fix: Segment Fault of PAW (#5738)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Qianruipku and pre-commit-ci-lite[bot] authored Dec 18, 2024
1 parent 0317913 commit f0ff82b
Show file tree
Hide file tree
Showing 26 changed files with 105 additions and 256 deletions.
13 changes: 2 additions & 11 deletions source/module_cell/atom_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,13 @@

Atom::Atom()
{
na = 0;
label = "\0";
label_orb = "\0";
nw = 0;
nwl = 0;
Rcut = 0.0; // pengfei Li 16-2-29
type = 0;
stapos_wf = 0;
mass = 0.0;
}

Atom::~Atom()
{
}

void Atom::set_index(void)
void Atom::set_index()
{
assert(nw != 0);
this->iw2l.resize(nw, 0);
Expand Down Expand Up @@ -84,7 +75,7 @@ void Atom::print_Atom(std::ofstream& ofs)

#include "module_base/parallel_common.h"
#ifdef __MPI
void Atom::bcast_atom(void)
void Atom::bcast_atom()
{
Parallel_Common::bcast_int(type);
Parallel_Common::bcast_int(na);
Expand Down
57 changes: 28 additions & 29 deletions source/module_cell/atom_spec.h
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
#ifndef ATOM_H
#define ATOM_H

#include "atom_pseudo.h"
#include "../module_io/output.h"
#include "atom_pseudo.h"
class Atom
{
public:

public:
// constructor and destructor
Atom();
~Atom();

Atom_pseudo ncpp;
double mass; // the mass of atom
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
std::vector<int> iw2l; // use iw to find L
std::vector<int> iw2_ylm;
std::vector<bool> iw2_new;
int nw; // number of local orbitals (l,n,m) of this type
std::vector<int> iw2_ylm;
std::vector<bool> iw2_new;
int nw = 0; // number of local orbitals (l,n,m) of this type

void set_index(void);

int type; // Index of atom type
int na; // Number of atoms in this type.
int type = 0; // Index of atom type
int na = 0; // Number of atoms in this type.

int nwl; // max L(Angular momentum) (for local basis)
double Rcut; //pengfei Li 16-2-29
int nwl = 0; // max L(Angular momentum) (for local basis)
double Rcut = 0.0; // pengfei Li 16-2-29
std::vector<int> l_nchi; // number of chi for each L
int stapos_wf; // start position of wave functions

std::string label; // atomic symbol
std::vector<ModuleBase::Vector3<double>> tau;// Cartesian coordinates of each atom in this type.
std::vector<ModuleBase::Vector3<double>> dis;// direct displacements of each atom in this type in current step liuyu modift 2023-03-22
std::vector<ModuleBase::Vector3<double>> taud;// Direct coordinates of each atom in this type.
std::vector<ModuleBase::Vector3<double>> vel;// velocities of each atom in this type.
int stapos_wf = 0; // start position of wave functions

std::string label = "\0"; // atomic symbol
std::vector<ModuleBase::Vector3<double>> tau; // Cartesian coordinates of each atom in this type.
std::vector<ModuleBase::Vector3<double>>
dis; // direct displacements of each atom in this type in current step liuyu modift 2023-03-22
std::vector<ModuleBase::Vector3<double>> taud; // Direct coordinates of each atom in this type.
std::vector<ModuleBase::Vector3<double>> vel; // velocities of each atom in this type.
std::vector<ModuleBase::Vector3<double>> force; // force acting on each atom in this type.
std::vector<ModuleBase::Vector3<double>> lambda; // Lagrange multiplier for each atom in this type. used in deltaspin
std::vector<ModuleBase::Vector3<double>>
lambda; // Lagrange multiplier for each atom in this type. used in deltaspin
std::vector<ModuleBase::Vector3<int>> constrain; // constrain for each atom in this type. used in deltaspin
std::string label_orb; // atomic Element symbol in the orbital file of lcao
std::string label_orb = "\0"; // atomic Element symbol in the orbital file of lcao

std::vector<double> mag;
std::vector<double> angle1;//spin angle, added by zhengdy-soc
std::vector<double> angle2;
std::vector<double> mag;
std::vector<double> angle1; // spin angle, added by zhengdy-soc
std::vector<double> angle2;
std::vector<ModuleBase::Vector3<double>> m_loc_;
// Coulomb potential v(r) = z/r
// It is a local potentail, and has no non-local potential parts.
bool coulomb_potential = false;
void print_Atom(std::ofstream &ofs);
void update_force(ModuleBase::matrix &fcs);
void print_Atom(std::ofstream& ofs);
void update_force(ModuleBase::matrix& fcs);
#ifdef __MPI
void bcast_atom(void);
void bcast_atom2(void);
#endif

};

#endif //Atomspec

#endif // Atomspec
40 changes: 0 additions & 40 deletions source/module_cell/test/support/mock_unitcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,14 @@
*/
void UnitCell::set_iat2iwt(const int& npol_in) {}
UnitCell::UnitCell() {
Coordinate = "Direct";
latName = "none";
lat0 = 0.0;
lat0_angstrom = 0.0;

ntype = 0;
nat = 0;
namax = 0;
nwmax = 0;

iat2it = nullptr;
iat2ia = nullptr;
iwt2iat = nullptr;
iwt2iw = nullptr;

itia2iat.create(1, 1);
lc = new int[3];

latvec = ModuleBase::Matrix3();
latvec_supercell = ModuleBase::Matrix3();
G = ModuleBase::Matrix3();
GT = ModuleBase::Matrix3();
GGT = ModuleBase::Matrix3();
invGGT = ModuleBase::Matrix3();

tpiba = 0.0;
tpiba2 = 0.0;
omega = 0.0;

atom_label = new std::string[1];
atom_mass = nullptr;
pseudo_fn = new std::string[1];
pseudo_type = new std::string[1];
orbital_fn = new std::string[1];

set_atom_flag = false;
}
UnitCell::~UnitCell() {
delete[] atom_label;
delete[] atom_mass;
delete[] pseudo_fn;
delete[] pseudo_type;
delete[] orbital_fn;
delete[] iat2it;
delete[] iat2ia;
delete[] iwt2iat;
delete[] iwt2iw;
delete[] lc;
if (set_atom_flag) {
delete[] atoms;
}
Expand Down
39 changes: 0 additions & 39 deletions source/module_cell/unitcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,7 @@ UnitCell::UnitCell() {
if (test_unitcell) {
ModuleBase::TITLE("unitcell", "Constructor");
}
Coordinate = "Direct";
latName = "none";
lat0 = 0.0;
lat0_angstrom = 0.0;

ntype = 0;
nat = 0;
namax = 0;
nwmax = 0;

iat2it = nullptr;
iat2ia = nullptr;
iwt2iat = nullptr;
iwt2iw = nullptr;

itia2iat.create(1, 1);
lc = new int[3];

latvec = ModuleBase::Matrix3();
latvec_supercell = ModuleBase::Matrix3();
G = ModuleBase::Matrix3();
GT = ModuleBase::Matrix3();
GGT = ModuleBase::Matrix3();
invGGT = ModuleBase::Matrix3();

tpiba = 0.0;
tpiba2 = 0.0;
omega = 0.0;

atom_label = new std::string[1];
atom_mass = nullptr;
pseudo_fn = new std::string[1];
pseudo_type = new std::string[1];

set_atom_flag = false;
}

UnitCell::~UnitCell() {
Expand All @@ -74,11 +40,6 @@ UnitCell::~UnitCell() {
delete[] pseudo_fn;
delete[] pseudo_type;
delete[] orbital_fn;
delete[] iat2it;
delete[] iat2ia;
delete[] iwt2iat;
delete[] iwt2iw;
delete[] lc;
if (set_atom_flag) {
delete[] atoms;
}
Expand Down
38 changes: 19 additions & 19 deletions source/module_cell/unitcell.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
// provide the basic information about unitcell.
class UnitCell {
public:
Atom* atoms;
Atom* atoms = nullptr;

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

Lattice lat;
std::string& Coordinate = lat.Coordinate;
std::string& latName = lat.latName;
double& lat0 = lat.lat0;
Expand All @@ -31,7 +32,6 @@ class UnitCell {
double& omega = lat.omega;
int*& lc = lat.lc;

Lattice lat;
ModuleBase::Matrix3& latvec = lat.latvec;
ModuleBase::Vector3<double>&a1 = lat.a1, &a2 = lat.a2, &a3 = lat.a3;
ModuleBase::Vector3<double>& latcenter = lat.latcenter;
Expand Down Expand Up @@ -181,15 +181,15 @@ class UnitCell {
// nelec : total number of electrons
// lmaxmax : revert from INPUT
//============================================================
int meshx;
int natomwfc;
int lmax;
int nmax;
int nmax_total; // mohan add 2009-09-10
int lmax_ppwf;
int lmaxmax; // liuyu 2021-07-04
bool init_vel; // liuyu 2021-07-15
// double nelec;
int meshx = 0;
int natomwfc = 0;
int lmax = 0;
int nmax = 0;
int nmax_total = 0; // mohan add 2009-09-10
int lmax_ppwf = 0;
int lmaxmax = 0; // liuyu 2021-07-04
bool init_vel = false; // liuyu 2021-07-15
// double nelec;

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

double* atom_mass;
std::string* atom_label;
std::string* pseudo_fn;
std::string* pseudo_type; // pseudopotential types for each elements,
// sunliang added 2022-09-15.
double* atom_mass = nullptr;
std::string* atom_label = new std::string[1];
std::string* pseudo_fn = new std::string[1];
std::string* pseudo_type = new std::string[1]; // pseudopotential types for each elements,
// sunliang added 2022-09-15.
std::string* orbital_fn = nullptr; // filenames of orbitals, liuyu add 2022-10-19
std::string
descriptor_file; // filenames of descriptor_file, liuyu add 2023-04-06
Expand Down
67 changes: 40 additions & 27 deletions source/module_cell/unitcell_data.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
#include "module_base/matrix3.h"
#include "module_base/intarray.h"
/// @brief info of lattice
#include "module_base/matrix3.h"
/// @brief info of lattice
struct Lattice
{
std::string Coordinate; // "Direct" or "Cartesian" or "Cartesian_angstrom"
std::string latName; // Lattice name
double lat0; // Lattice constant(bohr)(a.u.)
double lat0_angstrom;// Lattice constant(angstrom)
double tpiba;// 2*pi / lat0;
double tpiba2; // tpiba ^ 2
double omega;// the volume of the unit cell
int* lc; // Change the lattice vectors or not
std::string Coordinate = "Direct"; // "Direct" or "Cartesian" or "Cartesian_angstrom"
std::string latName = "none"; // Lattice name
double lat0 = 0.0; // Lattice constant(bohr)(a.u.)
double lat0_angstrom = 0.0; // Lattice constant(angstrom)
double tpiba = 0.0; // 2*pi / lat0;
double tpiba2 = 0.0; // tpiba ^ 2
double omega = 0.0; // the volume of the unit cell
int* lc = new int[3]; // Change the lattice vectors or not

ModuleBase::Matrix3 latvec; // Unitcell lattice vectors
ModuleBase::Vector3<double> a1, a2, a3; // Same as latvec, just at another form.
ModuleBase::Vector3<double> latcenter; // (a1+a2+a3)/2 the center of vector
ModuleBase::Matrix3 latvec_supercell; // Supercell lattice vectors
ModuleBase::Matrix3 G; // reciprocal lattice vector (2pi*inv(R) )
ModuleBase::Matrix3 GT; // traspose of G
ModuleBase::Matrix3 GGT; // GGT = G*GT
ModuleBase::Matrix3 invGGT; // inverse G
ModuleBase::Matrix3 latvec = ModuleBase::Matrix3(); // Unitcell lattice vectors
ModuleBase::Vector3<double> a1, a2, a3; // Same as latvec, just at another form.
ModuleBase::Vector3<double> latcenter; // (a1+a2+a3)/2 the center of vector
ModuleBase::Matrix3 latvec_supercell = ModuleBase::Matrix3(); // Supercell lattice vectors
ModuleBase::Matrix3 G = ModuleBase::Matrix3(); // reciprocal lattice vector (2pi*inv(R) )
ModuleBase::Matrix3 GT = ModuleBase::Matrix3(); // traspose of G
ModuleBase::Matrix3 GGT = ModuleBase::Matrix3(); // GGT = G*GT
ModuleBase::Matrix3 invGGT = ModuleBase::Matrix3(); // inverse G

~Lattice()
{
delete[] lc;
}
};

//========================================================
Expand All @@ -37,13 +42,21 @@ struct Lattice
/// @brief usefull data and index maps
struct Statistics
{
int ntype;// number of atom species in UnitCell
int nat; // total number of atoms of all species in unitcell
int* iat2it; //iat==>it, distinguish a atom belong to which type
int* iat2ia; //iat==>ia
int* iwt2iat; // iwt ==> iat.
int* iwt2iw; // iwt ==> iw, Peize Lin add 2018-07-02
ModuleBase::IntArray itia2iat;//(it, ia)==>iat, the index in nat, add 2009-3-2 by mohan
int namax;// the max na among all atom species
int nwmax;// the max nw among all atom species
int ntype = 0; // number of atom species in UnitCell
int nat = 0; // total number of atoms of all species in unitcell
int* iat2it = nullptr; // iat==>it, distinguish a atom belong to which type
int* iat2ia = nullptr; // iat==>ia
int* iwt2iat = nullptr; // iwt ==> iat.
int* iwt2iw = nullptr; // iwt ==> iw, Peize Lin add 2018-07-02
ModuleBase::IntArray itia2iat; //(it, ia)==>iat, the index in nat, add 2009-3-2 by mohan
int namax = 0; // the max na among all atom species
int nwmax = 0; // the max nw among all atom species

~Statistics()
{
delete[] iat2it;
delete[] iat2ia;
delete[] iwt2iat;
delete[] iwt2iw;
}
};
2 changes: 0 additions & 2 deletions source/module_elecstate/module_dm/test/test_cal_dm_R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ class DMTest : public testing::Test
{
delete paraV;
delete[] ucell.atoms;
delete[] ucell.iat2it;
delete[] ucell.iat2ia;
}

#ifdef __MPI
Expand Down
Loading

0 comments on commit f0ff82b

Please sign in to comment.