ppap4lmp  0.7.2
add_wrapped_position.cpp
Go to the documentation of this file.
1 
9 #include "add_wrapped_position.h"
10 
11 /* ------------------------------------------------------------------ */
12 
14  const ElPtr &elem)
15 {
16  ext_generator = elem;
17 }
18 
19 /* ------------------------------------------------------------------ */
20 
22  Json &data,
23  JsonToVoidFunc check_required_keys,
24  JsonToBoolFunc check_optional_keys)
25 {
26  check_required_keys({"xu", "yu", "zu"});
27 
28  auto el_box = ext_generator->get_element();
29 
30  el_box->check_required_keys({"lo_x", "lo_y", "lo_z", "hi_x", "hi_y", "hi_z"});
31 
32  auto &box = el_box->get_data();
33 
34  ArrayXd offset(3);
35  offset << box["lo_x"], box["lo_y"], box["lo_z"];
36 
37  ArrayXd length(3);
38  length << box["hi_x"], box["hi_y"], box["hi_z"];
39  length -= offset;
40 
41  for (auto &d : data)
42  {
43  ArrayXd unwrapped(3);
44  unwrapped << d["xu"], d["yu"], d["zu"];
45 
46  ArrayXd tmp_wrapped = unwrapped;
47 
48  tmp_wrapped -= offset;
49  tmp_wrapped /= length;
50 
51  tmp_wrapped = -tmp_wrapped.floor();
52  tmp_wrapped *= length;
53  tmp_wrapped += unwrapped;
54 
55  d["x"] = tmp_wrapped(0);
56  d["y"] = tmp_wrapped(1);
57  d["z"] = tmp_wrapped(2);
58  }
59 }
ShPtr< Element > ElPtr
An alias for a shared pointer of Element class.
Definition: element.h:378
std::function< bool(const Json &)> JsonToBoolFunc
An alias for a function accepts a Json object and returns a bool.
Definition: updater.h:20
This file has a definition of AddWrappedPosition class, which is a subclass of Adder class...
AddWrappedPosition(const ElPtr &elem)
Constructor of AddWrappedPosition class.
nlohmann::json Json
Json is an alias for nlohmann::json.
Definition: json.h:22
ShPtr< Generator > ext_generator
Definition: updater.h:64
virtual void compute_impl(Json &data, JsonToVoidFunc check_required_keys, JsonToBoolFunc check_optional_keys) override
This method overrides Updater::compute_impl.
Eigen::Array< double, Eigen::Dynamic, 1 > ArrayXd
ArrayXd is an alias for a column array of float numbers.
Definition: eigen.h:42
std::function< void(const Json &)> JsonToVoidFunc
An alias for a function accepts a Json object.
Definition: updater.h:18