30#include "communication.hpp"
31#include "system/System.hpp"
37#include <boost/mpi/collectives/all_reduce.hpp>
43#include <unordered_map>
52 std::vector<int> buffer_pid{};
53 std::vector<T> buffer_obs{};
61 if (ptr !=
nullptr and not ptr->is_ghost()) {
62 buffer_pid.emplace_back(pid);
63 buffer_obs.emplace_back(
kernel(*ptr));
68 std::unordered_map<int, T> map{};
72 for (std::size_t i = 0u; i < buffer_pid.size(); ++i) {
73 map[buffer_pid[i]] = buffer_obs[i];
106 int chain_length,
int n_chains) {
109 double dist = 0.0, dist2 = 0.0, dist4 = 0.0;
110 std::array<double, 4> re{};
112 for (
int i = 0; i < n_chains; i++) {
113 auto const pid2 = chain_start + i * chain_length;
114 auto const pid1 = pid2 + chain_length - 1;
115 prefetch.fetch(cell_structure, pid1);
116 prefetch.fetch(cell_structure, pid2);
118 auto const map = prefetch.join();
120 for (
int i = 0; i < n_chains; i++) {
121 auto const pid2 = chain_start + i * chain_length;
122 auto const pid1 = pid2 + chain_length - 1;
123 auto const norm2 = (map.at(pid1) - map.at(pid2)).norm2();
126 dist4 += norm2 * norm2;
128 auto const tmp =
static_cast<double>(n_chains);
131 re[1] = (n_chains == 1) ? 0. : std::sqrt(re[2] -
Utils::sqr(re[0]));
132 re[3] = (n_chains == 1) ? 0. : std::sqrt(dist4 / tmp -
Utils::sqr(re[2]));
138 int chain_length,
int n_chains) {
143 double r_G = 0.0, r_G2 = 0.0, r_G4 = 0.0;
144 std::array<double, 4> rg{};
146 auto has_virtual =
false;
147 for (
int i = 0; i < n_chains * chain_length; ++i) {
148 auto const pid = chain_start + i;
149 auto const ptr = cell_structure.get_local_particle(pid);
150 if (ptr !=
nullptr and not ptr->is_ghost() and ptr->is_virtual()) {
155 if (boost::mpi::all_reduce(
::comm_cart, has_virtual, std::logical_or<>{})) {
156 throw std::runtime_error(
157 "Center of mass is not well-defined for chains including virtual "
158 "sites. Virtual sites do not have a meaningful mass.");
161 for (
int i = 0; i < n_chains * chain_length; ++i) {
162 auto const pid = chain_start + i;
163 prefetch_com.fetch(cell_structure, pid);
164 prefetch_pos.fetch(cell_structure, pid);
165 prefetch_mass.fetch(cell_structure, pid);
168 auto const map_pos = prefetch_pos.join();
169 auto const map_com = prefetch_com.join();
170 auto const map_mass = prefetch_mass.join();
172 for (
int i = 0; i < n_chains; i++) {
175 for (
int j = 0; j < chain_length; j++) {
176 auto const pid = chain_start + i * chain_length + j;
177 r_CM += map_com.
at(pid);
178 M += map_mass.at(pid);
182 for (
int j = 0; j < chain_length; ++j) {
183 auto const pid = chain_start + i * chain_length + j;
184 auto const d = map_pos.at(pid) - r_CM;
187 tmp /=
static_cast<double>(chain_length);
192 auto const tmp =
static_cast<double>(n_chains);
195 rg[1] = (n_chains == 1) ? 0. : std::sqrt(rg[2] -
Utils::sqr(rg[0]));
196 rg[3] = (n_chains == 1) ? 0. : std::sqrt(r_G4 / tmp -
Utils::sqr(rg[2]));
202 int chain_length,
int n_chains) {
205 double r_H = 0.0, r_H2 = 0.0;
206 std::array<double, 2> rh{};
208 auto const chain_l =
static_cast<double>(chain_length);
209 auto const prefac = 0.5 * chain_l * (chain_l - 1.);
210 for (
int p = 0; p < n_chains; p++) {
211 for (
int i = chain_start + chain_length * p;
212 i < chain_start + chain_length * (p + 1); i++) {
213 prefetch.fetch(cell_structure, i);
214 for (
int j = i + 1; j < chain_start + chain_length * (p + 1); j++) {
215 prefetch.fetch(cell_structure, j);
219 auto const map = prefetch.join();
221 for (
int p = 0; p < n_chains; p++) {
223 for (
int i = chain_start + chain_length * p;
224 i < chain_start + chain_length * (p + 1); i++) {
225 for (
int j = i + 1; j < chain_start + chain_length * (p + 1); j++) {
226 ri += 1.0 / (map.at(i) - map.at(j)).norm();
229 auto const tmp = prefac / ri;
233 auto const tmp =
static_cast<double>(n_chains);
235 rh[1] = (n_chains == 1) ? 0. : std::sqrt(r_H2 / tmp -
Utils::sqr(rh[0]));
Vector implementation and trait types for boost qvm interoperability.
auto unfolded_position(Utils::Vector3d const &pos, Utils::Vector3i const &image_box) const
Unfold particle coordinates to image box.
Describes a cell structure / cell system.
Particle * get_local_particle(int id)
Get a local particle by id.
std::shared_ptr< CellStructure > cell_structure
std::shared_ptr< BoxGeometry > box_geo
DEVICE_QUALIFIER constexpr reference at(size_type i)
boost::mpi::communicator comm_cart
The communicator.
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.
std::array< double, 4 > calc_rg(System::System const &system, int chain_start, int chain_length, int n_chains)
Calculate the radius of gyration.
std::array< double, 2 > calc_rh(System::System const &system, int chain_start, int chain_length, int n_chains)
Calculate the hydrodynamic radius (ref.
std::array< double, 4 > calc_re(System::System const &system, int chain_start, int chain_length, int n_chains)
Calculate the end-to-end-distance.
This file contains the code for statistics on chains.
GatherCom(BoxGeometry const &box_geo)
BoxGeometry const & m_box_geo
Utils::Vector3d kernel(Particle const &p) const override
~GatherCom() override=default
~GatherMass() override=default
double kernel(Particle const &p) const override
Gather particle properties (or any derived quantities) on MPI rank 0.
virtual T kernel(Particle const &) const =0
void fetch(CellStructure const &cell_structure, int pid)
virtual ~GatherParticleTraits()=default
BoxGeometry const & m_box_geo
Utils::Vector3d kernel(Particle const &p) const override
~GatherPos() override=default
GatherPos(BoxGeometry const &box_geo)
Struct holding all information for one particle.
auto const & mass() const
auto const & image_box() const