Skip to content

Commit ea9b954

Browse files
committed
fix compilation error
1 parent 7162530 commit ea9b954

File tree

7 files changed

+69
-41
lines changed

7 files changed

+69
-41
lines changed

source/module_hamilt_general/module_xc/NCLibxc/NCLibxc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
module load gcc/7.3.0-wzm
88
g++ -std=c++17 -o my_program NCLibxc.cpp LebedevGrid.cpp interface_to_libxc.cpp -I/public1/soft/libxc/install/include -L/public1/soft/libxc/install/lib -lxc
99
*/
10+
#ifdef USE_LIBXC
1011
#include "NCLibxc.h"
1112
#include "interface_to_libxc.h"
1213
#include <iostream>
@@ -309,3 +310,4 @@ int main()
309310
}
310311
*/
311312

313+
#endif // USE_LIBXC

source/module_hamilt_general/module_xc/NCLibxc/NCLibxc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef NCLIBXC_H
22
#define NCLIBXC_H
33

4+
#ifdef USE_LIBXC
5+
46
#include <vector>
57
#include <array>
68
#include <complex>
@@ -50,5 +52,6 @@ class NCLibxc {
5052
// 声明 MakeAngularGrid 函数
5153
std::vector<std::array<double, 4>> MakeAngularGrid(int grid_level);
5254

55+
#endif // USE_LIBXC
5356

54-
#endif // NCLIBXC_H
57+
#endif // NCLIBXC_H

source/module_hamilt_general/module_xc/NCLibxc/interface_to_libxc.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// ./my_program
88

99
// func_id can be found in the libxc website https://libxc.gitlab.io/functionals/
10+
11+
#ifdef USE_LIBXC
12+
1013
#include "interface_to_libxc.h"
1114
#include <iostream>
1215

@@ -1046,4 +1049,4 @@ int main()
10461049

10471050

10481051
//////////////////////////////////////////////////////////////////////////////////////////////////
1049-
1052+
#endif // USE_LIBXC

source/module_hamilt_general/module_xc/NCLibxc/interface_to_libxc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#ifndef INTERFACE_TO_LIBXC_H
44
#define INTERFACE_TO_LIBXC_H
55

6+
#ifdef USE_LIBXC
7+
68
#include <xc.h>
79
#include <vector>
810
#include <stdexcept>
@@ -75,4 +77,6 @@ class LibxcInterface
7577
void example_mgga_spin();
7678
};
7779

78-
#endif // INTERFACE_TO_LIBXC_H
80+
#endif // USE_LIBXC
81+
82+
#endif // INTERFACE_TO_LIBXC_H

source/module_hamilt_general/module_xc/xc_functional_NCLibxc_gga.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// This file is for implementing multi-collinear appraoch for GGA functionals.
33
// NCLibxc package only completes multi-collienar approach for LDA functionals, because the GGA functionals need gradient that is entangled with ABACUS.
44
//Ref: PHYSICAL REVIEW RESEARCH 5, 013036 (2023)
5+
6+
#ifdef USE_LIBXC
7+
58
#include "xc_functional.h"
69
#include "module_base/parallel_reduce.h"
710
#include "module_base/timer.h"
@@ -243,3 +246,5 @@ std::pair<std::vector<double>, std::vector<Matrix2x2>> XC_Functional::gga_mc(int
243246

244247
return {E, V};
245248
}
249+
250+
#endif // USE_LIBXC

