OpenLB 1.7
Loading...
Searching...
No Matches
finiteDifference.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2006, 2007 Jonas Latt
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef FINITE_DIFFERENCE_H
25#define FINITE_DIFFERENCE_H
26
27namespace olb {
28
29namespace fd {
30
31// -------------------- First derivatives -------------------------------------
32
34template<typename T>
35constexpr T centralGradient(T u_p1, T u_m1) any_platform
36{
37 return (u_p1 - u_m1) / T{2};
38}
39
41template<typename T>
42constexpr T boundaryGradient(T u_0, T u_1, T u_2) any_platform
43{
44 return (-T{3}*u_0 + T{4}*u_1 - T{1}*u_2) / T{2};
45}
46
48template<typename T>
49constexpr T FSGradient(T u_0, T u_1, T u_2)
50{
51 return boundaryGradient(u_0, u_1, u_2);
52}
53
55template<typename T>
56constexpr T BSGradient(T u_0, T u_1, T u_2)
57{
58 return T{-1} * boundaryGradient(u_0, u_1, u_2);
59}
60
62template<typename T>
63constexpr T boundaryZeroGradient(T u_1, T u_2)
64{
65 return T{4}/T{3}*u_1 - T{1}/T{3}*u_2;
66}
67
68
69// -------------------- Second derivatives ------------------------------------
70// cf. Abramowitz, Stegun: Handbook of Mathematical Functions, 1964, p. 884
71
73template<typename T>
74constexpr T centralSecondDeriv(T u_m1, T u_0, T u_p1) any_platform
75{
76 return u_m1 - T{2}*u_0 + u_p1;
77}
78
80template<typename T>
81constexpr T centralSecondDeriv(T u_m2, T u_m1, T u_0, T u_p1, T u_p2) any_platform
82{
83 return (- u_m2 + T{16}*u_m1 - T{30}*u_0 + T{16}*u_p1 - u_p2) / T{12};
84}
85
86
87// -------------------- Interpolation -----------------------------------------
88
89
91template<typename T>
92constexpr T linearInterpolate(T u_0, T u_1, T pos)
93{
94 return (T{1}-pos)*u_0 + pos*u_1;
95}
96
97} // namespace fd
98
99} // namespace olb
100
101
102#endif
constexpr T boundaryZeroGradient(T u_1, T u_2)
Value at u_0 for which asymmetric gradient is zero (u_1 = u(x+1))
constexpr T centralSecondDeriv(T u_m1, T u_0, T u_p1) any_platform
Second order central second derivative (u_p1 = u(x+1))
constexpr T BSGradient(T u_0, T u_1, T u_2)
Backward second-order first derivative.
constexpr T centralGradient(T u_p1, T u_m1) any_platform
Second-order central gradient (u_p1 = u(x+1))
constexpr T linearInterpolate(T u_0, T u_1, T pos)
Linear interpolation (yields u0 at pos=0 and u1 at pos=1)
constexpr T FSGradient(T u_0, T u_1, T u_2)
Forward second-order first derivative.
constexpr T boundaryGradient(T u_0, T u_1, T u_2) any_platform
Second-order asymmetric gradient (u_1 = u(x+1))
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78