10#include <gtest/gtest.h>
11#include <yaml-cpp/yaml.h>
15class CartesainMeshTest2D_YPeriodic :
public ::testing::Test
18 CartesainMeshTest2D_YPeriodic(){};
20 virtual ~CartesainMeshTest2D_YPeriodic(){};
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 < 2; ++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;
71 for (
unsigned int i = 2; i < 4; ++i)
73 config[
"flow"][
"boundaryConditions"][i][
"u"][0] =
"PERIODIC";
74 config[
"flow"][
"boundaryConditions"][i][
"u"][1] = 0.0;
75 config[
"flow"][
"boundaryConditions"][i][
"v"][0] =
"PERIODIC";
76 config[
"flow"][
"boundaryConditions"][i][
"v"][1] = 0.0;
79 config[
"flow"][
"boundaryConditions"][3][
"u"][1] = 1.0;
87 ierr = DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED,
88 DM_BOUNDARY_GHOSTED, DMDA_STENCIL_BOX, 12, 11,
89 PETSC_DECIDE, PETSC_DECIDE, 1, 1,
nullptr,
nullptr,
92 ierr = DMSetUp(da[3]);
95 ierr = DMDAGetInfo(da[3],
nullptr,
nullptr,
nullptr,
nullptr, &nProc[0],
96 &nProc[1], &nProc[2],
nullptr,
nullptr,
nullptr,
97 nullptr,
nullptr,
nullptr);
100 ierr = DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED,
101 DM_BOUNDARY_GHOSTED, DMDA_STENCIL_BOX, 11, 11,
102 nProc[0], nProc[1], 1, 1,
nullptr,
nullptr, &da[0]);
104 ierr = DMSetUp(da[0]);
107 ierr = DMDACreate2d(PETSC_COMM_WORLD, DM_BOUNDARY_GHOSTED,
108 DM_BOUNDARY_GHOSTED, DMDA_STENCIL_BOX, 12, 11,
109 nProc[0], nProc[1], 1, 1,
nullptr,
nullptr, &da[1]);
111 ierr = DMSetUp(da[1]);
115 virtual void SetUp(){};
117 virtual void TearDown(){};
119 static void TearDownTestCase()
122 ierr = DMDestroy(&da[0]);
124 ierr = DMDestroy(&da[1]);
126 ierr = DMDestroy(&da[3]);
135DM CartesainMeshTest2D_YPeriodic::da[5]{
nullptr,
nullptr,
nullptr,
nullptr,
139TEST_F(CartesainMeshTest2D_YPeriodic, check_dim) { ASSERT_EQ(2, mesh->dim); }
142TEST_F(CartesainMeshTest2D_YPeriodic, check_min)
144 ASSERT_DOUBLE_EQ(0.1, mesh->min[0]);
145 ASSERT_DOUBLE_EQ(0.05, mesh->min[1]);
146 ASSERT_DOUBLE_EQ(0.0, mesh->min[2]);
150TEST_F(CartesainMeshTest2D_YPeriodic, check_max)
152 ASSERT_DOUBLE_EQ(5.0, mesh->max[0]);
153 ASSERT_DOUBLE_EQ(1.975, mesh->max[1]);
154 ASSERT_DOUBLE_EQ(1.0, mesh->max[2]);
158TEST_F(CartesainMeshTest2D_YPeriodic, check_n)
161 {11, 11, 1}, {12, 11, 1}, {1, 1, 1}, {12, 11, 1}, {13, 12, 1}};
163 for (
unsigned int f = 0; f < 5; ++f)
164 for (
unsigned int d = 0; d < 3; ++d) ASSERT_EQ(n[f][d], mesh->n[f][d]);
168TEST_F(CartesainMeshTest2D_YPeriodic, check_periodic)
171 {PETSC_FALSE, PETSC_TRUE, PETSC_FALSE},
172 {PETSC_FALSE, PETSC_FALSE, PETSC_FALSE}};
174 for (
unsigned int f = 0; f < 3; ++f)
175 for (
unsigned int d = 0; d < 3; ++d)
176 ASSERT_EQ(periodic[f][d], mesh->periodic[f][d]);
180TEST_F(CartesainMeshTest2D_YPeriodic, check_coord)
183 {{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},
184 {-0.11875, 0.21875, 0.5, 0.6875, 0.8125, 0.9125, 1.0125, 1.1125,
185 1.2125, 1.3375, 1.525, 1.80625, 2.14375},
187 {{-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,
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, 2.3125},
192 {{0.0}, {0.0}, {0.0}},
193 {{0.5, 1.1, 1.4, 1.55, 1.65, 1.75, 1.85, 1.95, 2.1, 2.4, 3.0, 4.2},
194 {0.21875, 0.5, 0.6875, 0.8125, 0.9125, 1.0125, 1.1125, 1.2125, 1.3375,
197 {{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},
198 {0.05, 0.3875, 0.6125, 0.7625, 0.8625, 0.9625, 1.0625, 1.1625, 1.2625,
199 1.4125, 1.6375, 1.975},
203 {&coordTrue[0][0][1], &coordTrue[0][1][1], &coordTrue[0][2][0]},
204 {&coordTrue[1][0][1], &coordTrue[1][1][1], &coordTrue[1][2][0]},
205 {&coordTrue[2][0][0], &coordTrue[2][1][0], &coordTrue[2][2][0]},
206 {&coordTrue[3][0][0], &coordTrue[3][1][0], &coordTrue[3][2][0]},
207 {&coordTrue[4][0][0], &coordTrue[4][1][0], &coordTrue[4][2][0]},
210 for (
unsigned int f = 0; f < 2; ++f)
212 for (
unsigned int d = 0; d < 2; ++d)
213 for (
int i = -1; i < mesh->n[f][d] + 1; ++i)
214 ASSERT_NEAR(coord[f][d][i], mesh->coord[f][d][i], 1e-12)
215 <<
"dL incorrect at field " << f <<
", direction " << d
216 <<
", index " << i << std::endl;
218 ASSERT_NEAR(coord[f][2][0], mesh->coord[f][2][0], 1e-12)
219 <<
"dL incorrect at field " << f <<
", direction " << 2
220 <<
", index " << 0 << std::endl;
223 for (
unsigned int f = 2; f < 5; ++f)
224 for (
unsigned int d = 0; d < 3; ++d)
225 for (
int i = 0; i < mesh->n[f][d]; ++i)
226 ASSERT_NEAR(coord[f][d][i], mesh->coord[f][d][i], 1e-12)
227 <<
"dL incorrect at field " << f <<
", direction " << d
228 <<
", index " << i << std::endl;
232TEST_F(CartesainMeshTest2D_YPeriodic, check_dL)
235 {{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},
236 {0.3375, 0.3375, 0.225, 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.15, 0.225,
239 {{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},
240 {0.3375, 0.28125, 0.1875, 0.125, 0.1, 0.1, 0.1, 0.1, 0.125, 0.1875,
241 0.28125, 0.3375, 0.28125},
243 {{1.0}, {1.0}, {1.0}},
244 {{0.8, 0.4, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.2, 0.4, 0.8, 1.6},
245 {0.3375, 0.225, 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.15, 0.225, 0.3375},
247 {{1.0}, {1.0}, {1.0}}};
250 {&dLTrue[0][0][1], &dLTrue[0][1][1], &dLTrue[0][2][0]},
251 {&dLTrue[1][0][1], &dLTrue[1][1][1], &dLTrue[1][2][0]},
252 {&dLTrue[2][0][0], &dLTrue[2][1][0], &dLTrue[2][2][0]},
253 {&dLTrue[3][0][0], &dLTrue[3][1][0], &dLTrue[3][2][0]},
254 {
nullptr,
nullptr,
nullptr}};
256 for (
unsigned int f = 0; f < 2; ++f)
258 for (
unsigned int d = 0; d < 2; ++d)
259 for (
int i = -1; i < mesh->n[f][d] + 1; ++i)
260 ASSERT_NEAR(dL[f][d][i], mesh->dL[f][d][i], 1e-12)
261 <<
"dL incorrect at field " << f <<
", direction " << d
262 <<
", index " << i << std::endl;
264 ASSERT_NEAR(dL[f][2][0], mesh->dL[f][2][0], 1e-12)
265 <<
"dL incorrect at field " << f <<
", direction " << 2
266 <<
", index " << 0 << std::endl;
269 for (
unsigned int f = 2; f < 4; ++f)
270 for (
unsigned int d = 0; d < 3; ++d)
271 for (
int i = 0; i < mesh->n[f][d]; ++i)
272 ASSERT_NEAR(dL[f][d][i], mesh->dL[f][d][i], 1e-12)
273 <<
"dL incorrect at field " << f <<
", direction " << d
274 <<
", index " << i << std::endl;
276 for (
unsigned int d = 0; d < 3; ++d)
277 ASSERT_FALSE(mesh->dL[4][d])
278 <<
"The dL of the vertex mesh is not nullptr." << std::endl;
282TEST_F(CartesainMeshTest2D_YPeriodic, check_UN)
284 ASSERT_EQ(253, mesh->UN)
285 <<
"The total number of velocity points is not correct." << std::endl;
289TEST_F(CartesainMeshTest2D_YPeriodic, check_pN)
291 ASSERT_EQ(132, mesh->pN)
292 <<
"The total number of pressure points is not correct." << std::endl;
296TEST_F(CartesainMeshTest2D_YPeriodic, check_da)
301 ierr = DMGetType(mesh->da[0], &type);
303 ASSERT_STREQ(type, DMDA)
304 <<
"u-velocity mesh is " << type <<
", not expected da" << std::endl;
306 ierr = DMGetType(mesh->da[1], &type);
308 ASSERT_STREQ(type, DMDA)
309 <<
"v-velocity mesh is " << type <<
", not expected da" << std::endl;
311 ierr = DMGetType(mesh->da[3], &type);
313 ASSERT_STREQ(type, DMDA)
314 <<
"v-velocity mesh is " << type <<
", not expected da" << std::endl;
316 ASSERT_FALSE(mesh->da[2])
317 <<
"w-velocity mesh should not be initialized." << std::endl;
318 ASSERT_FALSE(mesh->da[4])
319 <<
"vertex mesh should not be initialized." << std::endl;
323TEST_F(CartesainMeshTest2D_YPeriodic, check_nProc)
329 ierr = DMDAGetInfo(da[3],
nullptr,
nullptr,
nullptr,
nullptr, &nProc[0],
330 &nProc[1], &nProc[2],
nullptr,
nullptr,
nullptr,
nullptr,
334 ASSERT_EQ(nProc[0], mesh->nProc[0]);
335 ASSERT_EQ(nProc[1], mesh->nProc[1]);
336 ASSERT_EQ(nProc[2], mesh->nProc[2]);
340TEST_F(CartesainMeshTest2D_YPeriodic, check_bg)
343 for (
unsigned int f = 0; f < 5; f++)
345 if ((f == 2) || (f == 4))
continue;
347 ierr = DMDAGetLocalInfo(da[f], &info);
349 ASSERT_EQ(info.xs, mesh->bg[f][0]) <<
"f = " << f << std::endl;
350 ASSERT_EQ(info.ys, mesh->bg[f][1]) <<
"f = " << f << std::endl;
351 ASSERT_EQ(info.zs, mesh->bg[f][2]) <<
"f = " << f << std::endl;
354 ASSERT_EQ(0, mesh->bg[2][0]) <<
"f = " << 2 << std::endl;
355 ASSERT_EQ(0, mesh->bg[2][1]) <<
"f = " << 2 << std::endl;
356 ASSERT_EQ(0, mesh->bg[2][2]) <<
"f = " << 2 << std::endl;
360TEST_F(CartesainMeshTest2D_YPeriodic, check_ed)
363 for (
unsigned int f = 0; f < 5; f++)
365 if ((f == 2) || (f == 4))
continue;
367 ierr = DMDAGetLocalInfo(da[f], &info);
369 ASSERT_EQ(info.xs + info.xm, mesh->ed[f][0])
370 <<
"f = " << f << std::endl;
371 ASSERT_EQ(info.ys + info.ym, mesh->ed[f][1])
372 <<
"f = " << f << std::endl;
373 ASSERT_EQ(info.zs + info.zm, mesh->ed[f][2])
374 <<
"f = " << f << std::endl;
377 ASSERT_EQ(1, mesh->ed[2][0]) <<
"f = " << 2 << std::endl;
378 ASSERT_EQ(1, mesh->ed[2][1]) <<
"f = " << 2 << std::endl;
379 ASSERT_EQ(1, mesh->ed[2][2]) <<
"f = " << 2 << std::endl;
383TEST_F(CartesainMeshTest2D_YPeriodic, check_m)
386 for (
unsigned int f = 0; f < 5; f++)
388 if ((f == 2) || (f == 4))
continue;
390 ierr = DMDAGetLocalInfo(da[f], &info);
392 ASSERT_EQ(info.xm, mesh->m[f][0]) <<
"f = " << f << std::endl;
393 ASSERT_EQ(info.ym, mesh->m[f][1]) <<
"f = " << f << std::endl;
394 ASSERT_EQ(info.zm, mesh->m[f][2]) <<
"f = " << f << std::endl;
397 ASSERT_EQ(0, mesh->m[2][0]) <<
"f = " << 2 << std::endl;
398 ASSERT_EQ(0, mesh->m[2][1]) <<
"f = " << 2 << std::endl;
399 ASSERT_EQ(0, mesh->m[2][2]) <<
"f = " << 2 << std::endl;
403TEST_F(CartesainMeshTest2D_YPeriodic, check_UNLocal)
405 int N = mesh->m[0][0] * mesh->m[0][1] + mesh->m[1][0] * mesh->m[1][1];
406 ASSERT_EQ(N, mesh->UNLocal);
410TEST_F(CartesainMeshTest2D_YPeriodic, check_pNLocal)
412 int N = mesh->m[3][0] * mesh->m[3][1];
413 ASSERT_EQ(N, mesh->pNLocal);
417TEST_F(CartesainMeshTest2D_YPeriodic, check_UPack)
422 ierr = DMGetType(mesh->UPack, &type);
424 ASSERT_STREQ(type, DMCOMPOSITE);
426 DM dms[3]{
nullptr,
nullptr,
nullptr};
427 ierr = DMCompositeGetEntriesArray(mesh->UPack, dms);
429 ASSERT_EQ(dms[0], mesh->da[0]);
430 ASSERT_EQ(dms[1], mesh->da[1]);
431 ASSERT_EQ(dms[2], mesh->da[2]);
433 ierr = DMDestroy(&dms[0]);
435 ierr = DMDestroy(&dms[1]);
440TEST_F(CartesainMeshTest2D_YPeriodic, check_mpi)
443 PetscMPIInt rank, size;
445 ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size);
447 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
450 ASSERT_EQ(PETSC_COMM_WORLD, mesh->comm);
451 ASSERT_EQ(size, mesh->mpiSize);
452 ASSERT_EQ(rank, mesh->mpiRank);
456TEST_F(CartesainMeshTest2D_YPeriodic, check_getLocalIndex_ijk)
458 for (
int f = 0; f < 5; ++f)
466 for (
int k = mesh->bg[f][2]; k < mesh->ed[f][2]; k++)
467 for (
int j = mesh->bg[f][1] - 1; j < mesh->ed[f][1] + 1;
469 for (
int i = mesh->bg[f][0] - 1; i < mesh->ed[f][0] + 1;
473 mesh->getLocalIndex(f, i, j, k, idx);
475 PetscInt i2, j2, k2, idx2;
477 i2 = i - mesh->bg[f][0] + 1;
478 j2 = j - mesh->bg[f][1] + 1;
479 k2 = k - mesh->bg[f][2];
481 idx2 = i2 + j2 * (mesh->m[f][0] + 2) +
482 k2 * ((mesh->m[f][0] + 2) *
483 (mesh->m[f][1] + 2));
486 <<
"getLocalIndex wrong at field " << f
487 <<
" and (" << i <<
", " << j <<
", " << k
488 <<
") " << std::endl;
495TEST_F(CartesainMeshTest2D_YPeriodic, check_getNaturalIndex_ijk)
497 for (
int f = 0; f < 5; ++f)
500 for (
int k = 0; k < mesh->n[f][2]; k++)
501 for (
int j = 0; j < mesh->n[f][1]; j++)
502 for (
int i = 0; i < mesh->n[f][0]; i++)
505 mesh->getNaturalIndex(f, i, j, k, idx);
507 idx2 = i + j * mesh->n[f][0] +
508 k * (mesh->n[f][0] * mesh->n[f][1]);
511 <<
"getNatrualIndex wrong at field " << f
512 <<
" and internal points (" << i <<
", " << j <<
", "
513 << k <<
") " << std::endl;
517 for (
int k = 0; k < mesh->n[f][2]; k++)
518 for (
int i = 0; i < mesh->n[f][0]; i++)
520 PetscInt idx, idx2, j;
523 mesh->getNaturalIndex(f, i, j, k, idx);
524 idx2 = i + k * (mesh->n[f][0] * mesh->n[f][1]);
525 ASSERT_EQ(idx2, idx) <<
"getNatrualIndex wrong at field " << f
526 <<
" and top ghost point (" << i <<
", "
527 << j <<
", " << k <<
") " << std::endl;
530 mesh->getNaturalIndex(f, i, j, k, idx);
531 idx2 = i + (mesh->n[f][1] - 1) * mesh->n[f][0] +
532 k * (mesh->n[f][0] * mesh->n[f][1]);
533 ASSERT_EQ(idx2, idx) <<
"getNatrualIndex wrong at field " << f
534 <<
" and bottom ghost point (" << i <<
", "
535 << j <<
", " << k <<
") " << std::endl;
539 for (
int k = 0; k < mesh->n[f][2]; k++)
540 for (
int j = 0; j < mesh->n[f][1]; j++)
545 mesh->getNaturalIndex(f, i, j, k, idx);
546 ASSERT_EQ(-1, idx) <<
"getNatrualIndex wrong at field " << f
547 <<
" and right ghost point (" << i <<
", "
548 << j <<
", " << k <<
") " << std::endl;
551 mesh->getNaturalIndex(f, i, j, k, idx);
552 ASSERT_EQ(-1, idx) <<
"getNatrualIndex wrong at field " << f
553 <<
" and left ghost point (" << i <<
", "
554 << j <<
", " << k <<
") " << std::endl;
558 for (
int k = 0; k < mesh->n[f][2]; k++)
562 mesh->getNaturalIndex(f, -1, -1, 0, idx);
563 ASSERT_EQ(-1, idx) <<
"getNatrualIndex wrong at field " << f
564 <<
" and corner ghost point (" << -1 <<
", "
565 << -1 <<
", " << k <<
") " << std::endl;
567 mesh->getNaturalIndex(f, -1, mesh->n[f][1], 0, idx);
569 <<
"getNatrualIndex wrong at field " << f
570 <<
" and corner ghost point (" << -1 <<
", " << mesh->n[f][1]
571 <<
", " << k <<
") " << std::endl;
573 mesh->getNaturalIndex(f, mesh->n[f][0], -1, 0, idx);
574 ASSERT_EQ(-1, idx) <<
"getNatrualIndex wrong at field " << f
575 <<
" and corner ghost point (" << mesh->n[f][0]
576 <<
", " << -1 <<
", " << k <<
") " << std::endl;
578 mesh->getNaturalIndex(f, mesh->n[f][0], mesh->n[f][1], 0, idx);
580 <<
"getNatrualIndex wrong at field " << f
581 <<
" and corner ghost point (" << mesh->n[f][0] <<
", "
582 << mesh->n[f][1] <<
", " << k <<
") " << std::endl;
588TEST_F(CartesainMeshTest2D_YPeriodic, check_getGlobalIndex_ijk_internal)
590 for (
int f = 0; f < 5; ++f)
592 if ((f == 2) || (f == 4))
continue;
596 ISLocalToGlobalMapping mapping;
597 ierr = DMGetLocalToGlobalMapping(mesh->da[f], &mapping);
600 Vec vini, vinj, vink;
601 ierr = DMGetGlobalVector(mesh->da[f], &vini);
603 ierr = DMGetGlobalVector(mesh->da[f], &vinj);
605 ierr = DMGetGlobalVector(mesh->da[f], &vink);
608 for (
int k = mesh->bg[f][2]; k < mesh->ed[f][2]; k++)
609 for (
int j = mesh->bg[f][1]; j < mesh->ed[f][1]; j++)
610 for (
int i = mesh->bg[f][0]; i < mesh->ed[f][0]; i++)
614 ierr = DMDAConvertToCell(mesh->da[f], {k, j, i, 0}, &idx);
616 ierr = ISLocalToGlobalMappingApply(mapping, 1, &idx, &idx);
619 ierr = VecSetValue(vini, idx, i, INSERT_VALUES);
621 ierr = VecSetValue(vinj, idx, j, INSERT_VALUES);
623 ierr = VecSetValue(vink, idx, k, INSERT_VALUES);
626 ierr = VecAssemblyBegin(vini);
628 ierr = VecAssemblyBegin(vinj);
630 ierr = VecAssemblyBegin(vink);
632 ierr = VecAssemblyEnd(vini);
634 ierr = VecAssemblyEnd(vinj);
636 ierr = VecAssemblyEnd(vink);
639 Vec vouti, voutj, voutk;
641 ierr = VecScatterCreateToAll(vini, &ctx, &vouti);
643 ierr = VecDuplicate(vouti, &voutj);
645 ierr = VecDuplicate(vouti, &voutk);
648 VecScatterBegin(ctx, vini, vouti, INSERT_VALUES, SCATTER_FORWARD);
650 ierr = VecScatterEnd(ctx, vini, vouti, INSERT_VALUES, SCATTER_FORWARD);
653 VecScatterBegin(ctx, vinj, voutj, INSERT_VALUES, SCATTER_FORWARD);
655 ierr = VecScatterEnd(ctx, vinj, voutj, INSERT_VALUES, SCATTER_FORWARD);
658 VecScatterBegin(ctx, vink, voutk, INSERT_VALUES, SCATTER_FORWARD);
660 ierr = VecScatterEnd(ctx, vink, voutk, INSERT_VALUES, SCATTER_FORWARD);
664 for (
int k = 0; k < mesh->n[f][2]; k++)
665 for (
int j = 0; j < mesh->n[f][1]; j++)
666 for (
int i = 0; i < mesh->n[f][0]; i++)
669 ierr = mesh->getGlobalIndex(f, i, j, k, idx);
672 PetscReal vi, vj, vk;
673 ierr = VecGetValues(vouti, 1, &idx, &vi);
675 ierr = VecGetValues(voutj, 1, &idx, &vj);
677 ierr = VecGetValues(voutk, 1, &idx, &vk);
680 ASSERT_EQ(vi, PetscReal(i));
681 ASSERT_EQ(vj, PetscReal(j));
682 ASSERT_EQ(vk, PetscReal(k));
685 ierr = VecScatterDestroy(&ctx);
687 ierr = VecDestroy(&voutk);
689 ierr = VecDestroy(&voutj);
691 ierr = VecDestroy(&vouti);
693 ierr = VecDestroy(&vink);
695 ierr = VecDestroy(&vinj);
697 ierr = VecDestroy(&vini);
704 mapping = PETSC_NULL;
709TEST_F(CartesainMeshTest2D_YPeriodic, check_getGlobalIndex_ijk_ghosts)
711 for (
int f = 0; f < 5; ++f)
713 if ((f == 2) || (f == 4))
continue;
716 for (
int k = 0; k < mesh->n[f][2]; k++)
717 for (
int i = 0; i < mesh->n[f][0]; i++)
719 PetscInt idx, idx2, j;
722 mesh->getGlobalIndex(f, i, j, k, idx);
725 mesh->getGlobalIndex(f, i, 0, k, idx2);
727 <<
"getGlobalIndex wrong at field " << f <<
" and (" << i
728 <<
", " << j <<
", " << k <<
") " << std::endl;
731 mesh->getGlobalIndex(f, i, j, k, idx);
734 mesh->getGlobalIndex(f, i, mesh->n[f][1] - 1, k, idx2);
736 <<
"getGlobalIndex wrong at field " << f <<
" and (" << i
737 <<
", " << j <<
", " << k <<
") " << std::endl;
741 for (
int k = 0; k < mesh->n[f][2]; k++)
742 for (
int j = 0; j < mesh->n[f][1]; j++)
747 mesh->getGlobalIndex(f, i, j, k, idx);
749 <<
"getGlobalIndex wrong at field " << f <<
" and (" << i
750 <<
", " << j <<
", " << k <<
") " << std::endl;
753 mesh->getGlobalIndex(f, i, j, k, idx);
755 <<
"getGlobalIndex wrong at field " << f <<
" and (" << i
756 <<
", " << j <<
", " << k <<
") " << std::endl;
760 for (
int k = 0; k < mesh->n[f][2]; k++)
764 mesh->getGlobalIndex(f, -1, -1, 0, idx);
766 <<
"getGlobalIndex wrong at field " << f <<
" and (" << -1
767 <<
", " << -1 <<
", " << k <<
") " << std::endl;
769 mesh->getGlobalIndex(f, -1, mesh->n[f][1], 0, idx);
771 <<
"getGlobalIndex wrong at field " << f <<
" and (" << -1
772 <<
", " << mesh->n[f][1] <<
", " << k <<
") " << std::endl;
774 mesh->getGlobalIndex(f, mesh->n[f][0], -1, 0, idx);
775 ASSERT_EQ(-1, idx) <<
"getGlobalIndex wrong at field " << f
776 <<
" and (" << mesh->n[f][0] <<
", " << -1
777 <<
", " << k <<
") " << std::endl;
779 mesh->getGlobalIndex(f, mesh->n[f][0], mesh->n[f][1], 0, idx);
781 <<
"getGlobalIndex wrong at field " << f <<
" and ("
782 << mesh->n[f][0] <<
", " << mesh->n[f][1] <<
", " << k <<
") "
789TEST_F(CartesainMeshTest2D_YPeriodic, check_getPackedGlobalIndex_ijk_internal)
795 ierr = DMCompositeCreate(PETSC_COMM_WORLD, &UPack);
797 ierr = DMCompositeAddDM(UPack, da[0]);
799 ierr = DMCompositeAddDM(UPack, da[1]);
801 ierr = DMSetUp(UPack);
805 ierr = DMCreateGlobalVector(mesh->UPack, &fp);
807 ierr = DMCreateGlobalVector(mesh->UPack, &ip);
809 ierr = DMCreateGlobalVector(mesh->UPack, &jp);
811 ierr = DMCreateGlobalVector(mesh->UPack, &kp);
814 Vec fv[2], iv[2], jv[2], kv[2];
815 ierr = DMCompositeGetAccessArray(mesh->UPack, fp, 2,
nullptr, fv);
817 ierr = DMCompositeGetAccessArray(mesh->UPack, ip, 2,
nullptr, iv);
819 ierr = DMCompositeGetAccessArray(mesh->UPack, jp, 2,
nullptr, jv);
821 ierr = DMCompositeGetAccessArray(mesh->UPack, kp, 2,
nullptr, kv);
824 for (
int f = 0; f < 2; ++f)
826 ISLocalToGlobalMapping mapping;
827 ierr = DMGetLocalToGlobalMapping(mesh->da[f], &mapping);
830 for (
int k = mesh->bg[f][2]; k < mesh->ed[f][2]; ++k)
831 for (
int j = mesh->bg[f][1]; j < mesh->ed[f][1]; ++j)
832 for (
int i = mesh->bg[f][0]; i < mesh->ed[f][0]; ++i)
835 ierr = DMDAConvertToCell(mesh->da[f], {k, j, i, 0}, &idx);
837 ierr = ISLocalToGlobalMappingApply(mapping, 1, &idx, &idx);
840 ierr = VecSetValue(fv[f], idx, (PetscReal)f, INSERT_VALUES);
842 ierr = VecSetValue(iv[f], idx, (PetscReal)i, INSERT_VALUES);
844 ierr = VecSetValue(jv[f], idx, (PetscReal)j, INSERT_VALUES);
846 ierr = VecSetValue(kv[f], idx, (PetscReal)k, INSERT_VALUES);
850 ierr = VecAssemblyBegin(fv[f]);
852 ierr = VecAssemblyBegin(iv[f]);
854 ierr = VecAssemblyBegin(jv[f]);
856 ierr = VecAssemblyBegin(kv[f]);
858 ierr = VecAssemblyEnd(fv[f]);
860 ierr = VecAssemblyEnd(iv[f]);
862 ierr = VecAssemblyEnd(jv[f]);
864 ierr = VecAssemblyEnd(kv[f]);
867 ierr = ISLocalToGlobalMappingDestroy(&mapping);
871 ierr = DMCompositeRestoreAccessArray(mesh->UPack, fp, 2,
nullptr, fv);
873 ierr = DMCompositeRestoreAccessArray(mesh->UPack, ip, 2,
nullptr, iv);
875 ierr = DMCompositeRestoreAccessArray(mesh->UPack, jp, 2,
nullptr, jv);
877 ierr = DMCompositeRestoreAccessArray(mesh->UPack, kp, 2,
nullptr, kv);
881 Vec fps, ips, jps, kps;
883 ierr = VecScatterCreateToAll(fp, &ctx, &fps);
885 ierr = VecDuplicate(fps, &ips);
887 ierr = VecDuplicate(fps, &jps);
889 ierr = VecDuplicate(fps, &kps);
892 ierr = VecScatterBegin(ctx, fp, fps, INSERT_VALUES, SCATTER_FORWARD);
894 ierr = VecScatterEnd(ctx, fp, fps, INSERT_VALUES, SCATTER_FORWARD);
896 ierr = VecScatterBegin(ctx, ip, ips, INSERT_VALUES, SCATTER_FORWARD);
898 ierr = VecScatterEnd(ctx, ip, ips, INSERT_VALUES, SCATTER_FORWARD);
900 ierr = VecScatterBegin(ctx, jp, jps, INSERT_VALUES, SCATTER_FORWARD);
902 ierr = VecScatterEnd(ctx, jp, jps, INSERT_VALUES, SCATTER_FORWARD);
904 ierr = VecScatterBegin(ctx, kp, kps, INSERT_VALUES, SCATTER_FORWARD);
906 ierr = VecScatterEnd(ctx, kp, kps, INSERT_VALUES, SCATTER_FORWARD);
909 ierr = VecScatterDestroy(&ctx);
911 ierr = VecDestroy(&kp);
913 ierr = VecDestroy(&jp);
915 ierr = VecDestroy(&ip);
917 ierr = VecDestroy(&fp);
920 for (
int f = 0; f < 2; ++f)
923 for (
int k = 0; k < mesh->n[f][2]; k++)
924 for (
int j = 0; j < mesh->n[f][1]; j++)
925 for (
int i = 0; i < mesh->n[f][0]; i++)
928 ierr = mesh->getPackedGlobalIndex(f, i, j, k, idx);
931 PetscReal vf, vi, vj, vk;
932 ierr = VecGetValues(fps, 1, &idx, &vf);
934 ierr = VecGetValues(ips, 1, &idx, &vi);
936 ierr = VecGetValues(jps, 1, &idx, &vj);
938 ierr = VecGetValues(kps, 1, &idx, &vk);
941 ASSERT_EQ(vf, f) << f <<
".(" << i <<
", " << j <<
", " << k
943 ASSERT_EQ(vi, i) << f <<
".(" << i <<
", " << j <<
", " << k
945 ASSERT_EQ(vj, j) << f <<
".(" << i <<
", " << j <<
", " << k
947 ASSERT_EQ(vk, k) << f <<
".(" << i <<
", " << j <<
", " << k
952 ierr = VecDestroy(&kps);
954 ierr = VecDestroy(&jps);
956 ierr = VecDestroy(&ips);
958 ierr = VecDestroy(&fps);
963TEST_F(CartesainMeshTest2D_YPeriodic, check_getPackedGlobalIndex_ijk_ghost)
965 for (
int f = 0; f < 2; ++f)
968 for (
int k = 0; k < mesh->n[f][2]; k++)
969 for (
int i = 0; i < mesh->n[f][0]; i++)
971 PetscInt idx, idx2, j;
974 mesh->getPackedGlobalIndex(f, i, j, k, idx);
977 mesh->getPackedGlobalIndex(f, i, 0, k, idx2);
979 <<
"getPackedGlobalIndex wrong at field " << f <<
" and ("
980 << i <<
", " << j <<
", " << k <<
") " << std::endl;
983 mesh->getPackedGlobalIndex(f, i, j, k, idx);
986 mesh->getPackedGlobalIndex(f, i, mesh->n[f][1] - 1, k, idx2);
988 <<
"getPackedGlobalIndex wrong at field " << f <<
" and ("
989 << i <<
", " << j <<
", " << k <<
") " << std::endl;
993 for (
int k = 0; k < mesh->n[f][2]; k++)
994 for (
int j = 0; j < mesh->n[f][1]; j++)
999 mesh->getPackedGlobalIndex(f, i, j, k, idx);
1001 <<
"getPackedGlobalIndex wrong at field " << f <<
" and ("
1002 << i <<
", " << j <<
", " << k <<
") " << std::endl;
1005 mesh->getPackedGlobalIndex(f, i, j, k, idx);
1007 <<
"getPackedGlobalIndex wrong at field " << f <<
" and ("
1008 << i <<
", " << j <<
", " << k <<
") " << std::endl;
1012 for (
int k = 0; k < mesh->n[f][2]; k++)
1016 mesh->getPackedGlobalIndex(f, -1, -1, 0, idx);
1018 <<
"getPackedGlobalIndex wrong at field " << f <<
" and (" << -1
1019 <<
", " << -1 <<
", " << k <<
") " << std::endl;
1021 mesh->getPackedGlobalIndex(f, -1, mesh->n[f][1], 0, idx);
1023 <<
"getPackedGlobalIndex wrong at field " << f <<
" and (" << -1
1024 <<
", " << mesh->n[f][1] <<
", " << k <<
") " << std::endl;
1026 mesh->getPackedGlobalIndex(f, mesh->n[f][0], -1, 0, idx);
1027 ASSERT_EQ(-1, idx) <<
"getPackedGlobalIndex wrong at field " << f
1028 <<
" and (" << mesh->n[f][0] <<
", " << -1
1029 <<
", " << k <<
") " << std::endl;
1031 mesh->getPackedGlobalIndex(f, mesh->n[f][0], mesh->n[f][1], 0, idx);
1033 <<
"getPackedGlobalIndex wrong at field " << f <<
" and ("
1034 << mesh->n[f][0] <<
", " << mesh->n[f][1] <<
", " << k <<
") "
TEST_F(CartesainMeshTest2D_YPeriodic, 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