Panzer  Version of the Day
Panzer_PointRule.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 
44 #include "Panzer_PointRule.hpp"
45 
46 #include "Teuchos_Assert.hpp"
47 #include "Phalanx_DataLayout_MDALayout.hpp"
48 #include "Intrepid2_DefaultCubatureFactory.hpp"
49 #include "Panzer_Dimension.hpp"
50 #include "Panzer_CellData.hpp"
52 
54 PointRule(const std::string & ptName,
55  int np,
56  const panzer::CellData& cell_data) :
57  side(-1)
58 {
59  setup(ptName,np,cell_data);
60 }
61 
63 PointRule(const std::string & point_rule_name,
64  const int num_cells,
65  const int num_points_per_cell,
66  const int num_faces,
67  const int num_points_per_face,
68  const Teuchos::RCP<const shards::CellTopology> & cell_topology)
69 {
70  setup(point_rule_name, num_cells, num_points_per_cell, num_faces, num_points_per_face, cell_topology);
71 }
72 
76 PointRule(const panzer::PointDescriptor& description,
77  const Teuchos::RCP<const shards::CellTopology> & cell_topology,
78  const int num_cells)
79 {
80  int num_points_per_cell = description.getGenerator().numPoints(*cell_topology);
81  setup(description.getType(), num_cells, num_points_per_cell, 0, 0, cell_topology);
82 }
83 
85 setup(const std::string & ptName,
86  int np,
87  const panzer::CellData& cell_data)
88 {
89  point_name = ptName;
90  num_points = np;
91  spatial_dimension = cell_data.baseCellDimension();
92  workset_size = cell_data.numCells();
93  _num_faces = -1;
94  _num_points_per_face = -1;
95 
96  topology = cell_data.getCellTopology();
97  TEUCHOS_TEST_FOR_EXCEPTION(topology==Teuchos::null,std::runtime_error,
98  "PointRule::setup - Base topology from cell_data cannot be null!");
99  TEUCHOS_TEST_FOR_EXCEPTION(spatial_dimension!=(int) topology->getDimension(), std::runtime_error,
100  "PointRule::setup - Spatial dimension from cell_data does not match the cell topology.");
101 
102  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(topology), std::runtime_error,
103  "PointRule::setup - Failed to allocate cell topology!");
104 
105  // handle side issues : first veryify the 0D side follows the rules
106  if(cell_data.isSide() && spatial_dimension==1) {
107  TEUCHOS_ASSERT(num_points==1); // only one point on a node
108  }
109 
110  // now extract side topology
111  side_topology = getSideTopology(cell_data);
112  if (side_topology!=Teuchos::null)
113  side = cell_data.side();
114 
115  TEUCHOS_TEST_FOR_EXCEPTION(side >= 0 && Teuchos::is_null(side_topology),
116  std::runtime_error,
117  "Failed to allocate side topology!");
118 
119  // allocate data layout objects
120  using Teuchos::rcp;
121  using PHX::MDALayout;
122 
123  dl_scalar =
124  rcp(new MDALayout<Cell,IP>(workset_size,num_points));
125 
126  dl_vector =
127  rcp(new MDALayout<Cell,IP,Dim>(workset_size, num_points,
128  spatial_dimension));
129 
130  dl_tensor =
131  rcp(new MDALayout<Cell,IP,Dim,Dim>(workset_size, num_points,
132  spatial_dimension,
133  spatial_dimension));
134 
135  dl_vector3 =
136  rcp(new MDALayout<Cell,IP,Dim>(workset_size, num_points,3));
137  dl_tensor3x3 =
138  rcp(new MDALayout<Cell,IP,Dim,Dim>(workset_size, num_points,3,3));
139 
140 }
141 
142 
144 setup(const std::string & point_rule_name,
145  const int num_cells,
146  const int num_points_per_cell,
147  const int num_faces,
148  const int num_points_per_face,
149  const Teuchos::RCP<const shards::CellTopology> & cell_topology)
150 {
151 
152  topology = cell_topology;
153  TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::is_null(topology),std::runtime_error,
154  "PointRule::setup - Cell topology cannot be null.");
155 
156  point_name = point_rule_name;
157  num_points = num_points_per_cell;
158  spatial_dimension = cell_topology->getDimension();
159  workset_size = num_cells;
160  _num_faces = num_faces;
161  _num_points_per_face = num_points_per_face;
162  side = -1;
163 
164  // allocate data layout objects
165  dl_scalar = Teuchos::rcp(new PHX::MDALayout<Cell,IP>(workset_size,num_points));
166  dl_vector = Teuchos::rcp(new PHX::MDALayout<Cell,IP,Dim>(workset_size, num_points,spatial_dimension));
167  dl_tensor = Teuchos::rcp(new PHX::MDALayout<Cell,IP,Dim,Dim>(workset_size, num_points,spatial_dimension,spatial_dimension));
168 
169  dl_vector3 = Teuchos::rcp(new PHX::MDALayout<Cell,IP,Dim>(workset_size, num_points,3));
170  dl_tensor3x3 = Teuchos::rcp(new PHX::MDALayout<Cell,IP,Dim,Dim>(workset_size, num_points,3,3));
171 
172 }
173 
174 const std::string & panzer::PointRule::getName() const
175 {
176  return point_name;
177 }
178 
180 {
181  return (!Teuchos::is_null(side_topology));
182 }
183 
184 Teuchos::RCP<shards::CellTopology> panzer::PointRule::getSideTopology(const CellData & cell_data)
185 {
186  Teuchos::RCP<shards::CellTopology> sideTopo;
187  int spatial_dimension = cell_data.baseCellDimension();
188  Teuchos::RCP<const shards::CellTopology> topology = cell_data.getCellTopology();
189 
190  if (cell_data.isSide() && spatial_dimension>1) {
191  int side = cell_data.side();
192 
193  TEUCHOS_TEST_FOR_EXCEPTION( (side >= static_cast<int>(topology->getSideCount())),
194  std::runtime_error, "Error - local side "
195  << side << " is not in range (0->" << topology->getSideCount()-1
196  << ") of topologic entity!");
197 
198  sideTopo = Teuchos::rcp(new shards::CellTopology(topology->getCellTopologyData(topology->getDimension()-1,side)));
199  }
200  else if(cell_data.isSide() && spatial_dimension==1) {
201  sideTopo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData<shards::Node>()));
202  }
203 
204  return sideTopo;
205 }
206 
207 Teuchos::RCP<PHX::DataLayout>
209 {return Teuchos::rcp(new PHX::MDALayout<Cell>(workset_size));}
210 
211 Teuchos::RCP<PHX::DataLayout>
213 {return Teuchos::rcp(new PHX::MDALayout<Cell,Dim>(workset_size, dim0));}
214 
215 Teuchos::RCP<PHX::DataLayout>
216 panzer::PointRule::getCellDataLayout(const int dim0, const int dim1) const
217 {return Teuchos::rcp(new PHX::MDALayout<Cell,Dim,Dim>(workset_size, dim0, dim1));}
218 
219 
220 Teuchos::RCP<PHX::DataLayout>
222 {return Teuchos::rcp(new PHX::MDALayout<Cell,IP>(workset_size, num_points));}
223 
224 Teuchos::RCP<PHX::DataLayout>
226 {return Teuchos::rcp(new PHX::MDALayout<Cell,IP,Dim>(workset_size, num_points, dim0));}
227 
228 Teuchos::RCP<PHX::DataLayout>
229 panzer::PointRule::getCellPointDataLayout(const int dim0, const int dim1) const
230 {return Teuchos::rcp(new PHX::MDALayout<Cell,IP,Dim,Dim>(workset_size, num_points, dim0, dim1));}
231 
232 
233 Teuchos::RCP<PHX::DataLayout>
235 {return Teuchos::rcp(new PHX::MDALayout<Face>(_num_faces));}
236 
237 Teuchos::RCP<PHX::DataLayout>
239 {return Teuchos::rcp(new PHX::MDALayout<Face,Dim>(_num_faces, dim0));}
240 
241 Teuchos::RCP<PHX::DataLayout>
242 panzer::PointRule::getFaceDataLayout(const int dim0, const int dim1) const
243 {return Teuchos::rcp(new PHX::MDALayout<Face,Dim,Dim>(_num_faces, dim0, dim1));}
244 
245 
246 Teuchos::RCP<PHX::DataLayout>
248 {return Teuchos::rcp(new PHX::MDALayout<Face,IP>(_num_faces, _num_points_per_face));}
249 
250 Teuchos::RCP<PHX::DataLayout>
252 {return Teuchos::rcp(new PHX::MDALayout<Face,IP,Dim>(_num_faces, _num_points_per_face, dim0));}
253 
254 Teuchos::RCP<PHX::DataLayout>
255 panzer::PointRule::getFacePointDataLayout(const int dim0, const int dim1) const
256 {return Teuchos::rcp(new PHX::MDALayout<Face,IP,Dim,Dim>(_num_faces, _num_points_per_face, dim0, dim1));}
257 
258 
259 
260 void panzer::PointRule::print(std::ostream & os)
261 {
262  os << "panzer::PointRule ( "
263  << "Name = " << getName()
264  << ", Dimension = " << spatial_dimension
265  << ", Workset Size = " << workset_size
266  << ", Num Points = " << num_points
267  << ", Side = " << side
268  << " )";
269 }
Data for determining cell topology and dimensionality.
int baseCellDimension() const
Dimension of the base cell. NOT the dimension of the local side, even if the side() method returns tr...
bool isSide() const
Teuchos::RCP< const shards::CellTopology > getCellTopology() const
Get CellTopology for the base cell.
std::size_t numCells() const
const std::string & getType() const
Get unique string associated with the type of point descriptor. This will be used generate a hash to ...
const PointGenerator & getGenerator() const
virtual int numPoints(const shards::CellTopology &topo) const =0
Get the points for a particular topology.
Teuchos::RCP< PHX::DataLayout > getFaceDataLayout() const
Teuchos::RCP< PHX::DataLayout > getFacePointDataLayout() const
static Teuchos::RCP< shards::CellTopology > getSideTopology(const CellData &cell_data)
virtual void print(std::ostream &os)
print information about the integration rule
void setup(const std::string &ptName, int np, const panzer::CellData &cell_data)
Teuchos::RCP< PHX::DataLayout > getCellDataLayout() const
Teuchos::RCP< PHX::DataLayout > getCellPointDataLayout() const
const std::string & getName() const