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'");
97 throw std::invalid_argument(error_msg +
reason.str());
109 []() { return ::communicator.node_grid; }},
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();
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();
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") {
176 if (
name ==
"resort") {
180 if (
name ==
"get_state") {
184 auto const rd = get_regular_decomposition();
188 auto const hd = get_hybrid_decomposition();
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;
208 if (boost::get<std::string>(&
params.at(
"types")) !=
nullptr) {
211 throw std::invalid_argument(
"Unknown argument types='" +
key +
"'");
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") {
230 auto &
system = get_system();
231 system.on_observable_calc();
242 std::vector<int> neighbors;
251 if (name ==
"non_bonded_loop_trace") {
253 system.on_observable_calc();
254 std::vector<Variant>
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") {
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.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
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