9.1
general documentation
cs_math.h
Go to the documentation of this file.
1#ifndef __CS_MATH_H__
2#define __CS_MATH_H__
3
4/*============================================================================
5 * Mathematical base functions.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2025 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30#include "base/cs_defs.h"
31
32/*----------------------------------------------------------------------------
33 * Standard C library headers
34 *----------------------------------------------------------------------------*/
35
36#include <assert.h>
37#include <math.h>
38
39#if (defined(__NVCC__) && defined(__CUDA_ARCH__)) \
40 || defined(SYCL_LANGUAGE_VERSION) \
41 || defined(HAVE_OPENMP_TARGET)
42#include <float.h>
43#endif
44
45/*----------------------------------------------------------------------------
46 * Local headers
47 *----------------------------------------------------------------------------*/
48
49#if defined(DEBUG) && !defined(NDEBUG) /* Sanity check */
50#include "bft/bft_error.h"
51#endif
52
53/*----------------------------------------------------------------------------*/
54
56
57/*=============================================================================
58 * Local Macro definitions
59 *============================================================================*/
60
61/*============================================================================
62 * Type definition
63 *============================================================================*/
64
65/* Symmetric tensor component name */
66
67typedef enum {
68
74 XZ
75
77
78/*============================================================================
79 * Global variables
80 *============================================================================*/
81
82/* Numerical constants */
83
84#if (defined(__NVCC__) && defined(__CUDA_ARCH__)) \
85 || defined(SYCL_LANGUAGE_VERSION) \
86 || defined(HAVE_OPENMP_TARGET)
87
88/* On GPU, global variables are usually not accessible. */
89
90#define cs_math_zero_threshold FLT_MIN
91#define cs_math_epzero 1e-12
92#define cs_math_infinite_r 1.e30
93#define cs_math_big_r 1.e12
94#define cs_math_pi 3.14159265358979323846
95
96#else
97
98/* General constants accessible on CPU */
99
101extern const cs_real_t cs_math_epzero;
102extern const cs_real_t cs_math_infinite_r;
103extern const cs_real_t cs_math_big_r;
104extern const cs_real_t cs_math_pi;
105
106#endif
107
108#if !(defined(__NVCC__) && defined(__CUDA_ARCH__))
109
110extern const cs_real_t cs_math_1ov3;
111extern const cs_real_t cs_math_2ov3;
112extern const cs_real_t cs_math_4ov3;
113extern const cs_real_t cs_math_5ov3;
114extern const cs_real_t cs_math_1ov6;
115extern const cs_real_t cs_math_1ov12;
116extern const cs_real_t cs_math_1ov24;
117
118/* Identity matrix in dimension 3 */
119static const cs_real_33_t cs_math_33_identity = {{1., 0., 0.,},
120 {0., 1., 0.},
121 {0., 0., 1.}};
122static const cs_real_6_t cs_math_sym_33_identity = {1., 1., 1., 0. ,0., 0.};
123
124#endif
125
126/*----------------------------------------------------------------------------*/
127
129
130/*=============================================================================
131 * Templated inline functions
132 *============================================================================*/
133
134#if defined(__cplusplus)
135
136/*----------------------------------------------------------------------------*/
149/*----------------------------------------------------------------------------*/
150
151template <typename T, typename U>
154 const T xb[3],
155 const U xc[3])
156{
157 return ((xb[0] - xa[0])*xc[0]+(xb[1] - xa[1])*xc[1]+(xb[2] - xa[2])*xc[2]);
158}
159
160/*----------------------------------------------------------------------------*/
172/*----------------------------------------------------------------------------*/
173
174template <typename T, typename U>
177 const U v[3])
178{
179 double uv = u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
180
181 return uv;
182}
183
184/*----------------------------------------------------------------------------*/
194/*----------------------------------------------------------------------------*/
195
196template <typename T>
198cs_math_3_norm(const T v[3])
199{
200 return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
201}
202
203/*----------------------------------------------------------------------------*/
221/*----------------------------------------------------------------------------*/
222
223template <typename T, typename U, typename V>
226 const U t[6],
227 const V n2[3])
228{
229 return ( n1[0] * (t[0]*n2[0] + t[3]*n2[1] + t[5]*n2[2])
230 + n1[1] * (t[3]*n2[0] + t[1]*n2[1] + t[4]*n2[2])
231 + n1[2] * (t[5]*n2[0] + t[4]*n2[1] + t[2]*n2[2]));
232}
233
234/*----------------------------------------------------------------------------*/
244/*----------------------------------------------------------------------------*/
245
246template <typename T>
249{
250 cs_real_t v2 = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
251
252 return v2;
253}
254
255/*----------------------------------------------------------------------------*/
267/*----------------------------------------------------------------------------*/
268
269template <typename T, typename U>
270CS_F_HOST_DEVICE static inline void
271cs_math_3_normalize(const T vin[3],
272 U vout[3])
273{
274 cs_real_t norm = cs_math_3_norm(vin);
275
276 cs_real_t inv_norm = ((norm > cs_math_zero_threshold) ? 1. / norm : 0);
277
278 vout[0] = inv_norm * vin[0];
279 vout[1] = inv_norm * vin[1];
280 vout[2] = inv_norm * vin[2];
281}
282
283/*----------------------------------------------------------------------------*/
297/*----------------------------------------------------------------------------*/
298
299template <typename T, typename U, typename V>
300CS_F_HOST_DEVICE inline void
302 const U v[3],
303 V *restrict mv)
304{
305 mv[0] = m[0]*v[0] + m[3]*v[1] + m[5]*v[2];
306 mv[1] = m[3]*v[0] + m[1]*v[1] + m[4]*v[2];
307 mv[2] = m[5]*v[0] + m[4]*v[1] + m[2]*v[2];
308}
309
310/*----------------------------------------------------------------------------*/
323/*----------------------------------------------------------------------------*/
324
325template <typename T, typename U, typename V>
326CS_F_HOST_DEVICE inline void
328 U factor,
329 V v[3])
330{
331 cs_real_t v_dot_n = (factor -1.) * cs_math_3_dot_product(v, n);
332 for (int i = 0; i < 3; i++)
333 v[i] += v_dot_n * n[i];
334}
335
336/*----------------------------------------------------------------------------*/
350/*----------------------------------------------------------------------------*/
351
352template <typename T, typename U, typename V>
355 const U t[3][3],
356 const V n2[3])
357{
358 cs_real_t n_t_n
359 = ( n1[0]*t[0][0]*n2[0] + n1[1]*t[1][0]*n2[0] + n1[2]*t[2][0]*n2[0]
360 + n1[0]*t[0][1]*n2[1] + n1[1]*t[1][1]*n2[1] + n1[2]*t[2][1]*n2[1]
361 + n1[0]*t[0][2]*n2[2] + n1[1]*t[1][2]*n2[2] + n1[2]*t[2][2]*n2[2]);
362 return n_t_n;
363}
364
365/*----------------------------------------------------------------------------*/
378/*----------------------------------------------------------------------------*/
379
380template <typename T, typename U, typename V>
381CS_F_HOST_DEVICE inline void
383 const U v[3],
384 V *restrict vout)
385{
386 vout[0] = v[0]*(1.-n[0]*n[0])- v[1]* n[1]*n[0] - v[2]* n[2]*n[0];
387 vout[1] = -v[0]* n[0]*n[1] + v[1]*(1.-n[1]*n[1])- v[2]* n[2]*n[1];
388 vout[2] = -v[0]* n[0]*n[2] - v[1]* n[1]*n[2] + v[2]*(1.-n[2]*n[2]);
389}
390
391/*----------------------------------------------------------------------------*/
403/*----------------------------------------------------------------------------*/
404
405template <typename T, typename U, typename V>
406CS_F_HOST_DEVICE static inline void
408 const U v[3],
409 V *restrict uv)
410{
411 uv[0] = u[1]*v[2] - u[2]*v[1];
412 uv[1] = u[2]*v[0] - u[0]*v[2];
413 uv[2] = u[0]*v[1] - u[1]*v[0];
414}
415
416/*----------------------------------------------------------------------------*/
423/*----------------------------------------------------------------------------*/
424
425template <cs_lnum_t n, typename T>
426CS_F_HOST_DEVICE inline void
428 T b[n][n])
429{
430 T *p_a[n];
431 T t[n][n*2];
432
433 for (size_t i = 0; i < n; i++) {
434 p_a[i] = t[i];
435 for (size_t j = 0; j < n; j++) {
436 p_a[i][j] = a[i][j];
437 p_a[i][j+n] = 0;
438 }
439 p_a[i][i+n] = 1;
440 }
441
442 for (size_t i = 0; i < n; i++) {
443
444 // Pivot matrix rows (swap pointers)
445 for (size_t j = i+1; j < n; j++) {
446 if (cs::abs(p_a[i][i]) < cs::abs(p_a[j][i])) {
447 T* tmp = p_a[j];
448 p_a[j] = p_a[i];
449 p_a[i] = tmp;
450 }
451 }
452 // Linear combination of each row with other rows
453 for (size_t j = 0; j < n; j++) {
454 if (j != i) {
455 T s = p_a[j][i] / p_a[i][i];
456 for (size_t k = 0; k < 2*n; k++) {
457 p_a[j][k] -= p_a[i][k] * s;
458 }
459 }
460 }
461
462 }
463
464 // Scale and copy results
465 for (size_t i = 0; i < n; i++) {
466 T s = (T)1. / p_a[i][i];
467 for (size_t j = 0; j < n; j++) {
468 b[i][j] = p_a[i][n+j] * s;
469 }
470 }
471}
472
473/*----------------------------------------------------------------------------*/
481/*----------------------------------------------------------------------------*/
482
483template <typename T>
486{
487 T t[3][3] = {{a[0], a[3], a[5]},
488 {a[3], a[1], a[4]},
489 {a[5], a[4], a[2]}};
490 T s[3][3];
491
493
494 a[0] = s[0][0];
495 a[1] = s[1][1];
496 a[2] = s[2][2];
497
498 a[3] = s[0][1];
499 a[4] = s[1][2];
500 a[5] = s[0][2];
501}
502
503namespace cs {
504
505/*----------------------------------------------------------------------------*/
506/*
507 * \brief Return absolute value of a number.
508 *
509 * Specialized versions for floating point numbers should be faster than
510 * base version from cs_defs.h.
511 *
512 * \param[in] a value
513 *
514 * \return absolute value of a
515 */
516/*----------------------------------------------------------------------------*/
517
518CS_F_HOST_DEVICE inline double
519abs(const double a)
520{
521 return fabs(a);
522}
523
524CS_F_HOST_DEVICE inline float
525abs(const float a)
526{
527 return fabsf(a);
528}
529
530/*----------------------------------------------------------------------------*/
531/*
532 * \brief Return minimum of two values.
533 *
534 * Specialized versions for floating point numbers should be faster than
535 * base version from cs_defs.h.
536 *
537 * \param[in] a first value
538 * \param[in] b second value
539 *
540 * \return minimum of a and b
541 */
542/*----------------------------------------------------------------------------*/
543
544CS_F_HOST_DEVICE inline double
545min(const double a,
546 const double b)
547{
548 return fmin(a, b);
549}
550
551CS_F_HOST_DEVICE inline float
552min(const float a,
553 const float b)
554{
555 return fminf(a, b);
556}
557
558/*----------------------------------------------------------------------------*/
559/*
560 * \brief Return maximum of two values.
561 *
562 * Specialized versions for floating point numbers should be faster than
563 * base version from cs_defs.h.
564 *
565 * \param[in] a first value
566 * \param[in] b second value
567 *
568 * \return maximum of a and b
569 */
570/*----------------------------------------------------------------------------*/
571
572CS_F_HOST_DEVICE inline double
573max(const double a,
574 const double b)
575{
576 return fmax(a, b);
577}
578
579CS_F_HOST_DEVICE inline float
580max(const float a,
581 const float b)
582{
583 return fmaxf(a, b);
584}
585
586/*----------------------------------------------------------------------------*/
587/*
588 * \brief Clamp function for a given scalar value.
589 *
590 * Specialized versions for floating point numbers should be faster than
591 * base version from cs_defs.h.
592 *
593 * \param[in] x initial value
594 * \param[in] xmin min value for clamping
595 * \param[in] xmax max value for clamping
596 *
597 * \return clamped value which is 'x' if xmin < x < xmax or lower/upper bound
598 * otherwise
599 */
600/*----------------------------------------------------------------------------*/
601
602CS_F_HOST_DEVICE inline double
603clamp(const double x,
604 const double xmin,
605 const double xmax)
606{
607 return fmin(xmax, fmax(xmin, x));
608}
609
610CS_F_HOST_DEVICE inline float
611clamp(const float x,
612 const float xmin,
613 const float xmax)
614{
615 return fminf(xmax, fmaxf(xmin, x));
616}
617
618/*----------------------------------------------------------------------------*/
626/*----------------------------------------------------------------------------*/
627
628CS_F_HOST_DEVICE inline float
629pow2(float x)
630{
631 return x*x;
632}
633
634CS_F_HOST_DEVICE inline double
635pow2(double x)
636{
637 return x*x;
638}
639
640} // namespace cs
641
642#endif // defined(__cplusplus)
643
645
646/*=============================================================================
647 * Inline static functions
648 *============================================================================*/
649
650/*----------------------------------------------------------------------------*/
659/*----------------------------------------------------------------------------*/
660
661static inline int
663 int k)
664{
665 int ret = 1;
666 assert(n >= k);
667
668 const int n_iter = (k > n-k) ? n-k : k;
669 for (int j = 1; j <= n_iter; j++, n--) {
670 if (n % j == 0)
671 ret *= n/j;
672 else if (ret % j == 0)
673 ret = ret/j*n;
674 else
675 ret = (ret*n)/j;
676 }
677
678 return ret;
679}
680
681/*----------------------------------------------------------------------------*/
689/*----------------------------------------------------------------------------*/
690
691CS_F_HOST_DEVICE static inline cs_real_t
693{
694 cs_real_t ret = (x < 0) ? -x : x;
695
696 return ret;
697}
698
699/*----------------------------------------------------------------------------*/
707/*----------------------------------------------------------------------------*/
708
709CS_F_HOST_DEVICE static inline cs_real_t
711 cs_real_t y)
712{
713 cs_real_t ret = (x < y) ? x : y;
714
715 return ret;
716}
717
718/*----------------------------------------------------------------------------*/
726/*----------------------------------------------------------------------------*/
727
728CS_F_HOST_DEVICE static inline cs_real_t
730 cs_real_t y)
731{
732 cs_real_t ret = (x < y) ? y : x;
733
734 return ret;
735}
736
737/*----------------------------------------------------------------------------*/
748/*----------------------------------------------------------------------------*/
749
750CS_F_HOST_DEVICE static inline cs_real_t
752 cs_real_t xmin,
753 cs_real_t xmax)
754{
755 cs_real_t ret = cs_math_fmin(xmax, cs_math_fmax(xmin, x));
756
757 return ret;
758}
759
760/*----------------------------------------------------------------------------*/
768/*----------------------------------------------------------------------------*/
769
770CS_F_HOST_DEVICE static inline cs_real_t
772{
773 return x*x;
774}
775
776/*----------------------------------------------------------------------------*/
784/*----------------------------------------------------------------------------*/
785
786CS_F_HOST_DEVICE static inline cs_real_t
788{
789 return x*x;
790}
791
792/*----------------------------------------------------------------------------*/
800/*----------------------------------------------------------------------------*/
801
802CS_F_HOST_DEVICE static inline cs_real_t
804{
805 return x*x*x;
806}
807
808/*----------------------------------------------------------------------------*/
816/*----------------------------------------------------------------------------*/
817
818CS_F_HOST_DEVICE static inline cs_real_t
820{
821 cs_real_t x2 = x * x;
822 return x2 * x2;
823}
824
825/*----------------------------------------------------------------------------*/
833/*----------------------------------------------------------------------------*/
834
835CS_F_HOST_DEVICE static inline cs_real_t
837{
838 cs_real_t x2 = x * x;
839 return x * x2 * x2;
840}
841
842/*----------------------------------------------------------------------------*/
852/*----------------------------------------------------------------------------*/
853
854CS_F_HOST_DEVICE static inline cs_real_t
856 const cs_real_t xb[3])
857{
858 cs_real_t v[3];
859
860 v[0] = xb[0] - xa[0];
861 v[1] = xb[1] - xa[1];
862 v[2] = xb[2] - xa[2];
863
864 return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
865}
866
867/*----------------------------------------------------------------------------*/
877/*----------------------------------------------------------------------------*/
878
879CS_F_HOST_DEVICE static inline cs_real_t
881 const cs_real_t xb[3],
882 const cs_real_t xc[3])
883{
884 return ((xb[0] - xa[0])*xc[0]+(xb[1] - xa[1])*xc[1]+(xb[2] - xa[2])*xc[2]);
885}
886
887/*----------------------------------------------------------------------------*/
897/*----------------------------------------------------------------------------*/
898
899CS_F_HOST_DEVICE static inline cs_real_t
901 const cs_real_t xb[3])
902{
903 cs_real_t v[3] = {xb[0] - xa[0],
904 xb[1] - xa[1],
905 xb[2] - xa[2]};
906
907 return (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
908}
909
910/*----------------------------------------------------------------------------*/
919/*----------------------------------------------------------------------------*/
920
921CS_F_HOST_DEVICE static inline cs_real_t
923 const cs_real_t v[3])
924{
925 cs_real_t uv = u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
926
927 return uv;
928}
929
930/*----------------------------------------------------------------------------*/
940/*----------------------------------------------------------------------------*/
941
942CS_F_HOST_DEVICE static inline cs_real_t
944 const cs_real_t t[3][3],
945 const cs_real_t n2[3])
946{
947 cs_real_t n_t_n
948 = ( n1[0]*t[0][0]*n2[0] + n1[1]*t[1][0]*n2[0] + n1[2]*t[2][0]*n2[0]
949 + n1[0]*t[0][1]*n2[1] + n1[1]*t[1][1]*n2[1] + n1[2]*t[2][1]*n2[1]
950 + n1[0]*t[0][2]*n2[2] + n1[1]*t[1][2]*n2[2] + n1[2]*t[2][2]*n2[2]);
951 return n_t_n;
952}
953
954/*----------------------------------------------------------------------------*/
968/*----------------------------------------------------------------------------*/
969
970CS_F_HOST_DEVICE static inline cs_real_t
972 const cs_real_t t[6],
973 const cs_real_t n2[3])
974{
975 return ( n1[0] * (t[0]*n2[0] + t[3]*n2[1] + t[5]*n2[2])
976 + n1[1] * (t[3]*n2[0] + t[1]*n2[1] + t[4]*n2[2])
977 + n1[2] * (t[5]*n2[0] + t[4]*n2[1] + t[2]*n2[2]));
978}
979
980/*----------------------------------------------------------------------------*/
988/*----------------------------------------------------------------------------*/
989
990CS_F_HOST_DEVICE static inline cs_real_t
992{
993 return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
994}
995
996/*----------------------------------------------------------------------------*/
1004/*----------------------------------------------------------------------------*/
1005
1006CS_F_HOST_DEVICE static inline cs_real_t
1008{
1009 cs_real_t v2 = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
1010
1011 return v2;
1012}
1013
1014/*----------------------------------------------------------------------------*/
1023/*----------------------------------------------------------------------------*/
1024
1025CS_F_HOST_DEVICE static inline void
1027 cs_real_t vout[3])
1028{
1029 cs_real_t norm = cs_math_3_norm(vin);
1030
1031 cs_real_t inv_norm = ((norm > cs_math_zero_threshold) ? 1. / norm : 0);
1032
1033 vout[0] = inv_norm * vin[0];
1034 vout[1] = inv_norm * vin[1];
1035 vout[2] = inv_norm * vin[2];
1036}
1037
1038/*----------------------------------------------------------------------------*/
1049/*----------------------------------------------------------------------------*/
1050
1051CS_F_HOST_DEVICE static inline void
1053 const cs_real_t thres,
1054 cs_real_t vout[3])
1055{
1056 cs_real_t norm = cs_math_3_norm(vin);
1057
1058 cs_real_t inv_norm = ((norm > thres) ? 1. / norm : 1. / thres);
1059
1060 vout[0] = inv_norm * vin[0];
1061 vout[1] = inv_norm * vin[1];
1062 vout[2] = inv_norm * vin[2];
1063}
1064
1065/*----------------------------------------------------------------------------*/
1074/*----------------------------------------------------------------------------*/
1075
1076CS_F_HOST_DEVICE static inline void
1078 const cs_real_t v[3],
1079 cs_real_t *restrict vout)
1080{
1081 vout[0] = v[0]*(1.-n[0]*n[0])- v[1]* n[1]*n[0] - v[2]* n[2]*n[0];
1082 vout[1] = -v[0]* n[0]*n[1] + v[1]*(1.-n[1]*n[1])- v[2]* n[2]*n[1];
1083 vout[2] = -v[0]* n[0]*n[2] - v[1]* n[1]*n[2] + v[2]*(1.-n[2]*n[2]);
1084}
1085
1086/*----------------------------------------------------------------------------*/
1095/*----------------------------------------------------------------------------*/
1096
1097CS_F_HOST_DEVICE static inline void
1099 cs_real_t factor,
1100 cs_real_t v[3])
1101{
1102 cs_real_t v_dot_n = (factor -1.) * cs_math_3_dot_product(v, n);
1103 for (int i = 0; i < 3; i++)
1104 v[i] += v_dot_n * n[i];
1105}
1106
1107/*----------------------------------------------------------------------------*/
1117/*----------------------------------------------------------------------------*/
1118
1119CS_F_HOST_DEVICE static inline void
1121 cs_real_t factor,
1122 cs_real_t t[3][3])
1123{
1124 cs_real_t n_t_n = (factor -1.) *
1125 ( n[0] * t[0][0] * n[0] + n[1] * t[1][0] * n[0] + n[2] * t[2][0] * n[0]
1126 + n[0] * t[0][1] * n[1] + n[1] * t[1][1] * n[1] + n[2] * t[2][1] * n[1]
1127 + n[0] * t[0][2] * n[2] + n[1] * t[1][2] * n[2] + n[2] * t[2][2] * n[2]);
1128 for (int i = 0; i < 3; i++) {
1129 for (int j = 0; j < 3; j++)
1130 t[i][j] += n_t_n * n[i] * n[j];
1131 }
1132}
1133/*----------------------------------------------------------------------------*/
1142/*----------------------------------------------------------------------------*/
1143
1144CS_F_HOST_DEVICE static inline void
1146 const cs_real_t v[3],
1147 cs_real_t *restrict mv)
1148{
1149 mv[0] = m[0][0]*v[0] + m[0][1]*v[1] + m[0][2]*v[2];
1150 mv[1] = m[1][0]*v[0] + m[1][1]*v[1] + m[1][2]*v[2];
1151 mv[2] = m[2][0]*v[0] + m[2][1]*v[1] + m[2][2]*v[2];
1152}
1153
1154/*----------------------------------------------------------------------------*/
1163/*----------------------------------------------------------------------------*/
1164
1165CS_F_HOST_DEVICE static inline void
1167 const cs_real_t v[3],
1168 cs_real_t *restrict mv)
1169{
1170 mv[0] += m[0][0]*v[0] + m[0][1]*v[1] + m[0][2]*v[2];
1171 mv[1] += m[1][0]*v[0] + m[1][1]*v[1] + m[1][2]*v[2];
1172 mv[2] += m[2][0]*v[0] + m[2][1]*v[1] + m[2][2]*v[2];
1173}
1174
1175/*----------------------------------------------------------------------------*/
1184/*----------------------------------------------------------------------------*/
1185
1186CS_F_HOST_DEVICE static inline void
1188 const cs_real_t v[3],
1189 cs_real_t *restrict mv)
1190{
1191 mv[0] = m[0][0]*v[0] + m[1][0]*v[1] + m[2][0]*v[2];
1192 mv[1] = m[0][1]*v[0] + m[1][1]*v[1] + m[2][1]*v[2];
1193 mv[2] = m[0][2]*v[0] + m[1][2]*v[1] + m[2][2]*v[2];
1194}
1195
1196/*----------------------------------------------------------------------------*/
1206/*----------------------------------------------------------------------------*/
1207
1208CS_F_HOST_DEVICE static inline void
1210 const cs_real_t v[3],
1211 cs_real_t *restrict mv)
1212{
1213 mv[0] = m[0]*v[0] + m[3]*v[1] + m[5]*v[2];
1214 mv[1] = m[3]*v[0] + m[1]*v[1] + m[4]*v[2];
1215 mv[2] = m[5]*v[0] + m[4]*v[1] + m[2]*v[2];
1216}
1217
1218/*----------------------------------------------------------------------------*/
1228/*----------------------------------------------------------------------------*/
1229
1230CS_F_HOST_DEVICE static inline void
1232 const cs_real_t v[3],
1233 cs_real_t *restrict mv)
1234{
1235 mv[0] += m[0] * v[0] + m[3] * v[1] + m[5] * v[2];
1236 mv[1] += m[3] * v[0] + m[1] * v[1] + m[4] * v[2];
1237 mv[2] += m[5] * v[0] + m[4] * v[1] + m[2] * v[2];
1238}
1239
1240/*----------------------------------------------------------------------------*/
1250/*----------------------------------------------------------------------------*/
1251
1252CS_F_HOST_DEVICE static inline cs_real_t
1254 const cs_real_t m2[6])
1255{
1256 return m1[0]*m2[0] + 2.*m1[3]*m2[3] + 2.*m1[5]*m2[5]
1257 + m1[1]*m2[1] + 2.*m1[4]*m2[4]
1258 + m1[2]*m2[2];
1259}
1260
1261/*----------------------------------------------------------------------------*/
1269/*----------------------------------------------------------------------------*/
1270
1271CS_F_HOST_DEVICE static inline cs_real_t
1273{
1274 return (t[0][0] + t[1][1] + t[2][2]);
1275}
1276
1277/*----------------------------------------------------------------------------*/
1285/*----------------------------------------------------------------------------*/
1286
1287CS_F_HOST_DEVICE static inline cs_real_t
1289{
1290 return (t[0] + t[1] + t[2]);
1291}
1292
1293/*----------------------------------------------------------------------------*/
1302/*----------------------------------------------------------------------------*/
1303
1304CS_F_HOST_DEVICE static inline void
1306 const cs_real_t v[6],
1307 cs_real_t *restrict mv)
1308{
1309 for (int i = 0; i < 6; i++) {
1310 for (int j = 0; j < 6; j++)
1311 mv[i] = m[i][j] * v[j];
1312 }
1313}
1314
1315/*----------------------------------------------------------------------------*/
1324/*----------------------------------------------------------------------------*/
1325
1326CS_F_HOST_DEVICE static inline void
1328 const cs_real_t v[6],
1329 cs_real_t *restrict mv)
1330{
1331 for (int i = 0; i < 6; i++) {
1332 for (int j = 0; j < 6; j++)
1333 mv[i] += m[i][j] * v[j];
1334 }
1335}
1336
1337/*----------------------------------------------------------------------------*/
1345/*----------------------------------------------------------------------------*/
1346
1347CS_F_HOST_DEVICE static inline cs_real_t
1349{
1350 const cs_real_t com0 = m[1][1]*m[2][2] - m[2][1]*m[1][2];
1351 const cs_real_t com1 = m[2][1]*m[0][2] - m[0][1]*m[2][2];
1352 const cs_real_t com2 = m[0][1]*m[1][2] - m[1][1]*m[0][2];
1353
1354 return m[0][0]*com0 + m[1][0]*com1 + m[2][0]*com2;
1355}
1356
1357/*----------------------------------------------------------------------------*/
1365/*----------------------------------------------------------------------------*/
1366
1367CS_F_HOST_DEVICE static inline cs_real_t
1369{
1370 const cs_real_t com0 = m[1]*m[2] - m[4]*m[4];
1371 const cs_real_t com1 = m[4]*m[5] - m[3]*m[2];
1372 const cs_real_t com2 = m[3]*m[4] - m[1]*m[5];
1373
1374 return m[0]*com0 + m[3]*com1 + m[5]*com2;
1375}
1376
1377/*----------------------------------------------------------------------------*/
1385/*----------------------------------------------------------------------------*/
1386
1387CS_F_HOST_DEVICE static inline void
1389 const cs_real_t v[3],
1390 cs_real_t *restrict uv)
1391{
1392 uv[0] = (u[0] + v[0]) / 2.0;
1393 uv[1] = (u[1] + v[1]) / 2.0;
1394 uv[2] = (u[2] + v[2]) / 2.0;
1395}
1396
1397/*----------------------------------------------------------------------------*/
1405/*----------------------------------------------------------------------------*/
1406
1407#if defined(__INTEL_COMPILER)
1408#pragma optimization_level 0 /* Bug with O1 or above with icc 15.0.1 20141023 */
1409#endif
1410
1411CS_F_HOST_DEVICE static inline void
1413 const cs_real_t v[3],
1414 cs_real_t *restrict uv)
1415{
1416 uv[0] = u[1]*v[2] - u[2]*v[1];
1417 uv[1] = u[2]*v[0] - u[0]*v[2];
1418 uv[2] = u[0]*v[1] - u[1]*v[0];
1419}
1420
1421/*----------------------------------------------------------------------------*/
1431/*----------------------------------------------------------------------------*/
1432
1433#if defined(__INTEL_COMPILER)
1434#pragma optimization_level 0 /* Bug with O1 or above with icc 15.0.1 20141023 */
1435#endif
1436
1437CS_F_HOST_DEVICE static inline cs_real_t
1439 const cs_real_t v[3],
1440 const cs_real_t w[3])
1441{
1442 return (u[1]*v[2] - u[2]*v[1]) * w[0]
1443 + (u[2]*v[0] - u[0]*v[2]) * w[1]
1444 + (u[0]*v[1] - u[1]*v[0]) * w[2];
1445}
1446
1447/*----------------------------------------------------------------------------*/
1457/*----------------------------------------------------------------------------*/
1458
1459CS_F_HOST_DEVICE static inline void
1461 cs_real_t axes[3][3])
1462{
1463 assert(cs_math_3_norm(vect) > cs_math_zero_threshold);
1464
1465 // Compute normal - third axis
1466 cs_math_3_normalize(vect, axes[2]);
1467
1468 // Compute base's first axis
1469 // First test projection of Ox
1470 cs_real_t Ox[3] = {1., 0., 0.};
1471 cs_real_t w[3] = {0.};
1472
1473 cs_math_3_orthogonal_projection(axes[2], Ox, w);
1474
1475 // If Ox projection is null, project Oy
1477 cs_real_t Oy[3] = {0., 1., 0.};
1478 cs_math_3_orthogonal_projection(axes[2], Oy, w);
1479 }
1480
1481 cs_math_3_normalize(w, axes[0]);
1482
1483 // Compute base's second axis using cross product
1484 cs_math_3_cross_product(axes[2], axes[0], axes[1]);
1485}
1486
1487/*----------------------------------------------------------------------------*/
1494/*----------------------------------------------------------------------------*/
1495
1496CS_F_HOST_DEVICE static inline void
1498 cs_real_t out[3][3])
1499{
1500 out[0][0] = in[1][1]*in[2][2] - in[2][1]*in[1][2];
1501 out[0][1] = in[2][1]*in[0][2] - in[0][1]*in[2][2];
1502 out[0][2] = in[0][1]*in[1][2] - in[1][1]*in[0][2];
1503
1504 out[1][0] = in[2][0]*in[1][2] - in[1][0]*in[2][2];
1505 out[1][1] = in[0][0]*in[2][2] - in[2][0]*in[0][2];
1506 out[1][2] = in[1][0]*in[0][2] - in[0][0]*in[1][2];
1507
1508 out[2][0] = in[1][0]*in[2][1] - in[2][0]*in[1][1];
1509 out[2][1] = in[2][0]*in[0][1] - in[0][0]*in[2][1];
1510 out[2][2] = in[0][0]*in[1][1] - in[1][0]*in[0][1];
1511
1512 const double det = in[0][0]*out[0][0]+in[1][0]*out[0][1]+in[2][0]*out[0][2];
1513 const double invdet = 1./det;
1514
1515 out[0][0] *= invdet, out[0][1] *= invdet, out[0][2] *= invdet;
1516 out[1][0] *= invdet, out[1][1] *= invdet, out[1][2] *= invdet;
1517 out[2][0] *= invdet, out[2][1] *= invdet, out[2][2] *= invdet;
1518}
1519
1520/*----------------------------------------------------------------------------*/
1526/*----------------------------------------------------------------------------*/
1527
1528CS_F_HOST_DEVICE static inline void
1530{
1531 cs_real_t a00 = a[1][1]*a[2][2] - a[2][1]*a[1][2];
1532 cs_real_t a01 = a[2][1]*a[0][2] - a[0][1]*a[2][2];
1533 cs_real_t a02 = a[0][1]*a[1][2] - a[1][1]*a[0][2];
1534 cs_real_t a10 = a[2][0]*a[1][2] - a[1][0]*a[2][2];
1535 cs_real_t a11 = a[0][0]*a[2][2] - a[2][0]*a[0][2];
1536 cs_real_t a12 = a[1][0]*a[0][2] - a[0][0]*a[1][2];
1537 cs_real_t a20 = a[1][0]*a[2][1] - a[2][0]*a[1][1];
1538 cs_real_t a21 = a[2][0]*a[0][1] - a[0][0]*a[2][1];
1539 cs_real_t a22 = a[0][0]*a[1][1] - a[1][0]*a[0][1];
1540
1541 double det_inv = 1. / (a[0][0]*a00 + a[1][0]*a01 + a[2][0]*a02);
1542
1543 a[0][0] = a00 * det_inv;
1544 a[0][1] = a01 * det_inv;
1545 a[0][2] = a02 * det_inv;
1546 a[1][0] = a10 * det_inv;
1547 a[1][1] = a11 * det_inv;
1548 a[1][2] = a12 * det_inv;
1549 a[2][0] = a20 * det_inv;
1550 a[2][1] = a21 * det_inv;
1551 a[2][2] = a22 * det_inv;
1552}
1553
1554/*----------------------------------------------------------------------------*/
1561/*----------------------------------------------------------------------------*/
1562
1563CS_F_HOST_DEVICE static inline void
1565{
1566 cs_real_t a00 = a[1][1]*a[2][2] - a[2][1]*a[1][2];
1567 cs_real_t a01 = a[2][1]*a[0][2] - a[0][1]*a[2][2];
1568 cs_real_t a02 = a[0][1]*a[1][2] - a[1][1]*a[0][2];
1569 cs_real_t a11 = a[0][0]*a[2][2] - a[2][0]*a[0][2];
1570 cs_real_t a12 = a[1][0]*a[0][2] - a[0][0]*a[1][2];
1571 cs_real_t a22 = a[0][0]*a[1][1] - a[1][0]*a[0][1];
1572
1573 double det_inv = 1. / (a[0][0]*a00 + a[1][0]*a01 + a[2][0]*a02);
1574
1575 a[0][0] = a00 * det_inv;
1576 a[0][1] = a01 * det_inv;
1577 a[0][2] = a02 * det_inv;
1578 a[1][0] = a01 * det_inv;
1579 a[1][1] = a11 * det_inv;
1580 a[1][2] = a12 * det_inv;
1581 a[2][0] = a02 * det_inv;
1582 a[2][1] = a12 * det_inv;
1583 a[2][2] = a22 * det_inv;
1584}
1585
1586/*----------------------------------------------------------------------------*/
1596/*----------------------------------------------------------------------------*/
1597
1598CS_F_HOST_DEVICE static inline void
1600 cs_real_t *restrict sout)
1601{
1602 double detinv;
1603
1604 sout[0] = s[1]*s[2] - s[4]*s[4];
1605 sout[1] = s[0]*s[2] - s[5]*s[5];
1606 sout[2] = s[0]*s[1] - s[3]*s[3];
1607 sout[3] = s[4]*s[5] - s[3]*s[2];
1608 sout[4] = s[3]*s[5] - s[0]*s[4];
1609 sout[5] = s[3]*s[4] - s[1]*s[5];
1610
1611 detinv = 1. / (s[0]*sout[0] + s[3]*sout[3] + s[5]*sout[5]);
1612
1613 sout[0] *= detinv;
1614 sout[1] *= detinv;
1615 sout[2] *= detinv;
1616 sout[3] *= detinv;
1617 sout[4] *= detinv;
1618 sout[5] *= detinv;
1619}
1620
1621/*----------------------------------------------------------------------------*/
1629/*----------------------------------------------------------------------------*/
1630
1631CS_F_HOST_DEVICE static inline void
1633 const cs_real_t m2[3][3],
1634 cs_real_t mout[3][3])
1635{
1636 mout[0][0] = m1[0][0]*m2[0][0] + m1[0][1]*m2[1][0] + m1[0][2]*m2[2][0];
1637 mout[0][1] = m1[0][0]*m2[0][1] + m1[0][1]*m2[1][1] + m1[0][2]*m2[2][1];
1638 mout[0][2] = m1[0][0]*m2[0][2] + m1[0][1]*m2[1][2] + m1[0][2]*m2[2][2];
1639
1640 mout[1][0] = m1[1][0]*m2[0][0] + m1[1][1]*m2[1][0] + m1[1][2]*m2[2][0];
1641 mout[1][1] = m1[1][0]*m2[0][1] + m1[1][1]*m2[1][1] + m1[1][2]*m2[2][1];
1642 mout[1][2] = m1[1][0]*m2[0][2] + m1[1][1]*m2[1][2] + m1[1][2]*m2[2][2];
1643
1644 mout[2][0] = m1[2][0]*m2[0][0] + m1[2][1]*m2[1][0] + m1[2][2]*m2[2][0];
1645 mout[2][1] = m1[2][0]*m2[0][1] + m1[2][1]*m2[1][1] + m1[2][2]*m2[2][1];
1646 mout[2][2] = m1[2][0]*m2[0][2] + m1[2][1]*m2[1][2] + m1[2][2]*m2[2][2];
1647}
1648
1649/*----------------------------------------------------------------------------*/
1658/*----------------------------------------------------------------------------*/
1659
1660CS_F_HOST_DEVICE static inline void
1662 const cs_real_t q[3][3],
1663 cs_real_t mout[3][3])
1664{
1665 /* _m = M.Q */
1666 cs_real_33_t _m;
1667 _m[0][0] = m[0][0]*q[0][0] + m[0][1]*q[1][0] + m[0][2]*q[2][0];
1668 _m[0][1] = m[0][0]*q[0][1] + m[0][1]*q[1][1] + m[0][2]*q[2][1];
1669 _m[0][2] = m[0][0]*q[0][2] + m[0][1]*q[1][2] + m[0][2]*q[2][2];
1670
1671 _m[1][0] = m[1][0]*q[0][0] + m[1][1]*q[1][0] + m[1][2]*q[2][0];
1672 _m[1][1] = m[1][0]*q[0][1] + m[1][1]*q[1][1] + m[1][2]*q[2][1];
1673 _m[1][2] = m[1][0]*q[0][2] + m[1][1]*q[1][2] + m[1][2]*q[2][2];
1674
1675 _m[2][0] = m[2][0]*q[0][0] + m[2][1]*q[1][0] + m[2][2]*q[2][0];
1676 _m[2][1] = m[2][0]*q[0][1] + m[2][1]*q[1][1] + m[2][2]*q[2][1];
1677 _m[2][2] = m[2][0]*q[0][2] + m[2][1]*q[1][2] + m[2][2]*q[2][2];
1678
1679 /* mout = Q^t _m */
1680 mout[0][0] = q[0][0]*_m[0][0] + q[1][0]*_m[1][0] + q[2][0]*_m[2][0];
1681 mout[0][1] = q[0][0]*_m[0][1] + q[1][0]*_m[1][1] + q[2][0]*_m[2][1];
1682 mout[0][2] = q[0][0]*_m[0][2] + q[1][0]*_m[1][2] + q[2][0]*_m[2][2];
1683
1684 mout[1][0] = q[0][1]*_m[0][0] + q[1][1]*_m[1][0] + q[2][1]*_m[2][0];
1685 mout[1][1] = q[0][1]*_m[0][1] + q[1][1]*_m[1][1] + q[2][1]*_m[2][1];
1686 mout[1][2] = q[0][1]*_m[0][2] + q[1][1]*_m[1][2] + q[2][1]*_m[2][2];
1687
1688 mout[2][0] = q[0][2]*_m[0][0] + q[1][2]*_m[1][0] + q[2][2]*_m[2][0];
1689 mout[2][1] = q[0][2]*_m[0][1] + q[1][2]*_m[1][1] + q[2][2]*_m[2][1];
1690 mout[2][2] = q[0][2]*_m[0][2] + q[1][2]*_m[1][2] + q[2][2]*_m[2][2];
1691}
1692
1693/*----------------------------------------------------------------------------*/
1702/*----------------------------------------------------------------------------*/
1703
1704CS_F_HOST_DEVICE static inline void
1706 const cs_real_t q[3][3],
1707 cs_real_t mout[6])
1708{
1709 /* _m = M.Q */
1710 cs_real_33_t _m;
1711 _m[0][0] = m[0]*q[0][0] + m[3]*q[1][0] + m[5]*q[2][0];
1712 _m[0][1] = m[0]*q[0][1] + m[3]*q[1][1] + m[5]*q[2][1];
1713 _m[0][2] = m[0]*q[0][2] + m[3]*q[1][2] + m[5]*q[2][2];
1714
1715 _m[1][0] = m[3]*q[0][0] + m[1]*q[1][0] + m[4]*q[2][0];
1716 _m[1][1] = m[3]*q[0][1] + m[1]*q[1][1] + m[4]*q[2][1];
1717 _m[1][2] = m[3]*q[0][2] + m[1]*q[1][2] + m[4]*q[2][2];
1718
1719 _m[2][0] = m[5]*q[0][0] + m[4]*q[1][0] + m[2]*q[2][0];
1720 _m[2][1] = m[5]*q[0][1] + m[4]*q[1][1] + m[2]*q[2][1];
1721 _m[2][2] = m[5]*q[0][2] + m[4]*q[1][2] + m[2]*q[2][2];
1722
1723 /* mout = Q^t _m */
1724 mout[0] = q[0][0]*_m[0][0] + q[1][0]*_m[1][0] + q[2][0]*_m[2][0];
1725 mout[1] = q[0][1]*_m[0][1] + q[1][1]*_m[1][1] + q[2][1]*_m[2][1];
1726 mout[2] = q[0][2]*_m[0][2] + q[1][2]*_m[1][2] + q[2][2]*_m[2][2];
1727
1728 mout[3] = q[0][0]*_m[0][1] + q[1][0]*_m[1][1] + q[2][0]*_m[2][1];
1729 mout[4] = q[0][1]*_m[0][2] + q[1][1]*_m[1][2] + q[2][1]*_m[2][2];
1730 mout[5] = q[0][0]*_m[0][2] + q[1][0]*_m[1][2] + q[2][0]*_m[2][2];
1731}
1732
1733/*----------------------------------------------------------------------------*/
1742/*----------------------------------------------------------------------------*/
1743
1744CS_F_HOST_DEVICE static inline void
1746 const cs_real_t q[3][3],
1747 cs_real_t mout[3][3])
1748{
1749 /* _m = M.Q^t */
1750 cs_real_33_t _m;
1751 _m[0][0] = m[0][0]*q[0][0] + m[0][1]*q[0][1] + m[0][2]*q[0][2];
1752 _m[0][1] = m[0][0]*q[1][0] + m[0][1]*q[1][1] + m[0][2]*q[1][2];
1753 _m[0][2] = m[0][0]*q[2][0] + m[0][1]*q[2][1] + m[0][2]*q[2][2];
1754
1755 _m[1][0] = m[1][0]*q[0][0] + m[1][1]*q[0][1] + m[1][2]*q[0][2];
1756 _m[1][1] = m[1][0]*q[1][0] + m[1][1]*q[1][1] + m[1][2]*q[1][2];
1757 _m[1][2] = m[1][0]*q[2][0] + m[1][1]*q[2][1] + m[1][2]*q[2][2];
1758
1759 _m[2][0] = m[2][0]*q[0][0] + m[2][1]*q[0][1] + m[2][2]*q[0][2];
1760 _m[2][1] = m[2][0]*q[1][0] + m[2][1]*q[1][1] + m[2][2]*q[1][2];
1761 _m[2][2] = m[2][0]*q[2][0] + m[2][1]*q[2][1] + m[2][2]*q[2][2];
1762
1763 /* mout = Q _m */
1764 mout[0][0] = q[0][0]*_m[0][0] + q[0][1]*_m[1][0] + q[0][2]*_m[2][0];
1765 mout[0][1] = q[0][0]*_m[0][1] + q[0][1]*_m[1][1] + q[0][2]*_m[2][1];
1766 mout[0][2] = q[0][0]*_m[0][2] + q[0][1]*_m[1][2] + q[0][2]*_m[2][2];
1767
1768 mout[1][0] = q[1][0]*_m[0][0] + q[1][1]*_m[1][0] + q[1][2]*_m[2][0];
1769 mout[1][1] = q[1][0]*_m[0][1] + q[1][1]*_m[1][1] + q[1][2]*_m[2][1];
1770 mout[1][2] = q[1][0]*_m[0][2] + q[1][1]*_m[1][2] + q[1][2]*_m[2][2];
1771
1772 mout[2][0] = q[2][0]*_m[0][0] + q[2][1]*_m[1][0] + q[2][2]*_m[2][0];
1773 mout[2][1] = q[2][0]*_m[0][1] + q[2][1]*_m[1][1] + q[2][2]*_m[2][1];
1774 mout[2][2] = q[2][0]*_m[0][2] + q[2][1]*_m[1][2] + q[2][2]*_m[2][2];
1775}
1776
1777/*----------------------------------------------------------------------------*/
1786/*----------------------------------------------------------------------------*/
1787
1788CS_F_HOST_DEVICE static inline void
1790 const cs_real_t q[3][3],
1791 cs_real_t mout[6])
1792{
1793 /* _m = M.Q^t */
1794 cs_real_33_t _m;
1795 _m[0][0] = m[0]*q[0][0] + m[3]*q[0][1] + m[5]*q[0][2];
1796 _m[0][1] = m[0]*q[1][0] + m[3]*q[1][1] + m[5]*q[1][2];
1797 _m[0][2] = m[0]*q[2][0] + m[3]*q[2][1] + m[5]*q[2][2];
1798
1799 _m[1][0] = m[3]*q[0][0] + m[1]*q[0][1] + m[4]*q[0][2];
1800 _m[1][1] = m[3]*q[1][0] + m[1]*q[1][1] + m[4]*q[1][2];
1801 _m[1][2] = m[3]*q[2][0] + m[1]*q[2][1] + m[4]*q[2][2];
1802
1803 _m[2][0] = m[5]*q[0][0] + m[4]*q[0][1] + m[2]*q[0][2];
1804 _m[2][1] = m[5]*q[1][0] + m[4]*q[1][1] + m[2]*q[1][2];
1805 _m[2][2] = m[5]*q[2][0] + m[4]*q[2][1] + m[2]*q[2][2];
1806
1807 /* mout = Q _m */
1808 mout[0] = q[0][0]*_m[0][0] + q[0][1]*_m[1][0] + q[0][2]*_m[2][0];
1809 mout[1] = q[1][0]*_m[0][1] + q[1][1]*_m[1][1] + q[1][2]*_m[2][1];
1810 mout[2] = q[2][0]*_m[0][2] + q[2][1]*_m[1][2] + q[2][2]*_m[2][2];
1811
1812
1813 mout[3] = q[0][0]*_m[0][1] + q[0][1]*_m[1][1] + q[0][2]*_m[2][1];
1814 mout[4] = q[1][0]*_m[0][2] + q[1][1]*_m[1][2] + q[1][2]*_m[2][2];
1815 mout[5] = q[0][0]*_m[0][2] + q[0][1]*_m[1][2] + q[0][2]*_m[2][2];
1816}
1817
1818/*----------------------------------------------------------------------------*/
1827/*----------------------------------------------------------------------------*/
1828
1829CS_F_HOST_DEVICE static inline void
1831 cs_real_t m_sym[3][3],
1832 cs_real_t m_ant[3][3])
1833{
1834 /* sym = 0.5 (m + m_transpose) */
1835 m_sym[0][0] = 0.5 * (m[0][0] + m[0][0]);
1836 m_sym[0][1] = 0.5 * (m[0][1] + m[1][0]);
1837 m_sym[0][2] = 0.5 * (m[0][2] + m[2][0]);
1838 m_sym[1][0] = 0.5 * (m[1][0] + m[0][1]);
1839 m_sym[1][1] = 0.5 * (m[1][1] + m[1][1]);
1840 m_sym[1][2] = 0.5 * (m[1][2] + m[2][1]);
1841 m_sym[2][0] = 0.5 * (m[2][0] + m[0][2]);
1842 m_sym[2][1] = 0.5 * (m[2][1] + m[1][2]);
1843 m_sym[2][2] = 0.5 * (m[2][2] + m[2][2]);
1844
1845 /* ant = 0.5 (m - m_transpose) */
1846 m_ant[0][0] = 0.5 * (m[0][0] - m[0][0]);
1847 m_ant[0][1] = 0.5 * (m[0][1] - m[1][0]);
1848 m_ant[0][2] = 0.5 * (m[0][2] - m[2][0]);
1849 m_ant[1][0] = 0.5 * (m[1][0] - m[0][1]);
1850 m_ant[1][1] = 0.5 * (m[1][1] - m[1][1]);
1851 m_ant[1][2] = 0.5 * (m[1][2] - m[2][1]);
1852 m_ant[2][0] = 0.5 * (m[2][0] - m[0][2]);
1853 m_ant[2][1] = 0.5 * (m[2][1] - m[1][2]);
1854 m_ant[2][2] = 0.5 * (m[2][2] - m[2][2]);
1855}
1856
1857/*----------------------------------------------------------------------------*/
1866/*----------------------------------------------------------------------------*/
1867
1868CS_F_HOST_DEVICE static inline cs_real_t
1870{
1871 /* sym = 0.5 (m + m_transpose) */
1872 return cs_math_pow2(m[0][0])
1873 + cs_math_pow2(m[1][1])
1874 + cs_math_pow2(m[2][2])
1875 + 0.5 * ( cs_math_pow2(m[0][1] + m[1][0])
1876 + cs_math_pow2(m[0][2] + m[2][0])
1877 + cs_math_pow2(m[1][2] + m[2][1]));
1878}
1879
1880/*----------------------------------------------------------------------------*/
1888/*----------------------------------------------------------------------------*/
1889
1890CS_F_HOST_DEVICE static inline void
1892 const cs_real_t m2[3][3],
1893 cs_real_t (*restrict mout)[3])
1894{
1895 mout[0][0] += m1[0][0]*m2[0][0] + m1[0][1]*m2[1][0] + m1[0][2]*m2[2][0];
1896 mout[0][1] += m1[0][0]*m2[0][1] + m1[0][1]*m2[1][1] + m1[0][2]*m2[2][1];
1897 mout[0][2] += m1[0][0]*m2[0][2] + m1[0][1]*m2[1][2] + m1[0][2]*m2[2][2];
1898
1899 mout[1][0] += m1[1][0]*m2[0][0] + m1[1][1]*m2[1][0] + m1[1][2]*m2[2][0];
1900 mout[1][1] += m1[1][0]*m2[0][1] + m1[1][1]*m2[1][1] + m1[1][2]*m2[2][1];
1901 mout[1][2] += m1[1][0]*m2[0][2] + m1[1][1]*m2[1][2] + m1[1][2]*m2[2][2];
1902
1903 mout[2][0] += m1[2][0]*m2[0][0] + m1[2][1]*m2[1][0] + m1[2][2]*m2[2][0];
1904 mout[2][1] += m1[2][0]*m2[0][1] + m1[2][1]*m2[1][1] + m1[2][2]*m2[2][1];
1905 mout[2][2] += m1[2][0]*m2[0][2] + m1[2][1]*m2[1][2] + m1[2][2]*m2[2][2];
1906}
1907
1908/*----------------------------------------------------------------------------*/
1922/*----------------------------------------------------------------------------*/
1923
1924CS_F_HOST_DEVICE static inline void
1926 const cs_real_t s2[6],
1927 cs_real_t *restrict sout)
1928{
1929 /* S11 */
1930 sout[0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
1931 /* S22 */
1932 sout[1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
1933 /* S33 */
1934 sout[2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
1935 /* S12 = S21 */
1936 sout[3] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
1937 /* S23 = S32 */
1938 sout[4] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
1939 /* S13 = S31 */
1940 sout[5] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
1941}
1942
1943/*----------------------------------------------------------------------------*/
1951/*----------------------------------------------------------------------------*/
1952
1953CS_F_HOST_DEVICE static inline void
1955 cs_real_t (*restrict sout)[6])
1956{
1957 const int t2v[3][3] = {{0, 3, 5},
1958 {3, 1, 4},
1959 {5, 4, 2}};
1960
1961 const int iv2t[6] = {0, 1, 2, 0, 1, 0};
1962 const int jv2t[6] = {0, 1, 2, 1, 2, 2};
1963
1964 for (int i = 0; i < 6; i++) {
1965 for (int j = 0; j < 6; j++)
1966 sout[i][j] = 0;
1967 }
1968
1969 /* Consider : W = s*R + R*s^t .
1970 * W_ij = Sum_{k<3} [s_ik*r_jk + s_jk*r_ik]
1971 * We look for A_(ij,pq) such as A*R = W
1972 *
1973 * so
1974 * A_(ij,jk) takes s_ik
1975 * and
1976 * A_(ij,ik) takes s_jk
1977 */
1978 for (int ij = 0; ij < 6; ij++) {
1979 int i = iv2t[ij];
1980 int j = jv2t[ij];
1981 for (int k = 0; k < 3; k++) {
1982 int ik = t2v[i][k];
1983 int jk = t2v[j][k];
1984
1985 sout[ij][ik] += s[j][k];
1986 sout[ij][jk] += s[i][k];
1987 }
1988 }
1989}
1990
1991/*----------------------------------------------------------------------------*/
2003/*----------------------------------------------------------------------------*/
2004
2005CS_F_HOST_DEVICE static inline void
2007 const cs_real_t s2[6],
2008 const cs_real_t s3[6],
2009 cs_real_t (*restrict sout)[3])
2010{
2011 cs_real_t _sout[3][3];
2012
2013 /* S11 */
2014 _sout[0][0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
2015 /* S22 */
2016 _sout[1][1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
2017 /* S33 */
2018 _sout[2][2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
2019 /* S12 */
2020 _sout[0][1] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
2021 /* S21 */
2022 _sout[1][0] = s2[0]*s1[3] + s2[3]*s1[1] + s2[5]*s1[4];
2023 /* S23 */
2024 _sout[1][2] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
2025 /* S32 */
2026 _sout[2][1] = s2[3]*s1[5] + s2[1]*s1[4] + s2[4]*s1[2];
2027 /* S13 */
2028 _sout[0][2] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
2029 /* S31 */
2030 _sout[2][0] = s2[0]*s1[5] + s2[3]*s1[4] + s2[5]*s1[2];
2031
2032 sout[0][0] = _sout[0][0]*s3[0] + _sout[0][1]*s3[3] + _sout[0][2]*s3[5];
2033 /* S22 */
2034 sout[1][1] = _sout[1][0]*s3[3] + _sout[1][1]*s3[1] + _sout[1][2]*s3[4];
2035 /* S33 */
2036 sout[2][2] = _sout[2][0]*s3[5] + _sout[2][1]*s3[4] + _sout[2][2]*s3[2];
2037 /* S12 */
2038 sout[0][1] = _sout[0][0]*s3[3] + _sout[0][1]*s3[1] + _sout[0][2]*s3[4];
2039 /* S21 */
2040 sout[1][0] = s3[0]*_sout[1][0] + s3[3]*_sout[1][1] + s3[5]*_sout[1][2];
2041 /* S23 */
2042 sout[1][2] = _sout[1][0]*s3[5] + _sout[1][1]*s3[4] + _sout[1][2]*s3[2];
2043 /* S32 */
2044 sout[2][1] = s3[3]*_sout[2][0] + s3[1]*_sout[2][1] + s3[4]*_sout[2][2];
2045 /* S13 */
2046 sout[0][2] = _sout[0][0]*s3[5] + _sout[0][1]*s3[4] + _sout[0][2]*s3[2];
2047 /* S31 */
2048 sout[2][0] = s3[0]*_sout[2][0] + s3[3]*_sout[2][1] + s3[5]*_sout[2][2];
2049}
2050
2051/*----------------------------------------------------------------------------*/
2058/*----------------------------------------------------------------------------*/
2059
2060CS_F_HOST_DEVICE static inline void
2062 cs_nvec3_t *qv)
2063{
2064 cs_real_t magnitude = sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
2065
2066 qv->meas = magnitude;
2067 if (fabs(magnitude) > cs_math_zero_threshold) {
2068
2069 const cs_real_t inv = 1/magnitude;
2070 qv->unitv[0] = inv * v[0];
2071 qv->unitv[1] = inv * v[1];
2072 qv->unitv[2] = inv * v[2];
2073
2074 }
2075 else
2076 qv->unitv[0] = qv->unitv[1] = qv->unitv[2] = 0;
2077}
2078
2079/*----------------------------------------------------------------------------*/
2089/*----------------------------------------------------------------------------*/
2090
2091CS_F_HOST_DEVICE static inline void
2093{
2094 /* Factorization */
2095
2096 // j=0
2097 const cs_real_t d00 = ldlt[0]; // m00
2098 assert(fabs(d00) > cs_math_zero_threshold);
2099
2100 const cs_real_t f00 = 1. / d00;
2101 const cs_real_t l10 = ldlt[1] * f00; // m01
2102 const cs_real_t l20 = ldlt[3] * f00; // m02
2103 const cs_real_t l30 = ldlt[6] * f00; // m03
2104
2105 // j=1
2106 const cs_real_t d11 = ldlt[2] - l10*l10*d00; // m11
2107 assert(fabs(d11) > cs_math_zero_threshold);
2108 const cs_real_t f11 = 1. / d11;
2109 const cs_real_t l21 = (ldlt[4] - l20*d00*l10) * f11; // m12
2110 const cs_real_t l31 = (ldlt[7] - l30*d00*l10) * f11; // m13
2111
2112 // j=2
2113 const cs_real_t d22 = ldlt[5] - l20*d00*l20 - l21*d11*l21; // m22
2114 assert(fabs(d22) > cs_math_zero_threshold);
2115 const cs_real_t f22 = 1. / d22;
2116 const cs_real_t l32 = (ldlt[8] - l30*d00*l20 - l31*d11*l21) * f22; // m23
2117
2118 // j=3
2119 const cs_real_t d33 = ldlt[9] - l30*d00*l30 - l31*d11*l31 - l32*d22*l32; // m33
2120 assert(fabs(d33) > cs_math_zero_threshold);
2121 const cs_real_t f33 = 1. / d33;
2122
2123 ldlt[0] = f00;
2124 ldlt[1] = l10;
2125 ldlt[2] = f11;
2126 ldlt[3] = l20;
2127 ldlt[4] = l21;
2128 ldlt[5] = f22;
2129 ldlt[6] = l30;
2130 ldlt[7] = l31;
2131 ldlt[8] = l32;
2132 ldlt[9] = f33;
2133}
2134
2135/*----------------------------------------------------------------------------*/
2148/*----------------------------------------------------------------------------*/
2149
2150CS_F_HOST_DEVICE static inline cs_real_t
2152 const cs_real_t rhs[4])
2153{
2154 /* f00, f11, f22, f33, l32, l31, l30, l21, l20, l10
2155 0 1 2 3 4 5 6 7 8 9 */
2156
2157 cs_real_t x[4]; /* solution */
2158
2159 x[0] = rhs[0];
2160 x[1] = rhs[1] - x[0]*ldlt[1];
2161 x[2] = rhs[2] - x[0]*ldlt[3] - x[1]*ldlt[4];
2162 x[3] = rhs[3] - x[0]*ldlt[6] - x[1]*ldlt[7] - x[2]*ldlt[8];
2163
2164 x[3] = x[3]*ldlt[9];
2165
2166 return x[3];
2167
2168 /*
2169 x[2] = x[2]*ldlt[5] - ldlt[8]*x[3];
2170 x[1] = x[1]*ldlt[2] - ldlt[7]*x[3] - ldlt[4]*x[2];
2171 x[0] = x[0]*ldlt[0] - ldlt[6]*x[3] - ldlt[3]*x[2] - ldlt[1]*x[1];
2172 */
2173}
2174
2175/*=============================================================================
2176 * Public function prototypes
2177 *============================================================================*/
2178
2179/*----------------------------------------------------------------------------*/
2180/*
2181 * \brief Compute the length (Euclidean norm) between two points xa and xb in
2182 * a Cartesian coordinate system of dimension 3
2183 *
2184 * \param[in] xa coordinate of the first extremity
2185 * \param[in] xb coordinate of the second extremity
2186 * \param[out] len pointer to the length of the vector va -> vb
2187 * \param[out] unitv unitary vector along xa -> xb
2188 */
2189/*----------------------------------------------------------------------------*/
2190
2193 const cs_real_t xb[3],
2194 cs_real_t *len,
2195 cs_real_3_t unitv);
2196
2197/*----------------------------------------------------------------------------*/
2209/*----------------------------------------------------------------------------*/
2210
2211void
2213 cs_real_t eig_vals[3]);
2214
2215/*----------------------------------------------------------------------------*/
2228/*----------------------------------------------------------------------------*/
2229
2230void
2231cs_math_33_eigen(const cs_real_t m[3][3],
2232 cs_real_t *eig_ratio,
2233 cs_real_t *eig_max);
2234
2235/*----------------------------------------------------------------------------*/
2246/*----------------------------------------------------------------------------*/
2247
2248double
2249cs_math_surftri(const cs_real_t xv[3],
2250 const cs_real_t xe[3],
2251 const cs_real_t xf[3]);
2252
2253/*----------------------------------------------------------------------------*/
2265/*----------------------------------------------------------------------------*/
2266
2267double
2268cs_math_voltet(const cs_real_t xv[3],
2269 const cs_real_t xe[3],
2270 const cs_real_t xf[3],
2271 const cs_real_t xc[3]);
2272
2273/*----------------------------------------------------------------------------*/
2286/*----------------------------------------------------------------------------*/
2287
2288void
2290 const cs_real_t tol_err,
2291 cs_real_t eig_val[3],
2292 cs_real_t eig_vec[3][3]);
2293
2294/*----------------------------------------------------------------------------*/
2303/*----------------------------------------------------------------------------*/
2304
2305void
2306cs_math_fact_lu(const int n,
2307 const cs_real_t *a,
2308 cs_real_t *a_lu);
2309
2310/*----------------------------------------------------------------------------*/
2319/*----------------------------------------------------------------------------*/
2320
2321void
2322cs_math_fw_and_bw_lu(const cs_real_t a_lu[],
2323 const int n,
2324 cs_real_t x[],
2325 const cs_real_t b[]);
2326
2327/*----------------------------------------------------------------------------*/
2328
2330
2331#endif /* __CS_MATH_H__ */
#define restrict
Definition: cs_defs.h:158
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:585
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:374
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:376
#define END_C_DECLS
Definition: cs_defs.h:555
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:383
@ t
Definition: cs_field_pointer.h:95
@ k
Definition: cs_field_pointer.h:72
@ x2
Definition: cs_field_pointer.h:203
CS_F_HOST_DEVICE cs_real_t cs_math_3_dot_product(const T u[3], const U v[3])
Compute the dot product of two vectors of 3 real values.
Definition: cs_math.h:176
const cs_real_t cs_math_1ov6
static CS_F_HOST_DEVICE cs_real_t cs_math_pow3(cs_real_t x)
Compute the cube of a real value.
Definition: cs_math.h:803
static CS_F_HOST_DEVICE void cs_math_sym_33_inv_cramer(const cs_real_t s[6], cs_real_t *restrict sout)
Compute the inverse of a symmetric matrix using Cramer's rule.
Definition: cs_math.h:1599
CS_F_HOST_DEVICE cs_real_t cs_math_3_distance_dot_product(const T xa[3], const T xb[3], const U xc[3])
Compute .
Definition: cs_math.h:153
void cs_math_33_eig_val_vec(const cs_real_t m_in[3][3], const cs_real_t tol_err, cs_real_t eig_val[3], cs_real_t eig_vec[3][3])
Evaluate eigenvalues and eigenvectors of a real symmetric matrix m1[3,3]: m1*m2 = lambda*m2.
static CS_F_HOST_DEVICE void cs_math_33_extract_sym_ant(const cs_real_t m[3][3], cs_real_t m_sym[3][3], cs_real_t m_ant[3][3])
Extract from the given matrix its symmetric and anti-symmetric part.
Definition: cs_math.h:1830
double cs_math_surftri(const cs_real_t xv[3], const cs_real_t xe[3], const cs_real_t xf[3])
Compute the area of the convex_hull generated by 3 points. This corresponds to the computation of the...
Definition: cs_math.cpp:403
static CS_F_HOST_DEVICE void cs_math_sym_33_3_product_add(const cs_real_t m[6], const cs_real_t v[3], cs_real_t *restrict mv)
Compute the product of a symmetric matrix of 3x3 real values by a vector of 3 real values and add it ...
Definition: cs_math.h:1231
static CS_F_HOST_DEVICE void cs_nvec3(const cs_real_t v[3], cs_nvec3_t *qv)
Define a cs_nvec3_t structure from a cs_real_3_t.
Definition: cs_math.h:2061
static CS_F_HOST_DEVICE void cs_math_33_inv_cramer_sym_in_place(cs_real_t a[3][3])
Inverse a 3x3 symmetric matrix (with non-symmetric storage) in place, using Cramer's rule.
Definition: cs_math.h:1564
const cs_real_t cs_math_infinite_r
static CS_F_HOST_DEVICE cs_real_t cs_math_pow2(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:787
const cs_real_t cs_math_4ov3
static CS_F_HOST_DEVICE void cs_math_33t_3_product(const cs_real_t m[3][3], const cs_real_t v[3], cs_real_t *restrict mv)
Compute the product of the transpose of a matrix of 3x3 real values by a vector of 3 real values.
Definition: cs_math.h:1187
static CS_F_HOST_DEVICE cs_real_t cs_math_3_square_distance(const cs_real_t xa[3], const cs_real_t xb[3])
Compute the squared distance between two points xa and xb in a Cartesian coordinate system of dimensi...
Definition: cs_math.h:900
static CS_F_HOST_DEVICE cs_real_t cs_math_sym_33_determinant(const cs_real_t m[6])
Compute the determinant of a 3x3 symmetric matrix.
Definition: cs_math.h:1368
static CS_F_HOST_DEVICE void cs_math_sym_33_transform_r_to_a(const cs_real_t m[6], const cs_real_t q[3][3], cs_real_t mout[6])
Compute transformation from relative to absolute reference frame Q^t M Q.
Definition: cs_math.h:1705
static CS_F_HOST_DEVICE void cs_math_sym_33_product(const cs_real_t s1[6], const cs_real_t s2[6], cs_real_t *restrict sout)
Compute the product of two symmetric matrices.
Definition: cs_math.h:1925
static CS_F_HOST_DEVICE void cs_math_33_transform_r_to_a(const cs_real_t m[3][3], const cs_real_t q[3][3], cs_real_t mout[3][3])
Compute transformation from relative to absolute reference frame Q^t M Q.
Definition: cs_math.h:1661
static CS_F_HOST_DEVICE void cs_math_66_6_product(const cs_real_t m[6][6], const cs_real_t v[6], cs_real_t *restrict mv)
Compute the product of a matrix of 6x6 real values by a vector of 6 real values.
Definition: cs_math.h:1305
void cs_math_sym_33_eigen(const cs_real_t m[6], cs_real_t eig_vals[3])
Compute all eigenvalues of a 3x3 symmetric matrix with symmetric storage.
Definition: cs_math.cpp:191
CS_F_HOST_DEVICE void cs_math_sym_33_3_product(const T m[6], const U v[3], V *restrict mv)
Compute the product of a symmetric matrix of 3x3 real values by a vector of 3 real values....
Definition: cs_math.h:301
static CS_F_HOST_DEVICE cs_real_t cs_math_33_main_invariant_2(const cs_real_t m[3][3])
Compute the second main invariant of the symmetric part of a 3x3 tensor.
Definition: cs_math.h:1869
const cs_real_t cs_math_2ov3
CS_F_HOST_DEVICE void cs_math_matrix_gauss_inverse(const T a[n][n], T b[n][n])
Inverse square, dense matrix using Gauss-Jordan elimination.
Definition: cs_math.h:427
static CS_F_HOST_DEVICE cs_real_t cs_math_pow4(cs_real_t x)
Compute the 4-th power of a real value.
Definition: cs_math.h:819
void cs_math_fw_and_bw_lu(const cs_real_t a_lu[], const int n, cs_real_t x[], const cs_real_t b[])
Compute forward and backward to solve an LU P*P system.
Definition: cs_math.cpp:651
const cs_real_t cs_math_1ov12
static CS_F_HOST_DEVICE void cs_math_sym_33_double_product(const cs_real_t s1[6], const cs_real_t s2[6], const cs_real_t s3[6], cs_real_t(*restrict sout)[3])
Compute the product of three symmetric matrices.
Definition: cs_math.h:2006
static CS_F_HOST_DEVICE void cs_math_66_6_product_add(const cs_real_t m[6][6], const cs_real_t v[6], cs_real_t *restrict mv)
Compute the product of a matrix of 6x6 real values by a vector of 6 real values and add it to the vec...
Definition: cs_math.h:1327
static CS_F_HOST_DEVICE void cs_math_reduce_sym_prod_33_to_66(const cs_real_t s[3][3], cs_real_t(*restrict sout)[6])
Compute a 6x6 matrix A, equivalent to a 3x3 matrix s, such as: A*R_6 = R*s^t + s*R.
Definition: cs_math.h:1954
static CS_F_HOST_DEVICE void cs_math_3_cross_product(const T u[3], const U v[3], V *restrict uv)
Compute the cross product of two vectors of 3 real values.
Definition: cs_math.h:407
static CS_F_HOST_DEVICE void cs_math_33_normal_scaling_add(const cs_real_t n[3], cs_real_t factor, cs_real_t t[3][3])
Add the dot product with a normal vector to the normal,normal component of a tensor: t += factor * n....
Definition: cs_math.h:1120
static CS_F_HOST_DEVICE void cs_math_3_normalize_threshold(const cs_real_t vin[3], const cs_real_t thres, cs_real_t vout[3])
Normalise a vector of 3 real values and clip the norm using a threshold value.
Definition: cs_math.h:1052
void cs_math_33_eigen(const cs_real_t m[3][3], cs_real_t *eig_ratio, cs_real_t *eig_max)
Compute max/min eigenvalues ratio and max. eigenvalue of a 3x3 symmetric matrix with non-symmetric st...
Definition: cs_math.cpp:280
CS_F_HOST_DEVICE cs_real_t cs_math_3_33_3_dot_product(const T n1[3], const U t[3][3], const V n2[3])
Compute the dot product of a tensor t with two vectors, n1 and n2.
Definition: cs_math.h:354
CS_F_HOST_DEVICE void cs_math_3_normal_scaling(const T n[3], U factor, V v[3])
Add the dot product with a normal vector to the normal direction to a vector.
Definition: cs_math.h:327
CS_F_HOST_DEVICE cs_real_t cs_math_3_square_norm(const T v[3])
Compute the square norm of a vector of 3 real values.
Definition: cs_math.h:248
const cs_real_t cs_math_1ov24
CS_F_HOST_DEVICE void cs_math_6_gauss_inverse_in_place(T a[6])
Inverse 3x3 symmetric matrix in place, using Gauss-Jordan elimination.
Definition: cs_math.h:485
static CS_F_HOST_DEVICE void cs_math_33_inv_cramer_in_place(cs_real_t a[3][3])
Inverse a 3x3 matrix in place, using Cramer's rule.
Definition: cs_math.h:1529
static CS_F_HOST_DEVICE void cs_math_33_inv_cramer(const cs_real_t in[3][3], cs_real_t out[3][3])
Inverse a 3x3 matrix.
Definition: cs_math.h:1497
void cs_math_fact_lu(const int n, const cs_real_t *a, cs_real_t *a_lu)
Compute LU factorization of an array of dense matrices of identical size.
Definition: cs_math.cpp:599
cs_math_sym_tensor_component_t
Definition: cs_math.h:67
@ ZZ
Definition: cs_math.h:71
@ XY
Definition: cs_math.h:72
@ XZ
Definition: cs_math.h:74
@ YZ
Definition: cs_math.h:73
@ YY
Definition: cs_math.h:70
@ XX
Definition: cs_math.h:69
CS_F_HOST_DEVICE void cs_math_3_length_unitv(const cs_real_t xa[3], const cs_real_t xb[3], cs_real_t *len, cs_real_3_t unitv)
Compute the length (Euclidean norm) between two points xa and xb in a Cartesian coordinate system of ...
Definition: cs_math.cpp:370
static CS_F_HOST_DEVICE cs_real_t cs_math_3_triple_product(const cs_real_t u[3], const cs_real_t v[3], const cs_real_t w[3])
Compute the triple product.
Definition: cs_math.h:1438
static CS_F_HOST_DEVICE void cs_math_33_3_product_add(const cs_real_t m[3][3], const cs_real_t v[3], cs_real_t *restrict mv)
Compute the product of a matrix of 3x3 real values by a vector of 3 real values add.
Definition: cs_math.h:1166
static CS_F_HOST_DEVICE cs_real_t cs_math_3_distance(const cs_real_t xa[3], const cs_real_t xb[3])
Compute the (euclidean) distance between two points xa and xb in a Cartesian coordinate system of dim...
Definition: cs_math.h:855
CS_F_HOST_DEVICE cs_real_t cs_math_3_norm(const T v[3])
Compute the euclidean norm of a vector of dimension 3.
Definition: cs_math.h:198
static CS_F_HOST_DEVICE cs_real_t cs_math_pow5(cs_real_t x)
Compute the 5-th power of a real value.
Definition: cs_math.h:836
const cs_real_t cs_math_1ov3
static CS_F_HOST_DEVICE void cs_math_sym_33_transform_a_to_r(const cs_real_t m[6], const cs_real_t q[3][3], cs_real_t mout[6])
Compute transformation from absolute to relative reference frame Q M Q^t.
Definition: cs_math.h:1789
const cs_real_t cs_math_5ov3
static CS_F_HOST_DEVICE cs_real_t cs_math_33_determinant(const cs_real_t m[3][3])
Compute the determinant of a 3x3 matrix.
Definition: cs_math.h:1348
const cs_real_t cs_math_epzero
static CS_F_HOST_DEVICE void cs_math_33_product(const cs_real_t m1[3][3], const cs_real_t m2[3][3], cs_real_t mout[3][3])
Compute the product of two 3x3 real valued matrices.
Definition: cs_math.h:1632
const cs_real_t cs_math_big_r
CS_F_HOST_DEVICE void cs_math_3_orthogonal_projection(const T n[3], const U v[3], V *restrict vout)
Orthogonal projection of a vector with respect to a normalised vector.
Definition: cs_math.h:382
static CS_F_HOST_DEVICE void cs_math_33_transform_a_to_r(const cs_real_t m[3][3], const cs_real_t q[3][3], cs_real_t mout[3][3])
Compute transformation from absolute to relative reference frame Q M Q^t.
Definition: cs_math.h:1745
double cs_math_voltet(const cs_real_t xv[3], const cs_real_t xe[3], const cs_real_t xf[3], const cs_real_t xc[3])
Compute the volume of the convex_hull generated by 4 points. This is equivalent to the computation of...
Definition: cs_math.cpp:433
static CS_F_HOST_DEVICE cs_real_t cs_math_sym_44_partial_solve_ldlt(const cs_real_t ldlt[10], const cs_real_t rhs[4])
LDL^T: Modified Cholesky decomposition of a 4x4 SPD matrix. For more reference, see for instance http...
Definition: cs_math.h:2151
static CS_F_HOST_DEVICE void cs_math_3_normalize(const T vin[3], U vout[3])
Normalise a vector of 3 real values.
Definition: cs_math.h:271
static int cs_math_binom(int n, int k)
Computes the binomial coefficient of n and k.
Definition: cs_math.h:662
static CS_F_HOST_DEVICE void cs_math_3_average(const cs_real_t u[3], const cs_real_t v[3], cs_real_t *restrict uv)
Compute the average of two vector of dimension 3.
Definition: cs_math.h:1388
static CS_F_HOST_DEVICE void cs_math_33_product_add(const cs_real_t m1[3][3], const cs_real_t m2[3][3], cs_real_t(*restrict mout)[3])
Add the product of two 3x3 real matrices to a matrix.
Definition: cs_math.h:1891
static CS_F_HOST_DEVICE cs_real_t cs_math_6_trace(const cs_real_t t[6])
Compute the trace of a symmetric tensor.
Definition: cs_math.h:1288
static CS_F_HOST_DEVICE cs_real_t cs_math_sym_33_sym_33_product_trace(const cs_real_t m1[6], const cs_real_t m2[6])
Compute the product of two symmetric matrices of 3x3 real values and take the trace....
Definition: cs_math.h:1253
static CS_F_HOST_DEVICE void cs_math_sym_44_factor_ldlt(cs_real_t ldlt[10])
LDL^T: Modified Cholesky decomposition of a 4x4 SPD matrix. For more reference, see for instance http...
Definition: cs_math.h:2092
const cs_real_t cs_math_pi
static CS_F_HOST_DEVICE cs_real_t cs_math_clamp(cs_real_t x, cs_real_t xmin, cs_real_t xmax)
Clamp function for a given scalar value.
Definition: cs_math.h:751
static const cs_real_33_t cs_math_33_identity
Definition: cs_math.h:119
CS_F_HOST_DEVICE cs_real_t cs_math_3_sym_33_3_dot_product(const T n1[3], const U t[6], const V n2[3])
Compute the dot product of a symmetric tensor t with two vectors, n1 and n2.
Definition: cs_math.h:225
static const cs_real_6_t cs_math_sym_33_identity
Definition: cs_math.h:122
static CS_F_HOST_DEVICE cs_real_t cs_math_fabs(cs_real_t x)
Compute the absolute value of a real value.
Definition: cs_math.h:692
static CS_F_HOST_DEVICE cs_real_t cs_math_33_trace(const cs_real_t t[3][3])
Compute the trace of a 3x3 tensor.
Definition: cs_math.h:1272
static CS_F_HOST_DEVICE cs_real_t cs_math_fmin(cs_real_t x, cs_real_t y)
Compute the min value of two real values.
Definition: cs_math.h:710
const cs_real_t cs_math_zero_threshold
static CS_F_HOST_DEVICE void cs_math_33_3_product(const cs_real_t m[3][3], const cs_real_t v[3], cs_real_t *restrict mv)
Compute the product of a matrix of 3x3 real values by a vector of 3 real values.
Definition: cs_math.h:1145
static CS_F_HOST_DEVICE cs_real_t cs_math_sq(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:771
static CS_F_HOST_DEVICE void cs_math_3_orthonormal_basis(const cs_real_t vect[3], cs_real_t axes[3][3])
Build an orthonormal basis based on a first vector "vect". axes[0] is vect normalized,...
Definition: cs_math.h:1460
static CS_F_HOST_DEVICE cs_real_t cs_math_fmax(cs_real_t x, cs_real_t y)
Compute the max value of two real values.
Definition: cs_math.h:729
Definition: cs_array.h:1098
CS_F_HOST_DEVICE T max(const T a, const T b)
Definition: cs_defs.h:769
CS_F_HOST_DEVICE float pow2(float x)
Compute the square of a real value.
Definition: cs_math.h:629
CS_F_HOST_DEVICE T clamp(const T x, const T xmin, const T xmax)
Definition: cs_defs.h:794
CS_F_HOST_DEVICE T min(const T a, const T b)
Definition: cs_defs.h:746
CS_F_HOST_DEVICE T abs(const T a)
Definition: cs_defs.h:724
Definition: cs_defs.h:415
double meas
Definition: cs_defs.h:417
double unitv[3]
Definition: cs_defs.h:418