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 organize_distrs.h
31 
32     @brief Code for organizing a given set of primitive Gaussian
33     distributions (typically coming from basis function products); the
34     distributions are grouped according to their location in space,
35     their exponents, etc.
36 
37     @author: Elias Rudberg <em>responsible</em>
38 */
39 
40 #ifndef ORGANIZE_DISTRS_HEADER
41 #define ORGANIZE_DISTRS_HEADER
42 
43 #include "output.h"
44 #include "multipole.h"
45 #include "simple_sparse_mat.h"
46 
47 #include <vector>
48 
49 
50 typedef struct
51 {
52   int startIndex;
53   int distrCount;
54   int nmax;
55   ergo_real centerCoords[3];
56   ergo_real exponent;
57   ergo_real maxSizeGroup;
58   ergo_real maxExtentGroup;
59   ergo_real maxLimitingFactorGroup;
60   ergo_real maxAbsDmatElementGroup;
61   ergo_real multipoleEuclNormListForK[MAX_MULTIPOLE_DEGREE_BASIC+1];
62 } distr_group_struct;
63 
64 typedef struct
65 {
66   int basisFuncPairIndex;
67   int monomialIndex;
68   ergo_real coeff;
69 } minimal_distr_struct;
70 
71 typedef struct
72 {
73   int nmax;
74   ergo_real exponent;
75   int groupStartIndex;
76   int noOfGroups;
77   ergo_real maxLimitingFactorForCluster;
78   ergo_real multipoleEuclNormListForK[MAX_MULTIPOLE_DEGREE_BASIC+1];
79 } cluster_struct;
80 
81 typedef struct
82 {
83   int index_1;
84   int index_2;
85   int index_1_mod;
86   int index_2_mod;
87   int index_inbox_1;
88   int index_inbox_2;
89   int pairIndex;
90   ergo_real dmatElement;
91 } basis_func_pair_struct;
92 
93 #ifndef BASIS_FUNC_POLY_MAX_DEGREE
94 #error The constant BASIS_FUNC_POLY_MAX_DEGREE must be defined.
95 #endif
96 #if BASIS_FUNC_POLY_MAX_DEGREE<6
97 #define MAX_NO_OF_BASIS_FUNC_PAIRS_PER_BATCH 1000
98 #else
99 #define MAX_NO_OF_BASIS_FUNC_PAIRS_PER_BATCH 10000
100 #endif
101 
102 typedef struct
103 {
104   int clusterStartIndex;
105   int noOfClusters;
106   int noOfBasisFuncPairs;
107   int basisFuncPairListIndex;
108   int basisFuncForBatchsIndex;
109   int basisFuncForBatchCount;
110   int global_debug_id;
111 } batch_struct;
112 
113 struct basis_func_group_info_for_box {
114   int basisFuncGroupIndex;
115   ergo_real max_CS_factor;
116   ergo_real maxMomentVectorNormList[MAX_MULTIPOLE_DEGREE_BASIC+1];
117   int maxMultipoleDegree;
118 };
119 
120 
121 struct distr_org_struct {
122   std::vector<minimal_distr_struct> minimalDistrList;
123   std::vector<distr_group_struct> groupList;
124   std::vector<cluster_struct> clusterList;
125   std::vector<batch_struct> batchList;
126   std::vector<basis_func_pair_struct> basisFuncPairList;
127   std::vector<int> basisFuncListForBatchs;
128   std::vector<int> basisFuncListForBatchs_map;
129   std::vector<int> basisFuncList;
130   std::vector<i_j_val_struct> spMatElementList;
131   std::vector<int> spMatCountList;
132   std::vector<int> spMatIdxList;
133   std::vector<basis_func_group_info_for_box> basisFuncGroupInfoListForK;
134   struct Data {
135     ergo_real maxExtent;
136     ergo_real maxDistanceOutsideBox;
137     int maxNoOfMonomials;
138     Data();
139   };
140   Data data;
141   // Functions needed for CHT usage
142   void writeToBuffer(char* dataBuffer, size_t const bufferSize) const;
143   size_t getSize() const;
144   void assignFromBuffer(char const * dataBuffer, size_t const bufferSize);
145 };
146 
147 
148 int
149 organize_distributions(const IntegralInfo & integralInfo,
150 		       DistributionSpecStructLabeled* distrList_in,
151 		       int distrCount,
152 		       distr_org_struct* result,
153 		       const ergo_real* boxCenterCoords,
154 		       ergo_real boxWidth);
155 
156 #endif
157