笔者使用的4.1版本,默认安装到/opt/etsf/文件夹

采用官网的编译示例,

#include (stdio.h)//注意括号要修改
#include (xc.h)   //注意括号
int main()
{
  xc_func_type func;
  double rho[5] = {0.1, 0.2, 0.3, 0.4, 0.5};
  double sigma[5] = {0.2, 0.3, 0.4, 0.5, 0.6};
  double exc[5];
  int i, vmajor, vminor, vmicro, func_id = 1;
 
  xc_version(&vmajor, &vminor, &vmicro);
  printf("Libxc version: %d.%d.%d\n", vmajor, vminor, vmicro);
 
  if(xc_func_init(&func, func_id, XC_UNPOLARIZED) != 0){
    fprintf(stderr, "Functional '%d' not found\n", func_id);
    return 1;
  }
  switch(func.info->family)
    {
    case XC_FAMILY_LDA:
      xc_lda_exc(&func, 5, rho, exc);
      break;
    case XC_FAMILY_GGA:
    case XC_FAMILY_HYB_GGA:
      xc_gga_exc(&func, 5, rho, sigma, exc);
      break;
    }
  for(i=0; i<5; i+=1){
    printf("%lf %lf\n", rho[i], exc[i]);
  }
  xc_func_end(&func);
}

以及fortran对应的版本

program lxctest
   use xc_f90_types_m
   use xc_f90_lib_m
 
   implicit none
 
   TYPE(xc_f90_pointer_t) :: xc_func
   TYPE(xc_f90_pointer_t) :: xc_info
   real(8) :: rho(5) = (/0.1, 0.2, 0.3, 0.4, 0.5/)
   real(8) :: sigma(5) = (/0.2, 0.3, 0.4, 0.5, 0.6/)
   real(8) :: exc(5)
   integer :: i, vmajor, vminor, vmicro, func_id = 1
 
   call xc_f90_version(vmajor, vminor, vmicro)
   write(*,'("Libxc version: ",I1,".",I1,".",I1)') vmajor, vminor, vmicro
 
   call xc_f90_func_init(xc_func, xc_info, func_id, XC_UNPOLARIZED)
 
   select case (xc_f90_info_family(xc_info))
   case(XC_FAMILY_LDA)
     call xc_f90_lda_exc(xc_func, 5, rho(1), exc(1))
   case(XC_FAMILY_GGA, XC_FAMILY_HYB_GGA)
     call xc_f90_gga_exc(xc_func, 5, rho(1), sigma(1), exc(1))
   end select
 
   do i = 1, 5
     write(*,"(F8.6,1X,F9.6)") rho(i), exc(i)
   end do
 
   call xc_f90_func_end(xc_func)
 
end program lxctest

测试了几轮后,使用如下的编译条件即可正常编译和运行,也记录一下备忘。

g++                libxc_lda.cpp             -I/opt/etsf/include     -L/opt/etsf/lib      -lxc
gfortran      libxc_f90_test.f90    -I/opt/etsf/include     -L/opt/etsf/lib      -lxcf90      -lxc

(J_Sagat)

  • cf_libxc.txt
  • Last modified: 2019/09/24 00:23
  • (external edit)