Tinker9 70bd052 (Thu Nov 9 12:11:35 2023 -0800)
Loading...
Searching...
No Matches
rcman.h
1#pragma once
2#include "tool/macro.h"
3#include <type_traits>
4
5namespace tinker {
6inline namespace v1 {
9template <class E>
11{
12 static constexpr bool value = false;
13};
14}
15
20#define TINKER_ENABLE_ENUM_BITMASK(x) \
21 template <> \
22 struct EnableEnumBitMask<x> \
23 { \
24 static constexpr bool value = true; \
25 }
26
28template <class E>
29constexpr typename std::enable_if<EnableEnumBitMask<E>::value, E>::type
30operator|(E lhs, E rhs)
31{
32 using ut = typename std::underlying_type<E>::type;
33 return static_cast<E>(static_cast<ut>(lhs) | static_cast<ut>(rhs));
34}
35
37template <class E>
38constexpr bool operator&(E lhs, E rhs)
39{
40 using ut = typename std::underlying_type<E>::type;
41 return static_cast<bool>(static_cast<ut>(lhs) & static_cast<ut>(rhs));
42}
43
46{
47 DEALLOC = 0x001,
48 ALLOC = 0x002,
49 INIT = 0x004
50};
55
72{
73private:
74 void (*m_f)(RcOp); // pointer to function void fooData(RcOp);
75 RcOp m_op;
76
77public:
80 ResourceManagement(void (*f)(RcOp), RcOp op);
82};
83
87
91}
92
93extern "C"
94{
95 struct Eng;
96 struct EngGradVir;
97 struct EngAlyz;
98 struct EngGrad;
99 struct Grad;
100 struct GradVir;
101}
102
103namespace tinker {
106struct calc
107{
108 static constexpr int xyz = 0x001;
109 static constexpr int vel = 0x002;
110 static constexpr int mass = 0x004;
111 static constexpr int traj = 0x008;
112
113 static constexpr int energy = 0x010;
114 static constexpr int grad = 0x020;
115 static constexpr int virial = 0x040;
116 static constexpr int analyz = 0x080;
117 static constexpr int md = 0x100;
118
120 static constexpr int vmask = energy + grad + virial + analyz;
122 static constexpr int v0 = energy;
125 static constexpr int v1 = energy + grad + virial;
128 static constexpr int v3 = energy + analyz;
130 static constexpr int v4 = energy + grad;
132 static constexpr int v5 = grad;
134 static constexpr int v6 = grad + virial;
135
136 using V0 = Eng;
137 using V1 = EngGradVir;
138 using V3 = EngAlyz;
139 using V4 = EngGrad;
140 using V5 = Grad;
141 using V6 = GradVir;
142
144 template <int USE>
145 class Vers
146 {
147 public:
148 static constexpr int value = USE;
149 static constexpr int e = USE & calc::energy;
150 static constexpr int a = USE & calc::analyz;
151 static constexpr int g = USE & calc::grad;
152 static constexpr int v = USE & calc::virial;
153 static_assert(v ? (bool)g : true, "If calc::virial, must calc::grad.");
154 static_assert(a ? (bool)e : true, "If calc::analyz, must calc::energy.");
155 };
156};
157}
158
159extern "C"
160{
161 struct Eng : public tinker::calc::Vers<tinker::calc::v0>
162 {};
163 struct EngGradVir : public tinker::calc::Vers<tinker::calc::v1>
164 {};
165 struct EngAlyz : public tinker::calc::Vers<tinker::calc::v3>
166 {};
167 struct EngGrad : public tinker::calc::Vers<tinker::calc::v4>
168 {};
169 struct Grad : public tinker::calc::Vers<tinker::calc::v5>
170 {};
171 struct GradVir : public tinker::calc::Vers<tinker::calc::v6>
172 {};
173}
174
175//====================================================================//
176// //
177// Global Variables //
178// //
179//====================================================================//
180
181namespace tinker {
185}
Sanity checks for version constants.
Definition: rcman.h:146
static constexpr int g
Definition: rcman.h:151
static constexpr int value
Definition: rcman.h:148
static constexpr int e
Definition: rcman.h:149
static constexpr int a
Definition: rcman.h:150
static constexpr int v
Definition: rcman.h:152
#define TINKER_EXTERN
Definition: macro.h:108
static constexpr int xyz
Use coordinates.
Definition: rcman.h:108
static constexpr int v4
Energy and gradient.
Definition: rcman.h:130
static constexpr int md
Run MD simulation.
Definition: rcman.h:117
static constexpr int v3
Definition: rcman.h:128
static constexpr int mass
Use mass.
Definition: rcman.h:110
static constexpr bool value
Definition: rcman.h:12
static constexpr int virial
Evaluate virial tensor.
Definition: rcman.h:115
static constexpr int grad
Evaluate energy gradient.
Definition: rcman.h:114
static constexpr int analyz
Evaluate number of interactions.
Definition: rcman.h:116
static constexpr int traj
Use multi-frame trajectory.
Definition: rcman.h:111
ResourceManagement(void(*f)(RcOp), RcOp op)
static constexpr int v0
Similar to Tinker energy routines. Energy only.
Definition: rcman.h:122
static constexpr int v6
Gradient and virial.
Definition: rcman.h:134
static constexpr int v5
Gradient only.
Definition: rcman.h:132
static constexpr int v1
Definition: rcman.h:125
static constexpr int energy
Evaluate energy.
Definition: rcman.h:113
static constexpr int vel
Use velocities.
Definition: rcman.h:109
static constexpr int vmask
Bits mask to clear energy-irrelevant flags.
Definition: rcman.h:120
Resource management. Allocates resources in the object constructor and deallocates resources in the o...
Definition: rcman.h:72
#define TINKER_ENABLE_ENUM_BITMASK(x)
Explicitly enables mathematical calculation by casting enum class to integer.
Definition: rcman.h:20
ResourceOperation RcOp
Definition: rcman.h:54
constexpr bool operator&(E lhs, E rhs)
Definition: rcman.h:38
constexpr std::enable_if< EnableEnumBitMask< E >::value, E >::type operator|(E lhs, E rhs)
Definition: rcman.h:30
ResourceOperation
Definition: rcman.h:46
void deviceData(RcOp)
Set up and clean up device environment.
int rc_flag
Global bitmask.
@ ALLOC
Allocates resource.
@ DEALLOC
Deallocates resource.
@ INIT
Initializes resource.
Bitmasks for MD.
Definition: rcman.h:107
Direct mathematical calculation of enum class is prohibited in C++.
Definition: rcman.h:11
Definition: testrt.h:9
Definition: rcman.h:166
Definition: rcman.h:168
Definition: rcman.h:164
Definition: rcman.h:162
Definition: rcman.h:170
Definition: rcman.h:172