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
32 template<typename ArrayCellGIDs, typename ArraySideGIDs>
33 unsigned
34 getLocalSideIndexFromGlobalNodeList(const ArrayCellGIDs& cellGIDs,
35 const ArraySideGIDs& sideGIDs,
36 const shards::CellTopology& cell)
37 {
38 unsigned cell_dim = cell.getDimension();
39 //TEUCHOS_TEST_FOR_EXCEPTION(!cell.getSubcellHomogeneity(cell_dim - 1),
40 // std::runtime_error, "Sides are not homogeneous!");
41
42 unsigned local_side;
43 bool found_local_side = false;
44 unsigned side = 0;
45 while ( (side < cell.getSideCount()) && (!found_local_side) ) {
46
47 const shards::CellTopology
48 side_topo(cell.getCellTopologyData(cell.getDimension()-1, side));
49
50 unsigned num_side_nodes =
51 cell.getCellTopologyData()->side[side].topology->node_count;
52
53
54 std::list<unsigned> tmp_side_gid_list;
55 for (unsigned node = 0; node < num_side_nodes; ++node)
56 tmp_side_gid_list.push_back(cellGIDs[cell.getNodeMap(cell_dim - 1,
57 side, node)]);
58
59 bool side_matches = true;
60 unsigned node = 0;
61 while ( side_matches && (node < num_side_nodes) ) {
62
63 std::list<unsigned>::iterator search =
64 std::find(tmp_side_gid_list.begin(), tmp_side_gid_list.end(),
65 sideGIDs[node]);
66
67 if (search == tmp_side_gid_list.end())
68 side_matches = false;
69
70 ++node;
71 }
72
73 if (side_matches) {
74 found_local_side = true;
75 local_side = side;
76 }
77
78 ++side;
79 }
80
81 TEUCHOS_TEST_FOR_EXCEPTION(!found_local_side, std::runtime_error,
82 "Failed to find side!");
83
84 return local_side;
85 }
86
98 template<typename ArrayCellGIDs, typename ArraySideGIDs>
99 unsigned
100 getLocalSubcellIndexFromGlobalNodeList(const ArrayCellGIDs& cellGIDs,
101 const ArraySideGIDs& subcellGIDs,
102 const shards::CellTopology& cell,unsigned subcell_dim)
103 {
104 unsigned local_subcell;
105 bool found_local_subcell = false;
106 unsigned subcell = 0;
107 while ( (subcell < cell.getSubcellCount(subcell_dim)) && (!found_local_subcell) ) {
108
109 unsigned num_subcell_nodes =
110 cell.getCellTopologyData()->subcell[subcell_dim][subcell].topology->node_count;
111
112 std::list<unsigned> tmp_subcell_gid_list;
113 for (unsigned node = 0; node < num_subcell_nodes; ++node)
114 tmp_subcell_gid_list.push_back(cellGIDs[cell.getNodeMap(subcell_dim,
115 subcell, node)]);
116
117 bool subcell_matches = true;
118 unsigned node = 0;
119 while ( subcell_matches && (node < num_subcell_nodes) ) {
120
121 std::list<unsigned>::iterator search =
122 std::find(tmp_subcell_gid_list.begin(), tmp_subcell_gid_list.end(),
123 subcellGIDs[node]);
124
125 if (search == tmp_subcell_gid_list.end())
126 subcell_matches = false;
127
128 ++node;
129 }
130
131 if (subcell_matches) {
132 found_local_subcell = true;
133 local_subcell = subcell;
134 }
135
136 ++subcell;
137 }
138
139 TEUCHOS_TEST_FOR_EXCEPTION(!found_local_subcell, std::runtime_error,
140 "Failed to find subcell!");
141
142 return local_subcell;
143 }
144
163 template<typename ArrayCellGIDs, typename ArraySubcellGIDs>
164 void getLocalSubcellMapFromGlobalNodeLists(const ArrayCellGIDs& cellGIDs,
165 const std::vector<ArraySubcellGIDs> & subcellGIDs,
166 const shards::CellTopology& cell,unsigned subcell_dim,
167 std::vector<unsigned> & subcellMap)
168 {
169 subcellMap.resize(subcellGIDs.size());
170
171 // loop over subcell node indices searching for local subcell index
172 unsigned index = 0;
173 typename std::vector<ArraySubcellGIDs>::const_iterator subcellIter;
174 for(subcellIter=subcellGIDs.begin();subcellIter!=subcellGIDs.end();++subcellIter) {
175 unsigned localSubcell = getLocalSubcellIndexFromGlobalNodeList(cellGIDs,*subcellIter,cell,subcell_dim);
176
177 // build vector mapping current index to local subcell index
178 subcellMap[localSubcell] = index;
179
180 index++;
181 }
182 }
183
184}
185
186#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)