Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_FieldLibrary.cpp
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 #include "Panzer_FieldLibrary.hpp"
12 
13 namespace panzer {
14 
16 {
18 
19  if(layout==Teuchos::null) {
20  std::stringstream ss;
21  print(ss);
22  TEUCHOS_TEST_FOR_EXCEPTION(layout==Teuchos::null,std::logic_error,
23  "panzer::FieldLayoutLibrary::lookupBasis: cannot find field with name \"" + fieldName + "\"!\n"+ss.str());
24  }
25 
26  return layout->getBasis();
27 }
28 
30 {
31  bases.clear();
32 
33  // simply loop over map of basis name to pointers and add them to the vector
34  std::map<std::string,Teuchos::RCP<const panzer::PureBasis> >::const_iterator itr;
35  for(itr=basisNameToPointer_.begin();itr!=basisNameToPointer_.end();++itr)
36  bases.push_back(itr->second);
37 }
38 
39 void FieldLayoutLibrary::addFieldAndLayout(const std::string & fieldName,
41 {
42  fieldToLayout_[fieldName] = layout;
43  basisNameToPointer_[layout->getBasis()->name()] = layout->getBasis();
44 }
45 
47 {
48  typedef std::map<std::string,Teuchos::RCP<panzer::BasisIRLayout> > Map;
49  Map::const_iterator itr = fieldToLayout_.find(fieldName);
50  if(itr!=fieldToLayout_.end())
51  return itr->second;
52 
53  return Teuchos::null;
54 }
55 
56 void FieldLayoutLibrary::print(std::ostream & os) const
57 {
58  typedef std::map<std::string,Teuchos::RCP<panzer::BasisIRLayout> > Map;
59 
60  for(Map::const_iterator itr=fieldToLayout_.begin();itr!=fieldToLayout_.end();++itr) {
61  std::string fieldName = itr->first;
62  Teuchos::RCP<BasisIRLayout> basis = itr->second;
63 
64  os << "\"" << fieldName << "\"" << " {" << basis->name()
65  << "(dim=" << basis->dimension()
66  << ",cells=" << basis->numCells()
67  << ",points=" << basis->numPoints() << ")} ";
68  }
69 }
70 
71 void FieldLayoutLibrary::basisPairs(std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > & bases) const
72 {
73  typedef std::map<std::string,Teuchos::RCP<panzer::BasisIRLayout> > Map;
74  bases.clear();
75 
76  for(Map::const_iterator itr=fieldToLayout_.begin();itr!=fieldToLayout_.end();++itr) {
77  std::string fieldName = itr->first;
78  Teuchos::RCP<const PureBasis> basis = itr->second->getBasis();
79 
80  bases.push_back(std::make_pair(fieldName,basis));
81  }
82 }
83 
85 
87 {
88  typedef std::map<std::string,Teuchos::RCP<panzer::PureBasis> > Map;
89  Map::const_iterator itr = fieldToBasis_.find(fieldName);
90  if(itr!=fieldToBasis_.end())
91  return itr->second;
92 
93  return Teuchos::null;
94 }
95 
97 {
98  bases.clear();
99 
100  // simply loop over map of basis name to pointers and add them to the vector
101  std::map<std::string,Teuchos::RCP<const panzer::PureBasis> >::const_iterator itr;
102  for(itr=basisNameToPointer_.begin();itr!=basisNameToPointer_.end();++itr)
103  bases.push_back(itr->second);
104 }
105 
106 void FieldLibrary::addFieldAndBasis(const std::string & fieldName,
107  const Teuchos::RCP<panzer::PureBasis> & basis)
108 {
109  fieldToBasis_[fieldName] = basis;
110  basisNameToPointer_[basis->name()] = basis;
111 }
112 
114 {
115  typedef std::map<std::string,Teuchos::RCP<panzer::PureBasis> > Map;
116 
118 
119  // loop over each member of the map, create a new FieldLayout and addit to layout library
120  for(Map::const_iterator itr=fieldToBasis_.begin();itr!=fieldToBasis_.end();++itr) {
121  Teuchos::RCP<BasisIRLayout> layout = Teuchos::rcp(new BasisIRLayout(itr->second,ir));
122  layoutLibrary->addFieldAndLayout(itr->first,layout);
123  }
124 
125  return layoutLibrary;
126 }
127 
128 void FieldLibrary::print(std::ostream & os) const
129 {
130  typedef std::map<std::string,Teuchos::RCP<panzer::PureBasis> > Map;
131 
132  for(Map::const_iterator itr=fieldToBasis_.begin();itr!=fieldToBasis_.end();++itr) {
133  std::string fieldName = itr->first;
134  Teuchos::RCP<PureBasis> basis = itr->second;
135 
136  os << "\"" << fieldName << "\"" << " {" << basis->name()
137  << "(dim=" << basis->dimension()
138  << ",cells=" << basis->numCells() << ") ";
139  }
140 }
141 
143 void FieldLibrary::basisPairs(std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > & bases) const
144 {
145  typedef std::map<std::string,Teuchos::RCP<panzer::PureBasis> > Map;
146  bases.clear();
147 
148  for(Map::const_iterator itr=fieldToBasis_.begin();itr!=fieldToBasis_.end();++itr) {
149  std::string fieldName = itr->first;
150  Teuchos::RCP<PureBasis> basis = itr->second;
151 
152  bases.push_back(std::make_pair(fieldName,basis.getConst()));
153  }
154 }
155 
156 }
std::string name() const
A unique key that is the combination of the basis type and basis order.
Teuchos::RCP< panzer::BasisIRLayout > lookupLayout(const std::string &fieldName) const
Get the basis associated with a particular field.
RCP< const T > getConst() const
virtual void basisPairs(std::vector< std::pair< std::string, Teuchos::RCP< const panzer::PureBasis > > > &bases) const
Get vector of unique bases contained in this field library.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const PureBasis > getBasis() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void uniqueBases(std::vector< Teuchos::RCP< const panzer::PureBasis > > &bases) const
Get vector of unique bases contained in this field library.
void uniqueBases(std::vector< Teuchos::RCP< const panzer::PureBasis > > &bases) const
Get vector of unique bases contained in this field library.
virtual void print(std::ostream &os) const
std::map< std::string, Teuchos::RCP< panzer::PureBasis > > fieldToBasis_
Basic mapped storage.
Teuchos::RCP< const FieldLayoutLibrary > buildFieldLayoutLibrary(panzer::PointRule &ir) const
virtual Teuchos::RCP< const panzer::PureBasis > lookupBasis(const std::string &fieldName) const
Get the basis associated with a particular field.
void addFieldAndLayout(const std::string &fieldName, const Teuchos::RCP< panzer::BasisIRLayout > &basis)
std::map< std::string, Teuchos::RCP< const panzer::PureBasis > > basisNameToPointer_
std::map< std::string, Teuchos::RCP< panzer::BasisIRLayout > > fieldToLayout_
Basic mapped storage.
virtual Teuchos::RCP< const panzer::PureBasis > lookupBasis(const std::string &fieldName) const
Get the basis associated with a particular field.
std::map< std::string, Teuchos::RCP< const panzer::PureBasis > > basisNameToPointer_
void addFieldAndBasis(const std::string &fieldName, const Teuchos::RCP< panzer::PureBasis > &basis)
virtual void basisPairs(std::vector< std::pair< std::string, Teuchos::RCP< const panzer::PureBasis > > > &bases) const
Get vector of unique bases contained in this field library.
virtual void print(std::ostream &os) const