MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
tbint_runtime.h
1//
2// tbint_runtime.h
3//
4// Copyright (C) 2009 Edward Valeev
5//
6// Author: Edward Valeev <evaleev@vt.edu>
7// Maintainer: EV
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 _mpqc_src_lib_chemistry_qc_lcao_tbint_runtime_h
29#define _mpqc_src_lib_chemistry_qc_lcao_tbint_runtime_h
30
31#include <string>
32#include <util/state/state.h>
33#include <chemistry/qc/basis/intdescr.h>
34#include <math/distarray4/distarray4.h>
35#include <chemistry/qc/wfn/spin.h>
36#include <chemistry/qc/lcao/transform_factory.h>
37
38namespace sc {
39
41 class ParamsRegistry : public RefCount {
42
43 public:
46
48 void clear();
50 bool key_exists(const std::string& key) const;
53 std::string key(const Ref<IntParams>& params) const;
56 Ref<IntParams> value(const std::string& key) const;
58 void add(const std::string& key, const Ref<IntParams>& params) const;
60 std::string add(const Ref<IntParams>& params) const;
61
62 private:
64
65 static Ref<ParamsRegistry> instance_;
66
67 // Maps key to IntParams. IntParams objects are not unique, hence should compare them instead of pointers
70
71 Ref<RegistryType> params_;
72 };
73
78 public:
80 ParsedTwoBodyOperSetKey(const std::string& key);
81
82 const std::string& key() const { return key_; }
83 const std::string& oper() const { return oper_; }
84 const std::string& params() const { return params_; }
85
87 static std::string key(const std::string& oper,
88 const std::string& params);
90 template <int NumCenters>
91 static std::string key(const Ref<typename NCentersToIntDescr<NumCenters,2>::value>& descr)
92 {
93 return TwoBodyOperSetDescr::instance(descr->operset())->key() + ParamsRegistry::instance()->key(descr->params());
94 }
95
97 template<int NumCenters>
99 const std::string& operset_key, const Ref<IntParams>& p,
100 const Ref<Integral>& integral) {
101 if (operset_key
102 == TwoBodyOperSetDescr::instance(TwoBodyOperSet::ERI)->key()) {
104 integral, p);
105 }
106 if (operset_key
107 == TwoBodyOperSetDescr::instance(TwoBodyOperSet::R12)->key()) {
109 integral, p);
110 }
111 if (operset_key
112 == TwoBodyOperSetDescr::instance(TwoBodyOperSet::G12)->key()) {
114 integral, p);
115 }
116 if (operset_key
117 == TwoBodyOperSetDescr::instance(TwoBodyOperSet::G12NC)->key()) {
119 integral, p);
120 }
121 if (operset_key
122 == TwoBodyOperSetDescr::instance(TwoBodyOperSet::G12DKH)->key()) {
124 integral, p);
125 }
126 if (operset_key
127 == TwoBodyOperSetDescr::instance(TwoBodyOperSet::R12_0_G12)->key()) {
128 return new TwoBodyNCenterIntDescr<NumCenters,
129 TwoBodyOperSet::R12_0_G12>(integral, p);
130 }
131 if (operset_key
132 == TwoBodyOperSetDescr::instance(TwoBodyOperSet::R12_m1_G12)->key()) {
133 return new TwoBodyNCenterIntDescr<NumCenters,
134 TwoBodyOperSet::R12_m1_G12>(integral, p);
135 }
136 if (operset_key
137 == TwoBodyOperSetDescr::instance(TwoBodyOperSet::G12_T1_G12)->key()) {
138 return new TwoBodyNCenterIntDescr<NumCenters,
139 TwoBodyOperSet::G12_T1_G12>(integral, p);
140 }
141 if (operset_key
142 == TwoBodyOperSetDescr::instance(TwoBodyOperSet::DeltaFunction)->key()) {
143 return new TwoBodyNCenterIntDescr<NumCenters,
144 TwoBodyOperSet::DeltaFunction>(integral, p);
145 }
146 throw ProgrammingError(
147 "ParsedTwoBodyOperSetKey::create_descr() -- unknown oper",
148 __FILE__,
149 __LINE__);
150 }
151
152
153 private:
154 std::string key_;
155 std::string oper_;
156 std::string params_;
157 };
158
161 public:
162 ParsedTwoBodyFourCenterIntKey(const std::string& key);
163
164 const std::string& key() const { return key_; }
165 const std::string& bra1() const { return bra1_; }
166 const std::string& bra2() const { return bra2_; }
167 const std::string& ket1() const { return ket1_; }
168 const std::string& ket2() const { return ket2_; }
169 const std::string& oper() const { return oper_pkey_.oper(); }
170 const std::string& params() const { return oper_pkey_.params(); }
171 const std::string& layout() const { return layout_; }
172
174 static std::string key(const std::string& bra1,
175 const std::string& bra2,
176 const std::string& ket1,
177 const std::string& ket2,
178 const std::string& oper,
179 const std::string& params,
180 const std::string& layout);
182 static std::string key(const std::string& bra1,
183 const std::string& bra2,
184 const std::string& ket1,
185 const std::string& ket2,
186 const std::string& descr,
187 const std::string& layout);
188
189 private:
190 std::string key_;
191 std::string bra1_, bra2_, ket1_, ket2_;
192 ParsedTwoBodyOperSetKey oper_pkey_;
193 std::string layout_;
194 };
195
198 public:
199 ParsedTwoBodyThreeCenterIntKey(const std::string& key);
200
201 const std::string& key() const { return pkey_.key(); }
202 const std::string& bra1() const { return pkey_.bra1(); }
203 const std::string& bra2() const { return pkey_.bra2(); }
204 const std::string& ket1() const { return pkey_.ket1(); }
205 const std::string& oper() const { return pkey_.oper(); }
206 const std::string& params() const { return pkey_.params(); }
207
209 static std::string key(const std::string& bra1,
210 const std::string& bra2,
211 const std::string& ket1,
212 const std::string& oper,
213 const std::string& params);
215 static std::string key(const std::string& bra1,
216 const std::string& bra2,
217 const std::string& ket1,
218 const std::string& descr);
219
220 private:
221 // implemented in terms of the 4-center parser
223 };
224
227 public:
228 ParsedTwoBodyTwoCenterIntKey(const std::string& key);
229
230 const std::string& key() const { return pkey_.key(); }
231 const std::string& bra1() const { return pkey_.bra1(); }
232 const std::string& bra2() const { return pkey_.bra2(); }
233 const std::string& oper() const { return pkey_.oper(); }
234 const std::string& params() const { return pkey_.params(); }
235
237 static std::string key(const std::string& bra1,
238 const std::string& bra2,
239 const std::string& oper,
240 const std::string& params);
242 static std::string key(const std::string& bra1,
243 const std::string& bra2,
244 const std::string& descr);
245
246 private:
247 // implemented in terms of the 4-center parser
249 };
250
253 public:
254 static TwoBodyIntLayout b1b2_k1k2; // physicists layout
255 static TwoBodyIntLayout b1k1_b2k2; // chemists layout
256
257 TwoBodyIntLayout(const std::string& str);
259 TwoBodyIntLayout& operator=(const TwoBodyIntLayout& other);
260 bool operator==(const TwoBodyIntLayout& other) const;
261 operator std::string();
262
263 private:
264 typedef enum {
265 _b1b2_k1k2, // physicists layout
266 _b1k1_b2k2 // chemists layout
267 } Type;
268 Type type_;
269 };
270
271 class DensityFittingInfo;
272 namespace detail {
273 // computes the type of the object that holds the two-body MO integrals
274 // with the given number of centers
275 template <int NumCenters> struct TwoBodyIntEval;
276 template <> struct TwoBodyIntEval<4> {
278 typedef Ref<value> refvalue;
279 };
280 template <> struct TwoBodyIntEval<3> {
282 typedef Ref<value> refvalue;
283 };
284 template <> struct TwoBodyIntEval<2> {
285 typedef RefSCMatrix value;
286 typedef value refvalue;
287 };
288 // computes the type of the object that parses the labels for two-body MO integrals
289 // with the given number of centers
290 template <int NumCenters> struct ParsedTwoBodyIntKey;
291 template <> struct ParsedTwoBodyIntKey<4> {
293 };
294 template <> struct ParsedTwoBodyIntKey<3> {
296 };
297 template <> struct ParsedTwoBodyIntKey<2> {
299 };
300
301 // defines the type of the object that holds parameters of the two-body MO integrals runtime
302 // with the given number of centers. By default there are no parameters
303 template <int NumCenters> struct TwoBodyMOIntsRuntimeParams;
304 template <> struct TwoBodyMOIntsRuntimeParams<2> {
305 typedef DummySavableState value;
306 };
307 template <> struct TwoBodyMOIntsRuntimeParams<3> {
308 typedef DummySavableState value;
309 };
311 template <> struct TwoBodyMOIntsRuntimeParams<4> {
313 };
314
315 };
316
320 template <int NumCenters>
321 class TwoBodyMOIntsRuntime : virtual public SavableState {
322 public:
324 typedef typename detail::TwoBodyIntEval<NumCenters>::value TwoBodyIntEval;
325 typedef typename detail::TwoBodyIntEval<NumCenters>::refvalue TwoBodyIntEvalRef;
326 typedef typename NCentersToIntDescr<NumCenters,2>::value TwoBodyIntDescr;
327 typedef typename detail::ParsedTwoBodyIntKey<NumCenters>::value ParsedTwoBodyIntKey;
329
332 void save_data_state(StateOut& so);
334
336 void obsolete();
337
339 const Params* params() const { return const_cast<const Params*>(params_); } // cast because of serialization this can't be const
341 void params(const Params* p) { params_ = const_cast<Params*>(p); }
342
345 bool exists(const std::string& key) const;
346
353 TwoBodyIntEvalRef get(const std::string& key); // non-const: can compute integrals
354
358 static std::string descr_key(const Ref<TwoBodyIntDescr>& descr);
359
361 void remove_if(const std::string& space_key);
362
364 const Ref<MOIntsTransformFactory>& factory() const { return factory_; }
365
366 private:
367 Params* params_; //< optional parameters
368 Ref<MOIntsTransformFactory> factory_; //< that creates transforms
369
370 // Map to TwoBodyIntEval objects that have been computed previously
372 Ref<EvalRegistry> evals_;
373
374 // creates a TwoBodyIntEval object for a given key
375 const TwoBodyIntEvalRef& create_eval(const std::string& key);
376
380 Ref<TwoBodyIntDescr> create_descr(const std::string& oper_key,
381 const std::string& params_key);
382
383 static ClassDesc class_desc_;
384
385 };
386
387 template <int NumCenters>
388 ClassDesc
389 TwoBodyMOIntsRuntime<NumCenters>::class_desc_(typeid(this_type),
390 (std::string("TwoBodyMOIntsRuntime<") +
391 static_cast<char>('0' + NumCenters) +
392 std::string(">")).c_str(),
393 1,
394 "virtual public SavableState", 0, 0,
396
397 template <int NumCenters>
398 TwoBodyMOIntsRuntime<NumCenters>::TwoBodyMOIntsRuntime(const Ref<MOIntsTransformFactory>& f) : factory_(f),
399 evals_(EvalRegistry::instance()), params_(0)
400 {
401 }
402
403 template <int NumCenters>
404 void
406 {
407 SavableState::save_state(factory_.pointer(),so);
408 EvalRegistry::save_instance(evals_,so);
409 SavableState::save_state(params_,so);
410 }
411
412 template <int NumCenters>
414 {
415 }
416
417 template <int NumCenters>
418 void
420 evals_->clear();
421 }
422
423 template <int NumCenters>
425
426 template <>
428 ParsedTwoBodyMOIntsKeyInvolvesSpace(const std::string& skey) : space_key(skey) {}
429 bool operator()(const std::pair<std::string, detail::TwoBodyIntEval<4>::refvalue>& i) const {
430 const ParsedTwoBodyFourCenterIntKey pkey(i.first);
431 return pkey.bra1() == space_key ||
432 pkey.bra2() == space_key ||
433 pkey.ket1() == space_key ||
434 pkey.ket2() == space_key;
435 }
436 std::string space_key;
437 };
438 template <>
440 ParsedTwoBodyMOIntsKeyInvolvesSpace(const std::string& skey) : space_key(skey) {}
441 bool operator()(const std::pair<std::string, detail::TwoBodyIntEval<3>::refvalue>& i) const {
442 const ParsedTwoBodyThreeCenterIntKey pkey(i.first);
443 return pkey.bra1() == space_key ||
444 pkey.bra2() == space_key ||
445 pkey.ket1() == space_key;
446 }
447 std::string space_key;
448 };
449 template <>
451 ParsedTwoBodyMOIntsKeyInvolvesSpace(const std::string& skey) : space_key(skey) {}
452 bool operator()(const std::pair<std::string, detail::TwoBodyIntEval<2>::refvalue>& i) const {
453 const ParsedTwoBodyTwoCenterIntKey pkey(i.first);
454 return pkey.bra1() == space_key ||
455 pkey.bra2() == space_key;
456 }
457 std::string space_key;
458 };
459
460 template <int NumCenters>
461 void
462 TwoBodyMOIntsRuntime<NumCenters>::remove_if(const std::string& space_key) {
464 evals_->remove_if(pred);
465 }
466
467
468 template <int NumCenters>
469 bool
470 TwoBodyMOIntsRuntime<NumCenters>::exists(const std::string& key) const
471 {
472 return evals_->key_exists(key);
473 }
474
475 template <int NumCenters>
476 typename TwoBodyMOIntsRuntime<NumCenters>::TwoBodyIntEvalRef
478 {
479 if (evals_->key_exists(key)) {
480 return evals_->value(key);
481 }
482 else { // if not found
483 try { ParsedTwoBodyIntKey parsedkey(key); }
484 catch (...) {
485 std::ostringstream oss;
486 oss << "TwoBodyMOIntsRuntime<NumCenters>::get() -- key " << key << " does not match the format";
487 throw ProgrammingError(oss.str().c_str(),__FILE__,__LINE__);
488 }
489 // then create evaluated tform
490 const TwoBodyIntEvalRef& eval = create_eval(key);
491 return eval;
492 }
493 MPQC_ASSERT(false); // unreachable
494 }
495
496 template <int NumCenters>
497 std::string
499 {
500 return ParsedTwoBodyOperSetKey::key<NumCenters>(descr);
501 }
502
503 template <int NumCenters>
505 TwoBodyMOIntsRuntime<NumCenters>::create_descr(const std::string& oper_key,
506 const std::string& params_key)
507 {
508 Ref<IntParams> p = ParamsRegistry::instance()->value(params_key);
509 const Ref<Integral>& integral = factory()->integral();
510 return ParsedTwoBodyOperSetKey::create_descr<NumCenters>(oper_key,p,integral);
511 }
512
514
515 typedef TwoBodyMOIntsRuntime<4> TwoBodyFourCenterMOIntsRuntime;
516 typedef TwoBodyMOIntsRuntime<3> TwoBodyThreeCenterMOIntsRuntime;
517 typedef TwoBodyMOIntsRuntime<2> TwoBodyTwoCenterMOIntsRuntime;
518
520
524 public:
526 typedef Registry<std::string, RefSymmSCMatrix,
528 std::equal_to<std::string>, RefSymmSCMatrixEqual > KernelInverseRegistry;
529
536
538 const Ref<MOIntsTransformFactory>& factory() const { return factory_; }
540 const Ref<TwoBodyTwoCenterMOIntsRuntime>& runtime_2c() const { return runtime_2c_; }
542 const Ref<TwoBodyThreeCenterMOIntsRuntime>& runtime_3c() const { return runtime_3c_; }
544 const Ref<KernelInverseRegistry>& runtime_2c_inv() const { return runtime_2c_inv_; }
545
546 private:
547 static ClassDesc class_desc_;
548
552 Ref<KernelInverseRegistry> runtime_2c_inv_;
553
554 };
555
556
557} // end of namespace sc
558
559#endif // end of header guard
560
561
562// Local Variables:
563// mode: c++
564// c-file-style: "CLJ-CONDENSED"
565// End:
This class is used to contain information about classes.
Definition class.h:147
this is a singleton registry that holds IntParams objects.
Definition tbint_runtime.h:41
Ref< IntParams > value(const std::string &key) const
Returns params that correspond to key.
void clear()
erases all entries
bool key_exists(const std::string &key) const
key exists?
void add(const std::string &key, const Ref< IntParams > &params) const
register key->params mapping
std::string add(const Ref< IntParams > &params) const
register key->params mapping. A unique random key is generated automatically and returned
static const Ref< ParamsRegistry > & instance()
this is a singleton
std::string key(const Ref< IntParams > &params) const
Returns key that describes params.
Parsed representation of a string key that represents a set of 4-center 2-body integrals.
Definition tbint_runtime.h:160
static std::string key(const std::string &bra1, const std::string &bra2, const std::string &ket1, const std::string &ket2, const std::string &descr, const std::string &layout)
computes key from its components
static std::string key(const std::string &bra1, const std::string &bra2, const std::string &ket1, const std::string &ket2, const std::string &oper, const std::string &params, const std::string &layout)
computes key from its components
Parsed representation of a string key that represents a two-body operator set (TwoBodyOperSet + assoc...
Definition tbint_runtime.h:77
static std::string key(const Ref< typename NCentersToIntDescr< NumCenters, 2 >::value > &descr)
computes key from the given TwoBodyOperSetDescr object
Definition tbint_runtime.h:91
static std::string key(const std::string &oper, const std::string &params)
computes key from its components
static Ref< typename NCentersToIntDescr< NumCenters, 2 >::value > create_descr(const std::string &operset_key, const Ref< IntParams > &p, const Ref< Integral > &integral)
this factory method constructs a descriptor given operator key + IntParams object + Integrals object
Definition tbint_runtime.h:98
Parsed representation of a string key that represents a set of 3-center 2-body integrals.
Definition tbint_runtime.h:197
static std::string key(const std::string &bra1, const std::string &bra2, const std::string &ket1, const std::string &descr)
computes key from its components
static std::string key(const std::string &bra1, const std::string &bra2, const std::string &ket1, const std::string &oper, const std::string &params)
computes key from its components
Parsed representation of a string key that represents a set of 2-center 2-body integrals.
Definition tbint_runtime.h:226
static std::string key(const std::string &bra1, const std::string &bra2, const std::string &oper, const std::string &params)
computes key from its components
static std::string key(const std::string &bra1, const std::string &bra2, const std::string &descr)
computes key from its components
This is thrown when a situations arises that should be impossible.
Definition scexception.h:92
The base class for all reference counted objects.
Definition ref.h:192
The RefSCMatrix class is a smart pointer to an SCMatrix specialization.
Definition matrix.h:135
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition matrix.h:265
A template class that maintains references counts.
Definition ref.h:361
Registry wraps std::map and can be policy-configured to act as a Singleton or a regular object.
Definition registry.h:112
Base class for objects that can save/restore state.
Definition state.h:45
void save_state(StateOut &)
Save the state of the object as specified by the StateOut object.
Restores fundamental and user-defined types from images created with StateOut.
Definition statein.h:79
Serializes fundamental and user-defined types.
Definition stateout.h:71
describes the physical layout of the integrals in TwoBodyIntsAcc
Definition tbint_runtime.h:252
TwoBodyMOIntsRuntimeUnion23 packages 2-center and 3-center runtimes; it also keeps track of 2-center ...
Definition tbint_runtime.h:523
const Ref< TwoBodyTwoCenterMOIntsRuntime > & runtime_2c() const
runtime for 2-center integrals
Definition tbint_runtime.h:540
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
const Ref< TwoBodyThreeCenterMOIntsRuntime > & runtime_3c() const
runtime for 3-center integrals
Definition tbint_runtime.h:542
const Ref< KernelInverseRegistry > & runtime_2c_inv() const
runtime for 2-center integral matrix inverses
Definition tbint_runtime.h:544
const Ref< MOIntsTransformFactory > & factory() const
factory for creating AO->MO transforms
Definition tbint_runtime.h:538
Smart runtime support for computing MO-basis integrals.
Definition tbint_runtime.h:321
bool exists(const std::string &key) const
Returns true if the given TwoBodyIntEval is available.
Definition tbint_runtime.h:470
static std::string descr_key(const Ref< TwoBodyIntDescr > &descr)
Returns key that corresponds to descr.
Definition tbint_runtime.h:498
void save_data_state(StateOut &so)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
Definition tbint_runtime.h:405
const Params * params() const
return the params object that determines optional aspects of behavior of the runtime
Definition tbint_runtime.h:339
void params(const Params *p)
set the params object
Definition tbint_runtime.h:341
void remove_if(const std::string &space_key)
removes all entries that contain this space
Definition tbint_runtime.h:462
const Ref< MOIntsTransformFactory > & factory() const
returns the factory
Definition tbint_runtime.h:364
void obsolete()
obsoletes this object
Definition tbint_runtime.h:419
TwoBodyIntEvalRef get(const std::string &key)
Returns the TwoBodyIntEval that contains the integrals described by key.
Definition tbint_runtime.h:477
TwoBodyMOIntsTransform computes two-body integrals in MO basis using parallel integrals-direct AO->MO...
Definition transform_tbint.h:49
Implements descriptors for various two-body evaluators.
Definition intdescr.h:93
TwoBodyThreeCenterMOIntsTransform computes (xy|z) integrals, using parallel integral-direct AO->MO tr...
Definition transform_tbint.h:240
NonsingletonCreationPolicy is used to create non-Singletons on heap.
Definition registry.h:73
SpinCase1 other(SpinCase1 S)
given 1-spin return the other 1-spin
Contains all MPQC code up to version 3.
Definition mpqcin.h:14
DescribedClass * create()
This is used to pass a function that make void constructor calls to the ClassDesc constructor.
Definition class.h:102
this class encapsulates objects needed to perform density fitting of a 4-center integral
Definition df_runtime.h:235
useful as a dummy template argument
Definition state.h:116
Definition intdescr.h:156
Definition tbint_runtime.h:424
this functor can be used as a binary predicate for standard algorithms.
Definition ref.h:659
this functor compares RefSymmSCMatrix objects.
Definition matrix.h:537
@ G12
{eri, r12_0_g12, r12_m1_g12, t1g12, t2g12, g12t1g12}
Definition operator.h:347
@ R12
{eri, r12, r12t1, r12t2}
Definition operator.h:346
@ R12_0_G12
{r12_0_g12}
Definition operator.h:350
@ G12DKH
{g12p4g12_m_g12t1g12t1}
Definition operator.h:349
@ ERI
{eri}
Definition operator.h:345
@ R12_m1_G12
{r12_m1_g12}
Definition operator.h:351
@ G12_T1_G12
{g12t1g12}
Definition operator.h:352
@ G12NC
{eri, r12_0_g12, r12_m1_g12, g12t1g12, anti_g12g12}
Definition operator.h:348
@ DeltaFunction
{delta}
Definition operator.h:353
Definition tbint_runtime.h:290
Definition tbint_runtime.h:275
Definition tbint_runtime.h:303

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