Skip to content

Commit 88e431e

Browse files
committed
Initial transfer of program-independent code from SVN r221
Also adds .gitignore
1 parent 64ea685 commit 88e431e

30 files changed

+5166
-0
lines changed

.gitignore

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
## C++
2+
3+
# Prerequisites
4+
*.d
5+
6+
# Compiled Object files
7+
*.slo
8+
*.lo
9+
*.o
10+
*.obj
11+
12+
# Precompiled Headers
13+
*.gch
14+
*.pch
15+
16+
# Compiled Dynamic libraries
17+
*.so
18+
*.dylib
19+
*.dll
20+
21+
# Fortran module files
22+
*.mod
23+
*.smod
24+
25+
# Compiled Static libraries
26+
*.lai
27+
*.la
28+
*.a
29+
*.lib
30+
31+
# Executables
32+
*.exe
33+
*.out
34+
*.app
35+
36+
## Python
37+
38+
# Byte-compiled / optimized / DLL files
39+
__pycache__/
40+
*.py[cod]
41+
*$py.class
42+
43+
# C extensions
44+
*.so
45+
46+
# Distribution / packaging
47+
.Python
48+
build/
49+
develop-eggs/
50+
dist/
51+
downloads/
52+
eggs/
53+
.eggs/
54+
lib/
55+
lib64/
56+
parts/
57+
sdist/
58+
var/
59+
wheels/
60+
*.egg-info/
61+
.installed.cfg
62+
*.egg
63+
MANIFEST
64+
65+
# PyInstaller
66+
# Usually these files are written by a python script from a template
67+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
68+
*.manifest
69+
*.spec
70+
71+
# Installer logs
72+
pip-log.txt
73+
pip-delete-this-directory.txt
74+
75+
# Unit test / coverage reports
76+
htmlcov/
77+
.tox/
78+
.coverage
79+
.coverage.*
80+
.cache
81+
nosetests.xml
82+
coverage.xml
83+
*.cover
84+
.hypothesis/
85+
86+
# Translations
87+
*.mo
88+
*.pot
89+
90+
# Django stuff:
91+
*.log
92+
.static_storage/
93+
.media/
94+
local_settings.py
95+
96+
# Flask stuff:
97+
instance/
98+
.webassets-cache
99+
100+
# Scrapy stuff:
101+
.scrapy
102+
103+
# Sphinx documentation
104+
docs/_build/
105+
106+
# PyBuilder
107+
target/
108+
109+
# Jupyter Notebook
110+
.ipynb_checkpoints
111+
112+
# pyenv
113+
.python-version
114+
115+
# celery beat schedule file
116+
celerybeat-schedule
117+
118+
# SageMath parsed files
119+
*.sage.py
120+
121+
# Environments
122+
.env
123+
.venv
124+
env/
125+
venv/
126+
ENV/
127+
env.bak/
128+
venv.bak/
129+
130+
# Spyder project settings
131+
.spyderproject
132+
.spyproject
133+
134+
# Rope project settings
135+
.ropeproject
136+
137+
# mkdocs documentation
138+
/site
139+
140+
# mypy
141+
.mypy_cache/

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cmake_minimum_required(VERSION 2.8.5)
2+
project(LIBRESPONSE CXX)
3+
4+
find_package(Armadillo REQUIRED)
5+
6+
set(SRC
7+
configurable.C
8+
dump_ao_integrals.C
9+
index_printing.C
10+
indices.C
11+
matvec_i.C
12+
utils.C
13+
linear/helpers.C
14+
linear/interface.C
15+
linear/interface_nonorthogonal.C
16+
linear/printing.C
17+
operator_spec.C
18+
set_defaults.C
19+
)
20+
21+
add_library(response ${SRC})
22+
target_link_libraries(response "${ARMADILLO_LIBRARIES}")
23+
24+
if(OPENMP_FOUND)
25+
set_target_properties(response PROPERTIES COMPILE_FLAGS "${OpenMP_CXX_FLAGS}")
26+
endif(OPENMP_FOUND)

configurable.C

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include "configurable.h"
3+
4+
namespace libresponse {
5+
6+
const std::string &configurable::get_param(const std::string &key) const {
7+
ssmap_it_type i = m_params.find(key);
8+
return i == m_params.end() ? m_empty : i->second;
9+
}
10+
11+
void configurable::cfg(const std::string &key, const std::string &val) {
12+
m_params[key] = val;
13+
}
14+
15+
void configurable::dump_params() const {
16+
for (ssmap_it_type iter = m_params.begin(); iter != m_params.end(); ++iter)
17+
std::cout << " " << iter->first << ": " << iter->second << std::endl;
18+
}
19+
20+
bool configurable::has_param(const std::string &key) const {
21+
return static_cast<bool>(m_params.count(key));
22+
}
23+
24+
} // namespace libresponse

