Debian Codegraph @

packages/panzer/disc-fe/test/la_factory/UnitTest_GlobalIndexer.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 "UnitTest_GlobalIndexer.hpp"
12
13 #include "PanzerDiscFE_config.hpp"
14 #include "Panzer_Traits.hpp"
15
16 namespace panzer {
17 namespace unit_test {
18
19 // GlobalIndexer
20 /////////////////////////////////////////////////////////////////////////////////////////
21
22 GlobalIndexer::GlobalIndexer(int rank,int procCount)
23 : procRank_(rank)
24 {
25 TEUCHOS_TEST_FOR_EXCEPTION(procCount!=2,std::runtime_error,"unit_test::GlobalIndexer runs on only two processors!");
26 }
27
28 int GlobalIndexer::getFieldNum(const std::string & str) const
29 {
30 if(str=="U")
31 return 0;
32 else if(str=="T")
33 return 1;
34 else
35 TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"Can't find field \"" << str << "\" in unit_test::GlobalIndexer, try \'U\' or \'T\'");
36 }
37
38 const std::string & GlobalIndexer::getFieldString(int field) const
39 {
40 static std::string u = "U";
41 static std::string t = "T";
42
43 if(field==0)
44 return u;
45 else if(field==1)
46 return t;
47 else
48 TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"Can't find field \"" << field << "\" in unit_test::GlobalIndexer, try \'0\' or \'1\'");
49 }
50
51 void GlobalIndexer::getElementBlockIds(std::vector<std::string> & elementBlockIds) const
52 {
53 elementBlockIds.clear();
54 elementBlockIds.push_back("block_0");
55 }
56
57 bool GlobalIndexer::fieldInBlock(const std::string & field, const std::string & block) const
58 {
59 if(block!="block_0")
60 return false;
61
62 if(field=="U" || field=="T")
63 return true;
64
65 return false;
66 }
67
68 const std::vector<panzer::LocalOrdinal> & GlobalIndexer::getElementBlock(const std::string & blockId) const
69 {
70 TEUCHOS_TEST_FOR_EXCEPTION(blockId!="block_0",std::runtime_error,
71 "Can't find block ID \"" << blockId << "\" in unit_test::GlobalIndexer");
72
73 if(elements_==Teuchos::null) {
74 elements_ = Teuchos::rcp(new std::vector<panzer::LocalOrdinal>);
75 switch(procRank_) {
76 case 0:
77 elements_->push_back(0);
78 break;
79 case 1:
80 elements_->push_back(1);
81 break;
82 default:
83 TEUCHOS_ASSERT(false);
84 }
85 }
86
87 return *elements_;
88 }
89
90 void GlobalIndexer::getElementGIDs(panzer::LocalOrdinal /* localElmtId */, std::vector<panzer::GlobalOrdinal>& gids, const std::string& /* blockId */) const
91 {
92 gids.resize(8);
93
94 switch(procRank_) {
95 case 0:
96 gids[0] = 0; gids[1] = 1;
97 gids[2] = 2; gids[3] = 3;
98 gids[4] = 4; gids[5] = 5;
99 gids[6] = 6; gids[7] = 7;
100 break;
101 case 1:
102 gids[0] = 2; gids[1] = 3;
103 gids[2] = 8; gids[3] = 9;
104 gids[4] = 10; gids[5] = 11;
105 gids[6] = 4; gids[7] = 5;
106 break;
107 default:
108 break;
109 }
110 }
111
112 const std::vector<int> & GlobalIndexer::getGIDFieldOffsets(const std::string & blockId,int fieldNum) const
113 {
114 TEUCHOS_TEST_FOR_EXCEPTION(not ((fieldNum==0 || fieldNum==1) && blockId=="block_0"), std::runtime_error,
115 "unit_test::GlobalIndexer - Invalid field or block id specified");
116
117 if(field0Offset_==Teuchos::null || field1Offset_==Teuchos::null) {
118 field0Offset_ = Teuchos::rcp(new std::vector<int>(4));
119 (*field0Offset_)[0] = 0;
120 (*field0Offset_)[1] = 2;
121 (*field0Offset_)[2] = 4;
122 (*field0Offset_)[3] = 6;
123
124 field1Offset_ = Teuchos::rcp(new std::vector<int>(4));
125 (*field1Offset_)[0] = 1;
126 (*field1Offset_)[1] = 3;
127 (*field1Offset_)[2] = 5;
128 (*field1Offset_)[3] = 7;
129 }
130
131 if(fieldNum==0) return *field0Offset_;
132 else return *field1Offset_;
133 }
134
135 const std::pair<std::vector<int>,std::vector<int> > &
136 GlobalIndexer::getGIDFieldOffsets_closure(const std::string& /* blockId */, int /* fieldNum */,
137 int /* subcellDim */, int /* subcellId */) const
138 {
139 TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,
140 "unit_test::GlobalIndexer::getGIDFieldOffsets_closure is not implemented yet.");
141 }
142
143 ///////////////////////////////////////////////////////////////////////////////
144 //
145 // getOwnedIndices()
146 //
147 ///////////////////////////////////////////////////////////////////////////////
148 void
149 GlobalIndexer::
150 getOwnedIndices(
151 std::vector<panzer::GlobalOrdinal>& indices) const
152 {
153 indices.resize(6);
154 switch (procRank_)
155 {
156 case 0:
157 indices[0] = 0;
158 indices[1] = 1;
159 indices[2] = 2;
160 indices[3] = 3;
161 indices[4] = 6;
162 indices[5] = 7;
163 break;
164 case 1:
165 indices[0] = 8;
166 indices[1] = 9;
167 indices[2] = 10;
168 indices[3] = 11;
169 indices[4] = 4;
170 indices[5] = 5;
171 break;
172 default:
173 TEUCHOS_ASSERT(false);
174 } // end switch (procRank_)
175 } // end of getOwnedIndices()
176
177 ///////////////////////////////////////////////////////////////////////////////
178 //
179 // getGhostedIndices()
180 //
181 ///////////////////////////////////////////////////////////////////////////////
182 void
183 GlobalIndexer::
184 getGhostedIndices(
185 std::vector<panzer::GlobalOrdinal>& indices) const
186 {
187 indices.resize(2);
188 switch (procRank_)
189 {
190 case 0:
191 indices[0] = 4;
192 indices[1] = 5;
193 break;
194 case 1:
195 indices[0] = 2;
196 indices[1] = 3;
197 break;
198 default:
199 TEUCHOS_ASSERT(false);
200 } // end switch (procRank_)
201 } // end of getGhostedIndices()
202
203 ///////////////////////////////////////////////////////////////////////////////
204 //
205 // getOwnedAndGhostedIndices()
206 //
207 ///////////////////////////////////////////////////////////////////////////////
208 void
209 GlobalIndexer::
210 getOwnedAndGhostedIndices(std::vector<panzer::GlobalOrdinal>& indices) const
211 {
212 indices.resize(8);
213 switch (procRank_)
214 {
215 case 0:
216 indices[0] = 0;
217 indices[1] = 1;
218 indices[2] = 2;
219 indices[3] = 3;
220 indices[4] = 4;
221 indices[5] = 5;
222 indices[6] = 6;
223 indices[7] = 7;
224 break;
225 case 1:
226 indices[0] = 2;
227 indices[1] = 3;
228 indices[2] = 8;
229 indices[3] = 9;
230 indices[4] = 10;
231 indices[5] = 11;
232 indices[6] = 4;
233 indices[7] = 5;
234 break;
235 default:
236 TEUCHOS_ASSERT(false);
237 } // end switch (procRank_)
238 } // end of getOwnedAndGhostedIndices()
239
240 ///////////////////////////////////////////////////////////////////////////////
241 void GlobalIndexer::getElementGIDsAsInt(panzer::LocalOrdinal /* localElmtId */, std::vector<int>& gids, const std::string& /* blockId */) const
242 {
243 gids.resize(8);
244
245 switch(procRank_) {
246 case 0:
247 gids[0] = 0; gids[1] = 1;
248 gids[2] = 2; gids[3] = 3;
249 gids[4] = 4; gids[5] = 5;
250 gids[6] = 6; gids[7] = 7;
251 break;
252 case 1:
253 gids[0] = 2; gids[1] = 3;
254 gids[2] = 8; gids[3] = 9;
255 gids[4] = 10; gids[5] = 11;
256 gids[6] = 4; gids[7] = 5;
257 break;
258 default:
259 break;
260 }
261 }
262 ///////////////////////////////////////////////////////////////////////////////
263 void GlobalIndexer::
264 getOwnedIndicesAsInt(std::vector<int>& indices) const
265 {
266 indices.resize(6);
267 switch (procRank_)
268 {
269 case 0:
270 indices[0] = 0;
271 indices[1] = 1;
272 indices[2] = 2;
273 indices[3] = 3;
274 indices[4] = 6;
275 indices[5] = 7;
276 break;
277 case 1:
278 indices[0] = 8;
279 indices[1] = 9;
280 indices[2] = 10;
281 indices[3] = 11;
282 indices[4] = 4;
283 indices[5] = 5;
284 break;
285 default:
286 TEUCHOS_ASSERT(false);
287 } // end switch (procRank_)
288 } // end of getOwnedIndices()
289
290 ///////////////////////////////////////////////////////////////////////////////
291 void GlobalIndexer::
292 getGhostedIndicesAsInt(std::vector<int>& indices) const
293 {
294 indices.resize(2);
295 switch (procRank_)
296 {
297 case 0:
298 indices[0] = 4;
299 indices[1] = 5;
300 break;
301 case 1:
302 indices[0] = 2;
303 indices[1] = 3;
304 break;
305 default:
306 TEUCHOS_ASSERT(false);
307 } // end switch (procRank_)
308 } // end of getGhostedIndices()
309
310 ///////////////////////////////////////////////////////////////////////////////
311 void GlobalIndexer::
312 getOwnedAndGhostedIndicesAsInt(std::vector<int>& indices) const
313 {
314 indices.resize(8);
315 switch (procRank_)
316 {
317 case 0:
318 indices[0] = 0;
319 indices[1] = 1;
320 indices[2] = 2;
321 indices[3] = 3;
322 indices[4] = 4;
323 indices[5] = 5;
324 indices[6] = 6;
325 indices[7] = 7;
326 break;
327 case 1:
328 indices[0] = 2;
329 indices[1] = 3;
330 indices[2] = 8;
331 indices[3] = 9;
332 indices[4] = 10;
333 indices[5] = 11;
334 indices[6] = 4;
335 indices[7] = 5;
336 break;
337 default:
338 TEUCHOS_ASSERT(false);
339 } // end switch (procRank_)
340 } // end of getOwnedAndGhostedIndices()
341
342
343 ///////////////////////////////////////////////////////////////////////////////
344 //
345 // getNumOwned()
346 //
347 ///////////////////////////////////////////////////////////////////////////////
348 int
349 GlobalIndexer::
350 getNumOwned() const
351 {
352 return 6;
353 } // end of getNumOwned()
354
355 ///////////////////////////////////////////////////////////////////////////////
356 //
357 // getNumGhosted()
358 //
359 ///////////////////////////////////////////////////////////////////////////////
360 int
361 GlobalIndexer::
362 getNumGhosted() const
363 {
364 return 2;
365 } // end of getNumGhosted()
366
367 ///////////////////////////////////////////////////////////////////////////////
368 //
369 // getNumOwnedAndGhosted()
370 //
371 ///////////////////////////////////////////////////////////////////////////////
372 int
373 GlobalIndexer::
374 getNumOwnedAndGhosted() const
375 {
376 return 8;
377 } // end of getNumOwnedAndGhosted()
378
379 void GlobalIndexer::ownedIndices(const std::vector<panzer::GlobalOrdinal> & indices,std::vector<bool> & isOwned) const
380 {
381 std::vector<panzer::GlobalOrdinal> owned;
382 getOwnedIndices(owned);
383
384 isOwned.resize(indices.size(),false);
385 for(std::size_t i=0;i<indices.size();i++)
386 isOwned[i] = (std::find(owned.begin(),owned.end(),indices[i])!=owned.end());
387 }
388
389 /** Get field numbers associated with a particular element block.
390 */
391 const std::vector<int> & GlobalIndexer::getBlockFieldNumbers(const std::string & /* blockId */) const
392 {
393 static std::vector<int> fieldNums;
394 if(fieldNums.size()==0) {
395 fieldNums.resize(8);
396
397 fieldNums[0] = getFieldNum("U"); fieldNums[1] = getFieldNum("T");
398 fieldNums[2] = getFieldNum("U"); fieldNums[3] = getFieldNum("T");
399 fieldNums[4] = getFieldNum("U"); fieldNums[5] = getFieldNum("T");
400 fieldNums[6] = getFieldNum("U"); fieldNums[7] = getFieldNum("T");
401 }
402
403 return fieldNums;
404 }
405
406 void GlobalIndexer::getCoordinates(panzer::LocalOrdinal /* localElementId */, Kokkos::DynRankView<double,PHX::Device>& vertices)
407 {
408 vertices = Kokkos::DynRankView<double,PHX::Device>("vertices",1,4,2);
409 switch(procRank_) {
410 case 0:
411 vertices(0,0,0) = 0.0; vertices(0,0,1) = 0.0;
412 vertices(0,1,0) = 1.0; vertices(0,1,1) = 0.0;
413 vertices(0,2,0) = 1.0; vertices(0,2,1) = 1.0;
414 vertices(0,3,0) = 0.0; vertices(0,3,1) = 1.0;
415 break;
416 case 1:
417 vertices(0,0,0) = 1.0; vertices(0,0,1) = 0.0;
418 vertices(0,1,0) = 2.0; vertices(0,1,1) = 0.0;
419 vertices(0,2,0) = 2.0; vertices(0,2,1) = 1.0;
420 vertices(0,3,0) = 1.0; vertices(0,3,1) = 1.0;
421 break;
422 default:
423 TEUCHOS_ASSERT(false); // fail!
424 };
425 }
426
427 int GlobalIndexer::
428 getElementBlockGIDCount(const std::string &) const
429 {
430 return 8;
431 }
432
433 int GlobalIndexer::
434 getElementBlockGIDCount(const std::size_t &) const
435 {
436 return 8;
437 }
438
439 // GlobalIndexer_Element
440 /////////////////////////////////////////////////////////////////////////////////////////
441
442 GlobalIndexer_Element::GlobalIndexer_Element(int rank,int procCount)
443 : procRank_(rank)
444 {
445 TEUCHOS_TEST_FOR_EXCEPTION(procCount!=2,std::runtime_error,"unit_test::GlobalIndexer_Element runs on only two processors!");
446 }
447
448 int GlobalIndexer_Element::getFieldNum(const std::string & str) const
449 {
450 if(str=="U")
451 return 0;
452 else if(str=="T")
453 return 1;
454 else
455 TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"Can't find field \"" << str << "\" in unit_test::GlobalIndexer_Element, try \'U\' or \'T\'");
456 }
457
458 const std::string & GlobalIndexer_Element::getFieldString(int field) const
459 {
460 static std::string u = "U";
461 static std::string t = "T";
462
463 if(field==0)
464 return u;
465 else if(field==1)
466 return t;
467 else
468 TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"Can't find field \"" << field << "\" in unit_test::GlobalIndexer, try \'0\' or \'1\'");
469 }
470
471 void GlobalIndexer_Element::getElementBlockIds(std::vector<std::string> & elementBlockIds) const
472 {
473 elementBlockIds.clear();
474 elementBlockIds.push_back("block_0");
475 }
476
477 bool GlobalIndexer_Element::fieldInBlock(const std::string & field, const std::string & block) const
478 {
479 if(block!="block_0")
480 return false;
481
482 if(field=="U" || field=="T")
483 return true;
484
485 return false;
486 }
487
488 const std::vector<panzer::LocalOrdinal> & GlobalIndexer_Element::getElementBlock(const std::string & blockId) const
489 {
490 TEUCHOS_TEST_FOR_EXCEPTION(blockId!="block_0",std::runtime_error,
491 "Can't find block ID \"" << blockId << "\" in unit_test::GlobalIndexer_Element");
492
493 if(elements_==Teuchos::null) {
494 elements_ = Teuchos::rcp(new std::vector<panzer::LocalOrdinal>);
495 switch(procRank_) {
496 case 0:
497 elements_->push_back(0);
498 break;
499 case 1:
500 elements_->push_back(1);
501 break;
502 default:
503 TEUCHOS_ASSERT(false);
504 }
505 }
506
507 return *elements_;
508 }
509
510 void GlobalIndexer_Element::getElementGIDs(panzer::LocalOrdinal /* localElmtId */, std::vector<panzer::GlobalOrdinal>& gids, const std::string& /* blockId */) const
511 {
512 gids.resize(2);
513
514 switch(procRank_) {
515 case 0:
516 gids[0] = 0;
517 gids[1] = 1;
518 break;
519 case 1:
520 gids[0] = 2;
521 gids[1] = 3;
522 break;
523 default:
524 break;
525 }
526 }
527
528 const std::vector<int> & GlobalIndexer_Element::getGIDFieldOffsets(const std::string & blockId,int fieldNum) const
529 {
530 TEUCHOS_TEST_FOR_EXCEPTION(not ((fieldNum==0 || fieldNum==1) && blockId=="block_0"), std::runtime_error,
531 "unit_test::GlobalIndexer_Element - Invalid field or block id specified");
532
533 if(field0Offset_==Teuchos::null || field1Offset_==Teuchos::null) {
534 field0Offset_ = Teuchos::rcp(new std::vector<int>(1));
535 (*field0Offset_)[0] = 0;
536
537 field1Offset_ = Teuchos::rcp(new std::vector<int>(1));
538 (*field1Offset_)[0] = 1;
539 }
540
541 if(fieldNum==0) return *field0Offset_;
542 else return *field1Offset_;
543 }
544
545 const std::pair<std::vector<int>,std::vector<int> > &
546 GlobalIndexer_Element::getGIDFieldOffsets_closure(const std::string& /* blockId */, int /* fieldNum */,
547 int /* subcellDim */, int /* subcellId */) const
548 {
549 TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,
550 "unit_test::GlobalIndexer_Element::getGIDFieldOffsets_closure is not implemented yet.");
551 }
552
553 void GlobalIndexer_Element::getOwnedIndices(std::vector<panzer::GlobalOrdinal> & indices) const
554 {
555 indices.resize(2);
556 switch(procRank_) {
557 case 0:
558 indices[0] = 0;
559 indices[1] = 1;
560 break;
561 case 1:
562 indices[0] = 2;
563 indices[1] = 3;
564 break;
565 default:
566 TEUCHOS_ASSERT(false);
567 }
568 }
569
570 void GlobalIndexer_Element::getOwnedAndGhostedIndices(std::vector<panzer::GlobalOrdinal> & indices) const
571 {
572 indices.resize(2);
573 switch(procRank_) {
574 case 0:
575 indices[0] = 0;
576 indices[1] = 1;
577 break;
578 case 1:
579 indices[0] = 2;
580 indices[1] = 3;
581 break;
582 default:
583 TEUCHOS_ASSERT(false);
584 }
585 }
586
587 void GlobalIndexer_Element::ownedIndices(const std::vector<panzer::GlobalOrdinal> & indices,std::vector<bool> & isOwned) const
588 {
589 std::vector<panzer::GlobalOrdinal> owned;
590 getOwnedIndices(owned);
591
592 isOwned.resize(indices.size(),false);
593 for(std::size_t i=0;i<indices.size();i++)
594 isOwned[i] = (std::find(owned.begin(),owned.end(),indices[i])!=owned.end());
595 }
596
597 /** Get field numbers associated with a particular element block.
598 */
599 const std::vector<int> & GlobalIndexer_Element::getBlockFieldNumbers(const std::string & /* blockId */) const
600 {
601 static std::vector<int> fieldNums;
602 if(fieldNums.size()==0) {
603 fieldNums.resize(2);
604
605 fieldNums[0] = getFieldNum("U"); fieldNums[1] = getFieldNum("T");
606 }
607
608 return fieldNums;
609 }
610
611 void GlobalIndexer_Element::getCoordinates(panzer::LocalOrdinal /* localElementId */, Kokkos::DynRankView<double,PHX::Device>& vertices)
612 {
613 vertices = Kokkos::DynRankView<double,PHX::Device>("vertices",1,1,2);
614 switch(procRank_) {
615 case 0:
616 vertices(0,0,0) = 0.5; vertices(0,0,1) = 0.5;
617 break;
618 case 1:
619 vertices(0,0,0) = 1.5; vertices(0,0,1) = 0.5;
620 break;
621 default:
622 TEUCHOS_ASSERT(false); // fail!
623 };
624 }
625
626 int GlobalIndexer_Element::
627 getElementBlockGIDCount(const std::string &) const
628 {
629 return 2;
630 }
631
632 int GlobalIndexer_Element::
633 getElementBlockGIDCount(const std::size_t &) const
634 {
635 return 2;
636 }
637
638 // BlockGlobalIndexer
639 /////////////////////////////////////////////////////////////////////////////////////////
640
641 BlockGlobalIndexer::BlockGlobalIndexer(int /* blocks */, int rank, int procCount)
642 : procRank_(rank)
643 {
644 TEUCHOS_TEST_FOR_EXCEPTION(procCount!=2,std::runtime_error,"unit_test::BlockGlobalIndexer runs on only two processors!");
645 }
646
647 void BlockGlobalIndexer::getElementBlockIds(std::vector<std::string> & elementBlockIds) const
648 {
649 elementBlockIds.clear();
650 elementBlockIds.push_back("block_0");
651 }
652
653 const std::vector<panzer::LocalOrdinal> & BlockGlobalIndexer::getElementBlock(const std::string & blockId) const
654 {
655 TEUCHOS_TEST_FOR_EXCEPTION(blockId!="block_0",std::runtime_error,
656 "Can't find block ID \"" << blockId << "\" in unit_test::BlockGlobalIndexer");
657
658 if(elements_==Teuchos::null) {
659 elements_ = Teuchos::rcp(new std::vector<panzer::LocalOrdinal>);
660 switch(procRank_) {
661 case 0:
662 elements_->push_back(0);
663 break;
664 case 1:
665 elements_->push_back(1);
666 break;
667 default:
668 TEUCHOS_ASSERT(false);
669 }
670 }
671
672 return *elements_;
673 }
674
675 } // end unit test
676 } // end panzer