Debian Codegraph @

packages/panzer/adapters-stk/test/panzer_workset_builder/d_workset_builder.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 #include "Panzer_STK_Interface.hpp"
25 #include "Panzer_STK_SquareQuadMeshFactory.hpp"
26 #include "Panzer_Workset_Builder.hpp"
27 #include "Panzer_STK_SetupUtilities.hpp"
28 #include "Panzer_PhysicsBlock.hpp"
29 #include "Panzer_GlobalData.hpp"
30 #include "Panzer_BC.hpp"
31
32 #include "user_app_EquationSetFactory.hpp"
33
34 namespace panzer {
35
36 void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb,
37 std::vector<panzer::BC>& bcs, const int integration_order);
38
39 void testIpMatch(const panzer::WorksetDetails& d0, const panzer::WorksetDetails& d1,
40 const index_t num_cells, Teuchos::FancyOStream& out, bool& success);
41
42 TEUCHOS_UNIT_TEST(workset_builder, stk_edge)
43 {
44
45 RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList);
46 pl->set("X Blocks",2);
47 pl->set("Y Blocks",1);
48 pl->set("X Elements",2); // in each block
49 pl->set("Y Elements",2); // in each block
50
51 // This mesh will have element IDs
52 // 4 5 6 7
53 // 0 1 2 3
54
55 int myRank=0;
56 MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
57
58 panzer_stk::SquareQuadMeshFactory factory;
59 factory.setParameterList(pl);
60 RCP<panzer_stk::STK_Interface> mesh = factory.buildMesh(MPI_COMM_WORLD);
61 mesh->writeToExodus("test.exo");
62
63 std::vector<std::string> element_blocks;
64 mesh->getElementBlockNames(element_blocks);
65 const std::size_t workset_size = 20;
66
67 // Use a high integration order to test ordering of the fields in
68 // IntegrationValues2.
69 const int default_integration_order = 4;
70 Teuchos::RCP<Teuchos::ParameterList> ipb = Teuchos::parameterList("Physics Blocks");
71 std::vector<panzer::BC> bcs;
72 testInitialzation(ipb, bcs, default_integration_order);
73
74 // build physics blocks
75 //////////////////////////////////////////////////////////////
76 std::vector<Teuchos::RCP<panzer::PhysicsBlock> > physicsBlocks;
77 {
78 Teuchos::RCP<user_app::MyFactory> eqset_factory = Teuchos::rcp(new user_app::MyFactory);
79
80 std::map<std::string,std::string> block_ids_to_physics_ids;
81 block_ids_to_physics_ids["eblock-0_0"] = "test physics";
82 block_ids_to_physics_ids["eblock-1_0"] = "test physics";
83
84 std::map<std::string,Teuchos::RCP<const shards::CellTopology> > block_ids_to_cell_topo;
85 block_ids_to_cell_topo["eblock-0_0"] = mesh->getCellTopology("eblock-0_0");
86 block_ids_to_cell_topo["eblock-1_0"] = mesh->getCellTopology("eblock-1_0");
87
88 Teuchos::RCP<panzer::GlobalData> gd = panzer::createGlobalData();
89
90 panzer::buildPhysicsBlocks(block_ids_to_physics_ids,
91 block_ids_to_cell_topo,
92 ipb,
93 default_integration_order,
94 workset_size,
95 eqset_factory,
96 gd,
97 false,
98 physicsBlocks);
99 }
100
101 {
102 std::string sideset = "vertical_0";
103 Teuchos::RCP<const panzer::PhysicsBlock> pb_a = panzer::findPhysicsBlock(element_blocks[0],physicsBlocks);
104 Teuchos::RCP<const panzer::PhysicsBlock> pb_b = panzer::findPhysicsBlock(element_blocks[1],physicsBlocks);
105 Teuchos::RCP<std::map<unsigned,panzer::Workset> > worksets = panzer_stk::buildBCWorksets(
106 *mesh, pb_a->getWorksetNeeds(),pb_a->elementBlockID(),
107 pb_b->getWorksetNeeds(),pb_b->elementBlockID(), sideset);
108
109 if(myRank==0) {
110 TEST_EQUALITY(worksets->size(),0); // no elements on this processor
111 }
112 else {
113 TEST_EQUALITY(worksets->size(),1);
114 panzer::Workset& workset = worksets->begin()->second;
115
116 TEST_EQUALITY((*worksets).size(),1);
117 TEST_EQUALITY(workset.num_cells,2);
118 TEST_EQUALITY(workset.subcell_dim,1);
119 TEST_EQUALITY(workset.numDetails(),2);
120
121 // this is identical to workset(0)
122 TEST_EQUALITY(workset.subcell_index, 1);
123 TEST_EQUALITY(workset.block_id, "eblock-0_0");
124 TEST_EQUALITY(workset.cell_local_ids.size(),2);
125 TEST_EQUALITY(workset.cell_local_ids[0],0);
126 TEST_EQUALITY(workset.cell_local_ids[1],2);
127 TEST_EQUALITY(workset.ir_degrees->size(),1);
128 TEST_EQUALITY(workset.int_rules.size(),1);
129 TEST_EQUALITY(workset.basis_names->size(),2);
130 TEST_EQUALITY(workset.bases.size(),2);
131
132 TEST_EQUALITY(workset(0).subcell_index, 1);
133 TEST_EQUALITY(workset(0).block_id, "eblock-0_0");
134 TEST_EQUALITY(workset(0).cell_local_ids.size(),2);
135 TEST_EQUALITY(workset(0).cell_local_ids[0],0);
136 TEST_EQUALITY(workset(0).cell_local_ids[1],2);
137 TEST_EQUALITY(workset(0).ir_degrees->size(),1);
138 TEST_EQUALITY(workset(0).int_rules.size(),1);
139 TEST_EQUALITY(workset(0).basis_names->size(),2);
140 TEST_EQUALITY(workset(0).bases.size(),2);
141
142 TEST_EQUALITY(workset(1).subcell_index, 3);
143 TEST_EQUALITY(workset(1).block_id, "eblock-1_0");
144 TEST_EQUALITY(workset(1).cell_local_ids[0],5);
145 TEST_EQUALITY(workset(1).cell_local_ids[1],7);
146 TEST_EQUALITY(workset(1).ir_degrees->size(),1);
147 TEST_EQUALITY(workset(1).int_rules.size(),1);
148 TEST_EQUALITY(workset(1).basis_names->size(),2);
149 TEST_EQUALITY(workset(1).bases.size(),2);
150
151 testIpMatch(workset(0), workset(1), workset.num_cells, out, success);
152 }
153 }
154
155 {
156 std::string sideset = "vertical_0";
157 Teuchos::RCP<const panzer::PhysicsBlock> pb_a = panzer::findPhysicsBlock(element_blocks[1],physicsBlocks);
158 Teuchos::RCP<const panzer::PhysicsBlock> pb_b = panzer::findPhysicsBlock(element_blocks[0],physicsBlocks);
159 Teuchos::RCP<std::map<unsigned,panzer::Workset> > worksets = panzer_stk::buildBCWorksets(
160 *mesh, pb_a->getWorksetNeeds(),pb_a->elementBlockID(),
161 pb_b->getWorksetNeeds(),pb_b->elementBlockID(), sideset);
162
163 if(myRank==1) {
164 TEST_EQUALITY(worksets->size(),0); // no elements on this processor
165 }
166 else {
167 TEST_EQUALITY(worksets->size(),1);
168 panzer::Workset& workset = worksets->begin()->second;
169
170 TEST_EQUALITY(workset.num_cells,2);
171 TEST_EQUALITY(workset.subcell_dim,1);
172 TEST_EQUALITY(workset.numDetails(),2);
173
174 // this is identical to details[0]
175 TEST_EQUALITY(workset.subcell_index, 3);
176 TEST_EQUALITY(workset.block_id, "eblock-1_0");
177 TEST_EQUALITY(workset.cell_local_ids.size(),2);
178 TEST_EQUALITY(workset.cell_local_ids[0],1);
179 TEST_EQUALITY(workset.cell_local_ids[1],3);
180 TEST_EQUALITY(workset.ir_degrees->size(),1);
181 TEST_EQUALITY(workset.int_rules.size(),1);
182 TEST_EQUALITY(workset.basis_names->size(),2);
183 TEST_EQUALITY(workset.bases.size(),2);
184
185 TEST_EQUALITY(workset(0).subcell_index, 3);
186 TEST_EQUALITY(workset(0).block_id, "eblock-1_0");
187 TEST_EQUALITY(workset(0).cell_local_ids.size(),2);
188 TEST_EQUALITY(workset(0).cell_local_ids[0],1);
189 TEST_EQUALITY(workset(0).cell_local_ids[1],3);
190 TEST_EQUALITY(workset(0).ir_degrees->size(),1);
191 TEST_EQUALITY(workset(0).int_rules.size(),1);
192 TEST_EQUALITY(workset(0).basis_names->size(),2);
193 TEST_EQUALITY(workset(0).bases.size(),2);
194
195 TEST_EQUALITY(workset(1).subcell_index, 1);
196 TEST_EQUALITY(workset(1).block_id, "eblock-0_0");
197 TEST_EQUALITY(workset(1).cell_local_ids[0],4);
198 TEST_EQUALITY(workset(1).cell_local_ids[1],6);
199 TEST_EQUALITY(workset(1).ir_degrees->size(),1);
200 TEST_EQUALITY(workset(1).int_rules.size(),1);
201 TEST_EQUALITY(workset(1).basis_names->size(),2);
202 TEST_EQUALITY(workset(1).bases.size(),2);
203
204 testIpMatch(workset(0), workset(1), workset.num_cells, out, success);
205 }
206 }
207
208 }
209
210 void testInitialzation(const Teuchos::RCP<Teuchos::ParameterList>& ipb,
211 std::vector<panzer::BC>& bcs, const int integration_order)
212 {
213 // Physics block
214 Teuchos::ParameterList& physics_block = ipb->sublist("test physics");
215 {
216 Teuchos::ParameterList& p = physics_block.sublist("a");
217 p.set("Type","Energy");
218 p.set("Prefix","");
219 p.set("Model ID","solid");
220 p.set("Basis Type","HGrad");
221 p.set("Basis Order",2);
222 p.set("Integration Order",integration_order);
223 }
224 {
225 Teuchos::ParameterList& p = physics_block.sublist("b");
226 p.set("Type","Energy");
227 p.set("Prefix","ION_");
228 p.set("Model ID","ion solid");
229 p.set("Basis Type","HGrad");
230 p.set("Basis Order",1);
231 p.set("Integration Order",integration_order);
232 }
233
234 {
235 std::size_t bc_id = 0;
236 panzer::BCType neumann = BCT_Dirichlet;
237 std::string sideset_id = "left";
238 std::string element_block_id = "eblock-0_0";
239 std::string dof_name = "UX";
240 std::string strategy = "Constant";
241 double value = 5.0;
242 Teuchos::ParameterList p;
243 p.set("Value",value);
244 panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name,
245 strategy, p);
246 bcs.push_back(bc);
247 }
248 {
249 std::size_t bc_id = 0;
250 panzer::BCType neumann = BCT_Dirichlet;
251 std::string sideset_id = "right";
252 std::string element_block_id = "eblock-1_0";
253 std::string dof_name = "UX";
254 std::string strategy = "Constant";
255 double value = 5.0;
256 Teuchos::ParameterList p;
257 p.set("Value",value);
258 panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name,
259 strategy, p);
260 bcs.push_back(bc);
261 }
262 {
263 std::size_t bc_id = 0;
264 panzer::BCType neumann = BCT_Dirichlet;
265 std::string sideset_id = "top";
266 std::string element_block_id = "eblock-1_0";
267 std::string dof_name = "UX";
268 std::string strategy = "Constant";
269 double value = 5.0;
270 Teuchos::ParameterList p;
271 p.set("Value",value);
272 panzer::BC bc(bc_id, neumann, sideset_id, element_block_id, dof_name,
273 strategy, p);
274 bcs.push_back(bc);
275 }
276 }
277
278 void testIpMatch(const panzer::WorksetDetails& d0, const panzer::WorksetDetails& d1,
279 const index_t num_cells, Teuchos::FancyOStream& out, bool& success)
280 {
281 TEST_EQUALITY(d0.int_rules.size(), d1.int_rules.size());
282 for (std::size_t iri = 0; iri < d0.int_rules.size(); ++iri) {
283 const std::size_t num_ip = d0.int_rules[iri]->cub_points.extent(0),
284 num_dim = d0.int_rules[iri]->cub_points.extent(1);
285
286 auto d0_rules_view = d0.int_rules[iri]->ip_coordinates.get_static_view();
287 auto d0_rules_h = Kokkos::create_mirror_view(d0_rules_view);
288 Kokkos::deep_copy(d0_rules_h, d0_rules_view);
289
290 auto d1_rules_view = d1.int_rules[iri]->ip_coordinates.get_static_view();
291 auto d1_rules_h = Kokkos::create_mirror_view(d1_rules_view);
292 Kokkos::deep_copy(d1_rules_h, d1_rules_view);
293
294 for (index_t cell = 0; cell < num_cells; ++cell)
295 for (std::size_t ip = 0; ip < num_ip; ++ip)
296 for (std::size_t dim = 0; dim < num_dim; ++dim)
297 TEST_EQUALITY(d0_rules_h(cell, ip, dim), d1_rules_h(cell, ip, dim))
298 }
299 }
300
301 }