Tinker9 70bd052 (Thu Nov 9 12:11:35 2023 -0800)
Loading...
Searching...
No Matches
image.h
1#pragma once
2#include "ff/box.h"
3#include "math/libfunc.h"
4#include "seq/seq.h"
5
6namespace tinker {
9
14
16#define IMAGE_TRI__(xr, yr, zr, l1, l2, l3, ra, rb, rc) \
17 { \
18 real fx = REAL_FLOOR(0.5f + zr * ra.z + yr * ra.y + xr * ra.x); \
19 real fy = REAL_FLOOR(0.5f + zr * rb.z + yr * rb.y); \
20 real fz = REAL_FLOOR(0.5f + zr * rc.z); \
21 xr -= (fz * l1.z + fy * l1.y + fx * l1.x); \
22 yr -= (fz * l2.z + fy * l2.y); \
23 zr -= (fz * l3.z); \
24 }
25
27#define IMAGE_MONO__(xr, yr, zr, l1, l2, l3, ra, rb, rc) \
28 { \
29 real fx = REAL_FLOOR(0.5f + zr * ra.z + xr * ra.x); \
30 real fy = REAL_FLOOR(0.5f + yr * rb.y); \
31 real fz = REAL_FLOOR(0.5f + zr * rc.z); \
32 xr -= (fz * l1.z + fx * l1.x); \
33 yr -= (fy * l2.y); \
34 zr -= (fz * l3.z); \
35 }
36
38#define IMAGE_ORTHO__(xr, yr, zr, l1, l2, l3, ra, rb, rc) \
39 { \
40 real fx = REAL_FLOOR(0.5f + xr * ra.x); \
41 real fy = REAL_FLOOR(0.5f + yr * rb.y); \
42 real fz = REAL_FLOOR(0.5f + zr * rc.z); \
43 xr -= (fx * l1.x); \
44 yr -= (fy * l2.y); \
45 zr -= (fz * l3.z); \
46 }
47
49#define IMAGE_OCT__(xr, yr, zr, l1, l2, l3, ra, rb, rc) \
50 { \
51 real fx = xr * ra.x; \
52 real fy = yr * ra.x; \
53 real fz = zr * ra.x; \
54 fx -= REAL_FLOOR(0.5f + fx); \
55 fy -= REAL_FLOOR(0.5f + fy); \
56 fz -= REAL_FLOOR(0.5f + fz); \
57 if (REAL_ABS(fx) + REAL_ABS(fy) + REAL_ABS(fz) > 0.75f) { \
58 fx -= REAL_SIGN(0.5f, fx); \
59 fy -= REAL_SIGN(0.5f, fy); \
60 fz -= REAL_SIGN(0.5f, fz); \
61 } \
62 xr = fx * l1.x; \
63 yr = fy * l1.x; \
64 zr = fz * l1.x; \
65 }
66
68
69inline namespace v1 {
71{
73 static void img(real& restrict xr, real& restrict yr, real& restrict zr, real3 l1, real3 l2,
74 real3 l3, real3 ra, real3 rb, real3 rc)
75 {
76 IMAGE_ORTHO__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
77 }
78
79public:
81 static real img2(real& restrict xr, real& restrict yr, real& restrict zr, real3 l1, real3 l2,
82 real3 l3, real3 ra, real3 rb, real3 rc)
83 {
84 img(xr, yr, zr, l1, l2, l3, ra, rb, rc);
85 return xr * xr + yr * yr + zr * zr;
86 }
87};
88
90{
92 static void img(real& restrict xr, real& restrict yr, real& restrict zr, real3 l1, real3 l2,
93 real3 l3, real3 ra, real3 rb, real3 rc)
94 {
95 IMAGE_MONO__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
96 }
97
98public:
100 static real img2(real& restrict xr, real& restrict yr, real& restrict zr, real3 l1, real3 l2,
101 real3 l3, real3 ra, real3 rb, real3 rc)
102 {
103 img(xr, yr, zr, l1, l2, l3, ra, rb, rc);
104 return xr * xr + yr * yr + zr * zr;
105 }
106};
107
109{
111 static void img(real& restrict xr, real& restrict yr, real& restrict zr, real3 l1, real3 l2,
112 real3 l3, real3 ra, real3 rb, real3 rc)
113 {
114 IMAGE_TRI__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
115 }
116
117public:
119 static real img2(real& restrict xr, real& restrict yr, real& restrict zr, real3 l1, real3 l2,
120 real3 l3, real3 ra, real3 rb, real3 rc)
121 {
122 img(xr, yr, zr, l1, l2, l3, ra, rb, rc);
123 return xr * xr + yr * yr + zr * zr;
124 }
125};
126
128{
130 static void img(real& restrict xr, real& restrict yr, real& restrict zr, real3 l1, real3 l2,
131 real3 l3, real3 ra, real3 rb, real3 rc)
132 {
133 IMAGE_OCT__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
134 }
135
136public:
138 static real img2(real& restrict xr, real& restrict yr, real& restrict zr, real3 l1, real3 l2,
139 real3 l3, real3 ra, real3 rb, real3 rc)
140 {
141 img(xr, yr, zr, l1, l2, l3, ra, rb, rc);
142 return xr * xr + yr * yr + zr * zr;
143 }
144};
145
147{
148public:
151 real3, real3, real3)
152 {
153 return xr * xr + yr * yr + zr * zr;
154 }
155};
156
159 real3 l1, real3 l2, real3 l3, real3 ra, real3 rb, real3 rc)
160{
161 if (sh == BoxShape::ORTHO) {
162 IMAGE_ORTHO__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
163 } else if (sh == BoxShape::MONO) {
164 IMAGE_MONO__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
165 } else if (sh == BoxShape::TRI) {
166 IMAGE_TRI__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
167 } else if (sh == BoxShape::OCT) {
168 IMAGE_OCT__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
169 } else {
170 // UNBOND_BOX
171 }
172}
173
176 real3 l1, real3 l2, real3 l3, real3 ra, real3 rb, real3 rc)
177{
178 imageGeneral(xr, yr, zr, sh, l1, l2, l3, ra, rb, rc);
179 return xr * xr + yr * yr + zr * zr;
180}
181
183inline real imagen2General(real& xr, real& yr, real& zr, BoxShape sh, real3 l1, real3 l2, real3 l3,
184 real3 ra, real3 rb, real3 rc)
185{
186 if (sh == BoxShape::ORTHO) {
187 IMAGE_ORTHO__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
188 } else if (sh == BoxShape::MONO) {
189 IMAGE_MONO__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
190 } else if (sh == BoxShape::TRI) {
191 IMAGE_TRI__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
192 } else if (sh == BoxShape::OCT) {
193 IMAGE_OCT__(xr, yr, zr, l1, l2, l3, ra, rb, rc);
194 } else {
195 // UNBOND_BOX
196 }
197 return xr * xr + yr * yr + zr * zr;
198}
199}
200}
201
209#ifndef image
210# define image(x, y, z) imageGeneral(x, y, z, TINKER_IMAGE_ARGS)
211#endif
212
217#ifndef image2
218# define image2(x, y, z) image2General(x, y, z, TINKER_IMAGE_ARGS)
219#endif
220
225#ifndef imagen2
226# define imagen2(x, y, z) imagen2General(x, y, z, TINKER_IMAGE_ARGS)
227#endif
Definition: image.h:90
static __device__ real img2(real &__restrict__ xr, real &__restrict__ yr, real &__restrict__ zr, real3 l1, real3 l2, real3 l3, real3 ra, real3 rb, real3 rc)
Definition: image.h:100
Definition: image.h:128
static __device__ real img2(real &__restrict__ xr, real &__restrict__ yr, real &__restrict__ zr, real3 l1, real3 l2, real3 l3, real3 ra, real3 rb, real3 rc)
Definition: image.h:138
Definition: image.h:71
static __device__ real img2(real &__restrict__ xr, real &__restrict__ yr, real &__restrict__ zr, real3 l1, real3 l2, real3 l3, real3 ra, real3 rb, real3 rc)
Definition: image.h:81
Definition: image.h:109
static __device__ real img2(real &__restrict__ xr, real &__restrict__ yr, real &__restrict__ zr, real3 l1, real3 l2, real3 l3, real3 ra, real3 rb, real3 rc)
Definition: image.h:119
Definition: image.h:147
static __device__ real img2(real &__restrict__ xr, real &__restrict__ yr, real &__restrict__ zr, real3, real3, real3, real3, real3, real3)
Definition: image.h:150
#define SEQ_ROUTINE
Definition: acc/seqdef.h:7
Definition: acc/realndef.h:48
#define IMAGE_MONO__(xr, yr, zr, l1, l2, l3, ra, rb, rc)
Image displacement for the monoclinic PBC.
Definition: image.h:27
#define IMAGE_OCT__(xr, yr, zr, l1, l2, l3, ra, rb, rc)
Image displacement for the truncated octahedron PBC.
Definition: image.h:49
#define IMAGE_TRI__(xr, yr, zr, l1, l2, l3, ra, rb, rc)
Image displacement for the triclinic PBC.
Definition: image.h:16
BoxShape
Shapes of the periodic box.
Definition: box.h:11
#define IMAGE_ORTHO__(xr, yr, zr, l1, l2, l3, ra, rb, rc)
Image displacement for the orthogonal PBC.
Definition: image.h:38
@ TRI
triclinic
@ OCT
truncated octahedron
@ ORTHO
orthorgonal
@ MONO
monoclinic
#define restrict
Definition: macro.h:51
float real
Definition: precision.h:80
__device__ real image2General(real &__restrict__ xr, real &__restrict__ yr, real &__restrict__ zr, BoxShape sh, real3 l1, real3 l2, real3 l3, real3 ra, real3 rb, real3 rc)
Definition: image.h:175
__device__ real imagen2General(real &xr, real &yr, real &zr, BoxShape sh, real3 l1, real3 l2, real3 l3, real3 ra, real3 rb, real3 rc)
Definition: image.h:183
__device__ void imageGeneral(real &__restrict__ xr, real &__restrict__ yr, real &__restrict__ zr, BoxShape sh, real3 l1, real3 l2, real3 l3, real3 ra, real3 rb, real3 rc)
Definition: image.h:158
Definition: testrt.h:9