VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
MathUtil.hpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
32#ifndef MATHUTIL_H
33#define MATHUTIL_H
34
35#include <math.h>
36#include "muParser.h"
37
38namespace utilities
39{
40 static bool isEven( int integer )
41 {
42 if ( integer % 2 == 0 )
43 return true;
44 else
45 return false;
46 }
47
48 static bool isOdd( int integer )
49 {
50 if ( integer % 2 != 0 )
51 return true;
52 else
53 return false;
54 }
55
56 //convert from real to int
57 static int cint(real x)
58 {
60 if (modf(x,&intpart)>=.5)
61 return static_cast<int> (floor(x)+1);
62 else
63 return static_cast<int> (floor(x));
64 }
65
66 //create new mu parser for duct parabolic profile
67 //inflow in X
68 static mu::Parser getDuctParaboloidX(real Cy, real Hy, real Cz, real Hz, real V)
69 {
70 mu::Parser fct;
71 fct.SetExpr("V*(((-(x2-Cy)^2.0+(Hy/2.0)^2.0)/(Hy/2.0)^2.0)*((-(x3-Cz)^2.0+(Hz/2.0)^2.0)/(Hz/2.0)^2.0))" );
72 fct.DefineConst("Cy", Cy);
73 fct.DefineConst("Hy", Hy);
74 fct.DefineConst("Cz", Cz);
75 fct.DefineConst("Hz", Hz);
76 fct.DefineConst("V" , V );
77 return fct;
78 }
79 //inflow in Y
80 static mu::Parser getDuctParaboloidY(real Cx, real Hx, real Cz, real Hz, real V)
81 {
82 mu::Parser fct;
83 fct.SetExpr("V*(((-(x1-Cx)^2.0+(Hx/2.0)^2.0)/(Hx/2.0)^2.0)*((-(x3-Cz)^2.0+(Hz/2.0)^2.0)/(Hz/2.0)^2.0))" );
84 fct.DefineConst("Cx", Cx);
85 fct.DefineConst("Hx", Hx);
86 fct.DefineConst("Cz", Cz);
87 fct.DefineConst("Hz", Hz);
88 fct.DefineConst("V" , V );
89 return fct;
90 }
91 //inflow in Z
92 static mu::Parser getDuctParaboloidZ(real Cx, real Hx, real Cy, real Hy, real V)
93 {
94 mu::Parser fct;
95 fct.SetExpr("V*(((-(x1-Cx)^2.0+(Hx/2.0)^2.0)/(Hx/2.0)^2.0)*((-(x2-Cy)^2.0+(Hy/2.0)^2.0)/(Hy/2.0)^2.0))" );
96 fct.DefineConst("Cx", Cx);
97 fct.DefineConst("Hx", Hx);
98 fct.DefineConst("Cy", Cy);
99 fct.DefineConst("Hy", Hy);
100 fct.DefineConst("V" , V );
101 return fct;
102 }
103 //hash function
104 static unsigned int RSHash(const std::string& str)
105 {
106 unsigned int b = 378551;
107 unsigned int a = 63689;
108 unsigned int hash = 0;
109
110 for(std::size_t i = 0; i < str.length(); i++)
111 {
112 hash = hash * a + str[i];
113 a = a * b;
114 }
115
116 return hash;
117 }
118 //linear interpolation
119 static real linear_interpolation1D(real x0, real y0, real x1, real y1, real x)
120 {
121 real a = (y1 - y0) / (x1 - x0);
122 real b = -a*x0 + y0;
123 real y = a * x + b;
124 return y;
125 }
126}
127
128#endif
129
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43