41#include <boost/mpi/collectives/gather.hpp>
42#include <boost/variant.hpp>
52#include <unordered_map>
56static int coord(std::string
const &s) {
63 throw std::invalid_argument(
"Invalid Cartesian coordinate: '" + s +
"'");
88 auto const error_msg = std::string(
"Parameter 'node_grid'");
90 auto const new_node_grid = get_value<Utils::Vector3i>(v);
93 if (n_nodes_new != n_nodes_old) {
94 std::stringstream reason;
95 reason <<
": MPI world size " << n_nodes_old <<
" incompatible "
96 <<
"with new node grid [" << new_node_grid <<
"]";
97 throw std::invalid_argument(error_msg + reason.str());
109 []() { return ::communicator.node_grid; }},
112 auto const new_skin = get_value<double>(v);
114 if (
context()->is_head_node()) {
115 throw std::domain_error(
"Parameter 'skin' must be >= 0");
132 auto const hd = get_hybrid_decomposition();
133 auto const ns_types = hd.get_n_square_types();
134 return Variant{std::vector<int>(ns_types.begin(), ns_types.end())};
142 auto const rd = get_regular_decomposition();
143 auto const fcb = rd.fully_connected_boundary();
146 return Variant{std::unordered_map<std::string, Variant>{
156 auto const hd = get_hybrid_decomposition();
157 return Variant{hd.get_cutoff_regular()};
160 [
this]() {
return get_system().nonbonded_ias->maximal_cutoff(); }},
162 [
this]() {
return get_system().bonded_ias->maximal_cutoff(); }},
164 [
this]() {
return get_system().get_interaction_range(); }},
170 if (
name ==
"initialize") {
171 auto const cs_name = get_value<std::string>(
params,
"name");
172 auto const cs_type = cs_name_to_type.at(cs_name);
173 initialize(cs_type,
params);
176 if (
name ==
"resort") {
177 auto const global_flag = get_value_or<bool>(
params,
"global_flag",
true);
178 return mpi_resort_particles(global_flag);
180 if (
name ==
"get_state") {
184 auto const rd = get_regular_decomposition();
185 state[
"cell_grid"] =
Variant{rd.cell_grid};
186 state[
"cell_size"] =
Variant{rd.cell_size};
188 auto const hd = get_hybrid_decomposition();
189 state[
"cell_grid"] =
Variant{hd.get_cell_grid()};
190 state[
"cell_size"] =
Variant{hd.get_cell_size()};
191 mpi_resort_particles(
true);
192 state[
"parts_per_decomposition"] =
193 Variant{std::unordered_map<std::string, Variant>{
194 {
"regular", hd.count_particles_in_regular()},
195 {
"n_square", hd.count_particles_in_n_square()}}};
201 if (
name ==
"get_pairs") {
202 std::vector<Variant> out;
205 system.on_observable_calc();
206 std::vector<std::pair<int, int>> pair_list;
207 auto const distance = get_value<double>(
params,
"distance");
208 if (boost::get<std::string>(&
params.at(
"types")) !=
nullptr) {
209 auto const key = get_value<std::string>(
params,
"types");
211 throw std::invalid_argument(
"Unknown argument types='" + key +
"'");
215 auto const types = get_value<std::vector<int>>(
params,
"types");
219 std::transform(pair_list.begin(), pair_list.end(),
220 std::back_inserter(out),
221 [](std::pair<int, int>
const &pair) {
222 return std::vector<int>{pair.first, pair.second};
227 if (name ==
"get_neighbors") {
228 std::vector<std::vector<int>> neighbors_global;
229 context()->parallel_try_catch([
this, &neighbors_global, &
params]() {
230 auto &system = get_system();
231 system.on_observable_calc();
232 auto const dist = get_value<double>(
params,
"distance");
233 auto const pid = get_value<int>(
params,
"pid");
235 std::vector<int> neighbors_local;
237 neighbors_local = *ret;
239 boost::mpi::gather(context()->get_comm(), neighbors_local,
240 neighbors_global, 0);
242 std::vector<int> neighbors;
243 for (
auto const &neighbors_local : neighbors_global) {
244 if (not neighbors_local.empty()) {
245 neighbors = neighbors_local;
251 if (name ==
"non_bonded_loop_trace") {
253 system.on_observable_calc();
254 std::vector<Variant> out;
258 std::transform(pair_list.begin(), pair_list.end(), std::back_inserter(out),
260 return std::vector<Variant>{pair.id1, pair.id2,
261 pair.pos1, pair.pos2,
262 pair.vec21, pair.node};
266 if (name ==
"tune_skin") {
268 system.tune_verlet_skin(
269 get_value<double>(
params,
"min_skin"),
270 get_value<double>(
params,
"max_skin"), get_value<double>(
params,
"tol"),
271 get_value<int>(
params,
"int_steps"),
272 get_value_or<bool>(
params,
"adjust_max_skin",
false));
275 if (name ==
"get_max_range") {
281std::vector<int> CellSystem::mpi_resort_particles(
bool global_flag)
const {
283 cell_structure.resort_particles(global_flag);
285 auto const size =
static_cast<int>(cell_structure.local_particles().size());
286 std::vector<int> n_part_per_node;
287 boost::mpi::gather(context()->get_comm(), size, n_part_per_node, 0);
288 return n_part_per_node;
292 VariantMap
const &
params) {
293 auto const verlet = get_value_or<bool>(
params,
"use_verlet_lists",
true);
295 m_cell_structure->use_verlet_list = verlet;
297 auto const cutoff_regular = get_value<double>(
params,
"cutoff_regular");
298 auto const ns_types =
299 get_value_or<std::vector<int>>(
params,
"n_square_types", {});
300 auto n_square_types = std::set<int>{ns_types.begin(), ns_types.end()};
301 m_cell_structure->set_hybrid_decomposition(cutoff_regular, n_square_types);
303 std::optional<std::pair<int, int>> fcb_pair = std::nullopt;
304 if (
params.contains(
"fully_connected_boundary") and
307 get_value<VariantMap>(
params,
"fully_connected_boundary");
308 context()->parallel_try_catch([&fcb_pair, &variant]() {
309 fcb_pair = {{
coord(boost::get<std::string>(variant.at(
"boundary"))),
310 coord(boost::get<std::string>(variant.at(
"direction")))}};
313 context()->parallel_try_catch([
this, &fcb_pair]() {
314 m_cell_structure->set_regular_decomposition(
315 get_system().get_interaction_range(), fcb_pair);
318 system.set_cell_structure_topology(cs_type);
323 particle.
attach(m_system);
CellStructureType
Cell structure topology.
@ HYBRID
Hybrid decomposition.
@ REGULAR
Regular decomposition.
static int coord(std::string const &s)
static std::string coord_letter(int c)
Vector implementation and trait types for boost qvm interoperability.
Data structures for bonded interactions.
std::optional< std::vector< int > > get_short_range_neighbors(System::System const &system, int const pid, double const distance)
Get ids of particles that are within a certain distance of another particle.
std::vector< PairInfo > non_bonded_loop_trace(System::System const &system, int const rank)
Returns pairs of particle ids, positions and distance as seen by the non-bonded loop.
std::vector< std::pair< int, int > > get_pairs_of_types(System::System const &system, double const distance, std::vector< int > const &types)
Get pairs closer than distance if both their types are in types.
std::vector< std::pair< int, int > > get_pairs(System::System const &system, double const distance)
Get pairs closer than distance from the cells.
This file contains everything related to the global cell structure / cell system.
void add_parameters(std::vector< AutoParameter > &¶ms)
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
auto & get_cell_structure() const
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
virtual boost::mpi::communicator const & get_comm() const =0
VariantMap get_parameters() const
Get current parameters.
boost::string_ref name() const
Context * context() const
Responsible context.
void attach(std::weak_ptr<::System::System > system)
void attach(std::weak_ptr<::System::System > system)
auto const & get_system() const
Communicator communicator
This file contains the asynchronous MPI communication.
std::unordered_map< std::string, Variant > VariantMap
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.
bool is_none(Variant const &v)
constexpr const None none
None-"literal".
void gather_buffer(std::vector< T, Allocator > &buffer, boost::mpi::communicator const &comm, int root=0)
Gather buffer with different size on each node.
T product(Vector< T, N > const &v)
Various procedures concerning interactions between particles.
static auto & get_cell_structure()
void clear_particle_node()
Invalidate particle_node.
Particles creation and deletion.
static SteepestDescentParameters params
Currently active steepest descent instance.
Utils::Vector3i node_grid
void set_node_grid(Utils::Vector3i const &value)
Set new Cartesian topology.
static constexpr const ReadOnly read_only