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
28
namespace
ReactionMethods
{
29
30
struct
SingleReaction
{
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
66
Utils::Accumulator
accumulator_potential_energy_difference_exponential
=
67
Utils::Accumulator
(1);
68
int
tried_moves
= 0;
69
int
accepted_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
Accumulator.hpp
Utils::Accumulator
Definition
Accumulator.hpp:48
ReactionMethods
Definition
core/reaction_methods/ConstantpHEnsemble.hpp:26
ReactionMethods::SingleReaction
Definition
core/reaction_methods/SingleReaction.hpp:30
ReactionMethods::SingleReaction::SingleReaction
SingleReaction()=default
ReactionMethods::SingleReaction::tried_moves
int tried_moves
Definition
core/reaction_methods/SingleReaction.hpp:68
ReactionMethods::SingleReaction::reactant_types
std::vector< int > reactant_types
Definition
core/reaction_methods/SingleReaction.hpp:59
ReactionMethods::SingleReaction::accumulator_potential_energy_difference_exponential
Utils::Accumulator accumulator_potential_energy_difference_exponential
Definition
core/reaction_methods/SingleReaction.hpp:66
ReactionMethods::SingleReaction::get_acceptance_rate
double get_acceptance_rate() const
Definition
core/reaction_methods/SingleReaction.hpp:70
ReactionMethods::SingleReaction::gamma
double gamma
Definition
core/reaction_methods/SingleReaction.hpp:63
ReactionMethods::SingleReaction::nu_bar
int nu_bar
change in particle numbers for the reaction
Definition
core/reaction_methods/SingleReaction.hpp:65
ReactionMethods::SingleReaction::product_types
std::vector< int > product_types
Definition
core/reaction_methods/SingleReaction.hpp:61
ReactionMethods::SingleReaction::product_coefficients
std::vector< int > product_coefficients
Definition
core/reaction_methods/SingleReaction.hpp:62
ReactionMethods::SingleReaction::SingleReaction
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)
Definition
core/reaction_methods/SingleReaction.hpp:32
ReactionMethods::SingleReaction::reactant_coefficients
std::vector< int > reactant_coefficients
Definition
core/reaction_methods/SingleReaction.hpp:60
ReactionMethods::SingleReaction::accepted_moves
int accepted_moves
Definition
core/reaction_methods/SingleReaction.hpp:69
src
core
reaction_methods
SingleReaction.hpp
Generated on Fri Nov 8 2024 02:12:53 for ESPResSo by
1.9.8