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
22
#include "
script_interface/ScriptInterface.hpp
"
23
#include "
script_interface/auto_parameters/AutoParameters.hpp
"
24
25
#include "
core/ExclusionRadius.hpp
"
26
27
#include <memory>
28
#include <stdexcept>
29
#include <string>
30
31
namespace
ScriptInterface
{
32
namespace
ReactionMethods {
33
34
class
ExclusionRadius
:
public
AutoParameters
<ExclusionRadius> {
35
std::shared_ptr<::ExclusionRadius> m_obj;
36
37
public
:
38
ExclusionRadius
() {
39
add_parameters
({{
"search_algorithm"
,
40
[
this
](
Variant
const
&v) {
41
context
()->
parallel_try_catch
([&]() {
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) {
61
context
()->
parallel_try_catch
([&]() {
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) {
68
context
()->
parallel_try_catch
([&]() {
69
m_obj->set_exclusion_radius_per_type(
70
get_value<::ExclusionRadius::map_type>
(v));
71
});
72
},
73
[
this
]() {
74
return
make_unordered_map_of_variants
(
75
m_obj->exclusion_radius_per_type);
76
}}});
77
}
78
79
void
do_construct
(
VariantMap
const
¶ms)
override
{
80
context
()->
parallel_try_catch
([&]() {
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
¶ms)
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
AutoParameters.hpp
ScriptInterface.hpp
ScriptInterface::AutoParameters
Bind parameters in the script interface.
Definition
AutoParameters.hpp:94
ScriptInterface::AutoParameters< ExclusionRadius >::do_set_parameter
void do_set_parameter(const std::string &name, const Variant &value) final
Definition
AutoParameters.hpp:154
ScriptInterface::AutoParameters< ExclusionRadius >::add_parameters
void add_parameters(std::vector< AutoParameter > &¶ms)
Definition
AutoParameters.hpp:123
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::ExclusionRadius
Definition
script_interface/reaction_methods/ExclusionRadius.hpp:34
ScriptInterface::ReactionMethods::ExclusionRadius::do_call_method
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
Definition
script_interface/reaction_methods/ExclusionRadius.hpp:93
ScriptInterface::ReactionMethods::ExclusionRadius::do_construct
void do_construct(VariantMap const ¶ms) override
Definition
script_interface/reaction_methods/ExclusionRadius.hpp:79
ScriptInterface::ReactionMethods::ExclusionRadius::ExclusionRadius
ExclusionRadius()
Definition
script_interface/reaction_methods/ExclusionRadius.hpp:38
ScriptInterface::ReactionMethods::ExclusionRadius::get_instance
auto get_instance() const
Definition
script_interface/reaction_methods/ExclusionRadius.hpp:116
ExclusionRadius.hpp
ScriptInterface
Definition
script_interface/accumulators/AccumulatorBase.hpp:34
ScriptInterface::get_value
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
Definition
get_value.hpp:398
ScriptInterface::VariantMap
std::unordered_map< std::string, Variant > VariantMap
Definition
Variant.hpp:133
ScriptInterface::make_unordered_map_of_variants
auto make_unordered_map_of_variants(std::unordered_map< K, V > const &v)
Definition
Variant.hpp:144
ScriptInterface::impl::recursive_variant
Recursive variant implementation.
Definition
Variant.hpp:84
src
script_interface
reaction_methods
ExclusionRadius.hpp
Generated on Mon Sep 7 2026 01:24:52 for ESPResSo by
1.9.8