1 /* Ergo, version 3.8, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2019 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
30 /** @file boysfunction.h
31 
32     @brief Code for Boys function evaluation.
33 
34     @author: Elias Rudberg <em>responsible</em>
35 */
36 
37 #ifndef BOYSFUNCTION_HEADER
38 #define BOYSFUNCTION_HEADER
39 
40 #include <vector>
41 #include "realtype.h"
42 #include "polydegree.h"
43 
44 #include "config.h" // Needed to get the PRECISION_QUAD_FLT128 macro
45 
46 /* We need Boys functions up to a degree 4 times the highest degree of basis functions. */
47 #define BOYS_N_MAX (BASIS_FUNC_POLY_MAX_DEGREE*4+1)
48 
49 /* Tune things differently depending on required precision. */
50 #if defined(PRECISION_QUAD_FLT128)
51 #define BOYS_X_MAX 120.0
52 #define BOYS_TAB_DEGREE 12
53 #define BOYS_NO_OF_INTERVALS 1600
54 #elif defined(PRECISION_LONG_DOUBLE)
55 #define BOYS_X_MAX 85.0
56 #define BOYS_TAB_DEGREE 10
57 #define BOYS_NO_OF_INTERVALS 300
58 #else
59 #define BOYS_X_MAX 75.0
60 #define BOYS_TAB_DEGREE 10
61 #define BOYS_NO_OF_INTERVALS 200
62 #endif
63 
64 typedef struct {
65   ergo_real midx;
66   ergo_real A[BOYS_TAB_DEGREE];
67 } BoysFuncIntervalStruct;
68 
69 typedef struct {
70   BoysFuncIntervalStruct list[BOYS_NO_OF_INTERVALS];
71 } BoysFuncIntervalSetStruct;
72 
73 class BoysFunctionManager {
74  private:
75   std::vector<BoysFuncIntervalSetStruct> Boys_list;
76   ergo_real SavedPrefactor_list[BOYS_N_MAX];
77   int Boys_init_flag;
78   ergo_real BoysFunction_pretabulated(int n, ergo_real x) const;
79  public:
80   BoysFunctionManager();
81   void init();
82   ergo_real BoysFunction(int n, ergo_real x) const;
83   ergo_real BoysFunction_expensive(int n, ergo_real x, int noOfIntegrationIntervals, int method = 0) const;
84   // Stuff needed for Chunks&Tasks usage
85   void write_to_buffer ( char * dataBuffer, size_t const bufferSize ) const;
86   size_t get_size() const;
87   void assign_from_buffer ( char const * dataBuffer, size_t const bufferSize);
88 };
89 
90 #endif
91