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
"
35
#include "
constants/NumericConstants.h
"
36
#include "gmock/gmock.h"
37
38
#include "gtest/gtest.h"
39
#include <
basics/geometry3d/GbSpatialData3D.h
>
40
#include <cmath>
41
#include <memory>
42
43
using namespace
testing
;
44
using namespace
vf::basics::constant
;
45
46
const
real
c1o2p25
= c2o3 * c2o3;
47
template
<
typename
T> internal::FloatingEqMatcher<T>
Equal
(
T
a);
48
template
<> internal::FloatingEqMatcher<float>
Equal
(
float
a){
return
FloatEq
(a);};
49
template
<> internal::FloatingEqMatcher<double>
Equal
(
double
a){
return
DoubleEq
(a);};
50
51
52
TEST
(
StructuredMeshTest
,
Interpolation3DReal
)
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,
59
GbStructuredMesh3D<real>::InterpolationStrategy::Trilinear
);
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
64
TEST
(
StructuredMeshTest
,
Interpolation3DReal3
)
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,
73
GbStructuredMesh3D<real3>::InterpolationStrategy::Trilinear
);
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
78
TEST
(
StructuredMeshTest
,
Interpolation2DReal
)
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,
85
GbStructuredMesh3D<real>::InterpolationStrategy::Trilinear
);
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
91
TEST
(
PointCloudTest
,
InterpolationRealIDW3D
)
92
{
93
std::vector<real3> points {
94
{},
95
};
96
std::vector<real> data { 1.0 };
97
GbPointCloud3D<real>
pointCloud
(points, data, std::make_unique<
GbPointCloud3D<real>::InverseDistanceWeighing
>());
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
103
TEST
(
PointCloudTest
,
InterpolationRealIDW3D2
)
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 };
107
GbPointCloud3D<real>
pointCloud
(points, data, std::make_unique<
GbPointCloud3D<real>::InverseDistanceWeighing
>());
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
114
TEST
(
PointCloudTest
,
InterpolationRealIDW3D3
)
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 };
118
GbPointCloud3D<real>
pointCloud
(points, data, std::make_unique<
GbPointCloud3D<real>::InverseDistanceWeighing
>(2));
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
125
TEST
(
PointCloudTest
,
InterpolationReal3IDW3D
)
126
{
127
std::vector<real3> points {
128
{},
129
};
130
const
real3
one
{ 1.0, 1.0, 1.0 };
131
std::vector<real3> data {
one
};
132
GbPointCloud3D<real3>
pointCloud
(points, data, std::make_unique<
GbPointCloud3D<real3>::InverseDistanceWeighing
>());
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
138
TEST
(
PointCloudTest
,
InterpolationReal3IDW3D2
)
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
};
144
GbPointCloud3D<real3>
pointCloud
(points, data,
GbPointCloud3D<real3>::InverseDistanceWeighing::make
());
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 });
149
EXPECT_THAT
(
result
.x,
Equal
(
c1o2p25
/
weights
));
150
EXPECT_THAT
(
result
.y,
Equal
(
c1o2p25
/
weights
));
151
EXPECT_THAT
(
result
.z,
Equal
(
c1o2p25
/
weights
));
152
}
153
154
TEST
(
PointCloudTest
,
InterpolationNearestNeighborReal3D
)
155
{
156
std::vector<real3> points {
157
{},
158
};
159
std::vector<real> data { 1.0 };
160
GbPointCloud3D<real>
pointCloud
(points, data,
GbPointCloud3D<real>::NearestNeighbor::make
());
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
166
TEST
(
PointCloudTest
,
InterpolationNearestNeighborReal3D2
)
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 };
170
GbPointCloud3D<real>
pointCloud
(points, data,
GbPointCloud3D<real>::NearestNeighbor::make
());
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
177
TEST
(
PointCloudTest
,
InterpolationNearestNeighborReal3D3
)
178
{
179
std::vector<real3> points {
180
{},
181
};
182
const
real3
one
{ 1.0, 1.0, 1.0 };
183
std::vector<real3> data {
one
};
184
GbPointCloud3D<real3>
pointCloud
(points, data,
GbPointCloud3D<real3>::NearestNeighbor::make
());
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
190
TEST
(
PointCloudTest
,
InterpolationNearestNeighborReal33D2
)
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
};
196
GbPointCloud3D<real3>
pointCloud
(points, data,
GbPointCloud3D<real3>::NearestNeighbor::make
());
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
}
DataTypes.h
GbSpatialData3D.h
NumericConstants.h
GbPointCloud3D::InverseDistanceWeighing
Definition
GbSpatialData3D.h:341
GbPointCloud3D
This class provides an object to interpolate spatially distributed data to new points.
Definition
GbSpatialData3D.h:262
GbStructuredMesh3D
This class provides an object to interpolate data on a regular structured mesh to new points.
Definition
GbSpatialData3D.h:73
SPtr
std::shared_ptr< T > SPtr
Definition
PointerDefinitions.h:39
real
float real
Definition
DataTypes.h:42
GbStructuredMesh3D::interpolateToPoint
T interpolateToPoint(real3 point) const override
Definition
GbSpatialData3D.h:83
Equal
internal::FloatingEqMatcher< T > Equal(T a)
c1o2p25
const real c1o2p25
Definition
GbSpatialData3DTest.cpp:46
TEST
TEST(StructuredMeshTest, Interpolation3DReal)
Definition
GbSpatialData3DTest.cpp:52
testing
Definition
LogRedirector.cpp:39
vf::basics::constant
Definition
NumericConstants.h:41
real3
Definition
DataTypes.h:51
tests
unit-tests
basics
geometry3d
GbSpatialData3DTest.cpp
Generated on Sat Sep 12 2026 02:03:21 for VirtualFluids by
1.9.8