Panzer  Version of the Day
Panzer_WorksetDescriptor.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_WorksetDescriptor_hpp__
44 #define __Panzer_WorksetDescriptor_hpp__
45 
46 #include <string>
47 #include <ostream>
48 #include <functional>
49 #include "Panzer_HashUtils.hpp"
50 
51 namespace panzer {
52 
54  enum WorksetSizeType : int {
61  };
62 
83 public:
84 
92  WorksetDescriptor(const std::string & elementBlock,
93  const int worksetSize=WorksetSizeType::CLASSIC_MODE,
94  const bool requiresPartitioning=false,
95  const bool applyOrientations=true)
96  : elementBlock_(elementBlock),
97  worksetSize_(worksetSize),
100  sideAssembly_(false)
101  {
102  TEUCHOS_TEST_FOR_EXCEPTION(elementBlock_=="",std::runtime_error,
103  "WorksetDescriptor constr: Element block name must be non-empty!");
104  }
105 
115  WorksetDescriptor(const std::string & elementBlock,
116  const std::string & sideset,
117  const bool sideAssembly)
118  : elementBlock_(elementBlock),
119  sideset_(sideset),
121  requiresPartitioning_(false),
122  applyOrientations_(true),
124  {
125  TEUCHOS_TEST_FOR_EXCEPTION(elementBlock_=="",std::runtime_error,
126  "WorksetDescriptor constr: Element block name must be non-empty!");
127  TEUCHOS_TEST_FOR_EXCEPTION(sideset_=="",std::runtime_error,
128  "WorksetDescriptor constr: Side set name must be non-empty!");
129  }
130 
146  WorksetDescriptor(const std::string & elementBlock,
147  const std::string & sideset,
148  const int worksetSize=WorksetSizeType::CLASSIC_MODE,
149  const bool requiresPartitioning=false,
150  const bool applyOrientations=true)
151  : elementBlock_(elementBlock),
152  sideset_(sideset),
153  worksetSize_(worksetSize),
156  sideAssembly_(false)
157  {
158  TEUCHOS_TEST_FOR_EXCEPTION(elementBlock_=="",std::runtime_error,
159  "WorksetDescriptor constr: Element block name must be non-empty!");
160  TEUCHOS_TEST_FOR_EXCEPTION(sideset_=="",std::runtime_error,
161  "WorksetDescriptor constr: Side set name must be non-empty!");
162  }
163 
182  WorksetDescriptor(const std::string & elementBlock_0,
183  const std::string & elementBlock_1,
184  const std::string & sideset_0,
185  const std::string & sideset_1,
186  const int worksetSize=WorksetSizeType::CLASSIC_MODE,
187  const bool requiresPartitioning=false,
188  const bool applyOrientations=true)
189  : elementBlock_(elementBlock_0),
190  elementBlock_2_(elementBlock_1),
191  sideset_(sideset_0),
192  sideset_2_(sideset_1),
193  worksetSize_(worksetSize),
196  sideAssembly_(false)
197  {
198  TEUCHOS_TEST_FOR_EXCEPTION(elementBlock_=="",std::runtime_error,
199  "WorksetDescriptor constr: Element block 0 name must be non-empty!");
200  TEUCHOS_TEST_FOR_EXCEPTION(sideset_=="",std::runtime_error,
201  "WorksetDescriptor constr: Side set 0 name must be non-empty!");
202  TEUCHOS_TEST_FOR_EXCEPTION(elementBlock_2_=="",std::runtime_error,
203  "WorksetDescriptor constr: Element block 1 name must be non-empty!");
204  TEUCHOS_TEST_FOR_EXCEPTION(sideset_2_=="",std::runtime_error,
205  "WorksetDescriptor constr: Side set 1 name must be non-empty!");
206  }
207 
209  WorksetDescriptor(const WorksetDescriptor & src) = default;
210 
218  const std::string & getElementBlock(const int block=0) const
219  { return (block==0) ? elementBlock_ : elementBlock_2_; }
220 
228  const std::string & getSideset(const int block=0) const
229  { return (block==0) ? sideset_ : sideset_2_; }
230 
232  //TEUCHOS_DEPRECATED
233  bool sideAssembly() const
234  { return sideAssembly_; }
235 // { return useSideset(); }
236 
242  {
243  return useSideset() and elementBlock_2_ != "";
244  }
245 
252  bool requiresPartitioning() const
253  {
254  return requiresPartitioning_;
255  }
256 
258  bool useSideset() const
259  //{ return useSideset_; }
260  { return sideset_ != ""; }
261 
263  int getWorksetSize() const
264  { return worksetSize_; }
265 
266  bool applyOrientations() const {return applyOrientations_;}
267 
268 private:
269 
271  std::string elementBlock_;
272 
274  std::string elementBlock_2_;
275 
277  std::string sideset_;
278 
280  std::string sideset_2_;
281 
284 
287 
290 
296 };
297 
299 inline bool operator==(const WorksetDescriptor & a,const WorksetDescriptor & b)
300 {
301  if(a.useSideset())
302  // if side set is in use, check all fields
303  return a.getElementBlock()==b.getElementBlock()
304  && a.getSideset()==b.getSideset()
305  && a.sideAssembly()==b.sideAssembly()
306  && a.useSideset()==b.useSideset();
307  else
308  // otherwise check that both descriptor don't use side sets
309  // and check the element block (the remaining fields are allowed
310  // to be unset)
311  return a.getElementBlock()==b.getElementBlock()
312  && a.useSideset()==b.useSideset();
313 }
314 
316 inline std::size_t hash_value(const WorksetDescriptor & wd)
317 {
318  std::size_t seed = 0;
319 
321  if(wd.useSideset()) {
322  // optionally hash on side set and side assembly
323  panzer::hash_combine(seed,wd.getSideset());
325  }
326 
327  return seed;
328 }
329 
331 inline std::ostream & operator<<(std::ostream & os,const WorksetDescriptor & wd)
332 {
333  if(wd.useSideset())
334  os << "Side descriptor: "
335  << "eblock = \"" << wd.getElementBlock() << "\", "
336  << "ss = \"" << wd.getSideset() << "\", "
337  << "side assembly = " << (wd.sideAssembly() ? "on" : "off");
338  else
339  os << "Block descriptor: "
340  << "eblock = \"" << wd.getElementBlock() << "\"";
341 
342  return os;
343 }
344 
347 //TEUCHOS_DEPRECATED
348 inline WorksetDescriptor blockDescriptor(const std::string & eBlock)
349 { return WorksetDescriptor(eBlock); }
350 
353 //TEUCHOS_DEPRECATED
354 inline WorksetDescriptor sidesetDescriptor(const std::string & eBlock,const std::string & sideset)
355 { return WorksetDescriptor(eBlock,sideset,false); }
356 
360 //TEUCHOS_DEPRECATED
361 inline WorksetDescriptor sidesetVolumeDescriptor(const std::string & eBlock,const std::string & sideset)
362 { return WorksetDescriptor(eBlock,sideset,true); }
363 
364 }
365 
366 namespace std {
367 
368 template <>
369 struct hash<panzer::WorksetDescriptor>
370 {
371  std::size_t operator()(const panzer::WorksetDescriptor& wd) const
372  {
373  std::size_t seed = 0;
374 
376  if(wd.useSideset()) {
377  // optionally hash on side set and side assembly
378  panzer::hash_combine(seed,wd.getSideset());
380  }
381 
382  return seed;
383  }
384 };
385 
386 }
387 
388 #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...
std::size_t hash_value(const WorksetDescriptor &wd)
Hash function that satisifies the stl hash interface.
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.
int worksetSize_
Requested workset size.
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)
const std::string & getSideset(const int block=0) const
Get sideset name.
WorksetDescriptor(const std::string &elementBlock, const std::string &sideset, const int worksetSize=WorksetSizeType::CLASSIC_MODE, const bool requiresPartitioning=false, const bool applyOrientations=true)
bool operator==(const WorksetDescriptor &a, const WorksetDescriptor &b)
Equality operation for use with hash tables and maps.
bool connectsElementBlocks() const
Identifies this workset as an interface between two element blocks.
WorksetDescriptor(const std::string &elementBlock, const std::string &sideset, const bool sideAssembly)
WorksetDescriptor sidesetVolumeDescriptor(const std::string &eBlock, const std::string &sideset)
bool requiresPartitioning() const
Do we need to partition the local mesh prior to generating worksets.
std::string elementBlock_
Element block, required to be non-empty.
bool sideAssembly() const
Expects side set assembly on volume.
int getWorksetSize() const
Get the requested workset size (default -2 (workset size is set elsewhere), -1 (largest possible work...
bool useSideset() const
This descriptor is for a side set.
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.
void hash_combine(std::size_t &seed, const T &v)
std::ostream & operator<<(std::ostream &os, const AssemblyEngineInArgs &in)
std::size_t operator()(const panzer::WorksetDescriptor &wd) const
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::string & getElementBlock(const int block=0) const
Get element block name.
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.