Line data Source code
1 : /*----------------------------------------------------------------------------*/
2 : /* CP2K: A general program to perform molecular dynamics simulations */
3 : /* Copyright 2000-2024 CP2K developers group <https://cp2k.org> */
4 : /* */
5 : /* SPDX-License-Identifier: BSD-3-Clause */
6 : /*----------------------------------------------------------------------------*/
7 :
8 : #include "../common/grid_common.h"
9 : #include "../common/grid_constants.h"
10 : #include <stdbool.h>
11 : #include <stdio.h>
12 : #include <stdlib.h>
13 :
14 : #if defined(__CUDACC__) || defined(__HIPCC__)
15 : #define GRID_DEVICE __device__
16 : #else
17 : #define GRID_DEVICE
18 : #endif
19 :
20 : /*******************************************************************************
21 : * \brief Adds given value to matrix element cab[idx(b)][idx(a)].
22 : * This function has to be implemented by the importing compilation unit.
23 : * Without thread safety it's simply: cab[idx(b) * n + idx(a)] += value;
24 : * \author Ole Schuett
25 : ******************************************************************************/
26 : GRID_DEVICE static inline void cab_add(cab_store *cab, const orbital a,
27 : const orbital b, const double value);
28 :
29 : /*******************************************************************************
30 : * \brief Implementation of function GRID_FUNC_AB, ie. identity transformation.
31 : * \author Ole Schuett
32 : ******************************************************************************/
33 1016013015 : GRID_DEVICE static void prepare_pab_AB(const orbital a, const orbital b,
34 : const double pab_val, cab_store *cab) {
35 :
36 : // simply copy pab to cab
37 1016013015 : cab_add(cab, a, b, pab_val);
38 1016013015 : }
39 :
40 : /*******************************************************************************
41 : * \brief Implementation of function GRID_FUNC_DADB.
42 : * \author Ole Schuett
43 : ******************************************************************************/
44 14184656 : GRID_DEVICE static void prepare_pab_DADB(const orbital a, const orbital b,
45 : const double zeta, const double zetb,
46 : const double pab_val, cab_store *cab) {
47 :
48 : // creates cab such that mapping it with pgf_a pgf_b
49 : // is equivalent to mapping pab with 0.5 * (nabla pgf_a) . (nabla pgf_b)
50 : // (ddx pgf_a ) (ddx pgf_b) = (lax pgf_{a-1x} - 2*zeta*pgf_{a+1x})*(lbx
51 : // pgf_{b-1x} - 2*zetb*pgf_{b+1x})
52 :
53 56738624 : for (int i = 0; i < 3; i++) {
54 42553968 : cab_add(cab, down(i, a), down(i, b), 0.5 * a.l[i] * b.l[i] * pab_val);
55 42553968 : cab_add(cab, down(i, a), up(i, b), -1.0 * a.l[i] * zetb * pab_val);
56 42553968 : cab_add(cab, up(i, a), down(i, b), -1.0 * zeta * b.l[i] * pab_val);
57 42553968 : cab_add(cab, up(i, a), up(i, b), 2.0 * zeta * zetb * pab_val);
58 : }
59 14184656 : }
60 :
61 : /*******************************************************************************
62 : * \brief Implementation of function GRID_FUNC_ADBmDAB_{X,Y,Z}.
63 : * \author Ole Schuett
64 : ******************************************************************************/
65 1689996 : GRID_DEVICE static void prepare_pab_ADBmDAB(const int idir, const orbital a,
66 : const orbital b, const double zeta,
67 : const double zetb,
68 : const double pab_val,
69 : cab_store *cab) {
70 :
71 : // creates cab such that mapping it with pgf_a pgf_b
72 : // is equivalent to mapping pab with
73 : // pgf_a (nabla_{idir} pgf_b) - (nabla_{idir} pgf_a) pgf_b
74 : // ( pgf_a ) (ddx pgf_b) - (ddx pgf_a)( pgf_b ) =
75 : // pgf_a *(lbx pgf_{b-1x} - 2*zetb*pgf_{b+1x}) -
76 : // (lax pgf_{a-1x} - 2*zeta*pgf_{a+1x}) pgf_b
77 :
78 1689996 : cab_add(cab, a, down(idir, b), +b.l[idir] * pab_val);
79 1689996 : cab_add(cab, a, up(idir, b), -2.0 * zetb * pab_val);
80 1689996 : cab_add(cab, down(idir, a), b, -a.l[idir] * pab_val);
81 1689996 : cab_add(cab, up(idir, a), b, +2.0 * zeta * pab_val);
82 1689996 : }
83 :
84 : /*******************************************************************************
85 : * \brief Implementation of function GRID_FUNC_ARDBmDARB_{X,Y,Z}{X,Y,Z}.
86 : * \author Ole Schuett
87 : ******************************************************************************/
88 : GRID_DEVICE static void
89 2544396 : prepare_pab_ARDBmDARB(const int idir, const int ir, const orbital a,
90 : const orbital b, const double zeta, const double zetb,
91 : const double pab_val, cab_store *cab) {
92 :
93 : // creates cab such that mapping it with pgf_a pgf_b
94 : // is equivalent to mapping pab with
95 : // pgf_a (r-Rb)_{ir} (nabla_{idir} pgf_b) - (nabla_{idir} pgf_a) (r-Rb)_{ir}
96 : // pgf_b ( pgf_a )(r-Rb)_{ir} (ddx pgf_b) - (ddx pgf_a) (r-Rb)_{ir} ( pgf_b )
97 : // =
98 : // pgf_a *(lbx pgf_{b-1x+1ir} - 2*zetb*pgf_{b+1x+1ir})
99 : // -
100 : // (lax pgf_{a-1x} - 2*zeta*pgf_{a+1x}) pgf_{b+1ir}
101 :
102 2544396 : cab_add(cab, a, down(idir, up(ir, b)), b.l[idir] * pab_val);
103 2544396 : cab_add(cab, a, up(idir, up(ir, b)), -2.0 * zetb * pab_val);
104 2544396 : cab_add(cab, down(idir, a), up(ir, b), -a.l[idir] * pab_val);
105 2544396 : cab_add(cab, up(idir, a), up(ir, b), +2.0 * zeta * pab_val);
106 2544396 : }
107 :
108 : /*******************************************************************************
109 : * \brief Implementation of function GRID_FUNC_DABpADB_{X,Y,Z}.
110 : * \author Ole Schuett
111 : ******************************************************************************/
112 3522498 : GRID_DEVICE static void prepare_pab_DABpADB(const int idir, const orbital a,
113 : const orbital b, const double zeta,
114 : const double zetb,
115 : const double pab_val,
116 : cab_store *cab) {
117 :
118 : // creates cab such that mapping it with pgf_a pgf_b
119 : // is equivalent to mapping pab with
120 : // pgf_a (nabla_{idir} pgf_b) + (nabla_{idir} pgf_a) pgf_b
121 : // ( pgf_a ) (ddx pgf_b) + (ddx pgf_a)( pgf_b ) =
122 : // pgf_a *(lbx pgf_{b-1x} + 2*zetb*pgf_{b+1x}) +
123 : // (lax pgf_{a-1x} + 2*zeta*pgf_{a+1x}) pgf_b
124 :
125 3522498 : cab_add(cab, a, down(idir, b), b.l[idir] * pab_val);
126 3522498 : cab_add(cab, a, up(idir, b), -2.0 * zetb * pab_val);
127 3522498 : cab_add(cab, down(idir, a), b, a.l[idir] * pab_val);
128 3522498 : cab_add(cab, up(idir, a), b, -2.0 * zeta * pab_val);
129 3522498 : }
130 :
131 : /*******************************************************************************
132 : * \brief Implementation of function GRID_FUNC_DAB_{X,Y,Z}.
133 : * This function takes the derivates with respect to nuclear positions
134 : * which results in a change of signs compared to prepare_pab_DABpADB.
135 : * Only the derivative with respect to the primitive on the left.
136 : * \author Edward Ditler
137 : ******************************************************************************/
138 23706 : GRID_DEVICE static void prepare_pab_DAB(const int idir, const orbital a,
139 : const orbital b, const double zeta,
140 : const double pab_val, cab_store *cab) {
141 :
142 : // creates cab such that mapping it with pgf_a pgf_b
143 : // is equivalent to mapping pab with (nabla_{idir} pgf_a) pgf_b
144 : // (ddX pgf_a)( pgf_b ) =
145 : // (-lax pgf_{a-1x} - 2*zeta*pgf_{a+1x}) pgf_b
146 :
147 23706 : cab_add(cab, down(idir, a), b, -a.l[idir] * pab_val);
148 23706 : cab_add(cab, up(idir, a), b, +2.0 * zeta * pab_val);
149 23706 : }
150 :
151 : /*******************************************************************************
152 : * \brief Implementation of function GRID_FUNC_ADB_{X,Y,Z}.
153 : * This function takes the derivates with respect to nuclear positions
154 : * which results in a change of signs compared to prepare_pab_DABpADB.
155 : * Only the derivative with respect to the primitive on the right.
156 : * \author Edward Ditler
157 : ******************************************************************************/
158 23706 : GRID_DEVICE static void prepare_pab_ADB(const int idir, const orbital a,
159 : const orbital b, const double zetb,
160 : const double pab_val, cab_store *cab) {
161 :
162 : // creates cab such that mapping it with pgf_a pgf_b
163 : // is equivalent to mapping pab with
164 : // pgf_a (nabla_{idir} pgf_b) + (nabla_{idir} pgf_a) pgf_b
165 : // ( pgf_a ) (ddX pgf_b) =
166 : // pgf_a *(-lbx pgf_{b-1x} - 2*zetb*pgf_{b+1x})
167 :
168 23706 : cab_add(cab, a, down(idir, b), -b.l[idir] * pab_val);
169 23706 : cab_add(cab, a, up(idir, b), +2.0 * zetb * pab_val);
170 23706 : }
171 :
172 : /*******************************************************************************
173 : * \brief Implementation of function GRID_FUNC_CORE_{X,Y,Z}.
174 : * This function takes the derivates with respect to nuclear positions.
175 : * \author Edward Ditler
176 : ******************************************************************************/
177 108 : GRID_DEVICE static void prepare_pab_core(const int idir, const orbital a,
178 : const orbital b, const double zeta,
179 : const double pab_val, cab_store *cab) {
180 :
181 : // creates cab such that mapping it with pgf_a pgf_b
182 : // is equivalent to mapping pab with (nabla_{idir} pgf_a) pgf_b
183 : // (ddX pgf_a)( pgf_b ) = 2*zeta*pgf_{a+1x}) pgf_b
184 :
185 108 : cab_add(cab, a, down(idir, b), 0.0);
186 108 : cab_add(cab, a, up(idir, b), 0.0);
187 108 : cab_add(cab, down(idir, a), b, 0.0);
188 108 : cab_add(cab, up(idir, a), b, +2.0 * zeta * pab_val);
189 108 : }
190 :
191 : /*******************************************************************************
192 : * \brief Implementation of function GRID_FUNC_{DX,DY,DZ}.
193 : * \author Ole Schuett
194 : ******************************************************************************/
195 2071464 : GRID_DEVICE static void prepare_pab_Di(const int ider, const orbital a,
196 : const orbital b, const double zeta,
197 : const double zetb, const double pab_val,
198 : cab_store *cab) {
199 :
200 : // creates cab such that mapping it with pgf_a pgf_b
201 : // is equivalent to mapping pab with
202 : // d_{ider1} pgf_a d_{ider1} pgf_b
203 : // dx pgf_a dx pgf_b =
204 : // (lax pgf_{a-1x})*(lbx pgf_{b-1x}) - 2*zetb*lax*pgf_{a-1x}*pgf_{b+1x}
205 : // -
206 : // lbx pgf_{b-1x}*2*zeta*pgf_{a+1x}+ 4*zeta*zetab*pgf_{a+1x}pgf_{b+1x}
207 :
208 2071464 : cab_add(cab, down(ider, a), down(ider, b), a.l[ider] * b.l[ider] * pab_val);
209 2071464 : cab_add(cab, down(ider, a), up(ider, b), -2.0 * a.l[ider] * zetb * pab_val);
210 2071464 : cab_add(cab, up(ider, a), down(ider, b), -2.0 * zeta * b.l[ider] * pab_val);
211 2071464 : cab_add(cab, up(ider, a), up(ider, b), +4.0 * zeta * zetb * pab_val);
212 2071464 : }
213 :
214 : /*******************************************************************************
215 : * \brief Helper for grid_prepare_pab_DiDj.
216 : * \author Ole Schuett
217 : ******************************************************************************/
218 0 : GRID_DEVICE static void oneterm_dijdij(const int idir, const double func_a,
219 : const orbital a, const orbital b,
220 : const double zetb, cab_store *cab) {
221 :
222 0 : int i1, i2;
223 0 : if (idir == 0) {
224 : i1 = 0;
225 : i2 = 1;
226 : } else if (idir == 1) {
227 : i1 = 1;
228 : i2 = 2;
229 : } else if (idir == 2) {
230 : i1 = 2;
231 : i2 = 0;
232 : } else {
233 : return; // error
234 : }
235 :
236 0 : cab_add(cab, a, down(i1, down(i2, b)), b.l[i1] * b.l[i2] * func_a);
237 0 : cab_add(cab, a, up(i1, down(i2, b)), -2.0 * zetb * b.l[i2] * func_a);
238 0 : cab_add(cab, a, down(i1, up(i2, b)), -2.0 * zetb * b.l[i1] * func_a);
239 0 : cab_add(cab, a, up(i1, up(i2, b)), +4.0 * zetb * zetb * func_a);
240 : }
241 :
242 : /*******************************************************************************
243 : * \brief Implementation of function GRID_FUNC_{DXDY,DYDZ,DZDX}
244 : * \author Ole Schuett
245 : ******************************************************************************/
246 0 : GRID_DEVICE static void prepare_pab_DiDj(const int ider1, const int ider2,
247 : const orbital a, const orbital b,
248 : const double zeta, const double zetb,
249 : const double pab_val, cab_store *cab) {
250 :
251 : // creates cab such that mapping it with pgf_a pgf_b
252 : // is equivalent to mapping pab with
253 : // d_{ider1} pgf_a d_{ider1} pgf_b
254 :
255 0 : const double func_a1 = a.l[ider1] * a.l[ider2] * pab_val;
256 0 : oneterm_dijdij(ider1, func_a1, down(ider1, down(ider2, a)), b, zetb, cab);
257 :
258 0 : const double func_a2 = -2.0 * zeta * a.l[ider2] * pab_val;
259 0 : oneterm_dijdij(ider1, func_a2, up(ider1, down(ider2, a)), b, zetb, cab);
260 :
261 0 : const double func_a3 = -2.0 * zeta * a.l[ider1] * pab_val;
262 0 : oneterm_dijdij(ider1, func_a3, down(ider1, up(ider2, a)), b, zetb, cab);
263 :
264 0 : const double func_a4 = 4.0 * zeta * zeta * pab_val;
265 0 : oneterm_dijdij(ider1, func_a4, up(ider1, up(ider2, a)), b, zetb, cab);
266 0 : }
267 :
268 : /*******************************************************************************
269 : * \brief Helper for grid_prepare_pab_Di2.
270 : * \author Ole Schuett
271 : ******************************************************************************/
272 0 : GRID_DEVICE static void oneterm_diidii(const int idir, const double func_a,
273 : const orbital a, const orbital b,
274 : const double zetb, cab_store *cab) {
275 :
276 0 : cab_add(cab, a, down(idir, down(idir, b)),
277 0 : b.l[idir] * (b.l[idir] - 1) * func_a);
278 0 : cab_add(cab, a, b, -2.0 * zetb * (2 * b.l[idir] + 1) * func_a);
279 0 : cab_add(cab, a, up(idir, up(idir, b)), +4.0 * zetb * zetb * func_a);
280 0 : }
281 :
282 : /*******************************************************************************
283 : * \brief Implementation of function GRID_FUNC_{DXDX,DYDY,DZDZ}
284 : * \author Ole Schuett
285 : ******************************************************************************/
286 0 : GRID_DEVICE static void prepare_pab_Di2(const int ider, const orbital a,
287 : const orbital b, const double zeta,
288 : const double zetb, const double pab_val,
289 : cab_store *cab) {
290 :
291 : // creates cab such that mapping it with pgf_a pgf_b
292 : // is equivalent to mapping pab with
293 : // dd_{ider1} pgf_a dd_{ider1} pgf_b
294 :
295 0 : const double func_a1 = a.l[ider] * (a.l[ider] - 1) * pab_val;
296 0 : oneterm_diidii(ider, func_a1, down(ider, down(ider, a)), b, zetb, cab);
297 :
298 0 : const double func_a2 = -2.0 * zeta * (2 * a.l[ider] + 1) * pab_val;
299 0 : oneterm_diidii(ider, func_a2, a, b, zetb, cab);
300 :
301 0 : const double func_a3 = 4.0 * zeta * zeta * pab_val;
302 0 : oneterm_diidii(ider, func_a3, up(ider, up(ider, a)), b, zetb, cab);
303 0 : }
304 :
305 : /*******************************************************************************
306 : * \brief Transforms a given element of the density matrix according to func.
307 : * \param func Transformation function to apply, one of GRID_FUNC_*.
308 : * \param {a,b} Orbital angular momenta.
309 : * \param zet_{a,b} Gaussian exponents.
310 : * \param pab_val Input matrix element of pab.
311 : * \param n Leading dimensions of output matrix cab.
312 : * \param cab Output matrix.
313 : * \author Ole Schuett
314 : ******************************************************************************/
315 1040073545 : GRID_DEVICE static void prepare_pab(const enum grid_func func, const orbital a,
316 : const orbital b, const double zeta,
317 : const double zetb, const double pab_val,
318 : cab_store *cab) {
319 :
320 : // This switch statment will be in an inner loop but only with few iterations.
321 1040073545 : switch (func) {
322 1016013015 : case GRID_FUNC_AB:
323 1016013015 : prepare_pab_AB(a, b, pab_val, cab);
324 1016013015 : break;
325 14184656 : case GRID_FUNC_DADB:
326 14184656 : prepare_pab_DADB(a, b, zeta, zetb, pab_val, cab);
327 14184656 : break;
328 563332 : case GRID_FUNC_ADBmDAB_X:
329 563332 : prepare_pab_ADBmDAB(0, a, b, zeta, zetb, pab_val, cab);
330 563332 : break;
331 563332 : case GRID_FUNC_ADBmDAB_Y:
332 563332 : prepare_pab_ADBmDAB(1, a, b, zeta, zetb, pab_val, cab);
333 563332 : break;
334 563332 : case GRID_FUNC_ADBmDAB_Z:
335 563332 : prepare_pab_ADBmDAB(2, a, b, zeta, zetb, pab_val, cab);
336 563332 : break;
337 275958 : case GRID_FUNC_ARDBmDARB_XX:
338 275958 : prepare_pab_ARDBmDARB(0, 0, a, b, zeta, zetb, pab_val, cab);
339 275958 : break;
340 286087 : case GRID_FUNC_ARDBmDARB_XY:
341 286087 : prepare_pab_ARDBmDARB(0, 1, a, b, zeta, zetb, pab_val, cab);
342 286087 : break;
343 286087 : case GRID_FUNC_ARDBmDARB_XZ:
344 286087 : prepare_pab_ARDBmDARB(0, 2, a, b, zeta, zetb, pab_val, cab);
345 286087 : break;
346 286087 : case GRID_FUNC_ARDBmDARB_YX:
347 286087 : prepare_pab_ARDBmDARB(1, 0, a, b, zeta, zetb, pab_val, cab);
348 286087 : break;
349 275958 : case GRID_FUNC_ARDBmDARB_YY:
350 275958 : prepare_pab_ARDBmDARB(1, 1, a, b, zeta, zetb, pab_val, cab);
351 275958 : break;
352 286087 : case GRID_FUNC_ARDBmDARB_YZ:
353 286087 : prepare_pab_ARDBmDARB(1, 2, a, b, zeta, zetb, pab_val, cab);
354 286087 : break;
355 286087 : case GRID_FUNC_ARDBmDARB_ZX:
356 286087 : prepare_pab_ARDBmDARB(2, 0, a, b, zeta, zetb, pab_val, cab);
357 286087 : break;
358 286087 : case GRID_FUNC_ARDBmDARB_ZY:
359 286087 : prepare_pab_ARDBmDARB(2, 1, a, b, zeta, zetb, pab_val, cab);
360 286087 : break;
361 275958 : case GRID_FUNC_ARDBmDARB_ZZ:
362 275958 : prepare_pab_ARDBmDARB(2, 2, a, b, zeta, zetb, pab_val, cab);
363 275958 : break;
364 1174166 : case GRID_FUNC_DABpADB_X:
365 1174166 : prepare_pab_DABpADB(0, a, b, zeta, zetb, pab_val, cab);
366 1174166 : break;
367 1174166 : case GRID_FUNC_DABpADB_Y:
368 1174166 : prepare_pab_DABpADB(1, a, b, zeta, zetb, pab_val, cab);
369 1174166 : break;
370 1174166 : case GRID_FUNC_DABpADB_Z:
371 1174166 : prepare_pab_DABpADB(2, a, b, zeta, zetb, pab_val, cab);
372 1174166 : break;
373 7902 : case GRID_FUNC_DAB_X:
374 7902 : prepare_pab_DAB(0, a, b, zeta, pab_val, cab);
375 7902 : break;
376 7902 : case GRID_FUNC_DAB_Y:
377 7902 : prepare_pab_DAB(1, a, b, zeta, pab_val, cab);
378 7902 : break;
379 7902 : case GRID_FUNC_DAB_Z:
380 7902 : prepare_pab_DAB(2, a, b, zeta, pab_val, cab);
381 7902 : break;
382 7902 : case GRID_FUNC_ADB_X:
383 7902 : prepare_pab_ADB(0, a, b, zetb, pab_val, cab);
384 7902 : break;
385 7902 : case GRID_FUNC_ADB_Y:
386 7902 : prepare_pab_ADB(1, a, b, zetb, pab_val, cab);
387 7902 : break;
388 7902 : case GRID_FUNC_ADB_Z:
389 7902 : prepare_pab_ADB(2, a, b, zetb, pab_val, cab);
390 7902 : break;
391 36 : case GRID_FUNC_CORE_X:
392 36 : prepare_pab_core(0, a, b, zeta, pab_val, cab);
393 36 : break;
394 36 : case GRID_FUNC_CORE_Y:
395 36 : prepare_pab_core(1, a, b, zeta, pab_val, cab);
396 36 : break;
397 36 : case GRID_FUNC_CORE_Z:
398 36 : prepare_pab_core(2, a, b, zeta, pab_val, cab);
399 36 : break;
400 0 : case GRID_FUNC_DX:
401 0 : prepare_pab_Di(0, a, b, zeta, zetb, pab_val, cab);
402 0 : break;
403 0 : case GRID_FUNC_DY:
404 0 : prepare_pab_Di(1, a, b, zeta, zetb, pab_val, cab);
405 0 : break;
406 2071464 : case GRID_FUNC_DZ:
407 2071464 : prepare_pab_Di(2, a, b, zeta, zetb, pab_val, cab);
408 2071464 : break;
409 0 : case GRID_FUNC_DXDY:
410 0 : prepare_pab_DiDj(0, 1, a, b, zeta, zetb, pab_val, cab);
411 0 : break;
412 0 : case GRID_FUNC_DYDZ:
413 0 : prepare_pab_DiDj(1, 2, a, b, zeta, zetb, pab_val, cab);
414 0 : break;
415 0 : case GRID_FUNC_DZDX:
416 0 : prepare_pab_DiDj(2, 0, a, b, zeta, zetb, pab_val, cab);
417 0 : break;
418 0 : case GRID_FUNC_DXDX:
419 0 : prepare_pab_Di2(0, a, b, zeta, zetb, pab_val, cab);
420 0 : break;
421 0 : case GRID_FUNC_DYDY:
422 0 : prepare_pab_Di2(1, a, b, zeta, zetb, pab_val, cab);
423 0 : break;
424 0 : case GRID_FUNC_DZDZ:
425 0 : prepare_pab_Di2(2, a, b, zeta, zetb, pab_val, cab);
426 0 : break;
427 : default:
428 : break; // Error: Unknown ga_gb_function - do nothing.
429 : }
430 1040073545 : }
431 :
432 : /*******************************************************************************
433 : * \brief Differences in angular momentum.
434 : * \author Ole Schuett
435 : ******************************************************************************/
436 : typedef struct {
437 : int la_max_diff;
438 : int la_min_diff;
439 : int lb_max_diff;
440 : int lb_min_diff;
441 : } prepare_ldiffs;
442 :
443 : /*******************************************************************************
444 : * \brief Returns difference in angular momentum range for given func.
445 : * \author Ole Schuett
446 : ******************************************************************************/
447 86444433 : static prepare_ldiffs prepare_get_ldiffs(const enum grid_func func) {
448 86444433 : prepare_ldiffs ldiffs;
449 :
450 86444433 : switch (func) {
451 : case GRID_FUNC_AB:
452 : ldiffs.la_max_diff = 0;
453 : ldiffs.la_min_diff = 0;
454 : ldiffs.lb_max_diff = 0;
455 : ldiffs.lb_min_diff = 0;
456 : break;
457 2514574 : case GRID_FUNC_DADB:
458 : case GRID_FUNC_ADBmDAB_X:
459 : case GRID_FUNC_ADBmDAB_Y:
460 : case GRID_FUNC_ADBmDAB_Z:
461 : case GRID_FUNC_DABpADB_X:
462 : case GRID_FUNC_DABpADB_Y:
463 : case GRID_FUNC_DABpADB_Z:
464 : case GRID_FUNC_DAB_X:
465 : case GRID_FUNC_DAB_Y:
466 : case GRID_FUNC_DAB_Z:
467 : case GRID_FUNC_ADB_X:
468 : case GRID_FUNC_ADB_Y:
469 : case GRID_FUNC_ADB_Z:
470 : case GRID_FUNC_CORE_X:
471 : case GRID_FUNC_CORE_Y:
472 : case GRID_FUNC_CORE_Z:
473 2514574 : ldiffs.la_max_diff = +1;
474 2514574 : ldiffs.la_min_diff = -1;
475 2514574 : ldiffs.lb_max_diff = +1;
476 2514574 : ldiffs.lb_min_diff = -1;
477 2514574 : break;
478 287778 : case GRID_FUNC_ARDBmDARB_XX:
479 : case GRID_FUNC_ARDBmDARB_XY:
480 : case GRID_FUNC_ARDBmDARB_XZ:
481 : case GRID_FUNC_ARDBmDARB_YX:
482 : case GRID_FUNC_ARDBmDARB_YY:
483 : case GRID_FUNC_ARDBmDARB_YZ:
484 : case GRID_FUNC_ARDBmDARB_ZX:
485 : case GRID_FUNC_ARDBmDARB_ZY:
486 : case GRID_FUNC_ARDBmDARB_ZZ:
487 287778 : ldiffs.la_max_diff = +1;
488 287778 : ldiffs.la_min_diff = -1;
489 287778 : ldiffs.lb_max_diff = +2; // this is legit
490 287778 : ldiffs.lb_min_diff = -1;
491 287778 : break;
492 38464 : case GRID_FUNC_DX:
493 : case GRID_FUNC_DY:
494 : case GRID_FUNC_DZ:
495 38464 : ldiffs.la_max_diff = +1;
496 38464 : ldiffs.la_min_diff = -1;
497 38464 : ldiffs.lb_max_diff = +1;
498 38464 : ldiffs.lb_min_diff = -1;
499 38464 : break;
500 0 : case GRID_FUNC_DXDY:
501 : case GRID_FUNC_DYDZ:
502 : case GRID_FUNC_DZDX:
503 : case GRID_FUNC_DXDX:
504 : case GRID_FUNC_DYDY:
505 : case GRID_FUNC_DZDZ:
506 0 : ldiffs.la_max_diff = +2;
507 0 : ldiffs.la_min_diff = -2;
508 0 : ldiffs.lb_max_diff = +2;
509 0 : ldiffs.lb_min_diff = -2;
510 0 : break;
511 0 : default:
512 0 : fprintf(stderr, "Error: Unknown ga_gb_function %i.\n", func);
513 0 : abort();
514 : }
515 :
516 86444433 : return ldiffs;
517 : }
518 :
519 : // EOF
|