/usr/include/code_saturne/cs_math.h is in code-saturne-include 3.3.2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | #ifndef __CS_MATH_H__
#define __CS_MATH_H__
/*============================================================================
* Mathematical base functions.
*============================================================================*/
/*
This file is part of Code_Saturne, a general-purpose CFD tool.
Copyright (C) 1998-2014 EDF S.A.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
* Local headers
*----------------------------------------------------------------------------*/
#include "cs_defs.h"
/*----------------------------------------------------------------------------*/
BEGIN_C_DECLS
/*=============================================================================
* Local Macro definitions
*============================================================================*/
/*============================================================================
* Type definition
*============================================================================*/
/*============================================================================
* Global variables
*============================================================================*/
/*============================================================================
* Public function prototypes for Fortran API
*============================================================================*/
/*----------------------------------------------------------------------------
* Wrapper to cs_math_sym_33_inv_cramer
*----------------------------------------------------------------------------*/
void CS_PROCF (symmetric_matrix_inverse, SYMMETRIC_MATRIX_INVERSE)
(
cs_real_6_t sout,
const cs_real_6_t s
);
/*----------------------------------------------------------------------------
* Wrapper to cs_math_sym_33_product
*----------------------------------------------------------------------------*/
void CS_PROCF (symmetric_matrix_product, SYMMETRIC_MATRIX_PRODUCT)
(
cs_real_6_t sout,
const cs_real_6_t s1,
const cs_real_6_t s2
);
/*=============================================================================
* Public function prototypes
*============================================================================*/
/*----------------------------------------------------------------------------*/
/*!
* \brief Compute the product of a matrix of 3x3 real values by a vector of 3
* real values.
*
* \param[in] m matrix of 3x3 real values
* \param[in] v vector of 3 real values
*
* \return the result matrix vector product m.v.
*/
/*----------------------------------------------------------------------------*/
static inline void
cs_math_33_3_product(cs_real_33_t m,
const cs_real_3_t v,
cs_real_3_t mv)
{
for (int ii = 0; ii < 3; ii++)
mv[ii] = m[ii][0] * v[0] + m[ii][1] * v[1] + m[ii][2] * v[2];
}
/*----------------------------------------------------------------------------*/
/*!
* \brief Compute the dot product of two vectors of 3 real values.
*
* \param[in] u vector of 3 real values
* \param[in] v vector of 3 real values
*
* \return the resulting dot product u.v.
*/
/*----------------------------------------------------------------------------*/
static inline cs_real_t
cs_math_3_dot_product(const cs_real_3_t u, const cs_real_3_t v)
{
cs_real_t uv = 0.;
for (int ii = 0; ii < 3; ii++)
uv += u[ii]*v[ii];
return uv;
}
/*----------------------------------------------------------------------------*/
/*!
* \brief Compute the square norm of a vector of 3 real values.
*
* \param[in] v vector of 3 real values
*
* \return square norm of v.
*/
/*----------------------------------------------------------------------------*/
static inline cs_real_t
cs_math_3_square_norm(const cs_real_3_t v)
{
cs_real_t v2 = 0.;
for (int ii = 0; ii < 3; ii++)
v2 += v[ii]*v[ii];
return v2;
}
/*----------------------------------------------------------------------------*/
/*!
* \brief Compute the inverse of a symmetric matrix using Cramer's rule.
*
* \param[out] sout sout = s1 * s2
* \param[in] s symmetric matrix
*/
/*----------------------------------------------------------------------------*/
static inline void
cs_math_sym_33_inv_cramer(cs_real_6_t sout,
const cs_real_6_t s)
{
double detinv;
sout[0] = s[1]*s[2] - s[4]*s[4];
sout[1] = s[0]*s[2] - s[5]*s[5];
sout[2] = s[0]*s[1] - s[3]*s[3];
sout[3] = s[4]*s[5] - s[3]*s[2];
sout[4] = s[3]*s[5] - s[0]*s[4];
sout[5] = s[3]*s[4] - s[1]*s[5];
detinv = 1. / (s[0]*sout[0] + s[3]*sout[3] + s[5]*sout[5]);
sout[0] = sout[0] * detinv;
sout[1] = sout[1] * detinv;
sout[2] = sout[2] * detinv;
sout[3] = sout[3] * detinv;
sout[4] = sout[4] * detinv;
sout[5] = sout[5] * detinv;
}
/*----------------------------------------------------------------------------*/
/*!
* \brief Compute the product of two symmetric matrices.
*
* \param[out] sout sout = s1 * s2
* \param[in] s1 symmetric matrix
* \param[in] s2 symmetric matrix
*/
/*----------------------------------------------------------------------------*/
static inline void
cs_math_sym_33_product(cs_real_6_t sout,
const cs_real_6_t s1,
const cs_real_6_t s2)
{
/* S11 */
sout[0] = s1[0]*s2[0] + s1[3]*s2[3] + s1[5]*s2[5];
/* S22 */
sout[1] = s1[3]*s2[3] + s1[1]*s2[1] + s1[4]*s2[4];
/* S33 */
sout[2] = s1[5]*s2[5] + s1[4]*s2[4] + s1[2]*s2[2];
/* S12 = S21 */
sout[3] = s1[0]*s2[3] + s1[3]*s2[1] + s1[5]*s2[4];
/* S23 = S32 */
sout[4] = s1[3]*s2[5] + s1[1]*s2[4] + s1[4]*s2[2];
/* S13 = S31 */
sout[5] = s1[0]*s2[5] + s1[3]*s2[4] + s1[5]*s2[2];
}
/*----------------------------------------------------------------------------*/
END_C_DECLS
#endif /* __CS_MATH_H__ */
|