@@ -14,57 +14,50 @@ void Write_MLKEDF_Descriptors::generateTrainData_KS(
1414 ModulePW::PW_Basis_K *pw_psi,
1515 ModulePW::PW_Basis *pw_rho,
1616 UnitCell& ucell,
17- const double * veff
17+ const double * veff,
18+ const int nrxx
1819)
1920{
20- std::vector<std::vector<double >> nablaRho (3 , std::vector<double >(this ->cal_tool ->nx , 0 .));
21+ if (nrxx <= 0 )
22+ {
23+ ModuleBase::WARNING_QUIT (" Write_MLKEDF_Descriptors::generateTrainData_KS" , " nrxx must be greater than 0" );
24+ }
25+
26+ std::vector<std::vector<double >> drho (3 , std::vector<double >(nrxx, 0 .));
2127
22- this ->generate_descriptor (out_dir, pelec->charge ->rho , pw_rho, nablaRho );
28+ this ->generate_descriptor (out_dir, pelec->charge ->rho , pw_rho, drho, nrxx );
2329
24- std::vector<double > container ( this -> cal_tool -> nx );
25- std::vector<double > containernl ( this -> cal_tool -> nx );
30+ std::vector<double > enhancement (nrxx );
31+ std::vector<double > pauli (nrxx );
2632
27- const long unsigned cshape[] = {(long unsigned ) this ->cal_tool ->nx }; // shape of container and containernl
28- // enhancement factor of Pauli energy, and Pauli potential
29- this ->cal_tool ->getF_KS (psi, pelec, pw_psi, pw_rho, ucell, nablaRho, container, containernl);
33+ this ->cal_tool ->getF_KS (psi, pelec, pw_psi, pw_rho, ucell, drho, enhancement, pauli);
3034
3135 Symmetry_rho srho;
3236
33- Charge* ptempRho = new Charge ();
34- ptempRho->nspin = PARAM .inp .nspin ;
35- ptempRho->nrxx = this ->cal_tool ->nx ;
36- ptempRho->rho_core = pelec->charge ->rho_core ;
37- ptempRho->rho = new double *[1 ];
38- ptempRho->rho [0 ] = new double [this ->cal_tool ->nx ];
39- ptempRho->rhog = new std::complex <double >*[1 ];
40- ptempRho->rhog [0 ] = new std::complex <double >[pw_rho->npw ];
41-
42- for (int ir = 0 ; ir < this ->cal_tool ->nx ; ++ir){
43- ptempRho->rho [0 ][ir] = container[ir];
44- }
45- srho.begin (0 , *ptempRho, pw_rho, ucell.symm );
46- for (int ir = 0 ; ir < this ->cal_tool ->nx ; ++ir){
47- container[ir] = ptempRho->rho [0 ][ir];
48- }
37+ std::vector<double > rho_vec (nrxx);
38+ std::vector<std::complex <double >> rhog_vec (pw_rho->npw );
39+ double * rho_ptr = rho_vec.data ();
40+ std::complex <double >* rhog_ptr = rhog_vec.data ();
41+
42+ std::copy (enhancement.begin (), enhancement.end (), rho_vec.begin ());
43+ srho.begin (0 , &rho_ptr, &rhog_ptr, pw_rho->npw , nullptr , pw_rho, ucell.symm );
44+ std::copy (rho_vec.begin (), rho_vec.end (), enhancement.begin ());
45+
46+ std::copy (pauli.begin (), pauli.end (), rho_vec.begin ());
47+ srho.begin (0 , &rho_ptr, &rhog_ptr, pw_rho->npw , nullptr , pw_rho, ucell.symm );
48+ std::copy (rho_vec.begin (), rho_vec.end (), pauli.begin ());
4949
50- for (int ir = 0 ; ir < this ->cal_tool ->nx ; ++ir){
51- ptempRho->rho [0 ][ir] = containernl[ir];
52- }
53- srho.begin (0 , *ptempRho, pw_rho, ucell.symm );
54- for (int ir = 0 ; ir < this ->cal_tool ->nx ; ++ir){
55- containernl[ir] = ptempRho->rho [0 ][ir];
56- }
5750
58- npy::SaveArrayAsNumpy (out_dir + " /enhancement.npy" , false , 1 , cshape, container);
59- npy::SaveArrayAsNumpy (out_dir + " /pauli.npy" , false , 1 , cshape, containernl);
51+ // output data in .npy format
52+ const long unsigned cshape[] = {(long unsigned ) nrxx};
53+ npy::SaveArrayAsNumpy (out_dir + " /enhancement.npy" , false , 1 , cshape, enhancement);
54+ npy::SaveArrayAsNumpy (out_dir + " /pauli.npy" , false , 1 , cshape, pauli);
6055
61- for (int ir = 0 ; ir < this -> cal_tool -> nx ; ++ir)
56+ for (int ir = 0 ; ir < nrxx ; ++ir)
6257 {
63- container [ir] = veff[ir];
58+ enhancement [ir] = veff[ir];
6459 }
65- npy::SaveArrayAsNumpy (out_dir + " /veff.npy" , false , 1 , cshape, container);
66-
67- delete ptempRho;
60+ npy::SaveArrayAsNumpy (out_dir + " /veff.npy" , false , 1 , cshape, enhancement);
6861}
6962
7063void Write_MLKEDF_Descriptors::generateTrainData_KS (
@@ -74,12 +67,13 @@ void Write_MLKEDF_Descriptors::generateTrainData_KS(
7467 ModulePW::PW_Basis_K *pw_psi,
7568 ModulePW::PW_Basis *pw_rho,
7669 UnitCell& ucell,
77- const double * veff
70+ const double * veff,
71+ const int nrxx
7872)
7973{
8074 psi::Psi<std::complex <double >, base_device::DEVICE_CPU > psi_double (*psi);
8175
82- this ->generateTrainData_KS (out_dir, &psi_double, pelec, pw_psi, pw_rho, ucell, veff);
76+ this ->generateTrainData_KS (out_dir, &psi_double, pelec, pw_psi, pw_rho, ucell, veff, nrxx );
8377}
8478
8579#if ((defined __CUDA) || (defined __ROCM))
@@ -90,12 +84,13 @@ void Write_MLKEDF_Descriptors::generateTrainData_KS(
9084 ModulePW::PW_Basis_K *pw_psi,
9185 ModulePW::PW_Basis *pw_rho,
9286 UnitCell& ucell,
93- const double * veff
87+ const double * veff,
88+ const int nrxx
9489)
9590{
9691 psi::Psi<std::complex <double >, base_device::DEVICE_CPU > psi_cpu (*psi);
9792
98- this ->generateTrainData_KS (out_dir, &psi_cpu, pelec, pw_psi, pw_rho, ucell, veff);
93+ this ->generateTrainData_KS (out_dir, &psi_cpu, pelec, pw_psi, pw_rho, ucell, veff, nrxx );
9994}
10095
10196void Write_MLKEDF_Descriptors::generateTrainData_KS (
@@ -105,34 +100,36 @@ void Write_MLKEDF_Descriptors::generateTrainData_KS(
105100 ModulePW::PW_Basis_K *pw_psi,
106101 ModulePW::PW_Basis *pw_rho,
107102 UnitCell& ucell,
108- const double *veff
103+ const double *veff,
104+ const int nrxx
109105)
110106{
111107 psi::Psi<std::complex <double >, base_device::DEVICE_CPU > psi_cpu_double (*psi);
112108
113- this ->generateTrainData_KS (dir, &psi_cpu_double, pelec, pw_psi, pw_rho, ucell, veff);
109+ this ->generateTrainData_KS (dir, &psi_cpu_double, pelec, pw_psi, pw_rho, ucell, veff, nrxx );
114110}
115111#endif
116112
117113void Write_MLKEDF_Descriptors::generate_descriptor (
118114 const std::string& out_dir,
119115 const double * const *prho,
120116 ModulePW::PW_Basis *pw_rho,
121- std::vector<std::vector<double >> &nablaRho
117+ std::vector<std::vector<double >> &nablaRho,
118+ const int nrxx
122119)
123120{
124121 // container which will contain gamma, p, q in turn
125- std::vector<double > container (this -> cal_tool -> nx );
126- std::vector<double > new_container (this -> cal_tool -> nx );
122+ std::vector<double > container (nrxx );
123+ std::vector<double > new_container (nrxx );
127124 // container contains gammanl, pnl, qnl in turn
128- std::vector<double > containernl (this -> cal_tool -> nx );
129- std::vector<double > new_containernl (this -> cal_tool -> nx );
125+ std::vector<double > containernl (nrxx );
126+ std::vector<double > new_containernl (nrxx );
130127
131- const long unsigned cshape[] = {(long unsigned ) this -> cal_tool -> nx }; // shape of container and containernl
128+ const long unsigned cshape[] = {(long unsigned ) nrxx};
132129
133130 // rho
134- std::vector<double > rho (this -> cal_tool -> nx );
135- for (int ir = 0 ; ir < this -> cal_tool -> nx ; ++ir){
131+ std::vector<double > rho (nrxx );
132+ for (int ir = 0 ; ir < nrxx ; ++ir){
136133 rho[ir] = prho[0 ][ir];
137134 }
138135 npy::SaveArrayAsNumpy (out_dir + " /rho.npy" , false , 1 , cshape, rho);
@@ -236,4 +233,4 @@ std::string Write_MLKEDF_Descriptors::file_name(
236233
237234}
238235
239- #endif
236+ #endif
0 commit comments