Intrepid
Intrepid_CellToolsDef.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Pavel Bochev (pbboche@sandia.gov)
38 // Denis Ridzal (dridzal@sandia.gov), or
39 // Kara Peterson (kjpeter@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
44 
49 #ifndef INTREPID_CELLTOOLSDEF_HPP
50 #define INTREPID_CELLTOOLSDEF_HPP
51 
52 
53 namespace Intrepid {
54 
55  template<class Scalar>
57  const shards::CellTopology& parentCell){
58 
59 #ifdef HAVE_INTREPID_DEBUG
60  TEUCHOS_TEST_FOR_EXCEPTION( !(hasReferenceCell(parentCell) ), std::invalid_argument,
61  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): the specified cell topology does not have a reference cell.");
62 
63  TEUCHOS_TEST_FOR_EXCEPTION( !( (1 <= subcellDim) && (subcellDim <= 2 ) ), std::invalid_argument,
64  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): parametrization defined only for 1 and 2-dimensional subcells.");
65 #endif
66 
67  // Coefficients of the coordinate functions defining the parametrization maps are stored in
68  // rank-3 arrays with dimensions (SC, PCD, COEF) where:
69  // - SC is the subcell count of subcells with the specified dimension in the parent cell
70  // - PCD is Parent Cell Dimension, which gives the number of coordinate functions in the map:
71  // PCD = 2 for standard 2D cells and non-standard 2D cells: shell line and beam
72  // PCD = 3 for standard 3D cells and non-standard 3D cells: shell Tri and Quad
73  // - COEF is number of coefficients needed to specify a coordinate function:
74  // COEFF = 2 for edge parametrizations
75  // COEFF = 3 for both Quad and Tri face parametrizations. Because all Quad reference faces
76  // are affine, the coefficient of the bilinear term u*v is zero and is not stored, i.e.,
77  // 3 coefficients are sufficient to store Quad face parameterization maps.
78  //
79  // Arrays are sized and filled only when parametrization of a particular subcell is requested
80  // by setSubcellParametrization.
81 
82  // Edge maps for 2D non-standard cells: ShellLine and Beam
83  static FieldContainer<double> lineEdges; static int lineEdgesSet = 0;
84 
85  // Edge maps for 2D standard cells: Triangle and Quadrilateral
86  static FieldContainer<double> triEdges; static int triEdgesSet = 0;
87  static FieldContainer<double> quadEdges; static int quadEdgesSet = 0;
88 
89  // Edge maps for 3D non-standard cells: Shell Tri and Quad
90  static FieldContainer<double> shellTriEdges; static int shellTriEdgesSet = 0;
91  static FieldContainer<double> shellQuadEdges; static int shellQuadEdgesSet = 0;
92 
93  // Edge maps for 3D standard cells:
94  static FieldContainer<double> tetEdges; static int tetEdgesSet = 0;
95  static FieldContainer<double> hexEdges; static int hexEdgesSet = 0;
96  static FieldContainer<double> pyrEdges; static int pyrEdgesSet = 0;
97  static FieldContainer<double> wedgeEdges; static int wedgeEdgesSet = 0;
98 
99 
100  // Face maps for 3D non-standard cells: Shell Triangle and Quadrilateral
101  static FieldContainer<double> shellTriFaces; static int shellTriFacesSet = 0;
102  static FieldContainer<double> shellQuadFaces; static int shellQuadFacesSet = 0;
103 
104  // Face maps for 3D standard cells:
105  static FieldContainer<double> tetFaces; static int tetFacesSet = 0;
106  static FieldContainer<double> hexFaces; static int hexFacesSet = 0;
107  static FieldContainer<double> pyrFaces; static int pyrFacesSet = 0;
108  static FieldContainer<double> wedgeFaces; static int wedgeFacesSet = 0;
109 
110  // Select subcell parametrization according to its parent cell type
111  switch(parentCell.getKey() ) {
112 
113  // Tet cells
114  case shards::Tetrahedron<4>::key:
115  case shards::Tetrahedron<8>::key:
116  case shards::Tetrahedron<10>::key:
117  case shards::Tetrahedron<11>::key:
118  if(subcellDim == 2) {
119  if(!tetFacesSet){
120  setSubcellParametrization(tetFaces, subcellDim, parentCell);
121  tetFacesSet = 1;
122  }
123  return tetFaces;
124  }
125  else if(subcellDim == 1) {
126  if(!tetEdgesSet){
127  setSubcellParametrization(tetEdges, subcellDim, parentCell);
128  tetEdgesSet = 1;
129  }
130  return tetEdges;
131  }
132  else{
133  TEUCHOS_TEST_FOR_EXCEPTION( (subcellDim != 1 || subcellDim != 2), std::invalid_argument,
134  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): Tet parametrizations defined for 1 and 2-subcells only");
135  }
136  break;
137 
138  // Hex cells
139  case shards::Hexahedron<8>::key:
140  case shards::Hexahedron<20>::key:
141  case shards::Hexahedron<27>::key:
142  if(subcellDim == 2) {
143  if(!hexFacesSet){
144  setSubcellParametrization(hexFaces, subcellDim, parentCell);
145  hexFacesSet = 1;
146  }
147  return hexFaces;
148  }
149  else if(subcellDim == 1) {
150  if(!hexEdgesSet){
151  setSubcellParametrization(hexEdges, subcellDim, parentCell);
152  hexEdgesSet = 1;
153  }
154  return hexEdges;
155  }
156  else{
157  TEUCHOS_TEST_FOR_EXCEPTION( (subcellDim != 1 || subcellDim != 2), std::invalid_argument,
158  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): Hex parametrizations defined for 1 and 2-subcells only");
159  }
160  break;
161 
162  // Pyramid cells
163  case shards::Pyramid<5>::key:
164  case shards::Pyramid<13>::key:
165  case shards::Pyramid<14>::key:
166  if(subcellDim == 2) {
167  if(!pyrFacesSet){
168  setSubcellParametrization(pyrFaces, subcellDim, parentCell);
169  pyrFacesSet = 1;
170  }
171  return pyrFaces;
172  }
173  else if(subcellDim == 1) {
174  if(!pyrEdgesSet){
175  setSubcellParametrization(pyrEdges, subcellDim, parentCell);
176  pyrEdgesSet = 1;
177  }
178  return pyrEdges;
179  }
180  else {
181  TEUCHOS_TEST_FOR_EXCEPTION( (subcellDim != 1 || subcellDim != 2), std::invalid_argument,
182  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): Pyramid parametrizations defined for 1 and 2-subcells only");
183  }
184  break;
185 
186  // Wedge cells
187  case shards::Wedge<6>::key:
188  case shards::Wedge<15>::key:
189  case shards::Wedge<18>::key:
190  if(subcellDim == 2) {
191  if(!wedgeFacesSet){
192  setSubcellParametrization(wedgeFaces, subcellDim, parentCell);
193  wedgeFacesSet = 1;
194  }
195  return wedgeFaces;
196  }
197  else if(subcellDim == 1) {
198  if(!wedgeEdgesSet){
199  setSubcellParametrization(wedgeEdges, subcellDim, parentCell);
200  wedgeEdgesSet = 1;
201  }
202  return wedgeEdges;
203  }
204  else {
205  TEUCHOS_TEST_FOR_EXCEPTION( (subcellDim != 1 || subcellDim != 2), std::invalid_argument,
206  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): Wedge parametrization defined for 1 and 2-subcells only");
207  }
208  break;
209  //
210  // Standard 2D cells have only 1-subcells
211  //
212  case shards::Triangle<3>::key:
213  case shards::Triangle<4>::key:
214  case shards::Triangle<6>::key:
215  if(subcellDim == 1) {
216  if(!triEdgesSet){
217  setSubcellParametrization(triEdges, subcellDim, parentCell);
218  triEdgesSet = 1;
219  }
220  return triEdges;
221  }
222  else{
223  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
224  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): Triangle parametrizations defined for 1-subcells only");
225  }
226  break;
227 
228  case shards::Quadrilateral<4>::key:
229  case shards::Quadrilateral<8>::key:
230  case shards::Quadrilateral<9>::key:
231  if(subcellDim == 1) {
232  if(!quadEdgesSet){
233  setSubcellParametrization(quadEdges, subcellDim, parentCell);
234  quadEdgesSet = 1;
235  }
236  return quadEdges;
237  }
238  else{
239  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
240  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): Quad parametrizations defined for 1-subcells only");
241  }
242  break;
243  //
244  // Non-standard 3D Shell Tri and Quad cells have 1 and 2-subcells. Because they are 3D cells
245  // can't reuse edge parametrization arrays for 2D Triangle and Quadrilateral.
246  //
247  case shards::ShellTriangle<3>::key:
248  case shards::ShellTriangle<6>::key:
249  if(subcellDim == 2) {
250  if(!shellTriFacesSet){
251  setSubcellParametrization(shellTriFaces, subcellDim, parentCell);
252  shellTriFacesSet = 1;
253  }
254  return shellTriFaces;
255  }
256  else if(subcellDim == 1) {
257  if(!shellTriEdgesSet){
258  setSubcellParametrization(shellTriEdges, subcellDim, parentCell);
259  shellTriEdgesSet = 1;
260  }
261  return shellTriEdges;
262  }
263  else if( subcellDim != 1 || subcellDim != 2){
264  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
265  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): Shell Triangle parametrizations defined for 1 and 2-subcells only");
266  }
267  break;
268 
269  case shards::ShellQuadrilateral<4>::key:
270  case shards::ShellQuadrilateral<8>::key:
271  case shards::ShellQuadrilateral<9>::key:
272  if(subcellDim == 2) {
273  if(!shellQuadFacesSet){
274  setSubcellParametrization(shellQuadFaces, subcellDim, parentCell);
275  shellQuadFacesSet = 1;
276  }
277  return shellQuadFaces;
278  }
279  else if(subcellDim == 1) {
280  if(!shellQuadEdgesSet){
281  setSubcellParametrization(shellQuadEdges, subcellDim, parentCell);
282  shellQuadEdgesSet = 1;
283  }
284  return shellQuadEdges;
285  }
286  else if( subcellDim != 1 || subcellDim != 2){
287  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
288  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): Shell Quad parametrizations defined for 1 and 2-subcells only");
289  }
290  break;
291 
292  //
293  // Non-standard 2D cells: Shell Lines and Beams have 1-subcells
294  //
295  case shards::ShellLine<2>::key:
296  case shards::ShellLine<3>::key:
297  case shards::Beam<2>::key:
298  case shards::Beam<3>::key:
299  if(subcellDim == 1) {
300  if(!lineEdgesSet){
301  setSubcellParametrization(lineEdges, subcellDim, parentCell);
302  lineEdgesSet = 1;
303  }
304  return lineEdges;
305  }
306  else{
307  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
308  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): shell line/beam parametrizations defined for 1-subcells only");
309  }
310  break;
311 
312  default:
313  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
314  ">>> ERROR (Intrepid::CellTools::getSubcellParametrization): invalid cell topology.");
315  }//cell key
316  // To disable compiler warning, should never be reached
317  return lineEdges;
318  }
319 
320 
321 
322  template<class Scalar>
324  const int subcellDim,
325  const shards::CellTopology& parentCell)
326  {
327 #ifdef HAVE_INTREPID_DEBUG
328  TEUCHOS_TEST_FOR_EXCEPTION( !(hasReferenceCell(parentCell) ), std::invalid_argument,
329  ">>> ERROR (Intrepid::CellTools::setSubcellParametrization): the specified cell topology does not have a reference cell.");
330 
331  TEUCHOS_TEST_FOR_EXCEPTION( !( (1 <= subcellDim) && (subcellDim <= 2 ) ), std::invalid_argument,
332  ">>> ERROR (Intrepid::CellTools::setSubcellParametrization): parametrization defined only for 1 and 2-dimensional subcells.");
333 #endif
334  // subcellParametrization is rank-3 FieldContainer with dimensions (SC, PCD, COEF) where:
335  // - SC is the subcell count of subcells with the specified dimension in the parent cell
336  // - PCD is Parent Cell Dimension, which gives the number of coordinate functions in the map
337  // PCD = 2 for standard 2D cells and non-standard 2D cells: shell line and beam
338  // PCD = 3 for standard 3D cells and non-standard 3D cells: shell Tri and Quad
339  // - COEF is number of coefficients needed to specify a coordinate function:
340  // COEFF = 2 for edge parametrizations
341  // COEFF = 3 for both Quad and Tri face parametrizations. Because all Quad reference faces
342  // are affine, the coefficient of the bilinear term u*v is zero and is not stored, i.e.,
343  // 3 coefficients are sufficient to store Quad face parameterization maps.
344  //
345  // Edge parametrization maps [-1,1] to edge defined by (v0, v1)
346  // Face parametrization maps [-1,1]^2 to quadrilateral face (v0, v1, v2, v3), or
347  // standard 2-simplex {(0,0),(1,0),(0,1)} to traingle face (v0, v1, v2).
348  // This defines orientation-preserving parametrizations with respect to reference edge and
349  // face orientations induced by their vertex order.
350 
351  // get subcellParametrization dimensions: (sc, pcd, coeff)
352  unsigned sc = parentCell.getSubcellCount(subcellDim);
353  unsigned pcd = parentCell.getDimension();
354  unsigned coeff = (subcellDim == 1) ? 2 : 3;
355 
356 
357  // Resize container
358  subcellParametrization.resize(sc, pcd, coeff);
359 
360  // Edge parametrizations of 2D and 3D cells (shell lines and beams are 2D cells with edges)
361  if(subcellDim == 1){
362  for(unsigned subcellOrd = 0; subcellOrd < sc; subcellOrd++){
363 
364  int v0ord = parentCell.getNodeMap(subcellDim, subcellOrd, 0);
365  int v1ord = parentCell.getNodeMap(subcellDim, subcellOrd, 1);
366 
367  // vertexK[0] = x_k; vertexK[1] = y_k; vertexK[2] = z_k; z_k = 0 for 2D cells
368  // Note that ShellLine and Beam are 2D cells!
369  const double* v0 = getReferenceVertex(parentCell, v0ord);
370  const double* v1 = getReferenceVertex(parentCell, v1ord);
371 
372  // x(t) = (x0 + x1)/2 + t*(x1 - x0)/2
373  subcellParametrization(subcellOrd, 0, 0) = (v0[0] + v1[0])/2.0;
374  subcellParametrization(subcellOrd, 0, 1) = (v1[0] - v0[0])/2.0;
375 
376  // y(t) = (y0 + y1)/2 + t*(y1 - y0)/2
377  subcellParametrization(subcellOrd, 1, 0) = (v0[1] + v1[1])/2.0;
378  subcellParametrization(subcellOrd, 1, 1) = (v1[1] - v0[1])/2.0;
379 
380  if( pcd == 3 ) {
381  // z(t) = (z0 + z1)/2 + t*(z1 - z0)/2
382  subcellParametrization(subcellOrd, 2, 0) = (v0[2] + v1[2])/2.0;
383  subcellParametrization(subcellOrd, 2, 1) = (v1[2] - v0[2])/2.0;
384  }
385  }// for loop over 1-subcells
386  }
387 
388  // Face parametrizations of 3D cells: (shell Tri and Quad are 3D cells with faces)
389  // A 3D cell can have both Tri and Quad faces, but because they are affine images of the
390  // parametrization domain, 3 coefficients are enough to store them in both cases.
391  else if(subcellDim == 2) {
392  for(unsigned subcellOrd = 0; subcellOrd < sc; subcellOrd++){
393 
394  switch(parentCell.getKey(subcellDim,subcellOrd)){
395 
396  // Admissible triangular faces for 3D cells in Shards:
397  case shards::Triangle<3>::key:
398  case shards::Triangle<4>::key:
399  case shards::Triangle<6>::key:
400  {
401  int v0ord = parentCell.getNodeMap(subcellDim, subcellOrd, 0);
402  int v1ord = parentCell.getNodeMap(subcellDim, subcellOrd, 1);
403  int v2ord = parentCell.getNodeMap(subcellDim, subcellOrd, 2);
404  const double* v0 = getReferenceVertex(parentCell, v0ord);
405  const double* v1 = getReferenceVertex(parentCell, v1ord);
406  const double* v2 = getReferenceVertex(parentCell, v2ord);
407 
408  // x(u,v) = x0 + (x1 - x0)*u + (x2 - x0)*v
409  subcellParametrization(subcellOrd, 0, 0) = v0[0];
410  subcellParametrization(subcellOrd, 0, 1) = v1[0] - v0[0];
411  subcellParametrization(subcellOrd, 0, 2) = v2[0] - v0[0];
412 
413  // y(u,v) = y0 + (y1 - y0)*u + (y2 - y0)*v
414  subcellParametrization(subcellOrd, 1, 0) = v0[1];
415  subcellParametrization(subcellOrd, 1, 1) = v1[1] - v0[1];
416  subcellParametrization(subcellOrd, 1, 2) = v2[1] - v0[1];
417 
418  // z(u,v) = z0 + (z1 - z0)*u + (z2 - z0)*v
419  subcellParametrization(subcellOrd, 2, 0) = v0[2];
420  subcellParametrization(subcellOrd, 2, 1) = v1[2] - v0[2];
421  subcellParametrization(subcellOrd, 2, 2) = v2[2] - v0[2];
422  }
423  break;
424 
425  // Admissible quadrilateral faces for 3D cells in Shards:
426  case shards::Quadrilateral<4>::key:
427  case shards::Quadrilateral<8>::key:
428  case shards::Quadrilateral<9>::key:
429  {
430  int v0ord = parentCell.getNodeMap(subcellDim, subcellOrd, 0);
431  int v1ord = parentCell.getNodeMap(subcellDim, subcellOrd, 1);
432  int v2ord = parentCell.getNodeMap(subcellDim, subcellOrd, 2);
433  int v3ord = parentCell.getNodeMap(subcellDim, subcellOrd, 3);
434  const double* v0 = getReferenceVertex(parentCell, v0ord);
435  const double* v1 = getReferenceVertex(parentCell, v1ord);
436  const double* v2 = getReferenceVertex(parentCell, v2ord);
437  const double* v3 = getReferenceVertex(parentCell, v3ord);
438 
439  // x(u,v) = (x0+x1+x2+x3)/4+u*(-x0+x1+x2-x3)/4+v*(-x0-x1+x2+x3)/4+uv*(0=x0-x1+x2-x3)/4
440  subcellParametrization(subcellOrd, 0, 0) = ( v0[0] + v1[0] + v2[0] + v3[0])/4.0;
441  subcellParametrization(subcellOrd, 0, 1) = (-v0[0] + v1[0] + v2[0] - v3[0])/4.0;
442  subcellParametrization(subcellOrd, 0, 2) = (-v0[0] - v1[0] + v2[0] + v3[0])/4.0;
443 
444  // y(u,v) = (y0+y1+y2+y3)/4+u*(-y0+y1+y2-y3)/4+v*(-y0-y1+y2+y3)/4+uv*(0=y0-y1+y2-y3)/4
445  subcellParametrization(subcellOrd, 1, 0) = ( v0[1] + v1[1] + v2[1] + v3[1])/4.0;
446  subcellParametrization(subcellOrd, 1, 1) = (-v0[1] + v1[1] + v2[1] - v3[1])/4.0;
447  subcellParametrization(subcellOrd, 1, 2) = (-v0[1] - v1[1] + v2[1] + v3[1])/4.0;
448 
449  // z(u,v) = (z0+z1+z2+z3)/4+u*(-z0+z1+z2-z3)/4+v*(-z0-z1+z2+z3)/4+uv*(0=z0-z1+z2-z3)/4
450  subcellParametrization(subcellOrd, 2, 0) = ( v0[2] + v1[2] + v2[2] + v3[2])/4.0;
451  subcellParametrization(subcellOrd, 2, 1) = (-v0[2] + v1[2] + v2[2] - v3[2])/4.0;
452  subcellParametrization(subcellOrd, 2, 2) = (-v0[2] - v1[2] + v2[2] + v3[2])/4.0;
453  }
454  break;
455  default:
456  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
457  ">>> ERROR (Intrepid::CellTools::setSubcellParametrization): parametrization not defined for the specified face topology.");
458 
459  }// switch face topology key
460  }// for subcellOrd
461  }
462  }
463 
464 
465 
466  template<class Scalar>
467  const double* CellTools<Scalar>::getReferenceVertex(const shards::CellTopology& cell,
468  const int vertexOrd){
469 
470 #ifdef HAVE_INTREPID_DEBUG
471  TEUCHOS_TEST_FOR_EXCEPTION( !(hasReferenceCell(cell) ), std::invalid_argument,
472  ">>> ERROR (Intrepid::CellTools::getReferenceVertex): the specified cell topology does not have a reference cell.");
473 
474  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= vertexOrd) && (vertexOrd < (int)cell.getVertexCount() ) ), std::invalid_argument,
475  ">>> ERROR (Intrepid::CellTools::getReferenceVertex): invalid node ordinal for the specified cell topology. ");
476 #endif
477 
478  // Simply call getReferenceNode with the base topology of the cell
479  return getReferenceNode(cell.getBaseCellTopologyData(), vertexOrd);
480  }
481 
482 
483 
484  template<class Scalar>
485  template<class ArraySubcellVert>
486  void CellTools<Scalar>::getReferenceSubcellVertices(ArraySubcellVert & subcellVertices,
487  const int subcellDim,
488  const int subcellOrd,
489  const shards::CellTopology& parentCell){
490 #ifdef HAVE_INTREPID_DEBUG
491  TEUCHOS_TEST_FOR_EXCEPTION( !(hasReferenceCell(parentCell) ), std::invalid_argument,
492  ">>> ERROR (Intrepid::CellTools::getReferenceSubcellVertices): the specified cell topology does not have a reference cell.");
493 
494  // subcellDim can equal the cell dimension because the cell itself is a valid subcell! In this case
495  // the method will return all cell cellWorkset.
496  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= subcellDim) && (subcellDim <= (int)parentCell.getDimension()) ), std::invalid_argument,
497  ">>> ERROR (Intrepid::CellTools::getReferenceSubcellVertices): subcell dimension out of range.");
498 
499  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= subcellOrd) && (subcellOrd < (int)parentCell.getSubcellCount(subcellDim) ) ), std::invalid_argument,
500  ">>> ERROR (Intrepid::CellTools::getReferenceSubcellVertices): subcell ordinal out of range.");
501 
502  // Verify subcellVertices rank and dimensions
503  {
504  std::string errmsg = ">>> ERROR (Intrepid::CellTools::getReferenceSubcellVertices):";
505  TEUCHOS_TEST_FOR_EXCEPTION( !( requireRankRange(errmsg, subcellVertices, 2, 2) ), std::invalid_argument, errmsg);
506 
507  int subcVertexCount = parentCell.getVertexCount(subcellDim, subcellOrd);
508  int spaceDim = parentCell.getDimension();
509 
510  TEUCHOS_TEST_FOR_EXCEPTION( !( requireDimensionRange(errmsg, subcellVertices, 0, subcVertexCount, subcVertexCount) ),
511  std::invalid_argument, errmsg);
512 
513  TEUCHOS_TEST_FOR_EXCEPTION( !( requireDimensionRange(errmsg, subcellVertices, 1, spaceDim, spaceDim) ),
514  std::invalid_argument, errmsg);
515  }
516 #endif
517 
518  // Simply call getReferenceNodes with the base topology
519  getReferenceSubcellNodes(subcellVertices, subcellDim, subcellOrd, parentCell.getBaseCellTopologyData() );
520  }
521 
522 
523 
524  template<class Scalar>
525  const double* CellTools<Scalar>::getReferenceNode(const shards::CellTopology& cell,
526  const int nodeOrd){
527 
528 #ifdef HAVE_INTREPID_DEBUG
529  TEUCHOS_TEST_FOR_EXCEPTION( !(hasReferenceCell(cell) ), std::invalid_argument,
530  ">>> ERROR (Intrepid::CellTools::getReferenceNode): the specified cell topology does not have a reference cell.");
531 
532  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= nodeOrd) && (nodeOrd < (int)cell.getNodeCount() ) ), std::invalid_argument,
533  ">>> ERROR (Intrepid::CellTools::getReferenceNode): invalid node ordinal for the specified cell topology. ");
534 #endif
535 
536  // Cartesian coordinates of supported reference cell cellWorkset, padded to three-dimensions.
537  // Node order follows cell topology definition in Shards
538  static const double line[2][3] ={
539  {-1.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}
540  };
541  static const double line_3[3][3] = {
542  {-1.0, 0.0, 0.0}, { 1.0, 0.0, 0.0},
543  // Extension node: edge midpoint
544  { 0.0, 0.0, 0.0}
545  };
546 
547 
548  // Triangle topologies
549  static const double triangle[3][3] = {
550  { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}
551  };
552  static const double triangle_4[4][3] = {
553  { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0},
554  // Extension node: cell center
555  { 1/3, 1/3, 0.0}
556  };
557  static const double triangle_6[6][3] = {
558  { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0},
559  // Extension cellWorkset: 3 edge midpoints
560  { 0.5, 0.0, 0.0}, { 0.5, 0.5, 0.0}, { 0.0, 0.5, 0.0}
561  };
562 
563 
564  // Quadrilateral topologies
565  static const double quadrilateral[4][3] = {
566  {-1.0,-1.0, 0.0}, { 1.0,-1.0, 0.0}, { 1.0, 1.0, 0.0}, {-1.0, 1.0, 0.0}
567  };
568  static const double quadrilateral_8[8][3] = {
569  {-1.0,-1.0, 0.0}, { 1.0,-1.0, 0.0}, { 1.0, 1.0, 0.0}, {-1.0, 1.0, 0.0},
570  // Extension cellWorkset: 4 edge midpoints
571  { 0.0,-1.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}
572  };
573  static const double quadrilateral_9[9][3] = {
574  {-1.0,-1.0, 0.0}, { 1.0,-1.0, 0.0}, { 1.0, 1.0, 0.0}, {-1.0, 1.0, 0.0},
575  // Extension cellWorkset: 4 edge midpoints + 1 cell center
576  { 0.0,-1.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0}, { 0.0, 0.0, 0.0}
577  };
578 
579 
580  // Tetrahedron topologies
581  static const double tetrahedron[4][3] = {
582  { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}, { 0.0, 0.0, 1.0}
583  };
584  static const double tetrahedron_8[8][3] = {
585  { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}, { 0.0, 0.0, 1.0},
586  // Extension cellWorkset: 4 face centers (do not follow natural face order - see the cell topology!)
587  { 1/3, 0.0, 1/3}, { 1/3, 1/3, 1/3}, { 1/3, 1/3, 0.0}, { 0.0, 1/3, 1/3}
588  };
589  static const double tetrahedron_10[10][3] = {
590  { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}, { 0.0, 0.0, 1.0},
591  // Extension cellWorkset: 6 edge midpoints
592  { 0.5, 0.0, 0.0}, { 0.5, 0.5, 0.0}, { 0.0, 0.5, 0.0}, { 0.0, 0.0, 0.5}, { 0.5, 0.0, 0.5}, { 0.0, 0.5, 0.5}
593  };
594 
595  static const double tetrahedron_11[10][3] = {
596  { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}, { 0.0, 0.0, 1.0},
597  // Extension cellWorkset: 6 edge midpoints
598  { 0.5, 0.0, 0.0}, { 0.5, 0.5, 0.0}, { 0.0, 0.5, 0.0}, { 0.0, 0.0, 0.5}, { 0.5, 0.0, 0.5}, { 0.0, 0.5, 0.5}
599  };
600 
601 
602  // Hexahedron topologies
603  static const double hexahedron[8][3] = {
604  {-1.0,-1.0,-1.0}, { 1.0,-1.0,-1.0}, { 1.0, 1.0,-1.0}, {-1.0, 1.0,-1.0},
605  {-1.0,-1.0, 1.0}, { 1.0,-1.0, 1.0}, { 1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0}
606  };
607  static const double hexahedron_20[20][3] = {
608  {-1.0,-1.0,-1.0}, { 1.0,-1.0,-1.0}, { 1.0, 1.0,-1.0}, {-1.0, 1.0,-1.0},
609  {-1.0,-1.0, 1.0}, { 1.0,-1.0, 1.0}, { 1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0},
610  // Extension cellWorkset: 12 edge midpoints (do not follow natural edge order - see cell topology!)
611  { 0.0,-1.0,-1.0}, { 1.0, 0.0,-1.0}, { 0.0, 1.0,-1.0}, {-1.0, 0.0,-1.0},
612  {-1.0,-1.0, 0.0}, { 1.0,-1.0, 0.0}, { 1.0, 1.0, 0.0}, {-1.0, 1.0, 0.0},
613  { 0.0,-1.0, 1.0}, { 1.0, 0.0, 1.0}, { 0.0, 1.0, 1.0}, {-1.0, 0.0, 1.0}
614  };
615  static const double hexahedron_27[27][3] = {
616  {-1.0,-1.0,-1.0}, { 1.0,-1.0,-1.0}, { 1.0, 1.0,-1.0}, {-1.0, 1.0,-1.0},
617  {-1.0,-1.0, 1.0}, { 1.0,-1.0, 1.0}, { 1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0},
618  // Extension cellWorkset: 12 edge midpoints + 1 cell center + 6 face centers (do not follow natural subcell order!)
619  { 0.0,-1.0,-1.0}, { 1.0, 0.0,-1.0}, { 0.0, 1.0,-1.0}, {-1.0, 0.0,-1.0},
620  {-1.0,-1.0, 0.0}, { 1.0,-1.0, 0.0}, { 1.0, 1.0, 0.0}, {-1.0, 1.0, 0.0},
621  { 0.0,-1.0, 1.0}, { 1.0, 0.0, 1.0}, { 0.0, 1.0, 1.0}, {-1.0, 0.0, 1.0},
622  { 0.0, 0.0, 0.0},
623  { 0.0, 0.0,-1.0}, { 0.0, 0.0, 1.0}, {-1.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, {0.0,-1.0, 0.0}, {0.0, 1.0, 0.0}
624  };
625 
626 
627  // Pyramid topologies
628  static const double pyramid[5][3] = {
629  {-1.0,-1.0, 0.0}, { 1.0,-1.0, 0.0}, { 1.0, 1.0, 0.0}, {-1.0, 1.0, 0.0}, { 0.0, 0.0, 1.0}
630  };
631  static const double pyramid_13[13][3] = {
632  {-1.0,-1.0, 0.0}, { 1.0,-1.0, 0.0}, { 1.0, 1.0, 0.0}, {-1.0, 1.0, 0.0}, { 0.0, 0.0, 1.0},
633  // Extension cellWorkset: 8 edge midpoints
634  { 0.0,-1.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0},
635  {-0.5,-0.5, 0.5}, { 0.5,-0.5, 0.5}, { 0.5, 0.5, 0.5}, {-0.5, 0.5, 0.5}
636  };
637  static const double pyramid_14[14][3] = {
638  {-1.0,-1.0, 0.0}, { 1.0,-1.0, 0.0}, { 1.0, 1.0, 0.0}, {-1.0, 1.0, 0.0}, { 0.0, 0.0, 1.0},
639  // Extension cellWorkset: 8 edge midpoints + quadrilateral face midpoint
640  { 0.0,-1.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0}, {-1.0, 0.0, 0.0},
641  {-0.5,-0.5, 0.5}, { 0.5,-0.5, 0.5}, { 0.5, 0.5, 0.5}, {-0.5, 0.5, 0.5}, { 0.0, 0.0, 0.0}
642  };
643 
644 
645  // Wedge topologies
646  static const double wedge[6][3] = {
647  { 0.0, 0.0,-1.0}, { 1.0, 0.0,-1.0}, { 0.0, 1.0,-1.0}, { 0.0, 0.0, 1.0}, { 1.0, 0.0, 1.0}, { 0.0, 1.0, 1.0}
648  };
649  static const double wedge_15[15][3] = {
650  { 0.0, 0.0,-1.0}, { 1.0, 0.0,-1.0}, { 0.0, 1.0,-1.0}, { 0.0, 0.0, 1.0}, { 1.0, 0.0, 1.0}, { 0.0, 1.0, 1.0},
651  // Extension cellWorkset: 9 edge midpoints (do not follow natural edge order - see cell topology!)
652  { 0.5, 0.0,-1.0}, { 0.5, 0.5,-1.0}, { 0.0, 0.5,-1.0}, { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0},
653  { 0.5, 0.0, 1.0}, { 0.5, 0.5, 1.0}, { 0.0, 0.5, 1.0}
654  };
655  static const double wedge_18[18][3] = {
656  { 0.0, 0.0,-1.0}, { 1.0, 0.0,-1.0}, { 0.0, 1.0,-1.0}, { 0.0, 0.0, 1.0}, { 1.0, 0.0, 1.0}, { 0.0, 1.0, 1.0},
657  // Extension cellWorkset: 9 edge midpoints + 3 quad face centers (do not follow natural subcell order - see cell topology!)
658  { 0.5, 0.0,-1.0}, { 0.5, 0.5,-1.0}, { 0.0, 0.5,-1.0}, { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 0.0, 1.0, 0.0},
659  { 0.5, 0.0, 1.0}, { 0.5, 0.5, 1.0}, { 0.0, 0.5, 1.0},
660  { 0.5, 0.0, 0.0}, { 0.5, 0.5, 0.0}, { 0.0, 0.5, 0.0}
661  };
662 
663 
664  switch(cell.getKey() ) {
665 
666  // Base line topologies
667  case shards::Line<2>::key:
668  case shards::ShellLine<2>::key:
669  case shards::Beam<2>::key:
670  return line[nodeOrd];
671  break;
672 
673  // Extended line topologies
674  case shards::Line<3>::key:
675  case shards::ShellLine<3>::key:
676  case shards::Beam<3>::key:
677  return line_3[nodeOrd];
678  break;
679 
680 
681  // Base triangle topologies
682  case shards::Triangle<3>::key:
683  case shards::ShellTriangle<3>::key:
684  return triangle[nodeOrd];
685  break;
686 
687  // Extened Triangle topologies
688  case shards::Triangle<4>::key:
689  return triangle_4[nodeOrd];
690  break;
691  case shards::Triangle<6>::key:
692  case shards::ShellTriangle<6>::key:
693  return triangle_6[nodeOrd];
694  break;
695 
696 
697  // Base Quadrilateral topologies
698  case shards::Quadrilateral<4>::key:
699  case shards::ShellQuadrilateral<4>::key:
700  return quadrilateral[nodeOrd];
701  break;
702 
703  // Extended Quadrilateral topologies
704  case shards::Quadrilateral<8>::key:
705  case shards::ShellQuadrilateral<8>::key:
706  return quadrilateral_8[nodeOrd];
707  break;
708  case shards::Quadrilateral<9>::key:
709  case shards::ShellQuadrilateral<9>::key:
710  return quadrilateral_9[nodeOrd];
711  break;
712 
713 
714  // Base Tetrahedron topology
715  case shards::Tetrahedron<4>::key:
716  return tetrahedron[nodeOrd];
717  break;
718 
719  // Extended Tetrahedron topologies
720  case shards::Tetrahedron<8>::key:
721  return tetrahedron_8[nodeOrd];
722  break;
723  case shards::Tetrahedron<10>::key:
724  return tetrahedron_10[nodeOrd];
725  break;
726  case shards::Tetrahedron<11>::key:
727  return tetrahedron_11[nodeOrd];
728  break;
729 
730 
731  // Base Hexahedron topology
732  case shards::Hexahedron<8>::key:
733  return hexahedron[nodeOrd];
734  break;
735 
736  // Extended Hexahedron topologies
737  case shards::Hexahedron<20>::key:
738  return hexahedron_20[nodeOrd];
739  break;
740  case shards::Hexahedron<27>::key:
741  return hexahedron_27[nodeOrd];
742  break;
743 
744 
745  // Base Pyramid topology
746  case shards::Pyramid<5>::key:
747  return pyramid[nodeOrd];
748  break;
749 
750  // Extended pyramid topologies
751  case shards::Pyramid<13>::key:
752  return pyramid_13[nodeOrd];
753  break;
754  case shards::Pyramid<14>::key:
755  return pyramid_14[nodeOrd];
756  break;
757 
758 
759  // Base Wedge topology
760  case shards::Wedge<6>::key:
761  return wedge[nodeOrd];
762  break;
763 
764  // Extended Wedge topologies
765  case shards::Wedge<15>::key:
766  return wedge_15[nodeOrd];
767  break;
768  case shards::Wedge<18>::key:
769  return wedge_18[nodeOrd];
770  break;
771 
772  default:
773  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
774  ">>> ERROR (Intrepid::CellTools::getReferenceNode): invalid cell topology.");
775  }
776  // To disable compiler warning, should never be reached
777  return line[0];
778  }
779 
780 
781 
782  template<class Scalar>
783  template<class ArraySubcellNode>
784  void CellTools<Scalar>::getReferenceSubcellNodes(ArraySubcellNode & subcellNodes,
785  const int subcellDim,
786  const int subcellOrd,
787  const shards::CellTopology& parentCell){
788 #ifdef HAVE_INTREPID_DEBUG
789  TEUCHOS_TEST_FOR_EXCEPTION( !(hasReferenceCell(parentCell) ), std::invalid_argument,
790  ">>> ERROR (Intrepid::CellTools::getReferenceSubcellNodes): the specified cell topology does not have a reference cell.");
791 
792  // subcellDim can equal the cell dimension because the cell itself is a valid subcell! In this case
793  // the method will return all cell cellWorkset.
794  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= subcellDim) && (subcellDim <= (int)parentCell.getDimension()) ), std::invalid_argument,
795  ">>> ERROR (Intrepid::CellTools::getReferenceSubcellNodes): subcell dimension out of range.");
796 
797  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= subcellOrd) && (subcellOrd < (int)parentCell.getSubcellCount(subcellDim) ) ), std::invalid_argument,
798  ">>> ERROR (Intrepid::CellTools::getReferenceSubcellNodes): subcell ordinal out of range.");
799 
800  // Verify subcellNodes rank and dimensions
801  {
802  std::string errmsg = ">>> ERROR (Intrepid::CellTools::getReferenceSubcellNodes):";
803  TEUCHOS_TEST_FOR_EXCEPTION( !( requireRankRange(errmsg, subcellNodes, 2, 2) ), std::invalid_argument, errmsg);
804 
805  int subcNodeCount = parentCell.getNodeCount(subcellDim, subcellOrd);
806  int spaceDim = parentCell.getDimension();
807 
808  TEUCHOS_TEST_FOR_EXCEPTION( !( requireDimensionRange(errmsg, subcellNodes, 0, subcNodeCount, subcNodeCount) ),
809  std::invalid_argument, errmsg);
810 
811  TEUCHOS_TEST_FOR_EXCEPTION( !( requireDimensionRange(errmsg, subcellNodes, 1, spaceDim, spaceDim) ),
812  std::invalid_argument, errmsg);
813  }
814 #endif
815 
816  // Find how many cellWorkset does the specified subcell have.
817  int subcNodeCount = parentCell.getNodeCount(subcellDim, subcellOrd);
818 
819  // Loop over subcell cellWorkset
820  for(int subcNodeOrd = 0; subcNodeOrd < subcNodeCount; subcNodeOrd++){
821 
822  // Get the node number relative to the parent reference cell
823  int cellNodeOrd = parentCell.getNodeMap(subcellDim, subcellOrd, subcNodeOrd);
824 
825  // Loop over node's Cartesian coordinates
826  for(int dim = 0; dim < (int)parentCell.getDimension(); dim++){
827  subcellNodes(subcNodeOrd, dim) = CellTools::getReferenceNode(parentCell, cellNodeOrd)[dim];
828  }
829  }
830  }
831 
832 
833 
834  template<class Scalar>
835  int CellTools<Scalar>::hasReferenceCell(const shards::CellTopology& cell) {
836 
837  switch(cell.getKey() ) {
838  case shards::Line<2>::key:
839  case shards::Line<3>::key:
840  case shards::ShellLine<2>::key:
841  case shards::ShellLine<3>::key:
842  case shards::Beam<2>::key:
843  case shards::Beam<3>::key:
844 
845  case shards::Triangle<3>::key:
846  case shards::Triangle<4>::key:
847  case shards::Triangle<6>::key:
848  case shards::ShellTriangle<3>::key:
849  case shards::ShellTriangle<6>::key:
850 
851  case shards::Quadrilateral<4>::key:
852  case shards::Quadrilateral<8>::key:
853  case shards::Quadrilateral<9>::key:
854  case shards::ShellQuadrilateral<4>::key:
855  case shards::ShellQuadrilateral<8>::key:
856  case shards::ShellQuadrilateral<9>::key:
857 
858  case shards::Tetrahedron<4>::key:
859  case shards::Tetrahedron<8>::key:
860  case shards::Tetrahedron<10>::key:
861  case shards::Tetrahedron<11>::key:
862 
863  case shards::Hexahedron<8>::key:
864  case shards::Hexahedron<20>::key:
865  case shards::Hexahedron<27>::key:
866 
867  case shards::Pyramid<5>::key:
868  case shards::Pyramid<13>::key:
869  case shards::Pyramid<14>::key:
870 
871  case shards::Wedge<6>::key:
872  case shards::Wedge<15>::key:
873  case shards::Wedge<18>::key:
874  return 1;
875  break;
876 
877  default:
878  return 0;
879  }
880  return 0;
881  }
882 
883  //============================================================================================//
884  // //
885  // Jacobian, inverse Jacobian and Jacobian determinant //
886  // //
887  //============================================================================================//
888 
889  template<class Scalar>
890  template<class ArrayJac, class ArrayPoint, class ArrayCell>
891  void CellTools<Scalar>::setJacobian(ArrayJac & jacobian,
892  const ArrayPoint & points,
893  const ArrayCell & cellWorkset,
894  const shards::CellTopology & cellTopo,
895  const int & whichCell)
896  {
897  INTREPID_VALIDATE( validateArguments_setJacobian(jacobian, points, cellWorkset, whichCell, cellTopo) );
898 
899  int spaceDim = (int)cellTopo.getDimension();
900  int numCells = cellWorkset.dimension(0);
901  //points can be rank-2 (P,D), or rank-3 (C,P,D)
902  int numPoints = (points.rank() == 2) ? points.dimension(0) : points.dimension(1);
903 
904  // Jacobian is computed using gradients of an appropriate H(grad) basis function: define RCP to the base class
905  Teuchos::RCP< Basis< Scalar, FieldContainer<Scalar> > > HGRAD_Basis;
906 
907  // Choose the H(grad) basis depending on the cell topology. \todo define maps for shells and beams
908  switch( cellTopo.getKey() ){
909 
910  // Standard Base topologies (number of cellWorkset = number of vertices)
911  case shards::Line<2>::key:
912  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_LINE_C1_FEM<Scalar, FieldContainer<Scalar> >() );
913  break;
914 
915  case shards::Triangle<3>::key:
916  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_TRI_C1_FEM<Scalar, FieldContainer<Scalar> >() );
917  break;
918 
919  case shards::Quadrilateral<4>::key:
920  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_QUAD_C1_FEM<Scalar, FieldContainer<Scalar> >() );
921  break;
922 
923  case shards::Tetrahedron<4>::key:
924  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_TET_C1_FEM<Scalar, FieldContainer<Scalar> >() );
925  break;
926 
927  case shards::Hexahedron<8>::key:
928  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_HEX_C1_FEM<Scalar, FieldContainer<Scalar> >() );
929  break;
930 
931  case shards::Wedge<6>::key:
932  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_WEDGE_C1_FEM<Scalar, FieldContainer<Scalar> >() );
933  break;
934 
935  // Standard Extended topologies
936  case shards::Triangle<6>::key:
937  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_TRI_C2_FEM<Scalar, FieldContainer<Scalar> >() );
938  break;
939  case shards::Quadrilateral<9>::key:
940  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_QUAD_C2_FEM<Scalar, FieldContainer<Scalar> >() );
941  break;
942 
943  case shards::Tetrahedron<10>::key:
944  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_TET_C2_FEM<Scalar, FieldContainer<Scalar> >() );
945  break;
946 
947  case shards::Tetrahedron<11>::key:
948  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_TET_COMP12_FEM<Scalar, FieldContainer<Scalar> >() );
949  break;
950 
951  case shards::Hexahedron<27>::key:
952  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_HEX_C2_FEM<Scalar, FieldContainer<Scalar> >() );
953  break;
954 
955  case shards::Wedge<18>::key:
956  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_WEDGE_C2_FEM<Scalar, FieldContainer<Scalar> >() );
957  break;
958 
959  // These extended topologies are not used for mapping purposes
960  case shards::Quadrilateral<8>::key:
961  case shards::Hexahedron<20>::key:
962  case shards::Wedge<15>::key:
963  TEUCHOS_TEST_FOR_EXCEPTION( (true), std::invalid_argument,
964  ">>> ERROR (Intrepid::CellTools::setJacobian): Cell topology not supported. ");
965  break;
966 
967  // Base and Extended Line, Beam and Shell topologies
968  case shards::Line<3>::key:
969  case shards::Beam<2>::key:
970  case shards::Beam<3>::key:
971  case shards::ShellLine<2>::key:
972  case shards::ShellLine<3>::key:
973  case shards::ShellTriangle<3>::key:
974  case shards::ShellTriangle<6>::key:
975  case shards::ShellQuadrilateral<4>::key:
976  case shards::ShellQuadrilateral<8>::key:
977  case shards::ShellQuadrilateral<9>::key:
978  TEUCHOS_TEST_FOR_EXCEPTION( (true), std::invalid_argument,
979  ">>> ERROR (Intrepid::CellTools::setJacobian): Cell topology not supported. ");
980  break;
981  default:
982  TEUCHOS_TEST_FOR_EXCEPTION( (true), std::invalid_argument,
983  ">>> ERROR (Intrepid::CellTools::setJacobian): Cell topology not supported.");
984  }// switch
985 
986  // Temp (F,P,D) array for the values of basis functions gradients at the reference points
987  int basisCardinality = HGRAD_Basis -> getCardinality();
988  FieldContainer<Scalar> basisGrads(basisCardinality, numPoints, spaceDim);
989 
990  // Initialize jacobian
991  for(int i = 0; i < jacobian.size(); i++){
992  jacobian[i] = 0.0;
993  }
994 
995  // Handle separately rank-2 (P,D) and rank-3 (C,P,D) cases of points arrays.
996  switch(points.rank()) {
997 
998  // refPoints is (P,D): a single or multiple cell jacobians computed for a single set of ref. points
999  case 2:
1000  {
1001  // getValues requires rank-2 (P,D) input array, but points cannot be passed directly as argument because they are a user type
1002  FieldContainer<Scalar> tempPoints( points.dimension(0), points.dimension(1) );
1003  // Copy point set corresponding to this cell oridinal to the temp (P,D) array
1004  for(int pt = 0; pt < points.dimension(0); pt++){
1005  for(int dm = 0; dm < points.dimension(1) ; dm++){
1006  tempPoints(pt, dm) = points(pt, dm);
1007  }//dm
1008  }//pt
1009  HGRAD_Basis -> getValues(basisGrads, tempPoints, OPERATOR_GRAD);
1010 
1011  // The outer loops select the multi-index of the Jacobian entry: cell, point, row, col
1012  // If whichCell = -1, all jacobians are computed, otherwise a single cell jacobian is computed
1013  int cellLoop = (whichCell == -1) ? numCells : 1 ;
1014 
1015  if(whichCell == -1) {
1016  for(int cellOrd = 0; cellOrd < cellLoop; cellOrd++) {
1017  for(int pointOrd = 0; pointOrd < numPoints; pointOrd++) {
1018  for(int row = 0; row < spaceDim; row++){
1019  for(int col = 0; col < spaceDim; col++){
1020 
1021  // The entry is computed by contracting the basis index. Number of basis functions and vertices must be the same.
1022  for(int bfOrd = 0; bfOrd < basisCardinality; bfOrd++){
1023  jacobian(cellOrd, pointOrd, row, col) += cellWorkset(cellOrd, bfOrd, row)*basisGrads(bfOrd, pointOrd, col);
1024  } // bfOrd
1025  } // col
1026  } // row
1027  } // pointOrd
1028  } // cellOrd
1029  }
1030  else {
1031  for(int cellOrd = 0; cellOrd < cellLoop; cellOrd++) {
1032  for(int pointOrd = 0; pointOrd < numPoints; pointOrd++) {
1033  for(int row = 0; row < spaceDim; row++){
1034  for(int col = 0; col < spaceDim; col++){
1035 
1036  // The entry is computed by contracting the basis index. Number of basis functions and vertices must be the same.
1037  for(int bfOrd = 0; bfOrd < basisCardinality; bfOrd++){
1038  jacobian(pointOrd, row, col) += cellWorkset(whichCell, bfOrd, row)*basisGrads(bfOrd, pointOrd, col);
1039  } // bfOrd
1040  } // col
1041  } // row
1042  } // pointOrd
1043  } // cellOrd
1044  } // if whichcell
1045  }// case 2
1046  break;
1047 
1048  // points is (C,P,D): multiple jacobians computed at multiple point sets, one jacobian per cell
1049  case 3:
1050  {
1051  // getValues requires rank-2 (P,D) input array, refPoints cannot be used as argument: need temp (P,D) array
1052  FieldContainer<Scalar> tempPoints( points.dimension(1), points.dimension(2) );
1053 
1054  for(int cellOrd = 0; cellOrd < numCells; cellOrd++) {
1055 
1056  // Copy point set corresponding to this cell oridinal to the temp (P,D) array
1057  for(int pt = 0; pt < points.dimension(1); pt++){
1058  for(int dm = 0; dm < points.dimension(2) ; dm++){
1059  tempPoints(pt, dm) = points(cellOrd, pt, dm);
1060  }//dm
1061  }//pt
1062 
1063  // Compute gradients of basis functions at this set of ref. points
1064  HGRAD_Basis -> getValues(basisGrads, tempPoints, OPERATOR_GRAD);
1065 
1066  // Compute jacobians for the point set corresponding to the current cellordinal
1067  for(int pointOrd = 0; pointOrd < numPoints; pointOrd++) {
1068  for(int row = 0; row < spaceDim; row++){
1069  for(int col = 0; col < spaceDim; col++){
1070 
1071  // The entry is computed by contracting the basis index. Number of basis functions and vertices must be the same
1072  for(int bfOrd = 0; bfOrd < basisCardinality; bfOrd++){
1073  jacobian(cellOrd, pointOrd, row, col) += cellWorkset(cellOrd, bfOrd, row)*basisGrads(bfOrd, pointOrd, col);
1074  } // bfOrd
1075  } // col
1076  } // row
1077  } // pointOrd
1078  }//cellOrd
1079  }// case 3
1080 
1081  break;
1082 
1083  default:
1084  TEUCHOS_TEST_FOR_EXCEPTION( !( (points.rank() == 2) && (points.rank() == 3) ), std::invalid_argument,
1085  ">>> ERROR (Intrepid::CellTools::setJacobian): rank 2 or 3 required for points array. ");
1086  }//switch
1087  }
1088 
1089 
1090 
1091 template<class Scalar>
1092 template<class ArrayJacInv, class ArrayJac>
1093 void CellTools<Scalar>::setJacobianInv(ArrayJacInv & jacobianInv,
1094  const ArrayJac & jacobian)
1095 {
1096  INTREPID_VALIDATE( validateArguments_setJacobianInv(jacobianInv, jacobian) );
1097 
1098  RealSpaceTools<Scalar>::inverse(jacobianInv, jacobian);
1099 }
1100 
1101 
1102 
1103 template<class Scalar>
1104 template<class ArrayJacDet, class ArrayJac>
1105 void CellTools<Scalar>::setJacobianDet(ArrayJacDet & jacobianDet,
1106  const ArrayJac & jacobian)
1107 {
1108  INTREPID_VALIDATE( validateArguments_setJacobianDetArgs(jacobianDet, jacobian) );
1109 
1110  RealSpaceTools<Scalar>::det(jacobianDet, jacobian);
1111 }
1112 
1113 //============================================================================================//
1114 // //
1115 // Reference-to-physical frame mapping and its inverse //
1116 // //
1117 //============================================================================================//
1118 
1119 template<class Scalar>
1120 template<class ArrayPhysPoint, class ArrayRefPoint, class ArrayCell>
1121 void CellTools<Scalar>::mapToPhysicalFrame(ArrayPhysPoint & physPoints,
1122  const ArrayRefPoint & refPoints,
1123  const ArrayCell & cellWorkset,
1124  const shards::CellTopology & cellTopo,
1125  const int & whichCell)
1126 {
1127  INTREPID_VALIDATE(validateArguments_mapToPhysicalFrame( physPoints, refPoints, cellWorkset, cellTopo, whichCell) );
1128 
1129  int spaceDim = (int)cellTopo.getDimension();
1130  int numCells = cellWorkset.dimension(0);
1131  //points can be rank-2 (P,D), or rank-3 (C,P,D)
1132  int numPoints = (refPoints.rank() == 2) ? refPoints.dimension(0) : refPoints.dimension(1);
1133 
1134  // Mapping is computed using an appropriate H(grad) basis function: define RCP to the base class
1135  Teuchos::RCP<Basis<Scalar, FieldContainer<Scalar> > > HGRAD_Basis;
1136 
1137  // Choose the H(grad) basis depending on the cell topology. \todo define maps for shells and beams
1138  switch( cellTopo.getKey() ){
1139 
1140  // Standard Base topologies (number of cellWorkset = number of vertices)
1141  case shards::Line<2>::key:
1142  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_LINE_C1_FEM<Scalar, FieldContainer<Scalar> >() );
1143  break;
1144 
1145  case shards::Triangle<3>::key:
1146  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_TRI_C1_FEM<Scalar, FieldContainer<Scalar> >() );
1147  break;
1148 
1149  case shards::Quadrilateral<4>::key:
1150  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_QUAD_C1_FEM<Scalar, FieldContainer<Scalar> >() );
1151  break;
1152 
1153  case shards::Tetrahedron<4>::key:
1154  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_TET_C1_FEM<Scalar, FieldContainer<Scalar> >() );
1155  break;
1156 
1157  case shards::Hexahedron<8>::key:
1158  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_HEX_C1_FEM<Scalar, FieldContainer<Scalar> >() );
1159  break;
1160 
1161  case shards::Wedge<6>::key:
1162  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_WEDGE_C1_FEM<Scalar, FieldContainer<Scalar> >() );
1163  break;
1164 
1165  // Standard Extended topologies
1166  case shards::Triangle<6>::key:
1167  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_TRI_C2_FEM<Scalar, FieldContainer<Scalar> >() );
1168  break;
1169 
1170  case shards::Quadrilateral<9>::key:
1171  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_QUAD_C2_FEM<Scalar, FieldContainer<Scalar> >() );
1172  break;
1173 
1174  case shards::Tetrahedron<10>::key:
1175  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_TET_C2_FEM<Scalar, FieldContainer<Scalar> >() );
1176  break;
1177 
1178  case shards::Tetrahedron<11>::key:
1179  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_TET_COMP12_FEM<Scalar, FieldContainer<Scalar> >() );
1180  break;
1181 
1182  case shards::Hexahedron<27>::key:
1183  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_HEX_C2_FEM<Scalar, FieldContainer<Scalar> >() );
1184  break;
1185 
1186  case shards::Wedge<18>::key:
1187  HGRAD_Basis = Teuchos::rcp( new Basis_HGRAD_WEDGE_C2_FEM<Scalar, FieldContainer<Scalar> >() );
1188  break;
1189 
1190  // These extended topologies are not used for mapping purposes
1191  case shards::Quadrilateral<8>::key:
1192  case shards::Hexahedron<20>::key:
1193  case shards::Wedge<15>::key:
1194  TEUCHOS_TEST_FOR_EXCEPTION( (true), std::invalid_argument,
1195  ">>> ERROR (Intrepid::CellTools::mapToPhysicalFrame): Cell topology not supported. ");
1196  break;
1197 
1198  // Base and Extended Line, Beam and Shell topologies
1199  case shards::Line<3>::key:
1200  case shards::Beam<2>::key:
1201  case shards::Beam<3>::key:
1202  case shards::ShellLine<2>::key:
1203  case shards::ShellLine<3>::key:
1204  case shards::ShellTriangle<3>::key:
1205  case shards::ShellTriangle<6>::key:
1206  case shards::ShellQuadrilateral<4>::key:
1207  case shards::ShellQuadrilateral<8>::key:
1208  case shards::ShellQuadrilateral<9>::key:
1209  TEUCHOS_TEST_FOR_EXCEPTION( (true), std::invalid_argument,
1210  ">>> ERROR (Intrepid::CellTools::mapToPhysicalFrame): Cell topology not supported. ");
1211  break;
1212  default:
1213  TEUCHOS_TEST_FOR_EXCEPTION( (true), std::invalid_argument,
1214  ">>> ERROR (Intrepid::CellTools::mapToPhysicalFrame): Cell topology not supported.");
1215  }// switch
1216 
1217  // Temp (F,P) array for the values of nodal basis functions at the reference points
1218  int basisCardinality = HGRAD_Basis -> getCardinality();
1219  FieldContainer<Scalar> basisVals(basisCardinality, numPoints);
1220 
1221  // Initialize physPoints
1222  for(int i = 0; i < physPoints.size(); i++){
1223  physPoints[i] = 0.0;
1224  }
1225 
1226  // handle separately rank-2 (P,D) and rank-3 (C,P,D) cases of refPoints
1227  switch(refPoints.rank()) {
1228 
1229  // refPoints is (P,D): single set of ref. points is mapped to one or multiple physical cells
1230  case 2:
1231  {
1232  // getValues requires rank-2 (P,D) input array, but refPoints cannot be passed directly as argument because they are a user type
1233  FieldContainer<Scalar> tempPoints( refPoints.dimension(0), refPoints.dimension(1) );
1234  // Copy point set corresponding to this cell oridinal to the temp (P,D) array
1235  for(int pt = 0; pt < refPoints.dimension(0); pt++){
1236  for(int dm = 0; dm < refPoints.dimension(1) ; dm++){
1237  tempPoints(pt, dm) = refPoints(pt, dm);
1238  }//dm
1239  }//pt
1240  HGRAD_Basis -> getValues(basisVals, tempPoints, OPERATOR_VALUE);
1241 
1242  // If whichCell = -1, ref pt. set is mapped to all cells, otherwise, the set is mapped to one cell only
1243  int cellLoop = (whichCell == -1) ? numCells : 1 ;
1244 
1245  // Compute the map F(refPoints) = sum node_coordinate*basis(refPoints)
1246  for(int cellOrd = 0; cellOrd < cellLoop; cellOrd++) {
1247  for(int pointOrd = 0; pointOrd < numPoints; pointOrd++) {
1248  for(int dim = 0; dim < spaceDim; dim++){
1249  for(int bfOrd = 0; bfOrd < basisCardinality; bfOrd++){
1250 
1251  if(whichCell == -1){
1252  physPoints(cellOrd, pointOrd, dim) += cellWorkset(cellOrd, bfOrd, dim)*basisVals(bfOrd, pointOrd);
1253  }
1254  else{
1255  physPoints(pointOrd, dim) += cellWorkset(whichCell, bfOrd, dim)*basisVals(bfOrd, pointOrd);
1256  }
1257  } // bfOrd
1258  }// dim
1259  }// pointOrd
1260  }//cellOrd
1261  }// case 2
1262  break;
1263 
1264  // refPoints is (C,P,D): multiple sets of ref. points are mapped to matching number of physical cells.
1265  case 3:
1266  {
1267  // getValues requires rank-2 (P,D) input array, refPoints cannot be used as argument: need temp (P,D) array
1268  FieldContainer<Scalar> tempPoints( refPoints.dimension(1), refPoints.dimension(2) );
1269 
1270  // Compute the map F(refPoints) = sum node_coordinate*basis(refPoints)
1271  for(int cellOrd = 0; cellOrd < numCells; cellOrd++) {
1272 
1273  // Copy point set corresponding to this cell oridinal to the temp (P,D) array
1274  for(int pt = 0; pt < refPoints.dimension(1); pt++){
1275  for(int dm = 0; dm < refPoints.dimension(2) ; dm++){
1276  tempPoints(pt, dm) = refPoints(cellOrd, pt, dm);
1277  }//dm
1278  }//pt
1279 
1280  // Compute basis values for this set of ref. points
1281  HGRAD_Basis -> getValues(basisVals, tempPoints, OPERATOR_VALUE);
1282 
1283  for(int pointOrd = 0; pointOrd < numPoints; pointOrd++) {
1284  for(int dim = 0; dim < spaceDim; dim++){
1285  for(int bfOrd = 0; bfOrd < basisCardinality; bfOrd++){
1286 
1287  physPoints(cellOrd, pointOrd, dim) += cellWorkset(cellOrd, bfOrd, dim)*basisVals(bfOrd, pointOrd);
1288 
1289  } // bfOrd
1290  }// dim
1291  }// pointOrd
1292  }//cellOrd
1293  }// case 3
1294  break;
1295 
1296  default:
1297  TEUCHOS_TEST_FOR_EXCEPTION( !( (refPoints.rank() == 2) && (refPoints.rank() == 3) ), std::invalid_argument,
1298  ">>> ERROR (Intrepid::CellTools::mapToPhysicalFrame): rank 2 or 3 required for refPoints array. ");
1299  }
1300 }
1301 
1302 
1303 
1304 template<class Scalar>
1305 template<class ArrayRefPoint, class ArrayPhysPoint, class ArrayCell>
1306 void CellTools<Scalar>::mapToReferenceFrame(ArrayRefPoint & refPoints,
1307  const ArrayPhysPoint & physPoints,
1308  const ArrayCell & cellWorkset,
1309  const shards::CellTopology & cellTopo,
1310  const int & whichCell)
1311 {
1312  INTREPID_VALIDATE( validateArguments_mapToReferenceFrame(refPoints, physPoints, cellWorkset, cellTopo, whichCell) );
1313 
1314  int spaceDim = (int)cellTopo.getDimension();
1315  int numPoints;
1316  int numCells;
1317 
1318  // Define initial guesses to be the Cell centers of the reference cell topology
1319  FieldContainer<Scalar> cellCenter(spaceDim);
1320  switch( cellTopo.getKey() ){
1321  // Standard Base topologies (number of cellWorkset = number of vertices)
1322  case shards::Line<2>::key:
1323  cellCenter(0) = 0.0; break;
1324 
1325  case shards::Triangle<3>::key:
1326  case shards::Triangle<6>::key:
1327  cellCenter(0) = 1./3.; cellCenter(1) = 1./3.; break;
1328 
1329  case shards::Quadrilateral<4>::key:
1330  case shards::Quadrilateral<9>::key:
1331  cellCenter(0) = 0.0; cellCenter(1) = 0.0; break;
1332 
1333  case shards::Tetrahedron<4>::key:
1334  case shards::Tetrahedron<10>::key:
1335  case shards::Tetrahedron<11>::key:
1336  cellCenter(0) = 1./6.; cellCenter(1) = 1./6.; cellCenter(2) = 1./6.; break;
1337 
1338  case shards::Hexahedron<8>::key:
1339  case shards::Hexahedron<27>::key:
1340  cellCenter(0) = 0.0; cellCenter(1) = 0.0; cellCenter(2) = 0.0; break;
1341 
1342  case shards::Wedge<6>::key:
1343  case shards::Wedge<18>::key:
1344  cellCenter(0) = 1./3.; cellCenter(1) = 1./3.; cellCenter(2) = 0.0; break;
1345 
1346  // These extended topologies are not used for mapping purposes
1347  case shards::Quadrilateral<8>::key:
1348  case shards::Hexahedron<20>::key:
1349  case shards::Wedge<15>::key:
1350  TEUCHOS_TEST_FOR_EXCEPTION( (true), std::invalid_argument,
1351  ">>> ERROR (Intrepid::CellTools::mapToReferenceFrame): Cell topology not supported. ");
1352  break;
1353 
1354  // Base and Extended Line, Beam and Shell topologies
1355  case shards::Line<3>::key:
1356  case shards::Beam<2>::key:
1357  case shards::Beam<3>::key:
1358  case shards::ShellLine<2>::key:
1359  case shards::ShellLine<3>::key:
1360  case shards::ShellTriangle<3>::key:
1361  case shards::ShellTriangle<6>::key:
1362  case shards::ShellQuadrilateral<4>::key:
1363  case shards::ShellQuadrilateral<8>::key:
1364  case shards::ShellQuadrilateral<9>::key:
1365  TEUCHOS_TEST_FOR_EXCEPTION( (true), std::invalid_argument,
1366  ">>> ERROR (Intrepid::CellTools::mapToReferenceFrame): Cell topology not supported. ");
1367  break;
1368  default:
1369  TEUCHOS_TEST_FOR_EXCEPTION( (true), std::invalid_argument,
1370  ">>> ERROR (Intrepid::CellTools::mapToReferenceFrame): Cell topology not supported.");
1371  }// switch key
1372 
1373  // Resize initial guess depending on the rank of the physical points array
1374  FieldContainer<Scalar> initGuess;
1375 
1376  // Default: map (C,P,D) array of physical pt. sets to (C,P,D) array. Requires (C,P,D) initial guess.
1377  if(whichCell == -1){
1378  numPoints = physPoints.dimension(1);
1379  numCells = cellWorkset.dimension(0);
1380  initGuess.resize(numCells, numPoints, spaceDim);
1381  // Set initial guess:
1382  for(int c = 0; c < numCells; c++){
1383  for(int p = 0; p < numPoints; p++){
1384  for(int d = 0; d < spaceDim; d++){
1385  initGuess(c, p, d) = cellCenter(d);
1386  }// d
1387  }// p
1388  }// c
1389  }
1390  // Custom: map (P,D) array of physical pts. to (P,D) array. Requires (P,D) initial guess.
1391  else {
1392  numPoints = physPoints.dimension(0);
1393  initGuess.resize(numPoints, spaceDim);
1394  // Set initial guess:
1395  for(int p = 0; p < numPoints; p++){
1396  for(int d = 0; d < spaceDim; d++){
1397  initGuess(p, d) = cellCenter(d);
1398  }// d
1399  }// p
1400  }
1401 
1402  // Call method with initial guess
1403  mapToReferenceFrameInitGuess(refPoints, initGuess, physPoints, cellWorkset, cellTopo, whichCell);
1404 }
1405 
1406 
1407 
1408 template<class Scalar>
1409 template<class ArrayRefPoint, class ArrayInitGuess, class ArrayPhysPoint, class ArrayCell>
1411  const ArrayInitGuess & initGuess,
1412  const ArrayPhysPoint & physPoints,
1413  const ArrayCell & cellWorkset,
1414  const shards::CellTopology & cellTopo,
1415  const int & whichCell)
1416 {
1417  INTREPID_VALIDATE( validateArguments_mapToReferenceFrame(refPoints, initGuess, physPoints, cellWorkset, cellTopo, whichCell) );
1418 
1419  int spaceDim = (int)cellTopo.getDimension();
1420  int numPoints;
1421  int numCells=0;
1422 
1423  // Temp arrays for Newton iterates and Jacobians. Resize according to rank of ref. point array
1425  FieldContainer<Scalar> xTem;
1426  FieldContainer<Scalar> jacobian;
1427  FieldContainer<Scalar> jacobInv;
1428  FieldContainer<Scalar> error;
1429  FieldContainer<Scalar> cellCenter(spaceDim);
1430 
1431  // Default: map (C,P,D) array of physical pt. sets to (C,P,D) array. Requires (C,P,D) temp arrays and (C,P,D,D) Jacobians.
1432  if(whichCell == -1){
1433  numPoints = physPoints.dimension(1);
1434  numCells = cellWorkset.dimension(0);
1435  xOld.resize(numCells, numPoints, spaceDim);
1436  xTem.resize(numCells, numPoints, spaceDim);
1437  jacobian.resize(numCells,numPoints, spaceDim, spaceDim);
1438  jacobInv.resize(numCells,numPoints, spaceDim, spaceDim);
1439  error.resize(numCells,numPoints);
1440  // Set initial guess to xOld
1441  for(int c = 0; c < numCells; c++){
1442  for(int p = 0; p < numPoints; p++){
1443  for(int d = 0; d < spaceDim; d++){
1444  xOld(c, p, d) = initGuess(c, p, d);
1445  }// d
1446  }// p
1447  }// c
1448  }
1449  // Custom: map (P,D) array of physical pts. to (P,D) array. Requires (P,D) temp arrays and (P,D,D) Jacobians.
1450  else {
1451  numPoints = physPoints.dimension(0);
1452  xOld.resize(numPoints, spaceDim);
1453  xTem.resize(numPoints, spaceDim);
1454  jacobian.resize(numPoints, spaceDim, spaceDim);
1455  jacobInv.resize(numPoints, spaceDim, spaceDim);
1456  error.resize(numPoints);
1457  // Set initial guess to xOld
1458  for(int p = 0; p < numPoints; p++){
1459  for(int d = 0; d < spaceDim; d++){
1460  xOld(p, d) = initGuess(p, d);
1461  }// d
1462  }// p
1463  }
1464 
1465 
1466  // Newton method to solve the equation F(refPoints) - physPoints = 0:
1467  // refPoints = xOld - DF^{-1}(xOld)*(F(xOld) - physPoints) = xOld + DF^{-1}(xOld)*(physPoints - F(xOld))
1468  for(int iter = 0; iter < INTREPID_MAX_NEWTON; ++iter) {
1469 
1470  // Jacobians at the old iterates and their inverses.
1471  setJacobian(jacobian, xOld, cellWorkset, cellTopo, whichCell);
1472  setJacobianInv(jacobInv, jacobian);
1473 
1474  // The Newton step.
1475  mapToPhysicalFrame( xTem, xOld, cellWorkset, cellTopo, whichCell ); // xTem <- F(xOld)
1476  RealSpaceTools<Scalar>::subtract( xTem, physPoints, xTem ); // xTem <- physPoints - F(xOld)
1477  RealSpaceTools<Scalar>::matvec( refPoints, jacobInv, xTem); // refPoints <- DF^{-1}( physPoints - F(xOld) )
1478  RealSpaceTools<Scalar>::add( refPoints, xOld ); // refPoints <- DF^{-1}( physPoints - F(xOld) ) + xOld
1479 
1480  // l2 error (Euclidean distance) between old and new iterates: |xOld - xNew|
1481  RealSpaceTools<Scalar>::subtract( xTem, xOld, refPoints );
1482  RealSpaceTools<Scalar>::vectorNorm( error, xTem, NORM_TWO );
1483 
1484  // Average L2 error for a multiple sets of physical points: error is rank-2 (C,P) array
1485  double totalError;
1486  if(whichCell == -1) {
1487  FieldContainer<Scalar> cellWiseError(numCells);
1488  // error(C,P) -> cellWiseError(P)
1489  RealSpaceTools<Scalar>::vectorNorm( cellWiseError, error, NORM_ONE );
1490  totalError = RealSpaceTools<Scalar>::vectorNorm( cellWiseError, NORM_ONE );
1491  }
1492  //Average L2 error for a single set of physical points: error is rank-1 (P) array
1493  else{
1494  totalError = RealSpaceTools<Scalar>::vectorNorm( error, NORM_ONE );
1495  totalError = totalError;
1496  }
1497 
1498  // Stopping criterion:
1499  if (totalError < INTREPID_TOL) {
1500  break;
1501  }
1502  else if ( iter > INTREPID_MAX_NEWTON) {
1503  INTREPID_VALIDATE(std::cout << " Intrepid::CellTools::mapToReferenceFrameInitGuess failed to converge to desired tolerance within "
1504  << INTREPID_MAX_NEWTON << " iterations\n" );
1505  break;
1506  }
1507 
1508  // initialize next Newton step
1509  xOld = refPoints;
1510  } // for(iter)
1511 }
1512 
1513 
1514 
1515 template<class Scalar>
1516 template<class ArraySubcellPoint, class ArrayParamPoint>
1517 void CellTools<Scalar>::mapToReferenceSubcell(ArraySubcellPoint & refSubcellPoints,
1518  const ArrayParamPoint & paramPoints,
1519  const int subcellDim,
1520  const int subcellOrd,
1521  const shards::CellTopology & parentCell){
1522 
1523  int cellDim = parentCell.getDimension();
1524  int numPts = paramPoints.dimension(0);
1525 
1526 #ifdef HAVE_INTREPID_DEBUG
1527  TEUCHOS_TEST_FOR_EXCEPTION( !(hasReferenceCell(parentCell) ), std::invalid_argument,
1528  ">>> ERROR (Intrepid::CellTools::mapToReferenceSubcell): the specified cell topology does not have a reference cell.");
1529 
1530  TEUCHOS_TEST_FOR_EXCEPTION( !( (1 <= subcellDim) && (subcellDim <= 2 ) ), std::invalid_argument,
1531  ">>> ERROR (Intrepid::CellTools::mapToReferenceSubcell): method defined only for 1 and 2-dimensional subcells.");
1532 
1533  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= subcellOrd) && (subcellOrd < (int)parentCell.getSubcellCount(subcellDim) ) ), std::invalid_argument,
1534  ">>> ERROR (Intrepid::CellTools::mapToReferenceSubcell): subcell ordinal out of range.");
1535 
1536  // refSubcellPoints is rank-2 (P,D1), D1 = cell dimension
1537  std::string errmsg = ">>> ERROR (Intrepid::mapToReferenceSubcell):";
1538  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, refSubcellPoints, 2,2), std::invalid_argument, errmsg);
1539  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, refSubcellPoints, 1, cellDim, cellDim), std::invalid_argument, errmsg);
1540 
1541  // paramPoints is rank-2 (P,D2) with D2 = subcell dimension
1542  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, paramPoints, 2,2), std::invalid_argument, errmsg);
1543  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, paramPoints, 1, subcellDim, subcellDim), std::invalid_argument, errmsg);
1544 
1545  // cross check: refSubcellPoints and paramPoints: dimension 0 must match
1546  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, refSubcellPoints, 0, paramPoints, 0), std::invalid_argument, errmsg);
1547 #endif
1548 
1549 
1550  // Get the subcell map, i.e., the coefficients of the parametrization function for the subcell
1551  const FieldContainer<double>& subcellMap = getSubcellParametrization(subcellDim, parentCell);
1552 
1553  // Apply the parametrization map to every point in parameter domain
1554  if(subcellDim == 2) {
1555  for(int pt = 0; pt < numPts; pt++){
1556  double u = paramPoints(pt,0);
1557  double v = paramPoints(pt,1);
1558 
1559  // map_dim(u,v) = c_0(dim) + c_1(dim)*u + c_2(dim)*v because both Quad and Tri ref faces are affine!
1560  for(int dim = 0; dim < cellDim; dim++){
1561  refSubcellPoints(pt, dim) = subcellMap(subcellOrd, dim, 0) + \
1562  subcellMap(subcellOrd, dim, 1)*u + \
1563  subcellMap(subcellOrd, dim, 2)*v;
1564  }
1565  }
1566  }
1567  else if(subcellDim == 1) {
1568  for(int pt = 0; pt < numPts; pt++){
1569  for(int dim = 0; dim < cellDim; dim++) {
1570  refSubcellPoints(pt, dim) = subcellMap(subcellOrd, dim, 0) + subcellMap(subcellOrd, dim, 1)*paramPoints(pt,0);
1571  }
1572  }
1573  }
1574  else{
1575  TEUCHOS_TEST_FOR_EXCEPTION( !( (subcellDim == 1) || (subcellDim == 2) ), std::invalid_argument,
1576  ">>> ERROR (Intrepid::CellTools::mapToReferenceSubcell): method defined only for 1 and 2-subcells");
1577  }
1578 }
1579 
1580 
1581 
1582 template<class Scalar>
1583 template<class ArrayEdgeTangent>
1584 void CellTools<Scalar>::getReferenceEdgeTangent(ArrayEdgeTangent & refEdgeTangent,
1585  const int & edgeOrd,
1586  const shards::CellTopology & parentCell){
1587 
1588  int spaceDim = parentCell.getDimension();
1589 
1590 #ifdef HAVE_INTREPID_DEBUG
1591 
1592  TEUCHOS_TEST_FOR_EXCEPTION( !( (spaceDim == 2) || (spaceDim == 3) ), std::invalid_argument,
1593  ">>> ERROR (Intrepid::CellTools::getReferenceFaceTangents): two or three-dimensional parent cell required");
1594 
1595  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= edgeOrd) && (edgeOrd < (int)parentCell.getSubcellCount(1) ) ), std::invalid_argument,
1596  ">>> ERROR (Intrepid::CellTools::getReferenceFaceTangents): edge ordinal out of bounds");
1597 
1598  TEUCHOS_TEST_FOR_EXCEPTION( !( refEdgeTangent.size() == spaceDim ), std::invalid_argument,
1599  ">>> ERROR (Intrepid::CellTools::getReferenceFaceTangents): output array size is required to match space dimension");
1600 #endif
1601 
1602  // Edge parametrizations are computed in setSubcellParametrization and stored in rank-3 array
1603  // (subcOrd, coordinate, coefficient)
1604  const FieldContainer<double>& edgeMap = getSubcellParametrization(1, parentCell);
1605 
1606  // All ref. edge maps have affine coordinate functions: f_dim(u) = C_0(dim) + C_1(dim)*u,
1607  // => edge Tangent: -> C_1(*)
1608  refEdgeTangent(0) = edgeMap(edgeOrd, 0, 1);
1609  refEdgeTangent(1) = edgeMap(edgeOrd, 1, 1);
1610 
1611  // Skip last coordinate for 2D parent cells
1612  if(spaceDim == 3) {
1613  refEdgeTangent(2) = edgeMap(edgeOrd, 2, 1);
1614  }
1615 }
1616 
1617 
1618 
1619 template<class Scalar>
1620 template<class ArrayFaceTangentU, class ArrayFaceTangentV>
1621 void CellTools<Scalar>::getReferenceFaceTangents(ArrayFaceTangentU & uTan,
1622  ArrayFaceTangentV & vTan,
1623  const int & faceOrd,
1624  const shards::CellTopology & parentCell){
1625 
1626 #ifdef HAVE_INTREPID_DEBUG
1627  int spaceDim = parentCell.getDimension();
1628  TEUCHOS_TEST_FOR_EXCEPTION( !(spaceDim == 3), std::invalid_argument,
1629  ">>> ERROR (Intrepid::CellTools::getReferenceFaceTangents): three-dimensional parent cell required");
1630 
1631  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= faceOrd) && (faceOrd < (int)parentCell.getSubcellCount(2) ) ), std::invalid_argument,
1632  ">>> ERROR (Intrepid::CellTools::getReferenceFaceTangents): face ordinal out of bounds");
1633 
1634  TEUCHOS_TEST_FOR_EXCEPTION( !( (uTan.rank() == 1) && (vTan.rank() == 1) ), std::invalid_argument,
1635  ">>> ERROR (Intrepid::CellTools::getReferenceFaceTangents): rank = 1 required for output arrays");
1636 
1637  TEUCHOS_TEST_FOR_EXCEPTION( !( uTan.dimension(0) == spaceDim ), std::invalid_argument,
1638  ">>> ERROR (Intrepid::CellTools::getReferenceFaceTangents): dim0 (spatial dim) must match that of parent cell");
1639 
1640  TEUCHOS_TEST_FOR_EXCEPTION( !( vTan.dimension(0) == spaceDim ), std::invalid_argument,
1641  ">>> ERROR (Intrepid::CellTools::getReferenceFaceTangents): dim0 (spatial dim) must match that of parent cell");
1642 #endif
1643 
1644  // Face parametrizations are computed in setSubcellParametrization and stored in rank-3 array
1645  // (subcOrd, coordinate, coefficient): retrieve this array
1646  const FieldContainer<double>& faceMap = getSubcellParametrization(2, parentCell);
1647 
1648  /* All ref. face maps have affine coordinate functions: f_dim(u,v) = C_0(dim) + C_1(dim)*u + C_2(dim)*v
1649  * ` => Tangent vectors are: uTan -> C_1(*); vTan -> C_2(*)
1650  */
1651  // set uTan -> C_1(*)
1652  uTan(0) = faceMap(faceOrd, 0, 1);
1653  uTan(1) = faceMap(faceOrd, 1, 1);
1654  uTan(2) = faceMap(faceOrd, 2, 1);
1655 
1656  // set vTan -> C_2(*)
1657  vTan(0) = faceMap(faceOrd, 0, 2);
1658  vTan(1) = faceMap(faceOrd, 1, 2);
1659  vTan(2) = faceMap(faceOrd, 2, 2);
1660 }
1661 
1662 
1663 
1664 template<class Scalar>
1665 template<class ArraySideNormal>
1666 void CellTools<Scalar>::getReferenceSideNormal(ArraySideNormal & refSideNormal,
1667  const int & sideOrd,
1668  const shards::CellTopology & parentCell){
1669  int spaceDim = parentCell.getDimension();
1670 #ifdef HAVE_INTREPID_DEBUG
1671 
1672  TEUCHOS_TEST_FOR_EXCEPTION( !( (spaceDim == 2) || (spaceDim == 3) ), std::invalid_argument,
1673  ">>> ERROR (Intrepid::CellTools::getReferenceSideNormal): two or three-dimensional parent cell required");
1674 
1675  // Check side ordinal: by definition side is subcell whose dimension = spaceDim-1
1676  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= sideOrd) && (sideOrd < (int)parentCell.getSubcellCount(spaceDim - 1) ) ), std::invalid_argument,
1677  ">>> ERROR (Intrepid::CellTools::getReferenceSideNormal): side ordinal out of bounds");
1678 #endif
1679 
1680  if(spaceDim == 2){
1681 
1682  // 2D parent cells: side = 1D subcell (edge), call the edge tangent method and rotate tangents
1683  getReferenceEdgeTangent(refSideNormal, sideOrd, parentCell);
1684 
1685  // rotate t(t1, t2) to get n(t2, -t1) so that (n,t) is positively oriented: det(n1,n2/t1,t2)>0
1686  Scalar temp = refSideNormal(0);
1687  refSideNormal(0) = refSideNormal(1);
1688  refSideNormal(1) = -temp;
1689  }
1690  else{
1691  // 3D parent cell: side = 2D subcell (face), call the face normal method.
1692  getReferenceFaceNormal(refSideNormal, sideOrd, parentCell);
1693  }
1694 }
1695 
1696 
1697 
1698 template<class Scalar>
1699 template<class ArrayFaceNormal>
1700 void CellTools<Scalar>::getReferenceFaceNormal(ArrayFaceNormal & refFaceNormal,
1701  const int & faceOrd,
1702  const shards::CellTopology & parentCell){
1703  int spaceDim = parentCell.getDimension();
1704 
1705 #ifdef HAVE_INTREPID_DEBUG
1706 
1707  TEUCHOS_TEST_FOR_EXCEPTION( !(spaceDim == 3), std::invalid_argument,
1708  ">>> ERROR (Intrepid::CellTools::getReferenceFaceNormal): three-dimensional parent cell required");
1709 
1710  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= faceOrd) && (faceOrd < (int)parentCell.getSubcellCount(2) ) ), std::invalid_argument,
1711  ">>> ERROR (Intrepid::CellTools::getReferenceFaceNormal): face ordinal out of bounds");
1712 
1713  TEUCHOS_TEST_FOR_EXCEPTION( !( refFaceNormal.rank() == 1 ), std::invalid_argument,
1714  ">>> ERROR (Intrepid::CellTools::getReferenceFaceNormal): rank = 1 required for output array");
1715 
1716  TEUCHOS_TEST_FOR_EXCEPTION( !( refFaceNormal.dimension(0) == spaceDim ), std::invalid_argument,
1717  ">>> ERROR (Intrepid::CellTools::getReferenceFaceNormal): dim0 (spatial dim) must match that of parent cell");
1718 #endif
1719 
1720  // Reference face normal = vector product of reference face tangents. Allocate temp FC storage:
1721  FieldContainer<Scalar> uTan(spaceDim);
1722  FieldContainer<Scalar> vTan(spaceDim);
1723  getReferenceFaceTangents(uTan, vTan, faceOrd, parentCell);
1724 
1725  // Compute the vector product of the reference face tangents:
1726  RealSpaceTools<Scalar>::vecprod(refFaceNormal, uTan, vTan);
1727 }
1728 
1729 
1730 
1731 template<class Scalar>
1732 template<class ArrayEdgeTangent, class ArrayJac>
1733 void CellTools<Scalar>::getPhysicalEdgeTangents(ArrayEdgeTangent & edgeTangents,
1734  const ArrayJac & worksetJacobians,
1735  const int & worksetEdgeOrd,
1736  const shards::CellTopology & parentCell){
1737  int worksetSize = worksetJacobians.dimension(0);
1738  int edgePtCount = worksetJacobians.dimension(1);
1739  int pCellDim = parentCell.getDimension();
1740 
1741 #ifdef HAVE_INTREPID_DEBUG
1742  std::string errmsg = ">>> ERROR (Intrepid::CellTools::getPhysicalEdgeTangents):";
1743 
1744  TEUCHOS_TEST_FOR_EXCEPTION( !( (pCellDim == 3) || (pCellDim == 2) ), std::invalid_argument,
1745  ">>> ERROR (Intrepid::CellTools::getPhysicalEdgeTangents): 2D or 3D parent cell required");
1746 
1747  // (1) edgeTangents is rank-3 (C,P,D) and D=2, or 3 is required
1748  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, edgeTangents, 3,3), std::invalid_argument, errmsg);
1749  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, edgeTangents, 2, 2,3), std::invalid_argument, errmsg);
1750 
1751  // (2) worksetJacobians in rank-4 (C,P,D,D) and D=2, or 3 is required
1752  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, worksetJacobians, 4,4), std::invalid_argument, errmsg);
1753  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, worksetJacobians, 2, 2,3), std::invalid_argument, errmsg);
1754  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, worksetJacobians, 3, 2,3), std::invalid_argument, errmsg);
1755 
1756  // (4) cross-check array dimensions: edgeTangents (C,P,D) vs. worksetJacobians (C,P,D,D)
1757  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, edgeTangents, 0,1,2,2, worksetJacobians, 0,1,2,3), std::invalid_argument, errmsg);
1758 
1759 #endif
1760 
1761  // Temp storage for constant reference edge tangent: rank-1 (D) arrays
1762  FieldContainer<double> refEdgeTan(pCellDim);
1763  getReferenceEdgeTangent(refEdgeTan, worksetEdgeOrd, parentCell);
1764 
1765  // Loop over workset faces and edge points
1766  for(int pCell = 0; pCell < worksetSize; pCell++){
1767  for(int pt = 0; pt < edgePtCount; pt++){
1768 
1769  // Apply parent cell Jacobian to ref. edge tangent
1770  for(int i = 0; i < pCellDim; i++){
1771  edgeTangents(pCell, pt, i) = 0.0;
1772  for(int j = 0; j < pCellDim; j++){
1773  edgeTangents(pCell, pt, i) += worksetJacobians(pCell, pt, i, j)*refEdgeTan(j);
1774  }// for j
1775  }// for i
1776  }// for pt
1777  }// for pCell
1778 }
1779 
1780 
1781 
1782 template<class Scalar>
1783 template<class ArrayFaceTangentU, class ArrayFaceTangentV, class ArrayJac>
1784 void CellTools<Scalar>::getPhysicalFaceTangents(ArrayFaceTangentU & faceTanU,
1785  ArrayFaceTangentV & faceTanV,
1786  const ArrayJac & worksetJacobians,
1787  const int & worksetFaceOrd,
1788  const shards::CellTopology & parentCell){
1789  int worksetSize = worksetJacobians.dimension(0);
1790  int facePtCount = worksetJacobians.dimension(1);
1791  int pCellDim = parentCell.getDimension();
1792 
1793 #ifdef HAVE_INTREPID_DEBUG
1794  std::string errmsg = ">>> ERROR (Intrepid::CellTools::getPhysicalFaceTangents):";
1795 
1796  TEUCHOS_TEST_FOR_EXCEPTION( !(pCellDim == 3), std::invalid_argument,
1797  ">>> ERROR (Intrepid::CellTools::getPhysicalFaceTangents): three-dimensional parent cell required");
1798 
1799  // (1) faceTanU and faceTanV are rank-3 (C,P,D) and D=3 is required
1800  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, faceTanU, 3,3), std::invalid_argument, errmsg);
1801  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, faceTanU, 2, 3,3), std::invalid_argument, errmsg);
1802 
1803  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, faceTanV, 3,3), std::invalid_argument, errmsg);
1804  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, faceTanV, 2, 3,3), std::invalid_argument, errmsg);
1805 
1806  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, faceTanU, faceTanV), std::invalid_argument, errmsg);
1807 
1808  // (3) worksetJacobians in rank-4 (C,P,D,D) and D=3 is required
1809  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, worksetJacobians, 4,4), std::invalid_argument, errmsg);
1810  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, worksetJacobians, 2, 3,3), std::invalid_argument, errmsg);
1811  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, worksetJacobians, 3, 3,3), std::invalid_argument, errmsg);
1812 
1813  // (4) cross-check array dimensions: faceTanU (C,P,D) vs. worksetJacobians (C,P,D,D)
1814  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, faceTanU, 0,1,2,2, worksetJacobians, 0,1,2,3), std::invalid_argument, errmsg);
1815 
1816 #endif
1817 
1818  // Temp storage for the pair of constant ref. face tangents: rank-1 (D) arrays
1819  FieldContainer<double> refFaceTanU(pCellDim);
1820  FieldContainer<double> refFaceTanV(pCellDim);
1821  getReferenceFaceTangents(refFaceTanU, refFaceTanV, worksetFaceOrd, parentCell);
1822 
1823  // Loop over workset faces and face points
1824  for(int pCell = 0; pCell < worksetSize; pCell++){
1825  for(int pt = 0; pt < facePtCount; pt++){
1826 
1827  // Apply parent cell Jacobian to ref. face tangents
1828  for(int dim = 0; dim < pCellDim; dim++){
1829  faceTanU(pCell, pt, dim) = 0.0;
1830  faceTanV(pCell, pt, dim) = 0.0;
1831 
1832  // Unroll loops: parent cell dimension can only be 3
1833  faceTanU(pCell, pt, dim) = \
1834  worksetJacobians(pCell, pt, dim, 0)*refFaceTanU(0) + \
1835  worksetJacobians(pCell, pt, dim, 1)*refFaceTanU(1) + \
1836  worksetJacobians(pCell, pt, dim, 2)*refFaceTanU(2);
1837  faceTanV(pCell, pt, dim) = \
1838  worksetJacobians(pCell, pt, dim, 0)*refFaceTanV(0) + \
1839  worksetJacobians(pCell, pt, dim, 1)*refFaceTanV(1) + \
1840  worksetJacobians(pCell, pt, dim, 2)*refFaceTanV(2);
1841  }// for dim
1842  }// for pt
1843  }// for pCell
1844 }
1845 
1846 
1847 template<class Scalar>
1848 template<class ArraySideNormal, class ArrayJac>
1849 void CellTools<Scalar>::getPhysicalSideNormals(ArraySideNormal & sideNormals,
1850  const ArrayJac & worksetJacobians,
1851  const int & worksetSideOrd,
1852  const shards::CellTopology & parentCell){
1853  int worksetSize = worksetJacobians.dimension(0);
1854  int sidePtCount = worksetJacobians.dimension(1);
1855  int spaceDim = parentCell.getDimension();
1856 
1857 #ifdef HAVE_INTREPID_DEBUG
1858  TEUCHOS_TEST_FOR_EXCEPTION( !( (spaceDim == 2) || (spaceDim == 3) ), std::invalid_argument,
1859  ">>> ERROR (Intrepid::CellTools::getPhysicalSideNormals): two or three-dimensional parent cell required");
1860 
1861  // Check side ordinal: by definition side is subcell whose dimension = spaceDim-1
1862  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 <= worksetSideOrd) && (worksetSideOrd < (int)parentCell.getSubcellCount(spaceDim - 1) ) ), std::invalid_argument,
1863  ">>> ERROR (Intrepid::CellTools::getPhysicalSideNormals): side ordinal out of bounds");
1864 #endif
1865 
1866  if(spaceDim == 2){
1867 
1868  // 2D parent cells: side = 1D subcell (edge), call the edge tangent method and rotate tangents
1869  getPhysicalEdgeTangents(sideNormals, worksetJacobians, worksetSideOrd, parentCell);
1870 
1871  // rotate t(t1, t2) to get n(t2, -t1) so that (n,t) is positively oriented: det(n1,n2/t1,t2)>0
1872  for(int cell = 0; cell < worksetSize; cell++){
1873  for(int pt = 0; pt < sidePtCount; pt++){
1874  Scalar temp = sideNormals(cell, pt, 0);
1875  sideNormals(cell, pt, 0) = sideNormals(cell, pt, 1);
1876  sideNormals(cell, pt, 1) = -temp;
1877  }// for pt
1878  }// for cell
1879  }
1880  else{
1881  // 3D parent cell: side = 2D subcell (face), call the face normal method.
1882  getPhysicalFaceNormals(sideNormals, worksetJacobians, worksetSideOrd, parentCell);
1883  }
1884 }
1885 
1886 
1887 
1888 template<class Scalar>
1889 template<class ArrayFaceNormal, class ArrayJac>
1890 void CellTools<Scalar>::getPhysicalFaceNormals(ArrayFaceNormal & faceNormals,
1891  const ArrayJac & worksetJacobians,
1892  const int & worksetFaceOrd,
1893  const shards::CellTopology & parentCell){
1894  int worksetSize = worksetJacobians.dimension(0);
1895  int facePtCount = worksetJacobians.dimension(1);
1896  int pCellDim = parentCell.getDimension();
1897 
1898 #ifdef HAVE_INTREPID_DEBUG
1899  std::string errmsg = ">>> ERROR (Intrepid::CellTools::getPhysicalFaceNormals):";
1900 
1901  TEUCHOS_TEST_FOR_EXCEPTION( !(pCellDim == 3), std::invalid_argument,
1902  ">>> ERROR (Intrepid::CellTools::getPhysicalFaceNormals): three-dimensional parent cell required");
1903 
1904  // (1) faceNormals is rank-3 (C,P,D) and D=3 is required
1905  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, faceNormals, 3,3), std::invalid_argument, errmsg);
1906  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, faceNormals, 2, 3,3), std::invalid_argument, errmsg);
1907 
1908  // (3) worksetJacobians in rank-4 (C,P,D,D) and D=3 is required
1909  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, worksetJacobians, 4,4), std::invalid_argument, errmsg);
1910  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, worksetJacobians, 2, 3,3), std::invalid_argument, errmsg);
1911  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionRange(errmsg, worksetJacobians, 3, 3,3), std::invalid_argument, errmsg);
1912 
1913  // (4) cross-check array dimensions: faceNormals (C,P,D) vs. worksetJacobians (C,P,D,D)
1914  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, faceNormals, 0,1,2,2, worksetJacobians, 0,1,2,3), std::invalid_argument, errmsg);
1915 #endif
1916 
1917  // Temp storage for physical face tangents: rank-3 (C,P,D) arrays
1918  FieldContainer<Scalar> faceTanU(worksetSize, facePtCount, pCellDim);
1919  FieldContainer<Scalar> faceTanV(worksetSize, facePtCount, pCellDim);
1920  getPhysicalFaceTangents(faceTanU, faceTanV, worksetJacobians, worksetFaceOrd, parentCell);
1921 
1922  // Compute the vector product of the physical face tangents:
1923  RealSpaceTools<Scalar>::vecprod(faceNormals, faceTanU, faceTanV);
1924 
1925 
1926 }
1927 
1928 //============================================================================================//
1929 // //
1930 // Inclusion tests //
1931 // //
1932 //============================================================================================//
1933 
1934 
1935 template<class Scalar>
1937  const int pointDim,
1938  const shards::CellTopology & cellTopo,
1939  const double & threshold) {
1940 #ifdef HAVE_INTREPID_DEBUG
1941  TEUCHOS_TEST_FOR_EXCEPTION( !(pointDim == (int)cellTopo.getDimension() ), std::invalid_argument,
1942  ">>> ERROR (Intrepid::CellTools::checkPointInclusion): Point and cell dimensions do not match. ");
1943 #endif
1944  int testResult = 1;
1945 
1946  // Using these values in the tests effectievly inflates the reference element to a larger one
1947  double minus_one = -1.0 - threshold;
1948  double plus_one = 1.0 + threshold;
1949  double minus_zero = - threshold;
1950 
1951  // A cell with extended topology has the same reference cell as a cell with base topology.
1952  // => testing for inclusion in a reference Triangle<> and a reference Triangle<6> relies on
1953  // on the same set of inequalities. To eliminate unnecessary cases we switch on the base topology
1954  unsigned key = cellTopo.getBaseCellTopologyData() -> key ;
1955  switch( key ) {
1956 
1957  case shards::Line<>::key :
1958  if( !(minus_one <= point[0] && point[0] <= plus_one)) testResult = 0;
1959  break;
1960 
1961  case shards::Triangle<>::key : {
1962  Scalar distance = std::max( std::max( -point[0], -point[1] ), point[0] + point[1] - 1.0 );
1963  if( distance > threshold ) testResult = 0;
1964  break;
1965  }
1966 
1967  case shards::Quadrilateral<>::key :
1968  if(!( (minus_one <= point[0] && point[0] <= plus_one) && \
1969  (minus_one <= point[1] && point[1] <= plus_one) ) ) testResult = 0;
1970  break;
1971 
1972  case shards::Tetrahedron<>::key : {
1973  Scalar distance = std::max( std::max(-point[0],-point[1]), \
1974  std::max(-point[2], point[0] + point[1] + point[2] - 1) );
1975  if( distance > threshold ) testResult = 0;
1976  break;
1977  }
1978 
1979  case shards::Hexahedron<>::key :
1980  if(!((minus_one <= point[0] && point[0] <= plus_one) && \
1981  (minus_one <= point[1] && point[1] <= plus_one) && \
1982  (minus_one <= point[2] && point[2] <= plus_one))) \
1983  testResult = 0;
1984  break;
1985 
1986  // The base of the reference prism is the same as the reference triangle => apply triangle test
1987  // to X and Y coordinates and test whether Z is in [-1,1]
1988  case shards::Wedge<>::key : {
1989  Scalar distance = std::max( std::max( -point[0], -point[1] ), point[0] + point[1] - 1 );
1990  if( distance > threshold || \
1991  point[2] < minus_one || point[2] > plus_one) \
1992  testResult = 0;
1993  break;
1994  }
1995 
1996  // The base of the reference pyramid is the same as the reference quad cell => a horizontal plane
1997  // through a point P(x,y,z) intersects the pyramid at a quadrilateral that equals the base quad
1998  // scaled by (1-z) => P(x,y,z) is inside the pyramid <=> (x,y) is in [-1+z,1-z]^2 && 0 <= Z <= 1
1999  case shards::Pyramid<>::key : {
2000  Scalar left = minus_one + point[2];
2001  Scalar right = plus_one - point[2];
2002  if(!( (left <= point[0] && point[0] <= right) && \
2003  (left <= point[1] && point[1] <= right) &&
2004  (minus_zero <= point[2] && point[2] <= plus_one) ) ) \
2005  testResult = 0;
2006  break;
2007  }
2008 
2009  default:
2010  TEUCHOS_TEST_FOR_EXCEPTION( !( (key == shards::Line<>::key ) ||
2011  (key == shards::Triangle<>::key) ||
2012  (key == shards::Quadrilateral<>::key) ||
2013  (key == shards::Tetrahedron<>::key) ||
2014  (key == shards::Hexahedron<>::key) ||
2015  (key == shards::Wedge<>::key) ||
2016  (key == shards::Pyramid<>::key) ),
2017  std::invalid_argument,
2018  ">>> ERROR (Intrepid::CellTools::checkPointInclusion): Invalid cell topology. ");
2019  }
2020  return testResult;
2021 }
2022 
2023 
2024 
2025 template<class Scalar>
2026 template<class ArrayPoint>
2027 int CellTools<Scalar>::checkPointsetInclusion(const ArrayPoint& points,
2028  const shards::CellTopology & cellTopo,
2029  const double & threshold) {
2030 
2031  int rank = points.rank();
2032 
2033 #ifdef HAVE_INTREPID_DEBUG
2034  TEUCHOS_TEST_FOR_EXCEPTION( !( (1 <= points.rank() ) && (points.rank() <= 3) ), std::invalid_argument,
2035  ">>> ERROR (Intrepid::CellTools::checkPointsetInclusion): rank-1, 2 or 3 required for input points array. ");
2036 
2037  // The last dimension of points array at (rank - 1) is the spatial dimension. Must equal the cell dimension.
2038  TEUCHOS_TEST_FOR_EXCEPTION( !( points.dimension(rank - 1) == (int)cellTopo.getDimension() ), std::invalid_argument,
2039  ">>> ERROR (Intrepid::CellTools::checkPointsetInclusion): Point and cell dimensions do not match. ");
2040 #endif
2041 
2042  // create temp output array depending on the rank of the input array
2043  FieldContainer<int> inRefCell;
2044  switch(rank) {
2045  case 1: inRefCell.resize(1); break;
2046  case 2: inRefCell.resize( points.dimension(0) ); break;
2047  case 3: inRefCell.resize( points.dimension(0), points.dimension(1) ); break;
2048  }
2049 
2050  // Call the inclusion method which returns inclusion results for all points
2051  checkPointwiseInclusion(inRefCell, points, cellTopo, threshold);
2052 
2053  // Check if any points were outside, break when finding the first one
2054  int allInside = 1;
2055  for(int i = 0; i < inRefCell.size(); i++ ){
2056  if (inRefCell[i] == 0) {
2057  allInside = 0;
2058  break;
2059  }
2060  }
2061  return allInside;
2062 }
2063 
2064 
2065 
2066 template<class Scalar>
2067 template<class ArrayIncl, class ArrayPoint>
2069  const ArrayPoint & points,
2070  const shards::CellTopology & cellTopo,
2071  const double & threshold) {
2072  int apRank = points.rank();
2073 
2074 #ifdef HAVE_INTREPID_DEBUG
2075 
2076  // Verify that points and inRefCell have correct ranks and dimensions
2077  std::string errmsg = ">>> ERROR (Intrepid::CellTools::checkPointwiseInclusion):";
2078  if(points.rank() == 1) {
2079  TEUCHOS_TEST_FOR_EXCEPTION( !(inRefCell.rank() == 1 ), std::invalid_argument,
2080  ">>> ERROR (Intrepid::CellTools::checkPointwiseInclusion): rank-1 input array requires rank-1 output array.");
2081  TEUCHOS_TEST_FOR_EXCEPTION( !(inRefCell.dimension(0) == 1), std::invalid_argument,
2082  ">>> ERROR (Intrepid::CellTools::checkPointwiseInclusion): rank-1 input array requires dim0 = 1 for output array.");
2083  }
2084  else if(points.rank() == 2){
2085  TEUCHOS_TEST_FOR_EXCEPTION( !(inRefCell.rank() == 1 ), std::invalid_argument,
2086  ">>> ERROR (Intrepid::CellTools::checkPointwiseInclusion): rank-2 input array requires rank-1 output array.");
2087  // dimension 0 of the arrays must match
2088  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch( errmsg, inRefCell, 0, points, 0), std::invalid_argument, errmsg);
2089  }
2090  else if (points.rank() == 3) {
2091  TEUCHOS_TEST_FOR_EXCEPTION( !(inRefCell.rank() == 2 ), std::invalid_argument,
2092  ">>> ERROR (Intrepid::CellTools::checkPointwiseInclusion): rank-3 input array requires rank-2 output array.");
2093  // dimensions 0 and 1 of the arrays must match
2094  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch( errmsg, inRefCell, 0,1, points, 0,1), std::invalid_argument, errmsg);
2095  }
2096  else{
2097  TEUCHOS_TEST_FOR_EXCEPTION( !( (points.rank() == 1) || (points.rank() == 2) || (points.rank() == 3) ), std::invalid_argument,
2098  ">>> ERROR (Intrepid::CellTools::checkPointwiseInclusion): rank-1, 2 or 3 required for input points array. ");
2099  }
2100 
2101  // The last dimension of points array at (rank - 1) is the spatial dimension. Must equal the cell dimension.
2102  TEUCHOS_TEST_FOR_EXCEPTION( !( points.dimension(apRank - 1) == (int)cellTopo.getDimension() ), std::invalid_argument,
2103  ">>> ERROR (Intrepid::CellTools::checkPointwiseInclusion): Point and cell dimensions do not match. ");
2104 
2105 #endif
2106 
2107  // Initializations
2108  int dim0 = 1;
2109  int dim1 = 1;
2110  int pointDim = 0;
2111  switch(apRank) {
2112  case 1:
2113  pointDim = points.dimension(0);
2114  break;
2115  case 2:
2116  dim1 = points.dimension(0);
2117  pointDim = points.dimension(1);
2118  break;
2119  case 3:
2120  dim0 = points.dimension(0);
2121  dim1 = points.dimension(1);
2122  pointDim = points.dimension(2);
2123  break;
2124  default:
2125  TEUCHOS_TEST_FOR_EXCEPTION( !( (1 <= points.rank() ) && (points.rank() <= 3) ), std::invalid_argument,
2126  ">>> ERROR (Intrepid::CellTools::checkPointwiseInclusion): rank-1, 2 or 3 required for input points array. ");
2127  }// switch
2128 
2129 
2130  // This method can handle up to rank-3 input arrays. The spatial dim must be the last dimension.
2131  // The method uses [] accessor because array rank is determined at runtime and the appropriate
2132  // (i,j,..,k) accessor is not known. Use of [] requires the following offsets:
2133  // for input array = i0*dim1*pointDim + i1*dim1 (computed in 2 pieces: inPtr0 and inPtr1, resp)
2134  // for output array = i0*dim1 (computed in one piece: outPtr0)
2135  int inPtr0 = 0;
2136  int inPtr1 = 0;
2137  int outPtr0 = 0;
2138  Scalar point[3] = {0.0, 0.0, 0.0};
2139 
2140  for(int i0 = 0; i0 < dim0; i0++){
2141  outPtr0 = i0*dim1;
2142  inPtr0 = outPtr0*pointDim;
2143 
2144  for(int i1 = 0; i1 < dim1; i1++) {
2145  inPtr1 = inPtr0 + i1*pointDim;
2146  point[0] = points[inPtr1];
2147  if(pointDim > 1) {
2148  point[1] = points[inPtr1 + 1];
2149  if(pointDim > 2) {
2150  point[2] = points[inPtr1 + 2];
2151  if(pointDim > 3) {
2152  TEUCHOS_TEST_FOR_EXCEPTION( !( (1 <= pointDim) && (pointDim <= 3)), std::invalid_argument,
2153  ">>> ERROR (Intrepid::CellTools::checkPointwiseInclusion): Input array specifies invalid point dimension ");
2154  }
2155  }
2156  } //if(pointDim > 1)
2157  inRefCell[outPtr0 + i1] = checkPointInclusion(point, pointDim, cellTopo, threshold);
2158  } // for (i1)
2159  } // for(i2)
2160 
2161 }
2162 
2163 
2164 template<class Scalar>
2165 template<class ArrayIncl, class ArrayPoint, class ArrayCell>
2167  const ArrayPoint & points,
2168  const ArrayCell & cellWorkset,
2169  const shards::CellTopology & cell,
2170  const int & whichCell,
2171  const double & threshold)
2172 {
2173  INTREPID_VALIDATE( validateArguments_checkPointwiseInclusion(inCell, points, cellWorkset, whichCell, cell) );
2174 
2175  // For cell topologies with reference cells this test maps the points back to the reference cell
2176  // and uses the method for reference cells
2177  unsigned baseKey = cell.getBaseCellTopologyData() -> key;
2178 
2179  switch(baseKey){
2180 
2181  case shards::Line<>::key :
2182  case shards::Triangle<>::key:
2183  case shards::Quadrilateral<>::key :
2184  case shards::Tetrahedron<>::key :
2185  case shards::Hexahedron<>::key :
2186  case shards::Wedge<>::key :
2187  case shards::Pyramid<>::key :
2188  {
2189  FieldContainer<Scalar> refPoints;
2190 
2191  if(points.rank() == 2){
2192  refPoints.resize(points.dimension(0), points.dimension(1) );
2193  mapToReferenceFrame(refPoints, points, cellWorkset, cell, whichCell);
2194  checkPointwiseInclusion(inCell, refPoints, cell, threshold );
2195  }
2196  else if(points.rank() == 3){
2197  refPoints.resize(points.dimension(0), points.dimension(1), points.dimension(2) );
2198  mapToReferenceFrame(refPoints, points, cellWorkset, cell, whichCell);
2199  checkPointwiseInclusion(inCell, refPoints, cell, threshold );
2200  }
2201  break;
2202  }
2203  default:
2204  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
2205  ">>> ERROR (Intrepid::CellTools::checkPointwiseInclusion): cell topology not supported");
2206  }// switch
2207 
2208 }
2209 
2210 
2211 //============================================================================================//
2212 // //
2213 // Validation of input/output arguments for CellTools methods //
2214 // //
2215 //============================================================================================//
2216 
2217 template<class Scalar>
2218 template<class ArrayJac, class ArrayPoint, class ArrayCell>
2220  const ArrayPoint & points,
2221  const ArrayCell & cellWorkset,
2222  const int & whichCell,
2223  const shards::CellTopology & cellTopo){
2224 
2225  // Validate cellWorkset array
2226  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.rank() != 3), std::invalid_argument,
2227  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): rank = 3 required for cellWorkset array");
2228 
2229  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(0) <= 0), std::invalid_argument,
2230  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 0 (number of cells) >= 1 required for cellWorkset array");
2231 
2232  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(1) != (int)cellTopo.getSubcellCount(0) ), std::invalid_argument,
2233  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 1 (number of cell nodes) of cellWorkset array does not match cell topology");
2234 
2235  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(2) != (int)cellTopo.getDimension() ), std::invalid_argument,
2236  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 2 (spatial dimension) of cellWorkset array does not match cell dimension");
2237 
2238  // validate whichCell. It can be either -1 (default value) or a valid cell ordinal.
2239  TEUCHOS_TEST_FOR_EXCEPTION( !( ( (0 <= whichCell ) && (whichCell < cellWorkset.dimension(0) ) ) || (whichCell == -1) ), std::invalid_argument,
2240  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): whichCell = -1 or a valid cell ordinal is required.");
2241 
2242 
2243  // Validate points array: can be rank-2 (P,D) or rank-3 (C,P,D)
2244  // If rank-2: admissible jacobians: rank-3 (P,D,D) or rank-4 (C,P,D,D); admissible whichCell: -1 (default) or cell ordinal.
2245  if(points.rank() == 2) {
2246  TEUCHOS_TEST_FOR_EXCEPTION( (points.dimension(0) <= 0), std::invalid_argument,
2247  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 0 (number of points) >= 1 required for points array ");
2248 
2249  TEUCHOS_TEST_FOR_EXCEPTION( (points.dimension(1) != (int)cellTopo.getDimension() ), std::invalid_argument,
2250  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 1 (spatial dimension) of points array does not match cell dimension");
2251 
2252  // Validate the output array for the Jacobian: if whichCell == -1 all Jacobians are computed, rank-4 (C,P,D,D) required
2253  if(whichCell == -1) {
2254  TEUCHOS_TEST_FOR_EXCEPTION( (jacobian.rank() != 4), std::invalid_argument,
2255  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): rank = 4 required for jacobian array");
2256 
2257  TEUCHOS_TEST_FOR_EXCEPTION( (jacobian.dimension(0) != cellWorkset.dimension(0)), std::invalid_argument,
2258  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 0 (number of cells) of jacobian array must equal dim 0 of cellWorkset array");
2259 
2260  TEUCHOS_TEST_FOR_EXCEPTION( (jacobian.dimension(1) != points.dimension(0)), std::invalid_argument,
2261  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 1 (number of points) of jacobian array must equal dim 0 of points array");
2262 
2263  TEUCHOS_TEST_FOR_EXCEPTION( (jacobian.dimension(2) != points.dimension(1)), std::invalid_argument,
2264  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 2 (spatial dimension) of jacobian array must equal dim 1 of points array");
2265 
2266  TEUCHOS_TEST_FOR_EXCEPTION( !(jacobian.dimension(2) == jacobian.dimension(3) ), std::invalid_argument,
2267  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 2 = dim 3 (same spatial dimensions) required for jacobian array. ");
2268 
2269  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 < jacobian.dimension(3) ) && (jacobian.dimension(3) < 4) ), std::invalid_argument,
2270  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 2 and dim 3 (spatial dimensions) must be between 1 and 3. ");
2271  }
2272  // A single cell Jacobian is computed when whichCell != -1 (whichCell has been already validated), rank-3 (P,D,D) required
2273  else {
2274  TEUCHOS_TEST_FOR_EXCEPTION( (jacobian.rank() != 3), std::invalid_argument,
2275  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): rank = 3 required for jacobian array");
2276 
2277  TEUCHOS_TEST_FOR_EXCEPTION( (jacobian.dimension(0) != points.dimension(0)), std::invalid_argument,
2278  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 0 (number of points) of jacobian array must equal dim 0 of points array");
2279 
2280  TEUCHOS_TEST_FOR_EXCEPTION( (jacobian.dimension(1) != points.dimension(1)), std::invalid_argument,
2281  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 1 (spatial dimension) of jacobian array must equal dim 1 of points array");
2282 
2283  TEUCHOS_TEST_FOR_EXCEPTION( !(jacobian.dimension(1) == jacobian.dimension(2) ), std::invalid_argument,
2284  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 1 = dim 2 (same spatial dimensions) required for jacobian array. ");
2285 
2286  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 < jacobian.dimension(1) ) && (jacobian.dimension(1) < 4) ), std::invalid_argument,
2287  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 1 and dim 2 (spatial dimensions) must be between 1 and 3. ");
2288  }
2289  }
2290  // Point array is rank-3 (C,P,D): requires whichCell = -1 and rank-4 (C,P,D,D) jacobians
2291  else if(points.rank() ==3){
2292  std::string errmsg = ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian):";
2293  TEUCHOS_TEST_FOR_EXCEPTION( (points.dimension(0) != cellWorkset.dimension(0) ), std::invalid_argument,
2294  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 0 (number of cells) of points array must equal dim 0 of cellWorkset array");
2295 
2296  TEUCHOS_TEST_FOR_EXCEPTION( (points.dimension(1) <= 0), std::invalid_argument,
2297  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 1 (number of points) >= 1 required for points array ");
2298 
2299  TEUCHOS_TEST_FOR_EXCEPTION( (points.dimension(2) != (int)cellTopo.getDimension() ), std::invalid_argument,
2300  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 2 (spatial dimension) of points array does not match cell dimension");
2301 
2302  TEUCHOS_TEST_FOR_EXCEPTION( (whichCell != -1), std::invalid_argument,
2303  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): default value whichCell=-1 required for rank-3 input points");
2304 
2305  // rank-4 (C,P,D,D) jacobian required for rank-3 (C,P,D) input points
2306  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg, jacobian, 4, 4), std::invalid_argument,errmsg);
2307 
2308  TEUCHOS_TEST_FOR_EXCEPTION( (jacobian.dimension(0) != points.dimension(0)), std::invalid_argument,
2309  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 0 (number of cells) of jacobian array must equal dim 0 of points array");
2310 
2311  TEUCHOS_TEST_FOR_EXCEPTION( (jacobian.dimension(1) != points.dimension(1)), std::invalid_argument,
2312  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 1 (number of points) of jacobian array must equal dim 1 of points array");
2313 
2314  TEUCHOS_TEST_FOR_EXCEPTION( (jacobian.dimension(2) != points.dimension(2)), std::invalid_argument,
2315  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 2 (spatial dimension) of jacobian array must equal dim 2 of points array");
2316 
2317  TEUCHOS_TEST_FOR_EXCEPTION( !(jacobian.dimension(2) == jacobian.dimension(3) ), std::invalid_argument,
2318  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 2 = dim 3 (same spatial dimensions) required for jacobian array. ");
2319 
2320  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 < jacobian.dimension(3) ) && (jacobian.dimension(3) < 4) ), std::invalid_argument,
2321  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): dim 2 and dim 3 (spatial dimensions) must be between 1 and 3. ");
2322  }
2323  else {
2324  TEUCHOS_TEST_FOR_EXCEPTION( !( (points.rank() == 2) && (points.rank() ==3) ), std::invalid_argument,
2325  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobian): rank = 2 or 3 required for points array");
2326  }
2327 }
2328 
2329 
2330 
2331 template<class Scalar>
2332 template<class ArrayJacInv, class ArrayJac>
2333 void CellTools<Scalar>::validateArguments_setJacobianInv(const ArrayJacInv & jacobianInv,
2334  const ArrayJac & jacobian)
2335 {
2336  // Validate input jacobian array: admissible ranks & dimensions are:
2337  // - rank-4 with dimensions (C,P,D,D), or rank-3 with dimensions (P,D,D).
2338  int jacobRank = jacobian.rank();
2339  TEUCHOS_TEST_FOR_EXCEPTION( !( (jacobRank == 4) || (jacobRank == 3) ), std::invalid_argument,
2340  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianInv): rank = 4 or 3 required for jacobian array. ");
2341 
2342  // Verify correctness of spatial dimensions - they are the last two dimensions of the array: rank-2 and rank-1
2343  TEUCHOS_TEST_FOR_EXCEPTION( !(jacobian.dimension(jacobRank - 1) == jacobian.dimension(jacobRank - 2) ), std::invalid_argument,
2344  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianInv): dim(rank-2) = dim(rank-2) (same spatial dimensions) required for jacobian array. ");
2345 
2346  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 < jacobian.dimension(jacobRank - 1) ) && (jacobian.dimension(jacobRank - 1) < 4) ), std::invalid_argument,
2347  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianInv): dim(rank-1) and dim(rank-2) (spatial dimensions) must be between 1 and 3. ");
2348 
2349  // Validate output jacobianInv array: must have the same rank and dimensions as the input array.
2350  std::string errmsg = ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianInv):";
2351 
2352  TEUCHOS_TEST_FOR_EXCEPTION( !(requireRankMatch(errmsg, jacobianInv, jacobian) ), std::invalid_argument, errmsg);
2353 
2354  TEUCHOS_TEST_FOR_EXCEPTION( !(requireDimensionMatch(errmsg, jacobianInv, jacobian) ), std::invalid_argument, errmsg);
2355 }
2356 
2357 
2358 
2359 template<class Scalar>
2360 template<class ArrayJacDet, class ArrayJac>
2361 void CellTools<Scalar>::validateArguments_setJacobianDetArgs(const ArrayJacDet & jacobianDet,
2362  const ArrayJac & jacobian)
2363 {
2364  // Validate input jacobian array: admissible ranks & dimensions are:
2365  // - rank-4 with dimensions (C,P,D,D), or rank-3 with dimensions (P,D,D).
2366  int jacobRank = jacobian.rank();
2367  TEUCHOS_TEST_FOR_EXCEPTION( !( (jacobRank == 4) || (jacobRank == 3) ), std::invalid_argument,
2368  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianInv): rank = 4 or 3 required for jacobian array. ");
2369 
2370  // Verify correctness of spatial dimensions - they are the last two dimensions of the array: rank-2 and rank-1
2371  TEUCHOS_TEST_FOR_EXCEPTION( !(jacobian.dimension(jacobRank - 1) == jacobian.dimension(jacobRank - 2) ), std::invalid_argument,
2372  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianInv): dim(rank-2) = dim(rank-2) (same spatial dimensions) required for jacobian array. ");
2373 
2374  TEUCHOS_TEST_FOR_EXCEPTION( !( (0 < jacobian.dimension(jacobRank - 1) ) && (jacobian.dimension(jacobRank - 1) < 4) ), std::invalid_argument,
2375  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianInv): dim(rank-1) and dim(rank-2) (spatial dimensions) must be between 1 and 3. ");
2376 
2377 
2378  // Validate output jacobianDet array: must be rank-2 with dimensions (C,P) if jacobian was rank-4:
2379  if(jacobRank == 4){
2380  TEUCHOS_TEST_FOR_EXCEPTION( !(jacobianDet.rank() == 2), std::invalid_argument,
2381  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianDetArgs): rank = 2 required for jacobianDet if jacobian is rank-4. ");
2382 
2383  TEUCHOS_TEST_FOR_EXCEPTION( !(jacobianDet.dimension(0) == jacobian.dimension(0) ), std::invalid_argument,
2384  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianDetArgs): dim 0 (number of cells) of jacobianDet array must equal dim 0 of jacobian array. ");
2385 
2386  TEUCHOS_TEST_FOR_EXCEPTION( !(jacobianDet.dimension(1) == jacobian.dimension(1) ), std::invalid_argument,
2387  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianDetArgs): dim 1 (number of points) of jacobianDet array must equal dim 1 of jacobian array.");
2388  }
2389 
2390  // must be rank-1 with dimension (P) if jacobian was rank-3
2391  else {
2392  TEUCHOS_TEST_FOR_EXCEPTION( !(jacobianDet.rank() == 1), std::invalid_argument,
2393  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianDetArgs): rank = 1 required for jacobianDet if jacobian is rank-3. ");
2394 
2395  TEUCHOS_TEST_FOR_EXCEPTION( !(jacobianDet.dimension(0) == jacobian.dimension(0) ), std::invalid_argument,
2396  ">>> ERROR (Intrepid::CellTools::validateArguments_setJacobianDetArgs): dim 0 (number of points) of jacobianDet array must equal dim 0 of jacobian array.");
2397  }
2398 }
2399 
2400 
2401 
2402 template<class Scalar>
2403 template<class ArrayPhysPoint, class ArrayRefPoint, class ArrayCell>
2404 void CellTools<Scalar>::validateArguments_mapToPhysicalFrame(const ArrayPhysPoint & physPoints,
2405  const ArrayRefPoint & refPoints,
2406  const ArrayCell & cellWorkset,
2407  const shards::CellTopology & cellTopo,
2408  const int& whichCell)
2409 {
2410  std::string errmsg = ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame):";
2411 
2412  // Validate cellWorkset array
2413  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.rank() != 3), std::invalid_argument,
2414  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): rank = 3 required for cellWorkset array");
2415 
2416  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(0) <= 0), std::invalid_argument,
2417  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 0 (number of cells) >= 1 required for cellWorkset array");
2418 
2419  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(1) != (int)cellTopo.getSubcellCount(0) ), std::invalid_argument,
2420  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 1 (number of cell nodes) of cellWorkset array does not match cell topology");
2421 
2422  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(2) != (int)cellTopo.getDimension() ), std::invalid_argument,
2423  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 2 (spatial dimension) of cellWorkset array does not match cell dimension");
2424 
2425 
2426  // validate whichCell. It can be either -1 (default value) or a valid cell ordinal.
2427  TEUCHOS_TEST_FOR_EXCEPTION( !( ( (0 <= whichCell ) && (whichCell < cellWorkset.dimension(0) ) ) || (whichCell == -1) ), std::invalid_argument,
2428  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): whichCell = -1 or a valid cell ordinal is required.");
2429 
2430  // Validate refPoints array: can be rank-2 (P,D) or rank-3 (C,P,D) array
2431  // If rank-2: admissible output array is (P,D) or (C,P,D); admissible whichCell: -1 (default) or cell ordinal
2432  if(refPoints.rank() == 2) {
2433  TEUCHOS_TEST_FOR_EXCEPTION( (refPoints.dimension(0) <= 0), std::invalid_argument,
2434  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 0 (number of points) >= 1 required for refPoints array ");
2435 
2436  TEUCHOS_TEST_FOR_EXCEPTION( (refPoints.dimension(1) != (int)cellTopo.getDimension() ), std::invalid_argument,
2437  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 1 (spatial dimension) of refPoints array does not match cell dimension");
2438 
2439  // Validate output array: whichCell = -1 requires rank-3 array with dimensions (C,P,D)
2440  if(whichCell == -1) {
2441  TEUCHOS_TEST_FOR_EXCEPTION( ( (physPoints.rank() != 3) && (whichCell == -1) ), std::invalid_argument,
2442  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): rank = 3 required for physPoints array for the default whichCell value");
2443 
2444  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.dimension(0) != cellWorkset.dimension(0)), std::invalid_argument,
2445  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 0 (number of cells) of physPoints array must equal dim 0 of cellWorkset array");
2446 
2447  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.dimension(1) != refPoints.dimension(0)), std::invalid_argument,
2448  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 1 (number of points) of physPoints array must equal dim 0 of refPoints array");
2449 
2450  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.dimension(2) != (int)cellTopo.getDimension()), std::invalid_argument,
2451  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 2 (spatial dimension) does not match cell dimension ");
2452  }
2453  // 0 <= whichCell < num cells requires rank-2 (P,D) arrays for both refPoints and physPoints
2454  else{
2455  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.rank() != 2), std::invalid_argument,
2456  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): rank = 2 required for physPoints array");
2457 
2458  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.dimension(0) != refPoints.dimension(0)), std::invalid_argument,
2459  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 0 (number of points) of physPoints array must equal dim 0 of refPoints array");
2460 
2461  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.dimension(1) != (int)cellTopo.getDimension()), std::invalid_argument,
2462  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 1 (spatial dimension) does not match cell dimension ");
2463  }
2464  }
2465  // refPoints is (C,P,D): requires physPoints to be (C,P,D) and whichCell=-1 (because all cell mappings are applied)
2466  else if(refPoints.rank() == 3) {
2467 
2468  // 1. validate refPoints dimensions and rank
2469  TEUCHOS_TEST_FOR_EXCEPTION( (refPoints.dimension(0) != cellWorkset.dimension(0) ), std::invalid_argument,
2470  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 0 (number of cells) of refPoints and cellWorkset arraya are required to match ");
2471 
2472  TEUCHOS_TEST_FOR_EXCEPTION( (refPoints.dimension(1) <= 0), std::invalid_argument,
2473  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 1 (number of points) >= 1 required for refPoints array ");
2474 
2475  TEUCHOS_TEST_FOR_EXCEPTION( (refPoints.dimension(2) != (int)cellTopo.getDimension() ), std::invalid_argument,
2476  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): dim 2 (spatial dimension) of refPoints array does not match cell dimension");
2477 
2478  // 2. whichCell must be -1
2479  TEUCHOS_TEST_FOR_EXCEPTION( (whichCell != -1), std::invalid_argument,
2480  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): default value is required for rank-3 refPoints array");
2481 
2482  // 3. physPoints must match rank and dimensions of refPoints
2483  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankMatch(errmsg, refPoints, physPoints), std::invalid_argument, errmsg );
2484  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, refPoints, physPoints), std::invalid_argument, errmsg);
2485  }
2486  // if rank is not 2 or 3 throw exception
2487  else {
2488  TEUCHOS_TEST_FOR_EXCEPTION( !( (refPoints.rank() == 2) || (refPoints.rank() == 3) ), std::invalid_argument,
2489  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToPhysicalFrame): rank = 2 or 3 required for refPoints array");
2490  }
2491 }
2492 
2493 
2494 
2495 template<class Scalar>
2496 template<class ArrayRefPoint, class ArrayPhysPoint, class ArrayCell>
2498  const ArrayPhysPoint & physPoints,
2499  const ArrayCell & cellWorkset,
2500  const shards::CellTopology & cellTopo,
2501  const int& whichCell)
2502 {
2503  std::string errmsg = ">>> ERROR (Intrepid::CellTools::validateArguments_mapToReferenceFrame):";
2504  std::string errmsg1 = ">>> ERROR (Intrepid::CellTools::validateArguments_mapToReferenceFrame):";
2505 
2506  // Validate cellWorkset array
2507  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.rank() != 3), std::invalid_argument,
2508  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToReferenceFrame): rank = 3 required for cellWorkset array");
2509 
2510  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(0) <= 0), std::invalid_argument,
2511  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToReferenceFrame): dim 0 (number of cells) >= 1 required for cellWorkset array");
2512 
2513  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(1) != (int)cellTopo.getSubcellCount(0) ), std::invalid_argument,
2514  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToReferenceFrame): dim 1 (number of cell nodes) of cellWorkset array does not match cell topology");
2515 
2516  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(2) != (int)cellTopo.getDimension() ), std::invalid_argument,
2517  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToReferenceFrame): dim 2 (spatial dimension) of cellWorkset array does not match cell dimension");
2518 
2519  // Validate whichCell. It can be either -1 (default value) or a valid cell ordinal.
2520  TEUCHOS_TEST_FOR_EXCEPTION( !( ( (0 <= whichCell ) && (whichCell < cellWorkset.dimension(0) ) ) || (whichCell == -1) ), std::invalid_argument,
2521  ">>> ERROR (Intrepid::CellTools::validateArguments_mapToReferenceFrame): whichCell = -1 or a valid cell ordinal is required.");
2522 
2523  // Admissible ranks and dimensions of refPoints and physPoints depend on whichCell value:
2524  // default is to map multiple sets of points to multiple sets of points. (C,P,D) arrays required
2525  int validRank;
2526  if(whichCell == -1) {
2527  validRank = 3;
2528  errmsg1 += " default value of whichCell requires rank-3 arrays:";
2529  }
2530  // whichCell is valid cell ordinal => we map single set of pts to a single set of pts. (P,D) arrays required
2531  else{
2532  errmsg1 += " rank-2 arrays required when whichCell is valid cell ordinal";
2533  validRank = 2;
2534  }
2535  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankRange(errmsg1, refPoints, validRank,validRank), std::invalid_argument, errmsg1);
2536  TEUCHOS_TEST_FOR_EXCEPTION( !requireRankMatch(errmsg1, physPoints, refPoints), std::invalid_argument, errmsg1);
2537  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg1, refPoints, physPoints), std::invalid_argument, errmsg1);
2538 }
2539 
2540 
2541 
2542 template<class Scalar>
2543 template<class ArrayRefPoint, class ArrayInitGuess, class ArrayPhysPoint, class ArrayCell>
2545  const ArrayInitGuess & initGuess,
2546  const ArrayPhysPoint & physPoints,
2547  const ArrayCell & cellWorkset,
2548  const shards::CellTopology & cellTopo,
2549  const int& whichCell)
2550 {
2551  // Call the method that validates arguments with the default initial guess selection
2552  validateArguments_mapToReferenceFrame(refPoints, physPoints, cellWorkset, cellTopo, whichCell);
2553 
2554  // Then check initGuess: its rank and dimensions must match those of physPoints.
2555  std::string errmsg = ">>> ERROR (Intrepid::CellTools::validateArguments_mapToReferenceFrame):";
2556  TEUCHOS_TEST_FOR_EXCEPTION( !requireDimensionMatch(errmsg, initGuess, physPoints), std::invalid_argument, errmsg);
2557 }
2558 
2559 
2560 template<class Scalar>
2561 template<class ArrayIncl, class ArrayPoint, class ArrayCell>
2563  const ArrayPoint & physPoints,
2564  const ArrayCell & cellWorkset,
2565  const int & whichCell,
2566  const shards::CellTopology & cell)
2567 {
2568  // Validate cellWorkset array
2569  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.rank() != 3), std::invalid_argument,
2570  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): rank = 3 required for cellWorkset array");
2571 
2572  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(0) <= 0), std::invalid_argument,
2573  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 0 (number of cells) >= 1 required for cellWorkset array");
2574 
2575  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(1) != (int)cell.getSubcellCount(0) ), std::invalid_argument,
2576  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 1 (number of cell nodes) of cellWorkset array does not match cell topology");
2577 
2578  TEUCHOS_TEST_FOR_EXCEPTION( (cellWorkset.dimension(2) != (int)cell.getDimension() ), std::invalid_argument,
2579  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 2 (spatial dimension) of cellWorkset array does not match cell dimension");
2580 
2581 
2582  // Validate whichCell It can be either -1 (default value) or a valid cell ordinal.
2583  TEUCHOS_TEST_FOR_EXCEPTION( !( ( (0 <= whichCell ) && (whichCell < cellWorkset.dimension(0) ) ) || (whichCell == -1) ), std::invalid_argument,
2584  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): whichCell = -1 or a valid cell ordinal is required.");
2585 
2586 
2587  // Validate points array: can be rank-2 (P,D) or rank-3 (C,P,D)
2588  // If rank-2: admissible inCell is rank-1 (P); admissible whichCell is valid cell ordinal but not -1.
2589  if(physPoints.rank() == 2) {
2590 
2591  TEUCHOS_TEST_FOR_EXCEPTION( (whichCell == -1), std::invalid_argument,
2592  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): whichCell = a valid cell ordinal is required with rank-2 input array.");
2593 
2594  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.dimension(0) <= 0), std::invalid_argument,
2595  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 0 (number of points) >= 1 required for physPoints array ");
2596 
2597  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.dimension(1) != (int)cell.getDimension() ), std::invalid_argument,
2598  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 1 (spatial dimension) of physPoints array does not match cell dimension");
2599 
2600  // Validate inCell
2601  TEUCHOS_TEST_FOR_EXCEPTION( (inCell.rank() != 1), std::invalid_argument,
2602  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): rank = 1 required for inCell array");
2603 
2604  TEUCHOS_TEST_FOR_EXCEPTION( (inCell.dimension(0) != physPoints.dimension(0)), std::invalid_argument,
2605  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 0 (number of points) of inCell array must equal dim 0 of physPoints array");
2606  }
2607  // If rank-3: admissible inCell is rank-2 (C,P); admissible whichCell = -1.
2608  else if (physPoints.rank() == 3){
2609 
2610  TEUCHOS_TEST_FOR_EXCEPTION( !(whichCell == -1), std::invalid_argument,
2611  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): whichCell = -1 is required with rank-3 input array.");
2612 
2613  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.dimension(0) != cellWorkset.dimension(0) ), std::invalid_argument,
2614  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 0 (number of cells) of physPoints array must equal dim 0 of cellWorkset array ");
2615 
2616  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.dimension(1) <= 0), std::invalid_argument,
2617  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 1 (number of points) >= 1 required for physPoints array ");
2618 
2619  TEUCHOS_TEST_FOR_EXCEPTION( (physPoints.dimension(2) != (int)cell.getDimension() ), std::invalid_argument,
2620  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 2 (spatial dimension) of physPoints array does not match cell dimension");
2621 
2622  // Validate inCell
2623  TEUCHOS_TEST_FOR_EXCEPTION( (inCell.rank() != 2), std::invalid_argument,
2624  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): rank = 2 required for inCell array");
2625 
2626  TEUCHOS_TEST_FOR_EXCEPTION( (inCell.dimension(0) != physPoints.dimension(0)), std::invalid_argument,
2627  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 0 (number of cells) of inCell array must equal dim 0 of physPoints array");
2628 
2629  TEUCHOS_TEST_FOR_EXCEPTION( (inCell.dimension(1) != physPoints.dimension(1)), std::invalid_argument,
2630  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): dim 1 (number of points) of inCell array must equal dim 1 of physPoints array");
2631  }
2632  else {
2633  TEUCHOS_TEST_FOR_EXCEPTION( !( (physPoints.rank() == 2) && (physPoints.rank() ==3) ), std::invalid_argument,
2634  ">>> ERROR (Intrepid::CellTools::validateArguments_checkPointwiseInclusion): rank = 2 or 3 required for points array");
2635  }
2636 }
2637 
2638 
2639 
2640 //============================================================================================//
2641 // //
2642 // Debug //
2643 // //
2644 //============================================================================================//
2645 
2646 
2647 template<class Scalar>
2649  const int subcellOrd,
2650  const shards::CellTopology & parentCell){
2651 
2652  // Get number of vertices for the specified subcell and parent cell dimension
2653  int subcVertexCount = parentCell.getVertexCount(subcellDim, subcellOrd);
2654  int cellDim = parentCell.getDimension();
2655 
2656  // Allocate space for the subcell vertex coordinates
2657  FieldContainer<double> subcellVertices(subcVertexCount, cellDim);
2658 
2659  // Retrieve the vertex coordinates
2660  getReferenceSubcellVertices(subcellVertices,
2661  subcellDim,
2662  subcellOrd,
2663  parentCell);
2664 
2665  // Print the vertices
2666  std::cout
2667  << " Subcell " << std::setw(2) << subcellOrd
2668  << " is " << parentCell.getName(subcellDim, subcellOrd) << " with vertices = {";
2669 
2670  // Loop over subcell vertices
2671  for(int subcVertOrd = 0; subcVertOrd < subcVertexCount; subcVertOrd++){
2672  std::cout<< "(";
2673 
2674  // Loop over vertex Cartesian coordinates
2675  for(int dim = 0; dim < (int)parentCell.getDimension(); dim++){
2676  std::cout << subcellVertices(subcVertOrd, dim);
2677  if(dim < (int)parentCell.getDimension()-1 ) { std::cout << ","; }
2678  }
2679  std::cout<< ")";
2680  if(subcVertOrd < subcVertexCount - 1) { std::cout << ", "; }
2681  }
2682  std::cout << "}\n";
2683 }
2684 
2685 
2686 template<class Scalar>
2687 template<class ArrayCell>
2688 void CellTools<Scalar>::printWorksetSubcell(const ArrayCell & cellWorkset,
2689  const shards::CellTopology & parentCell,
2690  const int& pCellOrd,
2691  const int& subcellDim,
2692  const int& subcellOrd,
2693  const int& fieldWidth){
2694 
2695  // Get the ordinals, relative to reference cell, of subcell cellWorkset
2696  int subcNodeCount = parentCell.getNodeCount(subcellDim, subcellOrd);
2697  int pCellDim = parentCell.getDimension();
2698  std::vector<int> subcNodeOrdinals(subcNodeCount);
2699 
2700  for(int i = 0; i < subcNodeCount; i++){
2701  subcNodeOrdinals[i] = parentCell.getNodeMap(subcellDim, subcellOrd, i);
2702  }
2703 
2704  // Loop over parent cells and print subcell cellWorkset
2705 
2706  std::cout
2707  << " Subcell " << subcellOrd << " on parent cell " << pCellOrd << " is "
2708  << parentCell.getName(subcellDim, subcellOrd) << " with node(s) \n ({";
2709 
2710  for(int i = 0; i < subcNodeCount; i++){
2711 
2712  // print Cartesian coordinates of the node
2713  for(int dim = 0; dim < pCellDim; dim++){
2714  std::cout
2715  << std::setw(fieldWidth) << std::right << cellWorkset(pCellOrd, subcNodeOrdinals[i], dim);
2716  if(dim < pCellDim - 1){ std::cout << ","; }
2717  }
2718  std::cout << "}";
2719  if(i < subcNodeCount - 1){ std::cout <<", {"; }
2720  }
2721  std::cout << ")\n\n";
2722 }
2723 
2724 
2725 
2726 } // namespace Intrepid
2727 #endif
int size() const
Returns size of the FieldContainer defined as the product of its dimensions.
static const double * getReferenceNode(const shards::CellTopology &cell, const int nodeOrd)
Retrieves the Cartesian coordinates of a reference cell node.
static void validateArguments_mapToReferenceFrame(const ArrayRefPoint &refPoints, const ArrayPhysPoint &physPoints, const ArrayCell &cellWorkset, const shards::CellTopology &cellTopo, const int &whichCell)
Validates arguments to Intrepid::CellTools::mapToReferenceFrame with default initial guess...
static void getReferenceEdgeTangent(ArrayEdgeTangent &refEdgeTangent, const int &edgeOrd, const shards::CellTopology &parentCell)
Computes constant tangent vectors to edges of 2D or 3D reference cells.
static void mapToReferenceSubcell(ArraySubcellPoint &refSubcellPoints, const ArrayParamPoint &paramPoints, const int subcellDim, const int subcellOrd, const shards::CellTopology &parentCell)
Computes parameterization maps of 1- and 2-subcells of reference cells.
static void matvec(Scalar *matVec, const Scalar *inMat, const Scalar *inVec, const int dim)
Matrix-vector left multiply using contiguous data: matVec = inMat * inVec.
Implementation of the default H(grad)-compatible FEM basis of degree 1 on Wedge cell.
static void getPhysicalFaceNormals(ArrayFaceNormal &faceNormals, const ArrayJac &worksetJacobians, const int &worksetFaceOrd, const shards::CellTopology &parentCell)
Computes non-normalized normal vectors to physical faces in a face workset ; (see Subcell worksets fo...
static void setJacobianInv(ArrayJacInv &jacobianInv, const ArrayJac &jacobian)
Computes the inverse of the Jacobian matrix DF of the reference-to-physical frame map F...
Implementation of the default H(grad)-compatible FEM basis of degree 2 on Wedge cell.
static void getPhysicalEdgeTangents(ArrayEdgeTangent &edgeTangents, const ArrayJac &worksetJacobians, const int &worksetEdgeOrd, const shards::CellTopology &parentCell)
Computes non-normalized tangent vectors to physical edges in an edge workset ; (see Subcell worksets ...
static void mapToReferenceFrame(ArrayRefPoint &refPoints, const ArrayPhysPoint &physPoints, const ArrayCell &cellWorkset, const shards::CellTopology &cellTopo, const int &whichCell=-1)
Computes , the inverse of the reference-to-physical frame map using a default initial guess...
#define INTREPID_MAX_NEWTON
Maximum number of Newton iterations used internally in methods such as computing the action of the in...
static void getReferenceSideNormal(ArraySideNormal &refSideNormal, const int &sideOrd, const shards::CellTopology &parentCell)
Computes constant normal vectors to sides of 2D or 3D reference cells.
static void getReferenceFaceTangents(ArrayFaceTangentU &refFaceTanU, ArrayFaceTangentV &refFaceTanV, const int &faceOrd, const shards::CellTopology &parentCell)
Computes pairs of constant tangent vectors to faces of a 3D reference cells.
int dimension(const int whichDim) const
Returns the specified dimension.
Implementation of the default H(grad)-compatible FEM basis of degree 2 on Hexahedron cell...
static void printSubcellVertices(const int subcellDim, const int subcellOrd, const shards::CellTopology &parentCell)
Prints the reference space coordinates of the vertices of the specified subcell.
static void add(Scalar *sumArray, const Scalar *inArray1, const Scalar *inArray2, const int size)
Adds contiguous data inArray1 and inArray2 of size size: sumArray = inArray1 + inArray2.
static void getReferenceFaceNormal(ArrayFaceNormal &refFaceNormal, const int &faceOrd, const shards::CellTopology &parentCell)
Computes constant normal vectors to faces of 3D reference cell.
Implementation of the default H(grad)-compatible FEM basis of degree 1 on Line cell.
static void mapToPhysicalFrame(ArrayPhysPoint &physPoints, const ArrayRefPoint &refPoints, const ArrayCell &cellWorkset, const shards::CellTopology &cellTopo, const int &whichCell=-1)
Computes F, the reference-to-physical frame map.
Implementation of the default H(grad)-compatible FEM basis of degree 1 on Triangle cell...
static void getReferenceSubcellVertices(ArraySubcellVert &subcellVertices, const int subcellDim, const int subcellOrd, const shards::CellTopology &parentCell)
Retrieves the Cartesian coordinates of all vertices of a reference subcell.
static void getPhysicalSideNormals(ArraySideNormal &sideNormals, const ArrayJac &worksetJacobians, const int &worksetSideOrd, const shards::CellTopology &parentCell)
Computes non-normalized normal vectors to physical sides in a side workset .
static int checkPointsetInclusion(const ArrayPoint &points, const shards::CellTopology &cellTopo, const double &threshold=INTREPID_THRESHOLD)
Checks if a set of points belongs to a reference cell.
static int hasReferenceCell(const shards::CellTopology &cellTopo)
Checks if a cell topology has reference cell.
Implementation of the default H(grad)-compatible FEM basis of degree 1 on Quadrilateral cell...
Implementation of the default H(grad)-compatible FEM basis of degree 2 on Tetrahedron cell...
static void mapToReferenceFrameInitGuess(ArrayRefPoint &refPoints, const ArrayInitGuess &initGuess, const ArrayPhysPoint &physPoints, const ArrayCell &cellWorkset, const shards::CellTopology &cellTopo, const int &whichCell=-1)
Computation of , the inverse of the reference-to-physical frame map using user-supplied initial guess...
static void setSubcellParametrization(FieldContainer< double > &subcellParametrization, const int subcellDim, const shards::CellTopology &parentCell)
Defines orientation-preserving parametrizations of reference edges and faces of cell topologies with ...
static void getReferenceSubcellNodes(ArraySubcellNode &subcellNodes, const int subcellDim, const int subcellOrd, const shards::CellTopology &parentCell)
Retrieves the Cartesian coordinates of all nodes of a reference subcell.
static int checkPointInclusion(const Scalar *point, const int pointDim, const shards::CellTopology &cellTopo, const double &threshold=INTREPID_THRESHOLD)
Checks if a point belongs to a reference cell.
static const double * getReferenceVertex(const shards::CellTopology &cell, const int vertexOrd)
Retrieves the Cartesian coordinates of a reference cell vertex.
static void printWorksetSubcell(const ArrayCell &cellWorkset, const shards::CellTopology &parentCell, const int &pCellOrd, const int &subcellDim, const int &subcellOrd, const int &fieldWidth=3)
Prints the nodes of a subcell from a cell workset.
static Scalar vectorNorm(const Scalar *inVec, const int dim, const ENorm normType)
Computes norm (1, 2, infinity) of the vector inVec of size dim.
static void inverse(Scalar *inverseMat, const Scalar *inMat, const int dim)
Computes inverse of the square matrix inMat of size dim by dim.
static void validateArguments_checkPointwiseInclusion(ArrayIncl &inCell, const ArrayPoint &physPoints, const ArrayCell &cellWorkset, const int &whichCell, const shards::CellTopology &cell)
Validates arguments to Intrepid::CellTools::checkPointwiseInclusion.
Implementation of the default H(grad)-compatible FEM basis of degree 2 on Quadrilateral cell...
void resize(const int dim0)
Resizes FieldContainer to a rank-1 container with the specified dimension, initialized by 0...
static void validateArguments_setJacobianDetArgs(const ArrayJacDet &jacobianDet, const ArrayJac &jacobian)
Validates arguments to Intrepid::CellTools::setJacobianDet.
static void vecprod(ArrayVecProd &vecProd, const ArrayIn1 &inLeft, const ArrayIn2 &inRight)
Vector product using multidimensional arrays: vecProd = inVecLeft x inVecRight
Implementation of the default H(grad)-compatible FEM basis of degree 1 on Hexahedron cell...
static void validateArguments_setJacobianInv(const ArrayJacInv &jacobianInv, const ArrayJac &jacobian)
Validates arguments to Intrepid::CellTools::setJacobianInv.
static void validateArguments_mapToPhysicalFrame(const ArrayPhysPoint &physPoints, const ArrayRefPoint &refPoints, const ArrayCell &cellWorkset, const shards::CellTopology &cellTopo, const int &whichCell)
Validates arguments to Intrepid::CellTools::mapToPhysicalFrame.
static void checkPointwiseInclusion(ArrayIncl &inRefCell, const ArrayPoint &points, const shards::CellTopology &cellTopo, const double &threshold=INTREPID_THRESHOLD)
Checks every point in a set for inclusion in a reference cell.
static void validateArguments_setJacobian(const ArrayJac &jacobian, const ArrayPoint &points, const ArrayCell &cellWorkset, const int &whichCell, const shards::CellTopology &cellTopo)
Validates arguments to Intrepid::CellTools::setJacobian.
static void setJacobian(ArrayJac &jacobian, const ArrayPoint &points, const ArrayCell &cellWorkset, const shards::CellTopology &cellTopo, const int &whichCell=-1)
Computes the Jacobian matrix DF of the reference-to-physical frame map F.
static void subtract(Scalar *diffArray, const Scalar *inArray1, const Scalar *inArray2, const int size)
Subtracts contiguous data inArray2 from inArray1 of size size: diffArray = inArray1 - inArray2...
static const FieldContainer< double > & getSubcellParametrization(const int subcellDim, const shards::CellTopology &parentCell)
Returns array with the coefficients of the parametrization maps for the edges or faces of a reference...
static void setJacobianDet(ArrayJacDet &jacobianDet, const ArrayJac &jacobian)
Computes the determinant of the Jacobian matrix DF of the reference-to-physical frame map F...
static Scalar det(const Scalar *inMat, const int dim)
Computes determinant of the square matrix inMat of size dim by dim.
static void getPhysicalFaceTangents(ArrayFaceTangentU &faceTanU, ArrayFaceTangentV &faceTanV, const ArrayJac &worksetJacobians, const int &worksetFaceOrd, const shards::CellTopology &parentCell)
Computes non-normalized tangent vector pairs to physical faces in a face workset ; (see Subcell works...
Implementation of the default H(grad)-compatible FEM basis of degree 2 on Triangle cell...
Implementation of the default H(grad)-compatible FEM basis of degree 1 on Tetrahedron cell...