VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
GbSpatialData3DTest.cpp
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//
33//=======================================================================================
34#include "DataTypes.h"
36#include "gmock/gmock.h"
37
38#include "gtest/gtest.h"
40#include <cmath>
41#include <memory>
42
43using namespace testing;
44using namespace vf::basics::constant;
45
46const real c1o2p25 = c2o3 * c2o3;
47template<typename T> internal::FloatingEqMatcher<T> Equal(T a);
48template <> internal::FloatingEqMatcher<float> Equal(float a){return FloatEq(a);};
49template <> internal::FloatingEqMatcher<double> Equal(double a){return DoubleEq(a);};
50
51
53{
54 const real3 spacing { 1.0, 1.0, 1.0 };
55 const real3 origin {};
56 const std::array<uint, 3> nPoints { 2, 2, 2 };
57 const std::vector<real> data { 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0 };
58 GbStructuredMesh3D<real> mesh(spacing, origin, nPoints, data,
60 EXPECT_THAT(mesh.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(0.5));
61 EXPECT_THAT(mesh.interpolateToPoint({ 0, 0., 1.0 }), Eq(1.0));
62}
63
65{
66 const real3 spacing { 1.0, 1.0, 1.0 };
67 const real3 origin {};
68 const std::array<uint, 3> nPoints { 2, 2, 2 };
69 const real3 zero {};
70 const real3 one { 1.0, 1.0, 1.0 };
71 const std::vector<real3> data { zero, zero, zero, zero, one, one, one, one };
72 GbStructuredMesh3D<real3> mesh(spacing, origin, nPoints, data,
74 EXPECT_THAT(mesh.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(real3 { 0.5, 0.5, 0.5 }));
75 EXPECT_THAT(mesh.interpolateToPoint({ 0, 0., 1.0 }), Eq(one));
76}
77
79{
80 const real3 spacing { 1.0, 1.0, 0.0 };
81 const real3 origin {};
82 const std::array<uint, 3> nPoints { 2, 2, 1 };
83 const std::vector<real> data { 0.0, 1.0, 0.0, 1.0 };
84 GbStructuredMesh3D<real> mesh(spacing, origin, nPoints, data,
86 EXPECT_THAT(mesh.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(0.5));
87 EXPECT_THAT(mesh.interpolateToPoint({ 0, 0., 1.0 }), Eq(0.0));
88 EXPECT_THAT(mesh.interpolateToPoint({ 1.0, 1.0, -1.5 }), Eq(1.0));
89}
90
92{
93 std::vector<real3> points {
94 {},
95 };
96 std::vector<real> data { 1.0 };
98 EXPECT_THAT(pointCloud.interpolateToPoint({}), Eq(1.0));
99 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(1.0));
100 EXPECT_THAT(pointCloud.interpolateToPoint({ -0.5, -0.5, -0.5 }), Eq(1.0));
101}
102
104{
105 std::vector<real3> points { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 } };
106 std::vector<real> data { 0.0, 1.0 };
108 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.0, 0.0, 0.0 }), Eq(0.0));
109 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(0.5));
110 const real weights = c4o1 + c1o2p25;
111 EXPECT_THAT(pointCloud.interpolateToPoint({ -0.5, 0.0, 0.0 }), Equal(c1o2p25 / weights));
112}
113
115{
116 std::vector<real3> points { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 2.0, 0.0, 0.0 } };
117 std::vector<real> data { 0.0, 1.0, 100.0 };
119 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.0, 0.0, 0.0 }), Eq(0.0));
120 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(0.5));
121 const real weights = c4o1 + c1o2p25;
122 EXPECT_THAT(pointCloud.interpolateToPoint({ -0.5, 0.0, 0.0 }), Equal(c1o2p25 / weights));
123}
124
126{
127 std::vector<real3> points {
128 {},
129 };
130 const real3 one { 1.0, 1.0, 1.0 };
131 std::vector<real3> data { one };
133 EXPECT_THAT(pointCloud.interpolateToPoint({}), Eq(one));
134 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(one));
135 EXPECT_THAT(pointCloud.interpolateToPoint({ -0.5, -0.5, -0.5 }), Eq(one));
136}
137
139{
140 std::vector<real3> points { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 } };
141 const real3 zero {};
142 const real3 one { 1.0, 1.0, 1.0 };
143 std::vector<real3> data { zero, one };
145 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.0, 0.0, 0.0 }), Eq(zero));
146 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(one * 0.5));
147 const real weights = c4o1 + c1o2p25;
148 const real3 result = pointCloud.interpolateToPoint({ -0.5, 0.0, 0.0 });
152}
153
155{
156 std::vector<real3> points {
157 {},
158 };
159 std::vector<real> data { 1.0 };
161 EXPECT_THAT(pointCloud.interpolateToPoint({}), Eq(1.0));
162 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(1.0));
163 EXPECT_THAT(pointCloud.interpolateToPoint({ -0.5, -0.5, -0.5 }), Eq(1.0));
164}
165
167{
168 std::vector<real3> points { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 } };
169 std::vector<real> data { 0.0, 1.0 };
171 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.0, 0.0, 0.0 }), Eq(0.0));
172 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(1.0));
173 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.49999, 0.5, 0.5 }), Eq(0.0));
174 EXPECT_THAT(pointCloud.interpolateToPoint({ -0.5, 0.0, 0.0 }), Eq(0.0));
175}
176
178{
179 std::vector<real3> points {
180 {},
181 };
182 const real3 one { 1.0, 1.0, 1.0 };
183 std::vector<real3> data { one };
185 EXPECT_THAT(pointCloud.interpolateToPoint({}), Eq(one));
186 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(one));
187 EXPECT_THAT(pointCloud.interpolateToPoint({ -0.5, -0.5, -0.5 }), Eq(one));
188}
189
191{
192 std::vector<real3> points { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 } };
193 const real3 zero {};
194 const real3 one { 1.0, 1.0, 1.0 };
195 std::vector<real3> data { zero, one };
197 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.0, 0.0, 0.0 }), Eq(zero));
198 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.5, 0.5, 0.5 }), Eq(one));
199 EXPECT_THAT(pointCloud.interpolateToPoint({ 0.49999, 0.5, 0.5 }), Eq(zero));
200 EXPECT_THAT(pointCloud.interpolateToPoint({ -0.5, 0.0, 0.0 }), Eq(zero));
201}
This class provides an object to interpolate spatially distributed data to new points.
This class provides an object to interpolate data on a regular structured mesh to new points.
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
T interpolateToPoint(real3 point) const override
internal::FloatingEqMatcher< T > Equal(T a)
const real c1o2p25
TEST(StructuredMeshTest, Interpolation3DReal)