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
27
30
31#include <memory>
32#include <stdexcept>
33#include <string>
34#include <unordered_map>
35#include <vector>
36
37namespace ScriptInterface {
38namespace ReactionMethods {
39
40class ReactionAlgorithm : public AutoParameters<ReactionAlgorithm> {
41protected:
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;
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
61public:
62 virtual std::shared_ptr<::ReactionMethods::ReactionAlgorithm> RE() = 0;
63 virtual std::shared_ptr<::ReactionMethods::ReactionAlgorithm> const
64 RE() const = 0;
65
67
68 Variant do_call_method(std::string const &name,
69 VariantMap const &params) override;
70
71protected:
74 std::unordered_map<int, int> const &particle_numbers) const {
75 return ::ReactionMethods::calculate_factorial_expression(reaction,
76 particle_numbers);
77 }
78
79private:
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
Bind parameters in the script interface.
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
boost::string_ref name() const
Context * context() const
Responsible context.
Variant do_call_method(std::string const &name, VariantMap const &params) override
virtual double calculate_factorial_expression(::ReactionMethods::SingleReaction const &reaction, std::unordered_map< int, int > const &particle_numbers) const
virtual std::shared_ptr<::ReactionMethods::ReactionAlgorithm > RE()=0
virtual std::shared_ptr<::ReactionMethods::ReactionAlgorithm > const RE() const =0
int get_reaction_index(int reaction_id) const
Check reaction id is within the reaction container bounds.
std::vector< std::shared_ptr< SingleReaction > > m_reactions
Keep track of the script interface pointer of each reaction.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:67
static SteepestDescentParameters params
Currently active steepest descent instance.