Panzer  Version of the Day
Panzer_OrientationsInterface.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 
44 
45 #include "Panzer_GlobalIndexer.hpp"
46 #include "Panzer_ConnManager.hpp"
47 #include "PanzerDiscFE_config.hpp"
50 #include "Panzer_NodeType.hpp"
51 #include "Tpetra_Import.hpp"
52 #include "Tpetra_MultiVector.hpp"
53 
54 namespace panzer {
55 
56 namespace
57 {
58 
59 void
60 buildIntrepidOrientation(const Teuchos::RCP<const Teuchos::Comm<int>> & comm,
61  panzer::ConnManager & conn,
62  std::vector<Intrepid2::Orientation> & orientations)
63 {
64 
65  using MVector = Tpetra::MultiVector<panzer::GlobalOrdinal, panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType>;
66  using Map = Tpetra::Map<panzer::LocalOrdinal,panzer::GlobalOrdinal,panzer::TpetraNodeType>;
67  using Importer = Tpetra::Import<panzer::LocalOrdinal,panzer::GlobalOrdinal,panzer::TpetraNodeType>;
68  using NodeView = Kokkos::View<panzer::GlobalOrdinal*, Kokkos::DefaultHostExecutionSpace>;
69 
70  // First we need to build the indexing scheme
71  PHX::View<panzer::GlobalOrdinal*> owned_cells, ghost_cells, virtual_cells;
72  fillLocalCellIDs(comm, conn, owned_cells, ghost_cells, virtual_cells);
73 
74  // Build a map and importer for syncing the nodal connectivity
75  auto owned_cell_map = Teuchos::rcp(new Map(Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(),owned_cells,0,comm));
76  auto ghost_cell_map = Teuchos::rcp(new Map(Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(),ghost_cells,0,comm));
77 
78  // Build importer: imports from owned cells map to ghost cell map
79  auto importer = Teuchos::rcp(new Importer(owned_cell_map,ghost_cell_map));
80 
81  // Grab the cell topology from the conn manager
82  shards::CellTopology topology;
83  {
84  // Retrive element blocks and its meta data
85  const int numElementBlocks = conn.numElementBlocks();
86 
87  std::vector<std::string> elementBlockIds;
88  std::vector<shards::CellTopology> elementBlockTopologies;
89 
90  conn.getElementBlockIds(elementBlockIds);
91  conn.getElementBlockTopologies(elementBlockTopologies);
92 
93  TEUCHOS_TEST_FOR_EXCEPTION(numElementBlocks <= 0 &&
94  numElementBlocks != static_cast<int>(elementBlockIds.size()) &&
95  numElementBlocks != static_cast<int>(elementBlockTopologies.size()),
96  std::logic_error,
97  "panzer::buildIntrepidOrientation: Number of element blocks does not match to element block meta data");
98 
99  topology = elementBlockTopologies.at(0);
100  }
101  const int num_nodes_per_cell = topology.getVertexCount();
102 
103  // Create Tpetra multivectors for storing global node ids
104  auto owned_nodes_vector = Teuchos::rcp(new MVector(owned_cell_map,num_nodes_per_cell));
105  auto ghost_nodes_vector = Teuchos::rcp(new MVector(ghost_cell_map,num_nodes_per_cell));
106 
107  // Make sure the conn is setup for a nodal connectivity
108  panzer::NodalFieldPattern pattern(topology);
109  conn.buildConnectivity(pattern);
110 
111  const int num_owned_cells = owned_cells.extent(0);
112  const int num_ghost_cells = ghost_cells.extent(0);
113 
114  // Initialize the orientations vector
115  orientations.clear();
116  orientations.resize(num_owned_cells+num_ghost_cells);
117 
118  // Fill the owned vector with the nodal connectivity of the cells on this processor
119  {
120  auto vector_view = owned_nodes_vector->getLocalViewHost(Tpetra::Access::OverwriteAll);
121  for(int cell=0; cell<owned_cells.extent_int(0); ++cell){
122  const GlobalOrdinal * nodes = conn.getConnectivity(cell);
123  for(int node=0; node<num_nodes_per_cell; ++node)
124  vector_view(cell,node) = nodes[node];
125  }
126  }
127 
128  // Import into the ghost vector
129  ghost_nodes_vector->doImport(*owned_nodes_vector,*importer,Tpetra::CombineMode::REPLACE);
130 
131  // Add owned orientations
132  {
133  auto vector_view = owned_nodes_vector->getLocalViewHost(Tpetra::Access::ReadOnly);
134  for(int cell=0; cell<num_owned_cells; ++cell){
135  NodeView nodes("nodes",num_nodes_per_cell);
136  for(int node=0; node<num_nodes_per_cell; ++node)
137  nodes(node) = vector_view(cell,node);
138  orientations[cell] = Intrepid2::Orientation::getOrientation(topology, nodes);
139  }
140  }
141 
142  // Add ghost orientations
143  {
144  auto vector_view = ghost_nodes_vector->getLocalViewHost(Tpetra::Access::ReadOnly);
145  for(int ghost_cell=0; ghost_cell<num_ghost_cells; ++ghost_cell){
146  const int cell = num_owned_cells + ghost_cell;
147  NodeView nodes("nodes",num_nodes_per_cell);
148  for(int node=0; node<num_nodes_per_cell; ++node)
149  nodes(node) = vector_view(ghost_cell,node);
150  orientations[cell] = Intrepid2::Orientation::getOrientation(topology, nodes);
151  }
152  }
153 
154 }
155 
156 Teuchos::RCP<std::vector<Intrepid2::Orientation> >
157 buildIntrepidOrientation(const Teuchos::RCP<const GlobalIndexer> globalIndexer)
158 {
159  using Teuchos::rcp_dynamic_cast;
160  using Teuchos::RCP;
161  using Teuchos::rcp;
162 
163  auto orientation = rcp(new std::vector<Intrepid2::Orientation>);
164 
165  auto comm = globalIndexer->getComm();
166  auto conn = globalIndexer->getConnManager()->noConnectivityClone();
167 
168  TEUCHOS_TEST_FOR_EXCEPTION(conn == Teuchos::null,std::logic_error,
169  "panzer::buildIntrepidOrientation: Could not cast ConnManagerBase");
170 
171  buildIntrepidOrientation(comm, *conn, *orientation);
172  return orientation;
173 
174 }
175 
176 }
177 
179 OrientationsInterface(const Teuchos::RCP<const panzer::GlobalIndexer> & indexer)
180 {
182 }
183 
184 
185 Teuchos::RCP<const std::vector<Intrepid2::Orientation> >
188 {
189  TEUCHOS_ASSERT(not orientations_.is_null());
190  return orientations_;
191 }
192 
193 }
void fillLocalCellIDs(const Teuchos::RCP< const Teuchos::Comm< int >> &comm, panzer::ConnManager &conn, PHX::View< panzer::GlobalOrdinal *> &owned_cells, PHX::View< panzer::GlobalOrdinal *> &ghost_cells, PHX::View< panzer::GlobalOrdinal *> &virtual_cells)
Get the owned, ghost and virtual global cell ids for this process.
void buildIntrepidOrientation(std::vector< Intrepid2::Orientation > &orientation, panzer::ConnManager &connMgr)
Teuchos::RCP< const std::vector< Intrepid2::Orientation > > getOrientations() const
virtual void getElementBlockIds(std::vector< std::string > &elementBlockIds) const =0
virtual Teuchos::RCP< ConnManager > noConnectivityClone() const =0
Pure virtual base class for supplying mesh connectivity information to the DOF Manager.
Teuchos::RCP< const std::vector< Intrepid2::Orientation > > orientations_
Orientations.
virtual void getElementBlockTopologies(std::vector< shards::CellTopology > &elementBlockTopologies) const =0
virtual std::size_t numElementBlocks() const =0
OrientationsInterface()=delete
Block default constructor.
virtual void buildConnectivity(const FieldPattern &fp)=0
virtual const GlobalOrdinal * getConnectivity(LocalOrdinal localElmtId) const =0