MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
storage.h
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 __cplusplus
32
33#include <stddef.h>
34#include <util/class/class.h>
35#include <util/keyval/keyval.h>
36#include <util/container/eavlmmap.h>
37
38namespace sc {
39
40// the max shell number is 2^15 (sizeof(int) must be >= 4)
41#define SH_BITS 15 // the number of bits holding a shell index
42#define PE_BITS 1 // the number of bits holding a permutation
43
44#define SH_MASK ((1<<SH_BITS)-1)
45#define PE_MASK ((1<<PE_BITS)-1)
46
47#define SH0_SHIFT 0
48#define SH1_SHIFT (SH_BITS + SH0_SHIFT)
49#define P12_SHIFT (SH_BITS + SH1_SHIFT)
50#define P34_SHIFT (PE_BITS + P12_SHIFT)
51#define SH2_SHIFT 0
52#define SH3_SHIFT (SH_BITS + SH2_SHIFT)
53#define P13P24_SHIFT (SH_BITS + SH3_SHIFT)
54class IntegralKey {
55 public:
56 unsigned int sh0_sh1_p12_p34;
57 unsigned int sh2_sh3_p13p24;
58 public:
59 IntegralKey(int,int,int,int,int,int,int);
60 IntegralKey(const IntegralKey&);
61 bool operator == (const IntegralKey &k) const {
62 return (sh0_sh1_p12_p34 == k.sh0_sh1_p12_p34)
63 && (sh2_sh3_p13p24 == k.sh2_sh3_p13p24);
64 }
65 bool operator < (const IntegralKey &k) const {
66 if (sh0_sh1_p12_p34 < k.sh0_sh1_p12_p34) return true;
67 else if (sh0_sh1_p12_p34 > k.sh0_sh1_p12_p34) return false;
68 return sh2_sh3_p13p24 < k.sh2_sh3_p13p24;
69 }
70 int sh0() const { return (sh0_sh1_p12_p34>>SH0_SHIFT) & SH_MASK; }
71 int sh1() const { return (sh0_sh1_p12_p34>>SH1_SHIFT) & SH_MASK; }
72 int p12() const { return (sh0_sh1_p12_p34>>P12_SHIFT) & PE_MASK; }
73 int p34() const { return (sh0_sh1_p12_p34>>P34_SHIFT) & PE_MASK; }
74 int sh2() const { return (sh2_sh3_p13p24>>SH2_SHIFT) & SH_MASK; }
75 int sh3() const { return (sh2_sh3_p13p24>>SH3_SHIFT) & SH_MASK; }
76 int p13p24() const { return (sh2_sh3_p13p24>>P13P24_SHIFT) & PE_MASK; }
77};
78
79inline std::ostream&
80operator << (std::ostream &o, const IntegralKey &k)
81{
82 o << '[' << k.sh0()
83 << ' ' << k.sh1()
84 << ' ' << k.sh2()
85 << ' ' << k.sh3()
86 << ' ' << k.p12() << k.p34() << k.p13p24()
87 << " (" << k.sh0_sh1_p12_p34 << ' ' << k.sh2_sh3_p13p24 << ')'
88 << ']';
89 return o;
90}
91
92inline
93IntegralKey::IntegralKey(int sh1_, int sh2_, int sh3_, int sh4_,
94 int p12_, int p34_, int p13p24_)
95{
96 sh0_sh1_p12_p34 = (sh1_<<SH0_SHIFT)
97 |(sh2_<<SH1_SHIFT)
98 |(p12_<<P12_SHIFT)
99 |(p34_<<P34_SHIFT);
100 sh2_sh3_p13p24 = (sh3_<<SH2_SHIFT)
101 |(sh4_<<SH3_SHIFT)
102 |(p13p24_<<P13P24_SHIFT);
103}
104
105inline
106IntegralKey::IntegralKey(const IntegralKey& ik)
107{
108 sh0_sh1_p12_p34 = ik.sh0_sh1_p12_p34;
109 sh2_sh3_p13p24 = ik.sh2_sh3_p13p24;
110}
111
112inline int
113compare(const IntegralKey&k1, const IntegralKey&k2)
114{
115 if (k1.sh0_sh1_p12_p34 < k2.sh0_sh1_p12_p34) return -1;
116 else if (k1.sh0_sh1_p12_p34 > k2.sh0_sh1_p12_p34) return 1;
117
118 if (k1.sh2_sh3_p13p24 < k2.sh2_sh3_p13p24) return -1;
119 else if (k1.sh2_sh3_p13p24 > k2.sh2_sh3_p13p24) return 1;
120 else return 0;
121}
122
123class IntegralLink {
124 public:
125 EAVLMMapNode<IntegralKey, IntegralLink> intlist;
126 EAVLMMapNode<int, IntegralLink> costlist;
127 int size;
128 public:
129 IntegralLink(IntegralKey& key, int cost, int size);
130 static int size_to_actualsize(int size);
131 ~IntegralLink();
132 int actualsize() const;
133 int hash() const;
134 static int shells_to_hash(int,int,int,int);
135 int cost() const { return costlist.key; }
136 void print();
137
138 // the integrals are squirreled away after this
139 double* buffer() { return (double*)&this[1]; }
140 void* operator new(size_t, int);
141 void operator delete(void*, int);
142 void operator delete(void*);
143};
144
145inline int
146IntegralLink::shells_to_hash(int sh1,int sh2,int sh3,int sh4)
147{
148 return sh1 ^ (sh4<<4) ^ (sh2<<8) ^ (sh3<<12);
149}
150
151inline int
152IntegralLink::hash() const
153{
154 return shells_to_hash(intlist.key.sh0(),
155 intlist.key.sh1(),
156 intlist.key.sh2(),
157 intlist.key.sh3());
158}
159
160inline int
161IntegralLink::size_to_actualsize(int size)
162{
163 return size*sizeof(double) + sizeof(IntegralLink) + sizeof(void*)*2;
164}
165
166inline int
167IntegralLink::actualsize() const
168{
169 return size_to_actualsize(size);
170}
171
172class IntegralStorer: public DescribedClass {
173 private:
174 int table_size_;
175 EAVLMMap<int,IntegralLink> costlist;
176 EAVLMMap<IntegralKey,IntegralLink>* table_;
177 int maxsize_;
178 int currentsize_;
179 int n_integrals_;
180 int n_shellquart_;
181 public:
182 IntegralStorer();
183 IntegralStorer(const Ref<KeyVal>&);
184 ~IntegralStorer();
185 void init(int nbytes);
186 void done();
187 IntegralLink *find(IntegralKey&);
188 int should_store(int cost, int actualsize);
189 void store(IntegralKey& key, const double *buf,
190 int size, int cost, int actualsize);
191 void print_stats();
192 int table_size() const { return table_size_; }
193 EAVLMMap<IntegralKey,IntegralLink>&table_entry(int i){return table_[i];}
194};
195
196}
197
198#endif
199
200#endif
201
202// Local Variables:
203// mode: c++
204// c-file-style: "CLJ"
205// End:
std::vector< unsigned int > operator<<(const GaussianBasisSet &B, const GaussianBasisSet &A)
computes a map from basis functions in A to the equivalent basis functions in B.
Contains all MPQC code up to version 3.
Definition mpqcin.h:14

Generated at Wed Sep 25 2024 02:45:29 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.