Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_BlockedDOFManagerFactory_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_BlockedDOF_MANAGER_FACTORY_IMPL_HPP
44 #define PANZER_BlockedDOF_MANAGER_FACTORY_IMPL_HPP
45 
50 #include "Panzer_HashUtils.hpp"
51 
52 namespace panzer {
53 
54 template <typename LO,typename GO>
56 requiresBlocking(const std::string & fieldOrder)
57 {
58  std::vector<std::string> tokens;
59 
60  // break it up on spaces
61  StringTokenizer(tokens,fieldOrder," ",true);
62 
63  if(tokens.size()<2) // there has to be at least 2 tokens to block
64  return false;
65 
66  // check the prefix - must signal "blocked"
67  if(tokens[0]!="blocked:")
68  return false;
69 
70  // loop over tokens
71  bool acceptsHyphen = false;
72  for(std::size_t i=1;i<tokens.size();i++) {
73 
74  // acceptsHyphen can't be false, and then a hyphen accepted
75  TEUCHOS_TEST_FOR_EXCEPTION(tokens[i]=="-" && !acceptsHyphen,std::logic_error,
76  "Blocked assembly: Error \"Field Order\" hyphen error at "
77  "token " << i);
78 
79  if(acceptsHyphen && tokens[i]=="-")
80  acceptsHyphen = false;
81  else { // token must be a field
82  acceptsHyphen = true;
83  }
84  }
85 
86  return true;
87 }
88 
89 template <typename LO,typename GO>
91 buildBlocking(const std::string & fieldOrder,std::vector<std::vector<std::string> > & blocks)
92 {
93  // now we don't have to check
94  TEUCHOS_ASSERT(requiresBlocking(fieldOrder));
95 
96  std::vector<std::string> tokens;
97 
98  // break it up on spaces
99  StringTokenizer(tokens,fieldOrder," ",true);
100 
102  for(std::size_t i=1;i<tokens.size();i++) {
103 
104  if(tokens[i]!="-" && tokens[i-1]!="-") {
105  // if there is something to add, add it to the blocks
106  if(current!=Teuchos::null)
107  blocks.push_back(*current);
108 
109  current = Teuchos::rcp(new std::vector<std::string>);
110  }
111 
112  if(tokens[i]!="-")
113  current->push_back(tokens[i]);
114  }
115 
116  if(current!=Teuchos::null)
117  blocks.push_back(*current);
118 }
119 
120 template <typename LO,typename GO>
123  const std::vector<Teuchos::RCP<panzer::PhysicsBlock> > & physicsBlocks,
124  const Teuchos::RCP<ConnManager<LO,GO> > & connMngr,
125  const std::string & fieldOrder) const
126 {
127  TEUCHOS_ASSERT(requiresBlocking(fieldOrder));
128 
129  Teuchos::RCP<Teuchos::FancyOStream> pout = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
130  pout->setShowProcRank(true);
131  pout->setOutputToRootOnly(0);
132 
133  // build the DOF manager for the problem
135  = Teuchos::rcp(new panzer::BlockedDOFManager<LO,GO>(connMngr,*mpiComm));
136  dofManager->enableTieBreak(useTieBreak_);
137  dofManager->setUseDOFManagerFEI(useDOFManagerFEI_);
138 
139  // by default assume orientations are not required
140  bool orientationsRequired = false;
141 
142  std::vector<Teuchos::RCP<panzer::PhysicsBlock> >::const_iterator physIter;
143  for(physIter=physicsBlocks.begin();physIter!=physicsBlocks.end();++physIter) {
145 
146  const std::vector<StrPureBasisPair> & blockFields = pb->getProvidedDOFs();
147 
148  // insert all fields into a set
149  std::set<StrPureBasisPair,StrPureBasisComp> fieldNames;
150  fieldNames.insert(blockFields.begin(),blockFields.end());
151 
152  // add basis to DOF manager: block specific
153  std::set<StrPureBasisPair,StrPureBasisComp>::const_iterator fieldItr;
154  for (fieldItr=fieldNames.begin();fieldItr!=fieldNames.end();++fieldItr) {
155  // determine if orientations are required
156  orientationsRequired |= fieldItr->second->requiresOrientations();
157 
159  = fieldItr->second->getIntrepid2Basis();
161  dofManager->addField(pb->elementBlockID(),fieldItr->first,fp);
162  }
163  }
164 
165  // set orientations required flag
166  dofManager->setOrientationsRequired(orientationsRequired);
167 
168  std::vector<std::vector<std::string> > blocks;
169  buildBlocking(fieldOrder,blocks);
170  dofManager->setFieldOrder(blocks);
171 
172  dofManager->buildGlobalUnknowns();
173  // dofManager->printFieldInformation(*pout);
174 
175  return dofManager;
176 }
177 
178 }
179 
180 #endif
basic_FancyOStream & setShowProcRank(const bool showProcRank)
static void buildBlocking(const std::string &fieldorder, std::vector< std::vector< std::string > > &blocks)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
std::string elementBlockID() const
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
virtual Teuchos::RCP< panzer::UniqueGlobalIndexer< LO, std::pair< int, GO > > > buildUniqueGlobalIndexer(const Teuchos::RCP< const Teuchos::OpaqueWrapper< MPI_Comm > > &mpiComm, const std::vector< Teuchos::RCP< panzer::PhysicsBlock > > &physicsBlocks, const Teuchos::RCP< ConnManager< LO, GO > > &connMngr, const std::string &fieldOrder="") const
void StringTokenizer(std::vector< std::string > &tokens, const std::string &str, const std::string delimiters, bool trim)
Tokenize a string, put tokens in a vector.
#define TEUCHOS_ASSERT(assertion_test)
static bool requiresBlocking(const std::string &fieldorder)
const std::vector< StrPureBasisPair > & getProvidedDOFs() const