ppap4lmp  0.7.2
pro_mean_square_displacement.cpp
Go to the documentation of this file.
1 
10 #include "../utils/runtime_error.h"
11 
12 namespace ut = utils;
13 
14 /* ------------------------------------------------------------------ */
15 
17  const Vec<ElPtr> &elems)
18 {
19  register_generators(elems);
20 }
21 
22 /* ------------------------------------------------------------------ */
23 
25  ArrayXXd &positions,
26  const ElPtr &elem)
27 {
28  // NOTE: `id` property is check_required_keys to ensure data is sorted.
29  elem->check_required_keys({"xu", "yu", "zu", "id"});
30 
31  elem->make_2darray_from_data(positions, {"xu", "yu", "zu"});
32 
33  if (drift_correction)
34  {
35  elem->check_required_keys("mass");
36 
37  ArrayXd ms;
38  elem->make_1darray_from_data(ms, "mass");
39 
40  auto com = (positions.colwise()*ms).colwise().sum() / ms.sum();
41 
42  positions.rowwise() -= com;
43  }
44 }
45 
46 /* ------------------------------------------------------------------ */
47 
49  const int index)
50 {
51  ArrayXXd rs;
52  extract_positions(rs, generators[index]->get_element());
53 
54  auto displacement2_xyz = (rs - initial_rs).square();
55 
56  ArrayXd displacement2 = ArrayXd::Zero(displacement2_xyz.rows());
57 
58  for (int i = 0; i != 3; ++i)
59  {
60  if (dimension[i])
61  {
62  displacement2 += displacement2_xyz.col(i);
63  }
64  }
65 
66  displacement2_traj[index] = displacement2.transpose();
67 }
68 
69 /* ------------------------------------------------------------------ */
70 
72 {
74 
75  extract_positions(initial_rs, generators.front()->get_element());
76 
78 }
79 
80 /* ------------------------------------------------------------------ */
81 
83 {
84  const auto n_points = displacement2_traj.front().size();
85 
86  for (const auto &sd : displacement2_traj)
87  {
88  if (n_points != sd.size())
89  {
90  ut::runtime_error("Data sizes must be the same");
91  }
92  }
93 
95 
96  for (int i = 0; i != n_generators; ++i)
97  {
99  }
100 
102 
103  displacement2_traj.clear();
104  displacement2_traj.shrink_to_fit();
105 }
106 
107 /* ------------------------------------------------------------------ */
108 
110  bool include_x,
111  bool include_y,
112  bool include_z)
113 {
114  dimension = {include_x, include_y, include_z};
115 }
116 
117 /* ------------------------------------------------------------------ */
118 
120  bool without_drift_correction_)
121 {
122  drift_correction = !without_drift_correction_;
123 }
124 
125 /* ------------------------------------------------------------------ */
126 
128 {
129  return displacement2_array;
130 }
131 
132 /* ------------------------------------------------------------------ */
133 
135 {
137 }
virtual void run_impl(const int index) override
Implementation of analysis using an element of generators.
void without_drift_correction(bool without_drift_correction_=true)
Disable to correct a drift of center of mass of the simulation system.
Vec< ShPtr< Generator > > generators
Definition: processor.h:37
void extract_positions(ArrayXXd &positions, const ElPtr &elem)
Extract position vectors from an Element object.
ShPtr< Element > ElPtr
An alias for a shared pointer of Element class.
Definition: element.h:378
virtual void use_generator_at(const int i)
Call Generator::generate_data of i th Generator object in generators.
Definition: processor.cpp:58
ProMeanSquareDisplacement(const Vec< ElPtr > &elems)
Constructor of ProMeanSquareDisplacement class.
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ArrayXXd
ArrayXXd is an alias for a two-dimensional array of float numbers.
Definition: eigen.h:32
const ArrayXd & get_mean_square_displacement()
Get time series of the mean square displacement as a one-dimensional array. Each element of the array...
int n_generators
Definition: processor.h:31
virtual void finish() override
Fill displacement2_array with values of displacement2_traj, and calculate mean_square_displacement by...
This file has a definition of ProMeanSquareDisplacement class, which is a subclass of Processor class...
std::vector< T > Vec
Vec is an alias for vector (same as list in Python).
Definition: std.h:27
void runtime_error(const Str &msg)
Raise (for Python) and throw (for C++) a runtime error.
void set_dimension(bool include_x, bool include_y, bool include_z)
Specify dimensions to be considered. By default, the mean square displacement is computed in three di...
Namespace for utility functions.
Definition: join.h:14
Eigen::Array< double, Eigen::Dynamic, 1 > ArrayXd
ArrayXd is an alias for a column array of float numbers.
Definition: eigen.h:42
const ArrayXXd & get_displacement2_array()
Get computed time series of squared displacements from initial position for each target as a two-dime...
void register_generators(const Vec< ShPtr< GEN >> &gens)
Definition: processor.cpp:36
virtual void prepare() override
Set initial positions and resize displacement2_traj.