votca 2026-dev
Loading...
Searching...
No Matches
kmcengine.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_KMCENGINE_H
22#define VOTCA_XTP_KMCENGINE_H
23
24// Standard includes
25#include <cmath>
26#include <cstdint>
27#include <limits>
28#include <string>
29#include <vector>
30
31// Local VOTCA includes
32#include "eigen.h"
33#include "kmcrandom.h"
34#include "kmcwaitingtime.h"
35#include "tofgraph.h"
36
37namespace votca {
38namespace xtp {
39
67class KMCEngine {
68 public:
70
71 struct Pulse {
72 enum class Shape { Delta, Gaussian, Rectangular };
73 double start = 0.0; // s
76 double width = 0.0; // s: standard deviation (Gaussian) or full width
77 };
78
82 static std::vector<double> InjectionTimes(const std::vector<Pulse>& pulses,
83 Random& random);
84 static Pulse::Shape ShapeFromString(const std::string& name);
85
86 class Observer {
87 public:
88 virtual ~Observer() = default;
89 virtual void Inject(Index /*carrier*/, Index /*site*/, double /*t*/) {}
90 virtual void Hop(Index /*carrier*/, Index /*from*/, Index /*to*/,
91 const Eigen::Vector3d& /*dR*/, double /*t*/) {}
92 virtual void Absorb(Index /*carrier*/, Index /*site*/, double /*t*/) {}
93 virtual void Decay(Index /*carrier*/, Index /*site*/, double /*t*/) {}
94 };
95
99 const std::vector<double>* rates = nullptr;
101 bool replace = false;
102 };
103
104 struct Limits {
106 double max_time = std::numeric_limits<double>::infinity();
108 Index max_events = std::numeric_limits<Index>::max();
110 double max_wall_time = std::numeric_limits<double>::infinity();
112 Index max_decays = std::numeric_limits<Index>::max();
113 };
114
137
140 KMCEngine(const ToFGraph& graph, const WaitingTimeStrategy& strategy)
141 : graph_(graph), strategy_(strategy) {}
142
144 void setDecay(const DecaySettings& decay);
145
149 RunStatus Run(const std::vector<double>& injection_times, Random& random,
150 Observer& observer, const Limits& limits) const;
151
152 private:
156};
157
158} // namespace xtp
159} // namespace votca
160
161#endif // VOTCA_XTP_KMCENGINE_H
virtual void Absorb(Index, Index, double)
Definition kmcengine.h:92
virtual void Hop(Index, Index, Index, const Eigen::Vector3d &, double)
Definition kmcengine.h:90
virtual void Decay(Index, Index, double)
Definition kmcengine.h:93
virtual void Inject(Index, Index, double)
Definition kmcengine.h:89
const ToFGraph & graph_
Definition kmcengine.h:153
static std::vector< double > InjectionTimes(const std::vector< Pulse > &pulses, Random &random)
Definition kmcengine.cc:79
RunStatus Run(const std::vector< double > &injection_times, Random &random, Observer &observer, const Limits &limits) const
Definition kmcengine.cc:120
static Pulse::Shape ShapeFromString(const std::string &name)
Definition kmcengine.cc:67
DecaySettings decay_
Definition kmcengine.h:155
void setDecay(const DecaySettings &decay)
per-site decay; rates must be >= 0 and finite, one per site
Definition kmcengine.cc:103
KMCEngine(const ToFGraph &graph, const WaitingTimeStrategy &strategy)
Definition kmcengine.h:140
const WaitingTimeStrategy & strategy_
Definition kmcengine.h:154
Random numbers for kinetic Monte Carlo: one independent stream per (seed, stream) pair....
Definition kmcrandom.h:42
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
const std::vector< double > * rates
Definition kmcengine.h:99
bool replace
inject a new carrier at the time of every decay
Definition kmcengine.h:101
Index max_events
candidate events (hops and null events)
Definition kmcengine.h:108
double max_wall_time
wall-clock time of the run, s (checked every 4096 events)
Definition kmcengine.h:110
Index max_decays
stop after this many decays
Definition kmcengine.h:112
double max_time
simulated time, s
Definition kmcengine.h:106
Index blocked_injections
injections dropped because all source sites were occupied
Definition kmcengine.h:125
Index events
candidate events processed
Definition kmcengine.h:135