votca 2026-dev
Loading...
Searching...
No Matches
eigen.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_EIGEN_H
22#define VOTCA_XTP_EIGEN_H
23
24// CMake Generated file
25// clang-format off
26// order seems to matter here
27#include "votca_xtp_config.h"
29//clang-format on
30
31// Standard includes
32#include <string>
33
34// VOTCA includes
35#include <votca/tools/eigen.h>
36#include <votca/tools/types.h>
37typedef Eigen::Matrix<double, 9, 1> Vector9d;
38typedef Eigen::Matrix<double, 9, 9> Matrix9d;
39typedef Eigen::Array<votca::Index, Eigen::Dynamic, 1> ArrayXl;
40
41namespace votca {
42namespace xtp {
43
44inline bool XTP_HAS_MKL_OVERLOAD() {
45
46 bool mkl_overload = false;
47#ifdef EIGEN_USE_MKL_ALL
48 mkl_overload = true;
49#endif
50 bool mkl_found = false;
51#ifdef MKL_FOUND
52 mkl_found = true;
53#endif
54 if (mkl_overload && mkl_found) {
55 return true;
56 } else {
57 return false;
58 }
59}
60
63inline std::string EigenBackendDescription() {
65 return "MKL overload for Eigen (BLAS and LAPACK)";
66 }
67#if defined(APPLE_ACCELERATE_FOUND) && defined(EIGEN_USE_BLAS) && \
68 defined(EIGEN_USE_LAPACKE)
69 return "Apple Accelerate BLAS and LAPACKE overload for Eigen";
70#else
71 return "native Eigen implementation, no BLAS overload";
72#endif
73}
74
75// Stores matrix and energy together
77 public:
79 : energy_(0.0), matrix_(Eigen::MatrixXd::Zero(0, 0)){};
80
82 : energy_(0.0), matrix_(Eigen::MatrixXd::Zero(rows, cols)){};
83 Mat_p_Energy(double e, const Eigen::MatrixXd& mat)
84 : energy_(e), matrix_(mat){};
85 Mat_p_Energy(double e, Eigen::MatrixXd&& mat)
86 : energy_(e), matrix_(std::move(mat)){};
87
88 Mat_p_Energy operator+(const Mat_p_Energy& other) const {
89 Mat_p_Energy result = *this;
90 result. energy_ += other. energy_;
91 result. matrix_ += other. matrix_;
92 return result;
93 }
94
95 Index rows() const { return matrix_.rows(); }
96 Index cols() const { return matrix_.cols(); }
97 Eigen::MatrixXd& matrix() { return matrix_; }
98 double& energy() { return energy_; }
99 const Eigen::MatrixXd& matrix() const { return matrix_; }
100 double energy() const { return energy_; }
101
102 private:
103 double energy_;
104 Eigen::MatrixXd matrix_;
105};
106
107//Stores the diadicProduct of a vector with itself
108class AxA {
109 public:
110 AxA(const Eigen::Vector3d& a) {
111 data_.segment<3>(0) = a.x() * a;
112 data_.segment<2>(3) = a.y() * a.segment<2>(1);
113 data_[5] = a.z() * a.z();
114 }
115 inline const double& xx() const { return data_[0]; }
116 inline const double& xy() const { return data_[1]; }
117 inline const double& xz() const { return data_[2]; }
118 inline const double& yy() const { return data_[3]; }
119 inline const double& yz() const { return data_[4]; }
120 inline const double& zz() const { return data_[5]; }
121
122 private:
123 Eigen::Matrix<double, 6, 1> data_;
124 };
125
126
127
128
129#pragma omp declare reduction (+:Mat_p_Energy: omp_out=omp_out+omp_in)\
130 initializer(omp_priv=Mat_p_Energy(omp_orig.rows(),omp_orig.cols()))
131
132#pragma omp declare reduction (+: Eigen::VectorXd: omp_out=omp_out+omp_in)\
133 initializer(omp_priv=Eigen::VectorXd::Zero(omp_orig.size()))
134
135#pragma omp declare reduction (+: Eigen::MatrixXd: omp_out=omp_out+omp_in)\
136 initializer(omp_priv=Eigen::MatrixXd::Zero(omp_orig.rows(),omp_orig.cols()))
137
138#pragma omp declare reduction (+: Eigen::Matrix3d: omp_out=omp_out+omp_in)\
139 initializer(omp_priv=Eigen::Matrix3d::Zero())
140
141#pragma omp declare reduction (+: Eigen::Vector3d: omp_out=omp_out+omp_in)\
142 initializer(omp_priv=Eigen::Vector3d::Zero())
143
144namespace OPENMP {
146 Index nthreads = 1;
147#ifdef _OPENMP
148 nthreads = Index(omp_get_max_threads());
149#endif
150 return nthreads;
151}
152
154#ifdef _OPENMP
155 return omp_in_parallel();
156#endif
157return false;
158}
159
161 Index thread_id = 0;
162#ifdef _OPENMP
163 thread_id = Index(omp_get_thread_num());
164#endif
165 return thread_id;
166}
167
168#ifdef _OPENMP
169inline void setMaxThreads(Index threads) {
170 if (threads > 0) {
171 omp_set_num_threads(int(threads));
172 }
173}
174#else
175inline void setMaxThreads(Index) {}
176#endif
177} // namespace OPENMP
178} // namespace xtp
179} // namespace votca
180
181#endif // VOTCA_XTP_EIGEN_H
const double & zz() const
Definition eigen.h:120
const double & yz() const
Definition eigen.h:119
const double & yy() const
Definition eigen.h:118
const double & xy() const
Definition eigen.h:116
AxA(const Eigen::Vector3d &a)
Definition eigen.h:110
const double & xz() const
Definition eigen.h:117
const double & xx() const
Definition eigen.h:115
Eigen::Matrix< double, 6, 1 > data_
Definition eigen.h:123
Eigen::MatrixXd & matrix()
Definition eigen.h:97
Eigen::MatrixXd matrix_
Definition eigen.h:104
double & energy()
Definition eigen.h:98
const Eigen::MatrixXd & matrix() const
Definition eigen.h:99
Index cols() const
Definition eigen.h:96
double energy() const
Definition eigen.h:100
Index rows() const
Definition eigen.h:95
Mat_p_Energy operator+(const Mat_p_Energy &other) const
Definition eigen.h:88
Mat_p_Energy(Index rows, Index cols)
Definition eigen.h:81
Mat_p_Energy(double e, const Eigen::MatrixXd &mat)
Definition eigen.h:83
Mat_p_Energy(double e, Eigen::MatrixXd &&mat)
Definition eigen.h:85
STL namespace.
Index getMaxThreads()
Definition eigen.h:145
void setMaxThreads(Index)
Definition eigen.h:175
Index getThreadId()
Definition eigen.h:160
bool InsideActiveParallelRegion()
Definition eigen.h:153
bool XTP_HAS_MKL_OVERLOAD()
Definition eigen.h:44
std::string EigenBackendDescription()
Definition eigen.h:63
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
Eigen::Array< votca::Index, Eigen::Dynamic, 1 > ArrayXl
Definition eigen.h:39
Eigen::Matrix< double, 9, 9 > Matrix9d
Definition eigen.h:38
Eigen::Matrix< double, 9, 1 > Vector9d
Definition eigen.h:37