10#include <gtest/gtest.h>
11#include <yaml-cpp/yaml.h>
15class CartesianMeshTest2D_AllDirichlet :
public ::testing::Test
18 CartesianMeshTest2D_AllDirichlet(){};
20 virtual ~CartesianMeshTest2D_AllDirichlet(){};
22 static void SetUpTestCase()
28 config[
"mesh"].push_back(Node(NodeType::Map));
30 config[
"mesh"][0][
"direction"] =
"x";
31 config[
"mesh"][0][
"start"] =
"0.1";
32 config[
"mesh"][0][
"subDomains"].push_back(Node(NodeType::Map));
33 config[
"mesh"][0][
"subDomains"][0][
"end"] = 1.6;
34 config[
"mesh"][0][
"subDomains"][0][
"cells"] = 4;
35 config[
"mesh"][0][
"subDomains"][0][
"stretchRatio"] = 0.5;
36 config[
"mesh"][0][
"subDomains"][1][
"end"] = 1.9;
37 config[
"mesh"][0][
"subDomains"][1][
"cells"] = 3;
38 config[
"mesh"][0][
"subDomains"][1][
"stretchRatio"] = 1;
39 config[
"mesh"][0][
"subDomains"][2][
"end"] = 5.0;
40 config[
"mesh"][0][
"subDomains"][2][
"cells"] = 5;
41 config[
"mesh"][0][
"subDomains"][2][
"stretchRatio"] = 2.0;
43 config[
"mesh"][1][
"direction"] =
"y";
44 config[
"mesh"][1][
"start"] =
"0.05";
45 config[
"mesh"][1][
"subDomains"].push_back(Node(NodeType::Map));
46 config[
"mesh"][1][
"subDomains"][0][
"end"] = 0.8625;
47 config[
"mesh"][1][
"subDomains"][0][
"cells"] = 4;
48 config[
"mesh"][1][
"subDomains"][0][
"stretchRatio"] = 0.666666666666666;
49 config[
"mesh"][1][
"subDomains"][1][
"end"] = 1.1625;
50 config[
"mesh"][1][
"subDomains"][1][
"cells"] = 3;
51 config[
"mesh"][1][
"subDomains"][1][
"stretchRatio"] = 1.0;
52 config[
"mesh"][1][
"subDomains"][2][
"end"] = 1.975;
53 config[
"mesh"][1][
"subDomains"][2][
"cells"] = 4;
54 config[
"mesh"][1][
"subDomains"][2][
"stretchRatio"] = 1.5;
56 config[
"flow"] = YAML::Node(NodeType::Map);
57 config[
"flow"][
"boundaryConditions"].push_back(Node(NodeType::Map));
58 config[
"flow"][
"boundaryConditions"][0][
"location"] =
"xMinus";
59 config[
"flow"][
"boundaryConditions"][1][
"location"] =
"xPlus";
60 config[
"flow"][
"boundaryConditions"][2][
"location"] =
"yMinus";
61 config[
"flow"][
"boundaryConditions"][3][
"location"] =
"yPlus";
63 for (
unsigned int i = 0; i < 4; ++i)
65 config[
"flow"][
"boundaryConditions"][i][
"u"][0] =
"DIRICHLET";
66 config[
"flow"][
"boundaryConditions"][i][
"u"][1] = 0.0;
67 config[
"flow"][
"boundaryConditions"][i][
"v"][0] =
"DIRICHLET";
68 config[
"flow"][
"boundaryConditions"][i][
"v"][1] = 0.0;
70 config[
"flow"][
"boundaryConditions"][3][
"u"][1] = 1.0;
78 ierr = DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED,
79 DM_BOUNDARY_GHOSTED, DMDA_STENCIL_BOX, 12, 11,
80 PETSC_DECIDE, PETSC_DECIDE, 1, 1,
nullptr,
nullptr,
83 ierr = DMSetUp(da[3]);
86 ierr = DMDAGetInfo(da[3],
nullptr,
nullptr,
nullptr,
nullptr, &nProc[0],
87 &nProc[1], &nProc[2],
nullptr,
nullptr,
nullptr,
88 nullptr,
nullptr,
nullptr);
91 ierr = DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED,
92 DM_BOUNDARY_GHOSTED, DMDA_STENCIL_BOX, 11, 11,
93 nProc[0], nProc[1], 1, 1,
nullptr,
nullptr, &da[0]);
95 ierr = DMSetUp(da[0]);
98 ierr = DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED,
99 DM_BOUNDARY_GHOSTED, DMDA_STENCIL_BOX, 12, 10,
100 nProc[0], nProc[1], 1, 1,
nullptr,
nullptr, &da[1]);
102 ierr = DMSetUp(da[1]);
106 virtual void SetUp(){};
108 virtual void TearDown(){};
110 static void TearDownTestCase()
113 ierr = DMDestroy(&da[0]);
115 ierr = DMDestroy(&da[1]);
117 ierr = DMDestroy(&da[3]);
126DM CartesianMeshTest2D_AllDirichlet::da[5]{
nullptr,
nullptr,
nullptr,
nullptr,
130TEST_F(CartesianMeshTest2D_AllDirichlet, check_dim) { ASSERT_EQ(2, mesh->dim); }
133TEST_F(CartesianMeshTest2D_AllDirichlet, check_min)
135 ASSERT_DOUBLE_EQ(0.1, mesh->min[0]);
136 ASSERT_DOUBLE_EQ(0.05, mesh->min[1]);
137 ASSERT_DOUBLE_EQ(0.0, mesh->min[2]);
141TEST_F(CartesianMeshTest2D_AllDirichlet, check_max)
143 ASSERT_DOUBLE_EQ(5.0, mesh->max[0]);
144 ASSERT_DOUBLE_EQ(1.975, mesh->max[1]);
145 ASSERT_DOUBLE_EQ(1.0, mesh->max[2]);
149TEST_F(CartesianMeshTest2D_AllDirichlet, check_n)
152 {11, 11, 1}, {12, 10, 1}, {1, 1, 1}, {12, 11, 1}, {13, 12, 1}};
154 for (
unsigned int f = 0; f < 5; ++f)
155 for (
unsigned int d = 0; d < 3; ++d) ASSERT_EQ(n[f][d], mesh->n[f][d]);
159TEST_F(CartesianMeshTest2D_AllDirichlet, check_periodic)
162 {PETSC_FALSE, PETSC_FALSE, PETSC_FALSE},
163 {PETSC_FALSE, PETSC_FALSE, PETSC_FALSE}};
165 for (
unsigned int f = 0; f < 3; ++f)
166 for (
unsigned int d = 0; d < 3; ++d)
167 ASSERT_EQ(periodic[f][d], mesh->periodic[f][d]);
171TEST_F(CartesianMeshTest2D_AllDirichlet, check_coord)
174 {{0.1, 0.9, 1.3, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.2, 2.6, 3.4, 5.0},
175 {-0.11875, 0.21875, 0.5, 0.6875, 0.8125, 0.9125, 1.0125, 1.1125,
176 1.2125, 1.3375, 1.525, 1.80625, 2.14375},
178 {{-0.3, 0.5, 1.1, 1.4, 1.55, 1.65, 1.75, 1.85, 1.95, 2.1, 2.4, 3.0, 4.2,
180 {0.05, 0.3875, 0.6125, 0.7625, 0.8625, 0.9625, 1.0625, 1.1625, 1.2625,
181 1.4125, 1.6375, 1.975},
183 {{0.0}, {0.0}, {0.0}},
184 {{0.5, 1.1, 1.4, 1.55, 1.65, 1.75, 1.85, 1.95, 2.1, 2.4, 3.0, 4.2},
185 {0.21875, 0.5, 0.6875, 0.8125, 0.9125, 1.0125, 1.1125, 1.2125, 1.3375,
188 {{0.1, 0.9, 1.3, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.2, 2.6, 3.4, 5.0},
189 {0.05, 0.3875, 0.6125, 0.7625, 0.8625, 0.9625, 1.0625, 1.1625, 1.2625,
190 1.4125, 1.6375, 1.975},
194 {&coordTrue[0][0][1], &coordTrue[0][1][1], &coordTrue[0][2][0]},
195 {&coordTrue[1][0][1], &coordTrue[1][1][1], &coordTrue[1][2][0]},
196 {&coordTrue[2][0][0], &coordTrue[2][1][0], &coordTrue[2][2][0]},
197 {&coordTrue[3][0][0], &coordTrue[3][1][0], &coordTrue[3][2][0]},
198 {&coordTrue[4][0][0], &coordTrue[4][1][0], &coordTrue[4][2][0]},
201 for (
unsigned int f = 0; f < 2; ++f)
203 for (
unsigned int d = 0; d < 2; ++d)
204 for (
int i = -1; i < mesh->n[f][d] + 1; ++i)
205 ASSERT_NEAR(coord[f][d][i], mesh->coord[f][d][i], 1e-12)
206 <<
"dL incorrect at field " << f <<
", direction " << d
207 <<
", index " << i << std::endl;
209 ASSERT_NEAR(coord[f][2][0], mesh->coord[f][2][0], 1e-12)
210 <<
"dL incorrect at field " << f <<
", direction " << 2
211 <<
", index " << 0 << std::endl;
214 for (
unsigned int f = 2; f < 5; ++f)
215 for (
unsigned int d = 0; d < 3; ++d)
216 for (
int i = 0; i < mesh->n[f][d]; ++i)
217 ASSERT_NEAR(coord[f][d][i], mesh->coord[f][d][i], 1e-12)
218 <<
"dL incorrect at field " << f <<
", direction " << d
219 <<
", index " << i << std::endl;
223TEST_F(CartesianMeshTest2D_AllDirichlet, check_dL)
226 {{0.8, 0.6, 0.3, 0.15, 0.1, 0.1, 0.1, 0.1, 0.15, 0.3, 0.6, 1.2, 1.6},
227 {0.3375, 0.3375, 0.225, 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.15, 0.225,
230 {{0.8, 0.8, 0.4, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.2, 0.4, 0.8, 1.6, 1.6},
231 {0.3375, 0.28125, 0.1875, 0.125, 0.1, 0.1, 0.1, 0.1, 0.125, 0.1875,
234 {{1.0}, {1.0}, {1.0}},
235 {{0.8, 0.4, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.2, 0.4, 0.8, 1.6},
236 {0.3375, 0.225, 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.15, 0.225, 0.3375},
238 {{1.0}, {1.0}, {1.0}}};
241 {&dLTrue[0][0][1], &dLTrue[0][1][1], &dLTrue[0][2][0]},
242 {&dLTrue[1][0][1], &dLTrue[1][1][1], &dLTrue[1][2][0]},
243 {&dLTrue[2][0][0], &dLTrue[2][1][0], &dLTrue[2][2][0]},
244 {&dLTrue[3][0][0], &dLTrue[3][1][0], &dLTrue[3][2][0]},
245 {
nullptr,
nullptr,
nullptr}};
247 for (
unsigned int f = 0; f < 2; ++f)
249 for (
unsigned int d = 0; d < 2; ++d)
250 for (
int i = -1; i < mesh->n[f][d] + 1; ++i)
251 ASSERT_NEAR(dL[f][d][i], mesh->dL[f][d][i], 1e-12)
252 <<
"dL incorrect at field " << f <<
", direction " << d
253 <<
", index " << i << std::endl;
255 ASSERT_NEAR(dL[f][2][0], mesh->dL[f][2][0], 1e-12)
256 <<
"dL incorrect at field " << f <<
", direction " << 2
257 <<
", index " << 0 << std::endl;
260 for (
unsigned int f = 2; f < 4; ++f)
261 for (
unsigned int d = 0; d < 3; ++d)
262 for (
int i = 0; i < mesh->n[f][d]; ++i)
263 ASSERT_NEAR(dL[f][d][i], mesh->dL[f][d][i], 1e-12)
264 <<
"dL incorrect at field " << f <<
", direction " << d
265 <<
", index " << i << std::endl;
267 for (
unsigned int d = 0; d < 3; ++d)
268 ASSERT_FALSE(mesh->dL[4][d])
269 <<
"The dL of the vertex mesh is not nullptr." << std::endl;
273TEST_F(CartesianMeshTest2D_AllDirichlet, check_UN)
275 ASSERT_EQ(241, mesh->UN)
276 <<
"The total number of velocity points is not correct." << std::endl;
280TEST_F(CartesianMeshTest2D_AllDirichlet, check_pN)
282 ASSERT_EQ(132, mesh->pN)
283 <<
"The total number of pressure points is not correct." << std::endl;
287TEST_F(CartesianMeshTest2D_AllDirichlet, check_da)
292 ierr = DMGetType(mesh->da[0], &type);
294 ASSERT_STREQ(type, DMDA)
295 <<
"u-velocity mesh is " << type <<
", not expected da" << std::endl;
297 ierr = DMGetType(mesh->da[1], &type);
299 ASSERT_STREQ(type, DMDA)
300 <<
"v-velocity mesh is " << type <<
", not expected da" << std::endl;
302 ierr = DMGetType(mesh->da[3], &type);
304 ASSERT_STREQ(type, DMDA)
305 <<
"v-velocity mesh is " << type <<
", not expected da" << std::endl;
307 ASSERT_FALSE(mesh->da[2])
308 <<
"w-velocity mesh should not be initialized." << std::endl;
309 ASSERT_FALSE(mesh->da[4])
310 <<
"vertex mesh should not be initialized." << std::endl;
314TEST_F(CartesianMeshTest2D_AllDirichlet, check_nProc)
320 ierr = DMDAGetInfo(da[3],
nullptr,
nullptr,
nullptr,
nullptr, &nProc[0],
321 &nProc[1], &nProc[2],
nullptr,
nullptr,
nullptr,
nullptr,
325 ASSERT_EQ(nProc[0], mesh->nProc[0]);
326 ASSERT_EQ(nProc[1], mesh->nProc[1]);
327 ASSERT_EQ(nProc[2], mesh->nProc[2]);
331TEST_F(CartesianMeshTest2D_AllDirichlet, check_bg)
334 for (
unsigned int f = 0; f < 5; f++)
336 if ((f == 2) || (f == 4))
continue;
338 ierr = DMDAGetLocalInfo(da[f], &info);
340 ASSERT_EQ(info.xs, mesh->bg[f][0]) <<
"f = " << f << std::endl;
341 ASSERT_EQ(info.ys, mesh->bg[f][1]) <<
"f = " << f << std::endl;
342 ASSERT_EQ(info.zs, mesh->bg[f][2]) <<
"f = " << f << std::endl;
345 ASSERT_EQ(0, mesh->bg[2][0]) <<
"f = " << 2 << std::endl;
346 ASSERT_EQ(0, mesh->bg[2][1]) <<
"f = " << 2 << std::endl;
347 ASSERT_EQ(0, mesh->bg[2][2]) <<
"f = " << 2 << std::endl;
351TEST_F(CartesianMeshTest2D_AllDirichlet, check_ed)
354 for (
unsigned int f = 0; f < 5; f++)
356 if ((f == 2) || (f == 4))
continue;
358 ierr = DMDAGetLocalInfo(da[f], &info);
360 ASSERT_EQ(info.xs + info.xm, mesh->ed[f][0])
361 <<
"f = " << f << std::endl;
362 ASSERT_EQ(info.ys + info.ym, mesh->ed[f][1])
363 <<
"f = " << f << std::endl;
364 ASSERT_EQ(info.zs + info.zm, mesh->ed[f][2])
365 <<
"f = " << f << std::endl;
368 ASSERT_EQ(1, mesh->ed[2][0]) <<
"f = " << 2 << std::endl;
369 ASSERT_EQ(1, mesh->ed[2][1]) <<
"f = " << 2 << std::endl;
370 ASSERT_EQ(1, mesh->ed[2][2]) <<
"f = " << 2 << std::endl;
374TEST_F(CartesianMeshTest2D_AllDirichlet, check_m)
377 for (
unsigned int f = 0; f < 5; f++)
379 if ((f == 2) || (f == 4))
continue;
381 ierr = DMDAGetLocalInfo(da[f], &info);
383 ASSERT_EQ(info.xm, mesh->m[f][0]) <<
"f = " << f << std::endl;
384 ASSERT_EQ(info.ym, mesh->m[f][1]) <<
"f = " << f << std::endl;
385 ASSERT_EQ(info.zm, mesh->m[f][2]) <<
"f = " << f << std::endl;
388 ASSERT_EQ(0, mesh->m[2][0]) <<
"f = " << 2 << std::endl;
389 ASSERT_EQ(0, mesh->m[2][1]) <<
"f = " << 2 << std::endl;
390 ASSERT_EQ(0, mesh->m[2][2]) <<
"f = " << 2 << std::endl;
394TEST_F(CartesianMeshTest2D_AllDirichlet, check_UNLocal)
396 int N = mesh->m[0][0] * mesh->m[0][1] + mesh->m[1][0] * mesh->m[1][1];
397 ASSERT_EQ(N, mesh->UNLocal);
401TEST_F(CartesianMeshTest2D_AllDirichlet, check_pNLocal)
403 int N = mesh->m[3][0] * mesh->m[3][1];
404 ASSERT_EQ(N, mesh->pNLocal);
408TEST_F(CartesianMeshTest2D_AllDirichlet, check_UPack)
413 ierr = DMGetType(mesh->UPack, &type);
415 ASSERT_STREQ(type, DMCOMPOSITE);
417 DM dms[3]{
nullptr,
nullptr,
nullptr};
418 ierr = DMCompositeGetEntriesArray(mesh->UPack, dms);
420 ASSERT_EQ(dms[0], mesh->da[0]);
421 ASSERT_EQ(dms[1], mesh->da[1]);
422 ASSERT_EQ(dms[2], mesh->da[2]);
424 ierr = DMDestroy(&dms[0]);
426 ierr = DMDestroy(&dms[1]);
431TEST_F(CartesianMeshTest2D_AllDirichlet, check_mpi)
434 PetscMPIInt rank, size;
436 ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size);
438 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
441 ASSERT_EQ(PETSC_COMM_WORLD, mesh->comm);
442 ASSERT_EQ(size, mesh->mpiSize);
443 ASSERT_EQ(rank, mesh->mpiRank);
447TEST_F(CartesianMeshTest2D_AllDirichlet, check_getLocalIndex_ijk)
449 for (
int f = 0; f < 5; ++f)
457 for (
int k = mesh->bg[f][2]; k < mesh->ed[f][2]; k++)
458 for (
int j = mesh->bg[f][1] - 1; j < mesh->ed[f][1] + 1;
460 for (
int i = mesh->bg[f][0] - 1; i < mesh->ed[f][0] + 1;
464 mesh->getLocalIndex(f, i, j, k, idx);
466 PetscInt i2, j2, k2, idx2;
468 i2 = i - mesh->bg[f][0] + 1;
469 j2 = j - mesh->bg[f][1] + 1;
470 k2 = k - mesh->bg[f][2];
472 idx2 = i2 + j2 * (mesh->m[f][0] + 2) +
473 k2 * ((mesh->m[f][0] + 2) *
474 (mesh->m[f][1] + 2));
477 <<
"getLocalIndex wrong at field " << f
478 <<
" and (" << i <<
", " << j <<
", " << k
479 <<
") " << std::endl;
486TEST_F(CartesianMeshTest2D_AllDirichlet, check_getNaturalIndex_ijk)
488 for (
int f = 0; f < 5; ++f)
491 for (
int k = 0; k < mesh->n[f][2]; k++)
492 for (
int j = 0; j < mesh->n[f][1]; j++)
493 for (
int i = 0; i < mesh->n[f][0]; i++)
496 mesh->getNaturalIndex(f, i, j, k, idx);
498 idx2 = i + j * mesh->n[f][0] +
499 k * (mesh->n[f][0] * mesh->n[f][1]);
502 <<
"getNatrualIndex wrong at field " << f <<
" and ("
503 << i <<
", " << j <<
", " << k <<
") " << std::endl;
507 for (
int k = 0; k < mesh->n[f][2]; k++)
508 for (
int i = 0; i < mesh->n[f][0]; i++)
513 mesh->getNaturalIndex(f, i, j, k, idx);
515 <<
"getNatrualIndex wrong at field " << f <<
" and (" << i
516 <<
", " << j <<
", " << k <<
") " << std::endl;
519 mesh->getNaturalIndex(f, i, j, k, idx);
521 <<
"getNatrualIndex wrong at field " << f <<
" and (" << i
522 <<
", " << j <<
", " << k <<
") " << std::endl;
526 for (
int k = 0; k < mesh->n[f][2]; k++)
527 for (
int j = 0; j < mesh->n[f][1]; j++)
532 mesh->getNaturalIndex(f, i, j, k, idx);
534 <<
"getNatrualIndex wrong at field " << f <<
" and (" << i
535 <<
", " << j <<
", " << k <<
") " << std::endl;
538 mesh->getNaturalIndex(f, i, j, k, idx);
540 <<
"getNatrualIndex wrong at field " << f <<
" and (" << i
541 <<
", " << j <<
", " << k <<
") " << std::endl;
545 for (
int k = 0; k < mesh->n[f][2]; k++)
549 mesh->getNaturalIndex(f, -1, -1, 0, idx);
551 <<
"getNatrualIndex wrong at field " << f <<
" and (" << -1
552 <<
", " << -1 <<
", " << k <<
") " << std::endl;
554 mesh->getNaturalIndex(f, -1, mesh->n[f][1], 0, idx);
556 <<
"getNatrualIndex wrong at field " << f <<
" and (" << -1
557 <<
", " << mesh->n[f][1] <<
", " << k <<
") " << std::endl;
559 mesh->getNaturalIndex(f, mesh->n[f][0], -1, 0, idx);
560 ASSERT_EQ(-1, idx) <<
"getNatrualIndex wrong at field " << f
561 <<
" and (" << mesh->n[f][0] <<
", " << -1
562 <<
", " << k <<
") " << std::endl;
564 mesh->getNaturalIndex(f, mesh->n[f][0], mesh->n[f][1], 0, idx);
566 <<
"getNatrualIndex wrong at field " << f <<
" and ("
567 << mesh->n[f][0] <<
", " << mesh->n[f][1] <<
", " << k <<
") "
574TEST_F(CartesianMeshTest2D_AllDirichlet, check_getGlobalIndex_ijk_internal)
576 for (
int f = 0; f < 5; ++f)
578 if ((f == 2) || (f == 4))
continue;
582 ISLocalToGlobalMapping mapping;
583 ierr = DMGetLocalToGlobalMapping(mesh->da[f], &mapping);
586 Vec vini, vinj, vink;
587 ierr = DMGetGlobalVector(mesh->da[f], &vini);
589 ierr = DMGetGlobalVector(mesh->da[f], &vinj);
591 ierr = DMGetGlobalVector(mesh->da[f], &vink);
594 for (
int k = mesh->bg[f][2]; k < mesh->ed[f][2]; k++)
595 for (
int j = mesh->bg[f][1]; j < mesh->ed[f][1]; j++)
596 for (
int i = mesh->bg[f][0]; i < mesh->ed[f][0]; i++)
600 ierr = DMDAConvertToCell(mesh->da[f], {k, j, i, 0}, &idx);
602 ierr = ISLocalToGlobalMappingApply(mapping, 1, &idx, &idx);
605 ierr = VecSetValue(vini, idx, i, INSERT_VALUES);
607 ierr = VecSetValue(vinj, idx, j, INSERT_VALUES);
609 ierr = VecSetValue(vink, idx, k, INSERT_VALUES);
612 ierr = VecAssemblyBegin(vini);
614 ierr = VecAssemblyBegin(vinj);
616 ierr = VecAssemblyBegin(vink);
618 ierr = VecAssemblyEnd(vini);
620 ierr = VecAssemblyEnd(vinj);
622 ierr = VecAssemblyEnd(vink);
625 Vec vouti, voutj, voutk;
627 ierr = VecScatterCreateToAll(vini, &ctx, &vouti);
629 ierr = VecDuplicate(vouti, &voutj);
631 ierr = VecDuplicate(vouti, &voutk);
634 VecScatterBegin(ctx, vini, vouti, INSERT_VALUES, SCATTER_FORWARD);
636 ierr = VecScatterEnd(ctx, vini, vouti, INSERT_VALUES, SCATTER_FORWARD);
639 VecScatterBegin(ctx, vinj, voutj, INSERT_VALUES, SCATTER_FORWARD);
641 ierr = VecScatterEnd(ctx, vinj, voutj, INSERT_VALUES, SCATTER_FORWARD);
644 VecScatterBegin(ctx, vink, voutk, INSERT_VALUES, SCATTER_FORWARD);
646 ierr = VecScatterEnd(ctx, vink, voutk, INSERT_VALUES, SCATTER_FORWARD);
650 for (
int k = 0; k < mesh->n[f][2]; k++)
651 for (
int j = 0; j < mesh->n[f][1]; j++)
652 for (
int i = 0; i < mesh->n[f][0]; i++)
655 ierr = mesh->getGlobalIndex(f, i, j, k, idx);
658 PetscReal vi, vj, vk;
659 ierr = VecGetValues(vouti, 1, &idx, &vi);
661 ierr = VecGetValues(voutj, 1, &idx, &vj);
663 ierr = VecGetValues(voutk, 1, &idx, &vk);
666 ASSERT_EQ(vi, PetscReal(i));
667 ASSERT_EQ(vj, PetscReal(j));
668 ASSERT_EQ(vk, PetscReal(k));
671 ierr = VecScatterDestroy(&ctx);
673 ierr = VecDestroy(&voutk);
675 ierr = VecDestroy(&voutj);
677 ierr = VecDestroy(&vouti);
679 ierr = VecDestroy(&vink);
681 ierr = VecDestroy(&vinj);
683 ierr = VecDestroy(&vini);
690 mapping = PETSC_NULL;
695TEST_F(CartesianMeshTest2D_AllDirichlet, check_getGlobalIndex_ijk_ghosts)
697 for (
int f = 0; f < 5; ++f)
699 if ((f == 2) || (f == 4))
continue;
702 for (
int k = 0; k < mesh->n[f][2]; k++)
703 for (
int i = 0; i < mesh->n[f][0]; i++)
708 mesh->getGlobalIndex(f, i, j, k, idx);
710 <<
"getGlobalIndex wrong at field " << f <<
" and (" << i
711 <<
", " << j <<
", " << k <<
") " << std::endl;
714 mesh->getGlobalIndex(f, i, j, k, idx);
716 <<
"getGlobalIndex wrong at field " << f <<
" and (" << i
717 <<
", " << j <<
", " << k <<
") " << std::endl;
721 for (
int k = 0; k < mesh->n[f][2]; k++)
722 for (
int j = 0; j < mesh->n[f][1]; j++)
727 mesh->getGlobalIndex(f, i, j, k, idx);
729 <<
"getGlobalIndex wrong at field " << f <<
" and (" << i
730 <<
", " << j <<
", " << k <<
") " << std::endl;
733 mesh->getGlobalIndex(f, i, j, k, idx);
735 <<
"getGlobalIndex wrong at field " << f <<
" and (" << i
736 <<
", " << j <<
", " << k <<
") " << std::endl;
740 for (
int k = 0; k < mesh->n[f][2]; k++)
744 mesh->getGlobalIndex(f, -1, -1, 0, idx);
746 <<
"getGlobalIndex wrong at field " << f <<
" and (" << -1
747 <<
", " << -1 <<
", " << k <<
") " << std::endl;
749 mesh->getGlobalIndex(f, -1, mesh->n[f][1], 0, idx);
751 <<
"getGlobalIndex wrong at field " << f <<
" and (" << -1
752 <<
", " << mesh->n[f][1] <<
", " << k <<
") " << std::endl;
754 mesh->getGlobalIndex(f, mesh->n[f][0], -1, 0, idx);
755 ASSERT_EQ(-1, idx) <<
"getGlobalIndex wrong at field " << f
756 <<
" and (" << mesh->n[f][0] <<
", " << -1
757 <<
", " << k <<
") " << std::endl;
759 mesh->getGlobalIndex(f, mesh->n[f][0], mesh->n[f][1], 0, idx);
761 <<
"getGlobalIndex wrong at field " << f <<
" and ("
762 << mesh->n[f][0] <<
", " << mesh->n[f][1] <<
", " << k <<
") "
770 check_getPackedGlobalIndex_ijk_internal)
776 ierr = DMCompositeCreate(PETSC_COMM_WORLD, &UPack);
778 ierr = DMCompositeAddDM(UPack, da[0]);
780 ierr = DMCompositeAddDM(UPack, da[1]);
782 ierr = DMSetUp(UPack);
786 ierr = DMCreateGlobalVector(mesh->UPack, &fp);
788 ierr = DMCreateGlobalVector(mesh->UPack, &ip);
790 ierr = DMCreateGlobalVector(mesh->UPack, &jp);
792 ierr = DMCreateGlobalVector(mesh->UPack, &kp);
795 Vec fv[2], iv[2], jv[2], kv[2];
796 ierr = DMCompositeGetAccessArray(mesh->UPack, fp, 2,
nullptr, fv);
798 ierr = DMCompositeGetAccessArray(mesh->UPack, ip, 2,
nullptr, iv);
800 ierr = DMCompositeGetAccessArray(mesh->UPack, jp, 2,
nullptr, jv);
802 ierr = DMCompositeGetAccessArray(mesh->UPack, kp, 2,
nullptr, kv);
805 for (
int f = 0; f < 2; ++f)
807 ISLocalToGlobalMapping mapping;
808 ierr = DMGetLocalToGlobalMapping(mesh->da[f], &mapping);
811 for (
int k = mesh->bg[f][2]; k < mesh->ed[f][2]; ++k)
812 for (
int j = mesh->bg[f][1]; j < mesh->ed[f][1]; ++j)
813 for (
int i = mesh->bg[f][0]; i < mesh->ed[f][0]; ++i)
816 ierr = DMDAConvertToCell(mesh->da[f], {k, j, i, 0}, &idx);
818 ierr = ISLocalToGlobalMappingApply(mapping, 1, &idx, &idx);
821 ierr = VecSetValue(fv[f], idx, (PetscReal)f, INSERT_VALUES);
823 ierr = VecSetValue(iv[f], idx, (PetscReal)i, INSERT_VALUES);
825 ierr = VecSetValue(jv[f], idx, (PetscReal)j, INSERT_VALUES);
827 ierr = VecSetValue(kv[f], idx, (PetscReal)k, INSERT_VALUES);
831 ierr = VecAssemblyBegin(fv[f]);
833 ierr = VecAssemblyBegin(iv[f]);
835 ierr = VecAssemblyBegin(jv[f]);
837 ierr = VecAssemblyBegin(kv[f]);
839 ierr = VecAssemblyEnd(fv[f]);
841 ierr = VecAssemblyEnd(iv[f]);
843 ierr = VecAssemblyEnd(jv[f]);
845 ierr = VecAssemblyEnd(kv[f]);
848 ierr = ISLocalToGlobalMappingDestroy(&mapping);
852 ierr = DMCompositeRestoreAccessArray(mesh->UPack, fp, 2,
nullptr, fv);
854 ierr = DMCompositeRestoreAccessArray(mesh->UPack, ip, 2,
nullptr, iv);
856 ierr = DMCompositeRestoreAccessArray(mesh->UPack, jp, 2,
nullptr, jv);
858 ierr = DMCompositeRestoreAccessArray(mesh->UPack, kp, 2,
nullptr, kv);
862 Vec fps, ips, jps, kps;
864 ierr = VecScatterCreateToAll(fp, &ctx, &fps);
866 ierr = VecDuplicate(fps, &ips);
868 ierr = VecDuplicate(fps, &jps);
870 ierr = VecDuplicate(fps, &kps);
873 ierr = VecScatterBegin(ctx, fp, fps, INSERT_VALUES, SCATTER_FORWARD);
875 ierr = VecScatterEnd(ctx, fp, fps, INSERT_VALUES, SCATTER_FORWARD);
877 ierr = VecScatterBegin(ctx, ip, ips, INSERT_VALUES, SCATTER_FORWARD);
879 ierr = VecScatterEnd(ctx, ip, ips, INSERT_VALUES, SCATTER_FORWARD);
881 ierr = VecScatterBegin(ctx, jp, jps, INSERT_VALUES, SCATTER_FORWARD);
883 ierr = VecScatterEnd(ctx, jp, jps, INSERT_VALUES, SCATTER_FORWARD);
885 ierr = VecScatterBegin(ctx, kp, kps, INSERT_VALUES, SCATTER_FORWARD);
887 ierr = VecScatterEnd(ctx, kp, kps, INSERT_VALUES, SCATTER_FORWARD);
890 ierr = VecScatterDestroy(&ctx);
892 ierr = VecDestroy(&kp);
894 ierr = VecDestroy(&jp);
896 ierr = VecDestroy(&ip);
898 ierr = VecDestroy(&fp);
901 for (
int f = 0; f < 2; ++f)
904 for (
int k = 0; k < mesh->n[f][2]; k++)
905 for (
int j = 0; j < mesh->n[f][1]; j++)
906 for (
int i = 0; i < mesh->n[f][0]; i++)
909 ierr = mesh->getPackedGlobalIndex(f, i, j, k, idx);
912 PetscReal vf, vi, vj, vk;
913 ierr = VecGetValues(fps, 1, &idx, &vf);
915 ierr = VecGetValues(ips, 1, &idx, &vi);
917 ierr = VecGetValues(jps, 1, &idx, &vj);
919 ierr = VecGetValues(kps, 1, &idx, &vk);
922 ASSERT_EQ(vf, f) << f <<
".(" << i <<
", " << j <<
", " << k
924 ASSERT_EQ(vi, i) << f <<
".(" << i <<
", " << j <<
", " << k
926 ASSERT_EQ(vj, j) << f <<
".(" << i <<
", " << j <<
", " << k
928 ASSERT_EQ(vk, k) << f <<
".(" << i <<
", " << j <<
", " << k
933 ierr = VecDestroy(&kps);
935 ierr = VecDestroy(&jps);
937 ierr = VecDestroy(&ips);
939 ierr = VecDestroy(&fps);
944TEST_F(CartesianMeshTest2D_AllDirichlet, check_getPackedGlobalIndex_ijk_ghost)
946 for (
int f = 0; f < 2; ++f)
949 for (
int k = 0; k < mesh->n[f][2]; k++)
950 for (
int i = 0; i < mesh->n[f][0]; i++)
955 mesh->getPackedGlobalIndex(f, i, j, k, idx);
957 <<
"getPackedGlobalIndex wrong at field " << f <<
" and ("
958 << i <<
", " << j <<
", " << k <<
") " << std::endl;
961 mesh->getPackedGlobalIndex(f, i, j, k, idx);
963 <<
"getPackedGlobalIndex wrong at field " << f <<
" and ("
964 << i <<
", " << j <<
", " << k <<
") " << std::endl;
968 for (
int k = 0; k < mesh->n[f][2]; k++)
969 for (
int j = 0; j < mesh->n[f][1]; j++)
974 mesh->getPackedGlobalIndex(f, i, j, k, idx);
976 <<
"getPackedGlobalIndex wrong at field " << f <<
" and ("
977 << i <<
", " << j <<
", " << k <<
") " << std::endl;
980 mesh->getPackedGlobalIndex(f, i, j, k, idx);
982 <<
"getPackedGlobalIndex wrong at field " << f <<
" and ("
983 << i <<
", " << j <<
", " << k <<
") " << std::endl;
987 for (
int k = 0; k < mesh->n[f][2]; k++)
991 mesh->getPackedGlobalIndex(f, -1, -1, 0, idx);
993 <<
"getPackedGlobalIndex wrong at field " << f <<
" and (" << -1
994 <<
", " << -1 <<
", " << k <<
") " << std::endl;
996 mesh->getPackedGlobalIndex(f, -1, mesh->n[f][1], 0, idx);
998 <<
"getPackedGlobalIndex wrong at field " << f <<
" and (" << -1
999 <<
", " << mesh->n[f][1] <<
", " << k <<
") " << std::endl;
1001 mesh->getPackedGlobalIndex(f, mesh->n[f][0], -1, 0, idx);
1002 ASSERT_EQ(-1, idx) <<
"getPackedGlobalIndex wrong at field " << f
1003 <<
" and (" << mesh->n[f][0] <<
", " << -1
1004 <<
", " << k <<
") " << std::endl;
1006 mesh->getPackedGlobalIndex(f, mesh->n[f][0], mesh->n[f][1], 0, idx);
1008 <<
"getPackedGlobalIndex wrong at field " << f <<
" and ("
1009 << mesh->n[f][0] <<
", " << mesh->n[f][1] <<
", " << k <<
") "
TEST_F(CartesianMeshTest2D_AllDirichlet, check_dim)
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< BoolVec1D > BoolVec2D
2D std::vector holding PetscBool.
std::vector< RealVec1D > RealVec2D
2D std::vector holding PetscReal.
std::vector< RealVec2D > RealVec3D
3D std::vector holding PetscReal.
Prototype of mesh::MeshBase, type::Mesh, and factory function.
std::vector< GhostedVec2D > GhostedVec3D
a vector of vector pointers to mimic ghosted 2D vectors. type