Flow123d  3.9.0-454df51df
math_fce.h
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file math_fce.h
15  * @brief
16  */
17 
18 #ifndef MATH_H
19 #define MATH_H
20 
21 // TODO: Only mh_fe_values depends on this file. This file can be removed.
22 
23 //! small matrix types
24 typedef double SmallVec1_t[1];
25 typedef double SmallVec2_t[2];
26 typedef double SmallVec3_t[3];
27 typedef double SmallVec4_t[4];
28 
33 
34 
35 //! Numerical helpers
36 #include <float.h>
37 // DBL_MIN approx.= 2.22507e-308, least nonzero double
38 
39 // this should be used when we want to keep first digit nonzero
40 // such number have full double precision, smaller numbers loose precision
41 #define NUM_ZERO DBL_MIN/DBL_EPSILON
42 
43 // each use of ESP(value) indicate that we use some small value
44 // this small value should be relative to the number we want to compare
45 #define EPS(value) (value)
46 
47 // OBSOLETE
48 #define ZERO EPS(1e-12)
49 
50 #define DBL_EQ(i,j) (fabs((i)-(j))<NUM_ZERO)
51 #define DBL_GE(i,j) ((i)>(j)-NUM_ZERO)
52 #define DBL_LE(i,j) ((i)<(j)+NUM_ZERO)
53 #define DBL_GT(i,j) ((i)>(j)+NUM_ZERO)
54 #define DBL_LT(i,j) ((i)<(j)-NUM_ZERO)
55 
56 //! Usefull math macros
57 #define SQUARE(x) ((x) * (x))
58 #define SGN(x) ( ((x)>ZERO)? (1) : ( ((x)<(-ZERO))? (-1) : (0) ) )
59 #define SUBDET2(i,j,k,l) (a[(i)][(k)]*a[(j)][(l)]-a[(i)][(l)]*a[(j)][(k)])
60 #ifndef M_PI
61  #define M_PI 3.14159265358979323846264338327950288f
62 #endif
63 
64 // vector functions
65 double vector_length(double[]);
66 double scalar_product(double[],double[]);
67 void normalize_vector(double[]);
68 void scale_vector(double[],double);
69 
70 void vector_product(double[],double[],double[]);
71 void vector_difference(double[],double[],double[]);
72 // small matrix operations
73 double Det3( SmallMtx3 a);
74 double MatrixInverse(double *a,double *b,int size);
75 void PrintSmallMatrix(double *mtx, int size );
76 #endif
77 //-----------------------------------------------------------------------------
78 // vim: set cindent:
SmallVec1_t
double SmallVec1_t[1]
small matrix types
Definition: math_fce.h:24
vector_difference
void vector_difference(double[], double[], double[])
Definition: math_fce.cc:80
SmallVec4_t
double SmallVec4_t[4]
Definition: math_fce.h:27
SmallMtx4
SmallVec4_t * SmallMtx4
Definition: math_fce.h:32
normalize_vector
void normalize_vector(double[])
Definition: math_fce.cc:48
scale_vector
void scale_vector(double[], double)
Definition: math_fce.cc:60
SmallMtx1
SmallVec1_t * SmallMtx1
Definition: math_fce.h:29
MatrixInverse
double MatrixInverse(double *a, double *b, int size)
Definition: math_fce.cc:104
PrintSmallMatrix
void PrintSmallMatrix(double *mtx, int size)
Definition: math_fce.cc:214
SmallMtx3
SmallVec3_t * SmallMtx3
Definition: math_fce.h:31
vector_product
void vector_product(double[], double[], double[])
Definition: math_fce.cc:68
Det3
double Det3(SmallMtx3 a)
Definition: math_fce.cc:94
scalar_product
double scalar_product(double[], double[])
Definition: math_fce.cc:41
SmallMtx2
SmallVec2_t * SmallMtx2
Definition: math_fce.h:30
SmallVec2_t
double SmallVec2_t[2]
Definition: math_fce.h:25
SmallVec3_t
double SmallVec3_t[3]
Definition: math_fce.h:26
vector_length
double vector_length(double[])
Definition: math_fce.cc:34