Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_BlockedDOFManagerFactory.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 
43 #ifndef PANZER_BlockedDOF_MANAGER_FACTORY_IMPL_HPP
44 #define PANZER_BlockedDOF_MANAGER_FACTORY_IMPL_HPP
45 
51 #include "Panzer_HashUtils.hpp"
52 
53 namespace panzer {
54 
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 
90 buildBlocking(const std::string & fieldOrder,std::vector<std::vector<std::string> > & blocks)
91 {
92  // now we don't have to check
93  TEUCHOS_ASSERT(requiresBlocking(fieldOrder));
94 
95  std::vector<std::string> tokens;
96 
97  // break it up on spaces
98  StringTokenizer(tokens,fieldOrder," ",true);
99 
101  for(std::size_t i=1;i<tokens.size();i++) {
102 
103  if(tokens[i]!="-" && tokens[i-1]!="-") {
104  // if there is something to add, add it to the blocks
105  if(current!=Teuchos::null)
106  blocks.push_back(*current);
107 
108  current = Teuchos::rcp(new std::vector<std::string>);
109  }
110 
111  if(tokens[i]!="-")
112  current->push_back(tokens[i]);
113  }
114 
115  if(current!=Teuchos::null)
116  blocks.push_back(*current);
117 }
118 
121  const std::vector<Teuchos::RCP<panzer::PhysicsBlock> > & physicsBlocks,
122  const Teuchos::RCP<ConnManager> & connMngr,
123  const std::string & fieldOrder) const
124 {
125  TEUCHOS_ASSERT(requiresBlocking(fieldOrder));
126 
127  Teuchos::RCP<Teuchos::FancyOStream> pout = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
128  pout->setShowProcRank(true);
129  pout->setOutputToRootOnly(0);
130 
131  // build the DOF manager for the problem
133  = Teuchos::rcp(new panzer::BlockedDOFManager(connMngr,*mpiComm));
134  dofManager->enableTieBreak(useTieBreak_);
136 
137  // by default assume orientations are not required
138  bool orientationsRequired = false;
139 
140  std::vector<Teuchos::RCP<panzer::PhysicsBlock> >::const_iterator physIter;
141  for(physIter=physicsBlocks.begin();physIter!=physicsBlocks.end();++physIter) {
143 
144  const std::vector<StrPureBasisPair> & blockFields = pb->getProvidedDOFs();
145 
146  // insert all fields into a set
147  std::set<StrPureBasisPair,StrPureBasisComp> fieldNames;
148  fieldNames.insert(blockFields.begin(),blockFields.end());
149 
150  // add basis to DOF manager: block specific
151  std::set<StrPureBasisPair,StrPureBasisComp>::const_iterator fieldItr;
152  for (fieldItr=fieldNames.begin();fieldItr!=fieldNames.end();++fieldItr) {
153  // determine if orientations are required
154  orientationsRequired |= fieldItr->second->requiresOrientations();
155 
157  = fieldItr->second->getIntrepid2Basis();
159  dofManager->addField(pb->elementBlockID(),fieldItr->first,fp);
160  }
161  }
162 
163  // set orientations required flag
164  dofManager->setOrientationsRequired(orientationsRequired);
165 
166  std::vector<std::vector<std::string> > blocks;
167  buildBlocking(fieldOrder,blocks);
168  dofManager->setFieldOrder(blocks);
169 
170  dofManager->buildGlobalUnknowns();
171  // dofManager->printFieldInformation(*pout);
172 
173  return dofManager;
174 }
175 
176 }
177 
178 #endif
virtual Teuchos::RCP< panzer::GlobalIndexer > buildGlobalIndexer(const Teuchos::RCP< const Teuchos::OpaqueWrapper< MPI_Comm > > &mpiComm, const std::vector< Teuchos::RCP< panzer::PhysicsBlock > > &physicsBlocks, const Teuchos::RCP< ConnManager > &connMngr, const std::string &fieldOrder="") const
void setUseDOFManagerFEI(bool useFEI)
Use the FEI DOF manager internally, or the standard version.
void enableTieBreak(bool useTieBreak)
static bool requiresBlocking(const std::string &fieldorder)
basic_FancyOStream & setShowProcRank(const bool showProcRank)
#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
static void buildBlocking(const std::string &fieldorder, std::vector< std::vector< std::string > > &blocks)
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
void addField(const std::string &str, const Teuchos::RCP< const FieldPattern > &pattern)
Add a field to the DOF manager.
void setFieldOrder(const std::vector< std::vector< std::string > > &fieldOrder)
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)
const std::vector< StrPureBasisPair > & getProvidedDOFs() const