Debian Codegraph @

packages/panzer/adapters-stk/test/panzer_workset_builder/parallel_apply_orientations.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 "Teuchos_DefaultComm.hpp"
17 #include "Teuchos_GlobalMPISession.hpp"
18
19 #include "Panzer_STK_Version.hpp"
20 #include "PanzerAdaptersSTK_config.hpp"
21
22 #include "Panzer_WorksetContainer.hpp"
23 #include "Panzer_IntrepidBasisFactory.hpp"
24 #include "Panzer_DOFManager.hpp"
25 #include "Panzer_OrientationsInterface.hpp"
26
27 #include "Panzer_STK_Interface.hpp"
28 #include "Panzer_STK_SquareQuadMeshFactory.hpp"
29 #include "Panzer_STKConnManager.hpp"
30 #include "Panzer_STK_WorksetFactory.hpp"
31
32 namespace panzer {
33 namespace {
34
35 void
36 testApplyOrientations(const bool by_container,
37 const bool by_factory,
38 const bool use_needs,
39 const bool should_fail,
40 Teuchos::FancyOStream & out,
41 bool & success)
42 {
43 // In this test we want to create a simple 2 cell 2D mesh
44 // of quads which share a center face.
45 // If orientations are not applied, then the HDiv 1 basis will have an orientation (vector)
46 // on the interface that points outward from the cell center.
47 // If orientations are applied, then both vectors will point in the same direction.
48
49 auto comm = Teuchos::DefaultComm<int>::getComm();
50 const int rank = comm->getRank();
51
52 // Only works if we have 2 processors
53 TEST_EQUALITY(comm->getSize(), 2);
54
55 // So that I don't spell the name wrong later
56 const std::string element_block = "eblock-0_0";
57
58 // Basis has a single vector per face
59 const panzer::BasisDescriptor basis(1, "HDiv");
60
61 // Integrator has a single point per face
62 const panzer::IntegrationDescriptor integrator(0, panzer::IntegrationDescriptor::SURFACE);
63
64 // Create mesh
65 Teuchos::RCP<panzer_stk::STK_Interface> mesh;
66 {
67 // Each cell is 2x2 (same as reference cell)
68 auto pl = Teuchos::rcp(new Teuchos::ParameterList);
69 pl->set("X Elements",2);
70 pl->set("Y Elements",1);
71 pl->set("X0",-2.0);
72 pl->set("Xf", 2.0);
73 pl->set("Y0",-1.0);
74 pl->set("Yf", 1.0);
75
76 panzer_stk::SquareQuadMeshFactory factory;
77 factory.setParameterList(pl);
78 mesh = factory.buildMesh(MPI_COMM_WORLD);
79 }
80
81 // Need a dof manager to act as a global indexer
82 Teuchos::RCP<panzer::DOFManager> dof_manager;
83 {
84
85 // Build a connectivity manager for the given mesh
86 const auto conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager(mesh));
87
88 // Initialize the dof manager with the conn manager
89 dof_manager = Teuchos::rcp(new panzer::DOFManager(conn_manager,MPI_COMM_WORLD));
90
91 // Build an intrepid basis and a related field pattern for seeding the DOFManager
92 {
93 const auto & cell_topology = *mesh->getCellTopology(element_block);
94 auto intrepid_basis = panzer::createIntrepid2Basis<PHX::Device::execution_space,double,double>(basis.getType(),basis.getOrder(), cell_topology);
95 auto field_pattern = Teuchos::rcp(new panzer::Intrepid2FieldPattern(intrepid_basis));
96
97 // Add arbitrary field to dof manager to lock in the field pattern
98 dof_manager->addField(element_block, "B", field_pattern);
99 }
100
101 // Finalize the dof manager
102 dof_manager->buildGlobalUnknowns();
103 }
104
105 // Create a needs map
106 std::map<std::string, WorksetNeeds> needs_map;
107 needs_map[element_block].addBasis(basis);
108 needs_map[element_block].addIntegrator(integrator);
109
110 // Build a workset container
111 Teuchos::RCP<WorksetContainer> workset_container;
112 {
113 // Build workset factory
114 auto factory = Teuchos::rcp(new panzer_stk::WorksetFactory(mesh));
115
116 if(by_factory)
117 factory->setOrientationsInterface(Teuchos::rcp(new OrientationsInterface(dof_manager)));
118
119 if(use_needs)
120 workset_container = Teuchos::rcp(new WorksetContainer(factory, needs_map));
121 else
122 workset_container = Teuchos::rcp(new WorksetContainer(factory, {}));
123
124 if(by_container)
125 workset_container->setGlobalIndexer(dof_manager);
126 }
127
128 // Grab the one and only workset
129 auto worksets = workset_container->getWorksets(WorksetDescriptor(element_block, WorksetSizeType::ALL_ELEMENTS, true, by_container));
130 TEST_EQUALITY(worksets->size(), 1);
131
132 const auto & workset = (*worksets)[0];
133 const auto & basis_values = workset.getBasisValues(basis,integrator);
134
135 // Check to see if the basis values actually has orientations applied
136 if(by_factory or by_container){
137 TEST_ASSERT(basis_values.orientationsApplied());
138 } else {
139 TEST_ASSERT(not basis_values.orientationsApplied());
140 }
141
142 // Grab the basis values vector for the given integration points
143 const auto basis_vector_device = basis_values.getVectorBasisValues(false).get_static_view();
144 auto basis_vector = Kokkos::create_mirror_view(basis_vector_device);
145 Kokkos::deep_copy(basis_vector,basis_vector_device);
146
147 // Note that this is for a partitioned workset, which will have 1 owned cells, 1 ghost cell, and 3 virtual cells for a total of 5 cells
148 TEST_EQUALITY(basis_vector.extent_int(0),5); // cells
149 TEST_EQUALITY(basis_vector.extent_int(1),4); // basis
150 TEST_EQUALITY(basis_vector.extent_int(2),4); // points
151 TEST_EQUALITY(basis_vector.extent_int(3),2); // vector dim
152
153 // Print out the vector values to see what they are
154 out << "Basis Values:\n";
155 for(int c=0; c<2; ++c)
156 for(int b=0; b<4; ++b)
157 for(int p=0; p<4; ++p)
158 out << c << ", " << b << ", " << p << ": ["<<basis_vector(c,b,p,0)<<", "<<basis_vector(c,b,p,1)<<"]\n";
159
160 // We are going to make the interface between cell 0 (owned) and 1 (ghost)
161 // The basis function associated with that interface is (cell,basis) (0,1) and (1,3)
162 // Points are aligned with basis, so (cell,point) are also (0,1) and (1,3)
163 // Note that on rank 1, the cells are reversed
164
165 double normal_0[2] = {0}, normal_1[2] = {0};
166 if(rank==0){
167 normal_0[0] = basis_vector(0,1,1,0);
168 normal_0[1] = basis_vector(0,1,1,1);
169 normal_1[0] = basis_vector(1,3,3,0);
170 normal_1[1] = basis_vector(1,3,3,1);
171 } else {
172 normal_0[0] = basis_vector(0,3,1,0);
173 normal_0[1] = basis_vector(0,3,1,1);
174 normal_1[0] = basis_vector(1,1,3,0);
175 normal_1[1] = basis_vector(1,1,3,1);
176 }
177
178 const double vec[2] = {normal_0[0]+normal_1[0], normal_0[1]+normal_1[1]};
179
180 if(should_fail){
181 // The vectors oppose each other (1,0)+(-1,0), so the magnitude should be 0
182 TEUCHOS_ASSERT(vec[0]*vec[0]+vec[1]*vec[1] < 1.e-8);
183 } else {
184 // The vectors are the same (1,0)+(1,0), so the magnitude should be 2
185 TEUCHOS_ASSERT(vec[0]*vec[0]+vec[1]*vec[1] - 4 < 1.e-8);
186 }
187
188 }
189
190 }
191 }
192
193 TEUCHOS_UNIT_TEST(apply_orientations, none)
194 {
195 panzer::testApplyOrientations(false, false, true, true, out, success);
196 }
197
198 TEUCHOS_UNIT_TEST(apply_orientations, by_container)
199 {
200 panzer::testApplyOrientations(true, false, true, false, out, success);
201 }
202
203 TEUCHOS_UNIT_TEST(apply_orientations, by_factory)
204 {
205 panzer::testApplyOrientations(false, true, false, false, out, success);
206 }
207
208 TEUCHOS_UNIT_TEST(apply_orientations, by_both)
209 {
210 panzer::testApplyOrientations(true, true, false, false, out, success);
211 }