LIBINT 2.9.0
initialize.h
1/*
2 * Copyright (C) 2004-2024 Edward F. Valeev
3 *
4 * This file is part of Libint library.
5 *
6 * Libint library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser 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 * Libint library 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 Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with Libint library. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_lib_libint_initialize_h_
22#define _libint2_src_lib_libint_initialize_h_
23
24#include <libint2/util/cxxstd.h>
25#if LIBINT2_CPLUSPLUS_STD < 2011
26#error "Libint2 C++ API requires C++11 support"
27#endif
28
29#include <libint2.h>
30#include <libint2/deriv_map.h>
31#include <libint2/shgshell_ordering.h>
32#include <libint2/util/deprecated.h>
33#include <libint2/util/singleton.h>
34
35#include <atomic>
36#include <cassert>
37#include <iostream>
38
39namespace libint2 {
40
41namespace detail {
44 libint2_static_init();
45 libint2::DerivMapGenerator::initialize();
46 }
47 ~__initializer() { libint2_static_cleanup(); }
48};
49
50inline std::atomic<bool>& verbose_accessor() {
51 static std::atomic<bool> value{false};
52 return value;
53}
54inline std::ostream*& verbose_stream_accessor() {
55 static std::ostream* value = &std::clog;
56 return value;
57}
58inline std::atomic<SHGShellOrdering>& solid_harmonics_ordering_accessor() {
59 static std::atomic<SHGShellOrdering> value{
60 libint2::SHGShellOrdering_Standard};
61 return value;
62}
63} // namespace detail
64
68inline bool initialized() {
69 using namespace detail;
70 return managed_singleton<__initializer>::instance_exists();
71}
76inline void initialize(bool verbose = false) {
77 if (!initialized()) {
78 using namespace detail;
79 LIBINT_MAYBE_UNUSED __initializer* x =
80 managed_singleton<__initializer>::instance();
81 assert(x != nullptr);
82 verbose_accessor() = verbose;
83
84 // initialize() functions that take `SHGShellOrdering sho` as an argument
85 // aren't provided because
86 // * (a) with casting, it's hard to disentangle from `bool verbose`
87 // * (b) a separate setter is needed anyways for cases like the Python
88 // module, where initialize(sho) lives in libint code
89 // * code in initializer would go here as
90 // `solid_harmonics_ordering_accessor() = sho;`
91 }
92}
93
97inline void initialize(std::ostream& os) {
98 if (!initialized()) {
99 initialize(true);
100 using namespace detail;
101 verbose_stream_accessor() = &os;
102 }
103}
105inline void finalize() {
106 if (initialized()) {
107 using namespace detail;
108 managed_singleton<__initializer>::delete_instance();
109 verbose_accessor() = true;
110 verbose_stream_accessor() = &std::clog;
111 solid_harmonics_ordering_accessor() = libint2::SHGShellOrdering_Standard;
112 }
113}
117inline void set_solid_harmonics_ordering(SHGShellOrdering sho) {
118 detail::solid_harmonics_ordering_accessor() = sho;
119}
122inline SHGShellOrdering solid_harmonics_ordering() {
123 return detail::solid_harmonics_ordering_accessor();
124}
128inline std::ostream& verbose_stream() {
129 return *detail::verbose_stream_accessor();
130}
135inline bool verbose() {
136 if (initialized()) {
137 return detail::verbose_accessor();
138 } else {
139 return false;
140 }
141}
142} // namespace libint2
143
144#endif /* _libint2_src_lib_libint_initialize_h_ */
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
void initialize(bool verbose=false)
initializes the libint library if not currently initialized, no-op otherwise
Definition initialize.h:76
void set_solid_harmonics_ordering(SHGShellOrdering sho)
Setter for the SHGShellOrdering.
Definition initialize.h:117
std::ostream & verbose_stream()
Accessor for the disgnostics stream.
Definition initialize.h:128
bool initialized()
checks if the libint has been initialized.
Definition initialize.h:68
bool verbose()
Accessor for the verbose flag.
Definition initialize.h:135
void finalize()
finalizes the libint library.
Definition initialize.h:105
SHGShellOrdering solid_harmonics_ordering()
Accessor for the SHGShellOrdering.
Definition initialize.h:122
Definition initialize.h:42