votca 2026-dev
Loading...
Searching...
No Matches
scaledsolve.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 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_SCALEDSOLVE_H
22#define VOTCA_XTP_SCALEDSOLVE_H
23
24// Local VOTCA includes
25#include "eigen.h"
26
27namespace votca {
28namespace xtp {
29
43template <class IterativeSolver>
44Eigen::VectorXd ScaledSolve(const IterativeSolver& solver,
45 const Eigen::VectorXd& b, bool* solved = nullptr) {
46 const double scale = b.size() > 0 ? b.cwiseAbs().maxCoeff() : 0.0;
47 if (solved != nullptr) {
48 *solved = scale > 0.0;
49 }
50 if (!(scale > 0.0)) {
51 return Eigen::VectorXd::Zero(b.size());
52 }
53 Eigen::VectorXd x = solver.solve(b / scale);
54 return x * scale;
55}
56
57} // namespace xtp
58} // namespace votca
59
60#endif // VOTCA_XTP_SCALEDSOLVE_H
Eigen::VectorXd ScaledSolve(const IterativeSolver &solver, const Eigen::VectorXd &b, bool *solved=nullptr)
Solves A x = b with an Eigen iterative solver for the right-hand side scaled to a largest entry of 1.
Definition scaledsolve.h:44
Provides a means for comparing floating point numbers.
Definition basebead.h:33