Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
symtensor_collections.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
19#include "shambackends/sycl.hpp"
20#include "symtensors.hpp"
21
22namespace shammath {
23
24 template<class T, u32 low_order, u32 high_order>
26
27 template<class T>
28 struct SymTensorCollection<T, 0, 5> {
29 T t0;
35
36 static constexpr u32 num_component
40
41 static constexpr u32 offset_t0 = 0;
42 static constexpr u32 offset_t1 = 1;
43 static constexpr u32 offset_t2 = offset_t1 + SymTensor3d_1<T>::compo_cnt;
44 static constexpr u32 offset_t3 = offset_t2 + SymTensor3d_2<T>::compo_cnt;
45 static constexpr u32 offset_t4 = offset_t3 + SymTensor3d_3<T>::compo_cnt;
46 static constexpr u32 offset_t5 = offset_t4 + SymTensor3d_4<T>::compo_cnt;
47
48 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) {
49 auto A1 = SymTensor3d_1<T>{v.x(), v.y(), v.z()};
50
51 auto A2 = SymTensor3d_2<T>{
52 A1.v_0 * A1.v_0,
53 A1.v_1 * A1.v_0,
54 A1.v_2 * A1.v_0,
55 A1.v_1 * A1.v_1,
56 A1.v_2 * A1.v_1,
57 A1.v_2 * A1.v_2,
58 };
59
60 auto A3 = SymTensor3d_3<T>{
61 A2.v_00 * A1.v_0,
62 A2.v_01 * A1.v_0,
63 A2.v_02 * A1.v_0,
64 A2.v_11 * A1.v_0,
65 A2.v_12 * A1.v_0,
66 A2.v_22 * A1.v_0,
67 A2.v_11 * A1.v_1,
68 A2.v_12 * A1.v_1,
69 A2.v_22 * A1.v_1,
70 A2.v_22 * A1.v_2};
71
72 auto A4 = SymTensor3d_4<T>{
73 A3.v_000 * A1.v_0,
74 A3.v_001 * A1.v_0,
75 A3.v_002 * A1.v_0,
76 A3.v_011 * A1.v_0,
77 A3.v_012 * A1.v_0,
78 A3.v_022 * A1.v_0,
79 A3.v_111 * A1.v_0,
80 A3.v_112 * A1.v_0,
81 A3.v_122 * A1.v_0,
82 A3.v_222 * A1.v_0,
83 A3.v_111 * A1.v_1,
84 A3.v_112 * A1.v_1,
85 A3.v_122 * A1.v_1,
86 A3.v_222 * A1.v_1,
87 A3.v_222 * A1.v_2};
88
89 auto A5 = SymTensor3d_5<T>{A4.v_0000 * A1.v_0, A4.v_0001 * A1.v_0, A4.v_0002 * A1.v_0,
90 A4.v_0011 * A1.v_0, A4.v_0012 * A1.v_0, A4.v_0022 * A1.v_0,
91 A4.v_0111 * A1.v_0, A4.v_0112 * A1.v_0, A4.v_0122 * A1.v_0,
92 A4.v_0222 * A1.v_0, A4.v_1111 * A1.v_0, A4.v_1112 * A1.v_0,
93 A4.v_1122 * A1.v_0, A4.v_1222 * A1.v_0, A4.v_2222 * A1.v_0,
94 A4.v_1111 * A1.v_1, A4.v_1112 * A1.v_1, A4.v_1122 * A1.v_1,
95 A4.v_1222 * A1.v_1, A4.v_2222 * A1.v_1, A4.v_2222 * A1.v_2};
96
97 return {1, A1, A2, A3, A4, A5};
98 }
99
100 inline static SymTensorCollection zeros() {
101 auto A1 = SymTensor3d_1<T>{0, 0, 0};
102
103 auto A2 = SymTensor3d_2<T>{
104 0,
105 0,
106 0,
107 0,
108 0,
109 0,
110 };
111
112 auto A3 = SymTensor3d_3<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
113
114 auto A4 = SymTensor3d_4<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
115
116 auto A5
117 = SymTensor3d_5<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
118
119 return {0, A1, A2, A3, A4};
120 }
121
122 template<class Tacc>
123 inline void store(Tacc &&acc, u32 offset) const {
124 acc[offset + offset_t0] = t0;
125 t1.store(acc, offset + offset_t1);
126 t2.store(acc, offset + offset_t2);
127 t3.store(acc, offset + offset_t3);
128 t4.store(acc, offset + offset_t4);
129 t5.store(acc, offset + offset_t5);
130 }
131
132 template<class Tacc>
133 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
134 return SymTensorCollection{
135 acc[offset + offset_t0],
136 SymTensor3d_1<T>::load(acc, offset + offset_t1),
137 SymTensor3d_2<T>::load(acc, offset + offset_t2),
138 SymTensor3d_3<T>::load(acc, offset + offset_t3),
139 SymTensor3d_4<T>::load(acc, offset + offset_t4),
140 SymTensor3d_5<T>::load(acc, offset + offset_t5)};
141 }
142
143 inline SymTensorCollection<T, 0, 5> &operator*=(const T scal) {
144
145 t0 *= scal;
146 t1 *= scal;
147 t2 *= scal;
148 t3 *= scal;
149 t4 *= scal;
150 t5 *= scal;
151
152 return *this;
153 }
154
155 inline SymTensorCollection<T, 0, 5> &operator+=(const SymTensorCollection<T, 0, 5> other) {
156
157 t0 += other.t0;
158 t1 += other.t1;
159 t2 += other.t2;
160 t3 += other.t3;
161 t4 += other.t4;
162 t5 += other.t5;
163
164 return *this;
165 }
166
167 inline SymTensorCollection<T, 0, 5> operator-(
168 const SymTensorCollection<T, 0, 5> &other) const {
169 return {
170 t0 - other.t0,
171 t1 - other.t1,
172 t2 - other.t2,
173 t3 - other.t3,
174 t4 - other.t4,
175 t5 - other.t5};
176 }
177 };
178
179 template<class T>
180 struct SymTensorCollection<T, 0, 4> {
181 T t0;
186
187 static constexpr u32 num_component
190
191 static constexpr u32 offset_t0 = 0;
192 static constexpr u32 offset_t1 = 1;
193 static constexpr u32 offset_t2 = offset_t1 + SymTensor3d_1<T>::compo_cnt;
194 static constexpr u32 offset_t3 = offset_t2 + SymTensor3d_2<T>::compo_cnt;
195 static constexpr u32 offset_t4 = offset_t3 + SymTensor3d_3<T>::compo_cnt;
196
197 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) {
198 auto A1 = SymTensor3d_1<T>{v.x(), v.y(), v.z()};
199
200 auto A2 = SymTensor3d_2<T>{
201 A1.v_0 * A1.v_0,
202 A1.v_1 * A1.v_0,
203 A1.v_2 * A1.v_0,
204 A1.v_1 * A1.v_1,
205 A1.v_2 * A1.v_1,
206 A1.v_2 * A1.v_2,
207 };
208
209 auto A3 = SymTensor3d_3<T>{
210 A2.v_00 * A1.v_0,
211 A2.v_01 * A1.v_0,
212 A2.v_02 * A1.v_0,
213 A2.v_11 * A1.v_0,
214 A2.v_12 * A1.v_0,
215 A2.v_22 * A1.v_0,
216 A2.v_11 * A1.v_1,
217 A2.v_12 * A1.v_1,
218 A2.v_22 * A1.v_1,
219 A2.v_22 * A1.v_2};
220
221 auto A4 = SymTensor3d_4<T>{
222 A3.v_000 * A1.v_0,
223 A3.v_001 * A1.v_0,
224 A3.v_002 * A1.v_0,
225 A3.v_011 * A1.v_0,
226 A3.v_012 * A1.v_0,
227 A3.v_022 * A1.v_0,
228 A3.v_111 * A1.v_0,
229 A3.v_112 * A1.v_0,
230 A3.v_122 * A1.v_0,
231 A3.v_222 * A1.v_0,
232 A3.v_111 * A1.v_1,
233 A3.v_112 * A1.v_1,
234 A3.v_122 * A1.v_1,
235 A3.v_222 * A1.v_1,
236 A3.v_222 * A1.v_2};
237
238 return {1, A1, A2, A3, A4};
239 }
240
241 inline static SymTensorCollection zeros() {
242 auto A1 = SymTensor3d_1<T>{0, 0, 0};
243
244 auto A2 = SymTensor3d_2<T>{
245 0,
246 0,
247 0,
248 0,
249 0,
250 0,
251 };
252
253 auto A3 = SymTensor3d_3<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
254
255 auto A4 = SymTensor3d_4<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
256
257 return {0, A1, A2, A3, A4};
258 }
259
260 template<class Tacc>
261 inline void store(Tacc &&acc, u32 offset) const {
262 acc[offset + offset_t0] = t0;
263 t1.store(acc, offset + offset_t1);
264 t2.store(acc, offset + offset_t2);
265 t3.store(acc, offset + offset_t3);
266 t4.store(acc, offset + offset_t4);
267 }
268
269 template<class Tacc>
270 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
271 return SymTensorCollection{
272 acc[offset + offset_t0],
273 SymTensor3d_1<T>::load(acc, offset + offset_t1),
274 SymTensor3d_2<T>::load(acc, offset + offset_t2),
275 SymTensor3d_3<T>::load(acc, offset + offset_t3),
276 SymTensor3d_4<T>::load(acc, offset + offset_t4)};
277 }
278
279 inline SymTensorCollection<T, 0, 4> &operator*=(const T scal) {
280
281 t0 *= scal;
282 t1 *= scal;
283 t2 *= scal;
284 t3 *= scal;
285 t4 *= scal;
286
287 return *this;
288 }
289
290 inline SymTensorCollection<T, 0, 4> &operator+=(const SymTensorCollection<T, 0, 4> other) {
291
292 t0 += other.t0;
293 t1 += other.t1;
294 t2 += other.t2;
295 t3 += other.t3;
296 t4 += other.t4;
297
298 return *this;
299 }
300
301 inline SymTensorCollection<T, 0, 4> operator-(
302 const SymTensorCollection<T, 0, 4> &other) const {
303 return {t0 - other.t0, t1 - other.t1, t2 - other.t2, t3 - other.t3, t4 - other.t4};
304 }
305 };
306
307 template<class T>
308 struct SymTensorCollection<T, 0, 3> {
309 T t0;
313
314 static constexpr u32 num_component = 1 + SymTensor3d_1<T>::compo_cnt
317
318 static constexpr u32 offset_t0 = 0;
319 static constexpr u32 offset_t1 = 1;
320 static constexpr u32 offset_t2 = offset_t1 + SymTensor3d_1<T>::compo_cnt;
321 static constexpr u32 offset_t3 = offset_t2 + SymTensor3d_2<T>::compo_cnt;
322
323 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) {
324 auto A1 = SymTensor3d_1<T>{v.x(), v.y(), v.z()};
325
326 auto A2 = SymTensor3d_2<T>{
327 A1.v_0 * A1.v_0,
328 A1.v_1 * A1.v_0,
329 A1.v_2 * A1.v_0,
330 A1.v_1 * A1.v_1,
331 A1.v_2 * A1.v_1,
332 A1.v_2 * A1.v_2,
333 };
334
335 auto A3 = SymTensor3d_3<T>{
336 A2.v_00 * A1.v_0,
337 A2.v_01 * A1.v_0,
338 A2.v_02 * A1.v_0,
339 A2.v_11 * A1.v_0,
340 A2.v_12 * A1.v_0,
341 A2.v_22 * A1.v_0,
342 A2.v_11 * A1.v_1,
343 A2.v_12 * A1.v_1,
344 A2.v_22 * A1.v_1,
345 A2.v_22 * A1.v_2};
346
347 return {1, A1, A2, A3};
348 }
349
350 inline static SymTensorCollection zeros() {
351 auto A1 = SymTensor3d_1<T>{0, 0, 0};
352
353 auto A2 = SymTensor3d_2<T>{
354 0,
355 0,
356 0,
357 0,
358 0,
359 0,
360 };
361
362 auto A3 = SymTensor3d_3<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
363
364 return {0, A1, A2, A3};
365 }
366
367 template<class Tacc>
368 inline void store(Tacc &&acc, u32 offset) const {
369 acc[offset + offset_t0] = t0;
370 t1.store(acc, offset + offset_t1);
371 t2.store(acc, offset + offset_t2);
372 t3.store(acc, offset + offset_t3);
373 }
374
375 template<class Tacc>
376 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
377 return SymTensorCollection{
378 acc[offset + offset_t0],
379 SymTensor3d_1<T>::load(acc, offset + offset_t1),
380 SymTensor3d_2<T>::load(acc, offset + offset_t2),
381 SymTensor3d_3<T>::load(acc, offset + offset_t3)};
382 }
383
384 inline SymTensorCollection<T, 0, 3> &operator*=(const T scal) {
385
386 t0 *= scal;
387 t1 *= scal;
388 t2 *= scal;
389 t3 *= scal;
390
391 return *this;
392 }
393
394 inline SymTensorCollection<T, 0, 3> &operator+=(const SymTensorCollection<T, 0, 3> other) {
395
396 t0 += other.t0;
397 t1 += other.t1;
398 t2 += other.t2;
399 t3 += other.t3;
400
401 return *this;
402 }
403
404 inline SymTensorCollection<T, 0, 3> operator-(
405 const SymTensorCollection<T, 0, 3> &other) const {
406 return {t0 - other.t0, t1 - other.t1, t2 - other.t2, t3 - other.t3};
407 }
408 };
409
410 template<class T>
411 struct SymTensorCollection<T, 0, 2> {
412 T t0;
415
416 static constexpr u32 num_component
418
419 static constexpr u32 offset_t0 = 0;
420 static constexpr u32 offset_t1 = 1;
421 static constexpr u32 offset_t2 = offset_t1 + SymTensor3d_1<T>::compo_cnt;
422
423 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) {
424 auto A1 = SymTensor3d_1<T>{v.x(), v.y(), v.z()};
425
426 auto A2 = SymTensor3d_2<T>{
427 A1.v_0 * A1.v_0,
428 A1.v_1 * A1.v_0,
429 A1.v_2 * A1.v_0,
430 A1.v_1 * A1.v_1,
431 A1.v_2 * A1.v_1,
432 A1.v_2 * A1.v_2,
433 };
434
435 return {1, A1, A2};
436 }
437
438 inline static SymTensorCollection zeros() {
439 auto A1 = SymTensor3d_1<T>{0, 0, 0};
440
441 auto A2 = SymTensor3d_2<T>{
442 0,
443 0,
444 0,
445 0,
446 0,
447 0,
448 };
449
450 return {0, A1, A2};
451 }
452
453 template<class Tacc>
454 inline void store(Tacc &&acc, u32 offset) const {
455 acc[offset + offset_t0] = t0;
456 t1.store(acc, offset + offset_t1);
457 t2.store(acc, offset + offset_t2);
458 }
459
460 template<class Tacc>
461 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
462 return SymTensorCollection{
463 acc[offset + offset_t0],
464 SymTensor3d_1<T>::load(acc, offset + offset_t1),
465 SymTensor3d_2<T>::load(acc, offset + offset_t2)};
466 }
467
468 inline SymTensorCollection<T, 0, 2> &operator*=(const T scal) {
469
470 t0 *= scal;
471 t1 *= scal;
472 t2 *= scal;
473
474 return *this;
475 }
476
477 inline SymTensorCollection<T, 0, 2> &operator+=(const SymTensorCollection<T, 0, 2> other) {
478
479 t0 += other.t0;
480 t1 += other.t1;
481 t2 += other.t2;
482
483 return *this;
484 }
485
486 inline SymTensorCollection<T, 0, 2> operator-(
487 const SymTensorCollection<T, 0, 2> &other) const {
488 return {t0 - other.t0, t1 - other.t1, t2 - other.t2};
489 }
490 };
491
492 template<class T>
493 struct SymTensorCollection<T, 0, 1> {
494 T t0;
496
497 static constexpr u32 num_component = 1 + SymTensor3d_1<T>::compo_cnt;
498
499 static constexpr u32 offset_t0 = 0;
500 static constexpr u32 offset_t1 = 1;
501
502 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) {
503 auto A1 = SymTensor3d_1<T>{v.x(), v.y(), v.z()};
504
505 return {1, A1};
506 }
507 inline static SymTensorCollection zeros() {
508 auto A1 = SymTensor3d_1<T>{0, 0, 0};
509
510 return {0, A1};
511 }
512
513 template<class Tacc>
514 inline void store(Tacc &&acc, u32 offset) const {
515 acc[offset + offset_t0] = t0;
516 t1.store(acc, offset + offset_t1);
517 }
518
519 template<class Tacc>
520 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
521 return SymTensorCollection{
522 acc[offset + offset_t0], SymTensor3d_1<T>::load(acc, offset + offset_t1)};
523 }
524
525 inline SymTensorCollection<T, 0, 1> &operator*=(const T scal) {
526
527 t0 *= scal;
528 t1 *= scal;
529
530 return *this;
531 }
532
533 inline SymTensorCollection<T, 0, 1> &operator+=(const SymTensorCollection<T, 0, 1> other) {
534
535 t0 += other.t0;
536 t1 += other.t1;
537
538 return *this;
539 }
540
541 inline SymTensorCollection<T, 0, 1> operator-(
542 const SymTensorCollection<T, 0, 1> &other) const {
543 return {t0 - other.t0, t1 - other.t1};
544 }
545 };
546
547 template<class T>
548 struct SymTensorCollection<T, 0, 0> {
549 T t0;
550
551 static constexpr u32 num_component = 1;
552
553 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) { return {1}; }
554 inline static SymTensorCollection zeros() { return {0}; }
555
556 template<class Tacc>
557 inline void store(Tacc &&acc, u32 offset) const {
558 acc[offset + 0] = t0;
559 }
560
561 template<class Tacc>
562 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
563 return SymTensorCollection{acc[offset + 0]};
564 }
565
566 inline SymTensorCollection<T, 0, 0> &operator*=(const T scal) {
567
568 t0 *= scal;
569
570 return *this;
571 }
572
573 inline SymTensorCollection<T, 0, 0> &operator+=(const SymTensorCollection<T, 0, 0> other) {
574
575 t0 += other.t0;
576
577 return *this;
578 }
579
580 inline SymTensorCollection<T, 0, 0> operator-(
581 const SymTensorCollection<T, 0, 0> &other) const {
582 return {t0 - other.t0};
583 }
584 };
585
587
588 template<class T>
589 struct SymTensorCollection<T, 1, 5> {
590
596
597 static constexpr u32 num_component
601
602 static constexpr u32 offset_t1 = 0;
603 static constexpr u32 offset_t2 = offset_t1 + SymTensor3d_1<T>::compo_cnt;
604 static constexpr u32 offset_t3 = offset_t2 + SymTensor3d_2<T>::compo_cnt;
605 static constexpr u32 offset_t4 = offset_t3 + SymTensor3d_3<T>::compo_cnt;
606 static constexpr u32 offset_t5 = offset_t4 + SymTensor3d_4<T>::compo_cnt;
607
608 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) {
609 auto A1 = SymTensor3d_1<T>{v.x(), v.y(), v.z()};
610
611 auto A2 = SymTensor3d_2<T>{
612 A1.v_0 * A1.v_0,
613 A1.v_1 * A1.v_0,
614 A1.v_2 * A1.v_0,
615 A1.v_1 * A1.v_1,
616 A1.v_2 * A1.v_1,
617 A1.v_2 * A1.v_2,
618 };
619
620 auto A3 = SymTensor3d_3<T>{
621 A2.v_00 * A1.v_0,
622 A2.v_01 * A1.v_0,
623 A2.v_02 * A1.v_0,
624 A2.v_11 * A1.v_0,
625 A2.v_12 * A1.v_0,
626 A2.v_22 * A1.v_0,
627 A2.v_11 * A1.v_1,
628 A2.v_12 * A1.v_1,
629 A2.v_22 * A1.v_1,
630 A2.v_22 * A1.v_2};
631
632 auto A4 = SymTensor3d_4<T>{
633 A3.v_000 * A1.v_0,
634 A3.v_001 * A1.v_0,
635 A3.v_002 * A1.v_0,
636 A3.v_011 * A1.v_0,
637 A3.v_012 * A1.v_0,
638 A3.v_022 * A1.v_0,
639 A3.v_111 * A1.v_0,
640 A3.v_112 * A1.v_0,
641 A3.v_122 * A1.v_0,
642 A3.v_222 * A1.v_0,
643 A3.v_111 * A1.v_1,
644 A3.v_112 * A1.v_1,
645 A3.v_122 * A1.v_1,
646 A3.v_222 * A1.v_1,
647 A3.v_222 * A1.v_2};
648
649 auto A5 = SymTensor3d_5<T>{A4.v_0000 * A1.v_0, A4.v_0001 * A1.v_0, A4.v_0002 * A1.v_0,
650 A4.v_0011 * A1.v_0, A4.v_0012 * A1.v_0, A4.v_0022 * A1.v_0,
651 A4.v_0111 * A1.v_0, A4.v_0112 * A1.v_0, A4.v_0122 * A1.v_0,
652 A4.v_0222 * A1.v_0, A4.v_1111 * A1.v_0, A4.v_1112 * A1.v_0,
653 A4.v_1122 * A1.v_0, A4.v_1222 * A1.v_0, A4.v_2222 * A1.v_0,
654 A4.v_1111 * A1.v_1, A4.v_1112 * A1.v_1, A4.v_1122 * A1.v_1,
655 A4.v_1222 * A1.v_1, A4.v_2222 * A1.v_1, A4.v_2222 * A1.v_2};
656
657 return {A1, A2, A3, A4, A5};
658 }
659
660 inline static SymTensorCollection zeros() {
661 auto A1 = SymTensor3d_1<T>{0, 0, 0};
662
663 auto A2 = SymTensor3d_2<T>{
664 0,
665 0,
666 0,
667 0,
668 0,
669 0,
670 };
671
672 auto A3 = SymTensor3d_3<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
673
674 auto A4 = SymTensor3d_4<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
675
676 auto A5
677 = SymTensor3d_5<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
678
679 return {A1, A2, A3, A4};
680 }
681
682 template<class Tacc>
683 inline void store(Tacc &&acc, u32 offset) const {
684
685 t1.store(acc, offset + offset_t1);
686 t2.store(acc, offset + offset_t2);
687 t3.store(acc, offset + offset_t3);
688 t4.store(acc, offset + offset_t4);
689 t5.store(acc, offset + offset_t5);
690 }
691
692 template<class Tacc>
693 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
694 return SymTensorCollection{
695 SymTensor3d_1<T>::load(acc, offset + offset_t1),
696 SymTensor3d_2<T>::load(acc, offset + offset_t2),
697 SymTensor3d_3<T>::load(acc, offset + offset_t3),
698 SymTensor3d_4<T>::load(acc, offset + offset_t4),
699 SymTensor3d_5<T>::load(acc, offset + offset_t5)};
700 }
701
702 inline SymTensorCollection<T, 1, 5> &operator*=(const T scal) {
703
704 t1 *= scal;
705 t2 *= scal;
706 t3 *= scal;
707 t4 *= scal;
708 t5 *= scal;
709
710 return *this;
711 }
712
713 inline SymTensorCollection<T, 1, 5> &operator+=(const SymTensorCollection<T, 1, 5> other) {
714
715 t1 += other.t1;
716 t2 += other.t2;
717 t3 += other.t3;
718 t4 += other.t4;
719 t5 += other.t5;
720
721 return *this;
722 }
723
724 inline SymTensorCollection<T, 1, 5> operator-(
725 const SymTensorCollection<T, 1, 5> &other) const {
726 return {t1 - other.t1, t2 - other.t2, t3 - other.t3, t4 - other.t4, t5 - other.t5};
727 }
728 };
729
730 template<class T>
731 struct SymTensorCollection<T, 1, 4> {
732
737
738 static constexpr u32 num_component
741
742 static constexpr u32 offset_t1 = 0;
743 static constexpr u32 offset_t2 = offset_t1 + SymTensor3d_1<T>::compo_cnt;
744 static constexpr u32 offset_t3 = offset_t2 + SymTensor3d_2<T>::compo_cnt;
745 static constexpr u32 offset_t4 = offset_t3 + SymTensor3d_3<T>::compo_cnt;
746
747 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) {
748 auto A1 = SymTensor3d_1<T>{v.x(), v.y(), v.z()};
749
750 auto A2 = SymTensor3d_2<T>{
751 A1.v_0 * A1.v_0,
752 A1.v_1 * A1.v_0,
753 A1.v_2 * A1.v_0,
754 A1.v_1 * A1.v_1,
755 A1.v_2 * A1.v_1,
756 A1.v_2 * A1.v_2,
757 };
758
759 auto A3 = SymTensor3d_3<T>{
760 A2.v_00 * A1.v_0,
761 A2.v_01 * A1.v_0,
762 A2.v_02 * A1.v_0,
763 A2.v_11 * A1.v_0,
764 A2.v_12 * A1.v_0,
765 A2.v_22 * A1.v_0,
766 A2.v_11 * A1.v_1,
767 A2.v_12 * A1.v_1,
768 A2.v_22 * A1.v_1,
769 A2.v_22 * A1.v_2};
770
771 auto A4 = SymTensor3d_4<T>{
772 A3.v_000 * A1.v_0,
773 A3.v_001 * A1.v_0,
774 A3.v_002 * A1.v_0,
775 A3.v_011 * A1.v_0,
776 A3.v_012 * A1.v_0,
777 A3.v_022 * A1.v_0,
778 A3.v_111 * A1.v_0,
779 A3.v_112 * A1.v_0,
780 A3.v_122 * A1.v_0,
781 A3.v_222 * A1.v_0,
782 A3.v_111 * A1.v_1,
783 A3.v_112 * A1.v_1,
784 A3.v_122 * A1.v_1,
785 A3.v_222 * A1.v_1,
786 A3.v_222 * A1.v_2};
787
788 return {A1, A2, A3, A4};
789 }
790
791 inline static SymTensorCollection zeros() {
792 auto A1 = SymTensor3d_1<T>{0, 0, 0};
793
794 auto A2 = SymTensor3d_2<T>{
795 0,
796 0,
797 0,
798 0,
799 0,
800 0,
801 };
802
803 auto A3 = SymTensor3d_3<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
804
805 auto A4 = SymTensor3d_4<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
806
807 return {A1, A2, A3, A4};
808 }
809
810 template<class Tacc>
811 inline void store(Tacc &&acc, u32 offset) const {
812
813 t1.store(acc, offset + offset_t1);
814 t2.store(acc, offset + offset_t2);
815 t3.store(acc, offset + offset_t3);
816 t4.store(acc, offset + offset_t4);
817 }
818
819 template<class Tacc>
820 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
821 return SymTensorCollection{
822 SymTensor3d_1<T>::load(acc, offset + offset_t1),
823 SymTensor3d_2<T>::load(acc, offset + offset_t2),
824 SymTensor3d_3<T>::load(acc, offset + offset_t3),
825 SymTensor3d_4<T>::load(acc, offset + offset_t4)};
826 }
827
828 inline SymTensorCollection<T, 1, 4> &operator*=(const T scal) {
829
830 t1 *= scal;
831 t2 *= scal;
832 t3 *= scal;
833 t4 *= scal;
834
835 return *this;
836 }
837
838 inline SymTensorCollection<T, 1, 4> &operator+=(const SymTensorCollection<T, 1, 4> other) {
839
840 t1 += other.t1;
841 t2 += other.t2;
842 t3 += other.t3;
843 t4 += other.t4;
844
845 return *this;
846 }
847
848 inline SymTensorCollection<T, 1, 4> operator-(
849 const SymTensorCollection<T, 1, 4> &other) const {
850 return {t1 - other.t1, t2 - other.t2, t3 - other.t3, t4 - other.t4};
851 }
852 };
853
854 template<class T>
855 struct SymTensorCollection<T, 1, 3> {
856
860
861 static constexpr u32 num_component = SymTensor3d_1<T>::compo_cnt
864
865 static constexpr u32 offset_t1 = 0;
866 static constexpr u32 offset_t2 = offset_t1 + SymTensor3d_1<T>::compo_cnt;
867 static constexpr u32 offset_t3 = offset_t2 + SymTensor3d_2<T>::compo_cnt;
868
869 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) {
870 auto A1 = SymTensor3d_1<T>{v.x(), v.y(), v.z()};
871
872 auto A2 = SymTensor3d_2<T>{
873 A1.v_0 * A1.v_0,
874 A1.v_1 * A1.v_0,
875 A1.v_2 * A1.v_0,
876 A1.v_1 * A1.v_1,
877 A1.v_2 * A1.v_1,
878 A1.v_2 * A1.v_2,
879 };
880
881 auto A3 = SymTensor3d_3<T>{
882 A2.v_00 * A1.v_0,
883 A2.v_01 * A1.v_0,
884 A2.v_02 * A1.v_0,
885 A2.v_11 * A1.v_0,
886 A2.v_12 * A1.v_0,
887 A2.v_22 * A1.v_0,
888 A2.v_11 * A1.v_1,
889 A2.v_12 * A1.v_1,
890 A2.v_22 * A1.v_1,
891 A2.v_22 * A1.v_2};
892
893 return {A1, A2, A3};
894 }
895
896 inline static SymTensorCollection zeros() {
897 auto A1 = SymTensor3d_1<T>{0, 0, 0};
898
899 auto A2 = SymTensor3d_2<T>{
900 0,
901 0,
902 0,
903 0,
904 0,
905 0,
906 };
907
908 auto A3 = SymTensor3d_3<T>{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
909
910 return {A1, A2, A3};
911 }
912
913 template<class Tacc>
914 inline void store(Tacc &&acc, u32 offset) const {
915
916 t1.store(acc, offset + offset_t1);
917 t2.store(acc, offset + offset_t2);
918 t3.store(acc, offset + offset_t3);
919 }
920
921 template<class Tacc>
922 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
923 return SymTensorCollection{
924 SymTensor3d_1<T>::load(acc, offset + offset_t1),
925 SymTensor3d_2<T>::load(acc, offset + offset_t2),
926 SymTensor3d_3<T>::load(acc, offset + offset_t3)};
927 }
928
929 inline SymTensorCollection<T, 1, 3> &operator*=(const T scal) {
930
931 t1 *= scal;
932 t2 *= scal;
933 t3 *= scal;
934
935 return *this;
936 }
937
938 inline SymTensorCollection<T, 1, 3> &operator+=(const SymTensorCollection<T, 1, 3> other) {
939
940 t1 += other.t1;
941 t2 += other.t2;
942 t3 += other.t3;
943
944 return *this;
945 }
946
947 inline SymTensorCollection<T, 1, 3> operator-(
948 const SymTensorCollection<T, 1, 3> &other) const {
949 return {t1 - other.t1, t2 - other.t2, t3 - other.t3};
950 }
951 };
952
953 template<class T>
954 struct SymTensorCollection<T, 1, 2> {
955
958
959 static constexpr u32 num_component
961
962 static constexpr u32 offset_t1 = 0;
963 static constexpr u32 offset_t2 = offset_t1 + SymTensor3d_1<T>::compo_cnt;
964
965 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) {
966 auto A1 = SymTensor3d_1<T>{v.x(), v.y(), v.z()};
967
968 auto A2 = SymTensor3d_2<T>{
969 A1.v_0 * A1.v_0,
970 A1.v_1 * A1.v_0,
971 A1.v_2 * A1.v_0,
972 A1.v_1 * A1.v_1,
973 A1.v_2 * A1.v_1,
974 A1.v_2 * A1.v_2,
975 };
976
977 return {A1, A2};
978 }
979
980 inline static SymTensorCollection zeros() {
981 auto A1 = SymTensor3d_1<T>{0, 0, 0};
982
983 auto A2 = SymTensor3d_2<T>{
984 0,
985 0,
986 0,
987 0,
988 0,
989 0,
990 };
991
992 return {A1, A2};
993 }
994
995 template<class Tacc>
996 inline void store(Tacc &&acc, u32 offset) const {
997
998 t1.store(acc, offset + offset_t1);
999 t2.store(acc, offset + offset_t2);
1000 }
1001
1002 template<class Tacc>
1003 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
1004 return SymTensorCollection{
1005 SymTensor3d_1<T>::load(acc, offset + offset_t1),
1006 SymTensor3d_2<T>::load(acc, offset + offset_t2)};
1007 }
1008
1009 inline SymTensorCollection<T, 1, 2> &operator*=(const T scal) {
1010
1011 t1 *= scal;
1012 t2 *= scal;
1013
1014 return *this;
1015 }
1016
1017 inline SymTensorCollection<T, 1, 2> &operator+=(const SymTensorCollection<T, 1, 2> other) {
1018
1019 t1 += other.t1;
1020 t2 += other.t2;
1021
1022 return *this;
1023 }
1024
1025 inline SymTensorCollection<T, 1, 2> operator-(
1026 const SymTensorCollection<T, 1, 2> &other) const {
1027 return {t1 - other.t1, t2 - other.t2};
1028 }
1029 };
1030
1031 template<class T>
1032 struct SymTensorCollection<T, 1, 1> {
1033
1035
1036 static constexpr u32 num_component = SymTensor3d_1<T>::compo_cnt;
1037
1038 static constexpr u32 offset_t1 = 0;
1039
1040 inline static SymTensorCollection from_vec(const sycl::vec<T, 3> &v) {
1041 auto A1 = SymTensor3d_1<T>{v.x(), v.y(), v.z()};
1042
1043 return {A1};
1044 }
1045 inline static SymTensorCollection zeros() {
1046 auto A1 = SymTensor3d_1<T>{0, 0, 0};
1047
1048 return {A1};
1049 }
1050
1051 template<class Tacc>
1052 inline void store(Tacc &&acc, u32 offset) const {
1053
1054 t1.store(acc, offset + offset_t1);
1055 }
1056
1057 template<class Tacc>
1058 inline static SymTensorCollection load(Tacc &&acc, u32 offset) {
1059 return SymTensorCollection{SymTensor3d_1<T>::load(acc, offset + offset_t1)};
1060 }
1061
1062 inline SymTensorCollection<T, 1, 1> &operator*=(const T scal) {
1063
1064 t1 *= scal;
1065
1066 return *this;
1067 }
1068
1069 inline SymTensorCollection<T, 1, 1> &operator+=(const SymTensorCollection<T, 1, 1> other) {
1070
1071 t1 += other.t1;
1072
1073 return *this;
1074 }
1075
1076 inline SymTensorCollection<T, 1, 1> operator-(
1077 const SymTensorCollection<T, 1, 1> &other) const {
1078 return {t1 - other.t1};
1079 }
1080 };
1081} // namespace shammath
std::uint32_t u32
32 bit unsigned integer
namespace for math utility
Definition AABB.hpp:26