MRMD 0.4.0
Multi Resolution Molecular Dynamics
Loading...
Searching...
No Matches
Spherical.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 "constants.hpp"
18#include "datatypes.hpp"
19#include "util/math.hpp"
20
21namespace mrmd
22{
23namespace weighting_function
24{
26{
27private:
28 const Point3D center_;
29 const real_t atomisticRadius_;
30 const real_t atomisticRadiusSqr_;
31 const real_t hybridRegionDiameter_;
32 const real_t coarseRadiusSqr_;
33 const int exponent_;
34
35public:
36 KOKKOS_INLINE_FUNCTION
37 void operator()(const real_t x,
38 const real_t y,
39 const real_t z,
40 real_t& lambda,
41 real_t& gradLambdaX,
42 real_t& gradLambdaY,
43 real_t& gradLambdaZ) const
44 {
45 real_t dx[3] = {x - center_[0], y - center_[1], z - center_[2]};
46 auto dxSqr = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
47
48 if (dxSqr < atomisticRadiusSqr_)
49 {
50 lambda = 1_r;
51 gradLambdaX = 0_r;
52 gradLambdaY = 0_r;
53 gradLambdaZ = 0_r;
54 return;
55 }
56 if (dxSqr > coarseRadiusSqr_)
57 {
58 lambda = 0_r;
59 gradLambdaX = 0_r;
60 gradLambdaY = 0_r;
61 gradLambdaZ = 0_r;
62 return;
63 }
64
65 const auto r = std::sqrt(dxSqr);
66 const real_t arg = pi / (2_r * hybridRegionDiameter_) * (r - atomisticRadius_);
67 auto base = std::cos(arg);
68 lambda = util::powInt(base, exponent_);
69
70 auto factor = -pi / (2_r * hybridRegionDiameter_) * real_c(exponent_) * std::sin(arg) *
71 util::powInt(base, exponent_ - 1) / r;
72 gradLambdaX = factor * dx[0];
73 gradLambdaY = factor * dx[1];
74 gradLambdaZ = factor * dx[2];
75 }
76
77 KOKKOS_INLINE_FUNCTION
78 real_t operator()(const real_t x, const real_t y, const real_t z) const
79 {
80 real_t lambda;
81 real_t tmp;
82 operator()(x, y, z, lambda, tmp, tmp, tmp);
83 return lambda;
84 }
85
86 Spherical(const Point3D& center,
87 const real_t atomisticRadius,
88 const real_t hybridRegionDiameter,
89 const int exponent)
90 : center_(center),
91 atomisticRadius_(atomisticRadius),
92 hybridRegionDiameter_(hybridRegionDiameter),
93 exponent_(exponent),
94 atomisticRadiusSqr_(atomisticRadius * atomisticRadius),
95 coarseRadiusSqr_((atomisticRadius + hybridRegionDiameter) *
96 (atomisticRadius + hybridRegionDiameter))
97 {
98 }
99};
100} // namespace weighting_function
101} // namespace mrmd
Definition Spherical.hpp:26
KOKKOS_INLINE_FUNCTION real_t operator()(const real_t x, const real_t y, const real_t z) const
Definition Spherical.hpp:78
KOKKOS_INLINE_FUNCTION void operator()(const real_t x, const real_t y, const real_t z, real_t &lambda, real_t &gradLambdaX, real_t &gradLambdaY, real_t &gradLambdaZ) const
Definition Spherical.hpp:37
Spherical(const Point3D &center, const real_t atomisticRadius, const real_t hybridRegionDiameter, const int exponent)
Definition Spherical.hpp:86
KOKKOS_INLINE_FUNCTION real_t powInt(const real_t &x, const idx_t n)
Definition math.hpp:31
Definition BerendsenBarostat.cpp:18
Kokkos::Array< real_t, 3 > Point3D
Definition datatypes.hpp:100
constexpr auto pi
Definition constants.hpp:26
double real_t
Definition datatypes.hpp:99
KOKKOS_INLINE_FUNCTION constexpr real_t real_c(T t)
Definition datatypes.hpp:114