MRMD 0.4.0
Multi Resolution Molecular Dynamics
Loading...
Searching...
No Matches
math.hpp
Go to the documentation of this file.
1// Copyright 2024 Sebastian Eibl
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include "datatypes.hpp"
18
19namespace mrmd
20{
21namespace util
22{
23KOKKOS_INLINE_FUNCTION
24real_t dot3(real_t const* const a, real_t const* const b)
25{
26 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
27}
28
29KOKKOS_INLINE_FUNCTION real_t sqr(const real_t& sqr) { return sqr * sqr; }
30
31KOKKOS_INLINE_FUNCTION real_t powInt(const real_t& x, const idx_t n)
32{
33 auto ww = x;
34 auto yy = 1_r;
35
36 for (idx_t nn = (n > 0) ? n : -n; nn != 0; nn >>= 1)
37 {
38 if ((nn & 1) == 1)
39 {
40 yy *= ww;
41 }
42 ww *= ww;
43 }
44
45 return (n > 0) ? yy : 1.0 / yy;
46}
47
58KOKKOS_INLINE_FUNCTION real_t approxErfc(const real_t& x, real_t& expX2)
59{
60 assert(x > 0_r);
61
62 constexpr auto p = 0.3275911_r;
63 constexpr auto a1 = 0.254829592_r;
64 constexpr auto a2 = -0.284496736_r;
65 constexpr auto a3 = 1.421413741_r;
66 constexpr auto a4 = -1.453152027_r;
67 constexpr auto a5 = 1.061405429_r;
68 auto t = 1_r / (1_r + p * x);
69 expX2 = std::exp(-x * x);
70 return t * (a1 + t * (a2 + t * (a3 + t * (a4 + t * a5)))) * expX2;
71}
72
73KOKKOS_INLINE_FUNCTION real_t approxErfc(const real_t& x)
74{
75 [[maybe_unused]] real_t tmp;
76 return approxErfc(x, tmp);
77}
78
79} // namespace util
80} // namespace mrmd
KOKKOS_INLINE_FUNCTION real_t sqr(const real_t &sqr)
Definition math.hpp:29
KOKKOS_INLINE_FUNCTION real_t approxErfc(const real_t &x, real_t &expX2)
"Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Table" Milton Abramowitz ...
Definition math.hpp:58
KOKKOS_INLINE_FUNCTION real_t powInt(const real_t &x, const idx_t n)
Definition math.hpp:31
KOKKOS_INLINE_FUNCTION real_t dot3(real_t const *const a, real_t const *const b)
Definition math.hpp:24
Definition BerendsenBarostat.cpp:18
int64_t idx_t
Definition datatypes.hpp:91
double real_t
Definition datatypes.hpp:99