Debian Codegraph @

packages/panzer/disc-fe/test/local_mesh/setup_sublocal_mesh_info.cpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10
11 #include <Teuchos_ConfigDefs.hpp>
12 #include <Teuchos_UnitTestHarness.hpp>
13 #include <Teuchos_RCP.hpp>
14 #include <Teuchos_TimeMonitor.hpp>
15
16 #include "PanzerCore_config.hpp"
17
18 #include "Panzer_LocalMeshInfo.hpp"
19 #include "Panzer_LocalPartitioningUtilities.hpp"
20
21 #include "Panzer_UnitTest_LocalMeshUtilities.hpp"
22
23 #include <vector>
24 #include <string>
25 #include <iostream>
26
27 namespace panzer {
28
29 TEUCHOS_UNIT_TEST(setupSubLocalMeshInfo, basic)
30 {
31
32 // Make sure passing the function an empty parent info throws an error
33 {
34 Teuchos::RCP<panzer::LocalMeshInfoBase> mesh(new panzer::LocalMeshInfoBase);
35 std::vector<panzer::LocalOrdinal> local_cells = {0};
36 panzer::LocalMeshInfoBase sub_mesh;
37
38 TEST_THROW(partitioning_utilities::setupSubLocalMeshInfo(*mesh,local_cells,sub_mesh),std::logic_error);
39 }
40
41 // Make sure passing the function an empty set of cells throws an error
42 {
43 Teuchos::RCP<panzer::LocalMeshInfoBase> mesh = generateLocalMeshInfoBase();
44 std::vector<panzer::LocalOrdinal> local_cells = {};
45 panzer::LocalMeshInfoBase sub_mesh;
46
47 TEST_THROW(partitioning_utilities::setupSubLocalMeshInfo(*mesh,local_cells,sub_mesh),std::logic_error);
48 }
49
50 // Make sure that we can grab a couple of the cells as a local mesh
51 {
52 Teuchos::RCP<panzer::LocalMeshInfoBase> mesh = generateLocalMeshInfoBase();
53
54 // Skip cell 1 to make it a ghost cell
55 std::vector<panzer::LocalOrdinal> n_local_cells = {0,2};
56 panzer::LocalMeshInfoBase sub_mesh;
57
58 partitioning_utilities::setupSubLocalMeshInfo(*mesh,n_local_cells,sub_mesh);
59
60 TEST_EQUALITY(sub_mesh.num_owned_cells,2);
61 TEST_EQUALITY(sub_mesh.num_ghstd_cells,2);
62 TEST_EQUALITY(sub_mesh.num_virtual_cells,1);
63
64 // The following is just an analysis of the sub mesh
65 // If any of these fail after changing the setupSubLocalMeshInfo call, it may not be because the changes were wrong.
66 // It may just be a different ordering compared to what is currently expected (that is 100% OK, this test just needs to be updated).
67
68
69 // What we had in 'mesh'
70 // g o o o v
71 // ---------------------
72 // | 3 | 0 | 1 | 2 | 4 |
73 // ---------------------
74 // 0 1 2 3
75
76 // What we expect in 'sub_mesh'
77 // g o g o v
78 // ---------------------
79 // | 3 | 0 | 2 | 1 | 4 |
80 // ---------------------
81 // 3 2 1 0
82
83 auto local_cells = Kokkos::create_mirror_view(sub_mesh.local_cells);
84 auto global_cells = Kokkos::create_mirror_view(sub_mesh.global_cells);
85 auto face_to_cells = Kokkos::create_mirror_view(sub_mesh.face_to_cells);
86 auto face_to_lidx = Kokkos::create_mirror_view(sub_mesh.face_to_lidx);
87 auto cell_to_faces = Kokkos::create_mirror_view(sub_mesh.cell_to_faces);
88 Kokkos::deep_copy(local_cells , sub_mesh.local_cells);
89 Kokkos::deep_copy(global_cells , sub_mesh.global_cells);
90 Kokkos::deep_copy(face_to_cells, sub_mesh.face_to_cells);
91 Kokkos::deep_copy(face_to_lidx , sub_mesh.face_to_lidx);
92 Kokkos::deep_copy(cell_to_faces, sub_mesh.cell_to_faces);
93 TEST_EQUALITY(local_cells(0),0);
94 TEST_EQUALITY(local_cells(1),2);
95 TEST_EQUALITY(local_cells(2),1);
96 TEST_EQUALITY(local_cells(3),3);
97 TEST_EQUALITY(local_cells(4),4);
98
99 TEST_EQUALITY(global_cells(0),8);
100 TEST_EQUALITY(global_cells(1),2);
101 TEST_EQUALITY(global_cells(2),6);
102 TEST_EQUALITY(global_cells(3),1);
103 TEST_EQUALITY(global_cells(4),9);
104
105 TEST_EQUALITY(face_to_cells(0,0),1);
106 TEST_EQUALITY(face_to_cells(0,1),4);
107 TEST_EQUALITY(face_to_cells(1,0),1);
108 TEST_EQUALITY(face_to_cells(1,1),2);
109 TEST_EQUALITY(face_to_cells(2,0),0);
110 TEST_EQUALITY(face_to_cells(2,1),2);
111 TEST_EQUALITY(face_to_cells(3,0),0);
112 TEST_EQUALITY(face_to_cells(3,1),3);
113
114 TEST_EQUALITY(face_to_lidx(0,0),1);
115 TEST_EQUALITY(face_to_lidx(0,1),0);
116 TEST_EQUALITY(face_to_lidx(1,0),0);
117 TEST_EQUALITY(face_to_lidx(1,1),1);
118 TEST_EQUALITY(face_to_lidx(2,0),1);
119 TEST_EQUALITY(face_to_lidx(2,1),0);
120 TEST_EQUALITY(face_to_lidx(3,0),0);
121 TEST_EQUALITY(face_to_lidx(3,1),0);
122
123 TEST_EQUALITY(cell_to_faces(0,0),3);
124 TEST_EQUALITY(cell_to_faces(0,1),2);
125 TEST_EQUALITY(cell_to_faces(1,0),1);
126 TEST_EQUALITY(cell_to_faces(1,1),0);
127 TEST_EQUALITY(cell_to_faces(2,0),2);
128 TEST_EQUALITY(cell_to_faces(2,1),1);
129 TEST_EQUALITY(cell_to_faces(3,0),3);
130 TEST_EQUALITY(cell_to_faces(3,1),-1);
131 TEST_EQUALITY(cell_to_faces(4,0),0);
132 TEST_EQUALITY(cell_to_faces(4,1),-1);
133
134 }
135 }
136
137 } // end namespace panzer