programmer's 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-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_one24;
70 extern const cs_real_t cs_math_epzero;
71 extern const cs_real_t cs_math_infinite_r;
72 extern const cs_real_t cs_math_big_r;
73 extern const cs_real_t cs_math_pi;
74 
75 /*=============================================================================
76  * Inline static function prototypes
77  *============================================================================*/
78 
79 /*----------------------------------------------------------------------------*/
88 /*----------------------------------------------------------------------------*/
89 
90 static inline int
91 cs_math_binom(short int n,
92  short int k)
93 {
94  int ret = 1;
95  assert(n >= k);
96 
97  const short int n_iter = (k > n-k) ? n-k : k;
98  for (short int j = 1; j <= n_iter; j++, n--) {
99  if (n % j == 0)
100  ret *= n/j;
101  else if (ret % j == 0)
102  ret = ret/j*n;
103  else
104  ret = (ret*n)/j;
105  }
106 
107  return ret;
108 }
109 
110 /*----------------------------------------------------------------------------*/
118 /*----------------------------------------------------------------------------*/
119 
120 static inline cs_real_t
122 {
123  return x*x;
124 }
125 
126 /*----------------------------------------------------------------------------*/
134 /*----------------------------------------------------------------------------*/
135 
136 static inline cs_real_t
138 {
139  return x*x;
140 }
141 
142 /*----------------------------------------------------------------------------*/
150 /*----------------------------------------------------------------------------*/
151 
152 static inline cs_real_t
154 {
155  return x*x*x;
156 }
157 
158 /*----------------------------------------------------------------------------*/
166 /*----------------------------------------------------------------------------*/
167 
168 static inline cs_real_t
170 {
171  return (x*x)*(x*x);
172 }
173 
174 /*----------------------------------------------------------------------------*/
184 /*----------------------------------------------------------------------------*/
185 
186 static inline cs_real_t
188  const cs_real_t xb[3])
189 {
190  cs_real_t v[3];
191 
192  v[0] = xb[0] - xa[0];
193  v[1] = xb[1] - xa[1];
194  v[2] = xb[2] - xa[2];
195 
196  return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
197 }
198 
199 /*----------------------------------------------------------------------------*/
209 /*----------------------------------------------------------------------------*/
210 
211 static inline cs_real_t
213  const cs_real_t xb[3],
214  const cs_real_t xc[3])
215 {
216  return ((xb[0] - xa[0])*xc[0]+(xb[1] - xa[1])*xc[1]+(xb[2] - xa[2])*xc[2]);
217 }
218 
219 /*----------------------------------------------------------------------------*/
229 /*----------------------------------------------------------------------------*/
230 
231 static inline cs_real_t
233  const cs_real_t xb[3])
234 {
235  cs_real_t v[3] = {xb[0] - xa[0],
236  xb[1] - xa[1],
237  xb[2] - xa[2]};
238 
239  return (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
240 }
241 
242 /*----------------------------------------------------------------------------*/
251 /*----------------------------------------------------------------------------*/
252 
253 static inline cs_real_t
255  const cs_real_t v[3])
256 {
257  cs_real_t uv = u[0]*v[0] + u[1]*v[1] + u[2]*v[2];
258 
259  return uv;
260 }
261 
262 /*----------------------------------------------------------------------------*/
270 /*----------------------------------------------------------------------------*/
271 
272 static inline cs_real_t
274 {
275  return sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
276 }
277 
278 /*----------------------------------------------------------------------------*/
286 /*----------------------------------------------------------------------------*/
287 
288 static inline cs_real_t
290 {
291  cs_real_t v2 = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
292 
293  return v2;
294 }
295 
296 /*----------------------------------------------------------------------------*/
303 /*----------------------------------------------------------------------------*/
304 
305 static inline void
307  cs_real_t vout[restrict 3])
308 {
309  cs_real_t norm = cs_math_3_norm(vin);
310 
311  cs_real_t inv_norm = ((norm > cs_math_zero_threshold) ? 1. / norm : 0);
312 
313  vout[0] = inv_norm * vin[0];
314  vout[1] = inv_norm * vin[1];
315  vout[2] = inv_norm * vin[2];
316 }
317 
318 /*----------------------------------------------------------------------------*/
327 /*----------------------------------------------------------------------------*/
328 
329 static inline void
331  const cs_real_t v[3],
332  cs_real_t vout[restrict 3])
333 {
334  vout[0] = v[0]*(1.-n[0]*n[0])- v[1]* n[1]*n[0] - v[2]* n[2]*n[0];
335  vout[1] = -v[0]* n[0]*n[1] + v[1]*(1.-n[1]*n[1])- v[2]* n[2]*n[1];
336  vout[2] = -v[0]* n[0]*n[2] - v[1]* n[1]*n[2] + v[2]*(1.-n[2]*n[2]);
337 }
338 
339 /*----------------------------------------------------------------------------*/
348 /*----------------------------------------------------------------------------*/
349 
350 static inline void
352  const cs_real_t v[3],
353  cs_real_3_t mv)
354 {
355  mv[0] = m[0][0]*v[0] + m[0][1]*v[1] + m[0][2]*v[2];
356  mv[1] = m[1][0]*v[0] + m[1][1]*v[1] + m[1][2]*v[2];
357  mv[2] = m[2][0]*v[0] + m[2][1]*v[1] + m[2][2]*v[2];
358 }
359 
360 /*----------------------------------------------------------------------------*/
369 /*----------------------------------------------------------------------------*/
370 
371 static inline void
373  const cs_real_t v[3],
374  cs_real_3_t mv)
375 {
376  mv[0] += m[0][0]*v[0] + m[0][1]*v[1] + m[0][2]*v[2];
377  mv[1] += m[1][0]*v[0] + m[1][1]*v[1] + m[1][2]*v[2];
378  mv[2] += m[2][0]*v[0] + m[2][1]*v[1] + m[2][2]*v[2];
379 }
380 
381 /*----------------------------------------------------------------------------*/
390 /*----------------------------------------------------------------------------*/
391 
392 static inline void
394  const cs_real_t v[3],
395  cs_real_3_t mv)
396 {
397  mv[0] = m[0][0]*v[0] + m[1][0]*v[1] + m[2][0]*v[2];
398  mv[1] = m[0][1]*v[0] + m[1][1]*v[1] + m[2][1]*v[2];
399  mv[2] = m[0][2]*v[0] + m[1][2]*v[1] + m[2][2]*v[2];
400 }
401 
402 /*----------------------------------------------------------------------------*/
412 /*----------------------------------------------------------------------------*/
413 
414 static inline void
416  const cs_real_t v[3],
417  cs_real_t mv[restrict 3])
418 {
419  mv[0] = m[0] * v[0] + m[3] * v[1] + m[5] * v[2];
420  mv[1] = m[3] * v[0] + m[1] * v[1] + m[4] * v[2];
421  mv[2] = m[5] * v[0] + m[4] * v[1] + m[2] * v[2];
422 }
423 
424 /*----------------------------------------------------------------------------*/
434 /*----------------------------------------------------------------------------*/
435 
436 static inline void
438  const cs_real_t v[3],
439  cs_real_t mv[restrict 3])
440 {
441  mv[0] += m[0] * v[0] + m[3] * v[1] + m[5] * v[2];
442  mv[1] += m[3] * v[0] + m[1] * v[1] + m[4] * v[2];
443  mv[2] += m[5] * v[0] + m[4] * v[1] + m[2] * v[2];
444 }
445 
446 /*----------------------------------------------------------------------------*/
455 /*----------------------------------------------------------------------------*/
456 
457 static inline void
459  const cs_real_t v[6],
460  cs_real_t mv[restrict 6])
461 {
462  for (int i = 0; i < 6; i++) {
463  for (int j = 0; j < 6; j++)
464  mv[i] = m[i][j] * v[j];
465  }
466 }
467 
468 /*----------------------------------------------------------------------------*/
477 /*----------------------------------------------------------------------------*/
478 
479 static inline void
481  const cs_real_t v[6],
482  cs_real_t mv[restrict 6])
483 {
484  for (int i = 0; i < 6; i++) {
485  for (int j = 0; j < 6; j++)
486  mv[i] += m[i][j] * v[j];
487  }
488 }
489 
490 /*----------------------------------------------------------------------------*/
498 /*----------------------------------------------------------------------------*/
499 
500 static inline cs_real_t
502 {
503  const cs_real_t com0 = m[1][1]*m[2][2] - m[2][1]*m[1][2];
504  const cs_real_t com1 = m[2][1]*m[0][2] - m[0][1]*m[2][2];
505  const cs_real_t com2 = m[0][1]*m[1][2] - m[1][1]*m[0][2];
506 
507  return m[0][0]*com0 + m[1][0]*com1 + m[2][0]*com2;
508 }
509 
510 /*----------------------------------------------------------------------------*/
518 /*----------------------------------------------------------------------------*/
519 
520 static inline cs_real_t
522 {
523  const cs_real_t com0 = m[1]*m[2] - m[4]*m[4];
524  const cs_real_t com1 = m[4]*m[5] - m[3]*m[2];
525  const cs_real_t com2 = m[3]*m[4] - m[1]*m[5];
526 
527  return m[0]*com0 + m[3]*com1 + m[5]*com2;
528 }
529 
530 
531 /*----------------------------------------------------------------------------*/
539 /*----------------------------------------------------------------------------*/
540 
541 #if defined(__INTEL_COMPILER)
542 #pragma optimization_level 0 /* Bug with O1 or above with icc 15.0.1 20141023 */
543 #endif
544 
545 static inline void
547  const cs_real_t v[3],
548  cs_real_t uv[restrict 3])
549 {
550  uv[0] = u[1]*v[2] - u[2]*v[1];
551  uv[1] = u[2]*v[0] - u[0]*v[2];
552  uv[2] = u[0]*v[1] - u[1]*v[0];
553 }
554 
555 /*----------------------------------------------------------------------------*/
562 /*----------------------------------------------------------------------------*/
563 
564 static inline void
566  cs_real_t out[3][3])
567 {
568  out[0][0] = in[1][1]*in[2][2] - in[2][1]*in[1][2];
569  out[0][1] = in[2][1]*in[0][2] - in[0][1]*in[2][2];
570  out[0][2] = in[0][1]*in[1][2] - in[1][1]*in[0][2];
571 
572  out[1][0] = in[2][0]*in[1][2] - in[1][0]*in[2][2];
573  out[1][1] = in[0][0]*in[2][2] - in[2][0]*in[0][2];
574  out[1][2] = in[1][0]*in[0][2] - in[0][0]*in[1][2];
575 
576  out[2][0] = in[1][0]*in[2][1] - in[2][0]*in[1][1];
577  out[2][1] = in[2][0]*in[0][1] - in[0][0]*in[2][1];
578  out[2][2] = in[0][0]*in[1][1] - in[1][0]*in[0][1];
579 
580  const double det = in[0][0]*out[0][0]+in[1][0]*out[0][1]+in[2][0]*out[0][2];
581  const double invdet = 1/det;
582 
583  out[0][0] *= invdet, out[0][1] *= invdet, out[0][2] *= invdet;
584  out[1][0] *= invdet, out[1][1] *= invdet, out[1][2] *= invdet;
585  out[2][0] *= invdet, out[2][1] *= invdet, out[2][2] *= invdet;
586 }
587 
588 /*----------------------------------------------------------------------------*/
594 /*----------------------------------------------------------------------------*/
595 
596 static inline void
598 {
599  cs_real_t a00 = a[1][1]*a[2][2] - a[2][1]*a[1][2];
600  cs_real_t a01 = a[2][1]*a[0][2] - a[0][1]*a[2][2];
601  cs_real_t a02 = a[0][1]*a[1][2] - a[1][1]*a[0][2];
602  cs_real_t a10 = a[2][0]*a[1][2] - a[1][0]*a[2][2];
603  cs_real_t a11 = a[0][0]*a[2][2] - a[2][0]*a[0][2];
604  cs_real_t a12 = a[1][0]*a[0][2] - a[0][0]*a[1][2];
605  cs_real_t a20 = a[1][0]*a[2][1] - a[2][0]*a[1][1];
606  cs_real_t a21 = a[2][0]*a[0][1] - a[0][0]*a[2][1];
607  cs_real_t a22 = a[0][0]*a[1][1] - a[1][0]*a[0][1];
608 
609  double det_inv = 1. / (a[0][0]*a00 + a[1][0]*a01 + a[2][0]*a02);
610 
611  a[0][0] = a00 * det_inv;
612  a[0][1] = a01 * det_inv;
613  a[0][2] = a02 * det_inv;
614  a[1][0] = a10 * det_inv;
615  a[1][1] = a11 * det_inv;
616  a[1][2] = a12 * det_inv;
617  a[2][0] = a20 * det_inv;
618  a[2][1] = a21 * det_inv;
619  a[2][2] = a22 * det_inv;
620 }
621 
622 /*----------------------------------------------------------------------------*/
629 /*----------------------------------------------------------------------------*/
630 
631 static inline void
633 {
634  cs_real_t a00 = a[1][1]*a[2][2] - a[2][1]*a[1][2];
635  cs_real_t a01 = a[2][1]*a[0][2] - a[0][1]*a[2][2];
636  cs_real_t a02 = a[0][1]*a[1][2] - a[1][1]*a[0][2];
637  cs_real_t a11 = a[0][0]*a[2][2] - a[2][0]*a[0][2];
638  cs_real_t a12 = a[1][0]*a[0][2] - a[0][0]*a[1][2];
639  cs_real_t a22 = a[0][0]*a[1][1] - a[1][0]*a[0][1];
640 
641  double det_inv = 1. / (a[0][0]*a00 + a[1][0]*a01 + a[2][0]*a02);
642 
643  a[0][0] = a00 * det_inv;
644  a[0][1] = a01 * det_inv;
645  a[0][2] = a02 * det_inv;
646  a[1][0] = a01 * det_inv;
647  a[1][1] = a11 * det_inv;
648  a[1][2] = a12 * det_inv;
649  a[2][0] = a02 * det_inv;
650  a[2][1] = a12 * det_inv;
651  a[2][2] = a22 * det_inv;
652 }
653 
654 /*----------------------------------------------------------------------------*/
664 /*----------------------------------------------------------------------------*/
665 
666 static inline void
668  cs_real_t sout[restrict 6])
669 {
670  double detinv;
671 
672  sout[0] = s[1]*s[2] - s[4]*s[4];
673  sout[1] = s[0]*s[2] - s[5]*s[5];
674  sout[2] = s[0]*s[1] - s[3]*s[3];
675  sout[3] = s[4]*s[5] - s[3]*s[2];
676  sout[4] = s[3]*s[5] - s[0]*s[4];
677  sout[5] = s[3]*s[4] - s[1]*s[5];
678 
679  detinv = 1. / (s[0]*sout[0] + s[3]*sout[3] + s[5]*sout[5]);
680 
681  sout[0] *= detinv;
682  sout[1] *= detinv;
683  sout[2] *= detinv;
684  sout[3] *= detinv;
685  sout[4] *= detinv;
686  sout[5] *= detinv;
687 }
688 
689 /*----------------------------------------------------------------------------*/
702 /*----------------------------------------------------------------------------*/
703 
704 static inline void
706  const cs_real_t s2[6],
707  cs_real_t sout[restrict 6])
708 {
709  /* S11 */
710  sout[0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
711  /* S22 */
712  sout[1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
713  /* S33 */
714  sout[2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
715  /* S12 = S21 */
716  sout[3] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
717  /* S23 = S32 */
718  sout[4] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
719  /* S13 = S31 */
720  sout[5] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
721 }
722 
723 /*----------------------------------------------------------------------------*/
731 /*----------------------------------------------------------------------------*/
732 
733 static inline void
735  cs_real_t sout[restrict 6][6])
736 {
737  int tens2vect[3][3];
738  int iindex[6], jindex[6];
739 
740  tens2vect[0][0] = 0; tens2vect[0][1] = 3; tens2vect[0][2] = 5;
741  tens2vect[1][0] = 3; tens2vect[1][1] = 1; tens2vect[1][2] = 4;
742  tens2vect[2][0] = 5; tens2vect[2][1] = 4; tens2vect[2][2] = 2;
743 
744  iindex[0] = 0; iindex[1] = 1; iindex[2] = 2;
745  iindex[3] = 0; iindex[4] = 1; iindex[5] = 0;
746 
747  jindex[0] = 0; jindex[1] = 1; jindex[2] = 2;
748  jindex[3] = 1; jindex[4] = 2; jindex[5] = 2;
749 
750  /* Consider : W = R*s^t + s*R.
751  * W_ij = Sum_{k<3} [s_jk*r_ik + s_ik*r_jk]
752  * We look for A such as A*R = W
753  */
754  for (int i = 0; i < 6; i++) {
755  int ii = iindex[i];
756  int jj = jindex[i];
757  for (int k = 0; k < 3; k++) {
758  int ik = tens2vect[k][ii];
759  int jk = tens2vect[k][jj];
760 
761  sout[ik][i] += s[k][jj];
762 
763  sout[jk][i] += s[k][ii];
764  }
765  }
766 }
767 
768 /*----------------------------------------------------------------------------*/
780 /*----------------------------------------------------------------------------*/
781 
782 static inline void
784  const cs_real_t s2[6],
785  const cs_real_t s3[6],
786  cs_real_t sout[restrict 3][3])
787 {
788  cs_real_33_t _sout;
789 
790  /* S11 */
791  _sout[0][0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
792  /* S22 */
793  _sout[1][1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
794  /* S33 */
795  _sout[2][2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
796  /* S12 */
797  _sout[0][1] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
798  /* S21 */
799  _sout[1][0] = s2[0]*s1[3] + s2[3]*s1[1] + s2[5]*s1[4];
800  /* S23 */
801  _sout[1][2] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
802  /* S32 */
803  _sout[2][1] = s2[3]*s1[5] + s2[1]*s1[4] + s2[4]*s1[2];
804  /* S13 */
805  _sout[0][2] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
806  /* S31 */
807  _sout[2][0] = s2[0]*s1[5] + s2[3]*s1[4] + s2[5]*s1[2];
808 
809  sout[0][0] = _sout[0][0]*s3[0] + _sout[0][1]*s3[3] + _sout[0][2]*s3[5];
810  /* S22 */
811  sout[1][1] = _sout[1][0]*s3[3] + _sout[1][1]*s3[1] + _sout[1][2]*s3[4];
812  /* S33 */
813  sout[2][2] = _sout[2][0]*s3[5] + _sout[2][1]*s3[4] + _sout[2][2]*s3[2];
814  /* S12 */
815  sout[0][1] = _sout[0][0]*s3[3] + _sout[0][1]*s3[1] + _sout[0][2]*s3[4];
816  /* S21 */
817  sout[1][0] = s3[0]*_sout[1][0] + s3[3]*_sout[1][1] + s3[5]*_sout[1][2];
818  /* S23 */
819  sout[1][2] = _sout[1][0]*s3[5] + _sout[1][1]*s3[4] + _sout[1][2]*s3[2];
820  /* S32 */
821  sout[2][1] = s3[3]*_sout[2][0] + s3[1]*_sout[2][1] + s3[4]*_sout[2][2];
822  /* S13 */
823  sout[0][2] = _sout[0][0]*s3[5] + _sout[0][1]*s3[4] + _sout[0][2]*s3[2];
824  /* S31 */
825  sout[2][0] = s3[0]*_sout[2][0] + s3[3]*_sout[2][1] + s3[5]*_sout[2][2];
826 }
827 
828 /*----------------------------------------------------------------------------*/
835 /*----------------------------------------------------------------------------*/
836 
837 static inline void
839  cs_nvec3_t *qv)
840 {
841  cs_real_t magnitude = sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
842 
843  qv->meas = magnitude;
844  if (fabs(magnitude) > cs_math_zero_threshold) {
845 
846  const cs_real_t inv = 1/magnitude;
847  qv->unitv[0] = inv * v[0];
848  qv->unitv[1] = inv * v[1];
849  qv->unitv[2] = inv * v[2];
850 
851  }
852  else
853  qv->unitv[0] = qv->unitv[1] = qv->unitv[2] = 0;
854 
855 }
856 
857 /*=============================================================================
858  * Public function prototypes
859  *============================================================================*/
860 
861 /*----------------------------------------------------------------------------*/
865 /*----------------------------------------------------------------------------*/
866 
867 void
869 
870 /*----------------------------------------------------------------------------*/
874 /*----------------------------------------------------------------------------*/
875 
876 double
878 
879 /*----------------------------------------------------------------------------*/
889 /*----------------------------------------------------------------------------*/
890 
891 void
893  const cs_real_t xb[3],
894  cs_real_t *len,
895  cs_real_3_t unitv);
896 
897 /*----------------------------------------------------------------------------*/
909 /*----------------------------------------------------------------------------*/
910 
911 void
913  cs_real_t eig_vals[3]);
914 
915 /*----------------------------------------------------------------------------*/
928 /*----------------------------------------------------------------------------*/
929 
930 void
931 cs_math_33_eigen(const cs_real_t m[3][3],
932  cs_real_t *eig_ratio,
933  cs_real_t *eig_max);
934 
935 /*----------------------------------------------------------------------------*/
946 /*----------------------------------------------------------------------------*/
947 
948 double
949 cs_math_surftri(const cs_real_t xv[3],
950  const cs_real_t xe[3],
951  const cs_real_t xf[3]);
952 
953 /*----------------------------------------------------------------------------*/
965 /*----------------------------------------------------------------------------*/
966 
967 double
968 cs_math_voltet(const cs_real_t xv[3],
969  const cs_real_t xe[3],
970  const cs_real_t xf[3],
971  const cs_real_t xc[3]);
972 
973 /*----------------------------------------------------------------------------*/
983 /*----------------------------------------------------------------------------*/
984 
985 void
986 cs_math_fact_lu(cs_lnum_t n_blocks,
987  const int b_size,
988  const cs_real_t *a,
989  cs_real_t *a_lu);
990 
991 /*----------------------------------------------------------------------------*/
1001 /*----------------------------------------------------------------------------*/
1002 
1003 void
1004 cs_math_fw_and_bw_lu(const cs_real_t a_lu[],
1005  const int n,
1006  cs_real_t x[],
1007  const cs_real_t b[]);
1008 
1009 /*----------------------------------------------------------------------------*/
1010 
1012 
1013 #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&#39;s rule.
Definition: cs_math.h:667
Definition: cs_field_pointer.h:70
integer, save ik
Definition: numvar.f90:75
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:212
#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:254
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
size_t len
Definition: mei_scanner.c:569
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:306
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:437
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:458
static cs_real_t cs_math_pow3(cs_real_t x)
Compute the cube of a real value.
Definition: cs_math.h:153
static void cs_math_33_inv_cramer_in_place(cs_real_t a[3][3])
Inverse a 3x3 matrix in place, using Cramer&#39;s rule.
Definition: cs_math.h:597
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:351
const cs_real_t cs_math_pi
#define BEGIN_C_DECLS
Definition: cs_defs.h:461
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:537
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:521
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:187
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:300
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:783
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
Definition: cs_defs.h:337
Definition: cs_field_pointer.h:68
const cs_real_t cs_math_one24
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:289
static cs_real_t cs_math_sq(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:121
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:420
double precision, dimension(:,:,:), allocatable v
Definition: atimbr.f90:114
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:705
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:480
double cs_math_get_machine_epsilon(void)
Get the value related to the machine precision.
Definition: cs_math.c:195
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&#39;s rule...
Definition: cs_math.h:632
void cs_math_set_machine_epsilon(void)
Compute the value related to the machine precision.
Definition: cs_math.c:174
static cs_real_t cs_math_pow2(cs_real_t x)
Compute the square of a real value.
Definition: cs_math.h:137
double precision, save a
Definition: cs_fuel_incl.f90:146
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:450
double meas
Definition: cs_defs.h:339
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:215
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:501
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:273
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:565
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:309
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:330
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:546
static void cs_math_33_3_product_add(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 add.
Definition: cs_math.h:372
const cs_real_t cs_math_zero_threshold
double unitv[3]
Definition: cs_defs.h:340
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:169
static int cs_math_binom(short int n, short int k)
Computes the binomial coefficient of n and k.
Definition: cs_math.h:91
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:232
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:838
#define END_C_DECLS
Definition: cs_defs.h:462
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:393
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:415
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:387
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:479
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:734
double precision, save b
Definition: cs_fuel_incl.f90:146