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 
61 public:
62 
67  WorksetDescriptor(const std::string & eBlock)
68  : elementBlock_(eBlock),
69  useSideset_(false),
70  sideset_(""),
71  sideAssembly_(false)
72  { }
73 
83  WorksetDescriptor(const std::string & eBlock,
84  const std::string & sideset,
85  bool sideAssembly)
86  : elementBlock_(eBlock),
87  useSideset_(true),
88  sideset_(sideset),
90  {
91  TEUCHOS_TEST_FOR_EXCEPTION(sideset_=="",std::runtime_error,
92  "WorksetDescriptor constr: Side set name must be non-empty!");
93  }
94 
99  sideset_(src.sideset_),
101  {}
102 
104  std::string getElementBlock() const
105  { return elementBlock_; }
106 
108  std::string getSideset() const
109  { return sideset_; }
110 
112  bool sideAssembly() const
113  { return sideAssembly_; }
114 
116  bool useSideset() const
117  { return useSideset_; }
118 
119 private:
120 
122  std::string elementBlock_;
123 
126 
128  std::string sideset_;
129 
135 };
136 
138 inline bool operator==(const WorksetDescriptor & a,const WorksetDescriptor & b)
139 {
140  if(a.useSideset())
141  // if side set is in use, check all fields
142  return a.getElementBlock()==b.getElementBlock()
143  && a.getSideset()==b.getSideset()
144  && a.sideAssembly()==b.sideAssembly()
145  && a.useSideset()==b.useSideset();
146  else
147  // otherwise check that both descriptor don't use side sets
148  // and check the element block (the remaining fields are allowed
149  // to be unset)
150  return a.getElementBlock()==b.getElementBlock()
151  && a.useSideset()==b.useSideset();
152 }
153 
155 inline std::size_t hash_value(const WorksetDescriptor & wd)
156 {
157  std::size_t seed = 0;
158 
160  if(wd.useSideset()) {
161  // optionally hash on side set and side assembly
162  panzer::hash_combine(seed,wd.getSideset());
164  }
165 
166  return seed;
167 }
168 
170 inline std::ostream & operator<<(std::ostream & os,const WorksetDescriptor & wd)
171 {
172  if(wd.useSideset())
173  os << "Side descriptor: "
174  << "eblock = \"" << wd.getElementBlock() << "\", "
175  << "ss = \"" << wd.getSideset() << "\", "
176  << "side assembly = " << (wd.sideAssembly() ? "on" : "off");
177  else
178  os << "Block descriptor: "
179  << "eblock = \"" << wd.getElementBlock() << "\"";
180 
181  return os;
182 }
183 
186 inline WorksetDescriptor blockDescriptor(const std::string & eBlock)
187 { return WorksetDescriptor(eBlock); }
188 
191 inline WorksetDescriptor sidesetDescriptor(const std::string & eBlock,const std::string & sideset)
192 { return WorksetDescriptor(eBlock,sideset,false); }
193 
197 inline WorksetDescriptor sidesetVolumeDescriptor(const std::string & eBlock,const std::string & sideset)
198 { return WorksetDescriptor(eBlock,sideset,true); }
199 
200 }
201 
202 namespace std {
203 
204  template <>
205  struct hash<panzer::WorksetDescriptor>
206  {
207  std::size_t operator()(const panzer::WorksetDescriptor& wd) const
208  {
209  std::size_t seed = 0;
210 
212  if(wd.useSideset()) {
213  // optionally hash on side set and side assembly
214  panzer::hash_combine(seed,wd.getSideset());
216  }
217 
218  return seed;
219  }
220  };
221 
222 }
223 
224 #endif
WorksetDescriptor(const std::string &eBlock)
std::size_t hash_value(const WorksetDescriptor &wd)
Hash function that satisifies the stl hash interface.
std::string sideset_
Side set, must be non-empty if useSideset_ is true.
bool useSideset_
Use the side set information or not.
WorksetDescriptor sidesetDescriptor(const std::string &eBlock, const std::string &sideset)
WorksetDescriptor(const WorksetDescriptor &src)
Copy constructor.
bool operator==(const WorksetDescriptor &a, const WorksetDescriptor &b)
Equality operation for use with hash tables and maps.
WorksetDescriptor sidesetVolumeDescriptor(const std::string &eBlock, const std::string &sideset)
std::string elementBlock_
Element block, required to be non-empty.
bool sideAssembly() const
Expects side set assembly on volume.
std::string getSideset() const
Get the side set.
bool useSideset() const
This descriptor is for a side set.
WorksetDescriptor(const std::string &eBlock, const std::string &sideset, bool sideAssembly)
std::string getElementBlock() const
Get element block.
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 blockDescriptor(const std::string &eBlock)