Loading...
Searching...
No Matches
Gradient.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
5/*
6 * Gradient.cpp
7 *
8 * Created on: 20 Oct 2020
9 * Author: Maxim Masterov
10 * Company: SURFSara
11 */
12
13#include "Gradient.h"
14
15#include <array>
16#include <stdexcept>
17
19#include "FarField.h"
20#include "MinImage.h"
21#include "PairCutoff.h"
22
23#ifdef USE_HIGHWAY
24#include "GradientHwy.h"
25#endif
26
27namespace aux {
28namespace {
29
30void calculateCutoffDerivativeFields(
31 const gpr::Coord& x1, const gpr::Coord& x2,
32 const gpr::AtomsConfiguration& configuration,
33 const gpr::FieldMatrixd& lengths, double far_radius,
34 const std::vector<std::pair<Eigen::Index, Eigen::Index>>& dimensions,
35 uint8_t options,
36 gpr::Derivatives<std::vector<gpr::FieldMatrixd>>& derivatives,
37 gpr::Derivatives<std::vector<gpr::FieldMatrixd>>& per_type)
38{
39 const Eigen::Index coordinates = 3 * configuration.atoms_mov.type.size();
40 if (x1.cols() < coordinates || x2.cols() < coordinates)
41 throw std::invalid_argument(
42 "pair derivative rows do not contain every moving coordinate");
43 // Observation/channel indices follow the Cartesian coordinate prefix.
44 const auto left = gpr::radialPairFeatures(x1.leftCols(coordinates),
45 configuration, far_radius);
46 const auto right = gpr::radialPairFeatures(x2.leftCols(coordinates),
47 configuration, far_radius);
48 const std::array<uint8_t, 3> flags{OptionsForGradCalculation::D1,
51 std::array<gpr::FieldMatrixd, 3> aggregate;
52 const std::array<std::vector<gpr::FieldMatrixd>*, 3> grouped{
53 &per_type.D1, &per_type.D2, &per_type.D12};
54 const std::array<std::vector<gpr::FieldMatrixd>*, 3> output{
55 &derivatives.D1, &derivatives.D2, &derivatives.D12};
56 for (std::size_t field = 0; field < flags.size(); ++field) {
57 aggregate[field] = gpr::FieldMatrixd::Zero(x1.rows(), x2.rows());
58 grouped[field]->assign(
59 options & (flags[field] << 4) ? configuration.n_pt : 0,
60 gpr::FieldMatrixd::Zero(x1.rows(), x2.rows()));
61 }
62 for (const auto& dimension_pair: dimensions) {
63 const Eigen::Index first = dimension_pair.first;
64 const Eigen::Index second = dimension_pair.second;
65 if (first < 0 || second < 0 || first >= coordinates ||
66 second >= coordinates)
67 throw std::invalid_argument(
68 "cutoff derivative coordinate is outside the geometry");
69 for (gpr::FieldMatrixd& block: aggregate)
70 block.setZero();
71 for (Eigen::Index i = 0; i < x1.rows(); ++i) {
72 for (Eigen::Index j = 0; j < x2.rows(); ++j) {
74 left[i], right[j],
75 [&](const gpr::CutoffPairFeature* a,
76 const gpr::CutoffPairFeature* b) {
77 const Eigen::Index type = a ? a->type : b->type;
78 if (lengths.size() != 1 && type >= lengths.size())
79 return;
80 const double length =
81 lengths.data()[lengths.size() == 1 ? 0 : type];
82 const double inverse = 1.0 / (length * length);
83 const double delta =
84 (a ? a->value : 0.0) - (b ? b->value : 0.0);
85 const double da = a ? a->derivative(first) : 0.0;
86 const double db = b ? b->derivative(second) : 0.0;
87 const std::array<double, 3> values{
88 4.0 * inverse * delta * da,
89 -4.0 * inverse * delta * db,
90 -4.0 * inverse * da * db};
91 for (std::size_t field = 0; field < flags.size();
92 ++field) {
93 if (!(options & flags[field])) continue;
94 aggregate[field](i, j) += values[field];
95 // Pair-type fields store the negative derivative,
96 // as required by the shared geometry contractions.
97 if (options & (flags[field] << 4))
98 (*grouped[field])[type](i, j) -= values[field];
99 }
100 });
101 }
102 }
103 // Push this coordinate pair on its own. The aggregate was
104 // cleared at the start of the iteration.
105 for (std::size_t field = 0; field < flags.size(); ++field)
106 if (options & flags[field])
107 output[field]->push_back(aggregate[field]);
108 }
109}
110
111} // namespace
112
113// calculateDerivative and evaluateValueInDerivativeField were moved to the
114// header as static inline so the gradient hot path can elide cross-TU calls;
115// see commit message and Gradient.h for details.
116
117void Gradient::resizeDerivativeFields(const gpr::Coord& x1,
118 const gpr::Coord& x2,
119 const gpr::AtomsConfiguration& conf_info,
120 const uint8_t calc_options,
121 const uint8_t field_type,
123 std::vector<gpr::FieldMatrixd>& D_pt)
124{
125 D.resize(x1.rows(), x2.rows());
126 D.setZero();
127 if (calc_options & field_type) {
128 // Size the per-pairtype fields in place. push_back(D) copied the whole
129 // freshly-zeroed n1 x n2 aggregate once per pairtype -- a memcpy of
130 // zeros where an allocate-and-zero does the same job -- and reallocated
131 // on every growth step. resize + per-element resize reuses whatever
132 // storage the vector already holds, so a repeat call with unchanged
133 // dimensions does no allocation at all.
134 D_pt.resize(static_cast<std::size_t>(conf_info.n_pt));
135 for (auto& field: D_pt) {
136 field.resize(x1.rows(), x2.rows());
137 field.setZero();
138 }
139 } else {
140 D_pt.clear();
141 }
142}
143
144void Gradient::pushBackDerivativeField(const uint8_t calc_options,
145 const uint8_t field_type,
147 std::vector<gpr::FieldMatrixd>& D_vec)
148{
149 if (calc_options & field_type) D_vec.push_back(D);
150}
151
152void Gradient::calculateGradientBetweenMovingAtoms(
153 const gpr::Coord& x1, const gpr::Coord& x2,
154 const gpr::AtomsConfiguration& conf_info,
155 const gpr::FieldMatrixd& lengthScale, const gpr::Index_t direction_x1,
156 const gpr::Index_t direction_x2, const gpr::Indices2D& ind,
157 uint8_t calc_options, gpr::Derivatives<gpr::FieldMatrixd*> derivatives,
158 gpr::Derivatives<std::vector<gpr::FieldMatrixd>>& derivatives_pt,
159 std::vector<double>& invr2, std::vector<double>& deriv2)
160{
161 Eigen::Index n1 = x1.rows();
162 Eigen::Index n2 = x2.rows();
163
164 const Eigen::Index n_mov = conf_info.atoms_mov.type.cols();
165 if (static_cast<Eigen::Index>(ind.i) >= n_mov ||
166 static_cast<Eigen::Index>(ind.j) >= n_mov || direction_x1 > 2 ||
167 direction_x2 > 2) {
168 throw std::invalid_argument(
169 "moving-atom gradient index is outside the moving-atom geometry");
170 }
171 const Eigen::Index off_i = 3 * static_cast<Eigen::Index>(ind.i);
172 const Eigen::Index off_j = 3 * static_cast<Eigen::Index>(ind.j);
173 if (off_i + 2 >= x1.cols() || off_j + 2 >= x1.cols() ||
174 off_i + 2 >= x2.cols() || off_j + 2 >= x2.cols()) {
175 throw std::invalid_argument(
176 "moving-atom gradient coordinate is outside the geometry row");
177 }
178
179 const gpr::Index_t type_i = conf_info.atoms_mov.type(0, ind.i);
180 const gpr::Index_t type_j = conf_info.atoms_mov.type(0, ind.j);
181 if (static_cast<Eigen::Index>(type_i) >= conf_info.pairtype.rows() ||
182 static_cast<Eigen::Index>(type_j) >= conf_info.pairtype.cols()) {
183 throw std::invalid_argument(
184 "moving-atom gradient pair type is outside the pair-type table");
185 }
186 gpr::Index_t pt = conf_info.pairtype(type_i, type_j);
187 // Index_t is unsigned, so a `pt < 0` test here is dead: EMPTY (-1)
188 // arrives as UINT32_MAX and the equality catches it. The bound on the
189 // next line is what keeps the lengthScale index in range.
190 if (pt == static_cast<gpr::Index_t>(EMPTY)) return;
191 if (lengthScale.size() != 1 && pt >= lengthScale.size()) return;
192
193 const double length_scale = lengthScale.size() == 1
194 ? lengthScale(0, 0)
195 : *(lengthScale.data() + pt);
196 double lengtScale2_rec = 1. / (length_scale * length_scale);
197
198 // Direct pointer arithmetic instead of gpr::coord::at-returns-
199 // Vector3d-by-value chains. gpr::coord storage is
200 // row-major-of-packed-3D, so &mat.data()[row * mat.cols() + 3 * col]
201 // points at the (x, y, z) triple for row=row, atom=col.
202 const double* const x1_data = x1.data();
203 const Eigen::Index x1_cols = x1.cols();
204 const double* const x2_data = x2.data();
205 const Eigen::Index x2_cols = x2.cols();
206 const Eigen::Index x2_off_j = 3 * static_cast<Eigen::Index>(ind.j);
207 const Eigen::Index x2_off_i = 3 * static_cast<Eigen::Index>(ind.i);
208 const Eigen::Index x1_off_j = 3 * static_cast<Eigen::Index>(ind.j);
209 const Eigen::Index x1_off_i = 3 * static_cast<Eigen::Index>(ind.i);
210 const int dx2 = static_cast<int>(direction_x2);
211 const int dx1 = static_cast<int>(direction_x1);
212 const gpr::geometry::PairBox box(conf_info.cell);
213
214 // Pre-compute x2-dependent quantities outside the n-loop
215 invr2.resize(n2);
216 deriv2.resize(n2);
217 // Scalar gather (strided coords): stage r^2 in invr2 and the deriv
218 // numerator in deriv2, then transform in place with the vectorized
219 // 1/sqrt + cube (the expensive transcendental, SIMD-wide). Bit-identical
220 // to r=sqrt(r2); invr=1/r; deriv=num*invr^3.
221 for (Eigen::Index m = 0; m < n2; ++m) {
222 const double* p2j = x2_data + m * x2_cols + x2_off_j;
223 const double* p2i = x2_data + m * x2_cols + x2_off_i;
224 double dr[3];
225 box.displacement(p2i, p2j, dr);
226 invr2[m] = dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2]; // r^2
227 deriv2[m] = -dr[dx2]; // numerator: i - j
228 }
229#ifdef USE_HIGHWAY
230 gpr::hwy_kernels::recip_sqrt_cube(invr2.data(), deriv2.data(), invr2.data(),
231 deriv2.data(), static_cast<int64_t>(n2));
232#else
233 for (Eigen::Index m = 0; m < n2; ++m) {
234 const double invr = 1.0 / std::sqrt(invr2[m]);
235 invr2[m] = invr;
236 deriv2[m] = deriv2[m] * invr * invr * invr;
237 }
238#endif
239
240 // SIMD fast path for aggregate derivative fields. Pairtype-active calls
241 // keep scalar x1 inverse-distance arithmetic and vectorize the inner
242 // accumulation over x2 rows, preserving the reference row trajectory while
243 // removing the compute-bound per-entry field updates.
244#ifdef USE_HIGHWAY
245 // Any subset of D1/D2/D12 may be active; nullable pointers select the
246 // active aggregate and pairtype rows in the batched kernel.
247 constexpr uint8_t kAnyD = OptionsForGradCalculation::D1 |
250 constexpr uint8_t kAnyPt = OptionsForGradCalculation::D1_pt |
253 const bool hwy_fast = (calc_options & kAnyD) != 0 && n2 > 0;
254 const bool hwy_pairtype = hwy_fast && (calc_options & kAnyPt) != 0;
255 const bool hwy_d1 =
256 hwy_fast && (calc_options & OptionsForGradCalculation::D1);
257 const bool hwy_d2 =
258 hwy_fast && (calc_options & OptionsForGradCalculation::D2);
259 const bool hwy_d12 =
260 hwy_fast && (calc_options & OptionsForGradCalculation::D12);
261 const bool hwy_d1pt =
262 hwy_d1 && (calc_options & OptionsForGradCalculation::D1_pt);
263 const bool hwy_d2pt =
264 hwy_d2 && (calc_options & OptionsForGradCalculation::D2_pt);
265 const bool hwy_d12pt =
266 hwy_d12 && (calc_options & OptionsForGradCalculation::D12_pt);
267 double* const d1_data = hwy_d1 ? derivatives.D1->data() : nullptr;
268 double* const d2_data = hwy_d2 ? derivatives.D2->data() : nullptr;
269 double* const d12_data = hwy_d12 ? derivatives.D12->data() : nullptr;
270 double* const d1pt_data = hwy_d1pt ? derivatives_pt.D1[pt].data() : nullptr;
271 double* const d2pt_data = hwy_d2pt ? derivatives_pt.D2[pt].data() : nullptr;
272 double* const d12pt_data =
273 hwy_d12pt ? derivatives_pt.D12[pt].data() : nullptr;
274 const Eigen::Index d_cols =
275 hwy_d1 ? derivatives.D1->cols()
276 : (hwy_d2 ? derivatives.D2->cols()
277 : (hwy_d12 ? derivatives.D12->cols() : 0));
278 const double hwy_c = -4. * lengtScale2_rec;
279#endif
280
281#ifdef USE_HIGHWAY
282 if (hwy_fast) {
283 // Precompute the per-row invr1 / deriv_x1, then accumulate the whole
284 // n1 x n2 block in ONE batched SIMD call -- amortizes the per-row
285 // cross-TU dispatch/call overhead (perf: per-row wrapper 3.5% > 2.0%
286 // AVX2 work).
287 thread_local std::vector<double> invr1_arr;
288 thread_local std::vector<double> deriv_x1_arr;
289 invr1_arr.resize(static_cast<size_t>(n1));
290 deriv_x1_arr.resize(static_cast<size_t>(n1));
291 // Scalar gather -> stage r^2 / numerator, then one vectorised
292 // 1/sqrt + cube for both branches. The pairtype branch used to keep
293 // the scalar arithmetic on the grounds that its rows feed
294 // trajectory-sensitive derivative fields, but the two forms are the
295 // same values, not merely close: IEEE-754 requires sqrt and divide to
296 // be correctly rounded, and the kernel cubes left-associated exactly
297 // as the scalar expression does. Checked against the scalar formula
298 // over 4096 mixed structured and random inputs, zero differing
299 // elements in both outputs.
300 for (Eigen::Index n = 0; n < n1; ++n) {
301 const double* p1j = x1_data + n * x1_cols + x1_off_j;
302 const double* p1i = x1_data + n * x1_cols + x1_off_i;
303 double dr[3];
304 box.displacement(p1i, p1j, dr);
305 invr1_arr[static_cast<size_t>(n)] =
306 dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
307 deriv_x1_arr[static_cast<size_t>(n)] = -dr[dx1];
308 }
309 // Both branches need invr1 = 1/sqrt(r2) and num*invr1^3 over the same
310 // array; the pairtype branch was doing it scalar while the branch
311 // below called the vectorised kernel for the identical computation.
312 gpr::hwy_kernels::recip_sqrt_cube(invr1_arr.data(), deriv_x1_arr.data(),
313 invr1_arr.data(), deriv_x1_arr.data(),
314 static_cast<int64_t>(n1));
315 if (hwy_pairtype) {
316 gpr::hwy_kernels::accumulate_gradient_blocks_batched_pairtype(
317 d1_data, d2_data, d12_data, d1pt_data, d2pt_data, d12pt_data,
318 static_cast<int64_t>(d_cols), static_cast<int64_t>(n1),
319 invr1_arr.data(), deriv_x1_arr.data(), invr2.data(),
320 deriv2.data(), hwy_c, static_cast<int64_t>(n2));
321 } else {
322 gpr::hwy_kernels::accumulate_gradient_blocks_batched(
323 d1_data, d2_data, d12_data, static_cast<int64_t>(d_cols),
324 static_cast<int64_t>(n1), invr1_arr.data(), deriv_x1_arr.data(),
325 invr2.data(), deriv2.data(), hwy_c, static_cast<int64_t>(n2));
326 }
327 return;
328 }
329#endif
330
331 for (Eigen::Index n = 0; n < n1; ++n) {
332 const double* p1j = x1_data + n * x1_cols + x1_off_j;
333 const double* p1i = x1_data + n * x1_cols + x1_off_i;
334 double dr[3];
335 box.displacement(p1i, p1j, dr);
336 const double r_ij_1 =
337 std::sqrt(dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2]);
338 const double invr1 = 1.0 / r_ij_1;
339 const double deriv_x1 = (-dr[dx1]) * invr1 * invr1 * invr1;
340 for (Eigen::Index m = 0; m < n2; ++m) {
341 double r_diff_rec = invr1 - invr2[m];
342
343 evaluateValueInDerivativeField(
344 {n, m}, calc_options, OptionsForGradCalculation::D1,
345 lengtScale2_rec, pt, deriv_x1, r_diff_rec, *derivatives.D1,
346 derivatives_pt.D1);
347
348 evaluateValueInDerivativeField(
349 {n, m}, calc_options, OptionsForGradCalculation::D2,
350 lengtScale2_rec, pt, -r_diff_rec, deriv2[m], *derivatives.D2,
351 derivatives_pt.D2);
352
353 evaluateValueInDerivativeField(
354 {n, m}, calc_options, OptionsForGradCalculation::D12,
355 lengtScale2_rec, pt, deriv_x1, deriv2[m], *derivatives.D12,
356 derivatives_pt.D12);
357 }
358 }
359}
360
361void Gradient::calculateGradientBetweenMovingAndFrozenAtoms(
362 const gpr::Coord& x1, const gpr::Coord& x2,
363 const gpr::AtomsConfiguration& conf_info,
364 const gpr::FieldMatrixd& lengthScale, const gpr::Index_t direction_x1,
365 const gpr::Index_t direction_x2, const gpr::Indices2D& ind,
366 uint8_t calc_options, gpr::Derivatives<gpr::FieldMatrixd*> derivatives,
367 gpr::Derivatives<std::vector<gpr::FieldMatrixd>>& derivatives_pt,
368 std::vector<double>& invr2, std::vector<double>& deriv2)
369{
370 // x1-side scratch, mirroring the caller-supplied invr2/deriv2 pair.
371 // thread_local so the capacity survives across calls instead of being
372 // reallocated per moving-frozen atom pair.
373 thread_local std::vector<double> invr1_scratch;
374 thread_local std::vector<double> deriv1_scratch;
375
376 Eigen::Index n1 = x1.rows();
377 Eigen::Index n2 = x2.rows();
378
379 gpr::Index_t pt =
380 conf_info.pairtype(conf_info.atoms_mov.type(0, ind.i),
381 conf_info.atoms_froz_active.type(0, ind.j));
382 // Index_t is unsigned, so a `pt < 0` test here is dead: EMPTY (-1)
383 // arrives as UINT32_MAX and the equality catches it. The bound on the
384 // next line is what keeps the lengthScale index in range.
385 if (pt == static_cast<gpr::Index_t>(EMPTY)) return;
386 if (lengthScale.size() != 1 && pt >= lengthScale.size()) return;
387
388 const double length_scale = lengthScale.size() == 1
389 ? lengthScale(0, 0)
390 : *(lengthScale.data() + pt);
391 double lengtScale2_rec = 1. / (length_scale * length_scale);
392
393 // Direct pointer arithmetic; matches the Distance::dist_at /
394 // calculateGradientBetweenMovingAtoms rewrite. Frozen position is
395 // taken from atoms_froz_active.positions at row 0, column ind.j.
396 const double* const x1_data = x1.data();
397 const Eigen::Index x1_cols = x1.cols();
398 const double* const x2_data = x2.data();
399 const Eigen::Index x2_cols = x2.cols();
400 const double* const froz_pos =
401 conf_info.atoms_froz_active.positions.data() +
402 3 * static_cast<Eigen::Index>(ind.j);
403 const int dx1 = static_cast<int>(direction_x1);
404 const int dx2 = static_cast<int>(direction_x2);
405 const gpr::geometry::PairBox box(conf_info.cell);
406
407 const Eigen::Index x2_off_i = 3 * static_cast<Eigen::Index>(ind.i);
408 const Eigen::Index x1_off_i = 3 * static_cast<Eigen::Index>(ind.i);
409 if (far_field_radius_ > 0.0 && n1 > 0 &&
410 farFromCentre(box, farFieldCentre(conf_info, ind.i), froz_pos,
411 far_field_radius_))
412 return;
413
414 // Pre-compute x2-dependent quantities outside the n-loop
415 // r^2 and the numerator in a cheap strided pass, then the reciprocal
416 // square root and cube SIMD-wide, exactly as the moving-moving path above
417 // already does. This block was the only remaining place evaluating that
418 // transcendental one element at a time. Bit-identical: sqrt and divide are
419 // correctly rounded under IEEE-754, and the cube keeps the same
420 // left-to-right association.
421 invr2.resize(n2);
422 deriv2.resize(n2);
423 for (Eigen::Index m = 0; m < n2; ++m) {
424 const double* p2 = x2_data + m * x2_cols + x2_off_i;
425 double dr[3];
426 box.displacement(froz_pos, p2, dr);
427 invr2[m] = dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2]; // r^2
428 deriv2[m] = dr[dx2]; // numerator: moving - frozen
429 }
430#ifdef USE_HIGHWAY
431 gpr::hwy_kernels::recip_sqrt_cube(invr2.data(), deriv2.data(), invr2.data(),
432 deriv2.data(), static_cast<int64_t>(n2));
433#else
434 for (Eigen::Index m = 0; m < n2; ++m) {
435 const double invr = 1.0 / std::sqrt(invr2[m]);
436 invr2[m] = invr;
437 deriv2[m] = deriv2[m] * invr * invr * invr;
438 }
439#endif
440
441 // Same batching for the x1 side: r^2 and numerator first, then one
442 // vectorised reciprocal-sqrt-and-cube pass, so the (n, m) loop below only
443 // reads precomputed values.
444 invr1_scratch.resize(static_cast<std::size_t>(n1));
445 deriv1_scratch.resize(static_cast<std::size_t>(n1));
446 for (Eigen::Index n = 0; n < n1; ++n) {
447 const double* p1 = x1_data + n * x1_cols + x1_off_i;
448 double dr[3];
449 box.displacement(froz_pos, p1, dr);
450 invr1_scratch[static_cast<std::size_t>(n)] =
451 dr[0] * dr[0] + dr[1] * dr[1] + dr[2] * dr[2];
452 deriv1_scratch[static_cast<std::size_t>(n)] = dr[dx1];
453 }
454#ifdef USE_HIGHWAY
455 gpr::hwy_kernels::recip_sqrt_cube(
456 invr1_scratch.data(), deriv1_scratch.data(), invr1_scratch.data(),
457 deriv1_scratch.data(), static_cast<int64_t>(n1));
458#else
459 for (Eigen::Index n = 0; n < n1; ++n) {
460 const double invr = 1.0 / std::sqrt(invr1_scratch[n]);
461 invr1_scratch[n] = invr;
462 deriv1_scratch[n] = deriv1_scratch[n] * invr * invr * invr;
463 }
464#endif
465
466#ifdef USE_HIGHWAY
467 // The (n, m) body below is character-for-character the same accumulation
468 // that calculateGradientBetweenMovingAtoms performs, and that function
469 // hands the whole n1 x n2 block to one batched SIMD call rather than
470 // making three function calls per element. Use the same kernel here; the
471 // moving-frozen path had no batched route at all, which is the path that
472 // dominates once there are many active frozen atoms.
473 {
474 constexpr uint8_t kAnyD = OptionsForGradCalculation::D1 |
477 constexpr uint8_t kAnyPt = OptionsForGradCalculation::D1_pt |
480 const bool hwy_fast = (calc_options & kAnyD) != 0 && n2 > 0;
481 if (hwy_fast) {
482 const bool hwy_pairtype = (calc_options & kAnyPt) != 0;
483 const bool hwy_d1 =
484 (calc_options & OptionsForGradCalculation::D1) != 0;
485 const bool hwy_d2 =
486 (calc_options & OptionsForGradCalculation::D2) != 0;
487 const bool hwy_d12 =
488 (calc_options & OptionsForGradCalculation::D12) != 0;
489 const bool hwy_d1pt =
490 hwy_d1 && (calc_options & OptionsForGradCalculation::D1_pt);
491 const bool hwy_d2pt =
492 hwy_d2 && (calc_options & OptionsForGradCalculation::D2_pt);
493 const bool hwy_d12pt =
494 hwy_d12 && (calc_options & OptionsForGradCalculation::D12_pt);
495 double* const d1_data = hwy_d1 ? derivatives.D1->data() : nullptr;
496 double* const d2_data = hwy_d2 ? derivatives.D2->data() : nullptr;
497 double* const d12_data =
498 hwy_d12 ? derivatives.D12->data() : nullptr;
499 double* const d1pt_data =
500 hwy_d1pt ? derivatives_pt.D1[pt].data() : nullptr;
501 double* const d2pt_data =
502 hwy_d2pt ? derivatives_pt.D2[pt].data() : nullptr;
503 double* const d12pt_data =
504 hwy_d12pt ? derivatives_pt.D12[pt].data() : nullptr;
505 const Eigen::Index d_cols =
506 hwy_d1 ? derivatives.D1->cols()
507 : (hwy_d2 ? derivatives.D2->cols()
508 : (hwy_d12 ? derivatives.D12->cols() : 0));
509 const double hwy_c = -4. * lengtScale2_rec;
510
511 if (hwy_pairtype) {
512 gpr::hwy_kernels::accumulate_gradient_blocks_batched_pairtype(
513 d1_data, d2_data, d12_data, d1pt_data, d2pt_data,
514 d12pt_data, static_cast<int64_t>(d_cols),
515 static_cast<int64_t>(n1), invr1_scratch.data(),
516 deriv1_scratch.data(), invr2.data(), deriv2.data(), hwy_c,
517 static_cast<int64_t>(n2));
518 } else {
519 gpr::hwy_kernels::accumulate_gradient_blocks_batched(
520 d1_data, d2_data, d12_data, static_cast<int64_t>(d_cols),
521 static_cast<int64_t>(n1), invr1_scratch.data(),
522 deriv1_scratch.data(), invr2.data(), deriv2.data(), hwy_c,
523 static_cast<int64_t>(n2));
524 }
525 return;
526 }
527 }
528#endif
529
530 for (Eigen::Index n = 0; n < n1; ++n) {
531 const double r_ij_1_rec = invr1_scratch[static_cast<std::size_t>(n)];
532 const double deriv_x1 = deriv1_scratch[static_cast<std::size_t>(n)];
533
534 for (Eigen::Index m = 0; m < n2; ++m) {
535 double r_diff_rec = r_ij_1_rec - invr2[m];
536
537 evaluateValueInDerivativeField(
538 {n, m}, calc_options, OptionsForGradCalculation::D1,
539 lengtScale2_rec, pt, deriv_x1, r_diff_rec, *derivatives.D1,
540 derivatives_pt.D1);
541
542 evaluateValueInDerivativeField(
543 {n, m}, calc_options, OptionsForGradCalculation::D2,
544 lengtScale2_rec, pt, -r_diff_rec, deriv2[m], *derivatives.D2,
545 derivatives_pt.D2);
546
547 evaluateValueInDerivativeField(
548 {n, m}, calc_options, OptionsForGradCalculation::D12,
549 lengtScale2_rec, pt, deriv_x1, deriv2[m], *derivatives.D12,
550 derivatives_pt.D12);
551 }
552 }
553}
554
556 const gpr::Coord& x1, const gpr::Coord& x2,
557 const gpr::AtomsConfiguration& conf_info,
558 const gpr::FieldMatrixd& lengthScale, const gpr::FieldMatrixIdx& dims,
559 uint8_t calc_options,
560 gpr::Derivatives<std::vector<gpr::FieldMatrixd>>& derivatives,
561 gpr::Derivatives<std::vector<gpr::FieldMatrixd>>& derivatives_pt)
562{
563 if (conf_info.pair_cutoff > 0.0 || far_field_radius_ > 0.0) {
564 std::vector<std::pair<Eigen::Index, Eigen::Index>> dimensions;
565 for (Eigen::Index i = 0; i < dims.size(); ++i)
566 dimensions.emplace_back(dims.data()[i] - 1, dims.data()[i] - 1);
567 calculateCutoffDerivativeFields(
568 x1, x2, conf_info, lengthScale, far_field_radius_, dimensions,
569 calc_options, derivatives, derivatives_pt);
570 return;
571 }
572
573 // thread_local scratch: the accumulator matrices and the per-x2
574 // distance/derivative vectors are resized + zeroed on every call
575 // below (via resizeDerivativeFields and the pre-x1 loop in
576 // calculateGradientBetweenMovingAtoms), so reusing their Eigen/std
577 // storage across calls is value-identical while eliminating the
578 // per-call heap allocation. thread_local (not static) keeps each
579 // thread's scratch private under the OpenMP serial-oracle region.
580 thread_local gpr::FieldMatrixd D1;
581 thread_local gpr::FieldMatrixd D2;
582 thread_local gpr::FieldMatrixd D12;
583 thread_local std::vector<double> invr2_scratch;
584 thread_local std::vector<double> deriv2_scratch;
585 Eigen::Index N_mov = conf_info.atoms_mov.type.cols();
586 Eigen::Index N_fro = conf_info.atoms_froz_active.type.cols();
587
588 resizeDerivativeFields(x1, x2, conf_info, calc_options,
590 derivatives_pt.D1);
591
592 resizeDerivativeFields(x1, x2, conf_info, calc_options,
594 derivatives_pt.D2);
595
596 resizeDerivativeFields(x1, x2, conf_info, calc_options,
598 derivatives_pt.D12);
599
600 // Reserve space to avoid reallocations during push_back
601 const auto n_dims = static_cast<size_t>(dims.size());
602 if (calc_options & OptionsForGradCalculation::D1)
603 derivatives.D1.reserve(n_dims);
604 if (calc_options & OptionsForGradCalculation::D2)
605 derivatives.D2.reserve(n_dims);
606 if (calc_options & OptionsForGradCalculation::D12)
607 derivatives.D12.reserve(n_dims);
608
609 for (Eigen::Index dim_counter = 0; dim_counter < dims.size();
610 ++dim_counter) {
611 // A later coordinate must not keep the pairs of an earlier one.
612 D1.setZero();
613 D2.setZero();
614 D12.setZero();
615 gpr::Index_t i_dim = *(dims.data() + dim_counter);
616 gpr::Index_t i = ceil(i_dim / 3.) - 1;
617 gpr::Index_t xyz = i_dim - i * 3 - 1;
618
619 // Gradient between moving atoms
620 if (N_mov > 1) {
621 for (Eigen::Index j = 0; j < N_mov; ++j) {
622 if (i != j) {
623 calculateGradientBetweenMovingAtoms(
624 x1, x2, conf_info, lengthScale, xyz, xyz, {i, j},
625 calc_options, {&D1, &D2, &D12}, derivatives_pt,
626 invr2_scratch, deriv2_scratch);
627 }
628 }
629 }
630
631 // Gradient from moving atoms to active frozen atoms
632 if (N_fro > 0) {
633 for (Eigen::Index j = 0; j < N_fro; ++j) {
634 calculateGradientBetweenMovingAndFrozenAtoms(
635 x1, x2, conf_info, lengthScale, xyz, xyz, {i, j},
636 calc_options, {&D1, &D2, &D12}, derivatives_pt,
637 invr2_scratch, deriv2_scratch);
638 }
639 accumulateFarFieldDerivatives(x1, x2, conf_info, lengthScale, i,
640 xyz, xyz, calc_options, D1, D2, D12,
641 derivatives_pt);
642 }
643
644 pushBackDerivativeField(calc_options, OptionsForGradCalculation::D1, D1,
645 derivatives.D1);
646
647 pushBackDerivativeField(calc_options, OptionsForGradCalculation::D2, D2,
648 derivatives.D2);
649
650 pushBackDerivativeField(calc_options, OptionsForGradCalculation::D12,
651 D12, derivatives.D12);
652 }
653}
654
656 const gpr::Coord& x1, const gpr::Coord& x2,
657 const gpr::AtomsConfiguration& conf_info,
658 const gpr::FieldMatrixd& lengthScale, const gpr::FieldMatrixIdx& dims1,
659 const gpr::FieldMatrixIdx& dims2, const uint8_t calc_options,
660 [[maybe_unused]] const uint8_t direction_x2,
661 gpr::Derivatives<std::vector<gpr::FieldMatrixd>>& derivatives,
662 gpr::Derivatives<std::vector<gpr::FieldMatrixd>>& derivatives_pt)
663{
664 if (conf_info.pair_cutoff > 0.0 || far_field_radius_ > 0.0) {
665 std::vector<std::pair<Eigen::Index, Eigen::Index>> dimensions;
666 for (Eigen::Index i = 0; i < dims1.size(); ++i)
667 for (Eigen::Index j = 0; j < dims2.size(); ++j)
668 dimensions.emplace_back(dims1.data()[i] - 1,
669 dims2.data()[j] - 1);
670 calculateCutoffDerivativeFields(
671 x1, x2, conf_info, lengthScale, far_field_radius_, dimensions,
672 calc_options, derivatives, derivatives_pt);
673 return;
674 }
675
676 // thread_local scratch: D1/D2/D12/s2 are resized + (re)initialized
677 // on every call below, so their Eigen storage is reused across
678 // calls value-identically; thread_local keeps each thread private
679 // under the OpenMP serial-oracle region.
680 thread_local gpr::FieldMatrixd D1;
681 thread_local gpr::FieldMatrixd D2;
682 thread_local gpr::FieldMatrixd D12;
683 thread_local gpr::FieldMatrixd s2;
684 thread_local std::vector<double> invr2_scratch;
685 thread_local std::vector<double> deriv2_scratch;
686 Eigen::Index n1 = x1.rows();
687 Eigen::Index n2 = x2.rows();
688 Eigen::Index N_mov = conf_info.atoms_mov.type.cols();
689 Eigen::Index N_fro = conf_info.atoms_froz_active.type.cols();
690
691 D1.resize(n1, n2);
692 D1.setZero();
693 D2.resize(n1, n2);
694 D2.setZero();
695 D12.resize(n1, n2);
696 D12.setZero();
697 s2.resize(1, lengthScale.size());
698
699 resizeDerivativeFields(x1, x2, conf_info, calc_options,
701 derivatives_pt.D1);
702
703 resizeDerivativeFields(x1, x2, conf_info, calc_options,
705 derivatives_pt.D2);
706
707 resizeDerivativeFields(x1, x2, conf_info, calc_options,
709 derivatives_pt.D12);
710
711 // Reserve space to avoid reallocations during push_back
712 const auto total_dims =
713 static_cast<size_t>(dims1.size()) * static_cast<size_t>(dims2.size());
714 if (calc_options & OptionsForGradCalculation::D1)
715 derivatives.D1.reserve(total_dims);
716 if (calc_options & OptionsForGradCalculation::D2)
717 derivatives.D2.reserve(total_dims);
718 if (calc_options & OptionsForGradCalculation::D12)
719 derivatives.D12.reserve(total_dims);
720
721 for (Eigen::Index n = 0; n < s2.size(); ++n)
722 *(s2.data() + n) =
723 1. / (*(lengthScale.data() + n) * *(lengthScale.data() + n));
724
725 for (Eigen::Index dim_counter_1 = 0; dim_counter_1 < dims1.size();
726 ++dim_counter_1) {
727 for (Eigen::Index dim_counter_2 = 0; dim_counter_2 < dims2.size();
728 ++dim_counter_2) {
729 // A later coordinate pair must not keep an earlier pair.
730 // D12 holds only this pair. The pair type field is the running
731 // sum, so the two negations below flip only this pair.
732 D1.setZero();
733 D2.setZero();
734 D12.setZero();
735 gpr::Index_t i_dim_1 = *(dims1.data() + dim_counter_1);
736 gpr::Index_t i_1 = ceil(i_dim_1 / 3.) - 1;
737 gpr::Index_t i_dim_2 = *(dims2.data() + dim_counter_2);
738 gpr::Index_t i_2 = ceil(i_dim_2 / 3.) - 1;
739 gpr::Index_t xyz_1 = i_dim_1 - i_1 * 3 - 1;
740 gpr::Index_t xyz_2 = i_dim_2 - i_2 * 3 - 1;
741 gpr::Index_t i;
742
743 if (i_1 != i_2) {
744 i = i_1;
745 if (N_mov > 1) {
746 for (Eigen::Index j = 0; j < N_mov; ++j) {
747 if (i != j) {
748 calculateGradientBetweenMovingAtoms(
749 x1, x2, conf_info, lengthScale, xyz_1, xyz_1,
750 {i, j},
751 calc_options &
754 {&D1, &D2, &D12}, derivatives_pt, invr2_scratch,
755 deriv2_scratch);
756 }
757 }
758 }
759
760 if (N_fro > 0) {
761 for (Eigen::Index j = 0; j < N_fro; ++j) {
762 calculateGradientBetweenMovingAndFrozenAtoms(
763 x1, x2, conf_info, lengthScale, xyz_1, xyz_1,
764 {i, j},
765 calc_options & (OptionsForGradCalculation::D1 |
767 {&D1, &D2, &D12}, derivatives_pt, invr2_scratch,
768 deriv2_scratch);
769 }
770 accumulateFarFieldDerivatives(
771 x1, x2, conf_info, lengthScale, i, xyz_1, xyz_1,
772 calc_options & (OptionsForGradCalculation::D1 |
774 D1, D2, D12, derivatives_pt);
775 }
776
777 i = i_2;
778 if (N_mov > 1) {
779 for (Eigen::Index j = 0; j < N_mov; ++j) {
780 if (i != j) {
781 calculateGradientBetweenMovingAtoms(
782 x1, x2, conf_info, lengthScale, xyz_2, xyz_2,
783 {i, j},
784 calc_options &
787 {&D1, &D2, &D12}, derivatives_pt, invr2_scratch,
788 deriv2_scratch);
789 }
790 }
791 }
792
793 if (N_fro > 0) {
794 for (Eigen::Index j = 0; j < N_fro; ++j) {
795 calculateGradientBetweenMovingAndFrozenAtoms(
796 x1, x2, conf_info, lengthScale, xyz_2, xyz_2,
797 {i, j},
798 calc_options & (OptionsForGradCalculation::D2 |
800 {&D1, &D2, &D12}, derivatives_pt, invr2_scratch,
801 deriv2_scratch);
802 }
803 accumulateFarFieldDerivatives(
804 x1, x2, conf_info, lengthScale, i, xyz_2, xyz_2,
805 calc_options & (OptionsForGradCalculation::D2 |
807 D1, D2, D12, derivatives_pt);
808 }
809
810 // The pair-type field sums every coordinate pair. Negate it
811 // before this pair is added and again afterwards, so only
812 // this pair changes sign. One negation would also reverse
813 // every earlier pair.
814 if (calc_options & OptionsForGradCalculation::D12_pt) {
815 for (size_t n = 0; n < derivatives_pt.D12.size(); ++n) {
816 for (Eigen::Index m = 0;
817 m < derivatives_pt.D12[n].size(); ++m) {
818 *(derivatives_pt.D12[n].data() + m) *= -1.;
819 }
820 }
821 }
822
823 calculateGradientBetweenMovingAtoms(
824 x1, x2, conf_info, lengthScale, xyz_1, xyz_2, {i_1, i_2},
825 calc_options & (OptionsForGradCalculation::D12 |
827 {&D1, &D2, &D12}, derivatives_pt, invr2_scratch,
828 deriv2_scratch);
829
830 // The cross derivative of two different atoms comes back
831 // with the opposite sign from the Matlab convention. D12
832 // holds only this pair, so one negation corrects it.
833 for (Eigen::Index n = 0; n < D12.size(); ++n) {
834 *(D12.data() + n) *= -1;
835 }
836
837 if (calc_options & OptionsForGradCalculation::D12_pt) {
838 for (size_t n = 0; n < derivatives_pt.D12.size(); ++n) {
839 for (Eigen::Index m = 0;
840 m < derivatives_pt.D12[n].size(); ++m) {
841 *(derivatives_pt.D12[n].data() + m) *= -1.;
842 }
843 }
844 }
845 } else {
846 i = i_1;
847
848 if (N_mov > 1) {
849 for (Eigen::Index j = 0; j < N_mov; ++j) {
850 if (i != j) {
851 calculateGradientBetweenMovingAtoms(
852 x1, x2, conf_info, lengthScale, xyz_1, xyz_2,
853 {i, j}, calc_options, {&D1, &D2, &D12},
854 derivatives_pt, invr2_scratch, deriv2_scratch);
855 }
856 }
857 }
858
859 if (N_fro > 0) {
860 for (Eigen::Index j = 0; j < N_fro; ++j) {
861 calculateGradientBetweenMovingAndFrozenAtoms(
862 x1, x2, conf_info, lengthScale, xyz_1, xyz_2,
863 {i, j}, calc_options, {&D1, &D2, &D12},
864 derivatives_pt, invr2_scratch, deriv2_scratch);
865 }
866 accumulateFarFieldDerivatives(
867 x1, x2, conf_info, lengthScale, i, xyz_1, xyz_2,
868 calc_options, D1, D2, D12, derivatives_pt);
869 }
870 }
871
872 pushBackDerivativeField(calc_options, OptionsForGradCalculation::D1,
873 D1, derivatives.D1);
874
875 pushBackDerivativeField(calc_options, OptionsForGradCalculation::D2,
876 D2, derivatives.D2);
877
878 pushBackDerivativeField(calc_options,
880 derivatives.D12);
881 }
882 }
883}
884
886{
887 if (!(radius >= 0.0) || !std::isfinite(radius)) {
888 throw std::invalid_argument(
889 "far-field radius must be finite and non-negative");
890 }
891 far_field_radius_ = radius;
892}
893
894void Gradient::accumulateFarFieldDerivatives(
895 const gpr::Coord& x1, const gpr::Coord& x2,
896 const gpr::AtomsConfiguration& conf_info,
897 const gpr::FieldMatrixd& lengthScale, gpr::Index_t moving,
898 gpr::Index_t direction_x1, gpr::Index_t direction_x2, uint8_t calc_options,
900 gpr::Derivatives<std::vector<gpr::FieldMatrixd>>& derivatives_pt) const
901{
902 if (!(far_field_radius_ > 0.0) || x1.rows() == 0 || x2.rows() == 0) return;
903 const Eigen::Index n_frozen = conf_info.atoms_froz_active.type.size();
904 if (n_frozen == 0) return;
905 const Eigen::Index n_pt =
906 lengthScale.size() == 1 ? conf_info.n_pt : lengthScale.size();
907 if (n_pt <= 0) return;
908 const gpr::geometry::PairBox box(conf_info.cell);
909 const double* frozen = conf_info.atoms_froz_active.positions.data();
910 const double* centre = farFieldCentre(conf_info, moving);
911 std::vector<std::array<double, 9>> tensor(static_cast<std::size_t>(n_pt));
912 bool any = false;
913 for (Eigen::Index i = 0; i < n_frozen; ++i) {
914 const double* source = frozen + 3 * i;
915 if (!farFromCentre(box, centre, source, far_field_radius_)) continue;
916 const gpr::Index_t pt =
917 conf_info.pairtype(conf_info.atoms_mov.type(0, moving),
918 conf_info.atoms_froz_active.type(0, i));
919 if (pt == static_cast<gpr::Index_t>(EMPTY) ||
920 static_cast<Eigen::Index>(pt) >= n_pt)
921 continue;
922 const double length = lengthScale.size() == 1
923 ? lengthScale(0, 0)
924 : *(lengthScale.data() + pt);
925 const double two_s2 = 2.0 / (length * length);
926 double r[3];
927 box.displacement(source, centre, r);
928 double block[3][3];
929 for (int a = 0; a < 9; ++a)
930 block[a / 3][a % 3] = tensor[static_cast<std::size_t>(pt)][a];
931 addFarSource(block, r, two_s2);
932 for (int a = 0; a < 9; ++a)
933 tensor[static_cast<std::size_t>(pt)][a] = block[a / 3][a % 3];
934 any = true;
935 }
936 if (!any) return;
937 const int dx1 = static_cast<int>(direction_x1);
938 const int dx2 = static_cast<int>(direction_x2);
939 const double* x1_data = x1.data();
940 const double* x2_data = x2.data();
941 const Eigen::Index x1_cols = x1.cols();
942 const Eigen::Index x2_cols = x2.cols();
943 const Eigen::Index off = 3 * static_cast<Eigen::Index>(moving);
944 for (Eigen::Index n = 0; n < x1.rows(); ++n) {
945 const double* left = x1_data + n * x1_cols + off;
946 for (Eigen::Index m = 0; m < x2.rows(); ++m) {
947 const double* right = x2_data + m * x2_cols + off;
948 double delta[3];
949 farFieldDifference(box, centre, left, right, delta);
950 for (Eigen::Index pt = 0; pt < n_pt; ++pt) {
951 double block[3][3];
952 const auto& stored = tensor[static_cast<std::size_t>(pt)];
953 for (int a = 0; a < 9; ++a)
954 block[a / 3][a % 3] = stored[a];
955 double contracted[3];
956 farContract(block, delta, contracted);
957 if (calc_options & OptionsForGradCalculation::D1) {
958 const double d1 = 2.0 * contracted[dx1];
959 D1(n, m) += d1;
960 if (calc_options & OptionsForGradCalculation::D1_pt)
961 derivatives_pt.D1[static_cast<std::size_t>(pt)](n, m) -=
962 d1;
963 }
964 if (calc_options & OptionsForGradCalculation::D2) {
965 const double d2 = -2.0 * contracted[dx2];
966 D2(n, m) += d2;
967 if (calc_options & OptionsForGradCalculation::D2_pt)
968 derivatives_pt.D2[static_cast<std::size_t>(pt)](n, m) -=
969 d2;
970 }
971 if (calc_options & OptionsForGradCalculation::D12) {
972 const double d12 = -2.0 * block[dx1][dx2];
973 D12(n, m) += d12;
974 if (calc_options & OptionsForGradCalculation::D12_pt)
975 derivatives_pt.D12[static_cast<std::size_t>(pt)](
976 n, m) -= d12;
977 }
978 }
979 }
980 }
981}
982
983} /* namespace aux */
@ D1_pt
Definition Enums.h:23
@ D1
Definition Enums.h:19
@ D12
Definition Enums.h:21
@ D2_pt
Definition Enums.h:24
@ D2
Definition Enums.h:20
@ D12_pt
Definition Enums.h:25
#define EMPTY
Definition Macros.h:39
void setFarFieldRadius(double radius)
Definition Gradient.cpp:885
void calculateDerivativesDiffDim(const gpr::Coord &x1, const gpr::Coord &x2, const gpr::AtomsConfiguration &conf_info, const gpr::FieldMatrixd &lengthScale, const gpr::FieldMatrixIdx &dims1, const gpr::FieldMatrixIdx &dims2, const uint8_t calc_options, const uint8_t direction_x2, gpr::Derivatives< std::vector< gpr::FieldMatrixd > > &derivatives, gpr::Derivatives< std::vector< gpr::FieldMatrixd > > &derivatives_pt)
Evaluate gradient of covariance function, of which has been taken partial derivatives with respect to...
Definition Gradient.cpp:655
void calculateDerivativesSameDim(const gpr::Coord &x1, const gpr::Coord &x2, const gpr::AtomsConfiguration &conf_info, const gpr::FieldMatrixd &lengthScale, const gpr::FieldMatrixIdx &dims, uint8_t calc_options, gpr::Derivatives< std::vector< gpr::FieldMatrixd > > &derivatives, gpr::Derivatives< std::vector< gpr::FieldMatrixd > > &derivatives_pt)
Evaluate gradient of covariance function with respect to both input variables x and x2 (in same dimen...
Definition Gradient.cpp:555
bool farFromCentre(const gpr::geometry::PairBox &box, const double centre[3], const double frozen[3], double radius)
Definition FarField.h:81
void farFieldDifference(const gpr::geometry::PairBox &box, const double centre[3], const double left[3], const double right[3], double delta[3])
Definition FarField.h:36
void addFarSource(double tensor[3][3], const double r[3], double weight)
Definition FarField.h:49
void farContract(const double tensor[3][3], const double delta[3], double out[3])
Definition FarField.h:71
const double * farFieldCentre(const gpr::AtomsConfiguration &conf, Eigen::Index atom)
Definition FarField.h:15
Eigen::Matrix< Index_t, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixIdx
Definition Macros.h:29
void forEachCutoffPair(const CutoffPairFeatures &left, const CutoffPairFeatures &right, Function &&function)
Visit the union of two sparse feature rows in their common pair vocabulary.
Definition PairCutoff.h:105
FieldMatrixd Coord
Definition Macros.h:35
uint32_t Index_t
Definition Macros.h:17
std::vector< CutoffPairFeatures > radialPairFeatures(const Coord &positions, const AtomsConfiguration &configuration)
Eigen::Matrix< double, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixd
Definition Macros.h:25
Stores configurations of all atoms in the system.
Definition Structures.h:832
AtomsPositionAndType atoms_froz_active
Info on active frozen atoms.
Definition Structures.h:841
AtomsPositionAndType atoms_mov
Info on moving atoms.
Definition Structures.h:844
double derivative(Eigen::Index coordinate) const
Definition PairCutoff.h:81
Structure of directional derivatives.
Definition Structures.h:63
Eigen::Index j
Definition Structures.h:74
Eigen::Index i
Definition Structures.h:73