votca 2024.2-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// VOTCA includes
32#include <votca/tools/eigen.h>
33#include <votca/tools/types.h>
34typedef Eigen::Matrix<double, 9, 1> Vector9d;
35typedef Eigen::Matrix<double, 9, 9> Matrix9d;
36typedef Eigen::Array<votca::Index, Eigen::Dynamic, 1> ArrayXl;
37
38namespace votca {
39namespace xtp {
40
41inline bool XTP_HAS_MKL_OVERLOAD() {
42
43 bool mkl_overload = false;
44#ifdef EIGEN_USE_MKL_ALL
45 mkl_overload = true;
46#endif
47 bool mkl_found = false;
48#ifdef MKL_FOUND
49 mkl_found = true;
50#endif
51 if (mkl_overload && mkl_found) {
52 return true;
53 } else {
54 return false;
55 }
56}
57
58// Stores matrix and energy together
60 public:
62 : energy_(0.0), matrix_(Eigen::MatrixXd::Zero(0, 0)){};
63
65 : energy_(0.0), matrix_(Eigen::MatrixXd::Zero(rows, cols)){};
66 Mat_p_Energy(double e, const Eigen::MatrixXd& mat)
67 : energy_(e), matrix_(mat){};
68 Mat_p_Energy(double e, Eigen::MatrixXd&& mat)
69 : energy_(e), matrix_(std::move(mat)){};
70
71 Mat_p_Energy operator+(const Mat_p_Energy& other) const {
72 Mat_p_Energy result = *this;
73 result. energy_ += other. energy_;
74 result. matrix_ += other. matrix_;
75 return result;
76 }
77
78 Index rows() const { return matrix_.rows(); }
79 Index cols() const { return matrix_.cols(); }
80 Eigen::MatrixXd& matrix() { return matrix_; }
81 double& energy() { return energy_; }
82 const Eigen::MatrixXd& matrix() const { return matrix_; }
83 double energy() const { return energy_; }
84
85 private:
86 double energy_;
87 Eigen::MatrixXd matrix_;
88};
89
90//Stores the diadicProduct of a vector with itself
91class AxA {
92 public:
93 AxA(const Eigen::Vector3d& a) {
94 data_.segment<3>(0) = a.x() * a;
95 data_.segment<2>(3) = a.y() * a.segment<2>(1);
96 data_[5] = a.z() * a.z();
97 }
98 inline const double& xx() const { return data_[0]; }
99 inline const double& xy() const { return data_[1]; }
100 inline const double& xz() const { return data_[2]; }
101 inline const double& yy() const { return data_[3]; }
102 inline const double& yz() const { return data_[4]; }
103 inline const double& zz() const { return data_[5]; }
104
105 private:
106 Eigen::Matrix<double, 6, 1> data_;
107 };
108
109
110
111
112#pragma omp declare reduction (+:Mat_p_Energy: omp_out=omp_out+omp_in)\
113 initializer(omp_priv=Mat_p_Energy(omp_orig.rows(),omp_orig.cols()))
114
115#pragma omp declare reduction (+: Eigen::VectorXd: omp_out=omp_out+omp_in)\
116 initializer(omp_priv=Eigen::VectorXd::Zero(omp_orig.size()))
117
118#pragma omp declare reduction (+: Eigen::MatrixXd: omp_out=omp_out+omp_in)\
119 initializer(omp_priv=Eigen::MatrixXd::Zero(omp_orig.rows(),omp_orig.cols()))
120
121#pragma omp declare reduction (+: Eigen::Matrix3d: omp_out=omp_out+omp_in)\
122 initializer(omp_priv=Eigen::Matrix3d::Zero())
123
124#pragma omp declare reduction (+: Eigen::Vector3d: omp_out=omp_out+omp_in)\
125 initializer(omp_priv=Eigen::Vector3d::Zero())
126
127namespace OPENMP {
129 Index nthreads = 1;
130#ifdef _OPENMP
131 nthreads = Index(omp_get_max_threads());
132#endif
133 return nthreads;
134}
135
137#ifdef _OPENMP
138 return omp_in_parallel();
139#endif
140return false;
141}
142
144 Index thread_id = 0;
145#ifdef _OPENMP
146 thread_id = Index(omp_get_thread_num());
147#endif
148 return thread_id;
149}
150
151#ifdef _OPENMP
152inline void setMaxThreads(Index threads) {
153 if (threads > 0) {
154 omp_set_num_threads(int(threads));
155 }
156}
157#else
158inline void setMaxThreads(Index) {}
159#endif
160} // namespace OPENMP
161} // namespace xtp
162} // namespace votca
163
164#endif // VOTCA_XTP_EIGEN_H
const double & zz() const
Definition eigen.h:103
const double & yz() const
Definition eigen.h:102
const double & yy() const
Definition eigen.h:101
const double & xy() const
Definition eigen.h:99
AxA(const Eigen::Vector3d &a)
Definition eigen.h:93
const double & xz() const
Definition eigen.h:100
const double & xx() const
Definition eigen.h:98
Eigen::Matrix< double, 6, 1 > data_
Definition eigen.h:106
Eigen::MatrixXd & matrix()
Definition eigen.h:80
Eigen::MatrixXd matrix_
Definition eigen.h:87
double & energy()
Definition eigen.h:81
const Eigen::MatrixXd & matrix() const
Definition eigen.h:82
Index cols() const
Definition eigen.h:79
double energy() const
Definition eigen.h:83
Index rows() const
Definition eigen.h:78
Mat_p_Energy operator+(const Mat_p_Energy &other) const
Definition eigen.h:71
Mat_p_Energy(Index rows, Index cols)
Definition eigen.h:64
Mat_p_Energy(double e, const Eigen::MatrixXd &mat)
Definition eigen.h:66
Mat_p_Energy(double e, Eigen::MatrixXd &&mat)
Definition eigen.h:68
STL namespace.
Index getMaxThreads()
Definition eigen.h:128
void setMaxThreads(Index)
Definition eigen.h:158
Index getThreadId()
Definition eigen.h:143
bool InsideActiveParallelRegion()
Definition eigen.h:136
bool XTP_HAS_MKL_OVERLOAD()
Definition eigen.h:41
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
Eigen::Array< votca::Index, Eigen::Dynamic, 1 > ArrayXl
Definition eigen.h:36
Eigen::Matrix< double, 9, 9 > Matrix9d
Definition eigen.h:35
Eigen::Matrix< double, 9, 1 > Vector9d
Definition eigen.h:34