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"
47 #include "Teuchos_Assert.hpp"
48 #include "Phalanx_DataLayout_MDALayout.hpp"
49 #include <sstream>
50 
52 PureBasis(const std::string & basis_type,
53  const int basis_order,
54  const int num_cells,
55  const Teuchos::RCP<const shards::CellTopology> & cell_topology) :
56  topology_(cell_topology),
57  num_cells_(num_cells)
58 {
59  initialize(basis_type,basis_order);
60 }
61 
63 PureBasis(const std::string & basis_type,const int basis_order,const CellData & cell_data) :
64  topology_(cell_data.getCellTopology()),
65  num_cells_(cell_data.numCells())
66 {
67  initialize(basis_type,basis_order);
68 }
69 
70 void panzer::PureBasis::initialize(const std::string & in_basis_type,const int in_basis_order)
71 {
72  // Support for deprecated basis descriptions
73  std::string basis_type = in_basis_type;
74  int basis_order = in_basis_order;
75 
76  if (basis_type=="Q1" || basis_type=="T1") {
77  basis_type = "HGrad";
78  basis_order = 1;
79  }
80  else if (basis_type == "Q2" || basis_type=="T2") {
81  basis_type = "HGrad";
82  basis_order = 2;
83  }
84  else if (basis_type == "TEdge1" || basis_type=="QEdge1") {
85  basis_type = "HCurl";
86  basis_order = 1;
87  }
88  else if(basis_type == "Const") {
89  basis_type = "Const";
90  basis_order = 0;
91  }
92  // End deprecated basis support
93 
94  intrepid_basis_ = panzer::createIntrepid2Basis<double,Kokkos::DynRankView<double,PHX::Device> >(basis_type, basis_order, topology_);
95 
96  basis_type_ = basis_type;
97 
98  std::ostringstream os;
99  os << basis_type_ << ":" << basis_order;
100  basis_name_ = os.str();
101 
102  field_basis_name_ = "Basis: " + basis_name_;
103  field_basis_name_D1_ = "Grad Basis: " + basis_name_;
104  field_basis_name_D2_ = "D2 Basis: " + basis_name_;
105 
106  if( basis_type_ == "HGrad")
107  element_space_ = HGRAD;
108  else if(basis_type_=="HCurl")
109  element_space_ = HCURL;
110  else if(basis_type_=="HDiv")
111  element_space_ = HDIV;
112  else if(basis_type_=="Const")
113  element_space_ = CONST;
114  else { TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
115  "PureBasis::initializeIntrospection - Invalid basis name \""
116  << basis_type_ << "\""); }
117 
118  switch(getElementSpace()) {
119  case CONST:
120  basis_rank_ = 0;
121  break;
122  case HGRAD:
123  basis_rank_ = 0;
124  break;
125  case HCURL:
126  basis_rank_ = 1;
127  break;
128  case HDIV:
129  basis_rank_ = 1;
130  break;
131  default:
132  TEUCHOS_ASSERT(false);
133  break;
134  };
135 
136  using Teuchos::rcp;
137  using PHX::MDALayout;
138 
139  cell_data = rcp(new MDALayout<Cell>(numCells()));
140 
141  functional = rcp(new MDALayout<Cell,BASIS>(numCells(), cardinality()));
142 
143  functional_grad = rcp(new MDALayout<Cell,BASIS,Dim>(numCells(),
144  cardinality(),
145  dimension()));
146 
147  coordinates = rcp(new MDALayout<Cell,BASIS,Dim>(numCells(),
148  cardinality(),
149  dimension()));
150 
151  functional_D2 = rcp(new MDALayout<Cell,BASIS,Dim,Dim>(numCells(),
152  cardinality(),
153  dimension(),
154  dimension()));
155 }
156 
158 {
159  return intrepid_basis_->getCardinality();
160 }
161 
163 {
164  return num_cells_;
165 }
166 
168 {
169  return topology_->getDimension();
170 }
171 
172 std::string panzer::PureBasis::type() const
173 {
174  return basis_type_;
175 }
176 
178 {
179  return intrepid_basis_->getDegree();
180 }
181 
182 std::string panzer::PureBasis::name() const
183 {
184  return basis_name_;
185 }
186 
187 std::string panzer::PureBasis::fieldName() const
188 {
189  return field_basis_name_;
190 }
191 
193 {
194  return field_basis_name_D1_;
195 }
196 
198 {
199  return field_basis_name_D2_;
200 }
201 
202 Teuchos::RCP< Intrepid2::Basis<double,Kokkos::DynRankView<double,PHX::Device> > >
204 {
205  return intrepid_basis_;
206 }
207 
208 bool
210 {
211  typedef Kokkos::DynRankView<double,PHX::Device> Array;
212  Teuchos::RCP<const Intrepid2::DofCoordsInterface<Array> > coord_interface
213  = Teuchos::rcp_dynamic_cast<const Intrepid2::DofCoordsInterface<Array> >(getIntrepid2Basis());
214 
215  return !Teuchos::is_null(coord_interface);
216 }
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)
std::string fieldNameD2() const
int dimension() const
Returns the dimension of the basis from the topology.
std::string fieldName() const
Teuchos::RCP< Intrepid2::Basis< double, Kokkos::DynRankView< double, PHX::Device > > > getIntrepid2Basis() 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.