Debian Codegraph @

packages/panzer/adapters-stk/test/panzer_workset_builder/check_rotation_matrices.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 using Teuchos::RCP;
17 using Teuchos::rcp;
18
19 #include "Teuchos_DefaultComm.hpp"
20 #include "Teuchos_GlobalMPISession.hpp"
21
22 #include "Panzer_STK_Version.hpp"
23 #include "PanzerAdaptersSTK_config.hpp"
24
25 #include "Panzer_WorksetContainer.hpp"
26 #include "Panzer_WorksetDescriptor.hpp"
27 #include "Panzer_WorksetNeeds.hpp"
28 #include "Panzer_IntrepidBasisFactory.hpp"
29 #include "Panzer_IntegrationDescriptor.hpp"
30 #include "Panzer_DOFManager.hpp"
31 #include "Panzer_SubcellConnectivity.hpp"
32
33 #include "Panzer_STK_Interface.hpp"
34 #include "Panzer_STK_CubeHexMeshFactory.hpp"
35 #include "Panzer_STKConnManager.hpp"
36 #include "Panzer_STK_WorksetFactory.hpp"
37
38 namespace panzer {
39
40 TEUCHOS_UNIT_TEST(check_rotation_matrices, basic)
41 {
42 using Teuchos::RCP;
43 using Teuchos::rcp;
44
45 typedef Intrepid2::Basis<PHX::Device::execution_space,double,double> IntrepidBasis;
46
47 std::string element_block = "eblock-0_0_0";
48 std::string sideset = "left";
49
50 RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList);
51 pl->set("X Elements",1);
52 pl->set("Y Elements",1);
53 pl->set("Z Elements",1);
54 pl->set("X0",-0.001);
55 pl->set("Xf", 0.001);
56 pl->set("Y0",-0.0005);
57 pl->set("Yf", 0.0005);
58 pl->set("Z0",-0.0003333333333333333);
59 pl->set("Zf", 0.0003333333333333333);
60
61 panzer_stk::CubeHexMeshFactory factory;
62 factory.setParameterList(pl);
63 RCP<panzer_stk::STK_Interface> mesh = factory.buildMesh(MPI_COMM_WORLD);
64 RCP<const Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD));
65
66 // build DOF Manager (with a single HDiv basis)
67 /////////////////////////////////////////////////////////////
68
69 // build the connection manager
70 const RCP<panzer::ConnManager>
71 conn_manager = rcp(new panzer_stk::STKConnManager(mesh));
72
73 RCP<panzer::DOFManager> dof_manager
74 = rcp(new panzer::DOFManager(conn_manager,MPI_COMM_WORLD));
75
76 // build an intrepid basis and a related field pattern for seeding the DOFManager
77 {
78 RCP<IntrepidBasis> intrepid_basis
79 = panzer::createIntrepid2Basis<PHX::Device::execution_space,double,double>("HGrad",1,
80 *mesh->getCellTopology(element_block));
81 RCP<panzer::Intrepid2FieldPattern> field_pattern = rcp(new panzer::Intrepid2FieldPattern(intrepid_basis));
82
83 dof_manager->addField(element_block, "T", field_pattern);
84 }
85 dof_manager->buildGlobalUnknowns();
86
87 // build WorksetContainer
88 //////////////////////////////////////////////////////////////
89
90 panzer::IntegrationDescriptor sid(2*2, panzer::IntegrationDescriptor::SURFACE);
91
92 RCP<panzer_stk::WorksetFactory> wkstFactory
93 = rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory
94 RCP<panzer::WorksetContainer> wkstContainer // attach it to a workset container (uses lazy evaluation)
95 = rcp(new panzer::WorksetContainer(wkstFactory));
96
97 wkstContainer->setGlobalIndexer(dof_manager);
98
99 panzer::WorksetDescriptor workset_descriptor(element_block, panzer::WorksetSizeType::ALL_ELEMENTS, true,false);
100
101 auto worksets = wkstContainer->getWorksets(workset_descriptor);
102
103 TEST_ASSERT(worksets->size()==1);
104
105 auto & workset = (*worksets)[0];
106
107 auto rot_matrices = workset.getIntegrationValues(sid).getSurfaceRotationMatrices();
108 auto normals = workset.getIntegrationValues(sid).getSurfaceNormals();
109
110 const int num_owned_cells = workset.numOwnedCells();
111 const int num_ghost_cells = workset.numGhostCells();
112 const int num_real_cells = num_owned_cells + num_ghost_cells;
113 const int num_virtual_cells = workset.numVirtualCells();
114 const int num_cells = num_real_cells + num_virtual_cells;
115
116 const int faces_per_cell = 6; // hexahedron
117 auto & face_connectivity = workset.getFaceConnectivity();
118
119 // sanity check on cell counts: should have 6 virtual, 1 owned
120 TEST_EQUALITY(num_owned_cells, 1);
121 TEST_EQUALITY(num_ghost_cells, 0);
122 TEST_EQUALITY(num_virtual_cells, 6);
123
124 TEST_ASSERT(rot_matrices.rank()==4);
125 TEST_ASSERT(rot_matrices.extent_int(0)==num_cells);
126 TEST_ASSERT(rot_matrices.extent_int(2)==3);
127 TEST_ASSERT(rot_matrices.extent_int(3)==3);
128 out << "SIZES = "
129 << rot_matrices.extent(0) << " "
130 << rot_matrices.extent(1) << " "
131 << rot_matrices.extent(2) << " "
132 << rot_matrices.extent(3) << std::endl;
133
134 out << std::endl;
135
136 const int num_points = rot_matrices.extent_int(1);
137 const int points_per_face = num_points / faces_per_cell;
138 for(int c=0;c<rot_matrices.extent_int(0);c++) {
139 // rule for virtual cells is that they have rotation matrices defined only on local face ordinal 0;
140 // the rotation matrices for the other faces of the virtual cell should be all 0s.
141 const bool is_virtual = (c >= num_real_cells);
142 int virtual_local_face_id = -1; // the virtual cell face that adjoins the real cell
143
144 if (is_virtual)
145 {
146 // determine which face adjoins the real cell:
147 int face_ordinal = -1;
148 for (int local_face_id=0; local_face_id<faces_per_cell; local_face_id++)
149 {
150 face_ordinal = face_connectivity.subcellForCellHost(c, local_face_id);
151 if (face_ordinal >= 0)
152 {
153 virtual_local_face_id = local_face_id;
154 break;
155 }
156 }
157 }
158
159 auto rot_matrices_view = PHX::as_view(rot_matrices);
160 auto rot_matrices_h = Kokkos::create_mirror_view(rot_matrices_view);
161 Kokkos::deep_copy(rot_matrices_h, rot_matrices_view);
162
163 for(int p=0;p<num_points;p++) {
164 const int local_face_ordinal = p / points_per_face;
165 bool expect_rotation_matrix = true; // if false, we expect all 0s
166 if (is_virtual)
167 {
168 expect_rotation_matrix = (local_face_ordinal == virtual_local_face_id);
169 }
170 out << "Cell,Point = " << c << "," << p << std::endl;
171 out << " " << rot_matrices_h(c,p,0,0) << " " << rot_matrices_h(c,p,0,1) << " " << rot_matrices_h(c,p,0,2) << std::endl;
172 out << " " << rot_matrices_h(c,p,1,0) << " " << rot_matrices_h(c,p,1,1) << " " << rot_matrices_h(c,p,1,2) << std::endl;
173 out << " " << rot_matrices_h(c,p,2,0) << " " << rot_matrices_h(c,p,2,1) << " " << rot_matrices_h(c,p,2,2) << std::endl;
174 out << std::endl;
175
176 if (expect_rotation_matrix)
177 {
178 // mutually orthogonal
179 TEST_ASSERT(std::fabs(rot_matrices_h(c,p,0,0) * rot_matrices_h(c,p,1,0) +
180 rot_matrices_h(c,p,0,1) * rot_matrices_h(c,p,1,1) +
181 rot_matrices_h(c,p,0,2) * rot_matrices_h(c,p,1,2))<=1e-14);
182 TEST_ASSERT(std::fabs(rot_matrices_h(c,p,0,0) * rot_matrices_h(c,p,2,0) +
183 rot_matrices_h(c,p,0,1) * rot_matrices_h(c,p,2,1) +
184 rot_matrices_h(c,p,0,2) * rot_matrices_h(c,p,2,2))<=1e-14);
185 TEST_ASSERT(std::fabs(rot_matrices_h(c,p,1,0) * rot_matrices_h(c,p,2,0) +
186 rot_matrices_h(c,p,1,1) * rot_matrices_h(c,p,2,1) +
187 rot_matrices_h(c,p,1,2) * rot_matrices_h(c,p,2,2))<=1e-14);
188
189 // normalized
190 TEST_FLOATING_EQUALITY(std::sqrt(rot_matrices_h(c,p,0,0) * rot_matrices_h(c,p,0,0) +
191 rot_matrices_h(c,p,0,1) * rot_matrices_h(c,p,0,1) +
192 rot_matrices_h(c,p,0,2) * rot_matrices_h(c,p,0,2)),1.0,1e-14);
193 TEST_FLOATING_EQUALITY(std::sqrt(rot_matrices_h(c,p,1,0) * rot_matrices_h(c,p,1,0) +
194 rot_matrices_h(c,p,1,1) * rot_matrices_h(c,p,1,1) +
195 rot_matrices_h(c,p,1,2) * rot_matrices_h(c,p,1,2)),1.0,1e-14);
196 TEST_FLOATING_EQUALITY(std::sqrt(rot_matrices_h(c,p,2,0) * rot_matrices_h(c,p,2,0) +
197 rot_matrices_h(c,p,2,1) * rot_matrices_h(c,p,2,1) +
198 rot_matrices_h(c,p,2,2) * rot_matrices_h(c,p,2,2)),1.0,1e-14);
199 }
200 else
201 {
202 // virtual cell on a face other than local face 0: expect zeros
203 for (int i=0; i<3; i++)
204 {
205 for (int j=0; j<3; j++)
206 {
207 // since these should be filled in as exact machine 0s, we do non-floating comparison
208 TEST_EQUALITY(rot_matrices_h(c,p,i,j), 0.0);
209 }
210 }
211 }
212 }
213 }
214 }
215 }