Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_PureBasis.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_PureBasis.hpp"
44 #include "Panzer_Dimension.hpp"
45 #include "Panzer_CellData.hpp"
48 #include "Teuchos_Assert.hpp"
49 #include "Phalanx_DataLayout_MDALayout.hpp"
50 #include <sstream>
51 
53 PureBasis(const std::string & basis_type,
54  const int basis_order,
55  const int num_cells,
56  const Teuchos::RCP<const shards::CellTopology> & cell_topology) :
57  topology_(cell_topology),
58  num_cells_(num_cells)
59 {
60  initialize(basis_type,basis_order);
61 }
62 
64 PureBasis(const std::string & in_basis_type,
65  const int in_basis_order,
66  const CellData & in_cell_data) :
67  topology_(in_cell_data.getCellTopology()),
68  num_cells_(in_cell_data.numCells())
69 {
70  initialize(in_basis_type,in_basis_order);
71 }
72 
74 PureBasis(const panzer::BasisDescriptor & description,
75  const Teuchos::RCP<const shards::CellTopology> & cell_topology,
76  const int num_cells):
77  topology_(cell_topology),
78  num_cells_(num_cells)
79 {
80  initialize(description.getType(), description.getOrder());
81 }
82 
83 void panzer::PureBasis::initialize(const std::string & in_basis_type,const int in_basis_order)
84 {
85  // Support for deprecated basis descriptions
86  std::string basis_type = in_basis_type;
87  int basis_order = in_basis_order;
88 
89  if (basis_type=="Q1" || basis_type=="T1") {
90  basis_type = "HGrad";
91  basis_order = 1;
92  }
93  else if (basis_type == "Q2" || basis_type=="T2") {
94  basis_type = "HGrad";
95  basis_order = 2;
96  }
97  else if (basis_type == "TEdge1" || basis_type=="QEdge1") {
98  basis_type = "HCurl";
99  basis_order = 1;
100  }
101  else if(basis_type == "Const") {
102  basis_type = "Const";
103  basis_order = 0;
104  }
105  // End deprecated basis support
106 
107  intrepid_basis_ = panzer::createIntrepid2Basis<PHX::Device::execution_space,double,double>(basis_type, basis_order, *topology_);
108 
109  basis_type_ = basis_type;
110 
111  std::ostringstream os;
112  os << basis_type_ << ":" << basis_order;
113  basis_name_ = os.str();
114 
115  field_basis_name_ = "Basis: " + basis_name_;
116  field_basis_name_D1_ = "Grad Basis: " + basis_name_;
117  field_basis_name_D2_ = "D2 Basis: " + basis_name_;
118 
119  if( basis_type_ == "HGrad")
120  element_space_ = HGRAD;
121  else if(basis_type_=="HCurl")
122  element_space_ = HCURL;
123  else if(basis_type_=="HDiv")
124  element_space_ = HDIV;
125  else if(basis_type_=="Const")
126  element_space_ = CONST;
127  else if(basis_type_=="HVol")
128  element_space_ = HVOL;
129  else { TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
130  "PureBasis::initializeIntrospection - Invalid basis name \""
131  << basis_type_ << "\""); }
132 
133  switch(getElementSpace()) {
134  case CONST:
135  basis_rank_ = 0;
136  break;
137  case HVOL:
138  basis_rank_ = 0;
139  break;
140  case HGRAD:
141  basis_rank_ = 0;
142  break;
143  case HCURL:
144  basis_rank_ = 1;
145  break;
146  case HDIV:
147  basis_rank_ = 1;
148  break;
149  default:
150  TEUCHOS_ASSERT(false);
151  break;
152  };
153 
154  using Teuchos::rcp;
155  using PHX::MDALayout;
156 
157  cell_data = rcp(new MDALayout<Cell>(numCells()));
158 
159  functional = rcp(new MDALayout<Cell,BASIS>(numCells(), cardinality()));
160 
161  functional_grad = rcp(new MDALayout<Cell,BASIS,Dim>(numCells(),
162  cardinality(),
163  dimension()));
164 
165  coordinates = rcp(new MDALayout<Cell,BASIS,Dim>(numCells(),
166  cardinality(),
167  dimension()));
168 
169  functional_D2 = rcp(new MDALayout<Cell,BASIS,Dim,Dim>(numCells(),
170  cardinality(),
171  dimension(),
172  dimension()));
173 
174  local_mat_layout = Teuchos::rcp(new PHX::MDALayout<panzer::Cell, panzer::BASIS, panzer::BASIS>(
175  this->numCells(), this->cardinality(), this->cardinality()));
176 
177 }
178 
180 {
181  return intrepid_basis_->getCardinality();
182 }
183 
185 {
186  return num_cells_;
187 }
188 
190 {
191  return topology_->getDimension();
192 }
193 
194 std::string panzer::PureBasis::type() const
195 {
196  return basis_type_;
197 }
198 
200 {
201  return intrepid_basis_->getDegree();
202 }
203 
204 std::string panzer::PureBasis::name() const
205 {
206  return basis_name_;
207 }
208 
209 std::string panzer::PureBasis::fieldName() const
210 {
211  return field_basis_name_;
212 }
213 
215 {
216  return field_basis_name_D1_;
217 }
218 
220 {
221  return field_basis_name_D2_;
222 }
223 
226 {
227  return intrepid_basis_;
228 }
229 
230 bool
232 {
233  // typedef Kokkos::DynRankView<double,PHX::Device> Array;
234  // Teuchos::RCP<const Intrepid2::DofCoordsInterface<Array> > coord_interface
235  // = Teuchos::rcp_dynamic_cast<const Intrepid2::DofCoordsInterface<Array> >(getIntrepid2Basis());
236 
237  // return !Teuchos::is_null(coord_interface);
238 
239  return true;
240 }
std::string name() const
A unique key that is the combination of the basis type and basis order.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
int order() const
Returns the polynomial order of the basis.
int cardinality() const
Returns the number of basis coefficients.
std::string fieldName() const
int dimension() const
Returns the dimension of the basis from the topology.
bool supportsBasisCoordinates() const
std::string type() const
Returns the basis type.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
const std::string & getType() const
Get type of basis.
Data for determining cell topology and dimensionality.
PureBasis(const std::string &basis_type, const int basis_order, const CellData &cell_data)
Teuchos::RCP< Intrepid2::Basis< PHX::Device::execution_space, double, double > > getIntrepid2Basis() const
int getOrder() const
Get order of basis.
int numCells() const
Returns the number of cells in the data layouts.
void initialize(const std::string &basis_type, const int basis_order)
Initialize the basis object.
#define TEUCHOS_ASSERT(assertion_test)
std::string fieldNameD1() const
std::string fieldNameD2() const