54 std::vector<Variant> out;
64 auto const key = get_value<std::string>(v);
65 if (key ==
"order_n") {
66 RE()->neighbor_search_order_n =
true;
67 }
else if (key ==
"parallel") {
68 RE()->neighbor_search_order_n =
false;
70 throw std::invalid_argument(
"Unknown search algorithm '" + key +
76 if (
RE()->neighbor_search_order_n) {
77 return std::string(
"order_n");
79 return std::string(
"parallel");
81 {
"particle_inside_exclusion_range_touched",
83 RE()->particle_inside_exclusion_range_touched = get_value<bool>(v);
85 [
this]() {
return RE()->particle_inside_exclusion_range_touched; }},
91 [
this]() {
return RE()->get_exclusion_range(); }},
92 {
"exclusion_radius_per_type",
95 RE()->set_exclusion_radius_per_type(
96 get_value<std::unordered_map<int, double>>(v));
101 RE()->exclusion_radius_per_type);
107 if (
name ==
"calculate_factorial_expression") {
108 if (
context()->is_head_node()) {
109 auto &bookkeeping =
RE()->get_old_system_state();
110 auto &old_particle_numbers = bookkeeping.old_particle_numbers;
111 auto &reaction = *
m_reactions[bookkeeping.reaction_id]->get_reaction();
116 if (
name ==
"get_random_reaction_index") {
117 return RE()->i_random(
static_cast<int>(
RE()->reactions.size()));
119 if (
name ==
"potential_energy") {
120 return RE()->calculate_potential_energy();
122 if (
name ==
"create_new_trial_state") {
123 auto const reaction_id = get_value<int>(
params,
"reaction_id");
126 auto const optional =
RE()->create_new_trial_state(reaction_id);
133 if (
name ==
"make_reaction_mc_move_attempt") {
134 auto const bf = get_value<double>(
params,
"bf");
135 auto const E_pot_old = get_value<double>(
params,
"E_pot_old");
136 auto const E_pot_new = get_value<double>(
params,
"E_pot_new");
137 auto const reaction_id = get_value<int>(
params,
"reaction_id");
140 result =
RE()->make_reaction_mc_move_attempt(reaction_id, bf, E_pot_old,
145 if (
name ==
"setup_bookkeeping_of_empty_pids") {
146 RE()->setup_bookkeeping_of_empty_pids();
147 }
else if (
name ==
"remove_constraint") {
148 RE()->remove_constraint();
149 }
else if (
name ==
"set_cylindrical_constraint_in_z_direction") {
151 RE()->set_cyl_constraint(get_value<double>(
params,
"center_x"),
152 get_value<double>(
params,
"center_y"),
153 get_value<double>(
params,
"radius"));
155 }
else if (
name ==
"set_wall_constraints_in_z_direction") {
157 RE()->set_slab_constraint(get_value<double>(
params,
"slab_start_z"),
158 get_value<double>(
params,
"slab_end_z"));
160 }
else if (
name ==
"get_wall_constraints_in_z_direction") {
162 return RE()->get_slab_constraint_parameters();
165 }
else if (
name ==
"set_volume") {
167 [&]() {
RE()->set_volume(get_value<double>(
params,
"volume")); });
168 }
else if (
name ==
"get_volume") {
169 return RE()->get_volume();
170 }
else if (
name ==
"get_acceptance_rate_reaction") {
171 auto const index = get_value<int>(
params,
"reaction_id");
173 if (index < 0 or index >=
static_cast<int>(
m_reactions.size())) {
174 throw std::out_of_range(
"No reaction with id " + std::to_string(index));
177 return m_reactions[index]->get_reaction()->get_acceptance_rate();
178 }
else if (
name ==
"set_non_interacting_type") {
179 auto const type = get_value<int>(
params,
"type");
182 throw std::domain_error(
"Invalid type: " + std::to_string(type));
185 RE()->non_interacting_type = type;
187 }
else if (
name ==
"get_non_interacting_type") {
188 return RE()->non_interacting_type;
189 }
else if (
name ==
"displacement_mc_move_for_particles_of_type") {
190 auto const type = get_value<int>(
params,
"type_mc");
191 auto const n_particles =
192 get_value_or<int>(
params,
"particle_number_to_be_changed", 1);
195 result =
RE()->make_displacement_mc_move_attempt(type, n_particles);
198 }
else if (
name ==
"delete_particle") {
200 [&]() {
RE()->delete_particle(get_value<int>(
params,
"p_id")); });
201 }
else if (
name ==
"delete_reaction") {
202 auto const reaction_id = get_value<int>(
params,
"reaction_id");
205 delete_reaction(index + 1);
206 delete_reaction(index + 0);
207 }
else if (
name ==
"add_reaction") {
208 auto const reaction =
209 get_value<std::shared_ptr<SingleReaction>>(
params,
"reaction");
211 RE()->add_reaction(reaction->get_reaction());
212 }
else if (
name ==
"change_reaction_constant") {
213 auto const gamma = get_value<double>(
params,
"gamma");
214 auto const reaction_id = get_value<int>(
params,
"reaction_id");
216 if (reaction_id % 2 == 1) {
217 throw std::invalid_argument(
"Only forward reactions can be selected");
220 throw std::domain_error(
"gamma needs to be a strictly positive value");
224 m_reactions[index + 0]->get_reaction()->gamma = gamma;
225 m_reactions[index + 1]->get_reaction()->gamma = 1. / gamma;
226 }
else if (
name ==
"set_charge_of_type") {
227 auto const type = get_value<int>(
params,
"type");
228 auto const charge = get_value<double>(
params,
"charge");
229 RE()->charges_of_types[type] = charge;
230 }
else if (
context()->is_head_node()) {
231 throw std::runtime_error(
"unknown method '" +
name +
"()'");
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
virtual bool is_head_node() const =0
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.
void init_type_map(int type)
Particles creation and deletion.