Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
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>;
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.getNodeCount();
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  // TODO BWR see the note in IntrepidOrientation which muses on using the base topology (or at least the VERTICES, as requested by the intrepid call)
111 
112  const int num_owned_cells = owned_cells.extent(0);
113  const int num_ghost_cells = ghost_cells.extent(0);
114 
115  // Initialize the orientations vector
116  orientations.clear();
117  orientations.resize(num_owned_cells+num_ghost_cells);
118 
119  // Fill the owned vector with the nodal connectivity of the cells on this processor
120  {
121  auto vector_view = owned_nodes_vector->getLocalViewHost(Tpetra::Access::OverwriteAll);
122  for(int cell=0; cell<owned_cells.extent_int(0); ++cell){
123  const GlobalOrdinal * nodes = conn.getConnectivity(cell);
124  for(int node=0; node<num_nodes_per_cell; ++node)
125  vector_view(cell,node) = nodes[node];
126  }
127  }
128 
129  // Import into the ghost vector
130  ghost_nodes_vector->doImport(*owned_nodes_vector,*importer,Tpetra::CombineMode::REPLACE);
131 
132  // Add owned orientations
133  {
134  auto vector_view = owned_nodes_vector->getLocalViewHost(Tpetra::Access::ReadOnly);
135  for(int cell=0; cell<num_owned_cells; ++cell){
136  NodeView nodes("nodes",num_nodes_per_cell);
137  for(int node=0; node<num_nodes_per_cell; ++node)
138  nodes(node) = vector_view(cell,node);
139  orientations[cell] = Intrepid2::Orientation::getOrientation(topology, nodes);
140  }
141  }
142 
143  // Add ghost orientations
144  {
145  auto vector_view = ghost_nodes_vector->getLocalViewHost(Tpetra::Access::ReadOnly);
146  for(int ghost_cell=0; ghost_cell<num_ghost_cells; ++ghost_cell){
147  const int cell = num_owned_cells + ghost_cell;
148  NodeView nodes("nodes",num_nodes_per_cell);
149  for(int node=0; node<num_nodes_per_cell; ++node)
150  nodes(node) = vector_view(ghost_cell,node);
151  orientations[cell] = Intrepid2::Orientation::getOrientation(topology, nodes);
152  }
153  }
154 
155 }
156 
159 {
160  using Teuchos::rcp_dynamic_cast;
161  using Teuchos::RCP;
162  using Teuchos::rcp;
163 
164  auto orientation = rcp(new std::vector<Intrepid2::Orientation>);
165 
166  auto comm = globalIndexer->getComm();
167  auto conn = globalIndexer->getConnManager()->noConnectivityClone();
168 
169  TEUCHOS_TEST_FOR_EXCEPTION(conn == Teuchos::null,std::logic_error,
170  "panzer::buildIntrepidOrientation: Could not cast ConnManagerBase");
171 
172  buildIntrepidOrientation(comm, *conn, *orientation);
173  return orientation;
174 
175 }
176 
177 }
178 
181 {
183 }
184 
185 
189 {
191  return orientations_;
192 }
193 
194 }
virtual Teuchos::RCP< Teuchos::Comm< int > > getComm() const =0
Teuchos::RCP< const std::vector< Intrepid2::Orientation > > getOrientations() const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
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)
Builds the element orientations for all element blocks.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void getElementBlockIds(std::vector< std::string > &elementBlockIds) 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.
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.
#define TEUCHOS_ASSERT(assertion_test)
virtual void buildConnectivity(const FieldPattern &fp)=0
bool is_null() const
virtual const GlobalOrdinal * getConnectivity(LocalOrdinal localElmtId) const =0