ppap4lmp  0.7.2
pro_thickness_profile.cpp
Go to the documentation of this file.
1 
10 
11 /* ------------------------------------------------------------------ */
12 
14  const ElPtr &atoms,
15  const ElPtr &box)
16 {
18  new GenDict({{"Atoms", atoms}, {"Box", box}})));
19 }
20 
21 /* ------------------------------------------------------------------ */
22 
24  const Vec<std::pair<ElPtr,ElPtr>> &pairs)
25 {
26  Vec<ShPtr<GenDict>> gens;
27 
28  for (const auto &pair : pairs)
29  {
30  gens.push_back(ShPtr<GenDict>(
31  new GenDict({{"Atoms", pair.first}, {"Box", pair.second}})));
32  }
33 
34  register_generators(gens);
35 }
36 
37 /* ------------------------------------------------------------------ */
38 
40  const int index)
41 {
42  /* NOTE:
43  Although 'atom' is used for variable names,
44  profile thickness of something other than atoms can be computed too.
45  */
46  auto el_atoms = generators[index]->get_element("Atoms");
47 
48  el_atoms->check_required_keys({"x", "y", "z", "radius"});
49 
50  auto atoms = el_atoms->make_reduced_data({"x", "y", "z", "radius"});
51 
52  auto el_box = generators[index]->get_element("Box");
53 
54  el_box->check_required_keys({"lo_x", "lo_y", "hi_x", "hi_y"});
55 
56  auto &box = el_box->get_data();
57 
58  auto origin_x = box["lo_x"].get<double>();
59  auto origin_y = box["lo_y"].get<double>();
60  auto delta_x = (box["hi_x"].get<double>() - origin_x) / double(nx);
61  auto delta_y = (box["hi_y"].get<double>() - origin_y) / double(ny);
62 
63  if (shift_half)
64  {
65  origin_x += 0.5 * delta_x;
66  origin_y += 0.5 * delta_y;
67  }
68 
69  conditions[index] = {
70  {"origin_x", origin_x}, {"origin_y", origin_y},
71  {"delta_x", delta_x}, {"delta_y", delta_y},
72  {"nx", nx}, {"ny", ny}};
73 
74  /* NOTE:
75  Sorting atoms in descending order of height (coordinate in z
76  direction) can speed up this analysis significantly.
77  */
78  std::sort(
79  atoms.begin(), atoms.end(),
80  [](auto &a, auto &b) { return a["z"] > b["z"]; });
81 
82  // loop over all atoms
83 
84  profiles[index] = ArrayXXd::Zero(nx, ny);
85  auto &profile_tmp = profiles[index];
86 
87  const auto reciprocal_nx = 1.0 / double(nx);
88  const auto reciprocal_ny = 1.0 / double(ny);
89  const auto reciprocal_delta_x = 1.0 / delta_x;
90  const auto reciprocal_delta_y = 1.0 / delta_y;
91 
92  auto n_atoms = atoms.size();
93 
94  for (int i = 0; i != n_atoms; ++i)
95  {
96  auto atom = atoms[i];
97 
98  auto atom_x = atom["x"].get<double>() - origin_x;
99  auto atom_y = atom["y"].get<double>() - origin_y;
100  auto atom_z = atom["z"].get<double>() - offset;
101 
102  auto radius = atom["radius"].get<double>();
103  auto radius2 = radius*radius;
104 
105  auto grid_index_min_x = ceil((atom_x-radius)*reciprocal_delta_x);
106  auto grid_index_min_y = ceil((atom_y-radius)*reciprocal_delta_y);
107  auto grid_index_max_x = ceil((atom_x+radius)*reciprocal_delta_x);
108  auto grid_index_max_y = ceil((atom_y+radius)*reciprocal_delta_y);
109 
110  for (int ix = grid_index_min_x; ix != grid_index_max_x; ++ix)
111  {
112  for (int iy = grid_index_min_y; iy != grid_index_max_y; ++iy)
113  {
114  auto grid_x = ix*delta_x;
115  auto grid_y = iy*delta_y;
116 
117  auto dx = atom_x - grid_x;
118  auto dy = atom_y - grid_y;
119  auto dr2 = dx*dx + dy*dy;
120 
121  if (radius2 < dr2) continue;
122 
123  auto ix_in_box = ix - floor(ix*reciprocal_nx)*nx;
124  auto iy_in_box = iy - floor(iy*reciprocal_ny)*ny;
125 
126  auto dz2 = radius2 - dr2;
127 
128  auto d = atom_z - profile_tmp(ix_in_box, iy_in_box);
129 
130  if (d < 0.0 && dz2 < d*d) continue;
131 
132  profile_tmp(ix_in_box, iy_in_box) = atom_z + sqrt(dz2);
133  }
134  }
135  }
136 }
137 
138 /* ------------------------------------------------------------------ */
139 
141 {
142  conditions.resize(n_generators);
143  profiles.resize(n_generators);
144 }
145 
146 /* ------------------------------------------------------------------ */
147 
149  int nx_,
150  int ny_)
151 {
152  nx = nx_;
153  ny = ny_;
154 }
155 
156 /* ------------------------------------------------------------------ */
157 
159  double offset_)
160 {
161  offset = offset_;
162 }
163 
164 /* ------------------------------------------------------------------ */
165 
167  bool shift_half_)
168 {
169  shift_half = shift_half_;
170 }
171 
172 /* ------------------------------------------------------------------ */
173 
175 {
176  return conditions;
177 }
178 
179 /* ------------------------------------------------------------------ */
180 
182 {
183  return profiles;
184 }
Vec< ShPtr< Generator > > generators
Definition: processor.h:37
ShPtr< Element > ElPtr
An alias for a shared pointer of Element class.
Definition: element.h:378
virtual void run_impl(const int index) override
Implementation of analysis using an element of generators.
const Vec< ArrayXXd > & get_profiles()
Get a sequence of two-dimensional profile of film thickness as list of two-dimensional arrays...
void set_offset(double offset_)
Specify the offset for thickness (height).
const Vec< Json > & get_conditions()
Get computation conditions (origin of computed area, grid width and the number of grads) used by this...
int n_generators
Definition: processor.h:31
ProThicknessProfile(const ElPtr &atoms, const ElPtr &box)
Constructor of ProThicknessProfile class for a snapshot of simulation.
This file has a definition of ProThicknessProfile 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 register_generator(const ShPtr< GEN > &gen)
Definition: processor.cpp:16
void shift_half_delta(bool shift_half_=true)
Increment coordinates of the grid points by half the grid width. By default, grids in the x direction...
virtual void prepare() override
Resize conditions and profiles.
GenDict is a dictionary (or map) of Generator objects.
Definition: gen_dict.h:20
void set_grid(int nx_, int ny_)
Specify the number of grids in the x and y directions.
std::shared_ptr< T > ShPtr
ShPtr is an alias for shared pointer.
Definition: std.h:16
void register_generators(const Vec< ShPtr< GEN >> &gens)
Definition: processor.cpp:36