source/module_hamilt_general/module_xc/xc_functional_libxc_vxc.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,11 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
152152
if (n[0] - amag <= 0.0) { //ensure the rhoup and rhodn to libxc are positive
153153
continue;
154154
}
155+
std::vector<double> E_MC;
156+
std::vector<Matrix2x2> V_MC;
155157
for(const int &id : func_id){
156-
auto [E_MC, V_MC] = NCLibxc::lda_mc(id, n, mx, my, mz);
158+
//auto [E_MC, V_MC] = NCLibxc::lda_mc(id, n, mx, my, mz);
159+
std::tie(E_MC, V_MC) = NCLibxc::lda_mc(id, n, mx, my, mz);
157160
exc = e2*E_MC[0];
158161
v_nspin4(0, ir) += std::real(e2*(V_MC[0][0][0]+V_MC[0][1][1])/two);
159162
v_nspin4(1, ir) += std::real(e2*(V_MC[0][0][1]+V_MC[0][1][0])/two);
@@ -189,8 +192,11 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
189192
// }
190193
// }
191194

195+
std::vector<double> E_MC;
196+
std::vector<Matrix2x2> V_MC;
192197
for (const int& id : func_id) {
193-
auto [E_MC, V_MC] = XC_Functional::gga_mc(id, n, mx, my, mz, chr, tpiba);
198+
//auto [E_MC, V_MC] = XC_Functional::gga_mc(id, n, mx, my, mz, chr, tpiba);
199+
std::tie(E_MC, V_MC) = XC_Functional::gga_mc(id, n, mx, my, mz, chr, tpiba);
194200
#ifdef _OPENMP
195201
#pragma omp parallel for schedule(static, 1024) reduction(+:etxc) reduction(+:vtxc)
196202
#endif

source/module_hamilt_general/module_xc/xc_functional_vxc.cpp

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "module_parameter/parameter.h"
1111

1212
#ifdef USE_LIBXC
13-
#include "xc_functional_libxc.h"
1413
#include "NCLibxc/NCLibxc.h"
14+
#include "xc_functional_libxc.h"
1515
#include <tuple>
1616
#include <iostream>
1717
#include <vector>
@@ -179,40 +179,45 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional::v_xc(
179179
if (PARAM.inp.nspin == 4 && PARAM.inp.multicolin == 1
180180
&& (func_type == 0 || func_type == 1) )
181181
{ // noncollinear case added by Xiaoyu Zhang, Peking University, 2024.10.02. multicollinear method for lda Since NCLibxc needs libxc, this part codes will not be used.
182-
NCLibxc::print_NCLibxc();
183-
#ifdef _OPENMP
184-
#pragma omp parallel for reduction(+:etxc) reduction(+:vtxc)
185-
#endif
186-
for(int ir = 0;ir<nrxx; ir++)
187-
{
188-
if(!use_libxc){
189-
std::cerr << "Error: Multi-collinear approach does not support running without Libxc." << std::endl;
190-
std::exit(EXIT_FAILURE);
191-
}
192-
double exc = 0.0;
193-
for(int ipol=0;ipol<4;ipol++){
194-
v(ipol, ir) = 0;
195-
}
196-
NCLibxc nc_libxc;
197-
std::vector<double> n = {chr->rho[0][ir] + chr->rho_core[ir]};
198-
std::vector<double> mx = {chr->rho[1][ir]};
199-
std::vector<double> my = {chr->rho[2][ir]};
200-
std::vector<double> mz = {chr->rho[3][ir]};
201-
double amag = sqrt( pow(chr->rho[1][ir],2) + pow(chr->rho[2][ir],2) + pow(chr->rho[3][ir],2) );
202-
if (n[0] - amag <= 0.0) { //ensure the rhoup and rhodn to libxc are positive
203-
continue;
204-
}
205-
for(const int &id : func_id){
206-
auto [E_MC, V_MC] = NCLibxc::lda_mc(id, n, mx, my, mz);
207-
exc = e2*E_MC[0];
208-
v(0, ir) += std::real(e2*(V_MC[0][0][0]+V_MC[0][1][1])/two);
209-
v(1, ir) += std::real(e2*(V_MC[0][0][1]+V_MC[0][1][0])/two);
210-
v(2, ir) += std::real(e2*(V_MC[0][1][0]-V_MC[0][0][1])/twoi);
211-
v(3, ir) += std::real(e2*(V_MC[0][0][0]-V_MC[0][1][1])/two);
212-
etxc += exc * n[0];
213-
vtxc += v(0, ir) * chr->rho[0][ir] + v(1, ir) * chr->rho[1][ir] + v(2, ir) * chr->rho[2][ir] + v(3, ir) * chr->rho[3][ir];
214-
}
215-
}
182+
183+
std::cerr << "Error: Multi-collinear approach does not support running without Libxc." << std::endl;
184+
std::exit(EXIT_FAILURE);
185+
// NCLibxc::print_NCLibxc();
186+
//#ifdef _OPENMP
187+
//#pragma omp parallel for reduction(+:etxc) reduction(+:vtxc)
188+
//#endif
189+
// for(int ir = 0;ir<nrxx; ir++)
190+
// {
191+
// if(!use_libxc){
192+
// std::cerr << "Error: Multi-collinear approach does not support running without Libxc." << std::endl;
193+
// std::exit(EXIT_FAILURE);
194+
// }
195+
// double exc = 0.0;
196+
// for(int ipol=0;ipol<4;ipol++){
197+
// v(ipol, ir) = 0;
198+
// }
199+
//
200+
// std::vector<double> n = {chr->rho[0][ir] + chr->rho_core[ir]};
201+
// std::vector<double> mx = {chr->rho[1][ir]};
202+
// std::vector<double> my = {chr->rho[2][ir]};
203+
// std::vector<double> mz = {chr->rho[3][ir]};
204+
// double amag = sqrt( pow(chr->rho[1][ir],2) + pow(chr->rho[2][ir],2) + pow(chr->rho[3][ir],2) );
205+
// if (n[0] - amag <= 0.0) { //ensure the rhoup and rhodn to libxc are positive
206+
// continue;
207+
// }
208+
// std::vector<double> E_MC;
209+
// std::vector<Matrix2x2> V_MC;
210+
// for(const int &id : func_id){
211+
// std::tie(E_MC, V_MC) = NCLibxc::lda_mc(id, n, mx, my, mz);
212+
// exc = e2*E_MC[0];
213+
// v(0, ir) += std::real(e2*(V_MC[0][0][0]+V_MC[0][1][1])/two);
214+
// v(1, ir) += std::real(e2*(V_MC[0][0][1]+V_MC[0][1][0])/two);
215+
// v(2, ir) += std::real(e2*(V_MC[0][1][0]-V_MC[0][0][1])/twoi);
216+
// v(3, ir) += std::real(e2*(V_MC[0][0][0]-V_MC[0][1][1])/two);
217+
// etxc += exc * n[0];
218+
// vtxc += v(0, ir) * chr->rho[0][ir] + v(1, ir) * chr->rho[1][ir] + v(2, ir) * chr->rho[2][ir] + v(3, ir) * chr->rho[3][ir];
219+
// }
220+
// }
216221
}
217222

218223

@@ -224,7 +229,7 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional::v_xc(
224229
std::vector<double> dum;
225230
if(PARAM.inp.nspin == 4 && PARAM.inp.multicolin == 1) {
226231
if(func_type == 2 || func_type == 3) {
227-
NCLibxc::print_NCLibxc();
232+
//NCLibxc::print_NCLibxc();
228233
}
229234
if(func_type == 4 || func_type == 5) {
230235
std::cerr << "Error: Multi-collinear approach hasn't support hybrid functioanl yet" << std::endl;

0 commit comments

Comments
 (0)