configurable.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#ifndef LIBRESPONSE_CONFIGURABLE_H_
2+
#define LIBRESPONSE_CONFIGURABLE_H_
3+
4+
/*!
5+
* @file
6+
*
7+
* Inheritable configuration by wrapping a string->string map.
8+
*/
9+
10+
#include <cstdlib>
11+
#include <map>
12+
#include <sstream>
13+
#include <string>
14+
#include <stdexcept>
15+
16+
typedef std::map< std::string, std::string > ssmap;
17+
typedef ssmap::const_iterator ssmap_it_type;
18+
19+
namespace libresponse {
20+
21+
/*!
22+
* Inheritable configuration by wrapping a string->string map.
23+
*/
24+
class configurable {
25+
private:
26+
ssmap m_params; //!< Key-value parameters
27+
std::string m_empty; //!< Empty value
28+
29+
public:
30+
/*!
31+
* Default constructor
32+
*/
33+
configurable() { }
34+
35+
const std::string &get_param(const std::string &key) const;
36+
void cfg(const std::string &key, const std::string &val);
37+
38+
template<typename T>
39+
void get_param(const std::string &key, T &val) const;
40+
41+
template<typename T>
42+
T get_param(const std::string &key) const;
43+
44+
template<typename T>
45+
void cfg(const std::string &key, const T &val);
46+
47+
/*!
48+
* Print all key-value pairs to stdout
49+
*/
50+
void dump_params() const;
51+
52+
bool has_param(const std::string &key) const;
53+
};
54+
55+
56+
template<typename T>
57+
void configurable::cfg(const std::string &key, const T &val) {
58+
59+
std::ostringstream ss;
60+
ss << val;
61+
cfg(key, ss.str());
62+
}
63+
64+
65+
template<typename T>
66+
void configurable::get_param(const std::string &key, T &val) const {
67+
68+
const std::string &par = get_param(key);
69+
if (!par.empty()) {
70+
std::stringstream ss;
71+
ss << par; ss >> val;
72+
}
73+
}
74+
75+
76+
template<typename T>
77+
T configurable::get_param(const std::string &key) const {
78+
79+
if(m_params.count(key) == 0) {
80+
throw std::logic_error(
81+
"configurable::get_param(): no parameter with given name: " + key);
82+
}
83+
84+
T t;
85+
get_param(key, t);
86+
return t;
87+
}
88+
89+
} // namespace libresponse
90+
91+
#endif // LIBRESPONSE_CONFIGURABLE_H_

constants.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef LIBRESPONSE_CONSTANTS_H_
2+
#define LIBRESPONSE_CONSTANTS_H_
3+
4+
/*!
5+
* @brief Physical constants from CODATA 2014.
6+
*
7+
* @file
8+
*/
9+
10+
#include <armadillo>
11+
#include <set>
12+
#include <vector>
13+
14+
namespace libresponse {
15+
namespace constant {
16+
17+
const double fine_structure_constant = 7.2973525664e-3;
18+
const double alpha = fine_structure_constant;
19+
20+
} // namespace constant
21+
} // namespace libresponse
22+
23+
#endif // LIBRESPONSE_CONSTANTS_H_

dump_ao_integrals.C

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "dump_ao_integrals.h"
2+
3+
template void dump_integrals(
4+
const arma::mat& arma_integrals,
5+
const std::string& integral_description,
6+
const std::string& input_basename,
7+
const std::string& integral_filename_ending);
8+
template void dump_integrals(
9+
const arma::cube& arma_integrals,
10+
const std::string& integral_description,
11+
const std::string& input_basename,
12+
const std::string& integral_filename_ending);
13+
14+
void dump_ao_integrals(const std::vector<libresponse::operator_spec> &operators, const std::string &basename)
15+
{
16+
for (size_t i = 0; i < operators.size(); i++) {
17+
dump_integrals(
18+
operators[i].integrals_ao,
19+
operators[i].metadata.operator_label,
20+
basename,
21+
operators[i].metadata.operator_label + std::string(".dat"));
22+
}
23+
}

dump_ao_integrals.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef LIBRESPONSE_DUMP_AO_INTEGRALS_H_
2+
#define LIBRESPONSE_DUMP_AO_INTEGRALS_H_
3+
4+
#include "operator_spec.h"
5+
6+
/*!
7+
* @brief Write the contents of an Armadillo container (matrix, cube)
8+
* to disk.
9+
*/
10+
template<typename T>
11+
void dump_integrals(
12+
const T& arma_integrals,
13+
const std::string& integral_description,
14+
const std::string& input_basename,
15+
const std::string& integral_filename_ending) {
16+
17+
const std::string integral_filename = \
18+
input_basename + "." + integral_filename_ending;
19+
20+
std::cout \
21+
<< " Dumping " \
22+
<< integral_description \
23+
<< " integrals to file: " \
24+
<< integral_filename \
25+
<< std::endl;
26+
27+
const bool res = arma_integrals.save(integral_filename, arma::arma_ascii);
28+
29+
if (!res) {
30+
std::cout << " Couldn't save integrals to file." << std::endl;
31+
throw 1;
32+
}
33+
34+
return;
35+
36+
}
37+
38+
void dump_ao_integrals(const std::vector<libresponse::operator_spec> &operators, const std::string &basename);
39+
40+
#endif // LIBRESPONSE_DUMP_AO_INTEGRALS_H_

0 commit comments

Comments
 (0)