Multi Resolution Molecular Dynamics 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{
31{
32private:
33 const Point3D center_;
34 const real_t atomisticRadius_;
35 const real_t atomisticRadiusSqr_;
36 const real_t hybridRegionDiameter_;
37 const real_t coarseRadiusSqr_;
38 const int exponent_;
39
40public:
41 KOKKOS_INLINE_FUNCTION
42 void operator()(const real_t x,
43 const real_t y,
44 const real_t z,
45 real_t& lambda,
46 real_t& gradLambdaX,
47 real_t& gradLambdaY,
48 real_t& gradLambdaZ) const
49 {
50 real_t dx[3] = {x - center_[0], y - center_[1], z - center_[2]};
51 auto dxSqr = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2];
52
53 if (dxSqr < atomisticRadiusSqr_)
54 {
55 lambda = 1_r;
56 gradLambdaX = 0_r;
57 gradLambdaY = 0_r;
58 gradLambdaZ = 0_r;
59 return;
60 }
61 if (dxSqr > coarseRadiusSqr_)
62 {
63 lambda = 0_r;
64 gradLambdaX = 0_r;
65 gradLambdaY = 0_r;
66 gradLambdaZ = 0_r;
67 return;
68 }
69
70 const auto r = std::sqrt(dxSqr);
71 const real_t arg = pi / (2_r * hybridRegionDiameter_) * (r - atomisticRadius_);
72 auto base = std::cos(arg);
73 lambda = util::powInt(base, exponent_);
74
75 auto factor = -pi / (2_r * hybridRegionDiameter_) * real_c(exponent_) * std::sin(arg) *
76 util::powInt(base, exponent_ - 1) / r;
77 gradLambdaX = factor * dx[0];
78 gradLambdaY = factor * dx[1];
79 gradLambdaZ = factor * dx[2];
80 }
81
82 KOKKOS_INLINE_FUNCTION
83 real_t operator()(const real_t x, const real_t y, const real_t z) const
84 {
85 real_t lambda;
86 real_t tmp;
87 operator()(x, y, z, lambda, tmp, tmp, tmp);
88 return lambda;
89 }
90
91 Spherical(const Point3D& center,
92 const real_t atomisticRadius,
93 const real_t hybridRegionDiameter,
94 const int exponent)
95 : center_(center),
96 atomisticRadius_(atomisticRadius),
97 hybridRegionDiameter_(hybridRegionDiameter),
98 exponent_(exponent),
99 atomisticRadiusSqr_(atomisticRadius * atomisticRadius),
100 coarseRadiusSqr_((atomisticRadius + hybridRegionDiameter) *
101 (atomisticRadius + hybridRegionDiameter))
102 {
103 }
104};
105} // namespace weighting_function
106} // namespace mrmd
KOKKOS_INLINE_FUNCTION real_t operator()(const real_t x, const real_t y, const real_t z) const
Definition Spherical.hpp:83
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:42
Spherical(const Point3D &center, const real_t atomisticRadius, const real_t hybridRegionDiameter, const int exponent)
Definition Spherical.hpp:91
KOKKOS_INLINE_FUNCTION real_t powInt(const real_t &x, const idx_t n)
Definition math.hpp:31
Weighting functions for different interfaces and region geometries.
Top-level namespace of MRMD.
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
Kokkos::Array< real_t, 3 > Point3D
Definition datatypes.hpp:100