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