Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_GatherOrientation_impl.hpp
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 #ifndef PANZER_GATHER_ORIENTATION_IMPL_HPP
44 #define PANZER_GATHER_ORIENTATION_IMPL_HPP
45 
46 #include "Teuchos_Assert.hpp"
47 #include "Phalanx_DataLayout.hpp"
48 
49 #include "Panzer_GlobalIndexer.hpp"
51 #include "Panzer_PureBasis.hpp"
52 
53 #include "Teuchos_FancyOStream.hpp"
54 
55 template<typename EvalT,typename TRAITS,typename LO,typename GO>
59  const Teuchos::ParameterList& p)
60 {
61  indexers_.push_back(indexer);
62 
63  const std::vector<std::string>& names =
64  *(p.get< Teuchos::RCP< std::vector<std::string> > >("DOF Names"));
65 
66  indexerNames_ = p.get< Teuchos::RCP< std::vector<std::string> > >("Indexer Names");
67 
68  // this is beging to fix the issues with incorrect use of const
70  if(p.isType< Teuchos::RCP<panzer::PureBasis> >("Basis"))
71  basis = p.get< Teuchos::RCP<panzer::PureBasis> >("Basis");
72  else
73  basis = p.get< Teuchos::RCP<const panzer::PureBasis> >("Basis");
74 
75  gatherFieldOrientations_.resize(names.size());
76  for (std::size_t fd = 0; fd < names.size(); ++fd) {
77  gatherFieldOrientations_[fd] =
78  // PHX::MDField<ScalarT,Cell,NODE>(names[fd]+" Orientation",basis->functional);
79  PHX::MDField<ScalarT,Cell,NODE>(basis->name()+" Orientation",basis->functional);
80  this->addEvaluatedField(gatherFieldOrientations_[fd]);
81  }
82 
83  this->setName("Gather Orientation");
84 }
85 
86 template<typename EvalT,typename TRAITS,typename LO,typename GO>
88 GatherOrientation(const std::vector<Teuchos::RCP<const GlobalIndexer> > & indexers,
89  const Teuchos::ParameterList& p)
90  : indexers_(indexers)
91 {
92  const std::vector<std::string>& names =
93  *(p.get< Teuchos::RCP< std::vector<std::string> > >("DOF Names"));
94 
96 
97  // this is beging to fix the issues with incorrect use of const
99  if(p.isType< Teuchos::RCP<panzer::PureBasis> >("Basis"))
100  basis = p.get< Teuchos::RCP<panzer::PureBasis> >("Basis");
101  else
102  basis = p.get< Teuchos::RCP<const panzer::PureBasis> >("Basis");
103 
104  gatherFieldOrientations_.resize(names.size());
105  for (std::size_t fd = 0; fd < names.size(); ++fd) {
107  PHX::MDField<ScalarT,Cell,NODE>(basis->name()+" Orientation",basis->functional);
108  this->addEvaluatedField(gatherFieldOrientations_[fd]);
109  }
110 
111  this->setName("Gather Orientation");
112 }
113 
114 // **********************************************************************
115 template<typename EvalT,typename TRAITS,typename LO,typename GO>
117 postRegistrationSetup(typename TRAITS::SetupData /* d */,
118  PHX::FieldManager<TRAITS>& /* fm */)
119 {
120  TEUCHOS_ASSERT(gatherFieldOrientations_.size() == indexerNames_->size());
121 
122  indexerIds_.resize(gatherFieldOrientations_.size());
123  subFieldIds_.resize(gatherFieldOrientations_.size());
124 
125  for (std::size_t fd = 0; fd < gatherFieldOrientations_.size(); ++fd) {
126  // get field ID from DOF manager
127  const std::string& fieldName = (*indexerNames_)[fd];
128 
129  indexerIds_[fd] = getFieldBlock(fieldName,indexers_);
130  subFieldIds_[fd] = indexers_[indexerIds_[fd]]->getFieldNum(fieldName);
131  }
132 
133  indexerNames_ = Teuchos::null; // Don't need this anymore
134 }
135 
136 // **********************************************************************
137 template<typename EvalT,typename TRAITS,typename LO,typename GO>
139 evaluateFields(typename TRAITS::EvalData workset)
140 {
141  std::vector<double> orientation;
142 
143  // for convenience pull out some objects from workset
144  std::string blockId = this->wda(workset).block_id;
145  const std::vector<std::size_t> & localCellIds = this->wda(workset).cell_local_ids;
146 
147  // loop over the fields to be gathered
148  for (std::size_t fieldIndex=0; fieldIndex<gatherFieldOrientations_.size();fieldIndex++) {
149 
150  int indexerId = indexerIds_[fieldIndex];
151  int subFieldNum = subFieldIds_[fieldIndex];
152 
153  auto subRowIndexer = indexers_[indexerId];
154  const std::vector<int> & elmtOffset = subRowIndexer->getGIDFieldOffsets(blockId,subFieldNum);
155 
156  // gather operation for each cell in workset
157  for(std::size_t worksetCellIndex=0;worksetCellIndex<localCellIds.size();++worksetCellIndex) {
158  std::size_t cellLocalId = localCellIds[worksetCellIndex];
159 
160  subRowIndexer->getElementOrientation(cellLocalId,orientation);
161 
162  // loop over basis functions and fill the fields
163  for(std::size_t basis=0;basis<elmtOffset.size();basis++) {
164  int offset = elmtOffset[basis];
165  (gatherFieldOrientations_[fieldIndex])(worksetCellIndex,basis) = orientation[offset];
166  (gatherFieldOrientations_[fieldIndex])(worksetCellIndex,basis) = std::sqrt(-1.0);
167  }
168  }
169  }
170 }
171 
172 #endif
Teuchos::RCP< std::vector< std::string > > indexerNames_
T & get(const std::string &name, T def_value)
int getFieldBlock(const std::string &fieldName, const std::vector< Teuchos::RCP< const GlobalIndexer >> &ugis)
std::vector< PHX::MDField< ScalarT, Cell, NODE > > gatherFieldOrientations_
void evaluateFields(typename TRAITS::EvalData d)
bool isType(const std::string &name) const
#define TEUCHOS_ASSERT(assertion_test)
void postRegistrationSetup(typename TRAITS::SetupData d, PHX::FieldManager< TRAITS > &vm)