Intrepid
test_02.cpp
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 #include "Intrepid_CellTools.hpp"
52 #include "Shards_CellTopology.hpp"
53 
54 #include "Teuchos_oblackholestream.hpp"
55 #include "Teuchos_RCP.hpp"
56 #include "Teuchos_GlobalMPISession.hpp"
57 #include "Teuchos_ScalarTraits.hpp"
58 
59 using namespace std;
60 using namespace Intrepid;
61 using namespace shards;
62 
63 #define INTREPID_TEST_COMMAND( S , throwCounter, nException ) \
64 { \
65  ++nException; \
66  try { \
67  S ; \
68  } \
69  catch (std::logic_error err) { \
70  ++throwCounter; \
71  *outStream << "Expected Error " << nException << " -------------------------------------------------------------\n"; \
72  *outStream << err.what() << '\n'; \
73  *outStream << "-------------------------------------------------------------------------------" << "\n\n"; \
74  }; \
75 }
76 
77 
78 
79 int main(int argc, char *argv[]) {
80 
81  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
82 
84  typedef shards::CellTopology CellTopology;
85 
86  // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
87  int iprint = argc - 1;
88 
89  Teuchos::RCP<std::ostream> outStream;
90  Teuchos::oblackholestream bhs; // outputs nothing
91 
92  if (iprint > 0)
93  outStream = Teuchos::rcp(&std::cout, false);
94  else
95  outStream = Teuchos::rcp(&bhs, false);
96 
97  // Save the format state of the original std::cout.
98  Teuchos::oblackholestream oldFormatState;
99  oldFormatState.copyfmt(std::cout);
100 
101  *outStream \
102  << "===============================================================================\n" \
103  << "| |\n" \
104  << "| Unit Test CellTools |\n" \
105  << "| |\n" \
106  << "| 1) Mapping to and from reference cells with base and extended topologies|\n" \
107  << "| using default initial guesses when computing the inverse F^{-1} |\n" \
108  << "| 2) Repeat all tests from 1) using user-defined initial guess for F^{-1} |\n" \
109  << "| 3) Exception testing |\n" \
110  << "| |\n" \
111  << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov) |\n" \
112  << "| Denis Ridzal (dridzal@sandia.gov), or |\n" \
113  << "| Kara Peterson (kjpeter@sandia.gov) |\n" \
114  << "| |\n" \
115  << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
116  << "| Trilinos website: http://trilinos.sandia.gov |\n" \
117  << "| |\n" \
118  << "===============================================================================\n";
119 
120  int errorFlag = 0;
121 
122  // Collect all supported cell topologies
123  std::vector<shards::CellTopology> supportedTopologies;
124  supportedTopologies.push_back(shards::getCellTopologyData<Triangle<3> >() );
125  supportedTopologies.push_back(shards::getCellTopologyData<Triangle<6> >() );
126  supportedTopologies.push_back(shards::getCellTopologyData<Quadrilateral<4> >() );
127  supportedTopologies.push_back(shards::getCellTopologyData<Quadrilateral<9> >() );
128  supportedTopologies.push_back(shards::getCellTopologyData<Tetrahedron<4> >() );
129  supportedTopologies.push_back(shards::getCellTopologyData<Tetrahedron<10> >() );
130  supportedTopologies.push_back(shards::getCellTopologyData<Hexahedron<8> >() );
131  supportedTopologies.push_back(shards::getCellTopologyData<Hexahedron<27> >() );
132  supportedTopologies.push_back(shards::getCellTopologyData<Wedge<6> >() );
133  supportedTopologies.push_back(shards::getCellTopologyData<Wedge<18> >() );
134 
135  // Declare iterator to loop over the cell topologies
136  std::vector<shards::CellTopology>::iterator topo_iterator;
137 
138  // Test 1 scope
139  try{
140 
141  *outStream \
142  << "\n"
143  << "===============================================================================\n"\
144  << "| Test 1: computing F(x) and F^{-1}(x) using default initial guesses. |\n"\
145  << "===============================================================================\n\n";
146  /*
147  * Test summary:
148  *
149  * A reference point set is mapped to physical frame and then back to reference frame.
150  * Test passes if the final set of points matches the first set of points. The cell workset
151  * is generated by perturbing randomly the cellWorkset of a reference cell with the specified
152  * cell topology.
153  *
154  */
155  // Declare arrays for cell workset and point sets. We will have 10 cells in the wset. and 10 pts per pt. set
156  FieldContainer<double> cellWorkset; // physical cell workset
157  FieldContainer<double> refPoints; // reference point set(s)
158  FieldContainer<double> physPoints; // physical point set(s)
159  FieldContainer<double> controlPoints; // preimages: physical points mapped back to ref. frame
160 
161  // We will use cubature factory to get some points on the reference cells. Declare necessary arrays
162  DefaultCubatureFactory<double> cubFactory;
163  FieldContainer<double> cubPoints;
164  FieldContainer<double> cubWeights;
165 
166  // Initialize number of cells in the cell workset
167  int numCells = 10;
168 
169 
170  // Loop over cell topologies, make cell workset for each one by perturbing the cellWorkset & test methods
171  for(topo_iterator = supportedTopologies.begin(); topo_iterator != supportedTopologies.end(); ++topo_iterator){
172 
173  // 1. Define a single reference point set using cubature factory with order 4 cubature
174  Teuchos::RCP<Cubature<double> > cellCubature = cubFactory.create( (*topo_iterator), 4);
175  int cubDim = cellCubature -> getDimension();
176  int numPts = cellCubature -> getNumPoints();
177  cubPoints.resize(numPts, cubDim);
178  cubWeights.resize(numPts);
179  cellCubature -> getCubature(cubPoints, cubWeights);
180 
181  // 2. Define a cell workset by perturbing the cellWorkset of the reference cell with the specified topology
182  // 2.1 Resize dimensions of the rank-3 (C,N,D) cell workset array for the current topology
183  int numNodes = (*topo_iterator).getNodeCount();
184  int cellDim = (*topo_iterator).getDimension();
185  cellWorkset.resize(numCells, numNodes, cellDim);
186 
187  // 2.2 Copy cellWorkset of the reference cell with the same topology to temp rank-2 (N,D) array
188  FieldContainer<double> refCellNodes(numNodes, cellDim );
189  CellTools::getReferenceSubcellNodes(refCellNodes, cellDim, 0, (*topo_iterator) );
190 
191  // 2.3 Create randomly perturbed version of the reference cell and save in the cell workset array
192  for(int cellOrd = 0; cellOrd < numCells; cellOrd++){
193 
194  // Move vertices +/-0.125 along their axes. Gives nondegenerate cells for base and extended topologies
195  for(int nodeOrd = 0; nodeOrd < numNodes; nodeOrd++){
196  for(int d = 0; d < cellDim; d++){
197  double delta = Teuchos::ScalarTraits<double>::random()/16.0;
198  cellWorkset(cellOrd, nodeOrd, d) = refCellNodes(nodeOrd, d) + delta;
199  } // d
200  }// nodeOrd
201  }// cellOrd
202  /*
203  * 3.1 Test 1: single point set to single physical cell: map ref. point set in rank-2 (P,D) array
204  * to a physical point set in rank-2 (P,D) array for a specified cell ordinal. Use the cub.
205  * points array for this test. Resize physPoints and controlPoints to rank-2 (P,D) arrays.
206  */
207  physPoints.resize(numPts, cubDim);
208  controlPoints.resize(numPts, cubDim);
209 
210  *outStream
211  << " Mapping a set of " << numPts << " points to one cell in a workset of " << numCells << " "
212  << (*topo_iterator).getName() << " cells. \n";
213 
214  for(int cellOrd = 0; cellOrd < numCells; cellOrd++){
215 
216  // Forward map:: requires cell ordinal
217  CellTools::mapToPhysicalFrame(physPoints, cubPoints, cellWorkset, (*topo_iterator), cellOrd);
218  // Inverse map: requires cell ordinal
219  CellTools::mapToReferenceFrame(controlPoints, physPoints, cellWorkset, (*topo_iterator), cellOrd);
220 
221  // Points in controlPoints should match the originals in cubPoints up to a tolerance
222  for(int pt = 0; pt < numPts; pt++){
223  for(int d = 0; d < cellDim; d++){
224 
225  if( abs( controlPoints(pt, d) - cubPoints(pt, d) ) > 100.0*INTREPID_TOL ){
226  errorFlag++;
227  *outStream
228  << std::setw(70) << "^^^^----FAILURE!" << "\n"
229  << " Mapping a single point set to a single physical cell in a workset failed for: \n"
230  << " Cell Topology = " << (*topo_iterator).getName() << "\n"
231  << " Physical cell ordinal in workset = " << cellOrd << "\n"
232  << " Reference point ordinal = " << setprecision(12) << pt << "\n"
233  << " At reference point coordinate = " << setprecision(12) << d << "\n"
234  << " Original value = " << cubPoints(pt, d) << "\n"
235  << " F^{-1}F(P_d) = " << controlPoints(pt, d) <<"\n";
236  }
237  }// d
238  }// pt
239  }// cellOrd
240  /*
241  * 3.2 Test 2: single point set to multiple physical cells: map ref. point set in rank-2 (P,D) array
242  * to a physical point set in rank-3 (C, P,D) array for all cell ordinals. Use the cub.
243  * points array for this test. Resize physPoints and controlPoints to rank-3 (C,P,D) arrays.
244  */
245  physPoints.clear();
246  controlPoints.clear();
247  physPoints.resize(numCells, numPts, cubDim);
248  controlPoints.resize(numCells, numPts, cubDim);
249 
250  *outStream
251  << " Mapping a set of " << numPts << " points to all cells in workset of " << numCells << " "
252  << (*topo_iterator).getName() << " cells. \n";
253 
254  // Forward map: do not specify cell ordinal
255  CellTools::mapToPhysicalFrame(physPoints, cubPoints, cellWorkset, (*topo_iterator));
256  // Inverse map: do not specify cell ordinal
257  CellTools::mapToReferenceFrame(controlPoints, physPoints, cellWorkset, (*topo_iterator));
258 
259  // Check: points in controlPoints should match the originals in cubPoints up to a tolerance
260  for(int cellOrd = 0; cellOrd < numCells; cellOrd++){
261  for(int pt = 0; pt < numPts; pt++){
262  for(int d = 0; d < cellDim; d++){
263 
264  if( abs( controlPoints(cellOrd, pt, d) - cubPoints(pt, d) ) > 100.0*INTREPID_TOL ){
265  errorFlag++;
266  *outStream
267  << std::setw(70) << "^^^^----FAILURE!" << "\n"
268  << " Mapping a single point set to all physical cells in a workset failed for: \n"
269  << " Cell Topology = " << (*topo_iterator).getName() << "\n"
270  << " Physical cell ordinal in workset = " << cellOrd << "\n"
271  << " Reference point ordinal = " << setprecision(12) << pt << "\n"
272  << " At reference point coordinate = " << setprecision(12) << d << "\n"
273  << " Original value = " << cubPoints(pt, d) << "\n"
274  << " F^{-1}F(P_d) = " << controlPoints(cellOrd, pt, d) <<"\n";
275  }
276  }// d
277  }// pt
278  }// cellOrd
279  /*
280  * 3.3 Test 3: multiple point sets to multiple physical cells: map ref. point sets in rank-3 (C,P,D) array
281  * to physical point sets in rank-3 (C, P,D) array for all cell ordinals. The (C,P,D) array
282  * with reference point sets is obtained by cloning the cubature point array.
283  */
284  physPoints.clear();
285  controlPoints.clear();
286  refPoints.resize(numCells, numPts, cubDim);
287  physPoints.resize(numCells, numPts, cubDim);
288  controlPoints.resize(numCells, numPts, cubDim);
289 
290  // Clone cubature points in refPoints:
291  for(int c = 0; c < numCells; c++){
292  for(int pt = 0; pt < numPts; pt++){
293  for(int d = 0; d < cellDim; d++){
294  refPoints(c, pt, d) = cubPoints(pt, d);
295  }// d
296  }// pt
297  }// c
298 
299  *outStream
300  << " Mapping " << numCells << " sets of " << numPts << " points to corresponding cells in workset of " << numCells << " "
301  << (*topo_iterator).getName() << " cells. \n";
302 
303  // Forward map: do not specify cell ordinal
304  CellTools::mapToPhysicalFrame(physPoints, refPoints, cellWorkset, (*topo_iterator));
305  // Inverse map: do not specify cell ordinal
306  CellTools::mapToReferenceFrame(controlPoints, physPoints, cellWorkset, (*topo_iterator));
307 
308  // Check: points in controlPoints should match the originals in cubPoints up to a tolerance
309  for(int cellOrd = 0; cellOrd < numCells; cellOrd++){
310  for(int pt = 0; pt < numPts; pt++){
311  for(int d = 0; d < cellDim; d++){
312 
313  if( abs( controlPoints(cellOrd, pt, d) - cubPoints(pt, d) ) > 100.0*INTREPID_TOL ){
314  errorFlag++;
315  *outStream
316  << std::setw(70) << "^^^^----FAILURE!" << "\n"
317  << " Mapping multiple point sets to corresponding physical cells in a workset failed for: \n"
318  << " Cell Topology = " << (*topo_iterator).getName() << "\n"
319  << " Physical cell ordinal in workset = " << cellOrd << "\n"
320  << " Reference point ordinal = " << setprecision(12) << pt << "\n"
321  << " At reference point coordinate = " << setprecision(12) << d << "\n"
322  << " Original value = " << refPoints(cellOrd, pt, d) << "\n"
323  << " F^{-1}F(P_d) = " << controlPoints(cellOrd, pt, d) <<"\n";
324  }
325  }// d
326  }// pt
327  }// cellOrd
328  }// topo_iterator
329  }// try using default initial guesses branch
330 
331  /*************************************************************************************************
332  * Wrap up test: check if the test broke down unexpectedly due to an exception *
333  ************************************************************************************************/
334 
335  catch (std::logic_error err) {
336  *outStream << err.what() << "\n";
337  errorFlag = -1000;
338  };
339 
340 
341  // Test 2: repeat all of the above using the original points as user-defined initial guess
342  try{
343 
344  *outStream \
345  << "\n"
346  << "===============================================================================\n"\
347  << "| Test 2: computing F(x) and F^{-1}(x) using user-defined initial guess. |\n"\
348  << "===============================================================================\n\n";
349  /*
350  * Test summary:
351  *
352  * Repeats all parts of Test 1 using user-defined initial guesses in the computation of F^{-1}.
353  * The guesses are simply the exact solutions (the original set of points we started with)
354  * and so, this tests runs much faster because Newton converges in a single iteration.
355  *
356  */
357 
358  // Declare arrays for cell workset and point sets. We will have 10 cells in the wset. and 10 pts per pt. set
359  FieldContainer<double> cellWorkset; // physical cell workset
360  FieldContainer<double> physPoints; // physical point set(s)
361  FieldContainer<double> controlPoints; // preimages: physical points mapped back to ref. frame
362  FieldContainer<double> initialGuess; // User-defined initial guesses for F^{-1}
363 
364  // We will use cubature factory to get some points on the reference cells. Declare necessary arrays
365  DefaultCubatureFactory<double> cubFactory;
366  FieldContainer<double> cubPoints;
367  FieldContainer<double> cubWeights;
368 
369  // Initialize number of cells in the cell workset
370  int numCells = 10;
371 
372 
373  // Loop over cell topologies, make cell workset for each one by perturbing the cellWorkset & test methods
374  for(topo_iterator = supportedTopologies.begin(); topo_iterator != supportedTopologies.end(); ++topo_iterator){
375 
376  // 1. Define a single reference point set using cubature factory with order 6 cubature
377  Teuchos::RCP<Cubature<double> > cellCubature = cubFactory.create( (*topo_iterator), 4);
378  int cubDim = cellCubature -> getDimension();
379  int numPts = cellCubature -> getNumPoints();
380  cubPoints.resize(numPts, cubDim);
381  cubWeights.resize(numPts);
382  cellCubature -> getCubature(cubPoints, cubWeights);
383 
384  // 2. Define a cell workset by perturbing the cellWorkset of the reference cell with the specified topology
385  // 2.1 Resize dimensions of the rank-3 (C,N,D) cell workset array for the current topology
386  int numNodes = (*topo_iterator).getNodeCount();
387  int cellDim = (*topo_iterator).getDimension();
388  cellWorkset.resize(numCells, numNodes, cellDim);
389 
390  // 2.2 Copy cellWorkset of the reference cell with the same topology to temp rank-2 (N,D) array
391  FieldContainer<double> refCellNodes(numNodes, cellDim );
392  CellTools::getReferenceSubcellNodes(refCellNodes, cellDim, 0, (*topo_iterator) );
393 
394  // 2.3 Create randomly perturbed version of the reference cell and save in the cell workset array
395  for(int cellOrd = 0; cellOrd < numCells; cellOrd++){
396 
397  // Move vertices +/-0.125 along their axes. Gives nondegenerate cells for base and extended topologies
398  for(int nodeOrd = 0; nodeOrd < numNodes; nodeOrd++){
399  for(int d = 0; d < cellDim; d++){
400  double delta = Teuchos::ScalarTraits<double>::random()/16.0;
401  cellWorkset(cellOrd, nodeOrd, d) = refCellNodes(nodeOrd, d) + delta;
402  } // d
403  }// nodeOrd
404  }// cellOrd
405  /*
406  * 3.1 Test 1: single point set to single physical cell: map ref. point set in rank-2 (P,D) array
407  * to a physical point set in rank-2 (P,D) array for a specified cell ordinal. Use the cub.
408  * points array for this test. Resize physPoints and controlPoints to rank-2 (P,D) arrays.
409  */
410  physPoints.resize(numPts, cubDim);
411  controlPoints.resize(numPts, cubDim);
412 
413  *outStream
414  << " Mapping a set of " << numPts << " points to one cell in a workset of " << numCells << " "
415  << (*topo_iterator).getName() << " cells. \n";
416 
417  for(int cellOrd = 0; cellOrd < numCells; cellOrd++){
418 
419  // Forward map:: requires cell ordinal
420  CellTools::mapToPhysicalFrame(physPoints, cubPoints, cellWorkset, (*topo_iterator), cellOrd);
421  // Inverse map: requires cell ordinal. Use cubPoints as initial guess
422  CellTools::mapToReferenceFrameInitGuess(controlPoints, cubPoints, physPoints, cellWorkset, (*topo_iterator), cellOrd);
423 
424  // Points in controlPoints should match the originals in cubPoints up to a tolerance
425  for(int pt = 0; pt < numPts; pt++){
426  for(int d = 0; d < cellDim; d++){
427 
428  if( abs( controlPoints(pt, d) - cubPoints(pt, d) ) > 100.0*INTREPID_TOL ){
429  errorFlag++;
430  *outStream
431  << std::setw(70) << "^^^^----FAILURE!" << "\n"
432  << " Mapping a single point set to a single physical cell in a workset failed for: \n"
433  << " Cell Topology = " << (*topo_iterator).getName() << "\n"
434  << " Physical cell ordinal in workset = " << cellOrd << "\n"
435  << " Reference point ordinal = " << setprecision(12) << pt << "\n"
436  << " At reference point coordinate = " << setprecision(12) << d << "\n"
437  << " Original value = " << cubPoints(pt, d) << "\n"
438  << " F^{-1}F(P_d) = " << controlPoints(pt, d) <<"\n";
439  }
440  }// d
441  }// pt
442  }// cellOrd
443  /*
444  * 3.2 Test 2: single point set to multiple physical cells: map ref. point set in rank-2 (P,D) array
445  * to a physical point set in rank-3 (C, P,D) array for all cell ordinals. Use the cub.
446  * points array for this test. Resize physPoints and controlPoints to rank-3 (C,P,D) arrays.
447  */
448  physPoints.clear();
449  controlPoints.clear();
450  physPoints.resize(numCells, numPts, cubDim);
451  controlPoints.resize(numCells, numPts, cubDim);
452 
453  // Clone cubature points in initialGuess:
454  initialGuess.resize(numCells, numPts, cubDim);
455  for(int c = 0; c < numCells; c++){
456  for(int pt = 0; pt < numPts; pt++){
457  for(int d = 0; d < cellDim; d++){
458  initialGuess(c, pt, d) = cubPoints(pt, d);
459  }// d
460  }// pt
461  }// c
462 
463  *outStream
464  << " Mapping a set of " << numPts << " points to all cells in workset of " << numCells << " "
465  << (*topo_iterator).getName() << " cells. \n";
466 
467  // Forward map: do not specify cell ordinal
468  CellTools::mapToPhysicalFrame(physPoints, cubPoints, cellWorkset, (*topo_iterator));
469  // Inverse map: do not specify cell ordinal
470  CellTools::mapToReferenceFrameInitGuess(controlPoints, initialGuess, physPoints, cellWorkset, (*topo_iterator));
471 
472  // Check: points in controlPoints should match the originals in cubPoints up to a tolerance
473  for(int cellOrd = 0; cellOrd < numCells; cellOrd++){
474  for(int pt = 0; pt < numPts; pt++){
475  for(int d = 0; d < cellDim; d++){
476 
477  if( abs( controlPoints(cellOrd, pt, d) - cubPoints(pt, d) ) > 100.0*INTREPID_TOL ){
478  errorFlag++;
479  *outStream
480  << std::setw(70) << "^^^^----FAILURE!" << "\n"
481  << " Mapping a single point set to all physical cells in a workset failed for: \n"
482  << " Cell Topology = " << (*topo_iterator).getName() << "\n"
483  << " Physical cell ordinal in workset = " << cellOrd << "\n"
484  << " Reference point ordinal = " << setprecision(12) << pt << "\n"
485  << " At reference point coordinate = " << setprecision(12) << d << "\n"
486  << " Original value = " << cubPoints(pt, d) << "\n"
487  << " F^{-1}F(P_d) = " << controlPoints(cellOrd, pt, d) <<"\n";
488  }
489  }// d
490  }// pt
491  }// cellOrd
492  /*
493  * 3.3 Test 3: multiple point sets to multiple physical cells: map ref. point sets in rank-3 (C,P,D) array
494  * to physical point sets in rank-3 (C, P,D) array for all cell ordinals. The initialGuess
495  * array from last test is used as the required (C,P,D) array of reference points for the
496  * forward map and as the user-defined initial guess array for the inverse map
497  */
498  physPoints.clear();
499  controlPoints.clear();
500  physPoints.resize(numCells, numPts, cubDim);
501  controlPoints.resize(numCells, numPts, cubDim);
502 
503  *outStream
504  << " Mapping " << numCells << " sets of " << numPts << " points to corresponding cells in workset of " << numCells << " "
505  << (*topo_iterator).getName() << " cells. \n";
506 
507  // Forward map: do not specify cell ordinal
508  CellTools::mapToPhysicalFrame(physPoints, initialGuess, cellWorkset, (*topo_iterator));
509  // Inverse map: do not specify cell ordinal
510  CellTools::mapToReferenceFrameInitGuess(controlPoints, initialGuess, physPoints, cellWorkset, (*topo_iterator));
511 
512  // Check: points in controlPoints should match the originals in cubPoints up to a tolerance
513  for(int cellOrd = 0; cellOrd < numCells; cellOrd++){
514  for(int pt = 0; pt < numPts; pt++){
515  for(int d = 0; d < cellDim; d++){
516 
517  if( abs( controlPoints(cellOrd, pt, d) - cubPoints(pt, d) ) > 100.0*INTREPID_TOL ){
518  errorFlag++;
519  *outStream
520  << std::setw(70) << "^^^^----FAILURE!" << "\n"
521  << " Mapping multiple point sets to corresponding physical cells in a workset failed for: \n"
522  << " Cell Topology = " << (*topo_iterator).getName() << "\n"
523  << " Physical cell ordinal in workset = " << cellOrd << "\n"
524  << " Reference point ordinal = " << setprecision(12) << pt << "\n"
525  << " At reference point coordinate = " << setprecision(12) << d << "\n"
526  << " Original value = " << initialGuess(cellOrd, pt, d) << "\n"
527  << " F^{-1}F(P_d) = " << controlPoints(cellOrd, pt, d) <<"\n";
528  }
529  }// d
530  }// pt
531  }// cellOrd
532  } //topo-iterator
533  }// try user-defined initial guess
534 
535  /*************************************************************************************************
536  * Wrap up test: check if the test broke down unexpectedly due to an exception *
537  ************************************************************************************************/
538 
539  catch (std::logic_error err) {
540  *outStream << err.what() << "\n";
541  errorFlag = -1000;
542  };
543 
544  *outStream \
545  << "\n"
546  << "===============================================================================\n"\
547  << "| Test 3: Exception testing - only when HAVE_INTREPID_DEBUG is defined. |\n"\
548  << "===============================================================================\n\n";
549  /*
550  * Test summary:
551  * Calls methods of CellTools class with incorrectly configured arguments. This test is run only
552  * in debug mode because many of the exceptions are checked only in that mode.
553  *
554  */
555 
556  // Initialize throw counter for exception testing
557  int nException = 0;
558  int throwCounter = 0;
559 
560  try {
561 
562 #ifdef HAVE_INTREPID_DEBUG
563  // Some arbitrary dimensions
564  int C = 10;
565  int P = 21;
566  int N;
567  int D;
568  int V;
569 
570  // Array arguments
571  FieldContainer<double> jacobian;
572  FieldContainer<double> jacobianInv;
573  FieldContainer<double> jacobianDet;
574  FieldContainer<double> points;
575  FieldContainer<double> cellWorkset;
576  FieldContainer<double> physPoints;
577  FieldContainer<double> refPoints;
578  FieldContainer<double> initGuess;
579 
580  /***********************************************************************************************
581  * Exception tests for setJacobian method *
582  **********************************************************************************************/
583 
584  // Use the second cell topology for these tests (Triangle<6>)
585  topo_iterator = supportedTopologies.begin() + 1;
586  D = (*topo_iterator).getDimension();
587  N = (*topo_iterator).getNodeCount();
588  V = (*topo_iterator).getVertexCount();
589 
590  // 1. incorrect jacobian rank
591  jacobian.resize(C, P, D);
592  points.resize(P, D);
593  cellWorkset.resize(C, N, D);
594  INTREPID_TEST_COMMAND( CellTools::setJacobian(jacobian, points, cellWorkset, (*topo_iterator) ),
595  throwCounter, nException );
596 
597  // 2. Incorrect cellWorkset rank
598  cellWorkset.resize(C, D);
599  INTREPID_TEST_COMMAND( CellTools::setJacobian(jacobian, points, cellWorkset, (*topo_iterator) ),
600  throwCounter, nException );
601 
602  // 3. Incorrect points rank
603  cellWorkset.resize(C, N, D);
604  points.resize(D);
605  INTREPID_TEST_COMMAND( CellTools::setJacobian(jacobian, points, cellWorkset, (*topo_iterator) ),
606  throwCounter, nException );
607 
608  // 4. points rank incompatible with whichCell = valid cell ordinal
609  points.resize(C, P, D);
610  INTREPID_TEST_COMMAND( CellTools::setJacobian(jacobian, points, cellWorkset, (*topo_iterator), 0 ),
611  throwCounter, nException );
612 
613  // 5. Non-matching dim
614  jacobian.resize(C, P, D, D);
615  points.resize(C, P, D - 1);
616  INTREPID_TEST_COMMAND( CellTools::setJacobian(jacobian, points, cellWorkset, (*topo_iterator) ),
617  throwCounter, nException );
618 
619  // 6. Non-matching dim
620  jacobian.resize(C, P, D, D);
621  points.resize(C, P - 1, D);
622  INTREPID_TEST_COMMAND( CellTools::setJacobian(jacobian, points, cellWorkset, (*topo_iterator) ),
623  throwCounter, nException );
624 
625  // 7. Non-matching dim
626  jacobian.resize(C, P, D, D);
627  points.resize(C - 1, P, D);
628  INTREPID_TEST_COMMAND( CellTools::setJacobian(jacobian, points, cellWorkset, (*topo_iterator) ),
629  throwCounter, nException );
630 
631  // 8. Non-matching dim
632  jacobian.resize(C, P, D, D);
633  points.resize(C, P, D);
634  cellWorkset.resize(C, N, D - 1);
635  INTREPID_TEST_COMMAND( CellTools::setJacobian(jacobian, points, cellWorkset, (*topo_iterator) ),
636  throwCounter, nException );
637 
638  // 9. Non-matching dim
639  jacobian.resize(C, P, D, D);
640  points.resize(C, P, D);
641  cellWorkset.resize(C - 1, N, D);
642  INTREPID_TEST_COMMAND( CellTools::setJacobian(jacobian, points, cellWorkset, (*topo_iterator) ),
643  throwCounter, nException );
644 
645  // 10. Incompatible ranks
646  jacobian.resize(C, D, D);
647  points.resize(C, P, D);
648  cellWorkset.resize(C, N, D);
649  INTREPID_TEST_COMMAND( CellTools::setJacobian(jacobian, points, cellWorkset, (*topo_iterator) ),
650  throwCounter, nException );
651 
652  /***********************************************************************************************
653  * Exception tests for setJacobianInv method *
654  **********************************************************************************************/
655 
656  // 11. incompatible ranks
657  jacobian.resize(C, P, D, D);
658  jacobianInv.resize(P, D, D);
659  INTREPID_TEST_COMMAND( CellTools::setJacobianInv(jacobianInv, jacobian),
660  throwCounter, nException );
661 
662  // 12. incorrect ranks
663  jacobian.resize(D, D);
664  jacobianInv.resize(D, D);
665  INTREPID_TEST_COMMAND( CellTools::setJacobianInv(jacobianInv, jacobian),
666  throwCounter, nException );
667 
668  // 13. nonmatching dimensions
669  jacobian.resize(C, P, D, D - 1);
670  jacobianInv.resize(C, P, D, D);
671  INTREPID_TEST_COMMAND( CellTools::setJacobianInv(jacobianInv, jacobian),
672  throwCounter, nException );
673 
674  // 14. nonmatching dimensions
675  jacobian.resize(C, P, D - 1, D);
676  jacobianInv.resize(C, P, D, D);
677  INTREPID_TEST_COMMAND( CellTools::setJacobianInv(jacobianInv, jacobian),
678  throwCounter, nException );
679 
680  // 15. nonmatching dimensions
681  jacobian.resize(C, P - 1, D, D);
682  jacobianInv.resize(C, P, D, D);
683  INTREPID_TEST_COMMAND( CellTools::setJacobianInv(jacobianInv, jacobian),
684  throwCounter, nException );
685 
686  // 16. nonmatching dimensions
687  jacobian.resize(C - 1, P, D, D);
688  jacobianInv.resize(C, P, D, D);
689  INTREPID_TEST_COMMAND( CellTools::setJacobianInv(jacobianInv, jacobian),
690  throwCounter, nException );
691 
692  /***********************************************************************************************
693  * Exception tests for setJacobianDet method *
694  **********************************************************************************************/
695 
696  // 17. Incompatible ranks
697  jacobian.resize(C, P, D, D);
698  jacobianDet.resize(C, P, D);
699  INTREPID_TEST_COMMAND( CellTools::setJacobianDet(jacobianDet, jacobian),
700  throwCounter, nException );
701 
702  // 18. Incompatible ranks
703  jacobian.resize(P, D, D);
704  jacobianDet.resize(C, P);
705  INTREPID_TEST_COMMAND( CellTools::setJacobianDet(jacobianDet, jacobian),
706  throwCounter, nException );
707 
708  // 19. Incorrect rank
709  jacobian.resize(D, D);
710  jacobianDet.resize(C, P);
711  INTREPID_TEST_COMMAND( CellTools::setJacobianDet(jacobianDet, jacobian),
712  throwCounter, nException );
713 
714  // 20. Incorrect rank
715  jacobian.resize(C, P, D, D);
716  jacobianDet.resize(C);
717  INTREPID_TEST_COMMAND( CellTools::setJacobianDet(jacobianDet, jacobian),
718  throwCounter, nException );
719 
720  // 21. Incorrect dimension
721  jacobian.resize(C, P, D, D);
722  jacobianDet.resize(C, P-1);
723  INTREPID_TEST_COMMAND( CellTools::setJacobianDet(jacobianDet, jacobian),
724  throwCounter, nException );
725 
726  // 22. Incorrect dimension
727  jacobian.resize(C - 1, P, D, D);
728  jacobianDet.resize(C, P);
729  INTREPID_TEST_COMMAND( CellTools::setJacobianDet(jacobianDet, jacobian),
730  throwCounter, nException );
731 
732  /***********************************************************************************************
733  * Exception tests for mapToPhysicalFrame method *
734  **********************************************************************************************/
735 
736  // 23. Incorrect refPoint rank
737  refPoints.resize(P);
738  physPoints.resize(P, D);
739  cellWorkset.resize(C, N, D);
740  INTREPID_TEST_COMMAND( CellTools::mapToPhysicalFrame(physPoints, refPoints, cellWorkset, (*topo_iterator) ),
741  throwCounter, nException );
742  // 24. Incorrect workset rank
743  cellWorkset.resize(P, D);
744  refPoints.resize(P, D);
745  physPoints.resize(C, P, D);
746  INTREPID_TEST_COMMAND( CellTools::mapToPhysicalFrame(physPoints, refPoints, cellWorkset, (*topo_iterator) ),
747  throwCounter, nException );
748 
749  // 25. Incompatible ranks
750  refPoints.resize(C, P, D);
751  physPoints.resize(P, D);
752  cellWorkset.resize(C, N, D);
753  INTREPID_TEST_COMMAND( CellTools::mapToPhysicalFrame(physPoints, refPoints, cellWorkset, (*topo_iterator) ),
754  throwCounter, nException );
755 
756  // 26. Incompatible dimensions
757  refPoints.resize(C, P, D);
758  physPoints.resize(C, P, D - 1);
759  INTREPID_TEST_COMMAND( CellTools::mapToPhysicalFrame(physPoints, refPoints, cellWorkset, (*topo_iterator) ),
760  throwCounter, nException );
761 
762  // 27. Incompatible dimensions
763  refPoints.resize(C, P, D);
764  physPoints.resize(C, P - 1, D);
765  INTREPID_TEST_COMMAND( CellTools::mapToPhysicalFrame(physPoints, refPoints, cellWorkset, (*topo_iterator) ),
766  throwCounter, nException );
767 
768  // 28. Incompatible dimensions
769  refPoints.resize(C, P, D);
770  physPoints.resize(C - 1, P, D);
771  INTREPID_TEST_COMMAND( CellTools::mapToPhysicalFrame(physPoints, refPoints, cellWorkset, (*topo_iterator) ),
772  throwCounter, nException );
773 
774  // 29. Incorrect physPoints rank when whichCell is valid cell ordinal
775  refPoints.resize(P, D);
776  physPoints.resize(C, P, D);
777  INTREPID_TEST_COMMAND( CellTools::mapToPhysicalFrame(physPoints, refPoints, cellWorkset, (*topo_iterator), 0 ),
778  throwCounter, nException );
779 
780  /***********************************************************************************************
781  * Exception tests for mapToReferenceFrame method (with default initial guesses) *
782  **********************************************************************************************/
783 
784  // 30. incompatible ranks
785  refPoints.resize(C, P, D);
786  physPoints.resize(P, D);
787  cellWorkset.resize(C, N, D);
788  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrame(refPoints, physPoints, cellWorkset, (*topo_iterator) ),
789  throwCounter, nException );
790 
791  // 31. Incompatible ranks with whichCell = valid cell ordinal
792  refPoints.resize(C, P, D);
793  physPoints.resize(C, P, D);
794  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrame(refPoints, physPoints, cellWorkset, (*topo_iterator), 0 ),
795  throwCounter, nException );
796 
797  // 32. Incompatible ranks with whichCell = -1 (default)
798  refPoints.resize(P, D);
799  physPoints.resize(P, D);
800  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrame(refPoints, physPoints, cellWorkset, (*topo_iterator)),
801  throwCounter, nException );
802 
803  // 33. Nonmatching dimensions
804  refPoints.resize(C, P, D - 1);
805  physPoints.resize(C, P, D);
806  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrame(refPoints, physPoints, cellWorkset, (*topo_iterator)),
807  throwCounter, nException );
808 
809  // 34. Nonmatching dimensions
810  refPoints.resize(C, P - 1, D);
811  physPoints.resize(C, P, D);
812  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrame(refPoints, physPoints, cellWorkset, (*topo_iterator)),
813  throwCounter, nException );
814 
815  // 35. Nonmatching dimensions
816  refPoints.resize(C - 1, P, D);
817  physPoints.resize(C, P, D);
818  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrame(refPoints, physPoints, cellWorkset, (*topo_iterator)),
819  throwCounter, nException );
820 
821  // 36. Incorrect rank for cellWorkset
822  refPoints.resize(C, P, D);
823  physPoints.resize(C, P, D);
824  cellWorkset.resize(C, N);
825  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrame(refPoints, physPoints, cellWorkset, (*topo_iterator)),
826  throwCounter, nException );
827 
828  /***********************************************************************************************
829  * Exception tests for mapToReferenceFrameInitGuess method (initial guess is a parameter) *
830  **********************************************************************************************/
831 
832  // 37. Incompatible ranks
833  refPoints.resize(C, P, D);
834  physPoints.resize(C, P, D);
835  initGuess.resize(P, D);
836  cellWorkset.resize(C, N, D);
837  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrameInitGuess(refPoints, initGuess, physPoints, cellWorkset, (*topo_iterator) ),
838  throwCounter, nException );
839 
840  // 38. Incompatible ranks when whichCell is valid ordinal
841  refPoints.resize(P, D);
842  physPoints.resize(P, D);
843  initGuess.resize(C, P, D);
844  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrameInitGuess(refPoints, initGuess, physPoints, cellWorkset, (*topo_iterator), 0),
845  throwCounter, nException );
846 
847  // 39. Nonmatching dimensions
848  refPoints.resize(C, P, D);
849  physPoints.resize(C, P, D);
850  initGuess.resize(C, P, D - 1);
851  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrameInitGuess(refPoints, initGuess, physPoints, cellWorkset, (*topo_iterator)),
852  throwCounter, nException );
853 
854  // 40. Nonmatching dimensions
855  initGuess.resize(C, P - 1, D);
856  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrameInitGuess(refPoints, initGuess, physPoints, cellWorkset, (*topo_iterator)),
857  throwCounter, nException );
858 
859  // 41. Nonmatching dimensions
860  initGuess.resize(C - 1, P, D);
861  INTREPID_TEST_COMMAND( CellTools::mapToReferenceFrameInitGuess(refPoints, initGuess, physPoints, cellWorkset, (*topo_iterator)),
862  throwCounter, nException );
863 
864  /***********************************************************************************************
865  * Exception tests for mapToReferenceSubcell method *
866  **********************************************************************************************/
867 
868  FieldContainer<double> refSubcellPoints;
869  FieldContainer<double> paramPoints;
870  int subcellDim = 2;
871  int subcellOrd = 0;
872 
873  // This should set cell topology to Tetrahedron<10> so that we have real edges and faces.
874  topo_iterator += 5;
875  D = (*topo_iterator).getDimension();
876 
877  // 42. Incorrect array rank
878  refSubcellPoints.resize(P,3);
879  paramPoints.resize(P);
880  INTREPID_TEST_COMMAND( CellTools::mapToReferenceSubcell(refSubcellPoints, paramPoints, subcellDim, subcellOrd, (*topo_iterator)),
881  throwCounter, nException );
882 
883  // 43. Incorrect array rank
884  refSubcellPoints.resize(P);
885  paramPoints.resize(P, 2);
886  INTREPID_TEST_COMMAND( CellTools::mapToReferenceSubcell(refSubcellPoints, paramPoints, subcellDim, subcellOrd, (*topo_iterator)),
887  throwCounter, nException );
888 
889  // 44. Incorrect array dimension for face of 3D cell (should be 3)
890  refSubcellPoints.resize(P, 2);
891  paramPoints.resize(P, 2);
892  INTREPID_TEST_COMMAND( CellTools::mapToReferenceSubcell(refSubcellPoints, paramPoints, subcellDim, subcellOrd, (*topo_iterator)),
893  throwCounter, nException );
894 
895  // 45. Incorrect array dimension for parametrization domain of a face of 3D cell (should be 2)
896  refSubcellPoints.resize(P, 3);
897  paramPoints.resize(P, 3);
898  INTREPID_TEST_COMMAND( CellTools::mapToReferenceSubcell(refSubcellPoints, paramPoints, subcellDim, subcellOrd, (*topo_iterator)),
899  throwCounter, nException );
900 
901  /***********************************************************************************************
902  * Exception tests for getReferenceEdgeTangent method *
903  **********************************************************************************************/
904 
905  FieldContainer<double> refEdgeTangent;
906 
907  // 46. Incorrect rank
908  refEdgeTangent.resize(C,P,D);
909  INTREPID_TEST_COMMAND( CellTools::getReferenceEdgeTangent(refEdgeTangent, 0, (*topo_iterator)),
910  throwCounter, nException );
911 
912  // 47. Incorrect dimension D for Tet<10> cell
913  refEdgeTangent.resize(2);
914  INTREPID_TEST_COMMAND( CellTools::getReferenceEdgeTangent(refEdgeTangent, 0, (*topo_iterator)),
915  throwCounter, nException );
916 
917  // 48. Invalid edge ordinal for Tet<10>
918  refEdgeTangent.resize(C,P,D);
919  INTREPID_TEST_COMMAND( CellTools::getReferenceEdgeTangent(refEdgeTangent, 10, (*topo_iterator)),
920  throwCounter, nException );
921 
922  /***********************************************************************************************
923  * Exception tests for getReferenceFaceTangents method *
924  **********************************************************************************************/
925 
926  FieldContainer<double> refFaceTanU;
927  FieldContainer<double> refFaceTanV;
928 
929  // 49. Incorrect rank
930  refFaceTanU.resize(P, D);
931  refFaceTanV.resize(D);
932  INTREPID_TEST_COMMAND( CellTools::getReferenceFaceTangents(refFaceTanU, refFaceTanV, 0, (*topo_iterator)),
933  throwCounter, nException );
934 
935  // 50. Incorrect rank
936  refFaceTanU.resize(D);
937  refFaceTanV.resize(P, D);
938  INTREPID_TEST_COMMAND( CellTools::getReferenceFaceTangents(refFaceTanU, refFaceTanV, 0, (*topo_iterator)),
939  throwCounter, nException );
940 
941  // 51. Incorrect dimension for 3D cell
942  refFaceTanU.resize(D - 1);
943  refFaceTanV.resize(D);
944  INTREPID_TEST_COMMAND( CellTools::getReferenceFaceTangents(refFaceTanU, refFaceTanV, 0, (*topo_iterator)),
945  throwCounter, nException );
946 
947  // 52. Incorrect dimension for 3D cell
948  refFaceTanU.resize(D);
949  refFaceTanV.resize(D - 1);
950  INTREPID_TEST_COMMAND( CellTools::getReferenceFaceTangents(refFaceTanU, refFaceTanV, 0, (*topo_iterator)),
951  throwCounter, nException );
952 
953  // 53. Invalid face ordinal
954  refFaceTanU.resize(D);
955  refFaceTanV.resize(D);
956  INTREPID_TEST_COMMAND( CellTools::getReferenceFaceTangents(refFaceTanU, refFaceTanV, 10, (*topo_iterator)),
957  throwCounter, nException );
958 
959  /***********************************************************************************************
960  * Exception tests for getReferenceSide/FaceNormal methods *
961  **********************************************************************************************/
962 
963  FieldContainer<double> refSideNormal;
964 
965  // 54-55. Incorrect rank
966  refSideNormal.resize(C,P);
967  INTREPID_TEST_COMMAND( CellTools::getReferenceSideNormal(refSideNormal, 0, (*topo_iterator)),
968  throwCounter, nException );
969  INTREPID_TEST_COMMAND( CellTools::getReferenceFaceNormal(refSideNormal, 0, (*topo_iterator)),
970  throwCounter, nException );
971 
972  // 56-57. Incorrect dimension for 3D cell
973  refSideNormal.resize(D - 1);
974  INTREPID_TEST_COMMAND( CellTools::getReferenceSideNormal(refSideNormal, 0, (*topo_iterator)),
975  throwCounter, nException );
976  INTREPID_TEST_COMMAND( CellTools::getReferenceFaceNormal(refSideNormal, 0, (*topo_iterator)),
977  throwCounter, nException );
978 
979  // 58-59. Invalid side ordinal for Tet<10>
980  refSideNormal.resize(D);
981  INTREPID_TEST_COMMAND( CellTools::getReferenceSideNormal(refSideNormal, 10, (*topo_iterator)),
982  throwCounter, nException );
983  INTREPID_TEST_COMMAND( CellTools::getReferenceFaceNormal(refSideNormal, 10, (*topo_iterator)),
984  throwCounter, nException );
985 
986  // 60. Incorrect dimension for 2D cell: reset topo_iterator to the first cell in supportedTopologies which is Tri<3>
987  topo_iterator = supportedTopologies.begin();
988  D = (*topo_iterator).getDimension();
989  refSideNormal.resize(D - 1);
990  INTREPID_TEST_COMMAND( CellTools::getReferenceSideNormal(refSideNormal, 0, (*topo_iterator)),
991  throwCounter, nException );
992 
993  // 61. Invalid side ordinal for Tri<3>
994  refSideNormal.resize(D);
995  INTREPID_TEST_COMMAND( CellTools::getReferenceSideNormal(refSideNormal, 10, (*topo_iterator)),
996  throwCounter, nException );
997 
998  // 62. Cannot call the "face" method for 2D cells
999  refSideNormal.resize(D);
1000  INTREPID_TEST_COMMAND( CellTools::getReferenceFaceNormal(refSideNormal, 0, (*topo_iterator)),
1001  throwCounter, nException );
1002 
1003  /***********************************************************************************************
1004  * Exception tests for checkPoint/Pointset/PointwiseInclusion methods *
1005  **********************************************************************************************/
1006  points.resize(2,3,3,4);
1007  FieldContainer<int> inCell;
1008 
1009  // 63. Point dimension does not match cell topology
1010  double * point = 0;
1011  INTREPID_TEST_COMMAND(CellTools::checkPointInclusion(point, (*topo_iterator).getDimension() + 1, (*topo_iterator) ),
1012  throwCounter, nException );
1013 
1014  // 64. Invalid cell topology
1015  CellTopology pentagon_5(shards::getCellTopologyData<shards::Pentagon<> >() );
1016  INTREPID_TEST_COMMAND(CellTools::checkPointInclusion(point, pentagon_5.getDimension(), pentagon_5 ),
1017  throwCounter, nException );
1018 
1019  // 65. Incorrect spatial dimension of points
1020  points.resize(10, 10, (*topo_iterator).getDimension() + 1);
1021  INTREPID_TEST_COMMAND(CellTools::checkPointsetInclusion(points, (*topo_iterator) ),
1022  throwCounter, nException );
1023 
1024  // 66. Incorrect rank of input array
1025  points.resize(10,10,10,3);
1026  INTREPID_TEST_COMMAND(CellTools::checkPointsetInclusion(points, (*topo_iterator) ),
1027  throwCounter, nException );
1028 
1029  // 67. Incorrect rank of output array
1030  points.resize(10,10,(*topo_iterator).getDimension() );
1031  inCell.resize(10);
1032  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, points, (*topo_iterator) ),
1033  throwCounter, nException );
1034 
1035  // 68. Incorrect rank of output array
1036  points.resize(10, (*topo_iterator).getDimension() );
1037  inCell.resize(10, 10);
1038  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, points, (*topo_iterator) ),
1039  throwCounter, nException );
1040 
1041  // 69. Incorrect rank of output array
1042  points.resize((*topo_iterator).getDimension() );
1043  inCell.resize(10, 10);
1044  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, points, (*topo_iterator) ),
1045  throwCounter, nException );
1046 
1047  // 70. Incorrect dimension of output array
1048  points.resize(10, 10, (*topo_iterator).getDimension() );
1049  inCell.resize(10, 9);
1050  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, points, (*topo_iterator) ),
1051  throwCounter, nException );
1052 
1053  // 71. Incorrect dimension of output array
1054  points.resize(10, 10, (*topo_iterator).getDimension() );
1055  inCell.resize(9, 10);
1056  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, points, (*topo_iterator) ),
1057  throwCounter, nException );
1058 
1059  // 72. Incorrect dimension of output array
1060  points.resize(10, (*topo_iterator).getDimension() );
1061  inCell.resize(9);
1062  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, points, (*topo_iterator) ),
1063  throwCounter, nException );
1064 
1065  // 73. Incorrect spatial dimension of input array
1066  points.resize(10, 10, (*topo_iterator).getDimension() + 1);
1067  inCell.resize(10, 10);
1068  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, points, (*topo_iterator) ),
1069  throwCounter, nException );
1070 
1071  // 74. Incorrect rank of input array.
1072  points.resize(10,10,10,3);
1073  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, points, (*topo_iterator) ),
1074  throwCounter, nException );
1075 
1076 
1077  physPoints.resize(C, P, D);
1078  inCell.resize(C, P);
1079  // 75. Invalid rank of cellWorkset
1080  cellWorkset.resize(C, N, D, D);
1081  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator) ),
1082  throwCounter, nException );
1083 
1084  // 76. Invalid dimension 1 (node count) of cellWorkset
1085  cellWorkset.resize(C, N + 1, D);
1086  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator) ),
1087  throwCounter, nException );
1088 
1089  // 77. Invalid dimension 2 (spatial dimension) of cellWorkset
1090  cellWorkset.resize(C, N, D + 1);
1091  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator) ),
1092  throwCounter, nException );
1093 
1094  // 78. Invalid whichCell value (exceeds cell count in the workset)
1095  cellWorkset.resize(C, N, D);
1096  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator), C + 1 ),
1097  throwCounter, nException );
1098 
1099  // 79. Invalid whichCell for rank-3 physPoints (must be -1, here it is valid cell ordinal)
1100  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator), 0 ),
1101  throwCounter, nException );
1102 
1103  // 80. Invalid whichCell for rank-2 physPoints (must be a valid cell ordinal, here it is the default -1)
1104  physPoints.resize(P, D);
1105  inCell.resize(P);
1106  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator) ),
1107  throwCounter, nException );
1108 
1109  // 81. Incompatible ranks of I/O arrays
1110  physPoints.resize(C, P, D);
1111  inCell.resize(P);
1112  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator)),
1113  throwCounter, nException );
1114 
1115  // 82. Incompatible ranks of I/O arrays
1116  physPoints.resize(P, D);
1117  inCell.resize(C, P);
1118  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator), 0),
1119  throwCounter, nException );
1120 
1121  // 83. Incompatible dimensions of I/O arrays
1122  physPoints.resize(C, P, D);
1123  inCell.resize(C, P + 1);
1124  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator)),
1125  throwCounter, nException );
1126 
1127  // 84. Incompatible dimensions of I/O arrays: rank-3 Input
1128  physPoints.resize(C + 1, P, D);
1129  inCell.resize(C, P);
1130  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator)),
1131  throwCounter, nException );
1132 
1133  // 85. Incompatible dimensions of I/O arrays: rank-2 Input
1134  physPoints.resize(P, D);
1135  inCell.resize(P + 1);
1136  INTREPID_TEST_COMMAND(CellTools::checkPointwiseInclusion(inCell, physPoints, cellWorkset, (*topo_iterator), 0 ),
1137  throwCounter, nException );
1138 
1139 
1140  /***********************************************************************************************
1141  * Exception tests for getReferenceVertex/vertices/Node/Nodes methods *
1142  **********************************************************************************************/
1143 
1144  FieldContainer<double> subcellNodes;
1145 
1146  // 86-89. Cell does not have reference cell
1147  INTREPID_TEST_COMMAND(CellTools::getReferenceVertex(pentagon_5, 0), throwCounter, nException);
1148  INTREPID_TEST_COMMAND(CellTools::getReferenceNode(pentagon_5, 0), throwCounter, nException);
1149  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellVertices(subcellNodes, 0, 0, pentagon_5), throwCounter, nException);
1150  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellNodes(subcellNodes, 0, 0, pentagon_5), throwCounter, nException);
1151 
1152  // Use last cell topology (Wedge<18>) for these tests
1153  topo_iterator = supportedTopologies.end() - 1;
1154  D = (*topo_iterator).getDimension();
1155  int subcDim = D - 1;
1156  int S = (*topo_iterator).getSubcellCount(subcDim);
1157  V = (*topo_iterator).getVertexCount(subcDim, S - 1);
1158  subcellNodes.resize(V, D);
1159  // 90. subcell ordinal out of range
1160  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellVertices(subcellNodes, subcDim, S + 1, (*topo_iterator)),
1161  throwCounter, nException);
1162 
1163  // 91. subcell dim out of range
1164  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellVertices(subcellNodes, D + 1, S, (*topo_iterator)),
1165  throwCounter, nException);
1166 
1167  // 92. Incorrect rank for subcellNodes
1168  subcellNodes.resize(V, D, D);
1169  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellVertices(subcellNodes, subcDim, S - 1, (*topo_iterator)),
1170  throwCounter, nException);
1171 
1172  // 93. Incorrect dimension for subcellNodes
1173  subcellNodes.resize(V - 1, D);
1174  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellVertices(subcellNodes, subcDim, S - 1, (*topo_iterator)),
1175  throwCounter, nException);
1176 
1177  // 94. Incorrect dimension for subcellNodes
1178  subcellNodes.resize(V, D - 1);
1179  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellVertices(subcellNodes, subcDim, S - 1, (*topo_iterator)),
1180  throwCounter, nException);
1181 
1182 
1183  N = (*topo_iterator).getNodeCount(subcDim, S - 1);
1184  subcellNodes.resize(N, D);
1185  // 95. subcell ordinal out of range
1186  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellNodes(subcellNodes, subcDim, S + 1, (*topo_iterator)),
1187  throwCounter, nException);
1188 
1189  // 96. subcell dim out of range
1190  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellNodes(subcellNodes, D + 1, S, (*topo_iterator)),
1191  throwCounter, nException);
1192 
1193  // 97. Incorrect rank for subcellNodes
1194  subcellNodes.resize(N, D, D);
1195  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellNodes(subcellNodes, subcDim, S - 1, (*topo_iterator)),
1196  throwCounter, nException);
1197 
1198  // 98. Incorrect dimension for subcellNodes
1199  subcellNodes.resize(N - 1, D);
1200  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellNodes(subcellNodes, subcDim, S - 1, (*topo_iterator)),
1201  throwCounter, nException);
1202 
1203  // 99. Incorrect dimension for subcellNodes
1204  subcellNodes.resize(N, D - 1);
1205  INTREPID_TEST_COMMAND(CellTools::getReferenceSubcellNodes(subcellNodes, subcDim, S - 1, (*topo_iterator)),
1206  throwCounter, nException);
1207 
1208 #endif
1209  } // try exception testing
1210 
1211  /*************************************************************************************************
1212  * Wrap up test: check if the test broke down unexpectedly due to an exception *
1213  ************************************************************************************************/
1214 
1215  catch(std::logic_error err) {
1216  *outStream << err.what() << "\n";
1217  errorFlag = -1000;
1218  }
1219 
1220  // Check if number of thrown exceptions matches the one we expect
1221  if (throwCounter != nException) {
1222  errorFlag++;
1223  *outStream << std::setw(70) << "^^^^----FAILURE!" << "\n";
1224  }
1225 
1226 
1227  if (errorFlag != 0)
1228  std::cout << "End Result: TEST FAILED\n";
1229  else
1230  std::cout << "End Result: TEST PASSED\n";
1231 
1232  // reset format state of std::cout
1233  std::cout.copyfmt(oldFormatState);
1234 
1235  return errorFlag;
1236 }
1237 
1238 
1239 
1240 
1241 
1242 
1243 
int main(int argc, char *argv[])
outdated tests for orthogonal bases
Definition: test_02.cpp:63
void clear()
Clears FieldContainer to trivial container (one with rank = 0 and size = 0)
Header file for the Intrepid::CellTools class.
Header file for utility class to provide multidimensional containers.
Header file for the abstract base class Intrepid::DefaultCubatureFactory.
void resize(const int dim0)
Resizes FieldContainer to a rank-1 container with the specified dimension, initialized by 0...
A factory class that generates specific instances of cubatures.
Teuchos::RCP< Cubature< Scalar, ArrayPoint, ArrayWeight > > create(const shards::CellTopology &cellTopology, const std::vector< int > &degree)
Factory method.
A stateless class for operations on cell data. Provides methods for: