40#include <boost/mpi/collectives/all_reduce.hpp>
49#include <unordered_map>
60 throw std::domain_error(
"Chain analysis needs at least 1 chain");
63 throw std::domain_error(
"Chain analysis needs at least 1 bead per chain");
71 if (ptr !=
nullptr and not ptr->is_ghost()) {
84 if (ptr !=
nullptr and not ptr->is_ghost()) {
90 std::stringstream error_msg;
91 error_msg <<
"Particle with id " << pid <<
" does not exist; "
92 <<
"cannot perform analysis on the range chain_start="
95 <<
"Please provide a contiguous range of particle ids.";
96 throw std::runtime_error(error_msg.str());
108void Analysis::check_particle_type(
int p_type)
const {
109 auto const &nonbonded_ias =
get_system().nonbonded_ias;
111 std::stringstream error_msg;
112 error_msg <<
"Particle type " <<
p_type <<
" does not exist";
113 throw std::invalid_argument(error_msg.str());
119 if (
name ==
"linear_momentum") {
125 if (
name ==
"particle_energy") {
128 auto const local =
system.particle_short_range_energy_contribution(pid);
131 if (
name ==
"particle_bond_energy") {
136 auto const local =
system.particle_bond_energy(pid, bond_id,
partners);
139 if (
name ==
"potential_energy") {
141 return obs.accumulate(-(
obs.kinetic_lin[0] +
obs.kinetic_rot[0]));
143 if (
name ==
"particle_neighbor_pids") {
145 system.on_observable_calc();
146 std::unordered_map<int, std::vector<int>>
dict;
150 std::ranges::for_each(neighbor_pids, [&
dict](
auto const &
nbhood) {
157 if (
name ==
"dpd_pressure") {
159 return result.as_vector();
162 if (
name ==
"min_dist") {
173 if (
name ==
"center_of_mass") {
179 check_particle_type(
p_type);
186 if (
name ==
"angular_momentum") {
195 if (
name ==
"nbhood") {
201 if (
name ==
"calc_re") {
208 return std::vector<double>(result.begin(), result.end());
210 if (
name ==
"calc_rg") {
219 output =
Variant{std::vector<double>(result.begin(), result.end())};
223 if (
name ==
"calc_rh") {
231 throw std::domain_error(
232 "Hydrodynamic radius is undefined for chains shorter than 2 beads");
236 return std::vector<double>(result.begin(), result.end());
238 if (
name ==
"gyration_tensor") {
243 check_particle_type(
p_type);
246 result = std::vector<double>(
mat.begin(),
mat.end());
250 if (
name ==
"moment_of_inertia_matrix") {
254 check_particle_type(
p_type);
260 if (
name ==
"structure_factor") {
265 throw std::domain_error(
"order has to be a strictly positive number");
273 if (
name ==
"distribution") {
284 throw std::domain_error(
"Parameter 'r_min' must be > 0");
287 throw std::domain_error(
"Parameter 'r_min' must be >= 0");
290 throw std::domain_error(
"Parameter 'r_max' must be > 'r_min'");
293 throw std::domain_error(
"Parameter 'r_max' must be <= box_l / 2");
296 throw std::domain_error(
"Parameter 'r_bins' must be >= 1");
313 if (
name ==
"calculate_energy") {
314 return m_obs_stat->do_call_method(
"calculate_energy", {});
316 if (
name ==
"calculate_scalar_pressure") {
317 return m_obs_stat->do_call_method(
"calculate_scalar_pressure", {});
319 if (
name ==
"calculate_pressure_tensor") {
320 return m_obs_stat->do_call_method(
"calculate_pressure_tensor", {});
322 if (
name ==
"_observable_stat_test_fallthrough") {
324 return m_obs_stat->do_call_method(
"unknown", {});
327 if (
name ==
"get_instantaneous_pressure") {
328 return get_system().npt_inst_pressure->p_inst[0];
330 if (
name ==
"get_instantaneous_pressure_virial") {
331 return get_system().npt_inst_pressure->p_inst[1];
Vector implementation and trait types for boost qvm interoperability.
std::vector< NeighborPIDs > get_neighbor_pids(System::System const &system)
Returns pairs of particle ids and neighbor particle id lists.
This file contains everything related to the global cell structure / cell system.
Describes a cell structure / cell system.
Particle * get_local_particle(int id)
Get a local particle by id.
Variant do_call_method(std::string const &name, VariantMap const ¶meters) override
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Context * context() const
Responsible context.
std::string_view name() const
auto const & get_system() const
boost::mpi::communicator comm_cart
The communicator.
This file contains the asynchronous MPI communication.
Utils::Vector9d dpd_pressure(System::System &system, boost::mpi::communicator const &comm)
Pressure tensor contribution of the DPD interaction.
Routines to use DPD as thermostat or pair force .
static void check_topology(CellStructure const &cell_structure, int chain_start, int chain_length, int n_chains)
Check if a contiguous range of particle ids exists.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
auto make_unordered_map_of_variants(std::unordered_map< K, V > const &v)
T mpi_reduce_sum(boost::mpi::communicator const &comm, T const &result)
Reduce object by sum on the head node.
auto make_vector_of_variants(std::vector< T > const &v)
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 reduce_optional(boost::mpi::communicator const &comm, std::optional< T > const &result)
Reduce an optional on the head node.
Various procedures concerning interactions between particles.
Exports for the NpT code.
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.
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::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.
Recursive variant implementation.