votca 2026-dev
Loading...
Searching...
No Matches
chargeresponsesolver.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_CHARGERESPONSESOLVER_H
22#define VOTCA_XTP_CHARGERESPONSESOLVER_H
23
24// Standard includes
25#include <vector>
26
27// Local VOTCA includes
28#include "classicalsegment.h"
29#include "eeinteractor.h"
30#include "eigen.h"
31
32namespace votca {
33namespace xtp {
34
54 public:
55 ChargeResponseSolver(std::vector<PolarSegment>& segments,
56 const eeInteractor& interactor);
57
58 struct Info {
60 double error = 0.0; // relative residual
61 bool converged = false;
62 };
63
67 Info Solve(double tolerance, Index max_iter, bool use_previous);
68
72 double InternalChargeEnergy() const;
73
74 Index size() const { return dim_; }
75
76 // y + M^1/2 T M^1/2 y (public for tests)
77 Eigen::VectorXd Apply(const Eigen::VectorXd& y) const;
78
81 Eigen::MatrixXd DenseOperator() const;
83 Eigen::MatrixXd ApplyMhalf(const Eigen::MatrixXd& X) const;
87 Index ChargeIndex(Index k) const { return sites_[std::size_t(k)].q; }
88 Index NumCharges() const { return nq_; }
89
90 private:
91 struct SiteRef {
94 Index q; // index of its induced charge in x, -1 for Thole sites
95 };
96 // the couplings of sites a < b (FillDipoleInteraction / Thole inside a
97 // Thole segment, Gaussian kernel for the charges); none inside a CR
98 // segment (skip)
99 struct Coupling {
100 bool skip = false;
101 Eigen::Matrix3d T; // grad phi at b of the dipole at a
102 bool charges = false;
103 Eigen::Vector3d r; // pos b - pos a
104 double B0 = 0.0;
105 double B1 = 0.0;
106 };
107 Coupling PairCoupling(Index a, Index b) const;
108 Eigen::VectorXd ApplyT(const Eigen::VectorXd& x) const;
109 Eigen::VectorXd ApplyMhalf(const Eigen::VectorXd& x, bool inverse) const;
110 Eigen::VectorXd Sources() const;
111 Eigen::VectorXd ReadFromSites() const;
112 void WriteToSites(const Eigen::VectorXd& x);
113
114 std::vector<PolarSegment>& segments_;
116 std::vector<SiteRef> sites_;
119 // per charge-response segment: its first charge index, Pi^1/2 and the
120 // pseudo-inverse square root Pi^+1/2
124 Eigen::MatrixXd sqrt;
125 Eigen::MatrixXd inv_sqrt;
126 };
127 std::vector<SegmentBlock> blocks_;
128 // per site alpha^1/2 and alpha^-1/2
129 std::vector<Eigen::Matrix3d> alpha_sqrt_;
130 std::vector<Eigen::Matrix3d> alpha_inv_sqrt_;
131};
132
133} // namespace xtp
134} // namespace votca
135
136#endif // VOTCA_XTP_CHARGERESPONSESOLVER_H
Coupling PairCoupling(Index a, Index b) const
std::vector< PolarSegment > & segments_
Eigen::MatrixXd ApplyMhalf(const Eigen::MatrixXd &X) const
M^1/2 X for a matrix of unknown-space columns.
std::vector< SegmentBlock > blocks_
std::vector< Eigen::Matrix3d > alpha_sqrt_
void WriteToSites(const Eigen::VectorXd &x)
std::vector< Eigen::Matrix3d > alpha_inv_sqrt_
Eigen::VectorXd Apply(const Eigen::VectorXd &y) const
ChargeResponseSolver(std::vector< PolarSegment > &segments, const eeInteractor &interactor)
Eigen::VectorXd ApplyT(const Eigen::VectorXd &x) const
Info Solve(double tolerance, Index max_iter, bool use_previous)
Mediates interaction between polar and static sites.
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26