Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_WorksetContainer.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 
44 
46 
50 #include "Panzer_Dimension.hpp"
51 
52 namespace panzer {
53 
56  : worksetSize_(1)
57 {}
59  const std::map<std::string,WorksetNeeds> & needs)
60  : wkstFactory_(factory), worksetSize_(0)
61 {
62  // thats all!
63  ebToNeeds_ = needs;
64 }
65 
70  : wkstFactory_(wc.wkstFactory_)
71  , worksetSize_(wc.worksetSize_)
72 {
73 }
74 
79 {
80  this->clearVolumeWorksets();
81  this->clearSideWorksets();
82 }
83 
85 {
86  worksets_.clear();
87 }
88 
90 {
91  sideWorksets_.clear();
92 }
93 
95 setNeeds(const std::string & eBlock,const WorksetNeeds & needs)
96 {
97  clear(); // clear out old worksets
98  ebToNeeds_[eBlock] = needs;
99 }
100 
102 const WorksetNeeds & WorksetContainer::lookupNeeds(const std::string & eBlock) const
103 {
104  std::map<std::string,WorksetNeeds>::const_iterator itr = ebToNeeds_.find(eBlock);
105 
106  TEUCHOS_TEST_FOR_EXCEPTION(itr==ebToNeeds_.end(),std::logic_error,
107  "WorksetContainer::lookupNeeds no WorksetNeeds object is associated "
108  "with the element block \""+eBlock+"\".");
109 
110  return itr->second;
111 }
112 
115 {
116  Teuchos::RCP<std::vector<Workset> > worksetVector;
117  WorksetMap::iterator itr = worksets_.find(wd);
118  if(itr==worksets_.end()) {
119  // couldn't find workset, build it!
120  const WorksetNeeds & needs = lookupNeeds(wd.getElementBlock());
121  worksetVector = wkstFactory_->getWorksets(wd,needs);
122 
123  // apply orientations to the just constructed worksets
124  if(worksetVector!=Teuchos::null && wd.applyOrientations()) {
125  applyOrientations(wd.getElementBlock(),*worksetVector);
126  }
127 
128  if(worksetVector!=Teuchos::null)
129  setIdentifiers(wd,*worksetVector);
130 
131  // store vector for reuse in the future
132  worksets_[wd] = worksetVector;
133  }
134  else
135  worksetVector = itr->second;
136 
137  return worksetVector;
138 }
139 
143 {
145 
146  // this is the key for the workset map
147  SideMap::iterator itr = sideWorksets_.find(desc);
148 
149  if(itr==sideWorksets_.end()) {
150  // couldn't find workset, build it!
151  if (desc.connectsElementBlocks()) {
152  worksetMap = wkstFactory_->getSideWorksets(desc, lookupNeeds(desc.getElementBlock(0)),
153  lookupNeeds(desc.getElementBlock(1)));
154  }
155  else {
156  worksetMap = wkstFactory_->getSideWorksets(desc,lookupNeeds(desc.getElementBlock(0)));
157  }
158 
159  // apply orientations to the worksets for this side
160  if(worksetMap!=Teuchos::null)
161  applyOrientations(desc,*worksetMap);
162 
163  if(worksetMap!=Teuchos::null)
164  setIdentifiers(desc,*worksetMap);
165 
166  // store map for reuse in the future
167  sideWorksets_[desc] = worksetMap;
168  }
169  else {
170  worksetMap = itr->second;
171  }
172 
173  return worksetMap;
174 }
175 
176 
179 {
180  // apply the orientations for stored worksets
181  applyOrientations(ugi);
182 }
183 
185 addBasis(const std::string & type,int order,const std::string & rep_field)
186 {
187  using Teuchos::RCP;
188  using Teuchos::rcp;
189 
190  for(auto itr=ebToNeeds_.begin();itr!=ebToNeeds_.end();++itr) {
191  WorksetNeeds & needs = itr->second;
192  RCP<PureBasis> basis = rcp(new PureBasis(type,order,needs.cellData));
193 
194  // add in the new basis
195  needs.bases.push_back(basis);
196  needs.rep_field_name.push_back(rep_field);
197  }
198 
199  // clear all arrays, lazy evaluation means it will be rebuilt
200  clear();
201 }
202 
205 {
206  // this gurantees orientations won't accidently be applied twice.
207  TEUCHOS_ASSERT(globalIndexer_==Teuchos::null);
208 
209  globalIndexer_ = ugi;
210 
211  // this should be created once and stored in an appropriate place
212  TEUCHOS_TEST_FOR_EXCEPTION(globalIndexer_ == Teuchos::null, std::logic_error,
213  "global indexer is not set yet");
215 
216  // loop over volume worksets, apply orientations to each
217  for(WorksetMap::iterator itr=worksets_.begin();
218  itr!=worksets_.end();++itr) {
219  std::string eBlock = itr->first.getElementBlock();
220 
221  applyOrientations(eBlock,*itr->second);
222  }
223 
224  // loop over side worksets, apply orientations to each
225  for(SideMap::iterator itr=sideWorksets_.begin();
226  itr!=sideWorksets_.end();itr++) {
227 
228  applyOrientations(itr->first,*itr->second);
229  }
230 }
231 
233 setIdentifiers(const WorksetDescriptor & wd,std::vector<Workset> & worksets)
234 {
235  std::size_t hash = std::hash<WorksetDescriptor>()(wd); // this is really ugly, is this really a C++ standard?
236  for(std::size_t i=0;i<worksets.size();i++)
237  worksets[i].setIdentifier(hash+i);
238 }
239 
241 setIdentifiers(const WorksetDescriptor & wd,std::map<unsigned,Workset> & workset_map)
242 {
243  std::size_t hash = std::hash<WorksetDescriptor>()(wd); // this is really ugly, is this really a C++ standard?
244  std::size_t offset = 0;
245  for(auto itr : workset_map) {
246  // itr.second.setIdentifier(hash+offset);
247  workset_map[itr.first].setIdentifier(hash+offset);
248 
249  offset++;
250  }
251 }
252 
254 applyOrientations(const std::string & eBlock, std::vector<Workset> & worksets) const
255 {
256  using Teuchos::RCP;
257 
259  // this is for volume worksets //
261 
262  // short circuit if no global indexer exists
263  if(globalIndexer_==Teuchos::null) {
264  Teuchos::FancyOStream fout(Teuchos::rcpFromRef(std::cout));
265  fout.setOutputToRootOnly(0);
266 
267  fout << "Panzer Warning: No global indexer assigned to a workset container. "
268  << "Orientation of the basis for edge basis functions cannot be applied, "
269  << "if those basis functions are used, there will be problems!" << std::endl;
270  return;
271  }
272 
273  // this should be matched to global indexer size (not sure how to retrive it)
274  TEUCHOS_TEST_FOR_EXCEPTION(orientations_ == Teuchos::null, std::logic_error,
275  "intrepid2 orientation is not constructed");
276 
277  // loop over each basis requiring orientations, then apply them
279 
280  // Note: It may be faster to loop over the basis pairs on the inside (not really sure)
281 
282  const WorksetNeeds & needs = lookupNeeds(eBlock);
283 
284  if(needs.bases.size()>0) {
285  // sanity check that we aren't missing something (the old and new "needs" should not be used together)
286  TEUCHOS_ASSERT(needs.getBases().size()==0);
287 
288  for(std::size_t w=0;w<needs.bases.size();w++) {
289  const PureBasis & basis = *needs.bases[w];
290 
291  // no need for this if orientations are not required!
292  if(!basis.requiresOrientations())
293  continue;
294 
295  // build accessors for orientation fields
296  std::vector<Intrepid2::Orientation> ortsPerBlock;
297 
298  // loop over worksets compute and apply orientations
299  for(std::size_t i=0;i<worksets.size();i++) {
300  // break out of the workset loop
301  if(worksets[i].num_cells<=0) continue;
302 
303  for(std::size_t j=0;j<worksets[i].numDetails();j++) {
304  WorksetDetails & details = worksets[i](j);
305 
306  ortsPerBlock.clear();
307  for (int k=0;k<worksets[i].num_cells;++k) {
308  ortsPerBlock.push_back((*orientations_)[details.cell_local_ids[k]]);
309  }
310 
311  for(std::size_t basis_index=0;basis_index<details.bases.size();basis_index++) {
312  Teuchos::RCP<const BasisIRLayout> layout = details.bases[basis_index]->basis_layout;
313 
314  // only apply orientations if its relevant to the current needs
315  if(layout->getBasis()->name()!=basis.name())
316  continue;
317 
318  TEUCHOS_ASSERT(layout!=Teuchos::null);
319  TEUCHOS_ASSERT(layout->getBasis()!=Teuchos::null);
320  if(layout->getBasis()->requiresOrientations()) {
321  // apply orientations for this basis
322  details.bases[basis_index]->applyOrientations(ortsPerBlock,(int) worksets[i].num_cells);
323  }
324  }
325  }
326  }
327  } // end for w
328  }
329  else if(needs.getBases().size()>0) {
330  // sanity check that we aren't missing something (the old and new "needs" should not be used together)
331  TEUCHOS_ASSERT(needs.bases.size()==0);
332 
333  // This is for forwards compatibility, the needs now use "getBasis" calls as opposed
334  // to director accessors.
335  for(const auto & bd : needs.getBases()) {
336 
337  // build accessors for orientation fields
338  std::vector<Intrepid2::Orientation> ortsPerBlock;
339 
340  // loop over worksets compute and apply orientations
341  for(std::size_t i=0;i<worksets.size();i++) {
342  // break out of the workset loop
343  if(worksets[i].num_cells<=0) continue;
344 
345  for(std::size_t j=0;j<worksets[i].numDetails();j++) {
346  WorksetDetails & details = worksets[i](j);
347 
348  ortsPerBlock.clear();
349  // for (int k=0;k<worksets[i].num_cells;++k) {
350  for (int k=0;k<details.numOwnedCells();++k) {
351  ortsPerBlock.push_back((*orientations_)[details.cell_local_ids[k]]);
352  }
353 
354  for(const auto & id : needs.getIntegrators()) {
355  // apply orientations for this basis
356  details.getBasisValues(bd,id).applyOrientations(ortsPerBlock,(int) worksets[i].num_cells);
357  }
358  }
359  }
360  } // end for w
361  }
362 }
363 
364 
366 applyOrientations(const WorksetDescriptor & desc,std::map<unsigned,Workset> & worksets) const
367 {
368  using Teuchos::RCP;
369 
371  // this is for side worksets //
373 
374  // short circuit if no global indexer exists
375  if(globalIndexer_==Teuchos::null) {
376  Teuchos::FancyOStream fout(Teuchos::rcpFromRef(std::cout));
377  fout.setOutputToRootOnly(0);
378 
379  fout << "Panzer Warning: No global indexer assigned to a workset container. "
380  << "Orientation of the basis for edge basis functions cannot be applied, "
381  << "if those basis functions are used, there will be problems!";
382  return;
383  }
384 
385  // loop over each basis requiring orientations, then apply them
387 
388  // Note: It may be faster to loop over the basis pairs on the inside (not really sure)
389  const WorksetNeeds & needs = lookupNeeds(desc.getElementBlock());
390 
391  if(needs.bases.size()>0) {
392  // sanity check that we aren't missing something (the old and new "needs" should not be used together)
393  TEUCHOS_ASSERT(needs.getBases().size()==0);
394  for(std::size_t i=0;i<needs.bases.size();i++) {
395  const PureBasis & basis = *needs.bases[i];
396 
397  // no need for this if orientations are not required!
398  if(!basis.requiresOrientations()) continue;
399 
400  // build accessors for orientation fields
401  std::vector<Intrepid2::Orientation> ortsPerBlock;
402 
403  // loop over worksets compute and apply orientations
404  for(std::map<unsigned,Workset>::iterator itr=worksets.begin();
405  itr!=worksets.end();++itr) {
406 
407  // break out of the workset loop
408  if(itr->second.num_cells<=0) continue;
409 
410  for(std::size_t j=0;j<itr->second.numDetails();j++) {
411  WorksetDetails & details = itr->second(j);
412 
413  ortsPerBlock.clear();
414  for (int k=0;k<itr->second.num_cells;++k) {
415  ortsPerBlock.push_back((*orientations_)[details.cell_local_ids[k]]);
416  }
417 
418  for(std::size_t basis_index=0;basis_index<details.bases.size();basis_index++) {
419  Teuchos::RCP<const BasisIRLayout> layout = details.bases[basis_index]->basis_layout;
420 
421  // only apply orientations if its relevant to the current needs
422  if(layout->getBasis()->name()!=basis.name())
423  continue;
424 
425  TEUCHOS_ASSERT(layout!=Teuchos::null);
426  TEUCHOS_ASSERT(layout->getBasis()!=Teuchos::null);
427  if(layout->getBasis()->requiresOrientations()) {
428  // apply orientations for this basis
429  details.bases[basis_index]->applyOrientations(ortsPerBlock,(int) itr->second.num_cells);
430  }
431  }
432  }
433  }
434  } // end for i
435  }
436  else if(needs.getBases().size()>0) {
437  // sanity check that we aren't missing something (the old and new "needs" should not be used together)
438  TEUCHOS_ASSERT(needs.bases.size()==0);
439 
440  // This is for forwards compatibility, the needs now use "getBasis" calls as opposed
441  // to director accessors.
442  for(const auto & bd : needs.getBases()) {
443 
444  // build accessors for orientation fields
445  std::vector<Intrepid2::Orientation> ortsPerBlock;
446 
447  // loop over worksets compute and apply orientations
448  for(std::map<unsigned,Workset>::iterator itr=worksets.begin();
449  itr!=worksets.end();++itr) {
450 
451  // break out of the workset loop
452  if(itr->second.num_cells<=0) continue;
453 
454  for(std::size_t j=0;j<itr->second.numDetails();j++) {
455  WorksetDetails & details = itr->second(j);
456 
457  ortsPerBlock.clear();
458  for (int k=0;k<itr->second.num_cells;++k) {
459  ortsPerBlock.push_back((*orientations_)[details.cell_local_ids[k]]);
460  }
461 
462  for(const auto & id : needs.getIntegrators()) {
463  // apply orientations for this basis
464  details.getBasisValues(bd,id).applyOrientations(ortsPerBlock,(int) itr->second.num_cells);
465  }
466  }
467  }
468  } // end for w
469  }
470 }
471 
473  const std::vector<std::string> & elementBlockNames,
474  std::map<std::string,Teuchos::RCP<std::vector<Workset> > > & volumeWksts)
475 {
476  for(std::size_t i=0;i<elementBlockNames.size();i++) {
477  WorksetDescriptor wd = blockDescriptor(elementBlockNames[i]);
478  volumeWksts[elementBlockNames[i]] = wc.getWorksets(wd);
479  }
480 }
481 
483  const std::vector<BC> & bcs,
484  std::map<BC,Teuchos::RCP<std::map<unsigned,Workset> >,LessBC> & sideWksts)
485 {
486  for(std::size_t i=0;i<bcs.size();i++) {
487  WorksetDescriptor wd(bcs[i].elementBlockID(),bcs[i].sidesetID());
489  if(wksts!=Teuchos::null)
490  sideWksts[bcs[i]] = wksts;
491  }
492 }
493 
494 }
std::string name() const
A unique key that is the combination of the basis type and basis order.
std::vector< Teuchos::RCP< const PureBasis > > bases
void setGlobalIndexer(const Teuchos::RCP< const panzer::GlobalIndexer > &ugi)
Teuchos::RCP< std::vector< Intrepid2::Orientation > > orientations_
bool connectsElementBlocks() const
Identifies this workset as an interface between two element blocks.
WorksetContainer()
Default contructor, starts with no workset factory objects.
Teuchos::RCP< const panzer::GlobalIndexer > globalIndexer_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
panzer::BasisValues2< double > & getBasisValues(const panzer::BasisDescriptor &basis_description, const panzer::IntegrationDescriptor &integration_description)
Grab the basis values for a given basis description and integration description (throws error if it d...
std::vector< Teuchos::RCP< panzer::BasisValues2< double > > > bases
Static basis function data, key is basis name, value is index in the static_bases vector...
Teuchos::RCP< const WorksetFactoryBase > wkstFactory_
const std::string & getElementBlock(const int block=0) const
Get element block name.
int numOwnedCells() const
Number of cells owned by this workset.
std::vector< std::string > rep_field_name
void buildIntrepidOrientation(std::vector< Intrepid2::Orientation > &orientation, panzer::ConnManager &connMgr)
Class that provides access to worksets on each element block and side set.
bool requiresOrientations() const
WorksetMap worksets_
Maps element blocks to input physics block objects.
Teuchos::RCP< std::map< unsigned, Workset > > getSideWorksets(const WorksetDescriptor &desc)
Access, and construction of side worksets.
const std::vector< panzer::BasisDescriptor > & getBases() const
Get a list of bases being requested.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< std::vector< Workset > > getWorksets(const WorksetDescriptor &wd)
Access to volume worksets.
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
void setIdentifiers(const WorksetDescriptor &wd, std::vector< Workset > &worksets)
const std::vector< panzer::IntegrationDescriptor > & getIntegrators() const
Get a list of integrators being requested.
void applyOrientations(const Teuchos::RCP< const panzer::GlobalIndexer > &ugi)
const WorksetNeeds & lookupNeeds(const std::string &eBlock) const
Look up an input physics block, throws an exception if it can not be found.
void addBasis(const std::string &type, int order, const std::string &rep_field)
WorksetDescriptor blockDescriptor(const std::string &eBlock)
void getSideWorksetsFromContainer(WorksetContainer &wc, const std::vector< BC > &bcs, std::map< BC, Teuchos::RCP< std::map< unsigned, Workset > >, LessBC > &sideWksts)
Stores input information for a boundary condition.
Definition: Panzer_BC.hpp:81
Description and data layouts associated with a particular basis.
#define TEUCHOS_ASSERT(assertion_test)
void setNeeds(const std::string &eBlock, const WorksetNeeds &needs)
std::vector< GO > cell_local_ids
std::map< std::string, WorksetNeeds > ebToNeeds_
How to construct worksets.
void getVolumeWorksetsFromContainer(WorksetContainer &wc, const std::vector< std::string > &elementBlockNames, std::map< std::string, Teuchos::RCP< std::vector< Workset > > > &volumeWksts)