Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_Shards_Utilities.hpp
Go to the documentation of this file.
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#ifndef PANZER_SHARDS_UTILITIES
12#define PANZER_SHARDS_UTILITIES
13
14#include <iostream>
15#include <vector>
16#include <list>
17#include "Teuchos_Assert.hpp"
18#include "Shards_CellTopology.hpp"
19
20namespace panzer {
21
22 template<typename ArrayCellGIDs, typename ArraySideGIDs>
23 unsigned
24 getLocalSideIndexFromGlobalNodeList(const ArrayCellGIDs& cellGIDs,
25 const ArraySideGIDs& sideGIDs,
26 const shards::CellTopology& cell)
27 {
28 unsigned cell_dim = cell.getDimension();
29 //TEUCHOS_TEST_FOR_EXCEPTION(!cell.getSubcellHomogeneity(cell_dim - 1),
30 // std::runtime_error, "Sides are not homogeneous!");
31
32 unsigned local_side;
33 bool found_local_side = false;
34 unsigned side = 0;
35 while ( (side < cell.getSideCount()) && (!found_local_side) ) {
36
37 const shards::CellTopology
38 side_topo(cell.getCellTopologyData(cell.getDimension()-1, side));
39
40 unsigned num_side_nodes =
41 cell.getCellTopologyData()->side[side].topology->node_count;
42
43
44 std::list<unsigned> tmp_side_gid_list;
45 for (unsigned node = 0; node < num_side_nodes; ++node)
46 tmp_side_gid_list.push_back(cellGIDs[cell.getNodeMap(cell_dim - 1,
47 side, node)]);
48
49 bool side_matches = true;
50 unsigned node = 0;
51 while ( side_matches && (node < num_side_nodes) ) {
52
53 std::list<unsigned>::iterator search =
54 std::find(tmp_side_gid_list.begin(), tmp_side_gid_list.end(),
55 sideGIDs[node]);
56
57 if (search == tmp_side_gid_list.end())
58 side_matches = false;
59
60 ++node;
61 }
62
63 if (side_matches) {
64 found_local_side = true;
65 local_side = side;
66 }
67
68 ++side;
69 }
70
71 TEUCHOS_TEST_FOR_EXCEPTION(!found_local_side, std::runtime_error,
72 "Failed to find side!");
73
74 return local_side;
75 }
76
88 template<typename ArrayCellGIDs, typename ArraySideGIDs>
89 unsigned
90 getLocalSubcellIndexFromGlobalNodeList(const ArrayCellGIDs& cellGIDs,
91 const ArraySideGIDs& subcellGIDs,
92 const shards::CellTopology& cell,unsigned subcell_dim)
93 {
94 unsigned local_subcell;
95 bool found_local_subcell = false;
96 unsigned subcell = 0;
97 while ( (subcell < cell.getSubcellCount(subcell_dim)) && (!found_local_subcell) ) {
98
99 unsigned num_subcell_nodes =
100 cell.getCellTopologyData()->subcell[subcell_dim][subcell].topology->node_count;
101
102 std::list<unsigned> tmp_subcell_gid_list;
103 for (unsigned node = 0; node < num_subcell_nodes; ++node)
104 tmp_subcell_gid_list.push_back(cellGIDs[cell.getNodeMap(subcell_dim,
105 subcell, node)]);
106
107 bool subcell_matches = true;
108 unsigned node = 0;
109 while ( subcell_matches && (node < num_subcell_nodes) ) {
110
111 std::list<unsigned>::iterator search =
112 std::find(tmp_subcell_gid_list.begin(), tmp_subcell_gid_list.end(),
113 subcellGIDs[node]);
114
115 if (search == tmp_subcell_gid_list.end())
116 subcell_matches = false;
117
118 ++node;
119 }
120
121 if (subcell_matches) {
122 found_local_subcell = true;
123 local_subcell = subcell;
124 }
125
126 ++subcell;
127 }
128
129 TEUCHOS_TEST_FOR_EXCEPTION(!found_local_subcell, std::runtime_error,
130 "Failed to find subcell!");
131
132 return local_subcell;
133 }
134
153 template<typename ArrayCellGIDs, typename ArraySubcellGIDs>
154 void getLocalSubcellMapFromGlobalNodeLists(const ArrayCellGIDs& cellGIDs,
155 const std::vector<ArraySubcellGIDs> & subcellGIDs,
156 const shards::CellTopology& cell,unsigned subcell_dim,
157 std::vector<unsigned> & subcellMap)
158 {
159 subcellMap.resize(subcellGIDs.size());
160
161 // loop over subcell node indices searching for local subcell index
162 unsigned index = 0;
163 typename std::vector<ArraySubcellGIDs>::const_iterator subcellIter;
164 for(subcellIter=subcellGIDs.begin();subcellIter!=subcellGIDs.end();++subcellIter) {
165 unsigned localSubcell = getLocalSubcellIndexFromGlobalNodeList(cellGIDs,*subcellIter,cell,subcell_dim);
166
167 // build vector mapping current index to local subcell index
168 subcellMap[localSubcell] = index;
169
170 index++;
171 }
172 }
173
174}
175
176#endif
unsigned getLocalSubcellIndexFromGlobalNodeList(const ArrayCellGIDs &cellGIDs, const ArraySideGIDs &subcellGIDs, const shards::CellTopology &cell, unsigned subcell_dim)
void getLocalSubcellMapFromGlobalNodeLists(const ArrayCellGIDs &cellGIDs, const std::vector< ArraySubcellGIDs > &subcellGIDs, const shards::CellTopology &cell, unsigned subcell_dim, std::vector< unsigned > &subcellMap)
unsigned getLocalSideIndexFromGlobalNodeList(const ArrayCellGIDs &cellGIDs, const ArraySideGIDs &sideGIDs, const shards::CellTopology &cell)