programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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-2018 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 /*============================================================================
60  * Global variables
61  *============================================================================*/
62 
63 /* Numerical constants */
64 
66 extern const cs_real_t cs_math_onethird;
67 extern const cs_real_t cs_math_onesix;
68 extern const cs_real_t cs_math_onetwelve;
69 extern const cs_real_t cs_math_epzero;
70 extern const cs_real_t cs_math_infinite_r;
71 extern const cs_real_t cs_math_big_r;
72 extern const cs_real_t cs_math_pi;
73 
74 /*=============================================================================
75  * Inline static function prototypes
76  *============================================================================*/
77 
78 /*----------------------------------------------------------------------------*/
87 /*----------------------------------------------------------------------------*/
88 
89 static inline int
90 cs_math_binom(short int n,
91  short int k)
92 {
93  int ret = 1;
94  assert(n >= k);
95 
96  const short int n_iter = (k > n-k) ? n-k : k;
97  for (short int j = 1; j <= n_iter; j++, n--) {
98  if (n % j == 0)
99  ret *= n/j;
100  else if (ret % j == 0)
101  ret = ret/j*n;
102  else
103  ret = (ret*n)/j;
104  }
105 
106  return ret;
107 }
108 
109 /*----------------------------------------------------------------------------*/
117 /*----------------------------------------------------------------------------*/
118 
119 static inline cs_real_t
121 {
122  return x*x;
123 }
124 
125 /*----------------------------------------------------------------------------*/
133 /*----------------------------------------------------------------------------*/
134 
135 static inline cs_real_t
137 {
138  return x*x;
139 }
140 
141 /*----------------------------------------------------------------------------*/
149 /*----------------------------------------------------------------------------*/
150 
151 static inline cs_real_t
153 {
154  return x*x*x;
155 }
156 
157 /*----------------------------------------------------------------------------*/
165 /*----------------------------------------------------------------------------*/
166 
167 static inline cs_real_t
169 {
170  return (x*x)*(x*x);
171 }
172 
173 /*----------------------------------------------------------------------------*/
183 /*----------------------------------------------------------------------------*/
184 
185 static inline cs_real_t
187  const cs_real_t xb[3])
188 {
189  cs_real_t v[3];
190 
191  v[0] = xb[0] - xa[0];
192  v[1] = xb[1] - xa[1];
193  v[2] = xb[2] - xa[2];
194 
195  return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
196 }
197 
198 /*----------------------------------------------------------------------------*/
208 /*----------------------------------------------------------------------------*/
209 
210 static inline cs_real_t
212  const cs_real_t xb[3],
213  const cs_real_t xc[3])
214 {
215  return ((xb[0] - xa[0])*xc[0]+(xb[1] - xa[1])*xc[1]+(xb[2] - xa[2])*xc[2]);
216 }
217 
218 /*----------------------------------------------------------------------------*/
228 /*----------------------------------------------------------------------------*/
229 
230 static inline cs_real_t
232  const cs_real_t xb[3])
233 {
234  cs_real_t v[3] = {xb[0] - xa[0],
235  xb[1] - xa[1],
236  xb[2] - xa[2]};
237 
238  return (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
239 }
240 
241 /*----------------------------------------------------------------------------*/
250 /*----------------------------------------------------------------------------*/
251 
252 static inline cs_real_t
254  const cs_real_t v[3])
255 {
256  cs_real_t uv = u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
257 
258  return uv;
259 }
260 
261 /*----------------------------------------------------------------------------*/
269 /*----------------------------------------------------------------------------*/
270 
271 static inline cs_real_t
273 {
274  return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
275 }
276 
277 /*----------------------------------------------------------------------------*/
285 /*----------------------------------------------------------------------------*/
286 
287 static inline cs_real_t
289 {
290  cs_real_t v2 = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
291 
292  return v2;
293 }
294 
295 /*----------------------------------------------------------------------------*/
302 /*----------------------------------------------------------------------------*/
303 
304 static inline void
306  cs_real_t vout[restrict 3])
307 {
308  cs_real_t norm = cs_math_3_norm(vin);
309 
310  cs_real_t inv_norm = ((norm > cs_math_zero_threshold) ? 1. / norm : 0);
311 
312  vout[0] = inv_norm * vin[0];
313  vout[1] = inv_norm * vin[1];
314  vout[2] = inv_norm * vin[2];
315 }
316 
317 /*----------------------------------------------------------------------------*/
326 /*----------------------------------------------------------------------------*/
327 
328 static inline void
330  const cs_real_t v[3],
331  cs_real_3_t mv)
332 {
333  mv[0] = m[0][0]*v[0] + m[0][1]*v[1] + m[0][2]*v[2];
334  mv[1] = m[1][0]*v[0] + m[1][1]*v[1] + m[1][2]*v[2];
335  mv[2] = m[2][0]*v[0] + m[2][1]*v[1] + m[2][2]*v[2];
336 }
337 
338 /*----------------------------------------------------------------------------*/
347 /*----------------------------------------------------------------------------*/
348 
349 static inline void
351  const cs_real_t v[3],
352  cs_real_3_t mv)
353 {
354  mv[0] = m[0][0]*v[0] + m[1][0]*v[1] + m[2][0]*v[2];
355  mv[1] = m[0][1]*v[0] + m[1][1]*v[1] + m[2][1]*v[2];
356  mv[2] = m[0][2]*v[0] + m[1][2]*v[1] + m[2][2]*v[2];
357 }
358 
359 /*----------------------------------------------------------------------------*/
369 /*----------------------------------------------------------------------------*/
370 
371 static inline void
373  const cs_real_t v[3],
374  cs_real_t mv[restrict 3])
375 {
376  mv[0] = m[0] * v[0] + m[3] * v[1] + m[5] * v[2];
377  mv[1] = m[3] * v[0] + m[1] * v[1] + m[4] * v[2];
378  mv[2] = m[5] * v[0] + m[4] * v[1] + m[2] * v[2];
379 }
380 
381 /*----------------------------------------------------------------------------*/
391 /*----------------------------------------------------------------------------*/
392 
393 static inline void
395  const cs_real_t v[3],
396  cs_real_t mv[restrict 3])
397 {
398  mv[0] += m[0] * v[0] + m[3] * v[1] + m[5] * v[2];
399  mv[1] += m[3] * v[0] + m[1] * v[1] + m[4] * v[2];
400  mv[2] += m[5] * v[0] + m[4] * v[1] + m[2] * v[2];
401 }
402 
403 /*----------------------------------------------------------------------------*/
412 /*----------------------------------------------------------------------------*/
413 
414 static inline void
416  const cs_real_t v[6],
417  cs_real_t mv[restrict 6])
418 {
419  for (int i = 0; i < 6; i++) {
420  for (int j = 0; j < 6; j++)
421  mv[i] = m[i][j] * v[j];
422  }
423 }
424 
425 /*----------------------------------------------------------------------------*/
434 /*----------------------------------------------------------------------------*/
435 
436 static inline void
438  const cs_real_t v[6],
439  cs_real_t mv[restrict 6])
440 {
441  for (int i = 0; i < 6; i++) {
442  for (int j = 0; j < 6; j++)
443  mv[i] += m[i][j] * v[j];
444  }
445 }
446 
447 /*----------------------------------------------------------------------------*/
455 /*----------------------------------------------------------------------------*/
456 
457 static inline cs_real_t
459 {
460  const cs_real_t com0 = m[1][1]*m[2][2] - m[2][1]*m[1][2];
461  const cs_real_t com1 = m[2][1]*m[0][2] - m[0][1]*m[2][2];
462  const cs_real_t com2 = m[0][1]*m[1][2] - m[1][1]*m[0][2];
463 
464  return m[0][0]*com0 + m[1][0]*com1 + m[2][0]*com2;
465 }
466 
467 /*----------------------------------------------------------------------------*/
475 /*----------------------------------------------------------------------------*/
476 
477 static inline cs_real_t
479 {
480  const cs_real_t com0 = m[1]*m[2] - m[4]*m[4];
481  const cs_real_t com1 = m[4]*m[5] - m[3]*m[2];
482  const cs_real_t com2 = m[3]*m[4] - m[1]*m[5];
483 
484  return m[0]*com0 + m[3]*com1 + m[5]*com2;
485 }
486 
487 
488 /*----------------------------------------------------------------------------*/
496 /*----------------------------------------------------------------------------*/
497 
498 #if defined(__INTEL_COMPILER)
499 #pragma optimization_level 0 /* Bug with O1 or above with icc 15.0.1 20141023 */
500 #endif
501 
502 static inline void
504  const cs_real_t v[3],
505  cs_real_t uv[restrict 3])
506 {
507  uv[0] = u[1]*v[2] - u[2]*v[1];
508  uv[1] = u[2]*v[0] - u[0]*v[2];
509  uv[2] = u[0]*v[1] - u[1]*v[0];
510 }
511 
512 /*----------------------------------------------------------------------------*/
519 /*----------------------------------------------------------------------------*/
520 
521 static inline void
523  cs_real_t out[3][3])
524 {
525  out[0][0] = in[1][1]*in[2][2] - in[2][1]*in[1][2];
526  out[0][1] = in[2][1]*in[0][2] - in[0][1]*in[2][2];
527  out[0][2] = in[0][1]*in[1][2] - in[1][1]*in[0][2];
528 
529  out[1][0] = in[2][0]*in[1][2] - in[1][0]*in[2][2];
530  out[1][1] = in[0][0]*in[2][2] - in[2][0]*in[0][2];
531  out[1][2] = in[1][0]*in[0][2] - in[0][0]*in[1][2];
532 
533  out[2][0] = in[1][0]*in[2][1] - in[2][0]*in[1][1];
534  out[2][1] = in[2][0]*in[0][1] - in[0][0]*in[2][1];
535  out[2][2] = in[0][0]*in[1][1] - in[1][0]*in[0][1];
536 
537  const double det = in[0][0]*out[0][0]+in[1][0]*out[0][1]+in[2][0]*out[0][2];
538  const double invdet = 1/det;
539 
540  out[0][0] *= invdet, out[0][1] *= invdet, out[0][2] *= invdet;
541  out[1][0] *= invdet, out[1][1] *= invdet, out[1][2] *= invdet;
542  out[2][0] *= invdet, out[2][1] *= invdet, out[2][2] *= invdet;
543 }
544 
545 /*----------------------------------------------------------------------------*/
551 /*----------------------------------------------------------------------------*/
552 
553 static inline void
555 {
556  cs_real_t a00 = a[1][1]*a[2][2] - a[2][1]*a[1][2];
557  cs_real_t a01 = a[2][1]*a[0][2] - a[0][1]*a[2][2];
558  cs_real_t a02 = a[0][1]*a[1][2] - a[1][1]*a[0][2];
559  cs_real_t a10 = a[2][0]*a[1][2] - a[1][0]*a[2][2];
560  cs_real_t a11 = a[0][0]*a[2][2] - a[2][0]*a[0][2];
561  cs_real_t a12 = a[1][0]*a[0][2] - a[0][0]*a[1][2];
562  cs_real_t a20 = a[1][0]*a[2][1] - a[2][0]*a[1][1];
563  cs_real_t a21 = a[2][0]*a[0][1] - a[0][0]*a[2][1];
564  cs_real_t a22 = a[0][0]*a[1][1] - a[1][0]*a[0][1];
565 
566  double det_inv = 1. / (a[0][0]*a00 + a[1][0]*a01 + a[2][0]*a02);
567 
568  a[0][0] = a00 * det_inv;
569  a[0][1] = a01 * det_inv;
570  a[0][2] = a02 * det_inv;
571  a[1][0] = a10 * det_inv;
572  a[1][1] = a11 * det_inv;
573  a[1][2] = a12 * det_inv;
574  a[2][0] = a20 * det_inv;
575  a[2][1] = a21 * det_inv;
576  a[2][2] = a22 * det_inv;
577 }
578 
579 /*----------------------------------------------------------------------------*/
586 /*----------------------------------------------------------------------------*/
587 
588 static inline void
590 {
591  cs_real_t a00 = a[1][1]*a[2][2] - a[2][1]*a[1][2];
592  cs_real_t a01 = a[2][1]*a[0][2] - a[0][1]*a[2][2];
593  cs_real_t a02 = a[0][1]*a[1][2] - a[1][1]*a[0][2];
594  cs_real_t a11 = a[0][0]*a[2][2] - a[2][0]*a[0][2];
595  cs_real_t a12 = a[1][0]*a[0][2] - a[0][0]*a[1][2];
596  cs_real_t a22 = a[0][0]*a[1][1] - a[1][0]*a[0][1];
597 
598  double det_inv = 1. / (a[0][0]*a00 + a[1][0]*a01 + a[2][0]*a02);
599 
600  a[0][0] = a00 * det_inv;
601  a[0][1] = a01 * det_inv;
602  a[0][2] = a02 * det_inv;
603  a[1][0] = a01 * det_inv;
604  a[1][1] = a11 * det_inv;
605  a[1][2] = a12 * det_inv;
606  a[2][0] = a02 * det_inv;
607  a[2][1] = a12 * det_inv;
608  a[2][2] = a22 * det_inv;
609 }
610 
611 /*----------------------------------------------------------------------------*/
621 /*----------------------------------------------------------------------------*/
622 
623 static inline void
625  cs_real_t sout[restrict 6])
626 {
627  double detinv;
628 
629  sout[0] = s[1]*s[2] - s[4]*s[4];
630  sout[1] = s[0]*s[2] - s[5]*s[5];
631  sout[2] = s[0]*s[1] - s[3]*s[3];
632  sout[3] = s[4]*s[5] - s[3]*s[2];
633  sout[4] = s[3]*s[5] - s[0]*s[4];
634  sout[5] = s[3]*s[4] - s[1]*s[5];
635 
636  detinv = 1. / (s[0]*sout[0] + s[3]*sout[3] + s[5]*sout[5]);
637 
638  sout[0] *= detinv;
639  sout[1] *= detinv;
640  sout[2] *= detinv;
641  sout[3] *= detinv;
642  sout[4] *= detinv;
643  sout[5] *= detinv;
644 }
645 
646 /*----------------------------------------------------------------------------*/
659 /*----------------------------------------------------------------------------*/
660 
661 static inline void
663  const cs_real_t s2[6],
664  cs_real_t sout[restrict 6])
665 {
666  /* S11 */
667  sout[0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
668  /* S22 */
669  sout[1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
670  /* S33 */
671  sout[2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
672  /* S12 = S21 */
673  sout[3] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
674  /* S23 = S32 */
675  sout[4] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
676  /* S13 = S31 */
677  sout[5] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
678 }
679 
680 /*----------------------------------------------------------------------------*/
688 /*----------------------------------------------------------------------------*/
689 
690 static inline void
692  cs_real_t sout[restrict 6][6])
693 {
694  int tens2vect[3][3];
695  int iindex[6], jindex[6];
696 
697  tens2vect[0][0] = 0; tens2vect[0][1] = 3; tens2vect[0][2] = 5;
698  tens2vect[1][0] = 3; tens2vect[1][1] = 1; tens2vect[1][2] = 4;
699  tens2vect[2][0] = 5; tens2vect[2][1] = 4; tens2vect[2][2] = 2;
700 
701  iindex[0] = 0; iindex[1] = 1; iindex[2] = 2;
702  iindex[3] = 0; iindex[4] = 1; iindex[5] = 0;
703 
704  jindex[0] = 0; jindex[1] = 1; jindex[2] = 2;
705  jindex[3] = 1; jindex[4] = 2; jindex[5] = 2;
706 
707  /* Consider : W = R*s^t + s*R.
708  * W_ij = Sum_{k<3} [s_jk*r_ik + s_ik*r_jk]
709  * We look for A such as A*R = W
710  */
711  for (int i = 0; i < 6; i++) {
712  int ii = iindex[i];
713  int jj = jindex[i];
714  for (int k = 0; k < 3; k++) {
715  int ik = tens2vect[k][ii];
716  int jk = tens2vect[k][jj];
717 
718  sout[ik][i] += s[k][jj];
719 
720  sout[jk][i] += s[k][ii];
721  }
722  }
723 }
724 
725 /*----------------------------------------------------------------------------*/
737 /*----------------------------------------------------------------------------*/
738 
739 static inline void
741  const cs_real_t s2[6],
742  const cs_real_t s3[6],
743  cs_real_t sout[restrict 3][3])
744 {
745  cs_real_33_t _sout;
746 
747  /* S11 */
748  _sout[0][0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
749  /* S22 */
750  _sout[1][1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
751  /* S33 */
752  _sout[2][2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
753  /* S12 */
754  _sout[0][1] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
755  /* S21 */
756  _sout[1][0] = s2[0]*s1[3] + s2[3]*s1[1] + s2[5]*s1[4];
757  /* S23 */
758  _sout[1][2] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
759  /* S32 */
760  _sout[2][1] = s2[3]*s1[5] + s2[1]*s1[4] + s2[4]*s1[2];
761  /* S13 */
762  _sout[0][2] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
763  /* S31 */
764  _sout[2][0] = s2[0]*s1[5] + s2[3]*s1[4] + s2[5]*s1[2];
765 
766  sout[0][0] = _sout[0][0]*s3[0] + _sout[0][1]*s3[3] + _sout[0][2]*s3[5];
767  /* S22 */
768  sout[1][1] = _sout[1][0]*s3[3] + _sout[1][1]*s3[1] + _sout[1][2]*s3[4];
769  /* S33 */
770  sout[2][2] = _sout[2][0]*s3[5] + _sout[2][1]*s3[4] + _sout[2][2]*s3[2];
771  /* S12 */
772  sout[0][1] = _sout[0][0]*s3[3] + _sout[0][1]*s3[1] + _sout[0][2]*s3[4];
773  /* S21 */
774  sout[1][0] = s3[0]*_sout[1][0] + s3[3]*_sout[1][1] + s3[5]*_sout[1][2];
775  /* S23 */
776  sout[1][2] = _sout[1][0]*s3[5] + _sout[1][1]*s3[4] + _sout[1][2]*s3[2];
777  /* S32 */
778  sout[2][1] = s3[3]*_sout[2][0] + s3[1]*_sout[2][1] + s3[4]*_sout[2][2];
779  /* S13 */
780  sout[0][2] = _sout[0][0]*s3[5] + _sout[0][1]*s3[4] + _sout[0][2]*s3[2];
781  /* S31 */
782  sout[2][0] = s3[0]*_sout[2][0] + s3[3]*_sout[2][1] + s3[5]*_sout[2][2];
783 }
784 
785 /*=============================================================================
786  * Public function prototypes
787  *============================================================================*/
788 
789 /*----------------------------------------------------------------------------*/
793 /*----------------------------------------------------------------------------*/
794 
795 void
797 
798 /*----------------------------------------------------------------------------*/
802 /*----------------------------------------------------------------------------*/
803 
804 double
806 
807 /*----------------------------------------------------------------------------*/
817 /*----------------------------------------------------------------------------*/
818 
819 void
821  const cs_real_t xb[3],
822  cs_real_t *len,
823  cs_real_3_t unitv);
824 
825 /*----------------------------------------------------------------------------*/
837 /*----------------------------------------------------------------------------*/
838 
839 void
841  cs_real_t eig_vals[3]);
842 
843 /*----------------------------------------------------------------------------*/
856 /*----------------------------------------------------------------------------*/
857 
858 void
859 cs_math_33_eigen(const cs_real_t m[3][3],
860  cs_real_t *eig_ratio,
861  cs_real_t *eig_max);
862 
863 /*----------------------------------------------------------------------------*/
874 /*----------------------------------------------------------------------------*/
875 
876 double
877 cs_math_surftri(const cs_real_t xv[3],
878  const cs_real_t xe[3],
879  const cs_real_t xf[3]);
880 
881 /*----------------------------------------------------------------------------*/
893 /*----------------------------------------------------------------------------*/
894 
895 double
896 cs_math_voltet(const cs_real_t xv[3],
897  const cs_real_t xe[3],
898  const cs_real_t xf[3],
899  const cs_real_t xc[3]);
900 
901 /*----------------------------------------------------------------------------*/
911 /*----------------------------------------------------------------------------*/
912 
913 void
914 cs_math_fact_lu(cs_lnum_t n_blocks,
915  const int b_size,
916  const cs_real_t *a,
917  cs_real_t *a_lu);
918 
919 /*----------------------------------------------------------------------------*/
929 /*----------------------------------------------------------------------------*/
930 
931 void
932 cs_math_fw_and_bw_lu(const cs_real_t a_lu[],
933  const int n,
934  cs_real_t x[],
935  const cs_real_t b[]);
936 
937 /*----------------------------------------------------------------------------*/
938 
940 
941 #endif /* __CS_MATH_H__ */
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:624
Definition: cs_field_pointer.h:70
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:211
#define restrict
Definition: cs_defs.h:122
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:253
const cs_real_t cs_math_onesix
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:311
static void cs_math_3_normalise(const cs_real_t vin[3], cs_real_t vout[restrict 3])
Normalize a vector of 3 real values.
Definition: cs_math.h:305
const cs_real_t cs_math_big_r
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:394
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:415
static cs_real_t cs_math_pow3(cs_real_t x)
Compute the cube of a real value.
Definition: cs_math.h:152
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:554
static void cs_math_33_3_product(const cs_real_t m[3][3], const cs_real_t v[3], cs_real_3_t mv)
Compute the product of a matrix of 3x3 real values by a vector of 3 real values.
Definition: cs_math.h:329
const cs_real_t cs_math_pi
#define BEGIN_C_DECLS
Definition: cs_defs.h:453
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:536
const cs_real_t cs_math_epzero
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:478
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:186
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:299
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:740
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
Definition: cs_field_pointer.h:68
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:288
static cs_real_t cs_math_sq(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:120
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:419
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. Warning: this is valid if and only if s1 and s2 commut...
Definition: cs_math.h:662
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:437
double cs_math_get_machine_epsilon(void)
Get the value related to the machine precision.
Definition: cs_math.c:194
const cs_real_t cs_math_onetwelve
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:589
void cs_math_set_machine_epsilon(void)
Compute the value related to the machine precision.
Definition: cs_math.c:173
static cs_real_t cs_math_pow2(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:136
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:449
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:214
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:458
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:272
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:522
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:309
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:503
const cs_real_t cs_math_zero_threshold
const cs_real_t cs_math_onethird
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
static cs_real_t cs_math_pow4(cs_real_t x)
Compute the 4-th power of a real value.
Definition: cs_math.h:168
static int cs_math_binom(short int n, short int k)
Computes the binomial coefficient of n and k.
Definition: cs_math.h:90
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:231
#define END_C_DECLS
Definition: cs_defs.h:454
static void cs_math_33t_3_product(const cs_real_t m[3][3], const cs_real_t v[3], cs_real_3_t 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:350
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:315
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:372
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 (euclidien norm) between two points xa and xb in a cartesian coordinate system of ...
Definition: cs_math.c:386
const cs_real_t cs_math_infinite_r
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:478
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:691