programmer's documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups 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-2014 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 /*----------------------------------------------------------------------------
31  * Local headers
32  *----------------------------------------------------------------------------*/
33 
34 #include "cs_defs.h"
35 
36 /*----------------------------------------------------------------------------*/
37 
39 
40 /*=============================================================================
41  * Local Macro definitions
42  *============================================================================*/
43 
44 /*============================================================================
45  * Type definition
46  *============================================================================*/
47 
48 /*============================================================================
49  * Global variables
50  *============================================================================*/
51 
52 /*============================================================================
53  * Public function prototypes for Fortran API
54  *============================================================================*/
55 
56 /*----------------------------------------------------------------------------
57  * Wrapper to cs_math_sym_33_inv_cramer
58  *----------------------------------------------------------------------------*/
59 
60 void CS_PROCF (symmetric_matrix_inverse, SYMMETRIC_MATRIX_INVERSE)
61 (
62  cs_real_6_t sout,
63  const cs_real_6_t s
64 );
65 
66 /*----------------------------------------------------------------------------
67  * Wrapper to cs_math_sym_33_product
68  *----------------------------------------------------------------------------*/
69 
70 void CS_PROCF (symmetric_matrix_product, SYMMETRIC_MATRIX_PRODUCT)
71 (
72  cs_real_6_t sout,
73  const cs_real_6_t s1,
74  const cs_real_6_t s2
75 );
76 
77 /*=============================================================================
78  * Public function prototypes
79  *============================================================================*/
80 
81 /*----------------------------------------------------------------------------*/
91 /*----------------------------------------------------------------------------*/
92 
93 static inline void
94 cs_math_33_3_product(cs_real_33_t m,
95  const cs_real_3_t v,
96  cs_real_3_t mv)
97 {
98  for (int ii = 0; ii < 3; ii++)
99  mv[ii] = m[ii][0] * v[0] + m[ii][1] * v[1] + m[ii][2] * v[2];
100 }
101 
102 /*----------------------------------------------------------------------------*/
111 /*----------------------------------------------------------------------------*/
112 
113 static inline cs_real_t
114 cs_math_3_dot_product(const cs_real_3_t u, const cs_real_3_t v)
115 {
116  cs_real_t uv = 0.;
117 
118  for (int ii = 0; ii < 3; ii++)
119  uv += u[ii]*v[ii];
120 
121  return uv;
122 }
123 
124 /*----------------------------------------------------------------------------*/
132 /*----------------------------------------------------------------------------*/
133 
134 static inline cs_real_t
135 cs_math_3_square_norm(const cs_real_3_t v)
136 {
137  cs_real_t v2 = 0.;
138 
139  for (int ii = 0; ii < 3; ii++)
140  v2 += v[ii]*v[ii];
141 
142  return v2;
143 }
144 
145 /*----------------------------------------------------------------------------*/
152 /*----------------------------------------------------------------------------*/
153 
154 static inline void
155 cs_math_sym_33_inv_cramer(cs_real_6_t sout,
156  const cs_real_6_t s)
157 {
158  double detinv;
159 
160  sout[0] = s[1]*s[2] - s[4]*s[4];
161  sout[1] = s[0]*s[2] - s[5]*s[5];
162  sout[2] = s[0]*s[1] - s[3]*s[3];
163  sout[3] = s[4]*s[5] - s[3]*s[2];
164  sout[4] = s[3]*s[5] - s[0]*s[4];
165  sout[5] = s[3]*s[4] - s[1]*s[5];
166 
167  detinv = 1. / (s[0]*sout[0] + s[3]*sout[3] + s[5]*sout[5]);
168 
169  sout[0] = sout[0] * detinv;
170  sout[1] = sout[1] * detinv;
171  sout[2] = sout[2] * detinv;
172  sout[3] = sout[3] * detinv;
173  sout[4] = sout[4] * detinv;
174  sout[5] = sout[5] * detinv;
175 }
176 
177 /*----------------------------------------------------------------------------*/
185 /*----------------------------------------------------------------------------*/
186 
187 static inline void
188 cs_math_sym_33_product(cs_real_6_t sout,
189  const cs_real_6_t s1,
190  const cs_real_6_t s2)
191 {
192  /* S11 */
193  sout[0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
194  /* S22 */
195  sout[1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
196  /* S33 */
197  sout[2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
198  /* S12 = S21 */
199  sout[3] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
200  /* S23 = S32 */
201  sout[4] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
202  /* S13 = S31 */
203  sout[5] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
204 }
205 
206 /*----------------------------------------------------------------------------*/
207 
209 
210 #endif /* __CS_MATH_H__ */
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:309
BEGIN_C_DECLS void symmetric_matrix_inverse(cs_real_6_t sout, const cs_real_6_t s)
Definition: cs_math.c:91
#define BEGIN_C_DECLS
Definition: cs_defs.h:405
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:307
void symmetric_matrix_product(cs_real_6_t sout, const cs_real_6_t s1, const cs_real_6_t s2)
Definition: cs_math.c:105
#define END_C_DECLS
Definition: cs_defs.h:406
double cs_real_t
Definition: cs_defs.h:296
#define CS_PROCF(x, y)
Definition: cs_defs.h:419
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:311