ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/reaction_methods/ExclusionRadius.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023-2026 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#pragma once
21
24
26
27#include <memory>
28#include <stdexcept>
29#include <string>
30
31namespace ScriptInterface {
32namespace ReactionMethods {
33
34class ExclusionRadius : public AutoParameters<ExclusionRadius> {
35 std::shared_ptr<::ExclusionRadius> m_obj;
36
37public:
39 add_parameters({{"search_algorithm",
40 [this](Variant const &v) {
42 auto const key = get_value<std::string>(v);
43 if (key == "order_n") {
44 m_obj->neighbor_search_order_n = true;
45 } else if (key == "parallel") {
46 m_obj->neighbor_search_order_n = false;
47 } else {
48 throw std::invalid_argument(
49 "Unknown search algorithm '" + key + "'");
50 }
51 });
52 },
53 [this]() {
54 if (m_obj->neighbor_search_order_n) {
55 return std::string("order_n");
56 }
57 return std::string("parallel");
58 }},
59 {"exclusion_range",
60 [this](Variant const &v) {
62 m_obj->set_exclusion_range(get_value<double>(v));
63 });
64 },
65 [this]() { return m_obj->exclusion_range; }},
66 {"exclusion_radius_per_type",
67 [this](Variant const &v) {
69 m_obj->set_exclusion_radius_per_type(
71 });
72 },
73 [this]() {
75 m_obj->exclusion_radius_per_type);
76 }}});
77 }
78
79 void do_construct(VariantMap const &params) override {
81 m_obj = std::make_shared<::ExclusionRadius>(context()->get_comm());
82 });
83 do_set_parameter("exclusion_range", params.at("exclusion_range"));
84 if (params.contains("search_algorithm")) {
85 do_set_parameter("search_algorithm", params.at("search_algorithm"));
86 }
87 if (params.contains("exclusion_radius_per_type")) {
88 do_set_parameter("exclusion_radius_per_type",
89 params.at("exclusion_radius_per_type"));
90 }
91 }
92
93 Variant do_call_method(std::string const &name,
94 VariantMap const &params) override {
95 if (name == "check_exclusion_range") {
96 assert(not params.contains("type"));
97 auto const pid = get_value<int>(params, "pid");
98 if (params.contains("ptype")) {
99 auto const ptype = get_value<int>(params, "ptype");
100 return m_obj->check_exclusion_range(pid, ptype);
101 }
102 return m_obj->check_exclusion_range(pid);
103 }
104 if (name == "check_exclusion_range_any") {
105 auto const pids = get_value<std::vector<int>>(params, "pids");
106 auto const ptype = get_value<int>(params, "ptype");
107 auto touched = false;
108 for (auto pid : pids) {
109 touched |= m_obj->check_exclusion_range(pid, ptype);
110 }
111 return touched;
112 }
113 return {};
114 }
115
116 auto get_instance() const { return m_obj; }
117};
118
119} // namespace ReactionMethods
120} // namespace ScriptInterface
Bind parameters in the script interface.
void do_set_parameter(const std::string &name, const Variant &value) final
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Context * context() const
Responsible context.
std::string_view name() const
Variant do_call_method(std::string const &name, VariantMap const &params) override
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:133
auto make_unordered_map_of_variants(std::unordered_map< K, V > const &v)
Definition Variant.hpp:144
Recursive variant implementation.
Definition Variant.hpp:84