12#include <gtest/gtest.h>
13#include <yaml-cpp/yaml.h>
20class SingleBodyTest :
public ::testing::Test
25 virtual ~SingleBodyTest(){};
32 config[
"mesh"].push_back(Node(NodeType::Map));
33 config[
"mesh"][0][
"direction"] =
"x";
34 config[
"mesh"][1][
"direction"] =
"y";
35 for (
unsigned int i = 0; i < 2; ++i)
37 config[
"mesh"][i][
"start"] =
"0.1";
38 config[
"mesh"][i][
"subDomains"].push_back(Node(NodeType::Map));
39 config[
"mesh"][i][
"subDomains"][0][
"end"] = 1.0;
40 config[
"mesh"][i][
"subDomains"][0][
"cells"] = 10;
41 config[
"mesh"][i][
"subDomains"][0][
"stretchRatio"] = 1.0;
44 config[
"flow"] = YAML::Node(NodeType::Map);
45 config[
"flow"][
"boundaryConditions"].push_back(Node(NodeType::Map));
46 config[
"flow"][
"boundaryConditions"][0][
"location"] =
"xMinus";
47 config[
"flow"][
"boundaryConditions"][1][
"location"] =
"xPlus";
48 config[
"flow"][
"boundaryConditions"][2][
"location"] =
"yMinus";
49 config[
"flow"][
"boundaryConditions"][3][
"location"] =
"yPlus";
51 for (
unsigned int i = 0; i < 4; ++i)
53 config[
"flow"][
"boundaryConditions"][i][
"u"][0] =
"DIRICHLET";
54 config[
"flow"][
"boundaryConditions"][i][
"u"][1] = 0.0;
55 config[
"flow"][
"boundaryConditions"][i][
"v"][0] =
"DIRICHLET";
56 config[
"flow"][
"boundaryConditions"][i][
"v"][1] = 0.0;
58 config[
"flow"][
"boundaryConditions"][3][
"u"][1] = 1.0;
60 config[
"directory"] =
"body/";
61 config[
"bodies"][0][
"type"] =
"points";
62 config[
"bodies"][0][
"file"] =
"body2d.txt";
67 "body2d01",
"body/body2d.txt", body2d);
70 config[
"mesh"][2][
"direction"] =
"z";
71 config[
"mesh"][2][
"start"] =
"0.1";
72 config[
"mesh"][2][
"subDomains"].push_back(Node(NodeType::Map));
73 config[
"mesh"][2][
"subDomains"][0][
"end"] = 1.0;
74 config[
"mesh"][2][
"subDomains"][0][
"cells"] = 10;
75 config[
"mesh"][2][
"subDomains"][0][
"stretchRatio"] = 1.0;
76 for (
unsigned int i = 0; i < 4; ++i)
78 config[
"flow"][
"boundaryConditions"][i][
"w"][0] =
"DIRICHLET";
79 config[
"flow"][
"boundaryConditions"][i][
"w"][1] = 0.0;
81 config[
"flow"][
"boundaryConditions"][4][
"location"] =
"zMinus";
82 config[
"flow"][
"boundaryConditions"][5][
"location"] =
"zPlus";
84 for (
unsigned int i = 4; i < 6; ++i)
86 config[
"flow"][
"boundaryConditions"][i][
"u"][0] =
"PERIODIC";
87 config[
"flow"][
"boundaryConditions"][i][
"u"][1] = 0.0;
88 config[
"flow"][
"boundaryConditions"][i][
"v"][0] =
"PERIODIC";
89 config[
"flow"][
"boundaryConditions"][i][
"v"][1] = 0.0;
90 config[
"flow"][
"boundaryConditions"][i][
"w"][0] =
"PERIODIC";
91 config[
"flow"][
"boundaryConditions"][i][
"w"][1] = 0.0;
93 config[
"bodies"][0][
"file"] =
"body3d.txt";
97 "body3d01",
"body/body3d.txt", body3d);
100 virtual void TearDown(){};
107TEST_F(SingleBodyTest, initWithFilePath2D)
109 ASSERT_EQ(2, body2d->dim);
110 ASSERT_EQ(
"body2d01", body2d->name);
111 ASSERT_EQ(4, body2d->nPts);
112 std::vector<PetscReal> xCoords = {0.25, 0.75, 0.75, 0.25},
113 yCoords = {0.25, 0.25, 0.75, 0.75};
114 for (
unsigned int i = 0; i < 4; i++)
116 ASSERT_EQ(xCoords[i], body2d->coords[i][0]);
117 ASSERT_EQ(yCoords[i], body2d->coords[i][1]);
120 MPI_Comm_size(PETSC_COMM_WORLD, &size);
121 if (size == 1) ASSERT_EQ(body2d->nPts, body2d->nLclPts);
124TEST_F(SingleBodyTest, initWithFilePath3D)
126 ASSERT_EQ(3, body3d->dim);
127 ASSERT_EQ(
"body3d01", body3d->name);
128 ASSERT_EQ(8, body3d->nPts);
129 std::vector<PetscReal> xCoords = {0.25, 0.75, 0.75, 0.25,
130 0.25, 0.75, 0.75, 0.25},
131 yCoords = {0.25, 0.25, 0.75, 0.75,
132 0.25, 0.25, 0.75, 0.75},
133 zCoords = {0.25, 0.25, 0.25, 0.25,
134 0.75, 0.75, 0.75, 0.75};
135 for (
unsigned int i = 0; i < 4; i++)
137 ASSERT_EQ(xCoords[i], body3d->coords[i][0]);
138 ASSERT_EQ(yCoords[i], body3d->coords[i][1]);
139 ASSERT_EQ(zCoords[i], body3d->coords[i][2]);
142 MPI_Comm_size(PETSC_COMM_WORLD, &size);
143 if (size == 1) ASSERT_EQ(body3d->nPts, body3d->nLclPts);
148 PetscMPIInt size, index;
149 MPI_Comm_size(PETSC_COMM_WORLD, &size);
151 for (
int i = 0; i < body2d->nPts; i++)
153 body2d->findProc(i, index);
160 PetscMPIInt size, index;
161 MPI_Comm_size(PETSC_COMM_WORLD, &size);
163 for (
int i = 0; i < body3d->nPts; i++)
165 body3d->findProc(i, index);
172 PetscInt globalIndex, counter = 0;
174 for (
int i = 0; i < body2d->nPts; i++)
175 for (
int d = 0; d < ndof; d++)
177 body2d->getGlobalIndex(i, d, globalIndex);
178 ASSERT_EQ(counter, globalIndex);
179 MatStencil stencil = {0, 0, i, d};
180 body2d->getGlobalIndex(stencil, globalIndex);
181 ASSERT_EQ(counter, globalIndex);
188 PetscInt globalIndex, counter = 0;
190 for (
int i = 0; i < body3d->nPts; i++)
191 for (
int d = 0; d < ndof; d++)
193 body3d->getGlobalIndex(i, d, globalIndex);
194 ASSERT_EQ(counter, globalIndex);
195 MatStencil stencil = {0, 0, i, d};
196 body3d->getGlobalIndex(stencil, globalIndex);
197 ASSERT_EQ(counter, globalIndex);
202TEST_F(SingleBodyTest, calculateAvgForces2D)
205 DMCreateGlobalVector(body2d->da, &f);
208 body2d->calculateAvgForces(f, avg);
209 ASSERT_EQ(body2d->dim, (
int)avg.size());
210 for (
unsigned int d = 0; d < avg.size(); d++)
211 ASSERT_EQ(body2d->nPts * -1.0, avg[d]);
215TEST_F(SingleBodyTest, calculateAvgForces3D)
218 DMCreateGlobalVector(body3d->da, &f);
221 body3d->calculateAvgForces(f, avg);
222 ASSERT_EQ(body3d->dim, (
int)avg.size());
223 for (
unsigned int d = 0; d < avg.size(); d++)
224 ASSERT_EQ(body3d->nPts * -1.0, avg[d]);
231 PetscErrorCode ierr, status;
233 ::testing::InitGoogleTest(&argc, argv);
234 ierr = PetscInitialize(&argc, &argv,
nullptr,
nullptr); CHKERRQ(ierr);
235 status = RUN_ALL_TESTS();
236 ierr = PetscFinalize(); CHKERRQ(ierr);
PetscErrorCode createSingleBody(const MPI_Comm &comm, const PetscInt &dim, const std::string &type, const std::string &name, const std::string &filePath, type::SingleBody &body)
Factory function to create a single body.
std::shared_ptr< body::SingleBodyBase > SingleBody
Definition of type::SingleBody.
std::shared_ptr< mesh::MeshBase > Mesh
Type definition of Mesh.
PetscErrorCode createMesh(const MPI_Comm &comm, const YAML::Node &node, type::Mesh &mesh)
Factory function for creating a Mesh object.
std::vector< PetscReal > RealVec1D
1D std::vector holding PetscReal.
Prototype of mesh::MeshBase, type::Mesh, and factory function.
A toolbox for building flow solvers.
body::SingleBodyBase, type::SingleBody factory function.
TEST_F(SingleBodyTest, initWithFilePath2D)
int main(int argc, char **argv)