Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_WorksetDescriptor.hpp
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_WorksetDescriptor_hpp__
12 #define __Panzer_WorksetDescriptor_hpp__
13 
14 #include <string>
15 #include <ostream>
16 #include <functional>
17 #include "Panzer_HashUtils.hpp"
18 
19 namespace panzer {
20 
22  enum WorksetSizeType : int {
29  };
30 
51 public:
52 
60  WorksetDescriptor(const std::string & elementBlock,
61  const int worksetSize=WorksetSizeType::CLASSIC_MODE,
62  const bool requiresPartitioning=false,
63  const bool applyOrientations=true)
64  : elementBlock_(elementBlock),
65  worksetSize_(worksetSize),
68  sideAssembly_(false)
69  {
70  TEUCHOS_TEST_FOR_EXCEPTION(elementBlock_=="",std::runtime_error,
71  "WorksetDescriptor constr: Element block name must be non-empty!");
72  }
73 
83  WorksetDescriptor(const std::string & elementBlock,
84  const std::string & sideset,
85  const bool sideAssembly)
86  : elementBlock_(elementBlock),
87  sideset_(sideset),
89  requiresPartitioning_(false),
90  applyOrientations_(true),
91  sideAssembly_(sideAssembly)
92  {
93  TEUCHOS_TEST_FOR_EXCEPTION(elementBlock_=="",std::runtime_error,
94  "WorksetDescriptor constr: Element block name must be non-empty!");
95  TEUCHOS_TEST_FOR_EXCEPTION(sideset_=="",std::runtime_error,
96  "WorksetDescriptor constr: Side set name must be non-empty!");
97  }
98 
114  WorksetDescriptor(const std::string & elementBlock,
115  const std::string & sideset,
116  const int worksetSize=WorksetSizeType::CLASSIC_MODE,
117  const bool requiresPartitioning=false,
118  const bool applyOrientations=true)
119  : elementBlock_(elementBlock),
120  sideset_(sideset),
121  worksetSize_(worksetSize),
124  sideAssembly_(false)
125  {
126  TEUCHOS_TEST_FOR_EXCEPTION(elementBlock_=="",std::runtime_error,
127  "WorksetDescriptor constr: Element block name must be non-empty!");
128  TEUCHOS_TEST_FOR_EXCEPTION(sideset_=="",std::runtime_error,
129  "WorksetDescriptor constr: Side set name must be non-empty!");
130  }
131 
150  WorksetDescriptor(const std::string & elementBlock_0,
151  const std::string & elementBlock_1,
152  const std::string & sideset_0,
153  const std::string & sideset_1,
154  const int worksetSize=WorksetSizeType::CLASSIC_MODE,
155  const bool requiresPartitioning=false,
156  const bool applyOrientations=true)
157  : elementBlock_(elementBlock_0),
158  elementBlock_2_(elementBlock_1),
159  sideset_(sideset_0),
160  sideset_2_(sideset_1),
161  worksetSize_(worksetSize),
164  sideAssembly_(false)
165  {
166  TEUCHOS_TEST_FOR_EXCEPTION(elementBlock_=="",std::runtime_error,
167  "WorksetDescriptor constr: Element block 0 name must be non-empty!");
168  TEUCHOS_TEST_FOR_EXCEPTION(sideset_=="",std::runtime_error,
169  "WorksetDescriptor constr: Side set 0 name must be non-empty!");
170  TEUCHOS_TEST_FOR_EXCEPTION(elementBlock_2_=="",std::runtime_error,
171  "WorksetDescriptor constr: Element block 1 name must be non-empty!");
172  TEUCHOS_TEST_FOR_EXCEPTION(sideset_2_=="",std::runtime_error,
173  "WorksetDescriptor constr: Side set 1 name must be non-empty!");
174  }
175 
177  WorksetDescriptor(const WorksetDescriptor & src) = default;
178 
186  const std::string & getElementBlock(const int block=0) const
187  { return (block==0) ? elementBlock_ : elementBlock_2_; }
188 
196  const std::string & getSideset(const int block=0) const
197  { return (block==0) ? sideset_ : sideset_2_; }
198 
200  //TEUCHOS_DEPRECATED
201  bool sideAssembly() const
202  { return sideAssembly_; }
203 // { return useSideset(); }
204 
210  {
211  return useSideset() and elementBlock_2_ != "";
212  }
213 
220  bool requiresPartitioning() const
221  {
222  return requiresPartitioning_;
223  }
224 
227  //{ return useSideset_; }
228  { return sideset_ != ""; }
229 
231  int getWorksetSize() const
232  { return worksetSize_; }
233 
234  bool applyOrientations() const {return applyOrientations_;}
235 
236 private:
237 
239  std::string elementBlock_;
240 
242  std::string elementBlock_2_;
243 
245  std::string sideset_;
246 
248  std::string sideset_2_;
249 
252 
255 
258 
264 };
265 
267 inline bool operator==(const WorksetDescriptor & a,const WorksetDescriptor & b)
268 {
269  if(a.useSideset())
270  // if side set is in use, check all fields
271  return a.getElementBlock()==b.getElementBlock()
272  && a.getSideset()==b.getSideset()
273  && a.sideAssembly()==b.sideAssembly()
274  && a.useSideset()==b.useSideset();
275  else
276  // otherwise check that both descriptor don't use side sets
277  // and check the element block (the remaining fields are allowed
278  // to be unset)
279  return a.getElementBlock()==b.getElementBlock()
280  && a.useSideset()==b.useSideset();
281 }
282 
284 inline std::size_t hash_value(const WorksetDescriptor & wd)
285 {
286  std::size_t seed = 0;
287 
289  if(wd.useSideset()) {
290  // optionally hash on side set and side assembly
291  panzer::hash_combine(seed,wd.getSideset());
293  }
294 
295  return seed;
296 }
297 
299 inline std::ostream & operator<<(std::ostream & os,const WorksetDescriptor & wd)
300 {
301  if(wd.useSideset())
302  os << "Side descriptor: "
303  << "eblock = \"" << wd.getElementBlock() << "\", "
304  << "ss = \"" << wd.getSideset() << "\", "
305  << "side assembly = " << (wd.sideAssembly() ? "on" : "off");
306  else
307  os << "Block descriptor: "
308  << "eblock = \"" << wd.getElementBlock() << "\"";
309 
310  return os;
311 }
312 
315 //TEUCHOS_DEPRECATED
316 inline WorksetDescriptor blockDescriptor(const std::string & eBlock)
317 { return WorksetDescriptor(eBlock); }
318 
321 //TEUCHOS_DEPRECATED
322 inline WorksetDescriptor sidesetDescriptor(const std::string & eBlock,const std::string & sideset)
323 { return WorksetDescriptor(eBlock,sideset,false); }
324 
328 //TEUCHOS_DEPRECATED
329 inline WorksetDescriptor sidesetVolumeDescriptor(const std::string & eBlock,const std::string & sideset)
330 { return WorksetDescriptor(eBlock,sideset,true); }
331 
332 }
333 
334 namespace std {
335 
336 template <>
337 struct hash<panzer::WorksetDescriptor>
338 {
339  std::size_t operator()(const panzer::WorksetDescriptor& wd) const
340  {
341  std::size_t seed = 0;
342 
346  if(wd.useSideset()) {
347  // optionally hash on side set and side assembly
348  panzer::hash_combine(seed,wd.getSideset());
350  }
351 
352  return seed;
353  }
354 };
355 
356 }
357 
358 #endif
Backwards compatibility mode that ignores the worksetSize in the WorksetDescriptor.
WorksetSizeType
Special values for the workset size. When the workset size is set on the WorksetDescriptor an interge...
const std::string & getSideset(const int block=0) const
Get sideset name.
std::size_t hash_value(const WorksetDescriptor &wd)
Hash function that satisifies the stl hash interface.
bool connectsElementBlocks() const
Identifies this workset as an interface between two element blocks.
bool applyOrientations_
Apply orientations - used for continuous discretizations with edge/face elements. ...
std::string sideset_
Side set, must be non-empty if useSideset_ is true.
bool requiresPartitioning_
Marks if the mesh require partitioning before generating worksets.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
int worksetSize_
Requested workset size.
const std::string & getElementBlock(const int block=0) const
Get element block name.
bool useSideset() const
This descriptor is for a side set.
WorksetDescriptor sidesetDescriptor(const std::string &eBlock, const std::string &sideset)
WorksetDescriptor(const std::string &elementBlock, const int worksetSize=WorksetSizeType::CLASSIC_MODE, const bool requiresPartitioning=false, const bool applyOrientations=true)
WorksetDescriptor(const std::string &elementBlock, const std::string &sideset, const int worksetSize=WorksetSizeType::CLASSIC_MODE, const bool requiresPartitioning=false, const bool applyOrientations=true)
WorksetDescriptor(const std::string &elementBlock, const std::string &sideset, const bool sideAssembly)
std::size_t operator()(const panzer::WorksetDescriptor &wd) const
WorksetDescriptor sidesetVolumeDescriptor(const std::string &eBlock, const std::string &sideset)
std::string elementBlock_
Element block, required to be non-empty.
std::string sideset_2_
Side set on other side of side, must be non-empty if useSideset_ is true and elementBlock2_ is not em...
Workset size is set to zero.
bool sideAssembly() const
Expects side set assembly on volume.
bool operator==(const panzer::BasisDescriptor &left, const panzer::BasisDescriptor &right)
void hash_combine(std::size_t &seed, const T &v)
std::ostream & operator<<(std::ostream &os, const AssemblyEngineInArgs &in)
WorksetDescriptor(const std::string &elementBlock_0, const std::string &elementBlock_1, const std::string &sideset_0, const std::string &sideset_1, const int worksetSize=WorksetSizeType::CLASSIC_MODE, const bool requiresPartitioning=false, const bool applyOrientations=true)
WorksetDescriptor blockDescriptor(const std::string &eBlock)
const std::vector< std::pair< int, LocalOrdinal > > &pid_and_lid const
int getWorksetSize() const
Get the requested workset size (default -2 (workset size is set elsewhere), -1 (largest possible work...
bool requiresPartitioning() const
Do we need to partition the local mesh prior to generating worksets.
std::string elementBlock_2_
Element block on other side of side.
Workset size is set to the total number of local elements in the MPI process.