ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/reaction_methods/SingleReaction.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef REACTION_METHODS_SINGLE_REACTION_HPP
20#define REACTION_METHODS_SINGLE_REACTION_HPP
21
22#include <utils/Accumulator.hpp>
23
24#include <numeric>
25#include <stdexcept>
26#include <vector>
27
28namespace ReactionMethods {
29
31 SingleReaction() = default;
32 SingleReaction(double gamma, std::vector<int> const &reactant_types,
33 std::vector<int> const &reactant_coefficients,
34 std::vector<int> const &product_types,
35 std::vector<int> const &product_coefficients) {
36 if (reactant_types.size() != reactant_coefficients.size()) {
37 throw std::invalid_argument(
38 "reactants: number of types and coefficients have to match");
39 }
40 if (product_types.size() != product_coefficients.size()) {
41 throw std::invalid_argument(
42 "products: number of types and coefficients have to match");
43 }
44 if (gamma <= 0.) {
45 throw std::domain_error("gamma needs to be a strictly positive value");
46 }
47 this->reactant_types = reactant_types;
48 this->reactant_coefficients = reactant_coefficients;
49 this->product_types = product_types;
50 this->product_coefficients = product_coefficients;
51 this->gamma = gamma;
52 nu_bar = std::accumulate(product_coefficients.begin(),
53 product_coefficients.end(), 0) -
54 std::accumulate(reactant_coefficients.begin(),
55 reactant_coefficients.end(), 0);
56 }
57
58 // strict input to the algorithm
59 std::vector<int> reactant_types;
60 std::vector<int> reactant_coefficients;
61 std::vector<int> product_types;
62 std::vector<int> product_coefficients;
63 double gamma = {};
64 // calculated values that are stored for performance reasons
65 int nu_bar = {}; ///< change in particle numbers for the reaction
68 int tried_moves = 0;
70 double get_acceptance_rate() const {
71 return static_cast<double>(accepted_moves) /
72 static_cast<double>(tried_moves);
73 }
74};
75
76} // namespace ReactionMethods
77#endif
int nu_bar
change in particle numbers for the reaction
SingleReaction(double gamma, std::vector< int > const &reactant_types, std::vector< int > const &reactant_coefficients, std::vector< int > const &product_types, std::vector< int > const &product_coefficients)