Panzer  Version of the Day
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 & basis_type,const int basis_order,const CellData & cell_data) :
65  topology_(cell_data.getCellTopology()),
66  num_cells_(cell_data.numCells())
67 {
68  initialize(basis_type,basis_order);
69 }
70 
72 PureBasis(const panzer::BasisDescriptor & description,
73  const Teuchos::RCP<const shards::CellTopology> & cell_topology,
74  const int num_cells):
75  topology_(cell_topology),
76  num_cells_(num_cells)
77 {
78  initialize(description.getType(), description.getOrder());
79 }
80 
81 void panzer::PureBasis::initialize(const std::string & in_basis_type,const int in_basis_order)
82 {
83  // Support for deprecated basis descriptions
84  std::string basis_type = in_basis_type;
85  int basis_order = in_basis_order;
86 
87  if (basis_type=="Q1" || basis_type=="T1") {
88  basis_type = "HGrad";
89  basis_order = 1;
90  }
91  else if (basis_type == "Q2" || basis_type=="T2") {
92  basis_type = "HGrad";
93  basis_order = 2;
94  }
95  else if (basis_type == "TEdge1" || basis_type=="QEdge1") {
96  basis_type = "HCurl";
97  basis_order = 1;
98  }
99  else if(basis_type == "Const") {
100  basis_type = "Const";
101  basis_order = 0;
102  }
103  // End deprecated basis support
104 
105  intrepid_basis_ = panzer::createIntrepid2Basis<PHX::Device::execution_space,double,double>(basis_type, basis_order, *topology_);
106 
107  basis_type_ = basis_type;
108 
109  std::ostringstream os;
110  os << basis_type_ << ":" << basis_order;
111  basis_name_ = os.str();
112 
113  field_basis_name_ = "Basis: " + basis_name_;
114  field_basis_name_D1_ = "Grad Basis: " + basis_name_;
115  field_basis_name_D2_ = "D2 Basis: " + basis_name_;
116 
117  if( basis_type_ == "HGrad")
118  element_space_ = HGRAD;
119  else if(basis_type_=="HCurl")
120  element_space_ = HCURL;
121  else if(basis_type_=="HDiv")
122  element_space_ = HDIV;
123  else if(basis_type_=="Const")
124  element_space_ = CONST;
125  else { TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
126  "PureBasis::initializeIntrospection - Invalid basis name \""
127  << basis_type_ << "\""); }
128 
129  switch(getElementSpace()) {
130  case CONST:
131  basis_rank_ = 0;
132  break;
133  case HGRAD:
134  basis_rank_ = 0;
135  break;
136  case HCURL:
137  basis_rank_ = 1;
138  break;
139  case HDIV:
140  basis_rank_ = 1;
141  break;
142  default:
143  TEUCHOS_ASSERT(false);
144  break;
145  };
146 
147  using Teuchos::rcp;
148  using PHX::MDALayout;
149 
150  cell_data = rcp(new MDALayout<Cell>(numCells()));
151 
152  functional = rcp(new MDALayout<Cell,BASIS>(numCells(), cardinality()));
153 
154  functional_grad = rcp(new MDALayout<Cell,BASIS,Dim>(numCells(),
155  cardinality(),
156  dimension()));
157 
158  coordinates = rcp(new MDALayout<Cell,BASIS,Dim>(numCells(),
159  cardinality(),
160  dimension()));
161 
162  functional_D2 = rcp(new MDALayout<Cell,BASIS,Dim,Dim>(numCells(),
163  cardinality(),
164  dimension(),
165  dimension()));
166 
167  local_mat_layout = Teuchos::rcp(new PHX::MDALayout<panzer::Cell, panzer::BASIS, panzer::BASIS>(
168  this->numCells(), this->cardinality(), this->cardinality()));
169 
170 }
171 
173 {
174  return intrepid_basis_->getCardinality();
175 }
176 
178 {
179  return num_cells_;
180 }
181 
183 {
184  return topology_->getDimension();
185 }
186 
187 std::string panzer::PureBasis::type() const
188 {
189  return basis_type_;
190 }
191 
193 {
194  return intrepid_basis_->getDegree();
195 }
196 
197 std::string panzer::PureBasis::name() const
198 {
199  return basis_name_;
200 }
201 
202 std::string panzer::PureBasis::fieldName() const
203 {
204  return field_basis_name_;
205 }
206 
208 {
209  return field_basis_name_D1_;
210 }
211 
213 {
214  return field_basis_name_D2_;
215 }
216 
217 Teuchos::RCP< Intrepid2::Basis<PHX::Device::execution_space,double,double> >
219 {
220  return intrepid_basis_;
221 }
222 
223 bool
225 {
226  // typedef Kokkos::DynRankView<double,PHX::Device> Array;
227  // Teuchos::RCP<const Intrepid2::DofCoordsInterface<Array> > coord_interface
228  // = Teuchos::rcp_dynamic_cast<const Intrepid2::DofCoordsInterface<Array> >(getIntrepid2Basis());
229 
230  // return !Teuchos::is_null(coord_interface);
231 
232  return true;
233 }
bool supportsBasisCoordinates() const
std::string name() const
A unique key that is the combination of the basis type and basis order.
std::string fieldNameD1() const
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
std::string fieldNameD2() const
int dimension() const
Returns the dimension of the basis from the topology.
std::string fieldName() const
int numCells() const
Returns the number of cells in the data layouts.
std::string type() const
Returns the basis type.
int order() const
Returns the polynomial order of the basis.
void initialize(const std::string &basis_type, const int basis_order)
Initialize the basis object.
int cardinality() const
Returns the number of basis coefficients.
int getOrder() const
Get order of basis.
const std::string & getType() const
Get type of basis.