ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/reaction_methods/ReactionAlgorithm.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2021-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
20
#ifndef SCRIPT_INTERFACE_REACTION_METHODS_REACTION_ALGORITHM_HPP
21
#define SCRIPT_INTERFACE_REACTION_METHODS_REACTION_ALGORITHM_HPP
22
23
#include "
SingleReaction.hpp
"
24
25
#include "
script_interface/ScriptInterface.hpp
"
26
#include "
script_interface/particle_data/ParticleHandle.hpp
"
27
28
#include "
core/reaction_methods/ReactionAlgorithm.hpp
"
29
#include "
core/reaction_methods/utils.hpp
"
30
31
#include <memory>
32
#include <stdexcept>
33
#include <string>
34
#include <unordered_map>
35
#include <vector>
36
37
namespace
ScriptInterface
{
38
namespace
ReactionMethods
{
39
40
class
ReactionAlgorithm
:
public
AutoParameters
<ReactionAlgorithm> {
41
protected
:
42
/** Keep track of the script interface pointer of each reaction. */
43
std::vector<std::shared_ptr<SingleReaction>>
m_reactions
;
44
/**
45
* Check reaction id is within the reaction container bounds.
46
* Since each reaction has a corresponding backward reaction,
47
* the total number of reactions is doubled. Return the
48
* corresponding index for @ref ReactionAlgorithm::m_reactions.
49
*/
50
int
get_reaction_index
(
int
reaction_id)
const
{
51
auto
const
index = 2 * reaction_id;
52
context
()->
parallel_try_catch
([&]() {
53
if
(
index < 0 or index >
=
static_cast<
int
>
(
m_reactions
.size())) {
54
throw std::out_of_range(
"No reaction with id "
+
55
std::to_string(reaction_id));
56
}
57
});
58
return
index;
59
}
60
61
public
:
62
virtual
std::shared_ptr<::ReactionMethods::ReactionAlgorithm>
RE
() = 0;
63
virtual
std::shared_ptr<::ReactionMethods::ReactionAlgorithm>
const
64
RE
()
const
= 0;
65
66
ReactionAlgorithm
();
67
68
Variant
do_call_method
(std::string
const
&
name
,
69
VariantMap
const
&
params
)
override
;
70
71
protected
:
72
virtual
double
calculate_factorial_expression
(
73
::ReactionMethods::SingleReaction
const
&
reaction
,
74
std::unordered_map<int, int>
const
&
particle_numbers
)
const
{
75
return ::ReactionMethods::calculate_factorial_expression(
reaction
,
76
particle_numbers
);
77
}
78
79
private
:
80
void
delete_reaction(
int
reaction_id) {
81
m_reactions
.erase(
m_reactions
.begin() + reaction_id);
82
RE
()->delete_reaction(reaction_id);
83
}
84
85
std::string
get_internal_state
()
const override
{
86
assert
(
not
RE
()->is_reaction_under_way());
87
throw
std::runtime_error(
"Reaction methods do not support checkpointing"
);
88
}
89
};
90
91
}
/* namespace ReactionMethods */
92
}
/* namespace ScriptInterface */
93
94
#endif
ParticleHandle.hpp
ScriptInterface.hpp
ScriptInterface::AutoParameters
Bind parameters in the script interface.
Definition
AutoParameters.hpp:94
ScriptInterface::Context::parallel_try_catch
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
ScriptInterface::ObjectHandle::context
Context * context() const
Responsible context.
Definition
ObjectHandle.hpp:57
ScriptInterface::ObjectHandle::name
std::string_view name() const
Definition
ObjectHandle.cpp:117
ScriptInterface::ReactionMethods::ReactionAlgorithm
Definition
script_interface/reaction_methods/ReactionAlgorithm.hpp:40
ScriptInterface::ReactionMethods::ReactionAlgorithm::ReactionAlgorithm
ReactionAlgorithm()
Definition
script_interface/reaction_methods/ReactionAlgorithm.cpp:50
ScriptInterface::ReactionMethods::ReactionAlgorithm::do_call_method
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
Definition
script_interface/reaction_methods/ReactionAlgorithm.cpp:105
ScriptInterface::ReactionMethods::ReactionAlgorithm::calculate_factorial_expression
virtual double calculate_factorial_expression(::ReactionMethods::SingleReaction const &reaction, std::unordered_map< int, int > const &particle_numbers) const
Definition
script_interface/reaction_methods/ReactionAlgorithm.hpp:72
ScriptInterface::ReactionMethods::ReactionAlgorithm::RE
virtual std::shared_ptr<::ReactionMethods::ReactionAlgorithm > RE()=0
ScriptInterface::ReactionMethods::ReactionAlgorithm::get_internal_state
std::string get_internal_state() const override
Definition
script_interface/reaction_methods/ReactionAlgorithm.hpp:85
ScriptInterface::ReactionMethods::ReactionAlgorithm::RE
virtual std::shared_ptr<::ReactionMethods::ReactionAlgorithm > const RE() const =0
ScriptInterface::ReactionMethods::ReactionAlgorithm::get_reaction_index
int get_reaction_index(int reaction_id) const
Check reaction id is within the reaction container bounds.
Definition
script_interface/reaction_methods/ReactionAlgorithm.hpp:50
ScriptInterface::ReactionMethods::ReactionAlgorithm::m_reactions
std::vector< std::shared_ptr< SingleReaction > > m_reactions
Keep track of the script interface pointer of each reaction.
Definition
script_interface/reaction_methods/ReactionAlgorithm.hpp:43
stream
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Definition
common_cuda.cu:34
ReactionAlgorithm.hpp
utils.hpp
ReactionMethods
Definition
core/reaction_methods/ConstantpHEnsemble.hpp:26
ScriptInterface
Definition
script_interface/accumulators/AccumulatorBase.hpp:33
ScriptInterface::VariantMap
std::unordered_map< std::string, Variant > VariantMap
Definition
Variant.hpp:133
SingleReaction.hpp
params
static SteepestDescentParameters params
Currently active steepest descent instance.
Definition
steepest_descent.cpp:44
ReactionMethods::SingleReaction
Definition
core/reaction_methods/SingleReaction.hpp:30
ScriptInterface::impl::recursive_variant
Recursive variant implementation.
Definition
Variant.hpp:84
src
script_interface
reaction_methods
ReactionAlgorithm.hpp
Generated on Mon Dec 8 2025 02:32:30 for ESPResSo by
1.9.8