32#include "communication.hpp"
34#include "system/System.hpp"
41#include <boost/mpi/collectives/broadcast.hpp>
42#include <boost/mpi/collectives/reduce.hpp>
56template <
typename Archive,
typename... T>
58 std::apply([&](
auto &...
item) { ((
ar &
item), ...); }, pack);
64 using type = std::tuple<std::invoke_result_t<F, Particle const &>...>;
68 using type = std::invoke_result_t<F, Particle const &>;
76template <
class...
Trait>
78 std::vector<int>
const &
p_types,
82 for (
auto const &p :
system.cell_structure->local_particles()) {
84 buffer.emplace_back(
trait(p)...);
96 std::vector<int>
const &
set2) {
100 std::vector<Utils::Vector3d>
buf_pos{};
102 auto const &box_geo = *
system.box_geo;
104 for (
auto const &p :
system.cell_structure->local_particles()) {
107 buf_pos.emplace_back(box_geo.unfolded_position(p.pos(), p.image_box()));
118 auto mindist_sq = std::numeric_limits<double>::infinity();
128 for (
auto i =
j + 1ul; i !=
buf_type.size(); ++i) {
150 acc += p.mass() * p.v();
161 auto const &box_geo = *
system.box_geo;
162 auto const &cell_structure = *
system.cell_structure;
166 for (
auto const &p : cell_structure.local_particles()) {
168 local_com += box_geo.unfolded_position(p.pos(), p.image_box()) * p.mass();
180 auto const &box_geo = *
system.box_geo;
181 auto const &cell_structure = *
system.cell_structure;
184 for (
auto const &p : cell_structure.local_particles()) {
186 auto const pos = box_geo.unfolded_position(p.pos(), p.image_box());
194 std::vector<int>
const &
p_types) {
195 auto const &box_geo = *
system.box_geo;
197 return box_geo.unfolded_position(p.pos(), p.image_box());
205 static_cast<double>(
buf_pos.size());
207 for (
unsigned int i = 0
u; i < 3u; ++i) {
208 for (
unsigned int j = 0
u;
j < 3u; ++
j) {
212 mat[i * 3u +
j] = std::accumulate(
215 return acc + (pos[i] - center[i]) * (pos[j] - center[j]);
227 auto const &box_geo = *
system.box_geo;
228 auto const &cell_structure = *
system.cell_structure;
233 for (
auto const &p : cell_structure.local_particles()) {
235 auto const pos = box_geo.unfolded_position(p.pos(), p.image_box()) -
com;
236 auto const mass = p.mass();
237 mat[0] += mass * (pos[1] * pos[1] + pos[2] * pos[2]);
238 mat[4] += mass * (pos[0] * pos[0] + pos[2] * pos[2]);
239 mat[8] += mass * (pos[0] * pos[0] + pos[1] * pos[1]);
240 mat[1] -= mass * (pos[0] * pos[1]);
241 mat[2] -= mass * (pos[0] * pos[2]);
242 mat[5] -= mass * (pos[1] * pos[2]);
256 auto const &box_geo = *
system.box_geo;
258 for (
auto const &p :
system.cell_structure->local_particles()) {
259 auto const r_sq = box_geo.get_mi_vector(pos, p.pos()).norm2();
273std::vector<std::vector<double>>
279 auto const &box_geo = *
system.box_geo;
282 return box_geo.unfolded_position(p.pos(), p.image_box());
299 for (
auto const &[
pid1, pos1] :
buf1) {
302 for (
auto const &[
pid2, pos2] :
buf2) {
304 auto const act_dist2 = box_geo.get_mi_vector(pos1, pos2).norm2();
312 auto const min_dist = std::sqrt(
min_dist2);
314 auto const ind =
static_cast<int>(
329 low /=
static_cast<double>(
cnt);
330 for (
int i = 0; i <
r_bins; i++) {
337 for (
int i = 0; i <
r_bins - 1; i++)
342 std::vector<double> radii(
r_bins);
346 for (
int i = 1; i <
r_bins; ++i) {
347 radii[i] = radii[i - 1] *
log_fac;
351 for (
int i = 0; i <
r_bins; ++i) {
359std::vector<std::vector<double>>
362 auto const &box_geo = *
system.box_geo;
364 return box_geo.unfolded_position(p.pos(), p.image_box());
368 auto const twoPI_L = 2. * std::numbers::pi *
system.box_geo->length_inv()[0];
374 for (
int i = 0; i <=
order; i++) {
377 auto const n = i * i +
j *
j + k * k;
378 if ((
static_cast<std::size_t
>(n) <=
order_sq) && (n >= 1)) {
380 for (
auto const &pos :
buf_pos) {
392 std::size_t length = 0;
394 if (
ff[2 *
qi + 1] != 0) {
404 for (std::size_t i = 0; i <
order_sq; i++) {
405 if (
ff[2 * i + 1] != 0) {
Vector implementation and trait types for boost qvm interoperability.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
boost::mpi::communicator comm_cart
The communicator.
__device__ void vector_product(float const *a, float const *b, float *out)
void gather_buffer(std::vector< T, Allocator > &buffer, boost::mpi::communicator const &comm, int root=0)
Gather buffer with different size on each node.
DEVICE_QUALIFIER constexpr T sqr(T x)
Calculates the SQuaRe of x.
bool contains(Range &&rng, T const &value)
Check whether a range contains a value.
void serialize(Archive &ar, std::tuple< T... > &pack, unsigned int const)
Serialize std::tuple.
Utils::Vector3d center_of_mass(System::System const &system, int p_type)
Calculate the center of mass of particles of a certain type.
Utils::Vector3d angular_momentum(System::System const &system, int p_type)
Calculate the angular momentum of particles of a certain type.
std::vector< int > nbhood(System::System const &system, Utils::Vector3d const &pos, double dist)
Find all particles within a given radius dist around a position pos.
Utils::Vector9d moment_of_inertia_matrix(System::System const &system, int p_type)
Calculate the moment of inertia of particles of a certain type.
Utils::Vector9d gyration_tensor(System::System const &system, std::vector< int > const &p_types)
Calculate the gyration tensor of particles of certain types.
Utils::Vector3d calc_linear_momentum(System::System const &system, bool include_particles, bool include_lbfluid)
Calculate total momentum of the system (particles & LB fluid).
std::vector< std::vector< double > > structure_factor(System::System const &system, std::vector< int > const &p_types, int order)
Calculate the spherically averaged structure factor.
double mindist(System::System const &system, std::vector< int > const &set1, std::vector< int > const &set2)
Calculate the minimal distance of two particles with types in set1 and set2, respectively.
static auto gather_traits_for_types(System::System const &system, std::vector< int > const &p_types, Trait &&...trait)
Gather particle traits to MPI rank 0.
std::vector< std::vector< double > > calc_part_distribution(System::System const &system, std::vector< int > const &p1_types, std::vector< int > const &p2_types, double r_min, double r_max, int r_bins, bool log_flag, bool int_flag)
Calculate the distribution of particles around others.
Statistical tools to analyze simulations.
std::invoke_result_t< F, Particle const & > type
Decay a tuple of only 1 type to that type.
std::tuple< std::invoke_result_t< F, Particle const & >... > type
Struct holding all information for one particle.