votca 2026-dev
Loading...
Searching...
No Matches
graphrandomwalk.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_GRAPHRANDOMWALK_H
22#define VOTCA_XTP_GRAPHRANDOMWALK_H
23
24// Standard includes
25#include <array>
26#include <stdexcept>
27#include <string>
28#include <vector>
29
30// Third party includes
31#include <Eigen/SparseCore>
32
33// Local VOTCA includes
34#include "eigen.h"
35#include "tofgraph.h"
36
37namespace votca {
38namespace xtp {
39
82 public:
83 enum class Solver { Auto, Cholesky, LU, CG, BiCGSTAB };
84 enum class Observable { First, Transit };
85
86 struct Settings {
90 double tolerance = 1e-14;
93 Index max_states = 50000000;
94 };
95
96 struct Result {
97 std::string solver;
103 double backward_error = 0.0;
109 bool converged = true;
110
114 std::vector<std::vector<Index>> sources;
115 Eigen::VectorXd tau;
116 Eigen::VectorXd tau_std;
117
120 double tau_mean = 0.0;
121 double tau_std_injection = 0.0;
123 double tau_harmonic = 0.0;
124
128 Eigen::VectorXd occupation_time;
129 };
130
131 explicit GraphRandomWalk(const ToFGraph& graph) : graph_(graph) {
132 if (graph_.isBulk()) {
133 throw std::runtime_error(
134 "GraphRandomWalk: hitting times need a ToF graph with sinks, not a "
135 "bulk graph without sinks");
136 }
137 }
138
139 void setSettings(const Settings& settings) { settings_ = settings; }
140
141 Result SingleCarrier(Solver solver = Solver::Auto) const;
142
143 Result TwoCarriers(Observable observable, Solver solver = Solver::Auto) const;
144
145 static Solver SolverFromString(const std::string& name);
146 static Observable ObservableFromString(const std::string& name);
147
148 private:
149 struct Transient {
150 std::vector<Index> index_of; // graph site -> transient index or -1
151 std::vector<Index> site_of; // transient index -> graph site
152 Eigen::VectorXd half_log_weight; // -(U - Uref)/2kT
153 };
154 Transient FindTransient() const;
155
158};
159
160} // namespace xtp
161} // namespace votca
162
163#endif // VOTCA_XTP_GRAPHRANDOMWALK_H
Result TwoCarriers(Observable observable, Solver solver=Solver::Auto) const
GraphRandomWalk(const ToFGraph &graph)
void setSettings(const Settings &settings)
static Solver SolverFromString(const std::string &name)
Result SingleCarrier(Solver solver=Solver::Auto) const
static Observable ObservableFromString(const std::string &name)
Hopping graph for time-of-flight (ToF) transport.
Definition tofgraph.h:77
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
std::vector< std::vector< Index > > sources
Index iterations
iterative solvers: total iterations
double tau_harmonic
harmonic mean over the injection states (eq. 3.4 of the paper)
double tolerance
relative residual of the iterative solvers
Index direct_limit
auto: direct solvers up to this many unknowns, iterative above
Index max_states
two carriers: refuse larger pair spaces (memory)