GCC Code Coverage Report


Directory: ./
File: openvdb/openvdb/unittest/TestPotentialFlow.cc
Date: 2022-07-25 17:40:05
Exec Total Coverage
Lines: 153 153 100.0%
Functions: 4 4 100.0%
Branches: 258 1118 23.1%

Line Branch Exec Source
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
4 /// @file unittest/TestPotentialFlow.cc
5
6 #include <openvdb/openvdb.h>
7 #include <openvdb/tools/LevelSetSphere.h>
8 #include <openvdb/tools/PotentialFlow.h>
9
10 #include <gtest/gtest.h>
11
12
13 4 class TestPotentialFlow: public ::testing::Test
14 {
15 };
16
17
18
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestPotentialFlow, testMask)
19 {
20 using namespace openvdb;
21
22 const float radius = 1.5f;
23 const Vec3f center(0.0f, 0.0f, 0.0f);
24 const float voxelSize = 0.25f;
25 const float halfWidth = 3.0f;
26
27 FloatGrid::Ptr sphere =
28 1 tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, halfWidth);
29
30 const int dilation = 5;
31
32
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 MaskGrid::Ptr mask = tools::createPotentialFlowMask(*sphere, dilation);
33
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 MaskGrid::Ptr defaultMask = tools::createPotentialFlowMask(*sphere);
34
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(*mask == *defaultMask);
35
36 auto acc = mask->getAccessor();
37
38 // the isosurface of this sphere is at y = 6
39 // this mask forms a band dilated outwards from the isosurface by 5 voxels
40
41
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_TRUE(!acc.isValueOn(Coord(0, 5, 0)));
42
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_TRUE(acc.isValueOn(Coord(0, 6, 0)));
43
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_TRUE(acc.isValueOn(Coord(0, 10, 0)));
44
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_TRUE(!acc.isValueOn(Coord(0, 11, 0)));
45
46 { // error on non-uniform voxel size
47 FloatGrid::Ptr nonUniformSphere =
48
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, halfWidth);
49 math::Transform::Ptr nonUniformTransform(new math::Transform(
50
4/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
3 math::MapBase::Ptr(new math::ScaleMap(Vec3d(0.1, 0.2, 0.3)))));
51
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
2 nonUniformSphere->setTransform(nonUniformTransform);
52
53
4/22
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
2 EXPECT_THROW(tools::createPotentialFlowMask(*nonUniformSphere, dilation),
54 openvdb::ValueError);
55 }
56
57 // this is the minimum mask of one voxel either side of the isosurface
58
59
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 mask = tools::createPotentialFlowMask(*sphere, 2);
60
61
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
1 acc = mask->getAccessor();
62
63
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_TRUE(!acc.isValueOn(Coord(0, 5, 0)));
64
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_TRUE(acc.isValueOn(Coord(0, 6, 0)));
65
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_TRUE(acc.isValueOn(Coord(0, 7, 0)));
66
1/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_TRUE(!acc.isValueOn(Coord(0, 8, 0)));
67
68 // these should all produce the same masks as the dilation value is clamped
69
70
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 MaskGrid::Ptr negativeMask = tools::createPotentialFlowMask(*sphere, -1);
71
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 MaskGrid::Ptr zeroMask = tools::createPotentialFlowMask(*sphere, 0);
72
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 MaskGrid::Ptr oneMask = tools::createPotentialFlowMask(*sphere, 1);
73
74
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(*negativeMask == *mask);
75
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(*zeroMask == *mask);
76
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(*oneMask == *mask);
77 1 }
78
79
80
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestPotentialFlow, testNeumannVelocities)
81 {
82 using namespace openvdb;
83
84 const float radius = 1.5f;
85 const Vec3f center(0.0f, 0.0f, 0.0f);
86 const float voxelSize = 0.25f;
87 const float halfWidth = 3.0f;
88
89 FloatGrid::Ptr sphere =
90 1 tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, halfWidth);
91
92
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 MaskGrid::Ptr domain = tools::createPotentialFlowMask(*sphere);
93
94 {
95 // test identical potential from a wind velocity supplied through grid or background value
96
97 Vec3d windVelocityValue(0, 0, 10);
98
99
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
2 Vec3dTree::Ptr windTree(new Vec3dTree(sphere->tree(), zeroVal<Vec3d>(), TopologyCopy()));
100
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dilateActiveValues(*windTree, 2, tools::NN_FACE_EDGE_VERTEX, tools::IGNORE_TILES);
101 windTree->voxelizeActiveTiles();
102
103
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 1 times.
39 for (auto leaf = windTree->beginLeaf(); leaf; ++leaf) {
104
2/2
✓ Branch 0 taken 6837 times.
✓ Branch 1 taken 38 times.
6875 for (auto iter = leaf->beginValueOn(); iter; ++iter) {
105
1/2
✓ Branch 1 taken 6837 times.
✗ Branch 2 not taken.
6837 iter.setValue(windVelocityValue);
106 }
107 }
108
109
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 Vec3dGrid::Ptr windGrid(Vec3dGrid::create(windTree));
110
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 windGrid->setTransform(sphere->transform().copy());
111
112 auto windPotentialFromGrid = tools::createPotentialFlowNeumannVelocities(
113
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 *sphere, *domain, windGrid, Vec3d(0));
114
115
1/14
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(windPotentialFromGrid->transform(), sphere->transform());
116
117 auto windPotentialFromBackground = tools::createPotentialFlowNeumannVelocities(
118
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 *sphere, *domain, Vec3dGrid::Ptr(), windVelocityValue);
119
120 auto accessor = windPotentialFromGrid->getConstAccessor();
121 auto accessor2 = windPotentialFromBackground->getConstAccessor();
122
123
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_EQ(windPotentialFromGrid->activeVoxelCount(),
124 windPotentialFromBackground->activeVoxelCount());
125
126
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1 times.
21 for (auto leaf = windPotentialFromGrid->tree().cbeginLeaf(); leaf; ++leaf) {
127
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 20 times.
2094 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
128
4/22
✓ Branch 1 taken 2074 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 2074 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 2074 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 2074 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
2074 EXPECT_EQ(accessor.isValueOn(iter.getCoord()),
129 accessor2.isValueOn(iter.getCoord()));
130
5/22
✓ Branch 1 taken 2074 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2074 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2074 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2074 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2074 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
4148 EXPECT_EQ(accessor.getValue(iter.getCoord()),
131 accessor2.getValue(iter.getCoord()));
132 }
133 }
134
135 // test potential from a wind velocity supplied through grid background value
136
137 Vec3dTree::Ptr emptyWindTree(
138
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 new Vec3dTree(sphere->tree(), windVelocityValue, TopologyCopy()));
139
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 Vec3dGrid::Ptr emptyWindGrid(Vec3dGrid::create(emptyWindTree));
140
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 emptyWindGrid->setTransform(sphere->transform().copy());
141
142 auto windPotentialFromGridBackground = tools::createPotentialFlowNeumannVelocities(
143
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 *sphere, *domain, emptyWindGrid, Vec3d(0));
144
145
1/14
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
1 EXPECT_EQ(windPotentialFromGridBackground->transform(), sphere->transform());
146
147
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 accessor = windPotentialFromGridBackground->getConstAccessor();
148
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 accessor2 = windPotentialFromBackground->getConstAccessor();
149
150
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_EQ(windPotentialFromGridBackground->activeVoxelCount(),
151 windPotentialFromBackground->activeVoxelCount());
152
153
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1 times.
21 for (auto leaf = windPotentialFromGridBackground->tree().cbeginLeaf(); leaf; ++leaf) {
154
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 20 times.
2094 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
155
4/20
✓ Branch 1 taken 2074 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 2074 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 2074 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 2074 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
2074 EXPECT_EQ(accessor.isValueOn(iter.getCoord()),
156 accessor2.isValueOn(iter.getCoord()));
157
5/22
✓ Branch 1 taken 2074 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2074 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2074 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2074 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2074 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
4148 EXPECT_EQ(accessor.getValue(iter.getCoord()),
158 accessor2.getValue(iter.getCoord()));
159 }
160 }
161
162 // test potential values are double when applying wind velocity
163 // through grid and background values
164
165 auto windPotentialFromBoth = tools::createPotentialFlowNeumannVelocities(
166
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 *sphere, *domain, windGrid, windVelocityValue);
167
168
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 tools::prune(windPotentialFromBoth->tree(), Vec3d(1e-3));
169
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 tools::prune(windPotentialFromBackground->tree(), Vec3d(1e-3));
170
171
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 accessor = windPotentialFromBoth->getConstAccessor();
172
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 accessor2 = windPotentialFromBackground->getConstAccessor();
173
174
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1 times.
21 for (auto leaf = windPotentialFromBoth->tree().cbeginLeaf(); leaf; ++leaf) {
175
2/2
✓ Branch 0 taken 2074 times.
✓ Branch 1 taken 20 times.
2094 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
176
4/22
✓ Branch 1 taken 2074 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 2074 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 2074 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 2074 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
2074 EXPECT_EQ(accessor.isValueOn(iter.getCoord()),
177 accessor2.isValueOn(iter.getCoord()));
178
5/22
✓ Branch 1 taken 2074 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2074 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2074 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2074 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2074 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
4148 EXPECT_EQ(accessor.getValue(iter.getCoord()),
179 accessor2.getValue(iter.getCoord()) * 2);
180 }
181 }
182
183
2/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1 EXPECT_TRUE(*windPotentialFromBoth == *windPotentialFromBackground);
184 }
185
186
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 Vec3dGrid::Ptr zeroVelocity = Vec3dGrid::create(Vec3d(0));
187
188 { // error if grid is not a levelset
189 FloatGrid::Ptr nonLevelSetSphere =
190
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, halfWidth);
191
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 nonLevelSetSphere->setGridClass(GRID_FOG_VOLUME);
192
193
5/26
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 26 taken 1 times.
✗ Branch 27 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
3 EXPECT_THROW(tools::createPotentialFlowNeumannVelocities(
194 *nonLevelSetSphere, *domain, zeroVelocity, Vec3d(5)), openvdb::TypeError);
195 }
196
197 { // accept double level set grid
198 DoubleGrid::Ptr doubleSphere =
199
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::createLevelSetSphere<DoubleGrid>(radius, center, voxelSize, halfWidth);
200
201
6/26
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
4 EXPECT_NO_THROW(tools::createPotentialFlowNeumannVelocities(
202 *doubleSphere, *domain, zeroVelocity, Vec3d(5)));
203 }
204
205 { // zero boundary velocities and background velocity
206 Vec3d zeroVelocityValue(zeroVal<Vec3d>());
207 auto neumannVelocities = tools::createPotentialFlowNeumannVelocities(
208
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 *sphere, *domain, zeroVelocity, zeroVelocityValue);
209
3/18
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
1 EXPECT_EQ(neumannVelocities->activeVoxelCount(), Index64(0));
210 }
211 1 }
212
213
214
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 TEST_F(TestPotentialFlow, testUniformStream)
215 {
216 // this unit test checks the scalar potential and velocity flow field
217 // for a uniform stream which consists of a 100x100x100 cube of
218 // neumann voxels with constant velocity (0, 0, 1)
219
220 using namespace openvdb;
221
222 1 auto transform = math::Transform::createLinearTransform(1.0);
223
224
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1 auto mask = MaskGrid::create(false);
225
2/6
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
2 mask->setTransform(transform);
226 auto maskAccessor = mask->getAccessor();
227
228
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 auto neumann = Vec3dGrid::create(Vec3d(0));
229 auto neumannAccessor = neumann->getAccessor();
230
231
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
101 for (int i = -50; i < 50; i++) {
232
2/2
✓ Branch 0 taken 10000 times.
✓ Branch 1 taken 100 times.
10100 for (int j = -50; j < 50; j++) {
233
2/2
✓ Branch 0 taken 1000000 times.
✓ Branch 1 taken 10000 times.
1010000 for (int k = -50; k < 50; k++) {
234 Coord ijk(i, j, k);
235
2/4
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1000000 times.
✗ Branch 5 not taken.
1000000 maskAccessor.setValueOn(ijk, true);
236
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
1000000 neumannAccessor.setValueOn(ijk, Vec3d(0, 0, 1));
237 }
238 }
239 }
240
241 openvdb::math::pcg::State state = math::pcg::terminationDefaults<float>();
242
243 1 state.iterations = 2000;
244
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 state.absoluteError = 1e-8;
245
246
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto potential = tools::computeScalarPotential(*mask, *neumann, state);
247
248 // check convergence
249
250
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(state.success);
251
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(state.iterations > 0 && state.iterations < 1000);
252
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(state.absoluteError < 1e-6);
253
254
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_EQ(potential->activeVoxelCount(), mask->activeVoxelCount());
255
256 // for uniform flow along the z-axis, the scalar potential should be equal to the z co-ordinate
257
258
2/2
✓ Branch 0 taken 2744 times.
✓ Branch 1 taken 1 times.
2745 for (auto leaf = potential->tree().cbeginLeaf(); leaf; ++leaf) {
259
2/2
✓ Branch 0 taken 1000000 times.
✓ Branch 1 taken 2744 times.
1002744 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
260
1/2
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
1000000 const double staggeredZ = iter.getCoord().z() + 0.5;
261
2/18
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1000000 EXPECT_TRUE(math::isApproxEqual(iter.getValue(), staggeredZ, /*tolerance*/0.1));
262 }
263 }
264
265
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto flow = tools::computePotentialFlow(*potential, *neumann);
266
267
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_EQ(flow->activeVoxelCount(), mask->activeVoxelCount());
268
269 // flow velocity should be equal to the input velocity (0, 0, 1)
270
271
2/2
✓ Branch 0 taken 2744 times.
✓ Branch 1 taken 1 times.
2745 for (auto leaf = flow->tree().cbeginLeaf(); leaf; ++leaf) {
272
2/2
✓ Branch 0 taken 1000000 times.
✓ Branch 1 taken 2744 times.
1002744 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
273
2/18
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1000000 EXPECT_TRUE(math::isApproxEqual(iter.getValue().x(), 0.0, /*tolerance*/1e-6));
274
2/18
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1000000 EXPECT_TRUE(math::isApproxEqual(iter.getValue().y(), 0.0, /*tolerance*/1e-6));
275
2/18
✓ Branch 1 taken 1000000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1000000 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1000000 EXPECT_TRUE(math::isApproxEqual(iter.getValue().z(), 1.0, /*tolerance*/1e-6));
276 }
277 }
278 1 }
279
280
281
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 TEST_F(TestPotentialFlow, testFlowAroundSphere)
282 {
283 using namespace openvdb;
284
285 const float radius = 1.5f;
286 const Vec3f center(0.0f, 0.0f, 0.0f);
287 const float voxelSize = 0.25f;
288 const float halfWidth = 3.0f;
289
290 const int dilation = 50;
291
292 FloatGrid::Ptr sphere =
293 1 tools::createLevelSetSphere<FloatGrid>(radius, center, voxelSize, halfWidth);
294
295
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 MaskGrid::Ptr domain = tools::createPotentialFlowMask(*sphere, dilation);
296
297 { // compute potential flow for a global wind velocity around a sphere
298
299 Vec3f windVelocity(0, 0, 1);
300 Vec3fGrid::Ptr neumann = tools::createPotentialFlowNeumannVelocities(*sphere,
301
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 *domain, Vec3fGrid::Ptr(), windVelocity);
302
303 openvdb::math::pcg::State state = math::pcg::terminationDefaults<float>();
304
305 1 state.iterations = 2000;
306
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 state.absoluteError = 1e-8;
307
308
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 FloatGrid::Ptr potential = tools::computeScalarPotential(*domain, *neumann, state);
309
310 // compute a laplacian of the potential within the domain (excluding neumann voxels)
311 // and ensure it evaluates to zero
312
313
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 auto mask = BoolGrid::create(/*background=*/false);
314
3/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
2 mask->setTransform(potential->transform().copy());
315 mask->topologyUnion(*potential);
316
317
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto dilatedSphereMask = tools::interiorMask(*sphere);
318
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::dilateActiveValues(dilatedSphereMask->tree(), 1);
319 mask->topologyDifference(*dilatedSphereMask);
320
321
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 FloatGrid::Ptr laplacian = tools::laplacian(*potential, *mask);
322
323
2/2
✓ Branch 0 taken 2464 times.
✓ Branch 1 taken 1 times.
2465 for (auto leaf = laplacian->tree().cbeginLeaf(); leaf; ++leaf) {
324
2/2
✓ Branch 0 taken 1130886 times.
✓ Branch 1 taken 2464 times.
1133350 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
325
2/18
✓ Branch 1 taken 1130886 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1130886 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1130886 EXPECT_TRUE(math::isApproxEqual(iter.getValue(), 0.0f, /*tolerance*/1e-3f));
326 }
327 }
328
329
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 Vec3fGrid::Ptr flowVel = tools::computePotentialFlow(*potential, *neumann);
330
331 // compute the divergence of the flow velocity within the domain
332 // (excluding neumann voxels and exterior voxels)
333 // and ensure it evaluates to zero
334
335
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::erodeActiveValues(mask->tree(), 2, tools::NN_FACE, tools::IGNORE_TILES);
336
337
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 FloatGrid::Ptr divergence = tools::divergence(*flowVel, *mask);
338
339
2/2
✓ Branch 0 taken 2464 times.
✓ Branch 1 taken 1 times.
2465 for (auto leaf = divergence->tree().cbeginLeaf(); leaf; ++leaf) {
340
2/2
✓ Branch 0 taken 1033990 times.
✓ Branch 1 taken 2464 times.
1036454 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
341
2/18
✓ Branch 1 taken 1033990 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1033990 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1033990 EXPECT_TRUE(math::isApproxEqual(iter.getValue(), 0.0f, /*tolerance*/0.1f));
342 }
343 }
344
345 // check the background velocity has been applied correctly
346
347 Vec3fGrid::Ptr flowVelBackground =
348
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::computePotentialFlow(*potential, *neumann, windVelocity);
349
350
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
1 EXPECT_EQ(flowVelBackground->activeVoxelCount(),
351 flowVelBackground->activeVoxelCount());
352
353 auto maskAccessor = mask->getConstAccessor();
354
355 auto accessor = flowVel->getConstAccessor();
356 auto accessor2 = flowVelBackground->getConstAccessor();
357
358
2/2
✓ Branch 0 taken 2464 times.
✓ Branch 1 taken 1 times.
2465 for (auto leaf = flowVelBackground->tree().cbeginLeaf(); leaf; ++leaf) {
359
2/2
✓ Branch 0 taken 1131300 times.
✓ Branch 1 taken 2464 times.
1133764 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
360 // ignore values near the neumann boundary
361
3/4
✓ Branch 1 taken 1131300 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 97310 times.
✓ Branch 5 taken 1033990 times.
1131300 if (!maskAccessor.isValueOn(iter.getCoord())) continue;
362
363
2/4
✓ Branch 1 taken 1033990 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1033990 times.
✗ Branch 5 not taken.
1033990 const Vec3f value1 = accessor.getValue(iter.getCoord());
364
3/8
✓ Branch 1 taken 1033990 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1033990 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1033990 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
1033990 const Vec3f value2 = accessor2.getValue(iter.getCoord()) + windVelocity;
365
366
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1033990 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1033990 EXPECT_TRUE(math::isApproxEqual(value1.x(), value2.x(), /*tolerance=*/1e-3f));
367
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1033990 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1033990 EXPECT_TRUE(math::isApproxEqual(value1.y(), value2.y(), /*tolerance=*/1e-3f));
368
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1033990 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1033990 EXPECT_TRUE(math::isApproxEqual(value1.z(), value2.z(), /*tolerance=*/1e-3f));
369 }
370 }
371 }
372
373 { // check double-precision solve
374 DoubleGrid::Ptr sphereDouble =
375
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::createLevelSetSphere<DoubleGrid>(radius, center, voxelSize, halfWidth);
376
377 Vec3d windVelocity(0, 0, 1);
378 Vec3dGrid::Ptr neumann = tools::createPotentialFlowNeumannVelocities(*sphereDouble,
379
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 *domain, Vec3dGrid::Ptr(), windVelocity);
380
381 openvdb::math::pcg::State state = math::pcg::terminationDefaults<float>();
382
383 1 state.iterations = 2000;
384
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 state.absoluteError = 1e-8;
385
386
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 DoubleGrid::Ptr potential = tools::computeScalarPotential(*domain, *neumann, state);
387
388
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(potential);
389
390 // compute a laplacian of the potential within the domain (excluding neumann voxels)
391 // and ensure it evaluates to zero
392
393
2/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 auto mask = BoolGrid::create(/*background=*/false);
394
3/8
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
2 mask->setTransform(potential->transform().copy());
395 mask->topologyUnion(*potential);
396
397
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 auto dilatedSphereMask = tools::interiorMask(*sphereDouble);
398
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 tools::dilateActiveValues(dilatedSphereMask->tree(), 1);
399 mask->topologyDifference(*dilatedSphereMask);
400
401
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 DoubleGrid::Ptr laplacian = tools::laplacian(*potential, *mask);
402
403
2/2
✓ Branch 0 taken 2464 times.
✓ Branch 1 taken 1 times.
2465 for (auto leaf = laplacian->tree().cbeginLeaf(); leaf; ++leaf) {
404
2/2
✓ Branch 0 taken 1130886 times.
✓ Branch 1 taken 2464 times.
1133350 for (auto iter = leaf->cbeginValueOn(); iter; ++iter) {
405
2/18
✓ Branch 1 taken 1130886 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1130886 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
1130886 EXPECT_TRUE(math::isApproxEqual(iter.getValue(), 0.0, /*tolerance*/1e-5));
406 }
407 }
408
409
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 Vec3dGrid::Ptr flowVel = tools::computePotentialFlow(*potential, *neumann);
410
411
1/16
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
1 EXPECT_TRUE(flowVel);
412 }
413 1 }
414