Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_IntrepidOrientation.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #include "PanzerDiscFE_config.hpp"
44 #include "Panzer_GlobalIndexer.hpp"
46 
47 namespace panzer {
48 
49  void buildIntrepidOrientation(std::vector<Intrepid2::Orientation> & orientation,
50  panzer::ConnManager & connMgr)
51  {
52  using Teuchos::rcp_dynamic_cast;
53  using Teuchos::RCP;
54  using Teuchos::rcp;
55 
56  orientation.clear();
57 
58  // Retrive element blocks and its meta data
59  const int numElementBlocks = connMgr.numElementBlocks();
60 
61  std::vector<std::string> elementBlockIds;
62  std::vector<shards::CellTopology> elementBlockTopologies;
63 
64  connMgr.getElementBlockIds(elementBlockIds);
65  connMgr.getElementBlockTopologies(elementBlockTopologies);
66 
67  TEUCHOS_TEST_FOR_EXCEPTION(numElementBlocks <= 0 &&
68  numElementBlocks != static_cast<int>(elementBlockIds.size()) &&
69  numElementBlocks != static_cast<int>(elementBlockTopologies.size()),
70  std::logic_error,
71  "panzer::buildIntrepidOrientation: Number of element blocks does not match to element block meta data");
72 
73  // Currently panzer support only one type of elements for whole mesh (use the first cell topology)
74  const auto cellTopo = elementBlockTopologies.at(0);
75  const int numVerticesPerCell = cellTopo.getVertexCount();
76 
77  const auto fp = NodalFieldPattern(cellTopo);
78  connMgr.buildConnectivity(fp);
79 
80  // Count and pre-alloc orientations
81  int total_elems = 0;
82  for (int i=0;i<numElementBlocks;++i) {
83  total_elems += connMgr.getElementBlock(elementBlockIds.at(i)).size();
84  }
85 
86  orientation.resize(total_elems);
87  // Loop over element blocks
88  for (int i=0;i<numElementBlocks;++i) {
89  // get elements in a block
90  const auto &elementBlock = connMgr.getElementBlock(elementBlockIds.at(i));
91 
92  const int numElementsPerBlock = elementBlock.size();
93 
94  // construct orientation information
95  for (int c=0;c<numElementsPerBlock;++c) {
96  const int localCellId = elementBlock.at(c);
98  vertices(connMgr.getConnectivity(localCellId), numVerticesPerCell);
99  // This function call expects a view for the vertices, not the nodes
100  orientation[localCellId] = (Intrepid2::Orientation::getOrientation(cellTopo, vertices));
101  }
102  }
103  }
104 
107  {
108  using Teuchos::rcp_dynamic_cast;
109  using Teuchos::RCP;
110  using Teuchos::rcp;
111 
112  auto orientation = rcp(new std::vector<Intrepid2::Orientation>);
113 
114  {
116  = rcp_dynamic_cast<const GlobalIndexer>(globalIndexer);
117 
118  if (ugi!=Teuchos::null) {
119  const auto connMgr = ugi->getConnManager()->noConnectivityClone();
120 
121  TEUCHOS_TEST_FOR_EXCEPTION(connMgr == Teuchos::null,std::logic_error,
122  "panzer::buildIntrepidOrientation: ConnManager is null!");
123 
124  buildIntrepidOrientation(*orientation, *connMgr);
125  return orientation;
126  }
127  }
128 
129  TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
130  "panzer::buildIntrepidOrientation: Could not cast GlobalIndexer");
131  }
132 
133  void buildIntrepidOrientations(const std::vector<std::string>& eBlockNames,
134  const panzer::ConnManager & connMgrInput,
135  std::map<std::string,std::vector<Intrepid2::Orientation>> & orientations)
136  {
137  using Teuchos::rcp_dynamic_cast;
138  using Teuchos::RCP;
139  using Teuchos::rcp;
140 
141  auto connMgrPtr = connMgrInput.noConnectivityClone();
142  auto& connMgr = *connMgrPtr;
143 
144  // Map element block name to topology
145  std::map<std::string,shards::CellTopology> eb_name_to_topo;
146  {
147  std::vector<std::string> elementBlockIds;
148  connMgr.getElementBlockIds(elementBlockIds);
149 
150  std::vector<shards::CellTopology> elementBlockTopologies;
151  connMgr.getElementBlockTopologies(elementBlockTopologies);
152 
153  for (size_t i=0; i < elementBlockIds.size(); ++i) {
154  eb_name_to_topo[elementBlockIds[i]] = elementBlockTopologies[i];
155  }
156  }
157 
158  // Currently panzer supports only one element topology for whole mesh (use the first cell topology)
159  const auto cellTopo = eb_name_to_topo[eBlockNames[0]];
160  const int numVerticesPerCell = cellTopo.getVertexCount();
161 
162  const auto fp = NodalFieldPattern(cellTopo);
163  connMgr.buildConnectivity(fp);
164 
165  // Loop over requested element blocks
166  for (size_t i=0;i<eBlockNames.size();++i) {
167 
168  const auto &lids = connMgr.getElementBlock(eBlockNames[i]);
169  const size_t num_elems = lids.size();
170  auto& orts = orientations[eBlockNames[i]];
171  orts.resize(num_elems);
172 
173  for (size_t c=0;c<num_elems;++c) {
174  const int lid = lids[c];
176  vertices(connMgr.getConnectivity(lid),numVerticesPerCell);
177 
178  // This function call expects a view for the vertices, not the nodes
179  orts[c] = Intrepid2::Orientation::getOrientation(cellTopo, vertices);
180  }
181  }
182  }
183 
184 } // end namespace panzer
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void buildIntrepidOrientations(const std::vector< std::string > &eBlockNames, const panzer::ConnManager &connMgrInput, std::map< std::string, std::vector< Intrepid2::Orientation >> &orientations)
Builds the element orientations for the specified element blocks.
void buildIntrepidOrientation(std::vector< Intrepid2::Orientation > &orientation, panzer::ConnManager &connMgr)
Builds the element orientations for all element blocks.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual const std::vector< LocalOrdinal > & getElementBlock(const std::string &blockID) const =0
virtual void getElementBlockIds(std::vector< std::string > &elementBlockIds) const =0
virtual Teuchos::RCP< ConnManager > noConnectivityClone() const =0
virtual Teuchos::RCP< const ConnManager > getConnManager() const =0
Returns the connection manager currently being used.
Pure virtual base class for supplying mesh connectivity information to the DOF Manager.
virtual void getElementBlockTopologies(std::vector< shards::CellTopology > &elementBlockTopologies) const =0
virtual std::size_t numElementBlocks() const =0
Kokkos::View< const LO **, Kokkos::LayoutRight, PHX::Device > lids
virtual void buildConnectivity(const FieldPattern &fp)=0
virtual const GlobalOrdinal * getConnectivity(LocalOrdinal localElmtId) const =0