OpenLB 1.7
Loading...
Searching...
No Matches
dimensionConverter.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Nicolas Hafen, Mathias J. Krause
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 DIMENSION_CONVERTER_H
25#define DIMENSION_CONVERTER_H
26
27/* #include <numbers> */
28
31
32namespace olb {
33
34namespace utilities {
35
36namespace dimensions {
37
39// - differentiates between F2D and F3D indicators
40// - differentiates between D4 and D9 Rotation Matrix
41// - differentiates between D1 and D3 rotation related quantities
42template <unsigned D>
43struct convert;
44template <>
45struct convert<2> {
46private:
47 template <typename T>
48 constexpr static const T invSqrt2 = T{0.7071067811865475244008443621048490392848359376884740365883};
49 /* constexpr static const T invSqrt2 = T{1} / std::numbers::sqrt2; */
50
51public:
52 // Rotational dimensions (rotational degrees of freedom)
53 constexpr static const unsigned int rotation = 1;
54
55 // Number of entries in rotation matrix
56 constexpr static const unsigned int matrix = 4;
57
58 // Number of direct neighbors of a cell
59 constexpr static const unsigned short directNeighborsCount = 4;
60 // Directions to direct neighbors
61 constexpr static const short directNeighborDirections[directNeighborsCount][2] = {
62 {-1, 0}, {0,-1},
63 {1, 0}, { 0, 1}
64 };
65 // Number of all neighboring cells
66 constexpr static const unsigned short neighborsCount = 8;
67 // Directions to neighbors
68 constexpr static const short neighborDirections[neighborsCount][2] = {
69 {-1, 1}, {-1, 0}, {-1,-1}, { 0,-1},
70 { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}
71 };
72 // Normalized directions to neighbors
73 template <typename T>
74 constexpr static const T normalizedNeighborDirections[neighborsCount][2] = {
75 {-1*invSqrt2<T>, 1*invSqrt2<T>}, {-1, 0}, {-1*invSqrt2<T>,-1*invSqrt2<T>}, { 0,-1},
76 { 1*invSqrt2<T>,-1*invSqrt2<T>}, { 1, 0}, { 1*invSqrt2<T>, 1*invSqrt2<T>}, { 0, 1}
77 };
78
79 // Type used for surface representation
80 template<typename T>
82
83 // Converting rotational vector to serial type for field access
84 template<typename T>
85 static constexpr T serialize_rotation( Vector<T,rotation> angle )
86 {
87 return angle[0];
88 }
89};
90template <>
91struct convert<3> {
92private:
93 template <typename T>
94 constexpr static const T invSqrt2 = T{0.7071067811865475244008443621048490392848359376884740365883};
95 /* constexpr static const T invSqrt2 = T{1} / std::numbers::sqrt2; */
96 template <typename T>
97 constexpr static const T invSqrt3 = T{0.5773502691896257645091487805019574556476017512701268760186};
98 /* constexpr static const T invSqrt3 = std::numbers::inv_sqrt3; */
99
100public:
101 // Rotational dimensions (rotational degrees of freedom)
102 constexpr static const unsigned int rotation = 3;
103
104 // Number of entries in rotation matrix
105 constexpr static const unsigned int matrix = 9;
106
107 // Number of direct neighbors of a cell
108 constexpr static const unsigned short directNeighborsCount = 6;
109 // Directions to direct neighbors
110 constexpr static const short directNeighborDirections[directNeighborsCount][3] = {
111 {-1, 0, 0}, {0,-1, 0},
112 { 0, 0,-1}, {1, 0, 0},
113 { 0, 1, 0}, {0, 0, 1}
114 };
115 // Number of all neighboring cells
116 constexpr static const unsigned short neighborsCount = 26;
117 // Directions to neighbors
118 constexpr static const short neighborDirections[neighborsCount][3] = {
119 {-1, 0, 0}, { 0,-1, 0}, { 0, 0,-1},
120 {-1,-1, 0}, {-1, 1, 0}, {-1, 0,-1},
121 {-1, 0, 1}, { 0,-1,-1}, { 0,-1, 1},
122 {-1,-1,-1}, {-1,-1, 1}, {-1, 1,-1}, {-1, 1, 1},
123 { 1, 0, 0}, { 0, 1, 0}, { 0, 0, 1},
124 { 1, 1, 0}, { 1,-1, 0}, { 1, 0, 1},
125 { 1, 0,-1}, { 0, 1, 1}, { 0, 1,-1},
126 { 1, 1, 1}, { 1, 1,-1}, { 1,-1, 1}, { 1,-1,-1}
127 };
128 // Normalized directions to neighbors
129 template <typename T>
130 constexpr static const T normalizedNeighborDirections[neighborsCount][3] = {
131 {-1, 0, 0}, { 0,-1, 0}, { 0, 0,-1},
132 {-1*invSqrt2<T>,-1*invSqrt2<T>, 0}, {-1*invSqrt2<T>, 1*invSqrt2<T>, 0}, {-1*invSqrt2<T>, 0,-1*invSqrt2<T>},
133 {-1*invSqrt2<T>, 0, 1*invSqrt2<T>}, { 0,-1*invSqrt2<T>,-1*invSqrt2<T>}, { 0,-1*invSqrt2<T>, 1*invSqrt2<T>},
134 {-1*invSqrt3<T>,-1*invSqrt3<T>,-1*invSqrt3<T>}, {-1*invSqrt3<T>,-1*invSqrt3<T>, 1*invSqrt3<T>}, {-1*invSqrt3<T>, 1*invSqrt3<T>,-1*invSqrt3<T>}, {-1*invSqrt3<T>, 1*invSqrt3<T>, 1*invSqrt3<T>},
135 { 1, 0, 0}, { 0, 1, 0}, { 0, 0, 1},
136 { 1*invSqrt2<T>, 1*invSqrt2<T>, 0}, { 1*invSqrt2<T>,-1*invSqrt2<T>, 0}, { 1*invSqrt2<T>, 0, 1*invSqrt2<T>},
137 { 1*invSqrt2<T>, 0,-1*invSqrt2<T>}, { 0, 1*invSqrt2<T>, 1*invSqrt2<T>}, { 0, 1*invSqrt2<T>,-1*invSqrt2<T>},
138 { 1*invSqrt3<T>, 1*invSqrt3<T>, 1*invSqrt3<T>}, { 1*invSqrt3<T>, 1*invSqrt3<T>,-1*invSqrt3<T>}, { 1*invSqrt3<T>,-1*invSqrt3<T>, 1*invSqrt3<T>}, { 1*invSqrt3<T>,-1*invSqrt3<T>,-1*invSqrt3<T>}
139 };
140
141 // Type used for surface representation
142 template<typename T>
144
145 // Converting rotational vector to serial type for field access
146 template<typename T>
148 {
149 return angle;
150 }
151};
152
153
154} //namespace dimensions
155
156} //namespace utilities
157
158} //namespace olb
159
160
161#endif
Plain old scalar vector.
Definition vector.h:47
Top level namespace for all of OpenLB.
static constexpr T serialize_rotation(Vector< T, rotation > angle)
static constexpr Vector< T, rotation > serialize_rotation(Vector< T, rotation > angle)
Converts dimensions by deriving from given cartesian dimension D.