1 | //
|
---|
2 | // storage.h
|
---|
3 | //
|
---|
4 | // Copyright (C) 1996 Limit Point Systems, Inc.
|
---|
5 | //
|
---|
6 | // Author: Curtis Janssen <cljanss@limitpt.com>
|
---|
7 | // Maintainer: LPS
|
---|
8 | //
|
---|
9 | // This file is part of the SC Toolkit.
|
---|
10 | //
|
---|
11 | // The SC Toolkit is free software; you can redistribute it and/or modify
|
---|
12 | // it under the terms of the GNU Library General Public License as published by
|
---|
13 | // the Free Software Foundation; either version 2, or (at your option)
|
---|
14 | // any later version.
|
---|
15 | //
|
---|
16 | // The SC Toolkit is distributed in the hope that it will be useful,
|
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | // GNU Library General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU Library General Public License
|
---|
22 | // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
|
---|
23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
24 | //
|
---|
25 | // The U.S. Government is granted a limited license as per AL 91-7.
|
---|
26 | //
|
---|
27 |
|
---|
28 | #ifndef _chemistry_qc_intv3_storage_h
|
---|
29 | #define _chemistry_qc_intv3_storage_h
|
---|
30 |
|
---|
31 | #ifdef __GNUC__
|
---|
32 | #pragma interface
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #ifdef __cplusplus
|
---|
36 |
|
---|
37 | #include <stddef.h>
|
---|
38 | #include <util/class/class.h>
|
---|
39 | #include <util/keyval/keyval.h>
|
---|
40 | #include <util/container/eavlmmap.h>
|
---|
41 |
|
---|
42 | namespace sc {
|
---|
43 |
|
---|
44 | // the max shell number is 2^15 (sizeof(int) must be >= 4)
|
---|
45 | #define SH_BITS 15 // the number of bits holding a shell index
|
---|
46 | #define PE_BITS 1 // the number of bits holding a permutation
|
---|
47 |
|
---|
48 | #define SH_MASK ((1<<SH_BITS)-1)
|
---|
49 | #define PE_MASK ((1<<PE_BITS)-1)
|
---|
50 |
|
---|
51 | #define SH0_SHIFT 0
|
---|
52 | #define SH1_SHIFT (SH_BITS + SH0_SHIFT)
|
---|
53 | #define P12_SHIFT (SH_BITS + SH1_SHIFT)
|
---|
54 | #define P34_SHIFT (PE_BITS + P12_SHIFT)
|
---|
55 | #define SH2_SHIFT 0
|
---|
56 | #define SH3_SHIFT (SH_BITS + SH2_SHIFT)
|
---|
57 | #define P13P24_SHIFT (SH_BITS + SH3_SHIFT)
|
---|
58 | class IntegralKey {
|
---|
59 | public:
|
---|
60 | unsigned int sh0_sh1_p12_p34;
|
---|
61 | unsigned int sh2_sh3_p13p24;
|
---|
62 | public:
|
---|
63 | IntegralKey(int,int,int,int,int,int,int);
|
---|
64 | IntegralKey(const IntegralKey&);
|
---|
65 | bool operator == (const IntegralKey &k) const {
|
---|
66 | return (sh0_sh1_p12_p34 == k.sh0_sh1_p12_p34)
|
---|
67 | && (sh2_sh3_p13p24 == k.sh2_sh3_p13p24);
|
---|
68 | }
|
---|
69 | bool operator < (const IntegralKey &k) const {
|
---|
70 | return ((sh0_sh1_p12_p34 < k.sh0_sh1_p12_p34)?
|
---|
71 | true:(sh2_sh3_p13p24 < k.sh2_sh3_p13p24));
|
---|
72 | }
|
---|
73 | int sh0() const { return (sh0_sh1_p12_p34>>SH0_SHIFT) & SH_MASK; }
|
---|
74 | int sh1() const { return (sh0_sh1_p12_p34>>SH1_SHIFT) & SH_MASK; }
|
---|
75 | int p12() const { return (sh0_sh1_p12_p34>>P12_SHIFT) & PE_MASK; }
|
---|
76 | int p34() const { return (sh0_sh1_p12_p34>>P34_SHIFT) & PE_MASK; }
|
---|
77 | int sh2() const { return (sh2_sh3_p13p24>>SH2_SHIFT) & SH_MASK; }
|
---|
78 | int sh3() const { return (sh2_sh3_p13p24>>SH3_SHIFT) & SH_MASK; }
|
---|
79 | int p13p24() const { return (sh2_sh3_p13p24>>P13P24_SHIFT) & PE_MASK; }
|
---|
80 | };
|
---|
81 |
|
---|
82 | inline
|
---|
83 | IntegralKey::IntegralKey(int sh1_, int sh2_, int sh3_, int sh4_,
|
---|
84 | int p12_, int p34_, int p13p24_)
|
---|
85 | {
|
---|
86 | sh0_sh1_p12_p34 = (sh1_<<SH0_SHIFT)
|
---|
87 | |(sh2_<<SH1_SHIFT)
|
---|
88 | |(p12_<<P12_SHIFT)
|
---|
89 | |(p34_<<P34_SHIFT);
|
---|
90 | sh2_sh3_p13p24 = (sh3_<<SH2_SHIFT)
|
---|
91 | |(sh4_<<SH3_SHIFT)
|
---|
92 | |(p13p24_<<P13P24_SHIFT);
|
---|
93 | }
|
---|
94 |
|
---|
95 | inline
|
---|
96 | IntegralKey::IntegralKey(const IntegralKey& ik)
|
---|
97 | {
|
---|
98 | sh0_sh1_p12_p34 = ik.sh0_sh1_p12_p34;
|
---|
99 | sh2_sh3_p13p24 = ik.sh2_sh3_p13p24;
|
---|
100 | }
|
---|
101 |
|
---|
102 | inline int
|
---|
103 | compare(const IntegralKey&k1, const IntegralKey&k2)
|
---|
104 | {
|
---|
105 | if (k1.sh0_sh1_p12_p34 < k2.sh0_sh1_p12_p34) return -1;
|
---|
106 | else if (k1.sh0_sh1_p12_p34 > k2.sh0_sh1_p12_p34) return 1;
|
---|
107 |
|
---|
108 | if (k1.sh2_sh3_p13p24 < k2.sh2_sh3_p13p24) return -1;
|
---|
109 | else if (k1.sh2_sh3_p13p24 > k2.sh2_sh3_p13p24) return 1;
|
---|
110 | else return 0;
|
---|
111 | }
|
---|
112 |
|
---|
113 | class IntegralLink {
|
---|
114 | public:
|
---|
115 | EAVLMMapNode<IntegralKey, IntegralLink> intlist;
|
---|
116 | EAVLMMapNode<int, IntegralLink> costlist;
|
---|
117 | int size;
|
---|
118 | public:
|
---|
119 | IntegralLink(IntegralKey& key, int cost, int size);
|
---|
120 | static int size_to_actualsize(int size);
|
---|
121 | ~IntegralLink();
|
---|
122 | int actualsize() const;
|
---|
123 | int hash() const;
|
---|
124 | static int shells_to_hash(int,int,int,int);
|
---|
125 | int cost() const { return costlist.key; }
|
---|
126 | void print();
|
---|
127 |
|
---|
128 | // the integrals are squirreled away after this
|
---|
129 | double* buffer() { return (double*)&this[1]; }
|
---|
130 | void* operator new(size_t, int);
|
---|
131 | void operator delete(void*, int);
|
---|
132 | void operator delete(void*);
|
---|
133 | };
|
---|
134 |
|
---|
135 | inline int
|
---|
136 | IntegralLink::shells_to_hash(int sh1,int sh2,int sh3,int sh4)
|
---|
137 | {
|
---|
138 | return sh1 ^ (sh4<<4) ^ (sh2<<8) ^ (sh3<<12);
|
---|
139 | }
|
---|
140 |
|
---|
141 | inline int
|
---|
142 | IntegralLink::hash() const
|
---|
143 | {
|
---|
144 | return shells_to_hash(intlist.key.sh0(),
|
---|
145 | intlist.key.sh1(),
|
---|
146 | intlist.key.sh2(),
|
---|
147 | intlist.key.sh3());
|
---|
148 | }
|
---|
149 |
|
---|
150 | inline int
|
---|
151 | IntegralLink::size_to_actualsize(int size)
|
---|
152 | {
|
---|
153 | return size*sizeof(double) + sizeof(IntegralLink) + sizeof(void*)*2;
|
---|
154 | }
|
---|
155 |
|
---|
156 | inline int
|
---|
157 | IntegralLink::actualsize() const
|
---|
158 | {
|
---|
159 | return size_to_actualsize(size);
|
---|
160 | }
|
---|
161 |
|
---|
162 | class IntegralStorer: public DescribedClass {
|
---|
163 | private:
|
---|
164 | int table_size_;
|
---|
165 | EAVLMMap<int,IntegralLink> costlist;
|
---|
166 | EAVLMMap<IntegralKey,IntegralLink>* table_;
|
---|
167 | int maxsize_;
|
---|
168 | int currentsize_;
|
---|
169 | int n_integrals_;
|
---|
170 | int n_shellquart_;
|
---|
171 | public:
|
---|
172 | IntegralStorer();
|
---|
173 | IntegralStorer(const Ref<KeyVal>&);
|
---|
174 | ~IntegralStorer();
|
---|
175 | void init(int nbytes);
|
---|
176 | void done();
|
---|
177 | IntegralLink *find(IntegralKey&);
|
---|
178 | int should_store(int cost, int actualsize);
|
---|
179 | void store(IntegralKey& key, const double *buf,
|
---|
180 | int size, int cost, int actualsize);
|
---|
181 | void print_stats();
|
---|
182 | int table_size() const { return table_size_; }
|
---|
183 | };
|
---|
184 |
|
---|
185 | }
|
---|
186 |
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | #endif
|
---|
190 |
|
---|
191 | // Local Variables:
|
---|
192 | // mode: c++
|
---|
193 | // c-file-style: "CLJ"
|
---|
194 | // End:
|
---|