votca 2024.2-dev
Loading...
Searching...
No Matches
statefilter_base.cc
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// Local VOTCA includes
22
23namespace votca {
24namespace xtp {
25
26template <bool larger>
28 const Eigen::VectorXd& overlap, Index offset, double threshold) const {
29 std::vector<Index> index = std::vector<Index>(overlap.size());
30 std::iota(index.begin(), index.end(), offset);
31 std::stable_sort(index.begin(), index.end(), [&overlap](Index i1, Index i2) {
32 if (larger) {
33 return overlap[i1] > overlap[i2];
34 } else {
35 return overlap[i1] < overlap[i2];
36 }
37 });
38 Index validelements;
39 if (larger) {
40 validelements = (overlap.array() > threshold).sum();
41 } else {
42 validelements = (overlap.array() < threshold).sum();
43 }
44
45 std::vector<Index> indexes(validelements);
46 std::copy_n(index.begin(), validelements, indexes.begin());
47 return indexes;
48}
49
50std::vector<Index> StateFilter_base::ReduceAndSortIndecesUp(
51 const Eigen::VectorXd& overlap, Index offset, double threshold) const {
52 return ReduceAndSortIndeces<true>(overlap, offset, threshold);
53}
54std::vector<Index> StateFilter_base::ReduceAndSortIndecesDown(
55 const Eigen::VectorXd& overlap, Index offset, double threshold) const {
56 return ReduceAndSortIndeces<false>(overlap, offset, threshold);
57}
58
59} // namespace xtp
60} // namespace votca
std::vector< Index > ReduceAndSortIndeces(const Eigen::VectorXd &overlap, Index offset, double threshold) const
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26