QMCPACK
PolynomialFunctor3D.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 // Ye Luo, yeluo@anl.gov, Argonne National Laboratory
12 //
13 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
14 //////////////////////////////////////////////////////////////////////////////////////
15 
16 
17 #ifndef QMCPLUSPLUS_POLYNOMIAL3D_FUNCTOR_H
18 #define QMCPLUSPLUS_POLYNOMIAL3D_FUNCTOR_H
19 
20 #include "OptimizableFunctorBase.h"
22 #include "OhmmsData/AttributeSet.h"
23 #include "Numerics/LinearFit.h"
25 #include <cstdio>
26 #include <algorithm>
27 
28 namespace qmcplusplus
29 {
31 {
33  int N_eI, N_ee;
35  // Permutation vector, used when we need to pivot
36  // columns
37  std::vector<int> GammaPerm;
38 
40  std::vector<bool> IndepVar;
41  std::vector<real_type> GammaVec, dval_Vec;
42  std::vector<TinyVector<real_type, 3>> dgrad_Vec;
43  std::vector<Tensor<real_type, 3>> dhess_Vec;
46  std::vector<real_type> Parameters, d_valsFD;
47  std::vector<TinyVector<real_type, 3>> d_gradsFD;
48  std::vector<Tensor<real_type, 3>> d_hessFD;
49  std::vector<std::string> ParameterNames;
50  std::string iSpecies, eSpecies1, eSpecies2;
52  // Order of continuity
53  const int C;
55  bool notOpt;
56 
57  ///constructor
58  PolynomialFunctor3D(const std::string& my_name, real_type ee_cusp = 0.0, real_type eI_cusp = 0.0)
59  : OptimizableFunctorBase(my_name), N_eI(0), N_ee(0), ResetCount(0), C(3), scale(1.0), notOpt(false)
60  {
61  if (std::abs(ee_cusp) > 0.0 || std::abs(eI_cusp) > 0.0)
62  {
63  app_error() << "PolynomialFunctor3D does not support nonzero cusp.\n";
64  abort();
65  }
66  cutoff_radius = 0.0;
67  }
68 
69  OptimizableFunctorBase* makeClone() const override { return new PolynomialFunctor3D(*this); }
70 
71  void resize(int neI, int nee)
72  {
73  N_eI = neI;
74  N_ee = nee;
75  const double L = 0.5 * cutoff_radius;
76  gamma.resize(N_eI + 1, N_eI + 1, N_ee + 1);
77  index.resize(N_eI + 1, N_eI + 1, N_ee + 1);
78  NumGamma = ((N_eI + 1) * (N_eI + 2) / 2 * (N_ee + 1));
79  NumConstraints = (2 * N_eI + 1) + (N_eI + N_ee + 1);
80  int numParams = NumGamma - NumConstraints;
81  Parameters.resize(numParams);
82  d_valsFD.resize(numParams);
83  d_gradsFD.resize(numParams);
84  d_hessFD.resize(numParams);
85  GammaVec.resize(NumGamma);
86  dval_Vec.resize(NumGamma);
87  dgrad_Vec.resize(NumGamma);
88  dhess_Vec.resize(NumGamma);
90  // Assign indices
91  int num = 0;
92  for (int m = 0; m <= N_eI; m++)
93  for (int l = m; l <= N_eI; l++)
94  for (int n = 0; n <= N_ee; n++)
95  index(l, m, n) = index(m, l, n) = num++;
96  assert(num == NumGamma);
97  // std::cerr << "NumGamma = " << NumGamma << std::endl;
98  // Fill up contraint matrix
99  // For 3 constraints and 2 parameters, we would have
100  // |A00 A01 A02 A03 A04| |g0| |0 |
101  // |A11 A11 A12 A13 A14| |g1| |0 |
102  // |A22 A21 A22 A23 A24| |g2| = |0 |
103  // | 0 0 0 1 0 | |g3| |p0|
104  // | 0 0 0 0 1 | |g4| |p1|
105  ConstraintMatrix = 0.0;
106  // std::cerr << "ConstraintMatrix.size = " << ConstraintMatrix.size(0)
107  // << " by " << ConstraintMatrix.size(1) << std::endl;
108  // std::cerr << "index.size() = (" << index.size(0) << ", "
109  // << index.size(1) << ", " << index.size(2) << ").\n";
110  int k;
111  // e-e no-cusp constraint
112  for (k = 0; k <= 2 * N_eI; k++)
113  {
114  for (int m = 0; m <= k; m++)
115  {
116  int l = k - m;
117  if (l <= N_eI && m <= N_eI)
118  {
119  int i = index(l, m, 1);
120  if (l > m)
121  ConstraintMatrix(k, i) = 2.0;
122  else if (l == m)
123  ConstraintMatrix(k, i) = 1.0;
124  }
125  }
126  }
127  // e-I no-cusp constraint
128  for (int kp = 0; kp <= N_eI + N_ee; kp++)
129  {
130  if (kp <= N_ee)
131  {
132  ConstraintMatrix(k + kp, index(0, 0, kp)) = (real_type)C;
133  ConstraintMatrix(k + kp, index(0, 1, kp)) = -L;
134  }
135  for (int l = 1; l <= kp; l++)
136  {
137  int n = kp - l;
138  if (n >= 0 && n <= N_ee && l <= N_eI)
139  {
140  ConstraintMatrix(k + kp, index(l, 0, n)) = (real_type)C;
141  ConstraintMatrix(k + kp, index(l, 1, n)) = -L;
142  }
143  }
144  }
145  // {
146  // fprintf (stderr, "Constraint matrix:\n");
147  // for (int i=0; i<NumConstraints; i++) {
148  // for (int j=0; j<NumGamma; j++)
149  // fprintf (stderr, "%5.2f ", ConstraintMatrix(i,j));
150  // fprintf(stderr, "\n");
151  // }
152  // }
153  // Now, row-reduce constraint matrix
154  GammaPerm.resize(NumGamma);
155  IndepVar.resize(NumGamma, false);
156  // Set identity permutation
157  for (int i = 0; i < NumGamma; i++)
158  GammaPerm[i] = i;
159  int col = -1;
160  for (int row = 0; row < NumConstraints; row++)
161  {
162  int max_loc;
163  real_type max_abs;
164  do
165  {
166  col++;
167  max_loc = row;
168  max_abs = std::abs(ConstraintMatrix(row, col));
169  for (int ri = row + 1; ri < NumConstraints; ri++)
170  {
171  real_type abs_val = std::abs(ConstraintMatrix(ri, col));
172  if (abs_val > max_abs)
173  {
174  max_loc = ri;
175  max_abs = abs_val;
176  }
177  }
178  if (max_abs < 1.0e-6)
179  IndepVar[col] = true;
180  } while (max_abs < 1.0e-6);
181  ConstraintMatrix.swap_rows(row, max_loc);
182  real_type lead_inv = 1.0 / ConstraintMatrix(row, col);
183  for (int c = 0; c < NumGamma; c++)
184  ConstraintMatrix(row, c) *= lead_inv;
185  // Now, eliminate column entries
186  for (int ri = 0; ri < NumConstraints; ri++)
187  {
188  if (ri != row)
189  {
190  real_type val = ConstraintMatrix(ri, col);
191  for (int c = 0; c < NumGamma; c++)
192  ConstraintMatrix(ri, c) -= val * ConstraintMatrix(row, c);
193  }
194  }
195  }
196  for (int c = col + 1; c < NumGamma; c++)
197  IndepVar[c] = true;
198  // fprintf (stderr, "Reduced Constraint matrix:\n");
199  // for (int i=0; i<NumConstraints; i++) {
200  // for (int j=0; j<NumGamma; j++)
201  // fprintf (stderr, "%5.2f ", ConstraintMatrix(i,j));
202  // fprintf(stderr, "\n");
203  // }
204  // fprintf (stderr, "Independent vars = \n");
205  // for (int i=0; i<NumGamma; i++)
206  // if (IndepVar[i])
207  // fprintf (stderr, "%d ", i);
208  // fprintf (stderr, "\n");
209  // fprintf (stderr, "Inverse matrix:\n");
210  // // Now, invert constraint matrix
211  // Invert(ConstraintMatrix.data(), NumGamma, NumGamma);
212  // for (int i=0; i<NumGamma; i++) {
213  // for (int j=0; j<NumGamma; j++)
214  // fprintf (stderr, "%5.2f ", ConstraintMatrix(i,j));
215  // fprintf(stderr, "\n");
216  // }
217  }
218 
219  void reset() override
220  {
221  resize(N_eI, N_ee);
222  reset_gamma();
223  }
224 
225  void reset_gamma()
226  {
227  // fprintf (stderr, "Parameters:\n");
228  // for (int i=0; i<Parameters.size(); i++)
229  // fprintf (stderr, " %16.10e\n", Parameters[i]);
230  const double L = 0.5 * cutoff_radius;
231  std::fill(GammaVec.begin(), GammaVec.end(), 0.0);
232  // First, set all independent variables
233  int var = 0;
234  for (int i = 0; i < NumGamma; i++)
235  if (IndepVar[i])
236  GammaVec[i] = scale * Parameters[var++];
237  assert(var == Parameters.size());
238  // Now, set dependent variables
239  var = 0;
240  // std::cerr << "NumConstraints = " << NumConstraints << std::endl;
241  for (int i = 0; i < NumGamma; i++)
242  if (!IndepVar[i])
243  {
244  // fprintf (stderr, "constraintMatrix(%d,%d) = %1.10f\n",
245  // var, i, ConstraintMatrix(var,i));
246  assert(std::abs(ConstraintMatrix(var, i) - 1.0) < 1.0e-6);
247  for (int j = 0; j < NumGamma; j++)
248  if (i != j)
249  GammaVec[i] -= ConstraintMatrix(var, j) * GammaVec[j];
250  var++;
251  }
252  int num = 0;
253  for (int m = 0; m <= N_eI; m++)
254  for (int l = m; l <= N_eI; l++)
255  for (int n = 0; n <= N_ee; n++)
256  // gamma(m,l,n) = gamma(l,m,n) = unpermuted[num++];
257  gamma(m, l, n) = gamma(l, m, n) = GammaVec[num++];
258  // Now check that constraints have been satisfied
259  // e-e constraints
260  for (int k = 0; k <= 2 * N_eI; k++)
261  {
262  real_type sum = 0.0;
263  for (int m = 0; m <= k; m++)
264  {
265  int l = k - m;
266  if (l <= N_eI && m <= N_eI)
267  {
268  int i = index(l, m, 1);
269  if (l > m)
270  sum += 2.0 * GammaVec[i];
271  else if (l == m)
272  sum += GammaVec[i];
273  }
274  }
275  if (std::abs(sum) > 1.0e-9)
276  std::cerr << "error in k = " << k << " sum = " << sum << std::endl;
277  }
278  for (int k = 0; k <= 2 * N_eI; k++)
279  {
280  real_type sum = 0.0;
281  for (int l = 0; l <= k; l++)
282  {
283  int m = k - l;
284  if (m <= N_eI && l <= N_eI)
285  {
286  // fprintf (stderr, "k = %d gamma(%d, %d, 1) = %1.8f\n", k, l, m,
287  // gamma(l,m,1));
288  sum += gamma(l, m, 1);
289  }
290  }
291  if (std::abs(sum) > 1.0e-6)
292  {
293  app_error() << "e-e constraint not satisfied in PolynomialFunctor3D: k=" << k << " sum=" << sum << std::endl;
294  abort();
295  }
296  }
297  // e-I constraints
298  for (int k = 0; k <= N_eI + N_ee; k++)
299  {
300  real_type sum = 0.0;
301  for (int m = 0; m <= k; m++)
302  {
303  int n = k - m;
304  if (m <= N_eI && n <= N_ee)
305  {
306  sum += (real_type)C * gamma(0, m, n) - L * gamma(1, m, n);
307  // fprintf (stderr,
308  // "k = %d gamma(0,%d,%d) = %1.8f gamma(1,%d,%d)=%1.8f\n",
309  // k, m, n, gamma(0,m,n), m, n, gamma(1,m,n));
310  }
311  }
312  if (std::abs(sum) > 1.0e-6)
313  {
314  app_error() << "e-I constraint not satisfied in PolynomialFunctor3D: k=" << k << " sum=" << sum << std::endl;
315  abort();
316  }
317  }
318  }
319 
320  inline real_type evaluate(real_type r_12, real_type r_1I, real_type r_2I) const
321  {
322  constexpr real_type czero(0);
323  constexpr real_type cone(1);
324  constexpr real_type chalf(0.5);
325 
326  const real_type L = chalf * cutoff_radius;
327  if (r_1I >= L || r_2I >= L)
328  return czero;
329  real_type val = czero;
330  real_type r2l(cone);
331  for (int l = 0; l <= N_eI; l++)
332  {
333  real_type r2m(r2l);
334  for (int m = 0; m <= N_eI; m++)
335  {
336  real_type r2n(r2m);
337  for (int n = 0; n <= N_ee; n++)
338  {
339  val += gamma(l, m, n) * r2n;
340  r2n *= r_12;
341  }
342  r2m *= r_2I;
343  }
344  r2l *= r_1I;
345  }
346  for (int i = 0; i < C; i++)
347  val *= (r_1I - L) * (r_2I - L);
348  return val;
349  }
350 
351  // assume r_1I < L && r_2I < L, compression and screening is handled outside
352  inline real_type evaluateV(int Nptcl,
353  const real_type* restrict r_12_array,
354  const real_type* restrict r_1I_array,
355  const real_type* restrict r_2I_array) const
356  {
357  constexpr real_type czero(0);
358  constexpr real_type cone(1);
359  constexpr real_type chalf(0.5);
360 
361  const real_type L = chalf * cutoff_radius;
362  real_type val_tot = czero;
363 
364 #pragma omp simd aligned(r_12_array, r_1I_array, r_2I_array : QMC_SIMD_ALIGNMENT) reduction(+ : val_tot)
365  for (int ptcl = 0; ptcl < Nptcl; ptcl++)
366  {
367  const real_type r_12 = r_12_array[ptcl];
368  const real_type r_1I = r_1I_array[ptcl];
369  const real_type r_2I = r_2I_array[ptcl];
370  real_type val = czero;
371  real_type r2l(cone);
372  for (int l = 0; l <= N_eI; l++)
373  {
374  real_type r2m(r2l);
375  for (int m = 0; m <= N_eI; m++)
376  {
377  real_type r2n(r2m);
378  for (int n = 0; n <= N_ee; n++)
379  {
380  val += gamma(l, m, n) * r2n;
381  r2n *= r_12;
382  }
383  r2m *= r_2I;
384  }
385  r2l *= r_1I;
386  }
387  const real_type both_minus_L = (r_2I - L) * (r_1I - L);
388  for (int i = 0; i < C; i++)
389  val *= both_minus_L;
390  val_tot += val;
391  }
392 
393  return val_tot;
394  }
395 
397  real_type r_1I,
398  real_type r_2I,
400  Tensor<real_type, 3>& hess) const
401  {
402  constexpr real_type czero(0);
403  constexpr real_type cone(1);
404  constexpr real_type chalf(0.5);
405  constexpr real_type ctwo(2);
406 
407  const real_type L = chalf * cutoff_radius;
408  if (r_1I >= L || r_2I >= L)
409  {
410  grad = czero;
411  hess = czero;
412  return czero;
413  }
414  real_type val = czero;
415  grad = czero;
416  hess = czero;
417  real_type r2l(cone), r2l_1(czero), r2l_2(czero), lf(czero);
418  for (int l = 0; l <= N_eI; l++)
419  {
420  real_type r2m(cone), r2m_1(czero), r2m_2(czero), mf(czero);
421  for (int m = 0; m <= N_eI; m++)
422  {
423  real_type r2n(cone), r2n_1(czero), r2n_2(czero), nf(czero);
424  for (int n = 0; n <= N_ee; n++)
425  {
426  const real_type g = gamma(l, m, n);
427  const real_type g00x = g * r2l * r2m;
428  const real_type g10x = g * r2l_1 * r2m;
429  const real_type g01x = g * r2l * r2m_1;
430  const real_type gxx0 = g * r2n;
431 
432  val += g00x * r2n;
433  grad[0] += g00x * r2n_1;
434  grad[1] += g10x * r2n;
435  grad[2] += g01x * r2n;
436  hess(0, 0) += g00x * r2n_2;
437  hess(0, 1) += g10x * r2n_1;
438  hess(0, 2) += g01x * r2n_1;
439  hess(1, 1) += gxx0 * r2l_2 * r2m;
440  hess(1, 2) += gxx0 * r2l_1 * r2m_1;
441  hess(2, 2) += gxx0 * r2l * r2m_2;
442  nf += cone;
443  r2n_2 = r2n_1 * nf;
444  r2n_1 = r2n * nf;
445  r2n *= r_12;
446  }
447  mf += cone;
448  r2m_2 = r2m_1 * mf;
449  r2m_1 = r2m * mf;
450  r2m *= r_2I;
451  }
452  lf += cone;
453  r2l_2 = r2l_1 * lf;
454  r2l_1 = r2l * lf;
455  r2l *= r_1I;
456  }
457 
458  const real_type r_2I_minus_L = r_2I - L;
459  const real_type r_1I_minus_L = r_1I - L;
460  const real_type both_minus_L = r_2I_minus_L * r_1I_minus_L;
461  for (int i = 0; i < C; i++)
462  {
463  hess(0, 0) = both_minus_L * hess(0, 0);
464  hess(0, 1) = both_minus_L * hess(0, 1) + r_2I_minus_L * grad[0];
465  hess(0, 2) = both_minus_L * hess(0, 2) + r_1I_minus_L * grad[0];
466  hess(1, 1) = both_minus_L * hess(1, 1) + ctwo * r_2I_minus_L * grad[1];
467  hess(1, 2) = both_minus_L * hess(1, 2) + r_1I_minus_L * grad[1] + r_2I_minus_L * grad[2] + val;
468  hess(2, 2) = both_minus_L * hess(2, 2) + ctwo * r_1I_minus_L * grad[2];
469  grad[0] = both_minus_L * grad[0];
470  grad[1] = both_minus_L * grad[1] + r_2I_minus_L * val;
471  grad[2] = both_minus_L * grad[2] + r_1I_minus_L * val;
472  val *= both_minus_L;
473  }
474  hess(1, 0) = hess(0, 1);
475  hess(2, 0) = hess(0, 2);
476  hess(2, 1) = hess(1, 2);
477  return val;
478  }
479 
480  // assume r_1I < L && r_2I < L, compression and screening is handled outside
481  inline void evaluateVGL(int Nptcl,
482  const real_type* restrict r_12_array,
483  const real_type* restrict r_1I_array,
484  const real_type* restrict r_2I_array,
485  real_type* restrict val_array,
486  real_type* restrict grad0_array,
487  real_type* restrict grad1_array,
488  real_type* restrict grad2_array,
489  real_type* restrict hess00_array,
490  real_type* restrict hess11_array,
491  real_type* restrict hess22_array,
492  real_type* restrict hess01_array,
493  real_type* restrict hess02_array) const
494  {
495  constexpr real_type czero(0);
496  constexpr real_type cone(1);
497  constexpr real_type chalf(0.5);
498  constexpr real_type ctwo(2);
499 
500  const real_type L = chalf * cutoff_radius;
501 #pragma omp simd aligned(r_12_array, r_1I_array, r_2I_array, val_array, grad0_array, grad1_array, grad2_array, \
502  hess00_array, hess11_array, hess22_array, hess01_array, hess02_array \
503  : QMC_SIMD_ALIGNMENT)
504  for (int ptcl = 0; ptcl < Nptcl; ptcl++)
505  {
506  const real_type r_12 = r_12_array[ptcl];
507  const real_type r_1I = r_1I_array[ptcl];
508  const real_type r_2I = r_2I_array[ptcl];
509 
510  real_type val(czero);
511  real_type grad0(czero);
512  real_type grad1(czero);
513  real_type grad2(czero);
514  real_type hess00(czero);
515  real_type hess11(czero);
516  real_type hess22(czero);
517  real_type hess01(czero);
518  real_type hess02(czero);
519 
520  real_type r2l(cone), r2l_1(czero), r2l_2(czero), lf(czero);
521  for (int l = 0; l <= N_eI; l++)
522  {
523  real_type r2m(cone), r2m_1(czero), r2m_2(czero), mf(czero);
524  for (int m = 0; m <= N_eI; m++)
525  {
526  real_type r2n(cone), r2n_1(czero), r2n_2(czero), nf(czero);
527  for (int n = 0; n <= N_ee; n++)
528  {
529  const real_type g = gamma(l, m, n);
530  const real_type g00x = g * r2l * r2m;
531  const real_type g10x = g * r2l_1 * r2m;
532  const real_type g01x = g * r2l * r2m_1;
533  const real_type gxx0 = g * r2n;
534 
535  val += g00x * r2n;
536  grad0 += g00x * r2n_1;
537  grad1 += g10x * r2n;
538  grad2 += g01x * r2n;
539  hess00 += g00x * r2n_2;
540  hess01 += g10x * r2n_1;
541  hess02 += g01x * r2n_1;
542  hess11 += gxx0 * r2l_2 * r2m;
543  hess22 += gxx0 * r2l * r2m_2;
544  nf += cone;
545  r2n_2 = r2n_1 * nf;
546  r2n_1 = r2n * nf;
547  r2n *= r_12;
548  }
549  mf += cone;
550  r2m_2 = r2m_1 * mf;
551  r2m_1 = r2m * mf;
552  r2m *= r_2I;
553  }
554  lf += cone;
555  r2l_2 = r2l_1 * lf;
556  r2l_1 = r2l * lf;
557  r2l *= r_1I;
558  }
559 
560  const real_type r_2I_minus_L = r_2I - L;
561  const real_type r_1I_minus_L = r_1I - L;
562  const real_type both_minus_L = r_2I_minus_L * r_1I_minus_L;
563  for (int i = 0; i < C; i++)
564  {
565  hess00 = both_minus_L * hess00;
566  hess01 = both_minus_L * hess01 + r_2I_minus_L * grad0;
567  hess02 = both_minus_L * hess02 + r_1I_minus_L * grad0;
568  hess11 = both_minus_L * hess11 + ctwo * r_2I_minus_L * grad1;
569  hess22 = both_minus_L * hess22 + ctwo * r_1I_minus_L * grad2;
570  grad0 = both_minus_L * grad0;
571  grad1 = both_minus_L * grad1 + r_2I_minus_L * val;
572  grad2 = both_minus_L * grad2 + r_1I_minus_L * val;
573  val *= both_minus_L;
574  }
575 
576  val_array[ptcl] = val;
577  grad0_array[ptcl] = grad0 / r_12;
578  grad1_array[ptcl] = grad1 / r_1I;
579  grad2_array[ptcl] = grad2 / r_2I;
580  hess00_array[ptcl] = hess00;
581  hess11_array[ptcl] = hess11;
582  hess22_array[ptcl] = hess22;
583  hess01_array[ptcl] = hess01 / (r_12 * r_1I);
584  hess02_array[ptcl] = hess02 / (r_12 * r_2I);
585  }
586  }
587 
588 
589  inline real_type evaluate(const real_type r_12,
590  const real_type r_1I,
591  const real_type r_2I,
593  Tensor<real_type, 3>& hess,
595  {
596  grad = 0.0;
597  hess = 0.0;
598  d3 = grad;
599  const real_type L = 0.5 * cutoff_radius;
600  if (r_1I >= L || r_2I >= L)
601  return 0.0;
602  real_type val = 0.0;
603  real_type r2l(1.0), r2l_1(0.0), r2l_2(0.0), r2l_3(0.0), lf(0.0);
604  for (int l = 0; l <= N_eI; l++)
605  {
606  real_type r2m(1.0), r2m_1(0.0), r2m_2(0.0), r2m_3(0.0), mf(0.0);
607  for (int m = 0; m <= N_eI; m++)
608  {
609  real_type r2n(1.0), r2n_1(0.0), r2n_2(0.0), r2n_3(0.0), nf(0.0);
610  for (int n = 0; n <= N_ee; n++)
611  {
612  real_type g = gamma(l, m, n);
613  val += g * r2l * r2m * r2n;
614  grad[0] += nf * g * r2l * r2m * r2n_1;
615  grad[1] += lf * g * r2l_1 * r2m * r2n;
616  grad[2] += mf * g * r2l * r2m_1 * r2n;
617  hess(0, 0) += nf * (nf - 1.0) * g * r2l * r2m * r2n_2;
618  hess(0, 1) += nf * lf * g * r2l_1 * r2m * r2n_1;
619  hess(0, 2) += nf * mf * g * r2l * r2m_1 * r2n_1;
620  hess(1, 1) += lf * (lf - 1.0) * g * r2l_2 * r2m * r2n;
621  hess(1, 2) += lf * mf * g * r2l_1 * r2m_1 * r2n;
622  hess(2, 2) += mf * (mf - 1.0) * g * r2l * r2m_2 * r2n;
623  d3[0](0, 0) += nf * (nf - 1.0) * (nf - 2.0) * g * r2l * r2m * r2n_3;
624  d3[0](0, 1) += nf * (nf - 1.0) * lf * g * r2l_1 * r2m * r2n_2;
625  d3[0](0, 2) += nf * (nf - 1.0) * mf * g * r2l * r2m_1 * r2n_2;
626  d3[0](1, 1) += nf * lf * (lf - 1.0) * g * r2l_2 * r2m * r2n_1;
627  d3[0](1, 2) += nf * lf * mf * g * r2l_1 * r2m_1 * r2n_1;
628  d3[0](2, 2) += nf * mf * (mf - 1.0) * g * r2l * r2m_2 * r2n_1;
629  d3[1](1, 1) += lf * (lf - 1.0) * (lf - 2.0) * g * r2l_3 * r2m * r2n;
630  d3[1](1, 2) += lf * (lf - 1.0) * mf * g * r2l_2 * r2m_1 * r2n;
631  d3[1](2, 2) += lf * mf * (mf - 1.0) * g * r2l_1 * r2m_2 * r2n;
632  d3[2](2, 2) += mf * (mf - 1.0) * (mf - 2.0) * g * r2l * r2m_3 * r2n;
633  r2n_3 = r2n_2;
634  r2n_2 = r2n_1;
635  r2n_1 = r2n;
636  r2n *= r_12;
637  nf += 1.0;
638  }
639  r2m_3 = r2m_2;
640  r2m_2 = r2m_1;
641  r2m_1 = r2m;
642  r2m *= r_2I;
643  mf += 1.0;
644  }
645  r2l_3 = r2l_2;
646  r2l_2 = r2l_1;
647  r2l_1 = r2l;
648  r2l *= r_1I;
649  lf += 1.0;
650  }
651  for (int i = 0; i < C; i++)
652  {
653  d3[0](0, 0) = (r_1I - L) * (r_2I - L) * d3[0](0, 0);
654  d3[0](0, 1) = (r_1I - L) * (r_2I - L) * d3[0](0, 1) + (r_2I - L) * hess(0, 0);
655  d3[0](0, 2) = (r_1I - L) * (r_2I - L) * d3[0](0, 2) + (r_1I - L) * hess(0, 0);
656  d3[0](1, 1) = (r_1I - L) * (r_2I - L) * d3[0](1, 1) + 2.0 * (r_2I - L) * hess(0, 1);
657  d3[0](1, 2) = (r_1I - L) * (r_2I - L) * d3[0](1, 2) + (r_1I - L) * hess(0, 1) + (r_2I - L) * hess(0, 2) + grad[0];
658  d3[0](2, 2) = (r_1I - L) * (r_2I - L) * d3[0](2, 2) + 2.0 * (r_1I - L) * hess(0, 2);
659  d3[1](1, 1) = (r_1I - L) * (r_2I - L) * d3[1](1, 1) + 3.0 * (r_2I - L) * hess(1, 1);
660  d3[1](1, 2) = (r_1I - L) * (r_2I - L) * d3[1](1, 2) + 2.0 * (r_2I - L) * hess(1, 2) + 2.0 * grad[1] +
661  (r_1I - L) * hess(1, 1);
662  d3[1](2, 2) = (r_1I - L) * (r_2I - L) * d3[1](2, 2) + 2.0 * (r_1I - L) * hess(1, 2) + 2.0 * grad[2] +
663  (r_2I - L) * hess(2, 2);
664  d3[2](2, 2) = (r_1I - L) * (r_2I - L) * d3[2](2, 2) + 3.0 * (r_1I - L) * hess(2, 2);
665  hess(0, 0) = (r_1I - L) * (r_2I - L) * hess(0, 0);
666  hess(0, 1) = (r_1I - L) * (r_2I - L) * hess(0, 1) + (r_2I - L) * grad[0];
667  hess(0, 2) = (r_1I - L) * (r_2I - L) * hess(0, 2) + (r_1I - L) * grad[0];
668  hess(1, 1) = (r_1I - L) * (r_2I - L) * hess(1, 1) + 2.0 * (r_2I - L) * grad[1];
669  hess(1, 2) = (r_1I - L) * (r_2I - L) * hess(1, 2) + (r_1I - L) * grad[1] + (r_2I - L) * grad[2] + val;
670  hess(2, 2) = (r_1I - L) * (r_2I - L) * hess(2, 2) + 2.0 * (r_1I - L) * grad[2];
671  grad[0] = (r_1I - L) * (r_2I - L) * grad[0];
672  grad[1] = (r_1I - L) * (r_2I - L) * grad[1] + (r_2I - L) * val;
673  grad[2] = (r_1I - L) * (r_2I - L) * grad[2] + (r_1I - L) * val;
674  val *= (r_1I - L) * (r_2I - L);
675  }
676  hess(1, 0) = hess(0, 1);
677  hess(2, 0) = hess(0, 2);
678  hess(2, 1) = hess(1, 2);
679  d3[0](1, 0) = d3[0](0, 1);
680  d3[0](2, 0) = d3[0](0, 2);
681  d3[0](2, 1) = d3[0](1, 2);
682  d3[1](0, 0) = d3[0](1, 1);
683  d3[1](0, 1) = d3[0](0, 1);
684  d3[1](0, 2) = d3[0](1, 2);
685  d3[1](1, 0) = d3[0](0, 1);
686  d3[1](2, 0) = d3[0](1, 2);
687  d3[1](2, 1) = d3[1](1, 2);
688  d3[2](0, 0) = d3[0](0, 2);
689  d3[2](0, 1) = d3[0](1, 2);
690  d3[2](0, 2) = d3[0](2, 2);
691  d3[2](1, 0) = d3[0](1, 2);
692  d3[2](1, 1) = d3[1](1, 2);
693  d3[2](1, 2) = d3[1](2, 2);
694  d3[2](2, 0) = d3[0](2, 2);
695  d3[2](2, 1) = d3[1](2, 2);
696  return val;
697  }
698 
699 
700  inline real_type evaluate(const real_type r, const real_type rinv) { return 0.0; }
701 
702 
703  inline bool evaluateDerivativesFD(const real_type r_12,
704  const real_type r_1I,
705  const real_type r_2I,
706  std::vector<double>& d_vals,
707  std::vector<TinyVector<real_type, 3>>& d_grads,
708  std::vector<Tensor<real_type, 3>>& d_hess)
709  {
710  const real_type eps = 1.0e-6;
711  assert(d_vals.size() == Parameters.size());
712  assert(d_grads.size() == Parameters.size());
713  assert(d_hess.size() == Parameters.size());
714  for (int ip = 0; ip < Parameters.size(); ip++)
715  {
716  real_type v_plus, v_minus;
717  TinyVector<real_type, 3> g_plus, g_minus;
718  Tensor<real_type, 3> h_plus, h_minus;
719  real_type save_p = Parameters[ip];
720  Parameters[ip] = save_p + eps;
721  reset_gamma();
722  v_plus = evaluate(r_12, r_1I, r_2I, g_plus, h_plus);
723  Parameters[ip] = save_p - eps;
724  reset_gamma();
725  v_minus = evaluate(r_12, r_1I, r_2I, g_minus, h_minus);
726  Parameters[ip] = save_p;
727  reset_gamma();
728  real_type dp_inv = 0.5 / eps;
729  d_vals[ip] = dp_inv * (v_plus - v_minus);
730  d_grads[ip] = dp_inv * (g_plus - g_minus);
731  d_hess[ip] = dp_inv * (h_plus - h_minus);
732  }
733  return true;
734  }
735 
736  ///calculate derivatives with respect to polynomial parameters
737  inline bool evaluateDerivatives(const real_type r_12,
738  const real_type r_1I,
739  const real_type r_2I,
740  std::vector<real_type>& d_vals)
741  {
742  const real_type L = 0.5 * cutoff_radius;
743  if (r_1I >= L || r_2I >= L)
744  return false;
745 
746  constexpr real_type czero(0);
747  constexpr real_type cone(1);
748 
749  real_type dval_dgamma;
750 
751  for (int i = 0; i < dval_Vec.size(); i++)
752  dval_Vec[i] = czero;
753 
754  const real_type r_2I_minus_L = r_2I - L;
755  const real_type r_1I_minus_L = r_1I - L;
756  const real_type both_minus_L = r_2I_minus_L * r_1I_minus_L;
757 
758  real_type r2l(cone);
759  for (int l = 0; l <= N_eI; l++)
760  {
761  real_type r2m(cone);
762  for (int m = 0; m <= N_eI; m++)
763  {
764  int num;
765  if (m > l)
766  num = ((2 * N_eI - l + 3) * l / 2 + m - l) * (N_ee + 1);
767  else
768  num = ((2 * N_eI - m + 3) * m / 2 + l - m) * (N_ee + 1);
769  real_type r2n(cone);
770  for (int n = 0; n <= N_ee; n++, num++)
771  {
772  dval_dgamma = r2l * r2m * r2n;
773  for (int i = 0; i < C; i++)
774  dval_dgamma *= both_minus_L;
775 
776  // Now, pack into vectors
777  dval_Vec[num] += scale * dval_dgamma;
778  r2n *= r_12;
779  }
780  r2m *= r_2I;
781  }
782  r2l *= r_1I;
783  }
784  // for (int i=0; i<dval_Vec.size(); i++)
785  // fprintf (stderr, "dval_Vec[%d] = %12.6e\n", i, dval_Vec[i]);
786  ///////////////////////////////////////////
787  // Now, compensate for constraint matrix //
788  ///////////////////////////////////////////
789  std::fill(d_vals.begin(), d_vals.end(), 0.0);
790  int var = 0;
791  for (int i = 0; i < NumGamma; i++)
792  if (IndepVar[i])
793  {
794  d_vals[var] = dval_Vec[i];
795  var++;
796  }
797  int constraint = 0;
798  for (int i = 0; i < NumGamma; i++)
799  {
800  if (!IndepVar[i])
801  {
802  int indep_var = 0;
803  for (int j = 0; j < NumGamma; j++)
804  if (IndepVar[j])
805  {
806  d_vals[indep_var] -= ConstraintMatrix(constraint, j) * dval_Vec[i];
807  indep_var++;
808  }
809  else if (i != j)
810  assert(std::abs(ConstraintMatrix(constraint, j)) < 1.0e-10);
811  constraint++;
812  }
813  }
814  return true;
815  }
816 
817  inline bool evaluateDerivatives(const real_type r_12,
818  const real_type r_1I,
819  const real_type r_2I,
820  std::vector<real_type>& d_vals,
821  std::vector<TinyVector<real_type, 3>>& d_grads,
822  std::vector<Tensor<real_type, 3>>& d_hess)
823  {
824  const real_type L = 0.5 * cutoff_radius;
825  if (r_1I >= L || r_2I >= L)
826  return false;
827 
828  constexpr real_type czero(0);
829  constexpr real_type cone(1);
830  constexpr real_type ctwo(2);
831 
832  real_type dval_dgamma;
833  TinyVector<real_type, 3> dgrad_dgamma;
834  Tensor<real_type, 3> dhess_dgamma;
835 
836  for (int i = 0; i < dval_Vec.size(); i++)
837  {
838  dval_Vec[i] = czero;
839  dgrad_Vec[i] = czero;
840  dhess_Vec[i] = czero;
841  }
842 
843  const real_type r_2I_minus_L = r_2I - L;
844  const real_type r_1I_minus_L = r_1I - L;
845  const real_type both_minus_L = r_2I_minus_L * r_1I_minus_L;
846 
847  real_type r2l(cone), r2l_1(czero), r2l_2(czero), lf(czero);
848  for (int l = 0; l <= N_eI; l++)
849  {
850  real_type r2m(cone), r2m_1(czero), r2m_2(czero), mf(czero);
851  for (int m = 0; m <= N_eI; m++)
852  {
853  int num;
854  if (m > l)
855  num = ((2 * N_eI - l + 3) * l / 2 + m - l) * (N_ee + 1);
856  else
857  num = ((2 * N_eI - m + 3) * m / 2 + l - m) * (N_ee + 1);
858  real_type r2n(cone), r2n_1(czero), r2n_2(czero), nf(czero);
859  for (int n = 0; n <= N_ee; n++, num++)
860  {
861  dval_dgamma = r2l * r2m * r2n;
862  dgrad_dgamma[0] = r2l * r2m * r2n_1;
863  dgrad_dgamma[1] = r2l_1 * r2m * r2n;
864  dgrad_dgamma[2] = r2l * r2m_1 * r2n;
865  dhess_dgamma(0, 0) = r2l * r2m * r2n_2;
866  dhess_dgamma(0, 1) = r2l_1 * r2m * r2n_1;
867  dhess_dgamma(0, 2) = r2l * r2m_1 * r2n_1;
868  dhess_dgamma(1, 1) = r2l_2 * r2m * r2n;
869  dhess_dgamma(1, 2) = r2l_1 * r2m_1 * r2n;
870  dhess_dgamma(2, 2) = r2l * r2m_2 * r2n;
871 
872  for (int i = 0; i < C; i++)
873  {
874  dhess_dgamma(0, 0) = both_minus_L * dhess_dgamma(0, 0);
875  dhess_dgamma(0, 1) = both_minus_L * dhess_dgamma(0, 1) + r_2I_minus_L * dgrad_dgamma[0];
876  dhess_dgamma(0, 2) = both_minus_L * dhess_dgamma(0, 2) + r_1I_minus_L * dgrad_dgamma[0];
877  dhess_dgamma(1, 1) = both_minus_L * dhess_dgamma(1, 1) + ctwo * r_2I_minus_L * dgrad_dgamma[1];
878  dhess_dgamma(1, 2) = both_minus_L * dhess_dgamma(1, 2) + r_1I_minus_L * dgrad_dgamma[1] +
879  r_2I_minus_L * dgrad_dgamma[2] + dval_dgamma;
880  dhess_dgamma(2, 2) = both_minus_L * dhess_dgamma(2, 2) + ctwo * r_1I_minus_L * dgrad_dgamma[2];
881  dgrad_dgamma[0] = both_minus_L * dgrad_dgamma[0];
882  dgrad_dgamma[1] = both_minus_L * dgrad_dgamma[1] + r_2I_minus_L * dval_dgamma;
883  dgrad_dgamma[2] = both_minus_L * dgrad_dgamma[2] + r_1I_minus_L * dval_dgamma;
884  dval_dgamma *= both_minus_L;
885  }
886 
887  // Now, pack into vectors
888  dval_Vec[num] += scale * dval_dgamma;
889  for (int i = 0; i < 3; i++)
890  {
891  dgrad_Vec[num][i] += scale * dgrad_dgamma[i];
892  dhess_Vec[num](i, i) += scale * dhess_dgamma(i, i);
893  for (int j = i + 1; j < 3; j++)
894  {
895  dhess_Vec[num](i, j) += scale * dhess_dgamma(i, j);
896  dhess_Vec[num](j, i) = dhess_Vec[num](i, j);
897  }
898  }
899 
900  nf += cone;
901  r2n_2 = r2n_1 * nf;
902  r2n_1 = r2n * nf;
903  r2n *= r_12;
904  }
905  mf += cone;
906  r2m_2 = r2m_1 * mf;
907  r2m_1 = r2m * mf;
908  r2m *= r_2I;
909  }
910  lf += cone;
911  r2l_2 = r2l_1 * lf;
912  r2l_1 = r2l * lf;
913  r2l *= r_1I;
914  }
915  // for (int i=0; i<dval_Vec.size(); i++)
916  // fprintf (stderr, "dval_Vec[%d] = %12.6e\n", i, dval_Vec[i]);
917  ///////////////////////////////////////////
918  // Now, compensate for constraint matrix //
919  ///////////////////////////////////////////
920  std::fill(d_vals.begin(), d_vals.end(), 0.0);
921  int var = 0;
922  for (int i = 0; i < NumGamma; i++)
923  if (IndepVar[i])
924  {
925  d_vals[var] = dval_Vec[i];
926  d_grads[var] = dgrad_Vec[i];
927  d_hess[var] = dhess_Vec[i];
928  var++;
929  }
930  int constraint = 0;
931  for (int i = 0; i < NumGamma; i++)
932  {
933  if (!IndepVar[i])
934  {
935  int indep_var = 0;
936  for (int j = 0; j < NumGamma; j++)
937  if (IndepVar[j])
938  {
939  d_vals[indep_var] -= ConstraintMatrix(constraint, j) * dval_Vec[i];
940  d_grads[indep_var] -= ConstraintMatrix(constraint, j) * dgrad_Vec[i];
941  d_hess[indep_var] -= ConstraintMatrix(constraint, j) * dhess_Vec[i];
942  indep_var++;
943  }
944  else if (i != j)
945  assert(std::abs(ConstraintMatrix(constraint, j)) < 1.0e-10);
946  constraint++;
947  }
948  }
949  return true;
950 #ifdef DEBUG_DERIVS
951  evaluateDerivativesFD(r_12, r_1I, r_2I, d_valsFD, d_gradsFD, d_hessFD);
952  fprintf(stderr, "Param Analytic Finite diffference\n");
953  for (int ip = 0; ip < Parameters.size(); ip++)
954  fprintf(stderr, " %3d %12.6e %12.6e\n", ip, d_vals[ip], d_valsFD[ip]);
955  fprintf(stderr, "Param Analytic Finite diffference\n");
956  for (int ip = 0; ip < Parameters.size(); ip++)
957  fprintf(stderr, " %3d %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e\n", ip, d_grads[ip][0], d_gradsFD[ip][0],
958  d_grads[ip][1], d_gradsFD[ip][1], d_grads[ip][2], d_gradsFD[ip][2]);
959  fprintf(stderr, "Param Analytic Finite diffference\n");
960  for (int ip = 0; ip < Parameters.size(); ip++)
961  for (int dim = 0; dim < 3; dim++)
962  fprintf(stderr, " %3d %12.6e %12.6e %12.6e %12.6e %12.6e %12.6e\n", ip, d_hess[ip](0, dim),
963  d_hessFD[ip](0, dim), d_hess[ip](1, dim), d_hessFD[ip](1, dim), d_hess[ip](2, dim),
964  d_hessFD[ip](2, dim));
965 #endif
966  }
967 
968  inline real_type f(real_type r) override { return 0.0; }
969  inline real_type df(real_type r) override { return 0.0; }
970 
971  bool put(xmlNodePtr cur) override
972  {
973  ReportEngine PRE("PolynomialFunctor3D", "put(xmlNodePtr)");
974  // //CuspValue = -1.0e10;
975  // NumParams_eI = NumParams_ee = 0;
976  cutoff_radius = 0.0;
977  OhmmsAttributeSet rAttrib;
978  rAttrib.add(N_ee, "esize");
979  rAttrib.add(N_eI, "isize");
980  rAttrib.add(cutoff_radius, "rcut");
981  rAttrib.put(cur);
982  if (N_eI == 0)
983  PRE.error("You must specify a positive number for \"isize\"", true);
984  if (N_ee == 0)
985  PRE.error("You must specify a positive number for \"esize\"", true);
986  app_summary() << " Ion: " << iSpecies << " electron-electron: " << eSpecies1 << " - " << eSpecies2
987  << std::endl;
988  app_summary() << " Number of parameters for e-e: " << N_ee << ", for e-I: " << N_eI << std::endl;
989  app_summary() << " Cutoff radius: " << cutoff_radius << std::endl;
990  app_summary() << std::endl;
991  resize(N_eI, N_ee);
992  // Now read coefficents
993  xmlNodePtr xmlCoefs = cur->xmlChildrenNode;
994  while (xmlCoefs != NULL)
995  {
996  std::string cname((const char*)xmlCoefs->name);
997  if (cname == "coefficients")
998  {
999  std::string type("0"), id("0"), opt("yes");
1000  OhmmsAttributeSet cAttrib;
1001  cAttrib.add(id, "id");
1002  cAttrib.add(type, "type");
1003  cAttrib.add(opt, "optimize");
1004  cAttrib.put(xmlCoefs);
1005  notOpt = (opt == "no");
1006  if (type != "Array")
1007  {
1008  PRE.error("Unknown correlation type " + type + " in PolynomialFunctor3D." + "Resetting to \"Array\"");
1009  xmlNewProp(xmlCoefs, (const xmlChar*)"type", (const xmlChar*)"Array");
1010  }
1011  std::vector<real_type> params;
1012  putContent(params, xmlCoefs);
1013  if (params.size() == Parameters.size())
1014  Parameters = params;
1015  else
1016  {
1017  app_log() << "Expected " << Parameters.size() << " parameters,"
1018  << " but found " << params.size() << " in PolynomialFunctor3D.\n";
1019  if (params.size() != 0)
1020  abort(); //you think you know what they should be but don't.
1021  }
1022  // Setup parameter names
1023  for (int i = 0; i < Parameters.size(); i++)
1024  {
1025  std::stringstream sstr;
1026  sstr << id << "_" << i;
1027  ;
1028  if (!notOpt)
1029  myVars.insert(sstr.str(), Parameters[i], optimize::LOGLINEAR_P, true);
1030  }
1031  // for (int i=0; i< N_ee; i++)
1032  // for (int j=0; j < N_eI; j++)
1033  // for (int k=0; k<=j; k++) {
1034  // std::stringstream sstr;
1035  // sstr << id << "_" << i << "_" << j << "_" << k;
1036  // myVars.insert(sstr.str(),Parameters[index],true);
1037  // ParamArray(i,j,k) = ParamArray(i,k,j) = Parameters[index];
1038  // index++;
1039  // }
1040  if (!notOpt)
1041  {
1042  int left_pad_spaces = 6;
1043  myVars.print(app_log(), left_pad_spaces, true);
1044  app_log() << std::endl;
1045  }
1046  }
1047  xmlCoefs = xmlCoefs->next;
1048  }
1049  reset_gamma();
1050  return true;
1051  }
1052 
1053  void resetParametersExclusive(const opt_variables_type& active) override
1054  {
1055  if (notOpt)
1056  return;
1057 
1058  for (int i = 0; i < Parameters.size(); ++i)
1059  {
1060  int loc = myVars.where(i);
1061  if (loc >= 0)
1062  {
1063  Parameters[i] = std::real(myVars[i] = active[loc]);
1064  }
1065  }
1066 
1067  if (ResetCount++ == 100)
1068  ResetCount = 0;
1069 
1070  reset_gamma();
1071  }
1072 
1074  {
1075  if (notOpt)
1076  return;
1077 
1079  active.insertFrom(myVars);
1080  }
1081 
1082  void checkOutVariables(const opt_variables_type& active) override
1083  {
1084  if (notOpt)
1085  return;
1086  myVars.getIndex(active);
1087  }
1088 
1089  void print(std::ostream& os)
1090  {
1091  /* no longer correct. Ye Luo
1092  int n=100;
1093  real_type d=cutoff_radius/100.,r=0;
1094  real_type u,du,d2du;
1095  for(int i=0; i<n; ++i)
1096  {
1097  u=evaluate(r,du,d2du);
1098  os << std::setw(22) << r << std::setw(22) << u << std::setw(22) << du
1099  << std::setw(22) << d2du << std::endl;
1100  r+=d;
1101  }
1102  */
1103  }
1104 
1105  inline int getNumParameters() { return Parameters.size(); }
1106 };
1107 } // namespace qmcplusplus
1108 #endif
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
std::vector< real_type > dval_Vec
QMCTraits::RealType real
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void setIndexDefault()
set default Indices, namely all the variables are active
void reset() override
reset function
MakeReturn< UnaryNode< FnFabs, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t abs(const Vector< T1, C1 > &l)
real_type evaluateV(int Nptcl, const real_type *restrict r_12_array, const real_type *restrict r_1I_array, const real_type *restrict r_2I_array) const
std::ostream & app_log()
Definition: OutputManager.h:65
std::ostream & app_summary()
Definition: OutputManager.h:63
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
constexpr std::complex< float > czero
Definition: BLAS.hpp:51
constexpr std::complex< float > cone
Definition: BLAS.hpp:50
std::ostream & app_error()
Definition: OutputManager.h:67
void swap_rows(int r1, int r2)
Definition: OhmmsMatrix.h:249
std::vector< std::string > ParameterNames
void resize(size_type n, size_type m)
Resize the container.
Definition: OhmmsMatrix.h:99
Define a base class for one-dimensional functions with optimizable variables.
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Definition: OhmmsArray.h:65
real_type evaluate(const real_type r, const real_type rinv)
bool evaluateDerivativesFD(const real_type r_12, const real_type r_1I, const real_type r_2I, std::vector< double > &d_vals, std::vector< TinyVector< real_type, 3 >> &d_grads, std::vector< Tensor< real_type, 3 >> &d_hess)
std::vector< real_type > Parameters
void checkOutVariables(const opt_variables_type &active) override
check out variational optimizable variables
real_type evaluate(real_type r_12, real_type r_1I, real_type r_2I) const
void resetParametersExclusive(const opt_variables_type &active) override
reset the parameters during optimizations.
real_type evaluate(real_type r_12, real_type r_1I, real_type r_2I, TinyVector< real_type, 3 > &grad, Tensor< real_type, 3 > &hess) const
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32
bool evaluateDerivatives(const real_type r_12, const real_type r_1I, const real_type r_2I, std::vector< real_type > &d_vals)
calculate derivatives with respect to polynomial parameters
void insert(const std::string &vname, real_type v, bool enable=true, int type=OTHER_P)
Definition: VariableSet.h:133
Final class and should not be derived.
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
declaration of ProgressReportEngine
bool put(xmlNodePtr cur) override
process xmlnode and registers variables to optimize
real_type df(real_type r) override
class to handle a set of variables that can be modified during optimizations
Definition: VariableSet.h:49
int where(int i) const
return the locator of the i-th Index
Definition: VariableSet.h:90
std::vector< real_type > GammaVec
OHMMS_PRECISION real_type
bool evaluateDerivatives(const real_type r_12, const real_type r_1I, const real_type r_2I, std::vector< real_type > &d_vals, std::vector< TinyVector< real_type, 3 >> &d_grads, std::vector< Tensor< real_type, 3 >> &d_hess)
Base class for any functor with optimizable parameters.
bool putContent(T &a, xmlNodePtr cur)
replaces a&#39;s value with the first "element" in the "string" returned by XMLNodeString{cur}.
Definition: libxmldefs.h:88
Define determinant operators.
void error(const std::string &msg, bool fatal=false)
std::vector< TinyVector< real_type, 3 > > d_gradsFD
void insertFrom(const VariableSet &input)
insert a VariableSet to the list
Definition: VariableSet.cpp:37
std::vector< TinyVector< real_type, 3 > > dgrad_Vec
void checkInVariablesExclusive(opt_variables_type &active) override
check in variational parameters to the global list of parameters used by the optimizer.
PolynomialFunctor3D(const std::string &my_name, real_type ee_cusp=0.0, real_type eI_cusp=0.0)
constructor
OptimizableFunctorBase * makeClone() const override
create a clone of this object
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
void evaluateVGL(int Nptcl, const real_type *restrict r_12_array, const real_type *restrict r_1I_array, const real_type *restrict r_2I_array, real_type *restrict val_array, real_type *restrict grad0_array, real_type *restrict grad1_array, real_type *restrict grad2_array, real_type *restrict hess00_array, real_type *restrict hess11_array, real_type *restrict hess22_array, real_type *restrict hess01_array, real_type *restrict hess02_array) const
void print(std::ostream &os, int leftPadSpaces=0, bool printHeader=false) const
optimize::VariableSet::real_type real_type
typedef for real values
int getIndex(const std::string &vname) const
return the Index vaule for the named parameter
std::vector< Tensor< real_type, 3 > > d_hessFD
real_type evaluate(const real_type r_12, const real_type r_1I, const real_type r_2I, TinyVector< real_type, 3 > &grad, Tensor< real_type, 3 > &hess, TinyVector< Tensor< real_type, 3 >, 3 > &d3)
real_type f(real_type r) override
std::vector< real_type > d_valsFD
std::vector< Tensor< real_type, 3 > > dhess_Vec
opt_variables_type myVars
set of variables to be optimized