/*
 Copyright (C) 2019 Daniel Mejia-Rodriguez
               2020 Susi Lehtola

 This Source Code Form is subject to the terms of the Mozilla Public
 License, v. 2.0. If a copy of the MPL was not distributed with this
 file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/


#include "util.h"
#include "xc_funcs.h"

#define XC_MGGA_C_R2SCANL        719 /* Deorbitalized r^2SCAN correlation */

/* The deorbitalization is performed symbolically in
   maple/mgga_exc/mgga_c_r2scanl.mpl: r2SCAN correlation's iso-orbital indicator
   is taken from PC07 rather than assembled from a kinetic energy density at run
   time.  r2SCAN correlation's regularization parameter eta is not exposed here,
   so it is baked at its default in the Maple source and only PC07's parameters
   survive. */
typedef struct{
  double pc07_a, pc07_b;
} mgga_c_r2scanl_params;

#define N_PAR 2
static const char *names[N_PAR] = {
  "_a", "_b"  /* parameters of pc07 */
};
static const char *desc[N_PAR] = {
  "pc07 a", "pc07 b"
};
static const double par_r2scanl[N_PAR] = {
  1.784720, 0.258304
};

static void
mgga_c_r2scanl_init(xc_func_type *p)
{
  assert(p != NULL && p->params == NULL);
  p->params = libxc_malloc_flags(sizeof(mgga_c_r2scanl_params), p->info->flags);
}

#include "maple2c/mgga_exc/mgga_c_r2scanl.c"
#include "work_mgga.c"

#ifdef __cplusplus
extern "C"
#endif
const xc_func_info_type xc_func_info_mgga_c_r2scanl = {
  XC_MGGA_C_R2SCANL,
  XC_CORRELATION,
  "Deorbitalized re-regularized SCAN (r2SCAN-L) correlation",
  XC_FAMILY_MGGA,
  {&xc_ref_Mejia2020_121109, &xc_ref_Furness2020_8208, &xc_ref_Furness2020_9248, NULL, NULL},
  XC_FLAGS_3D | XC_FLAGS_NEEDS_LAPLACIAN | XC_FLAGS_I_HAVE_ALL,
  1e-15,
  {N_PAR, names, desc, par_r2scanl, set_ext_params_cpy},
  mgga_c_r2scanl_init, NULL,
  NULL, NULL, &work_mgga
};
