votca 2026-dev
Loading...
Searching...
No Matches
lifetimesimulation.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_LIFETIMESIMULATION_H
22#define VOTCA_XTP_LIFETIMESIMULATION_H
23
24// Standard includes
25#include <cstdint>
26#include <limits>
27#include <memory>
28#include <string>
29#include <vector>
30
31// Local VOTCA includes
32#include "eigen.h"
33#include "kmcengine.h"
34#include "kmcrates.h"
35#include "kmcwaitingtime.h"
36#include "tofgraph.h"
37
38namespace votca {
39namespace xtp {
40
64 public:
65 struct Settings {
66 std::uint64_t seed = 1;
70 Index decays = 1000;
72 double max_wall_time = std::numeric_limits<double>::infinity();
74 bool keep_records = false;
78 };
79
80 struct Record {
83 double time = 0.0; // of the decay
84 double lifetime = 0.0; // decay - injection
87 Eigen::Vector3d displacement = Eigen::Vector3d::Zero();
88 };
89
91 struct DecaySums {
93 double lifetime = 0.0;
94 double lifetime2 = 0.0;
95 double distance = 0.0;
96 double distance2 = 0.0; // |R|^2
97 double distance4 = 0.0; // |R|^4
98 Eigen::Vector3d components = Eigen::Vector3d::Zero();
99 double hops = 0.0;
100 };
101
103 double time = 0.0;
105 double energy = 0.0; // mean site energy of the carriers
106 };
107
108 struct Result {
110 double lifetime = 0.0;
111 double lifetime_error = 0.0;
112 double hops = 0.0; // mean per carrier
113 double mean_distance = 0.0; // <|R|>
115 double squared_displacement = 0.0; // <|R|^2>
117 Eigen::Vector3d squared_components = Eigen::Vector3d::Zero(); // <R_a^2>
119 Eigen::VectorXd decay_fraction;
121 Eigen::VectorXd occupation;
122 std::vector<Record> records;
123 std::vector<EnergySample> energy;
127 double simulated_time = 0.0; // all runs
128 };
129
130 struct ExactResult {
131 double lifetime = 0.0;
133 Eigen::Vector3d squared_components = Eigen::Vector3d::Zero();
134 Eigen::VectorXd decay_probability;
136 Eigen::VectorXd occupation;
137 std::string solver;
138 double backward_error = 0.0;
139 bool converged = false;
140 };
141
144 LifetimeSimulation(const ToFGraph& graph, std::vector<double> decay_rates,
145 const Settings& settings);
146 LifetimeSimulation(const ToFGraph& graph, std::vector<double> decay_rates,
147 const Settings& settings, const TimeDependentRates& rates,
148 WaitingTimeStrategy& strategy);
149
150 Result Simulate() const;
151
154 static ExactResult Exact(const ToFGraph& graph,
155 const std::vector<double>& decay_rates,
156 Index direct_limit = 20000,
157 double tolerance = 1e-12);
158
159 private:
161 std::vector<double> decay_rates_;
163 std::unique_ptr<TimeDependentRates> own_rates_;
164 std::unique_ptr<WaitingTimeStrategy> own_strategy_;
165 std::unique_ptr<KMCEngine> engine_;
166
167 void Check() const;
168 void Setup(WaitingTimeStrategy& strategy, const TimeDependentRates& rates);
169 struct RunData {
171 std::vector<Record> records;
172 Eigen::VectorXd occupation; // time per site
173 Eigen::VectorXd decays; // per site
175 };
176 RunData SingleRun(Index run, Index decays,
177 std::vector<EnergySample>* energy) const;
178};
179
180} // namespace xtp
181} // namespace votca
182
183#endif // VOTCA_XTP_LIFETIMESIMULATION_H
std::unique_ptr< TimeDependentRates > own_rates_
std::unique_ptr< KMCEngine > engine_
std::unique_ptr< WaitingTimeStrategy > own_strategy_
static ExactResult Exact(const ToFGraph &graph, const std::vector< double > &decay_rates, Index direct_limit=20000, double tolerance=1e-12)
RunData SingleRun(Index run, Index decays, std::vector< EnergySample > *energy) const
void Setup(WaitingTimeStrategy &strategy, const TimeDependentRates &rates)
LifetimeSimulation(const ToFGraph &graph, std::vector< double > decay_rates, const Settings &settings)
Hop rates of the edges of a ToFGraph as functions of time.
Definition kmcrates.h:52
Hopping graph for time-of-flight (ToF) transport.
Definition tofgraph.h:77
How a carrier's next hop is drawn: the waiting time and the destination. The pluggable part of the KM...
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
Eigen::VectorXd occupation
expected time per site per carrier, normalized by the lifetime
Eigen::VectorXd occupation
occupation probability per site (sum: number of carriers)
Eigen::VectorXd decay_fraction
fraction of the decays per site
double max_wall_time
wall-clock limit of each run (s)
bool keep_records
keep the record of every decay
Index decays
decays in total, distributed over the runs