MRMD 0.4.0
Multi Resolution Molecular Dynamics
Loading...
Searching...
No Matches
UpdateMolecules.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 "data/Atoms.hpp"
18#include "data/Molecules.hpp"
19#include "datatypes.hpp"
20
22{
23
24template <typename WEIGHTING_FUNCTION>
25static void update(const data::Molecules& molecules,
26 const data::Atoms& atoms,
27 const WEIGHTING_FUNCTION& weight)
28{
29 auto moleculesPos = molecules.getPos();
30 auto moleculesLambda = molecules.getLambda();
31 auto moleculesModulatedLambda = molecules.getModulatedLambda();
32 auto moleculesGradLambda = molecules.getGradLambda();
33 auto moleculesAtomsOffset = molecules.getAtomsOffset();
34 auto moleculesNumAtoms = molecules.getNumAtoms();
35
36 auto atomsPos = atoms.getPos();
37 auto atomsRelativeMass = atoms.getRelativeMass();
38
39 auto policy =
40 Kokkos::RangePolicy<>(0, molecules.numLocalMolecules + molecules.numGhostMolecules);
41 auto kernel = KOKKOS_LAMBDA(const idx_t& moleculeIdx)
42 {
43 auto atomsStart = moleculesAtomsOffset(moleculeIdx);
44 auto atomsEnd = atomsStart + moleculesNumAtoms(moleculeIdx);
45
46 moleculesPos(moleculeIdx, 0) = 0_r;
47 moleculesPos(moleculeIdx, 1) = 0_r;
48 moleculesPos(moleculeIdx, 2) = 0_r;
49
50 for (auto atomIdx = atomsStart; atomIdx < atomsEnd; ++atomIdx)
51 {
52 assert(atomsRelativeMass(atomIdx) > 1e-8 &&
53 "Contribution almost zero. Did you forget to set relative mass?");
54 moleculesPos(moleculeIdx, 0) += atomsPos(atomIdx, 0) * atomsRelativeMass(atomIdx);
55 moleculesPos(moleculeIdx, 1) += atomsPos(atomIdx, 1) * atomsRelativeMass(atomIdx);
56 moleculesPos(moleculeIdx, 2) += atomsPos(atomIdx, 2) * atomsRelativeMass(atomIdx);
57 }
58
59 weight(moleculesPos(moleculeIdx, 0),
60 moleculesPos(moleculeIdx, 1),
61 moleculesPos(moleculeIdx, 2),
62 moleculesLambda(moleculeIdx),
63 moleculesModulatedLambda(moleculeIdx),
64 moleculesGradLambda(moleculeIdx, 0),
65 moleculesGradLambda(moleculeIdx, 1),
66 moleculesGradLambda(moleculeIdx, 2));
67 };
68 Kokkos::parallel_for("UpdateMolecules::update", policy, kernel);
69 Kokkos::fence();
70}
71
72} // namespace mrmd::action::UpdateMolecules
Data structure for storing information about atoms on the host and the device.
Definition Atoms.hpp:35
KOKKOS_FORCEINLINE_FUNCTION relative_mass_t getRelativeMass() const
Definition Atoms.hpp:70
KOKKOS_FORCEINLINE_FUNCTION pos_t getPos() const
Definition Atoms.hpp:64
Definition Molecules.hpp:29
KOKKOS_FORCEINLINE_FUNCTION atoms_offset_t getAtomsOffset() const
Definition Molecules.hpp:67
KOKKOS_FORCEINLINE_FUNCTION num_atoms_t getNumAtoms() const
Definition Molecules.hpp:68
KOKKOS_FORCEINLINE_FUNCTION pos_t getPos() const
Definition Molecules.hpp:58
KOKKOS_FORCEINLINE_FUNCTION modulated_lambda_t getModulatedLambda() const
Definition Molecules.hpp:62
idx_t numGhostMolecules
Definition Molecules.hpp:121
KOKKOS_FORCEINLINE_FUNCTION lambda_t getLambda() const
Definition Molecules.hpp:61
idx_t numLocalMolecules
Definition Molecules.hpp:120
KOKKOS_FORCEINLINE_FUNCTION grad_lambda_t getGradLambda() const
Definition Molecules.hpp:66
Definition UpdateMolecules.hpp:22
static void update(const data::Molecules &molecules, const data::Atoms &atoms, const WEIGHTING_FUNCTION &weight)
Definition UpdateMolecules.hpp:25
int64_t idx_t
Definition datatypes.hpp:91