Loading...
Searching...
No Matches
ForceNorm.h
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
12#pragma once
13
14#include <algorithm>
15#include <cmath>
16
17namespace eonc {
18
19namespace detail {
20
25inline double maxFreeAtomForceNormScalar(const double *forces,
26 const double *fixed, long begin,
27 long nAtoms) {
28 double best = 0.0;
29 if (forces == nullptr || nAtoms <= 0 || begin >= nAtoms) {
30 return best;
31 }
32 if (begin < 0) {
33 begin = 0;
34 }
35 for (long i = begin; i < nAtoms; ++i) {
36 if (fixed != nullptr) {
37 const double *mask = fixed + 3 * i;
38 if (mask[0] > 0.5 && mask[1] > 0.5 && mask[2] > 0.5) {
39 continue;
40 }
41 }
42 const double *row = forces + 3 * i;
43 const double xx = row[0] * row[0];
44 const double yy = row[1] * row[1];
45 const double zz = row[2] * row[2];
46 const double norm = std::sqrt((xx + yy) + zz);
47 if (std::isnan(norm)) {
48 return norm;
49 }
50 best = std::max(best, norm);
51 }
52 return best;
53}
54
55} // namespace detail
56
62[[nodiscard]] double maxFreeAtomForceNorm(const double *forces,
63 const double *fixed, long nAtoms);
64
65} // namespace eonc
double maxFreeAtomForceNormScalar(const double *forces, const double *fixed, long begin, long nAtoms)
Scalar max of per-atom Euclidean norms on [begin, nAtoms).
Definition ForceNorm.h:25
RAII resource manager for the ARTn C library with global synchronization.
double maxFreeAtomForceNorm(const double *forces, const double *fixed, long nAtoms)
Max Euclidean norm over N x 3 row-major force rows.