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 //
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 #include "Panzer_FieldLibrary.hpp"
44 
45 namespace panzer {
46 
48 {
50 
51  if(layout==Teuchos::null) {
52  std::stringstream ss;
53  print(ss);
54  TEUCHOS_TEST_FOR_EXCEPTION(layout==Teuchos::null,std::logic_error,
55  "panzer::FieldLayoutLibrary::lookupBasis: cannot find field with name \"" + fieldName + "\"!\n"+ss.str());
56  }
57 
58  return layout->getBasis();
59 }
60 
62 {
63  bases.clear();
64 
65  // simply loop over map of basis name to pointers and add them to the vector
66  std::map<std::string,Teuchos::RCP<const panzer::PureBasis> >::const_iterator itr;
67  for(itr=basisNameToPointer_.begin();itr!=basisNameToPointer_.end();++itr)
68  bases.push_back(itr->second);
69 }
70 
71 void FieldLayoutLibrary::addFieldAndLayout(const std::string & fieldName,
73 {
74  fieldToLayout_[fieldName] = layout;
75  basisNameToPointer_[layout->getBasis()->name()] = layout->getBasis();
76 }
77 
79 {
80  typedef std::map<std::string,Teuchos::RCP<panzer::BasisIRLayout> > Map;
81  Map::const_iterator itr = fieldToLayout_.find(fieldName);
82  if(itr!=fieldToLayout_.end())
83  return itr->second;
84 
85  return Teuchos::null;
86 }
87 
88 void FieldLayoutLibrary::print(std::ostream & os) const
89 {
90  typedef std::map<std::string,Teuchos::RCP<panzer::BasisIRLayout> > Map;
91 
92  for(Map::const_iterator itr=fieldToLayout_.begin();itr!=fieldToLayout_.end();++itr) {
93  std::string fieldName = itr->first;
94  Teuchos::RCP<BasisIRLayout> basis = itr->second;
95 
96  os << "\"" << fieldName << "\"" << " {" << basis->name()
97  << "(dim=" << basis->dimension()
98  << ",cells=" << basis->numCells()
99  << ",points=" << basis->numPoints() << ")} ";
100  }
101 }
102 
103 void FieldLayoutLibrary::basisPairs(std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > & bases) const
104 {
105  typedef std::map<std::string,Teuchos::RCP<panzer::BasisIRLayout> > Map;
106  bases.clear();
107 
108  for(Map::const_iterator itr=fieldToLayout_.begin();itr!=fieldToLayout_.end();++itr) {
109  std::string fieldName = itr->first;
110  Teuchos::RCP<const PureBasis> basis = itr->second->getBasis();
111 
112  bases.push_back(std::make_pair(fieldName,basis));
113  }
114 }
115 
117 
119 {
120  typedef std::map<std::string,Teuchos::RCP<panzer::PureBasis> > Map;
121  Map::const_iterator itr = fieldToBasis_.find(fieldName);
122  if(itr!=fieldToBasis_.end())
123  return itr->second;
124 
125  return Teuchos::null;
126 }
127 
129 {
130  bases.clear();
131 
132  // simply loop over map of basis name to pointers and add them to the vector
133  std::map<std::string,Teuchos::RCP<const panzer::PureBasis> >::const_iterator itr;
134  for(itr=basisNameToPointer_.begin();itr!=basisNameToPointer_.end();++itr)
135  bases.push_back(itr->second);
136 }
137 
138 void FieldLibrary::addFieldAndBasis(const std::string & fieldName,
139  const Teuchos::RCP<panzer::PureBasis> & basis)
140 {
141  fieldToBasis_[fieldName] = basis;
142  basisNameToPointer_[basis->name()] = basis;
143 }
144 
146 {
147  typedef std::map<std::string,Teuchos::RCP<panzer::PureBasis> > Map;
148 
150 
151  // loop over each member of the map, create a new FieldLayout and addit to layout library
152  for(Map::const_iterator itr=fieldToBasis_.begin();itr!=fieldToBasis_.end();++itr) {
153  Teuchos::RCP<BasisIRLayout> layout = Teuchos::rcp(new BasisIRLayout(itr->second,ir));
154  layoutLibrary->addFieldAndLayout(itr->first,layout);
155  }
156 
157  return layoutLibrary;
158 }
159 
160 void FieldLibrary::print(std::ostream & os) const
161 {
162  typedef std::map<std::string,Teuchos::RCP<panzer::PureBasis> > Map;
163 
164  for(Map::const_iterator itr=fieldToBasis_.begin();itr!=fieldToBasis_.end();++itr) {
165  std::string fieldName = itr->first;
166  Teuchos::RCP<PureBasis> basis = itr->second;
167 
168  os << "\"" << fieldName << "\"" << " {" << basis->name()
169  << "(dim=" << basis->dimension()
170  << ",cells=" << basis->numCells() << ") ";
171  }
172 }
173 
175 void FieldLibrary::basisPairs(std::vector<std::pair<std::string,Teuchos::RCP<const panzer::PureBasis> > > & bases) const
176 {
177  typedef std::map<std::string,Teuchos::RCP<panzer::PureBasis> > Map;
178  bases.clear();
179 
180  for(Map::const_iterator itr=fieldToBasis_.begin();itr!=fieldToBasis_.end();++itr) {
181  std::string fieldName = itr->first;
182  Teuchos::RCP<PureBasis> basis = itr->second;
183 
184  bases.push_back(std::make_pair(fieldName,basis.getConst()));
185  }
186 }
187 
188 }
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