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_(-1)
61 {
62  // thats all!
63  ebToNeeds_ = needs;
64 }
65 
70  : wkstFactory_(wc.wkstFactory_)
71  , worksetSize_(wc.worksetSize_)
72 {
73 }
74 
79 {
80  worksets_.clear();
81  sideWorksets_.clear();
82 }
83 
85 setNeeds(const std::string & eBlock,const WorksetNeeds & needs)
86 {
87  clear(); // clear out old worksets
88  ebToNeeds_[eBlock] = needs;
89 }
90 
92 const WorksetNeeds & WorksetContainer::lookupNeeds(const std::string & eBlock) const
93 {
94  std::map<std::string,WorksetNeeds>::const_iterator itr = ebToNeeds_.find(eBlock);
95 
96  TEUCHOS_TEST_FOR_EXCEPTION(itr==ebToNeeds_.end(),std::logic_error,
97  "WorksetContainer::lookupNeeds no WorksetNeeds object is associated "
98  "with the element block \""+eBlock+"\".");
99 
100  return itr->second;
101 }
102 
105 {
106  Teuchos::RCP<std::vector<Workset> > worksetVector;
107  WorksetMap::iterator itr = worksets_.find(wd);
108  if(itr==worksets_.end()) {
109  // couldn't find workset, build it!
110  const WorksetNeeds & needs = lookupNeeds(wd.getElementBlock());
111  worksetVector = wkstFactory_->getWorksets(wd,needs);
112 
113  // apply orientations to the just constructed worksets
114  if(worksetVector!=Teuchos::null && wd.applyOrientations()) {
115  applyOrientations(wd.getElementBlock(),*worksetVector);
116  }
117 
118  if(worksetVector!=Teuchos::null)
119  setIdentifiers(wd,*worksetVector);
120 
121  // store vector for reuse in the future
122  worksets_[wd] = worksetVector;
123  }
124  else
125  worksetVector = itr->second;
126 
127  return worksetVector;
128 }
129 
133 {
135 
136  // this is the key for the workset map
137  SideMap::iterator itr = sideWorksets_.find(desc);
138 
139  if(itr==sideWorksets_.end()) {
140  // couldn't find workset, build it!
141  if (desc.connectsElementBlocks()) {
142  worksetMap = wkstFactory_->getSideWorksets(desc, lookupNeeds(desc.getElementBlock(0)),
143  lookupNeeds(desc.getElementBlock(1)));
144  }
145  else {
146  worksetMap = wkstFactory_->getSideWorksets(desc,lookupNeeds(desc.getElementBlock(0)));
147  }
148 
149  // apply orientations to the worksets for this side
150  if(worksetMap!=Teuchos::null)
151  applyOrientations(desc,*worksetMap);
152 
153  if(worksetMap!=Teuchos::null)
154  setIdentifiers(desc,*worksetMap);
155 
156  // store map for reuse in the future
157  sideWorksets_[desc] = worksetMap;
158  }
159  else {
160  worksetMap = itr->second;
161  }
162 
163  return worksetMap;
164 }
165 
166 
169 {
170  // apply the orientations for stored worksets
171  applyOrientations(ugi);
172 }
173 
175 addBasis(const std::string & type,int order,const std::string & rep_field)
176 {
177  using Teuchos::RCP;
178  using Teuchos::rcp;
179 
180  for(auto itr=ebToNeeds_.begin();itr!=ebToNeeds_.end();++itr) {
181  WorksetNeeds & needs = itr->second;
182  RCP<PureBasis> basis = rcp(new PureBasis(type,order,needs.cellData));
183 
184  // add in the new basis
185  needs.bases.push_back(basis);
186  needs.rep_field_name.push_back(rep_field);
187  }
188 
189  // clear all arrays, lazy evaluation means it will be rebuilt
190  clear();
191 }
192 
195 {
196  // this gurantees orientations won't accidently be applied twice.
197  TEUCHOS_ASSERT(globalIndexer_==Teuchos::null);
198 
199  globalIndexer_ = ugi;
200 
201  // this should be created once and stored in an appropriate place
202  TEUCHOS_TEST_FOR_EXCEPTION(globalIndexer_ == Teuchos::null, std::logic_error,
203  "global indexer is not set yet");
205 
206  // loop over volume worksets, apply orientations to each
207  for(WorksetMap::iterator itr=worksets_.begin();
208  itr!=worksets_.end();++itr) {
209  std::string eBlock = itr->first.getElementBlock();
210 
211  applyOrientations(eBlock,*itr->second);
212  }
213 
214  // loop over side worksets, apply orientations to each
215  for(SideMap::iterator itr=sideWorksets_.begin();
216  itr!=sideWorksets_.end();itr++) {
217 
218  applyOrientations(itr->first,*itr->second);
219  }
220 }
221 
223 setIdentifiers(const WorksetDescriptor & wd,std::vector<Workset> & worksets)
224 {
225  std::size_t hash = std::hash<WorksetDescriptor>()(wd); // this is really ugly, is this really a C++ standard?
226  for(std::size_t i=0;i<worksets.size();i++)
227  worksets[i].setIdentifier(hash+i);
228 }
229 
231 setIdentifiers(const WorksetDescriptor & wd,std::map<unsigned,Workset> & workset_map)
232 {
233  std::size_t hash = std::hash<WorksetDescriptor>()(wd); // this is really ugly, is this really a C++ standard?
234  std::size_t offset = 0;
235  for(auto itr : workset_map) {
236  // itr.second.setIdentifier(hash+offset);
237  workset_map[itr.first].setIdentifier(hash+offset);
238 
239  offset++;
240  }
241 }
242 
244 applyOrientations(const std::string & eBlock, std::vector<Workset> & worksets) const
245 {
246  using Teuchos::RCP;
247 
249  // this is for volume worksets //
251 
252  // short circuit if no global indexer exists
253  if(globalIndexer_==Teuchos::null) {
254  Teuchos::FancyOStream fout(Teuchos::rcpFromRef(std::cout));
255  fout.setOutputToRootOnly(0);
256 
257  fout << "Panzer Warning: No global indexer assigned to a workset container. "
258  << "Orientation of the basis for edge basis functions cannot be applied, "
259  << "if those basis functions are used, there will be problems!" << std::endl;
260  return;
261  }
262 
263  // this should be matched to global indexer size (not sure how to retrive it)
264  TEUCHOS_TEST_FOR_EXCEPTION(orientations_ == Teuchos::null, std::logic_error,
265  "intrepid2 orientation is not constructed");
266 
267  // loop over each basis requiring orientations, then apply them
269 
270  // Note: It may be faster to loop over the basis pairs on the inside (not really sure)
271 
272  const WorksetNeeds & needs = lookupNeeds(eBlock);
273 
274  if(needs.bases.size()>0) {
275  // sanity check that we aren't missing something (the old and new "needs" should not be used together)
276  TEUCHOS_ASSERT(needs.getBases().size()==0);
277 
278  for(std::size_t w=0;w<needs.bases.size();w++) {
279  const PureBasis & basis = *needs.bases[w];
280 
281  // no need for this if orientations are not required!
282  if(!basis.requiresOrientations())
283  continue;
284 
285  // build accessors for orientation fields
286  std::vector<Intrepid2::Orientation> ortsPerBlock;
287 
288  // loop over worksets compute and apply orientations
289  for(std::size_t i=0;i<worksets.size();i++) {
290  // break out of the workset loop
291  if(worksets[i].num_cells<=0) continue;
292 
293  for(std::size_t j=0;j<worksets[i].numDetails();j++) {
294  WorksetDetails & details = worksets[i](j);
295 
296  ortsPerBlock.clear();
297  for (int k=0;k<worksets[i].num_cells;++k) {
298  ortsPerBlock.push_back((*orientations_)[details.cell_local_ids[k]]);
299  }
300 
301  for(std::size_t basis_index=0;basis_index<details.bases.size();basis_index++) {
302  Teuchos::RCP<const BasisIRLayout> layout = details.bases[basis_index]->basis_layout;
303 
304  // only apply orientations if its relevant to the current needs
305  if(layout->getBasis()->name()!=basis.name())
306  continue;
307 
308  TEUCHOS_ASSERT(layout!=Teuchos::null);
309  TEUCHOS_ASSERT(layout->getBasis()!=Teuchos::null);
310  if(layout->getBasis()->requiresOrientations()) {
311  // apply orientations for this basis
312  details.bases[basis_index]->applyOrientations(ortsPerBlock,(int) worksets[i].num_cells);
313  }
314  }
315  }
316  }
317  } // end for w
318  }
319  else if(needs.getBases().size()>0) {
320  // sanity check that we aren't missing something (the old and new "needs" should not be used together)
321  TEUCHOS_ASSERT(needs.bases.size()==0);
322 
323  // This is for forwards compatibility, the needs now use "getBasis" calls as opposed
324  // to director accessors.
325  for(const auto & bd : needs.getBases()) {
326 
327  // build accessors for orientation fields
328  std::vector<Intrepid2::Orientation> ortsPerBlock;
329 
330  // loop over worksets compute and apply orientations
331  for(std::size_t i=0;i<worksets.size();i++) {
332  // break out of the workset loop
333  if(worksets[i].num_cells<=0) continue;
334 
335  for(std::size_t j=0;j<worksets[i].numDetails();j++) {
336  WorksetDetails & details = worksets[i](j);
337 
338  ortsPerBlock.clear();
339  // for (int k=0;k<worksets[i].num_cells;++k) {
340  for (int k=0;k<details.numOwnedCells();++k) {
341  ortsPerBlock.push_back((*orientations_)[details.cell_local_ids[k]]);
342  }
343 
344  for(const auto & id : needs.getIntegrators()) {
345  // apply orientations for this basis
346  details.getBasisValues(bd,id).applyOrientations(ortsPerBlock,(int) worksets[i].num_cells);
347  }
348  }
349  }
350  } // end for w
351  }
352 }
353 
354 
356 applyOrientations(const WorksetDescriptor & desc,std::map<unsigned,Workset> & worksets) const
357 {
358  using Teuchos::RCP;
359 
361  // this is for side worksets //
363 
364  // short circuit if no global indexer exists
365  if(globalIndexer_==Teuchos::null) {
366  Teuchos::FancyOStream fout(Teuchos::rcpFromRef(std::cout));
367  fout.setOutputToRootOnly(0);
368 
369  fout << "Panzer Warning: No global indexer assigned to a workset container. "
370  << "Orientation of the basis for edge basis functions cannot be applied, "
371  << "if those basis functions are used, there will be problems!";
372  return;
373  }
374 
375  // loop over each basis requiring orientations, then apply them
377 
378  // Note: It may be faster to loop over the basis pairs on the inside (not really sure)
379  const WorksetNeeds & needs = lookupNeeds(desc.getElementBlock());
380 
381  if(needs.bases.size()>0) {
382  // sanity check that we aren't missing something (the old and new "needs" should not be used together)
383  TEUCHOS_ASSERT(needs.getBases().size()==0);
384  for(std::size_t i=0;i<needs.bases.size();i++) {
385  const PureBasis & basis = *needs.bases[i];
386 
387  // no need for this if orientations are not required!
388  if(!basis.requiresOrientations()) continue;
389 
390  // build accessors for orientation fields
391  std::vector<Intrepid2::Orientation> ortsPerBlock;
392 
393  // loop over worksets compute and apply orientations
394  for(std::map<unsigned,Workset>::iterator itr=worksets.begin();
395  itr!=worksets.end();++itr) {
396 
397  // break out of the workset loop
398  if(itr->second.num_cells<=0) continue;
399 
400  for(std::size_t j=0;j<itr->second.numDetails();j++) {
401  WorksetDetails & details = itr->second(j);
402 
403  ortsPerBlock.clear();
404  for (int k=0;k<itr->second.num_cells;++k) {
405  ortsPerBlock.push_back((*orientations_)[details.cell_local_ids[k]]);
406  }
407 
408  for(std::size_t basis_index=0;basis_index<details.bases.size();basis_index++) {
409  Teuchos::RCP<const BasisIRLayout> layout = details.bases[basis_index]->basis_layout;
410 
411  // only apply orientations if its relevant to the current needs
412  if(layout->getBasis()->name()!=basis.name())
413  continue;
414 
415  TEUCHOS_ASSERT(layout!=Teuchos::null);
416  TEUCHOS_ASSERT(layout->getBasis()!=Teuchos::null);
417  if(layout->getBasis()->requiresOrientations()) {
418  // apply orientations for this basis
419  details.bases[basis_index]->applyOrientations(ortsPerBlock,(int) itr->second.num_cells);
420  }
421  }
422  }
423  }
424  } // end for i
425  }
426  else if(needs.getBases().size()>0) {
427  // sanity check that we aren't missing something (the old and new "needs" should not be used together)
428  TEUCHOS_ASSERT(needs.bases.size()==0);
429 
430  // This is for forwards compatibility, the needs now use "getBasis" calls as opposed
431  // to director accessors.
432  for(const auto & bd : needs.getBases()) {
433 
434  // build accessors for orientation fields
435  std::vector<Intrepid2::Orientation> ortsPerBlock;
436 
437  // loop over worksets compute and apply orientations
438  for(std::map<unsigned,Workset>::iterator itr=worksets.begin();
439  itr!=worksets.end();++itr) {
440 
441  // break out of the workset loop
442  if(itr->second.num_cells<=0) continue;
443 
444  for(std::size_t j=0;j<itr->second.numDetails();j++) {
445  WorksetDetails & details = itr->second(j);
446 
447  ortsPerBlock.clear();
448  for (int k=0;k<itr->second.num_cells;++k) {
449  ortsPerBlock.push_back((*orientations_)[details.cell_local_ids[k]]);
450  }
451 
452  for(const auto & id : needs.getIntegrators()) {
453  // apply orientations for this basis
454  details.getBasisValues(bd,id).applyOrientations(ortsPerBlock,(int) itr->second.num_cells);
455  }
456  }
457  }
458  } // end for w
459  }
460 }
461 
463  const std::vector<std::string> & elementBlockNames,
464  std::map<std::string,Teuchos::RCP<std::vector<Workset> > > & volumeWksts)
465 {
466  for(std::size_t i=0;i<elementBlockNames.size();i++) {
467  WorksetDescriptor wd = blockDescriptor(elementBlockNames[i]);
468  volumeWksts[elementBlockNames[i]] = wc.getWorksets(wd);
469  }
470 }
471 
473  const std::vector<BC> & bcs,
474  std::map<BC,Teuchos::RCP<std::map<unsigned,Workset> >,LessBC> & sideWksts)
475 {
476  for(std::size_t i=0;i<bcs.size();i++) {
477  WorksetDescriptor wd(bcs[i].elementBlockID(),bcs[i].sidesetID());
479  if(wksts!=Teuchos::null)
480  sideWksts[bcs[i]] = wksts;
481  }
482 }
483 
484 }
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
Teuchos::RCP< std::vector< Intrepid2::Orientation > > orientations_
bool connectsElementBlocks() const
Identifies this workset as an interface between two element blocks.
void setGlobalIndexer(const Teuchos::RCP< const panzer::UniqueGlobalIndexerBase > &ugi)
WorksetContainer()
Default contructor, starts with no workset factory objects.
#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
Class that provides access to worksets on each element block and side set.
bool requiresOrientations() const
Teuchos::RCP< std::vector< Intrepid2::Orientation > > buildIntrepidOrientation(const Teuchos::RCP< const UniqueGlobalIndexerBase > globalIndexer)
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)
void applyOrientations(const Teuchos::RCP< const panzer::UniqueGlobalIndexerBase > &ugi)
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.
Teuchos::RCP< const panzer::UniqueGlobalIndexerBase > globalIndexer_
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)