8.0
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-2023 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 "cs_defs.h"
31 
32 /*----------------------------------------------------------------------------
33  * Standard C library headers
34  *----------------------------------------------------------------------------*/
35 
36 #include <assert.h>
37 #include <math.h>
38 
39 /*----------------------------------------------------------------------------
40  * Local headers
41  *----------------------------------------------------------------------------*/
42 
43 #if defined(DEBUG) && !defined(NDEBUG) /* Sanity check */
44 #include "bft_error.h"
45 #endif
46 
47 /*----------------------------------------------------------------------------*/
48 
50 
51 /*=============================================================================
52  * Local Macro definitions
53  *============================================================================*/
54 
55 /*============================================================================
56  * Type definition
57  *============================================================================*/
58 
59 /* Symmetric tensor component name */
60 
61 typedef enum {
62 
63  XX,
64  YY,
65  ZZ,
66  XY,
67  YZ,
68  XZ
69 
71 
72 /*============================================================================
73  * Global variables
74  *============================================================================*/
75 
76 /* Numerical constants */
77 
79 extern const cs_real_t cs_math_1ov3;
80 extern const cs_real_t cs_math_2ov3;
81 extern const cs_real_t cs_math_4ov3;
82 extern const cs_real_t cs_math_5ov3;
83 extern const cs_real_t cs_math_1ov6;
84 extern const cs_real_t cs_math_1ov12;
85 extern const cs_real_t cs_math_1ov24;
86 extern const cs_real_t cs_math_epzero;
87 extern const cs_real_t cs_math_infinite_r;
88 extern const cs_real_t cs_math_big_r;
89 extern const cs_real_t cs_math_pi;
90 
91 /* Identity matrix in dimension 3 */
92 static const cs_real_33_t cs_math_33_identity = {{1., 0., 0.,},
93  {0., 1., 0.},
94  {0., 0., 1.}};
95 static const cs_real_6_t cs_math_sym_33_identity = {1., 1., 1., 0. ,0., 0.};
96 
97 /*=============================================================================
98  * Inline static function prototypes
99  *============================================================================*/
100 
101 /*----------------------------------------------------------------------------*/
110 /*----------------------------------------------------------------------------*/
111 
112 static inline int
114  int k)
115 {
116  int ret = 1;
117  assert(n >= k);
118 
119  const int n_iter = (k > n-k) ? n-k : k;
120  for (int j = 1; j <= n_iter; j++, n--) {
121  if (n % j == 0)
122  ret *= n/j;
123  else if (ret % j == 0)
124  ret = ret/j*n;
125  else
126  ret = (ret*n)/j;
127  }
128 
129  return ret;
130 }
131 
132 /*----------------------------------------------------------------------------*/
140 /*----------------------------------------------------------------------------*/
141 
142 static inline cs_real_t
144 {
145  cs_real_t ret = (x < 0) ? -x : x;
146 
147  return ret;
148 }
149 
150 /*----------------------------------------------------------------------------*/
158 /*----------------------------------------------------------------------------*/
159 
160 static inline cs_real_t
162  cs_real_t y)
163 {
164  cs_real_t ret = (x < y) ? x : y;
165 
166  return ret;
167 }
168 
169 /*----------------------------------------------------------------------------*/
177 /*----------------------------------------------------------------------------*/
178 
179 static inline cs_real_t
181  cs_real_t y)
182 {
183  cs_real_t ret = (x < y) ? y : x;
184 
185  return ret;
186 }
187 
188 /*----------------------------------------------------------------------------*/
199 /*----------------------------------------------------------------------------*/
200 
201 static inline cs_real_t
203  cs_real_t xmin,
204  cs_real_t xmax)
205 {
206  cs_real_t ret = cs_math_fmin(xmax, cs_math_fmax(xmin, x));
207 
208  return ret;
209 }
210 
211 /*----------------------------------------------------------------------------*/
219 /*----------------------------------------------------------------------------*/
220 
221 static inline cs_real_t
223 {
224  return x*x;
225 }
226 
227 /*----------------------------------------------------------------------------*/
235 /*----------------------------------------------------------------------------*/
236 
237 static inline cs_real_t
239 {
240  return x*x;
241 }
242 
243 /*----------------------------------------------------------------------------*/
251 /*----------------------------------------------------------------------------*/
252 
253 static inline cs_real_t
255 {
256  return x*x*x;
257 }
258 
259 /*----------------------------------------------------------------------------*/
267 /*----------------------------------------------------------------------------*/
268 
269 static inline cs_real_t
271 {
272  return (x*x)*(x*x);
273 }
274 
275 /*----------------------------------------------------------------------------*/
285 /*----------------------------------------------------------------------------*/
286 
287 static inline cs_real_t
289  const cs_real_t xb[3])
290 {
291  cs_real_t v[3];
292 
293  v[0] = xb[0] - xa[0];
294  v[1] = xb[1] - xa[1];
295  v[2] = xb[2] - xa[2];
296 
297  return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
298 }
299 
300 /*----------------------------------------------------------------------------*/
310 /*----------------------------------------------------------------------------*/
311 
312 static inline cs_real_t
314  const cs_real_t xb[3],
315  const cs_real_t xc[3])
316 {
317  return ((xb[0] - xa[0])*xc[0]+(xb[1] - xa[1])*xc[1]+(xb[2] - xa[2])*xc[2]);
318 }
319 
320 /*----------------------------------------------------------------------------*/
330 /*----------------------------------------------------------------------------*/
331 
332 static inline cs_real_t
334  const cs_real_t xb[3])
335 {
336  cs_real_t v[3] = {xb[0] - xa[0],
337  xb[1] - xa[1],
338  xb[2] - xa[2]};
339 
340  return (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
341 }
342 
343 /*----------------------------------------------------------------------------*/
352 /*----------------------------------------------------------------------------*/
353 
354 static inline cs_real_t
356  const cs_real_t v[3])
357 {
358  cs_real_t uv = u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
359 
360  return uv;
361 }
362 
363 /*----------------------------------------------------------------------------*/
373 /*----------------------------------------------------------------------------*/
374 
375 static inline cs_real_t
377  const cs_real_t t[3][3],
378  const cs_real_t n2[3])
379 {
380  cs_real_t n_t_n
381  = ( n1[0]*t[0][0]*n2[0] + n1[1]*t[1][0]*n2[0] + n1[2]*t[2][0]*n2[0]
382  + n1[0]*t[0][1]*n2[1] + n1[1]*t[1][1]*n2[1] + n1[2]*t[2][1]*n2[1]
383  + n1[0]*t[0][2]*n2[2] + n1[1]*t[1][2]*n2[2] + n1[2]*t[2][2]*n2[2]);
384  return n_t_n;
385 }
386 
387 /*----------------------------------------------------------------------------*/
401 /*----------------------------------------------------------------------------*/
402 
403 static inline cs_real_t
405  const cs_real_t t[6],
406  const cs_real_t n2[3])
407 {
408  return ( n1[0] * (t[0]*n2[0] + t[3]*n2[1] + t[5]*n2[2])
409  + n1[1] * (t[3]*n2[0] + t[1]*n2[1] + t[4]*n2[2])
410  + n1[2] * (t[5]*n2[0] + t[4]*n2[1] + t[2]*n2[2]));
411 }
412 
413 /*----------------------------------------------------------------------------*/
421 /*----------------------------------------------------------------------------*/
422 
423 static inline cs_real_t
425 {
426  return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
427 }
428 
429 /*----------------------------------------------------------------------------*/
437 /*----------------------------------------------------------------------------*/
438 
439 static inline cs_real_t
441 {
442  cs_real_t v2 = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
443 
444  return v2;
445 }
446 
447 /*----------------------------------------------------------------------------*/
456 /*----------------------------------------------------------------------------*/
457 
458 static inline void
460  cs_real_t vout[3])
461 {
462  cs_real_t norm = cs_math_3_norm(vin);
463 
464  cs_real_t inv_norm = ((norm > cs_math_zero_threshold) ? 1. / norm : 0);
465 
466  vout[0] = inv_norm * vin[0];
467  vout[1] = inv_norm * vin[1];
468  vout[2] = inv_norm * vin[2];
469 }
470 
471 /*----------------------------------------------------------------------------*/
480 /*----------------------------------------------------------------------------*/
481 
482 static inline void
484  cs_real_t vout[3])
485 {
486  cs_real_t norm = cs_math_3_norm(vin);
487 
488  cs_real_t inv_norm = ((norm > cs_math_zero_threshold) ? 1. / norm : 0);
489 
490  vout[0] = inv_norm * vin[0];
491  vout[1] = inv_norm * vin[1];
492  vout[2] = inv_norm * vin[2];
493 }
494 
495 /*----------------------------------------------------------------------------*/
504 /*----------------------------------------------------------------------------*/
505 
506 static inline void
508  const cs_real_t v[3],
509  cs_real_t vout[restrict 3])
510 {
511  vout[0] = v[0]*(1.-n[0]*n[0])- v[1]* n[1]*n[0] - v[2]* n[2]*n[0];
512  vout[1] = -v[0]* n[0]*n[1] + v[1]*(1.-n[1]*n[1])- v[2]* n[2]*n[1];
513  vout[2] = -v[0]* n[0]*n[2] - v[1]* n[1]*n[2] + v[2]*(1.-n[2]*n[2]);
514 }
515 
516 /*----------------------------------------------------------------------------*/
525 /*----------------------------------------------------------------------------*/
526 
527 static inline void
529  cs_real_t factor,
530  cs_real_t v[3])
531 {
532  cs_real_t v_dot_n = (factor -1.) * cs_math_3_dot_product(v, n);
533  for (int i = 0; i < 3; i++)
534  v[i] += v_dot_n * n[i];
535 }
536 
537 /*----------------------------------------------------------------------------*/
547 /*----------------------------------------------------------------------------*/
548 
549 static inline void
551  cs_real_t factor,
552  cs_real_t t[3][3])
553 {
554  cs_real_t n_t_n = (factor -1.) *
555  ( n[0] * t[0][0] * n[0] + n[1] * t[1][0] * n[0] + n[2] * t[2][0] * n[0]
556  + n[0] * t[0][1] * n[1] + n[1] * t[1][1] * n[1] + n[2] * t[2][1] * n[1]
557  + n[0] * t[0][2] * n[2] + n[1] * t[1][2] * n[2] + n[2] * t[2][2] * n[2]);
558  for (int i = 0; i < 3; i++) {
559  for (int j = 0; j < 3; j++)
560  t[i][j] += n_t_n * n[i] * n[j];
561  }
562 }
563 /*----------------------------------------------------------------------------*/
572 /*----------------------------------------------------------------------------*/
573 
574 static inline void
576  const cs_real_t v[3],
577  cs_real_t mv[restrict 3])
578 {
579  mv[0] = m[0][0]*v[0] + m[0][1]*v[1] + m[0][2]*v[2];
580  mv[1] = m[1][0]*v[0] + m[1][1]*v[1] + m[1][2]*v[2];
581  mv[2] = m[2][0]*v[0] + m[2][1]*v[1] + m[2][2]*v[2];
582 }
583 
584 /*----------------------------------------------------------------------------*/
593 /*----------------------------------------------------------------------------*/
594 
595 static inline void
597  const cs_real_t v[3],
598  cs_real_t mv[restrict 3])
599 {
600  mv[0] += m[0][0]*v[0] + m[0][1]*v[1] + m[0][2]*v[2];
601  mv[1] += m[1][0]*v[0] + m[1][1]*v[1] + m[1][2]*v[2];
602  mv[2] += m[2][0]*v[0] + m[2][1]*v[1] + m[2][2]*v[2];
603 }
604 
605 /*----------------------------------------------------------------------------*/
614 /*----------------------------------------------------------------------------*/
615 
616 static inline void
618  const cs_real_t v[3],
619  cs_real_t mv[restrict 3])
620 {
621  mv[0] = m[0][0]*v[0] + m[1][0]*v[1] + m[2][0]*v[2];
622  mv[1] = m[0][1]*v[0] + m[1][1]*v[1] + m[2][1]*v[2];
623  mv[2] = m[0][2]*v[0] + m[1][2]*v[1] + m[2][2]*v[2];
624 }
625 
626 /*----------------------------------------------------------------------------*/
636 /*----------------------------------------------------------------------------*/
637 
638 static inline void
640  const cs_real_t v[3],
641  cs_real_t mv[restrict 3])
642 {
643  mv[0] = m[0]*v[0] + m[3]*v[1] + m[5]*v[2];
644  mv[1] = m[3]*v[0] + m[1]*v[1] + m[4]*v[2];
645  mv[2] = m[5]*v[0] + m[4]*v[1] + m[2]*v[2];
646 }
647 
648 /*----------------------------------------------------------------------------*/
658 /*----------------------------------------------------------------------------*/
659 
660 static inline void
662  const cs_real_t v[3],
663  cs_real_t mv[restrict 3])
664 {
665  mv[0] += m[0] * v[0] + m[3] * v[1] + m[5] * v[2];
666  mv[1] += m[3] * v[0] + m[1] * v[1] + m[4] * v[2];
667  mv[2] += m[5] * v[0] + m[4] * v[1] + m[2] * v[2];
668 }
669 
670 /*----------------------------------------------------------------------------*/
678 /*----------------------------------------------------------------------------*/
679 
680 static inline cs_real_t
682 {
683  return (t[0] + t[1] + t[2]);
684 }
685 
686 /*----------------------------------------------------------------------------*/
695 /*----------------------------------------------------------------------------*/
696 
697 static inline void
699  const cs_real_t v[6],
700  cs_real_t mv[restrict 6])
701 {
702  for (int i = 0; i < 6; i++) {
703  for (int j = 0; j < 6; j++)
704  mv[i] = m[i][j] * v[j];
705  }
706 }
707 
708 /*----------------------------------------------------------------------------*/
717 /*----------------------------------------------------------------------------*/
718 
719 static inline void
721  const cs_real_t v[6],
722  cs_real_t mv[restrict 6])
723 {
724  for (int i = 0; i < 6; i++) {
725  for (int j = 0; j < 6; j++)
726  mv[i] += m[i][j] * v[j];
727  }
728 }
729 
730 /*----------------------------------------------------------------------------*/
738 /*----------------------------------------------------------------------------*/
739 
740 static inline cs_real_t
742 {
743  const cs_real_t com0 = m[1][1]*m[2][2] - m[2][1]*m[1][2];
744  const cs_real_t com1 = m[2][1]*m[0][2] - m[0][1]*m[2][2];
745  const cs_real_t com2 = m[0][1]*m[1][2] - m[1][1]*m[0][2];
746 
747  return m[0][0]*com0 + m[1][0]*com1 + m[2][0]*com2;
748 }
749 
750 /*----------------------------------------------------------------------------*/
758 /*----------------------------------------------------------------------------*/
759 
760 static inline cs_real_t
762 {
763  const cs_real_t com0 = m[1]*m[2] - m[4]*m[4];
764  const cs_real_t com1 = m[4]*m[5] - m[3]*m[2];
765  const cs_real_t com2 = m[3]*m[4] - m[1]*m[5];
766 
767  return m[0]*com0 + m[3]*com1 + m[5]*com2;
768 }
769 
770 /*----------------------------------------------------------------------------*/
778 /*----------------------------------------------------------------------------*/
779 
780 #if defined(__INTEL_COMPILER)
781 #pragma optimization_level 0 /* Bug with O1 or above with icc 15.0.1 20141023 */
782 #endif
783 
784 static inline void
786  const cs_real_t v[3],
787  cs_real_t uv[restrict 3])
788 {
789  uv[0] = u[1]*v[2] - u[2]*v[1];
790  uv[1] = u[2]*v[0] - u[0]*v[2];
791  uv[2] = u[0]*v[1] - u[1]*v[0];
792 }
793 
794 /*----------------------------------------------------------------------------*/
804 /*----------------------------------------------------------------------------*/
805 
806 #if defined(__INTEL_COMPILER)
807 #pragma optimization_level 0 /* Bug with O1 or above with icc 15.0.1 20141023 */
808 #endif
809 
810 static inline cs_real_t
812  const cs_real_t v[3],
813  const cs_real_t w[3])
814 {
815  return (u[1]*v[2] - u[2]*v[1]) * w[0]
816  + (u[2]*v[0] - u[0]*v[2]) * w[1]
817  + (u[0]*v[1] - u[1]*v[0]) * w[2];
818 }
819 
820 /*----------------------------------------------------------------------------*/
830 /*----------------------------------------------------------------------------*/
831 
832 static inline void
834  cs_real_t axes[3][3])
835 {
836  assert(cs_math_3_norm(vect) > cs_math_zero_threshold);
837 
838  // Compute first axis
839  cs_math_3_normalize(vect, axes[0]);
840 
841  // Compute second axis
842  // First test projection of Ox
843  cs_real_t Ox[3] = {1., 0., 0.};
844  cs_real_t w[3] = {0.};
845 
846  cs_math_3_orthogonal_projection(axes[0], Ox, w);
847 
848  // If Ox projection is null, project Oy
850  cs_real_t Oy[3] = {0., 1., 0.};
851  cs_math_3_orthogonal_projection(axes[0], Oy, w);
852  }
853 
854  cs_math_3_normalize(w, axes[1]);
855 
856  // Compute third axis using cross product
857  cs_math_3_cross_product(axes[0], axes[1], axes[2]);
858 }
859 
860 /*----------------------------------------------------------------------------*/
867 /*----------------------------------------------------------------------------*/
868 
869 static inline void
871  cs_real_t out[3][3])
872 {
873  out[0][0] = in[1][1]*in[2][2] - in[2][1]*in[1][2];
874  out[0][1] = in[2][1]*in[0][2] - in[0][1]*in[2][2];
875  out[0][2] = in[0][1]*in[1][2] - in[1][1]*in[0][2];
876 
877  out[1][0] = in[2][0]*in[1][2] - in[1][0]*in[2][2];
878  out[1][1] = in[0][0]*in[2][2] - in[2][0]*in[0][2];
879  out[1][2] = in[1][0]*in[0][2] - in[0][0]*in[1][2];
880 
881  out[2][0] = in[1][0]*in[2][1] - in[2][0]*in[1][1];
882  out[2][1] = in[2][0]*in[0][1] - in[0][0]*in[2][1];
883  out[2][2] = in[0][0]*in[1][1] - in[1][0]*in[0][1];
884 
885  const double det = in[0][0]*out[0][0]+in[1][0]*out[0][1]+in[2][0]*out[0][2];
886  const double invdet = 1./det;
887 
888  out[0][0] *= invdet, out[0][1] *= invdet, out[0][2] *= invdet;
889  out[1][0] *= invdet, out[1][1] *= invdet, out[1][2] *= invdet;
890  out[2][0] *= invdet, out[2][1] *= invdet, out[2][2] *= invdet;
891 }
892 
893 /*----------------------------------------------------------------------------*/
899 /*----------------------------------------------------------------------------*/
900 
901 static inline void
903 {
904  cs_real_t a00 = a[1][1]*a[2][2] - a[2][1]*a[1][2];
905  cs_real_t a01 = a[2][1]*a[0][2] - a[0][1]*a[2][2];
906  cs_real_t a02 = a[0][1]*a[1][2] - a[1][1]*a[0][2];
907  cs_real_t a10 = a[2][0]*a[1][2] - a[1][0]*a[2][2];
908  cs_real_t a11 = a[0][0]*a[2][2] - a[2][0]*a[0][2];
909  cs_real_t a12 = a[1][0]*a[0][2] - a[0][0]*a[1][2];
910  cs_real_t a20 = a[1][0]*a[2][1] - a[2][0]*a[1][1];
911  cs_real_t a21 = a[2][0]*a[0][1] - a[0][0]*a[2][1];
912  cs_real_t a22 = a[0][0]*a[1][1] - a[1][0]*a[0][1];
913 
914  double det_inv = 1. / (a[0][0]*a00 + a[1][0]*a01 + a[2][0]*a02);
915 
916  a[0][0] = a00 * det_inv;
917  a[0][1] = a01 * det_inv;
918  a[0][2] = a02 * det_inv;
919  a[1][0] = a10 * det_inv;
920  a[1][1] = a11 * det_inv;
921  a[1][2] = a12 * det_inv;
922  a[2][0] = a20 * det_inv;
923  a[2][1] = a21 * det_inv;
924  a[2][2] = a22 * det_inv;
925 }
926 
927 /*----------------------------------------------------------------------------*/
934 /*----------------------------------------------------------------------------*/
935 
936 static inline void
938 {
939  cs_real_t a00 = a[1][1]*a[2][2] - a[2][1]*a[1][2];
940  cs_real_t a01 = a[2][1]*a[0][2] - a[0][1]*a[2][2];
941  cs_real_t a02 = a[0][1]*a[1][2] - a[1][1]*a[0][2];
942  cs_real_t a11 = a[0][0]*a[2][2] - a[2][0]*a[0][2];
943  cs_real_t a12 = a[1][0]*a[0][2] - a[0][0]*a[1][2];
944  cs_real_t a22 = a[0][0]*a[1][1] - a[1][0]*a[0][1];
945 
946  double det_inv = 1. / (a[0][0]*a00 + a[1][0]*a01 + a[2][0]*a02);
947 
948  a[0][0] = a00 * det_inv;
949  a[0][1] = a01 * det_inv;
950  a[0][2] = a02 * det_inv;
951  a[1][0] = a01 * det_inv;
952  a[1][1] = a11 * det_inv;
953  a[1][2] = a12 * det_inv;
954  a[2][0] = a02 * det_inv;
955  a[2][1] = a12 * det_inv;
956  a[2][2] = a22 * det_inv;
957 }
958 
959 /*----------------------------------------------------------------------------*/
969 /*----------------------------------------------------------------------------*/
970 
971 static inline void
973  cs_real_t sout[restrict 6])
974 {
975  double detinv;
976 
977  sout[0] = s[1]*s[2] - s[4]*s[4];
978  sout[1] = s[0]*s[2] - s[5]*s[5];
979  sout[2] = s[0]*s[1] - s[3]*s[3];
980  sout[3] = s[4]*s[5] - s[3]*s[2];
981  sout[4] = s[3]*s[5] - s[0]*s[4];
982  sout[5] = s[3]*s[4] - s[1]*s[5];
983 
984  detinv = 1. / (s[0]*sout[0] + s[3]*sout[3] + s[5]*sout[5]);
985 
986  sout[0] *= detinv;
987  sout[1] *= detinv;
988  sout[2] *= detinv;
989  sout[3] *= detinv;
990  sout[4] *= detinv;
991  sout[5] *= detinv;
992 }
993 
994 /*----------------------------------------------------------------------------*/
1002 /*----------------------------------------------------------------------------*/
1003 
1004 static inline void
1006  const cs_real_t m2[3][3],
1007  cs_real_t mout[3][3])
1008 {
1009  mout[0][0] = m1[0][0]*m2[0][0] + m1[0][1]*m2[1][0] + m1[0][2]*m2[2][0];
1010  mout[0][1] = m1[0][0]*m2[0][1] + m1[0][1]*m2[1][1] + m1[0][2]*m2[2][1];
1011  mout[0][2] = m1[0][0]*m2[0][2] + m1[0][1]*m2[1][2] + m1[0][2]*m2[2][2];
1012 
1013  mout[1][0] = m1[1][0]*m2[0][0] + m1[1][1]*m2[1][0] + m1[1][2]*m2[2][0];
1014  mout[1][1] = m1[1][0]*m2[0][1] + m1[1][1]*m2[1][1] + m1[1][2]*m2[2][1];
1015  mout[1][2] = m1[1][0]*m2[0][2] + m1[1][1]*m2[1][2] + m1[1][2]*m2[2][2];
1016 
1017  mout[2][0] = m1[2][0]*m2[0][0] + m1[2][1]*m2[1][0] + m1[2][2]*m2[2][0];
1018  mout[2][1] = m1[2][0]*m2[0][1] + m1[2][1]*m2[1][1] + m1[2][2]*m2[2][1];
1019  mout[2][2] = m1[2][0]*m2[0][2] + m1[2][1]*m2[1][2] + m1[2][2]*m2[2][2];
1020 }
1021 
1022 /*----------------------------------------------------------------------------*/
1031 /*----------------------------------------------------------------------------*/
1032 
1033 static inline void
1035  const cs_real_t q[3][3],
1036  cs_real_t mout[3][3])
1037 {
1038  /* _m = M.Q */
1039  cs_real_33_t _m;
1040  _m[0][0] = m[0][0]*q[0][0] + m[0][1]*q[1][0] + m[0][2]*q[2][0];
1041  _m[0][1] = m[0][0]*q[0][1] + m[0][1]*q[1][1] + m[0][2]*q[2][1];
1042  _m[0][2] = m[0][0]*q[0][2] + m[0][1]*q[1][2] + m[0][2]*q[2][2];
1043 
1044  _m[1][0] = m[1][0]*q[0][0] + m[1][1]*q[1][0] + m[1][2]*q[2][0];
1045  _m[1][1] = m[1][0]*q[0][1] + m[1][1]*q[1][1] + m[1][2]*q[2][1];
1046  _m[1][2] = m[1][0]*q[0][2] + m[1][1]*q[1][2] + m[1][2]*q[2][2];
1047 
1048  _m[2][0] = m[2][0]*q[0][0] + m[2][1]*q[1][0] + m[2][2]*q[2][0];
1049  _m[2][1] = m[2][0]*q[0][1] + m[2][1]*q[1][1] + m[2][2]*q[2][1];
1050  _m[2][2] = m[2][0]*q[0][2] + m[2][1]*q[1][2] + m[2][2]*q[2][2];
1051 
1052  /* mout = Q^t _m */
1053  mout[0][0] = q[0][0]*_m[0][0] + q[1][0]*_m[1][0] + q[2][0]*_m[2][0];
1054  mout[0][1] = q[0][0]*_m[0][1] + q[1][0]*_m[1][1] + q[2][0]*_m[2][1];
1055  mout[0][2] = q[0][0]*_m[0][2] + q[1][0]*_m[1][2] + q[2][0]*_m[2][2];
1056 
1057  mout[1][0] = q[0][1]*_m[0][0] + q[1][1]*_m[1][0] + q[2][1]*_m[2][0];
1058  mout[1][1] = q[0][1]*_m[0][1] + q[1][1]*_m[1][1] + q[2][1]*_m[2][1];
1059  mout[1][2] = q[0][1]*_m[0][2] + q[1][1]*_m[1][2] + q[2][1]*_m[2][2];
1060 
1061  mout[2][0] = q[0][2]*_m[0][0] + q[1][2]*_m[1][0] + q[2][2]*_m[2][0];
1062  mout[2][1] = q[0][2]*_m[0][1] + q[1][2]*_m[1][1] + q[2][2]*_m[2][1];
1063  mout[2][2] = q[0][2]*_m[0][2] + q[1][2]*_m[1][2] + q[2][2]*_m[2][2];
1064 }
1065 
1066 /*----------------------------------------------------------------------------*/
1075 /*----------------------------------------------------------------------------*/
1076 
1077 static inline void
1079  const cs_real_t q[3][3],
1080  cs_real_t mout[6])
1081 {
1082  /* _m = M.Q */
1083  cs_real_33_t _m;
1084  _m[0][0] = m[0]*q[0][0] + m[3]*q[1][0] + m[5]*q[2][0];
1085  _m[0][1] = m[0]*q[0][1] + m[3]*q[1][1] + m[5]*q[2][1];
1086  _m[0][2] = m[0]*q[0][2] + m[3]*q[1][2] + m[5]*q[2][2];
1087 
1088  _m[1][0] = m[3]*q[0][0] + m[1]*q[1][0] + m[4]*q[2][0];
1089  _m[1][1] = m[3]*q[0][1] + m[1]*q[1][1] + m[4]*q[2][1];
1090  _m[1][2] = m[3]*q[0][2] + m[1]*q[1][2] + m[4]*q[2][2];
1091 
1092  _m[2][0] = m[5]*q[0][0] + m[4]*q[1][0] + m[2]*q[2][0];
1093  _m[2][1] = m[5]*q[0][1] + m[4]*q[1][1] + m[2]*q[2][1];
1094  _m[2][2] = m[5]*q[0][2] + m[4]*q[1][2] + m[2]*q[2][2];
1095 
1096  /* mout = Q^t _m */
1097  mout[0] = q[0][0]*_m[0][0] + q[1][0]*_m[1][0] + q[2][0]*_m[2][0];
1098  mout[1] = q[0][1]*_m[0][1] + q[1][1]*_m[1][1] + q[2][1]*_m[2][1];
1099  mout[2] = q[0][2]*_m[0][2] + q[1][2]*_m[1][2] + q[2][2]*_m[2][2];
1100 
1101  mout[3] = q[0][0]*_m[0][1] + q[1][0]*_m[1][1] + q[2][0]*_m[2][1];
1102  mout[4] = q[0][1]*_m[0][2] + q[1][1]*_m[1][2] + q[2][1]*_m[2][2];
1103  mout[5] = q[0][0]*_m[0][2] + q[1][0]*_m[1][2] + q[2][0]*_m[2][2];
1104 
1105 }
1106 
1107 /*----------------------------------------------------------------------------*/
1116 /*----------------------------------------------------------------------------*/
1117 
1118 static inline void
1120  const cs_real_t q[3][3],
1121  cs_real_t mout[3][3])
1122 {
1123  /* _m = M.Q^t */
1124  cs_real_33_t _m;
1125  _m[0][0] = m[0][0]*q[0][0] + m[0][1]*q[0][1] + m[0][2]*q[0][2];
1126  _m[0][1] = m[0][0]*q[1][0] + m[0][1]*q[1][1] + m[0][2]*q[1][2];
1127  _m[0][2] = m[0][0]*q[2][0] + m[0][1]*q[2][1] + m[0][2]*q[2][2];
1128 
1129  _m[1][0] = m[1][0]*q[0][0] + m[1][1]*q[0][1] + m[1][2]*q[0][2];
1130  _m[1][1] = m[1][0]*q[1][0] + m[1][1]*q[1][1] + m[1][2]*q[1][2];
1131  _m[1][2] = m[1][0]*q[2][0] + m[1][1]*q[2][1] + m[1][2]*q[2][2];
1132 
1133  _m[2][0] = m[2][0]*q[0][0] + m[2][1]*q[0][1] + m[2][2]*q[0][2];
1134  _m[2][1] = m[2][0]*q[1][0] + m[2][1]*q[1][1] + m[2][2]*q[1][2];
1135  _m[2][2] = m[2][0]*q[2][0] + m[2][1]*q[2][1] + m[2][2]*q[2][2];
1136 
1137  /* mout = Q _m */
1138  mout[0][0] = q[0][0]*_m[0][0] + q[0][1]*_m[1][0] + q[0][2]*_m[2][0];
1139  mout[0][1] = q[0][0]*_m[0][1] + q[0][1]*_m[1][1] + q[0][2]*_m[2][1];
1140  mout[0][2] = q[0][0]*_m[0][2] + q[0][1]*_m[1][2] + q[0][2]*_m[2][2];
1141 
1142  mout[1][0] = q[1][0]*_m[0][0] + q[1][1]*_m[1][0] + q[1][2]*_m[2][0];
1143  mout[1][1] = q[1][0]*_m[0][1] + q[1][1]*_m[1][1] + q[1][2]*_m[2][1];
1144  mout[1][2] = q[1][0]*_m[0][2] + q[1][1]*_m[1][2] + q[1][2]*_m[2][2];
1145 
1146  mout[2][0] = q[2][0]*_m[0][0] + q[2][1]*_m[1][0] + q[2][2]*_m[2][0];
1147  mout[2][1] = q[2][0]*_m[0][1] + q[2][1]*_m[1][1] + q[2][2]*_m[2][1];
1148  mout[2][2] = q[2][0]*_m[0][2] + q[2][1]*_m[1][2] + q[2][2]*_m[2][2];
1149 }
1150 
1151 /*----------------------------------------------------------------------------*/
1160 /*----------------------------------------------------------------------------*/
1161 
1162 static inline void
1164  const cs_real_t q[3][3],
1165  cs_real_t mout[6])
1166 {
1167  /* _m = M.Q^t */
1168  cs_real_33_t _m;
1169  _m[0][0] = m[0]*q[0][0] + m[3]*q[0][1] + m[5]*q[0][2];
1170  _m[0][1] = m[0]*q[1][0] + m[3]*q[1][1] + m[5]*q[1][2];
1171  _m[0][2] = m[0]*q[2][0] + m[3]*q[2][1] + m[5]*q[2][2];
1172 
1173  _m[1][0] = m[3]*q[0][0] + m[1]*q[0][1] + m[4]*q[0][2];
1174  _m[1][1] = m[3]*q[1][0] + m[1]*q[1][1] + m[4]*q[1][2];
1175  _m[1][2] = m[3]*q[2][0] + m[1]*q[2][1] + m[4]*q[2][2];
1176 
1177  _m[2][0] = m[5]*q[0][0] + m[4]*q[0][1] + m[2]*q[0][2];
1178  _m[2][1] = m[5]*q[1][0] + m[4]*q[1][1] + m[2]*q[1][2];
1179  _m[2][2] = m[5]*q[2][0] + m[4]*q[2][1] + m[2]*q[2][2];
1180 
1181  /* mout = Q _m */
1182  mout[0] = q[0][0]*_m[0][0] + q[0][1]*_m[1][0] + q[0][2]*_m[2][0];
1183  mout[1] = q[1][0]*_m[0][1] + q[1][1]*_m[1][1] + q[1][2]*_m[2][1];
1184  mout[2] = q[2][0]*_m[0][2] + q[2][1]*_m[1][2] + q[2][2]*_m[2][2];
1185 
1186 
1187  mout[3] = q[0][0]*_m[0][1] + q[0][1]*_m[1][1] + q[0][2]*_m[2][1];
1188  mout[4] = q[1][0]*_m[0][2] + q[1][1]*_m[1][2] + q[1][2]*_m[2][2];
1189  mout[5] = q[0][0]*_m[0][2] + q[0][1]*_m[1][2] + q[0][2]*_m[2][2];
1190 }
1191 
1192 /*----------------------------------------------------------------------------*/
1201 /*----------------------------------------------------------------------------*/
1202 
1203 static inline void
1205  cs_real_t m_sym[3][3],
1206  cs_real_t m_ant[3][3])
1207 {
1208  /* sym = 0.5 (m + m_transpose) */
1209  m_sym[0][0] = 0.5 * (m[0][0] + m[0][0]);
1210  m_sym[0][1] = 0.5 * (m[0][1] + m[1][0]);
1211  m_sym[0][2] = 0.5 * (m[0][2] + m[2][0]);
1212  m_sym[1][0] = 0.5 * (m[1][0] + m[0][1]);
1213  m_sym[1][1] = 0.5 * (m[1][1] + m[1][1]);
1214  m_sym[1][2] = 0.5 * (m[1][2] + m[2][1]);
1215  m_sym[2][0] = 0.5 * (m[2][0] + m[0][2]);
1216  m_sym[2][1] = 0.5 * (m[2][1] + m[1][2]);
1217  m_sym[2][2] = 0.5 * (m[2][2] + m[2][2]);
1218 
1219  /* ant = 0.5 (m - m_transpose) */
1220  m_ant[0][0] = 0.5 * (m[0][0] - m[0][0]);
1221  m_ant[0][1] = 0.5 * (m[0][1] - m[1][0]);
1222  m_ant[0][2] = 0.5 * (m[0][2] - m[2][0]);
1223  m_ant[1][0] = 0.5 * (m[1][0] - m[0][1]);
1224  m_ant[1][1] = 0.5 * (m[1][1] - m[1][1]);
1225  m_ant[1][2] = 0.5 * (m[1][2] - m[2][1]);
1226  m_ant[2][0] = 0.5 * (m[2][0] - m[0][2]);
1227  m_ant[2][1] = 0.5 * (m[2][1] - m[1][2]);
1228  m_ant[2][2] = 0.5 * (m[2][2] - m[2][2]);
1229 }
1230 
1231 /*----------------------------------------------------------------------------*/
1239 /*----------------------------------------------------------------------------*/
1240 
1241 static inline void
1243  const cs_real_t m2[3][3],
1244  cs_real_t mout[restrict 3][3])
1245 {
1246  mout[0][0] += m1[0][0]*m2[0][0] + m1[0][1]*m2[1][0] + m1[0][2]*m2[2][0];
1247  mout[0][1] += m1[0][0]*m2[0][1] + m1[0][1]*m2[1][1] + m1[0][2]*m2[2][1];
1248  mout[0][2] += m1[0][0]*m2[0][2] + m1[0][1]*m2[1][2] + m1[0][2]*m2[2][2];
1249 
1250  mout[1][0] += m1[1][0]*m2[0][0] + m1[1][1]*m2[1][0] + m1[1][2]*m2[2][0];
1251  mout[1][1] += m1[1][0]*m2[0][1] + m1[1][1]*m2[1][1] + m1[1][2]*m2[2][1];
1252  mout[1][2] += m1[1][0]*m2[0][2] + m1[1][1]*m2[1][2] + m1[1][2]*m2[2][2];
1253 
1254  mout[2][0] += m1[2][0]*m2[0][0] + m1[2][1]*m2[1][0] + m1[2][2]*m2[2][0];
1255  mout[2][1] += m1[2][0]*m2[0][1] + m1[2][1]*m2[1][1] + m1[2][2]*m2[2][1];
1256  mout[2][2] += m1[2][0]*m2[0][2] + m1[2][1]*m2[1][2] + m1[2][2]*m2[2][2];
1257 }
1258 
1259 /*----------------------------------------------------------------------------*/
1273 /*----------------------------------------------------------------------------*/
1274 
1275 static inline void
1277  const cs_real_t s2[6],
1278  cs_real_t sout[restrict 6])
1279 {
1280  /* S11 */
1281  sout[0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
1282  /* S22 */
1283  sout[1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
1284  /* S33 */
1285  sout[2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
1286  /* S12 = S21 */
1287  sout[3] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
1288  /* S23 = S32 */
1289  sout[4] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
1290  /* S13 = S31 */
1291  sout[5] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
1292 }
1293 
1294 /*----------------------------------------------------------------------------*/
1302 /*----------------------------------------------------------------------------*/
1303 
1304 static inline void
1306  cs_real_t sout[restrict 6][6])
1307 {
1308  const int t2v[3][3] = {{0, 3, 5},
1309  {3, 1, 4},
1310  {5, 4, 2}};
1311 
1312  const int iv2t[6] = {0, 1, 2, 0, 1, 0};
1313  const int jv2t[6] = {0, 1, 2, 1, 2, 2};
1314 
1315  for (int i = 0; i < 6; i++) {
1316  for (int j = 0; j < 6; j++)
1317  sout[i][j] = 0;
1318  }
1319 
1320  /* Consider : W = s*R + R*s^t .
1321  * W_ij = Sum_{k<3} [s_ik*r_jk + s_jk*r_ik]
1322  * We look for A_(ij,pq) such as A*R = W
1323  *
1324  * so
1325  * A_(ij,jk) takes s_ik
1326  * and
1327  * A_(ij,ik) takes s_jk
1328  */
1329  for (int ij = 0; ij < 6; ij++) {
1330  int i = iv2t[ij];
1331  int j = jv2t[ij];
1332  for (int k = 0; k < 3; k++) {
1333  int ik = t2v[i][k];
1334  int jk = t2v[j][k];
1335 
1336  sout[ij][ik] += s[j][k];
1337  sout[ij][jk] += s[i][k];
1338  }
1339  }
1340 }
1341 
1342 /*----------------------------------------------------------------------------*/
1354 /*----------------------------------------------------------------------------*/
1355 
1356 static inline void
1358  const cs_real_t s2[6],
1359  const cs_real_t s3[6],
1360  cs_real_t sout[restrict 3][3])
1361 {
1362  cs_real_t _sout[3][3];
1363 
1364  /* S11 */
1365  _sout[0][0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
1366  /* S22 */
1367  _sout[1][1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
1368  /* S33 */
1369  _sout[2][2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
1370  /* S12 */
1371  _sout[0][1] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
1372  /* S21 */
1373  _sout[1][0] = s2[0]*s1[3] + s2[3]*s1[1] + s2[5]*s1[4];
1374  /* S23 */
1375  _sout[1][2] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
1376  /* S32 */
1377  _sout[2][1] = s2[3]*s1[5] + s2[1]*s1[4] + s2[4]*s1[2];
1378  /* S13 */
1379  _sout[0][2] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
1380  /* S31 */
1381  _sout[2][0] = s2[0]*s1[5] + s2[3]*s1[4] + s2[5]*s1[2];
1382 
1383  sout[0][0] = _sout[0][0]*s3[0] + _sout[0][1]*s3[3] + _sout[0][2]*s3[5];
1384  /* S22 */
1385  sout[1][1] = _sout[1][0]*s3[3] + _sout[1][1]*s3[1] + _sout[1][2]*s3[4];
1386  /* S33 */
1387  sout[2][2] = _sout[2][0]*s3[5] + _sout[2][1]*s3[4] + _sout[2][2]*s3[2];
1388  /* S12 */
1389  sout[0][1] = _sout[0][0]*s3[3] + _sout[0][1]*s3[1] + _sout[0][2]*s3[4];
1390  /* S21 */
1391  sout[1][0] = s3[0]*_sout[1][0] + s3[3]*_sout[1][1] + s3[5]*_sout[1][2];
1392  /* S23 */
1393  sout[1][2] = _sout[1][0]*s3[5] + _sout[1][1]*s3[4] + _sout[1][2]*s3[2];
1394  /* S32 */
1395  sout[2][1] = s3[3]*_sout[2][0] + s3[1]*_sout[2][1] + s3[4]*_sout[2][2];
1396  /* S13 */
1397  sout[0][2] = _sout[0][0]*s3[5] + _sout[0][1]*s3[4] + _sout[0][2]*s3[2];
1398  /* S31 */
1399  sout[2][0] = s3[0]*_sout[2][0] + s3[3]*_sout[2][1] + s3[5]*_sout[2][2];
1400 }
1401 
1402 /*----------------------------------------------------------------------------*/
1409 /*----------------------------------------------------------------------------*/
1410 
1411 static inline void
1413  cs_nvec3_t *qv)
1414 {
1415  cs_real_t magnitude = sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
1416 
1417  qv->meas = magnitude;
1418  if (fabs(magnitude) > cs_math_zero_threshold) {
1419 
1420  const cs_real_t inv = 1/magnitude;
1421  qv->unitv[0] = inv * v[0];
1422  qv->unitv[1] = inv * v[1];
1423  qv->unitv[2] = inv * v[2];
1424 
1425  }
1426  else
1427  qv->unitv[0] = qv->unitv[1] = qv->unitv[2] = 0;
1428 }
1429 
1430 /*=============================================================================
1431  * Public function prototypes
1432  *============================================================================*/
1433 
1434 /*----------------------------------------------------------------------------*/
1444 /*----------------------------------------------------------------------------*/
1445 
1446 void
1447 cs_math_3_length_unitv(const cs_real_t xa[3],
1448  const cs_real_t xb[3],
1449  cs_real_t *len,
1450  cs_real_3_t unitv);
1451 
1452 /*----------------------------------------------------------------------------*/
1464 /*----------------------------------------------------------------------------*/
1465 
1466 void
1467 cs_math_sym_33_eigen(const cs_real_t m[6],
1468  cs_real_t eig_vals[3]);
1469 
1470 /*----------------------------------------------------------------------------*/
1483 /*----------------------------------------------------------------------------*/
1484 
1485 void
1486 cs_math_33_eigen(const cs_real_t m[3][3],
1487  cs_real_t *eig_ratio,
1488  cs_real_t *eig_max);
1489 
1490 /*----------------------------------------------------------------------------*/
1501 /*----------------------------------------------------------------------------*/
1502 
1503 double
1504 cs_math_surftri(const cs_real_t xv[3],
1505  const cs_real_t xe[3],
1506  const cs_real_t xf[3]);
1507 
1508 /*----------------------------------------------------------------------------*/
1520 /*----------------------------------------------------------------------------*/
1521 
1522 double
1523 cs_math_voltet(const cs_real_t xv[3],
1524  const cs_real_t xe[3],
1525  const cs_real_t xf[3],
1526  const cs_real_t xc[3]);
1527 
1528 /*----------------------------------------------------------------------------*/
1541 /*----------------------------------------------------------------------------*/
1542 
1543 void
1544 cs_math_33_eig_val_vec(const cs_real_t m_in[3][3],
1545  const cs_real_t tol_err,
1546  cs_real_t eig_val[restrict 3],
1547  cs_real_t eig_vec[restrict 3][3]);
1548 
1549 /*----------------------------------------------------------------------------*/
1559 /*----------------------------------------------------------------------------*/
1560 
1561 void
1562 cs_math_fact_lu(cs_lnum_t n_blocks,
1563  const int b_size,
1564  const cs_real_t *a,
1565  cs_real_t *a_lu);
1566 
1567 /*----------------------------------------------------------------------------*/
1577 /*----------------------------------------------------------------------------*/
1578 
1579 void
1580 cs_math_fw_and_bw_lu(const cs_real_t a_lu[],
1581  const int n,
1582  cs_real_t x[],
1583  const cs_real_t b[]);
1584 
1585 /*----------------------------------------------------------------------------*/
1595 /*----------------------------------------------------------------------------*/
1596 
1597 void
1599 
1600 /*----------------------------------------------------------------------------*/
1613 /*----------------------------------------------------------------------------*/
1614 
1615 cs_real_t
1617  const cs_real_t rhs[4]);
1618 
1619 /*----------------------------------------------------------------------------*/
1620 
1622 
1623 #endif /* __CS_MATH_H__ */
#define restrict
Definition: cs_defs.h:139
#define BEGIN_C_DECLS
Definition: cs_defs.h:509
double cs_real_t
Floating-point value.
Definition: cs_defs.h:319
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:332
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:334
#define END_C_DECLS
Definition: cs_defs.h:510
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:341
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:313
@ t
Definition: cs_field_pointer.h:92
@ k
Definition: cs_field_pointer.h:70
static cs_real_t cs_math_fabs(cs_real_t x)
Compute the absolute value of a real value.
Definition: cs_math.h:143
static cs_real_t cs_math_sym_33_determinant(const cs_real_6_t m)
Compute the determinant of a 3x3 symmetric matrix.
Definition: cs_math.h:761
static 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:333
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.c:403
static 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:180
static void cs_math_3_normal_scaling(const cs_real_t n[3], cs_real_t factor, cs_real_t v[3])
Add the dot product with a normal vector to the normal direction to a vector.
Definition: cs_math.h:528
static 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 sout[restrict 3][3])
Compute the product of three symmetric matrices.
Definition: cs_math.h:1357
const cs_real_t cs_math_1ov6
static 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:550
static 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:161
static void cs_math_sym_33_3_product(const cs_real_t m[6], const cs_real_t v[3], cs_real_t mv[restrict 3])
Compute the product of a symmetric matrix of 3x3 real values by a vector of 3 real values....
Definition: cs_math.h:639
static 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:202
static 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:288
static void cs_math_sym_33_3_product_add(const cs_real_t m[6], const cs_real_t v[3], cs_real_t mv[restrict 3])
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:661
static cs_real_t cs_math_6_trace(const cs_real_t t[6])
Compute the trace of a symmetric tensor.
Definition: cs_math.h:681
static 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:833
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.c:436
const cs_real_t cs_math_infinite_r
static cs_real_t cs_math_3_norm(const cs_real_t v[3])
Compute the euclidean norm of a vector of dimension 3.
Definition: cs_math.h:424
static cs_real_t cs_math_3_square_norm(const cs_real_t v[3])
Compute the square norm of a vector of 3 real values.
Definition: cs_math.h:440
const cs_real_t cs_math_4ov3
static 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:1119
static cs_real_t cs_math_pow2(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:238
static void cs_math_33_product_add(const cs_real_t m1[3][3], const cs_real_t m2[3][3], cs_real_t mout[restrict 3][3])
Add the product of two 3x3 real matrices to a matrix.
Definition: cs_math.h:1242
static 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:902
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.c:230
const cs_real_t cs_math_2ov3
static void cs_math_3_normalize(const cs_real_t vin[3], cs_real_t vout[3])
Normalise a vector of 3 real values.
Definition: cs_math.h:483
static 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:1163
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[])
Block Jacobi utilities. Compute forward and backward to solve an LU P*P system.
Definition: cs_math.c:680
const cs_real_t cs_math_1ov12
static cs_real_t cs_math_pow3(cs_real_t x)
Compute the cube of a real value.
Definition: cs_math.h:254
void cs_math_fact_lu(cs_lnum_t n_blocks, const int b_size, 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.c:622
static void cs_math_sym_33_product(const cs_real_t s1[6], const cs_real_t s2[6], cs_real_t sout[restrict 6])
Compute the product of two symmetric matrices.
Definition: cs_math.h:1276
static 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:1204
static void cs_math_33t_3_product(const cs_real_t m[3][3], const cs_real_t v[3], cs_real_t mv[restrict 3])
Compute the product of the transpose of a matrix of 3x3 real values by a vector of 3 real values.
Definition: cs_math.h:617
static 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:937
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.c:316
static 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:870
const cs_real_t cs_math_1ov24
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.c:784
static cs_real_t cs_math_3_dot_product(const cs_real_t u[3], const cs_real_t v[3])
Compute the dot product of two vectors of 3 real values.
Definition: cs_math.h:355
static 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:811
static void cs_math_3_cross_product(const cs_real_t u[3], const cs_real_t v[3], cs_real_t uv[restrict 3])
Compute the cross product of two vectors of 3 real values.
Definition: cs_math.h:785
cs_math_sym_tensor_component_t
Definition: cs_math.h:61
@ ZZ
Definition: cs_math.h:65
@ XY
Definition: cs_math.h:66
@ XZ
Definition: cs_math.h:68
@ YZ
Definition: cs_math.h:67
@ YY
Definition: cs_math.h:64
@ XX
Definition: cs_math.h:63
static void cs_math_3_orthogonal_projection(const cs_real_t n[3], const cs_real_t v[3], cs_real_t vout[restrict 3])
Orthogonal projection of a vector with respect to a normalised vector.
Definition: cs_math.h:507
static void cs_math_sym_33_inv_cramer(const cs_real_t s[6], cs_real_t sout[restrict 6])
Compute the inverse of a symmetric matrix using Cramer's rule.
Definition: cs_math.h:972
static void cs_math_33_3_product(const cs_real_t m[3][3], const cs_real_t v[3], cs_real_t mv[restrict 3])
Compute the product of a matrix of 3x3 real values by a vector of 3 real values.
Definition: cs_math.h:575
const cs_real_t cs_math_1ov3
static cs_real_t cs_math_3_distance_dot_product(const cs_real_t xa[3], const cs_real_t xb[3], const cs_real_t xc[3])
Compute .
Definition: cs_math.h:313
static 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:1078
static void cs_math_33_3_product_add(const cs_real_t m[3][3], const cs_real_t v[3], cs_real_t mv[restrict 3])
Compute the product of a matrix of 3x3 real values by a vector of 3 real values add.
Definition: cs_math.h:596
static 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:1034
const cs_real_t cs_math_5ov3
static cs_real_t cs_math_sq(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:222
static void cs_math_66_6_product_add(const cs_real_t m[6][6], const cs_real_t v[6], cs_real_t mv[restrict 6])
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:720
const cs_real_t cs_math_epzero
static cs_real_t cs_math_3_sym_33_3_dot_product(const cs_real_t n1[3], const cs_real_t t[6], const cs_real_t n2[3])
Compute the dot product of a symmetric tensor t with two vectors, n1 and n2.
Definition: cs_math.h:404
const cs_real_t cs_math_big_r
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.c:466
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[restrict 3], cs_real_t eig_vec[restrict 3][3])
Evaluate eigenvalues and eigenvectors of a real symmetric matrix m1[3,3]: m1*m2 = lambda*m2.
Definition: cs_math.c:498
static int cs_math_binom(int n, int k)
Computes the binomial coefficient of n and k.
Definition: cs_math.h:113
static void cs_nvec3(const cs_real_3_t v, cs_nvec3_t *qv)
Define a cs_nvec3_t structure from a cs_real_3_t.
Definition: cs_math.h:1412
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.c:725
static void cs_math_reduce_sym_prod_33_to_66(const cs_real_t s[3][3], cs_real_t sout[restrict 6][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:1305
const cs_real_t cs_math_pi
static void cs_math_66_6_product(const cs_real_t m[6][6], const cs_real_t v[6], cs_real_t mv[restrict 6])
Compute the product of a matrix of 6x6 real values by a vector of 6 real values.
Definition: cs_math.h:698
static const cs_real_33_t cs_math_33_identity
Definition: cs_math.h:92
static cs_real_t cs_math_pow4(cs_real_t x)
Compute the 4-th power of a real value.
Definition: cs_math.h:270
static const cs_real_6_t cs_math_sym_33_identity
Definition: cs_math.h:95
static void cs_math_3_normalise(const cs_real_t vin[3], cs_real_t vout[3])
Normalize a vector of 3 real values.
Definition: cs_math.h:459
static 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:741
static 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:1005
static cs_real_t cs_math_3_33_3_dot_product(const cs_real_t n1[3], const cs_real_t t[3][3], const cs_real_t n2[3])
Compute the dot product of a tensor t with two vectors, n1 and n2.
Definition: cs_math.h:376
const cs_real_t cs_math_zero_threshold
double precision, dimension(:,:,:), allocatable u
Definition: atimbr.f90:113
double precision, dimension(:,:,:), allocatable v
Definition: atimbr.f90:114
integer, save ik
turbulent kinetic energy
Definition: numvar.f90:75
double precision, save a
Definition: cs_fuel_incl.f90:148
double precision, save b
Definition: cs_fuel_incl.f90:148
Definition: cs_defs.h:367
double meas
Definition: cs_defs.h:369
double unitv[3]
Definition: cs_defs.h:370