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-2016 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  const cs_real_6_t s,
63  cs_real_6_t sout
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  const cs_real_6_t s1,
73  const cs_real_6_t s2,
74  cs_real_6_t sout
75 );
76 
77 /*=============================================================================
78  * Public function prototypes
79  *============================================================================*/
80 
81 /*----------------------------------------------------------------------------*/
91 /*----------------------------------------------------------------------------*/
92 
93 static inline void
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 
103 /*----------------------------------------------------------------------------*/
114 /*----------------------------------------------------------------------------*/
115 
116 static inline void
118  const cs_real_3_t v,
119  cs_real_3_t mv)
120 {
121  mv[0] = m[0] * v[0] + m[3] * v[1] + m[5] * v[2];
122  mv[1] = m[3] * v[0] + m[1] * v[1] + m[4] * v[2];
123  mv[2] = m[5] * v[0] + m[4] * v[1] + m[2] * v[2];
124 }
125 
126 /*----------------------------------------------------------------------------*/
135 /*----------------------------------------------------------------------------*/
136 
137 static inline cs_real_t
139 {
140  cs_real_t uv = 0.;
141 
142  for (int ii = 0; ii < 3; ii++)
143  uv += u[ii]*v[ii];
144 
145  return uv;
146 }
147 
148 /*----------------------------------------------------------------------------*/
156 /*----------------------------------------------------------------------------*/
157 
158 static inline cs_real_t
160 {
161  cs_real_t v2 = 0.;
162 
163  for (int ii = 0; ii < 3; ii++)
164  v2 += v[ii]*v[ii];
165 
166  return v2;
167 }
168 
169 /*----------------------------------------------------------------------------*/
177 /*----------------------------------------------------------------------------*/
178 
179 static inline void
181  cs_real_6_t sout)
182 {
183  double detinv;
184 
185  sout[0] = s[1]*s[2] - s[4]*s[4];
186  sout[1] = s[0]*s[2] - s[5]*s[5];
187  sout[2] = s[0]*s[1] - s[3]*s[3];
188  sout[3] = s[4]*s[5] - s[3]*s[2];
189  sout[4] = s[3]*s[5] - s[0]*s[4];
190  sout[5] = s[3]*s[4] - s[1]*s[5];
191 
192  detinv = 1. / (s[0]*sout[0] + s[3]*sout[3] + s[5]*sout[5]);
193 
194  sout[0] = sout[0] * detinv;
195  sout[1] = sout[1] * detinv;
196  sout[2] = sout[2] * detinv;
197  sout[3] = sout[3] * detinv;
198  sout[4] = sout[4] * detinv;
199  sout[5] = sout[5] * detinv;
200 }
201 
202 /*----------------------------------------------------------------------------*/
211 /*----------------------------------------------------------------------------*/
212 
213 static inline void
215  const cs_real_6_t s2,
216  cs_real_6_t sout)
217 {
218  /* S11 */
219  sout[0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
220  /* S22 */
221  sout[1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
222  /* S33 */
223  sout[2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
224  /* S12 = S21 */
225  sout[3] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
226  /* S23 = S32 */
227  sout[4] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
228  /* S13 = S31 */
229  sout[5] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
230 }
231 
232 /*----------------------------------------------------------------------------*/
233 
235 
236 #endif /* __CS_MATH_H__ */
void symmetric_matrix_inverse(const cs_real_6_t s, cs_real_6_t sout)
Definition: cs_math.c:92
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:309
void symmetric_matrix_product(const cs_real_6_t s1, const cs_real_6_t s2, cs_real_6_t sout)
Definition: cs_math.c:106
#define BEGIN_C_DECLS
Definition: cs_defs.h:419
double precision, dimension(:,:,:), allocatable v
Definition: atimbr.f90:108
Definition: cs_field_pointer.h:67
static cs_real_t cs_math_3_square_norm(const cs_real_3_t v)
Compute the square norm of a vector of 3 real values.
Definition: cs_math.h:159
static cs_real_t cs_math_3_dot_product(const cs_real_3_t u, const cs_real_3_t v)
Compute the dot product of two vectors of 3 real values.
Definition: cs_math.h:138
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:307
static void cs_math_sym_33_inv_cramer(const cs_real_6_t s, cs_real_6_t sout)
Compute the inverse of a symmetric matrix using Cramer&#39;s rule. NB: Symmetric matrix are stored as fol...
Definition: cs_math.h:180
static void cs_math_33_3_product(const cs_real_33_t m, const cs_real_3_t v, 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:94
#define END_C_DECLS
Definition: cs_defs.h:420
double cs_real_t
Definition: cs_defs.h:296
static void cs_math_sym_33_product(const cs_real_6_t s1, const cs_real_6_t s2, cs_real_6_t sout)
Compute the product of two symmetric matrices. NB: Symmetric matrix are stored as follows (s11...
Definition: cs_math.h:214
#define CS_PROCF(x, y)
Definition: cs_defs.h:433
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:311
static void cs_math_sym_33_3_product(const cs_real_6_t m, const cs_real_3_t v, cs_real_3_t mv)
Compute the product of a symmetric matrix of 3x3 real values by a vector of 3 real values...
Definition: cs_math.h:117