Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_BlockedDOFManagerFactory.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
11#ifndef PANZER_BlockedDOF_MANAGER_FACTORY_IMPL_HPP
12#define PANZER_BlockedDOF_MANAGER_FACTORY_IMPL_HPP
13
19#include "Panzer_HashUtils.hpp"
20
21namespace panzer {
22
24requiresBlocking(const std::string & fieldOrder)
25{
26 std::vector<std::string> tokens;
27
28 // break it up on spaces
29 StringTokenizer(tokens,fieldOrder," ",true);
30
31 if(tokens.size()<2) // there has to be at least 2 tokens to block
32 return false;
33
34 // check the prefix - must signal "blocked"
35 if(tokens[0]!="blocked:")
36 return false;
37
38 // loop over tokens
39 bool acceptsHyphen = false;
40 for(std::size_t i=1;i<tokens.size();i++) {
41
42 // acceptsHyphen can't be false, and then a hyphen accepted
43 TEUCHOS_TEST_FOR_EXCEPTION(tokens[i]=="-" && !acceptsHyphen,std::logic_error,
44 "Blocked assembly: Error \"Field Order\" hyphen error at "
45 "token " << i);
46
47 if(acceptsHyphen && tokens[i]=="-")
48 acceptsHyphen = false;
49 else { // token must be a field
50 acceptsHyphen = true;
51 }
52 }
53
54 return true;
55}
56
58buildBlocking(const std::string & fieldOrder,std::vector<std::vector<std::string> > & blocks)
59{
60 // now we don't have to check
61 TEUCHOS_ASSERT(requiresBlocking(fieldOrder));
62
63 std::vector<std::string> tokens;
64
65 // break it up on spaces
66 StringTokenizer(tokens,fieldOrder," ",true);
67
68 Teuchos::RCP<std::vector<std::string> > current;
69 for(std::size_t i=1;i<tokens.size();i++) {
70
71 if(tokens[i]!="-" && tokens[i-1]!="-") {
72 // if there is something to add, add it to the blocks
73 if(current!=Teuchos::null)
74 blocks.push_back(*current);
75
76 current = Teuchos::rcp(new std::vector<std::string>);
77 }
78
79 if(tokens[i]!="-")
80 current->push_back(tokens[i]);
81 }
82
83 if(current!=Teuchos::null)
84 blocks.push_back(*current);
85}
86
87Teuchos::RCP<panzer::GlobalIndexer>
88BlockedDOFManagerFactory::buildGlobalIndexer(const Teuchos::RCP<const Teuchos::OpaqueWrapper<MPI_Comm> > & mpiComm,
89 const std::vector<Teuchos::RCP<panzer::PhysicsBlock> > & physicsBlocks,
90 const Teuchos::RCP<ConnManager> & connMngr,
91 const std::string & fieldOrder) const
92{
93 TEUCHOS_ASSERT(requiresBlocking(fieldOrder));
94
95 Teuchos::RCP<Teuchos::FancyOStream> pout = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
96 pout->setShowProcRank(true);
97 pout->setOutputToRootOnly(0);
98
99 // build the DOF manager for the problem
100 Teuchos::RCP<panzer::BlockedDOFManager> dofManager
101 = Teuchos::rcp(new panzer::BlockedDOFManager(connMngr,*mpiComm));
102 dofManager->enableTieBreak(useTieBreak_);
103 dofManager->setUseDOFManagerFEI(useDOFManagerFEI_);
104
105 // by default assume orientations are not required
106 bool orientationsRequired = false;
107
108 std::vector<Teuchos::RCP<panzer::PhysicsBlock> >::const_iterator physIter;
109 for(physIter=physicsBlocks.begin();physIter!=physicsBlocks.end();++physIter) {
110 Teuchos::RCP<const panzer::PhysicsBlock> pb = *physIter;
111
112 const std::vector<StrPureBasisPair> & blockFields = pb->getProvidedDOFs();
113
114 // insert all fields into a set
115 std::set<StrPureBasisPair,StrPureBasisComp> fieldNames;
116 fieldNames.insert(blockFields.begin(),blockFields.end());
117
118 // add basis to DOF manager: block specific
119 std::set<StrPureBasisPair,StrPureBasisComp>::const_iterator fieldItr;
120 for (fieldItr=fieldNames.begin();fieldItr!=fieldNames.end();++fieldItr) {
121 // determine if orientations are required
122 orientationsRequired |= fieldItr->second->requiresOrientations();
123
124 Teuchos::RCP< Intrepid2::Basis<PHX::Device::execution_space,double,double> > intrepidBasis
125 = fieldItr->second->getIntrepid2Basis();
126 Teuchos::RCP<Intrepid2FieldPattern> fp = Teuchos::rcp(new Intrepid2FieldPattern(intrepidBasis));
127 dofManager->addField(pb->elementBlockID(),fieldItr->first,fp);
128 }
129 }
130
131 // set orientations required flag
132 dofManager->setOrientationsRequired(orientationsRequired);
133
134 std::vector<std::vector<std::string> > blocks;
135 buildBlocking(fieldOrder,blocks);
136 dofManager->setFieldOrder(blocks);
137
138 dofManager->buildGlobalUnknowns();
139 // dofManager->printFieldInformation(*pout);
140
141 return dofManager;
142}
143
144}
145
146#endif
static bool requiresBlocking(const std::string &fieldorder)
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
static void buildBlocking(const std::string &fieldorder, std::vector< std::vector< std::string > > &blocks)
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.