Line data Source code
1 : #pragma once
2 :
3 : #include "tarch/utils/Utils.h"
4 :
5 : namespace simplemd {
6 : namespace moleculemappings {
7 : class ConvertForcesFloatToFixedMapping;
8 : }
9 : } // namespace simplemd
10 :
11 : /*
12 : * fixed-point math for force accumulation
13 : * only active in debug mode, useful for verification of simulation results
14 : * because results do not depend on order of force summation
15 : * this expects forces to contain long int and converts them back into double
16 : */
17 : class simplemd::moleculemappings::ConvertForcesFloatToFixedMapping {
18 : public:
19 : void beginMoleculeIteration() const {}
20 :
21 0 : KOKKOS_FUNCTION void handleMolecule(simplemd::Molecule& molecule) const {
22 0 : DEFINE_DECIMAL_FP_LIMITS(6);
23 :
24 0 : tarch::la::Vector<MD_DIM, double> force = stepFP6 * molecule.getForce();
25 0 : long long fb0{(long long)(force[0])};
26 0 : long long fb1{(long long)(force[1])};
27 0 : long long fb2{(long long)(force[2])};
28 0 : long long& fb0r = fb0;
29 0 : long long& fb1r = fb1;
30 0 : long long& fb2r = fb2;
31 0 : molecule.getForce()[0] = *(double*)(&fb0r);
32 0 : molecule.getForce()[1] = *(double*)(&fb1r);
33 0 : molecule.getForce()[2] = *(double*)(&fb2r);
34 0 : }
35 :
36 : void endMoleculeIteration() const {}
37 :
38 : static const bool IsParallel = true;
39 : };
|