Intrepid
example_01.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 
50 #include "Intrepid_CellTools.hpp"
52 #include "Shards_CellTopology.hpp"
53 #include "Teuchos_GlobalMPISession.hpp"
54 
55 using namespace std;
56 using namespace Intrepid;
57 using namespace shards;
58 
59 int main(int argc, char *argv[]) {
60 
61  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
62 
63  std::cout \
64  << "===============================================================================\n" \
65  << "| |\n" \
66  << "| Example use of the CellTools class |\n" \
67  << "| |\n" \
68  << "| 1) Using shards::CellTopology to get cell types and topology |\n" \
69  << "| 2) Using CellTools to get cell Jacobians and their inverses and dets |\n" \
70  << "| 3) Testing points for inclusion in reference and physical cells |\n" \
71  << "| 4) Mapping points to and from reference cells with base and extended |\n" \
72  << "| topologies. |\n" \
73  << "| |\n" \
74  << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov) or |\n" \
75  << "| Denis Ridzal (dridzal@sandia.gov) |\n" \
76  << "| Kara Peterson (kjpeter@sandia.gov). |\n" \
77  << "| |\n" \
78  << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \
79  << "| Shards's website: http://trilinos.sandia.gov/packages/shards |\n" \
80  << "| Trilinos website: http://trilinos.sandia.gov |\n" \
81  << "| |\n" \
82  << "===============================================================================\n"\
83  << "| EXAMPLE 1: Query of cell types and topology |\n"\
84  << "===============================================================================\n";
85 
86 
89  typedef shards::CellTopology CellTopology;
90 
91 
92  // Vector to hold cell topologies
93  std::vector<CellTopology> shardsTopologies;
94 
95 
96  // All 2D cell topologies in Shards:
97  int cellDim = 2;
98  shards::getTopologies(shardsTopologies, cellDim);
99  std::cout << "Number of all " << cellDim
100  << "D Shards cell topologies = " << shardsTopologies.size() << "\n\n";
101 
102  for(unsigned i = 0; i < shardsTopologies.size(); i++){
103  std::cout << shardsTopologies[i].getName() << "\n";
104  }
105  std::cout <<"\n";
106 
107 
108  // All standard 2D cell topologies in Shards:
109  shards::getTopologies(shardsTopologies, cellDim,
110  shards::STANDARD_CELL);
111  std::cout << "Number of all "
112  << cellDim << "D standard Shards cell topologies = " << shardsTopologies.size() << "\n\n";
113 
114  for(unsigned i = 0; i < shardsTopologies.size(); i++){
115  std::cout << shardsTopologies[i].getName() << "\n";
116  }
117  std::cout <<"\n";
118 
119 
120  // All standard 2D cells with base topologies in Shards:
121  shards::getTopologies(shardsTopologies, cellDim,
122  shards::STANDARD_CELL,
123  shards::BASE_TOPOLOGY);
124  std::cout << "Number of all " << cellDim
125  << "D standard Shards cells with base topologies = " << shardsTopologies.size() << "\n\n";
126 
127  for(unsigned i = 0; i < shardsTopologies.size(); i++){
128  std::cout << shardsTopologies[i].getName() << "\n";
129  }
130  std::cout <<"\n";
131 
132 
133  // All standard 2D cells with extended topologies in Shards:
134  shards::getTopologies(shardsTopologies, cellDim,
135  shards::STANDARD_CELL,
136  shards::EXTENDED_TOPOLOGY);
137  std::cout << "Number of all " << cellDim
138  << "D standard Shards cells with extended topologies = " << shardsTopologies.size() << "\n\n";
139 
140  for(unsigned i = 0; i < shardsTopologies.size(); i++){
141  std::cout << shardsTopologies[i].getName() << "\n";
142  }
143  std::cout <<"\n";
144 
145 
146  // All non-standard 2D cells with base topologies in Shards:
147  shards::getTopologies(shardsTopologies, cellDim,
148  shards::NONSTANDARD_CELL,
149  shards::BASE_TOPOLOGY);
150  std::cout << "Number of all " << cellDim
151  << "D non-standard Shards cells with base topologies = " << shardsTopologies.size() << "\n\n";
152 
153  for(unsigned i = 0; i < shardsTopologies.size(); i++){
154  std::cout << shardsTopologies[i].getName() << "\n";
155  }
156  std::cout <<"\n";
157 
158 
159  // All non-standard 2D cells with extended topologies in Shards:
160  shards::getTopologies(shardsTopologies, cellDim,
161  shards::NONSTANDARD_CELL,
162  shards::EXTENDED_TOPOLOGY);
163  std::cout << "Number of all " << cellDim
164  << "D non-standard Shards cells with extended topologies = " << shardsTopologies.size() << "\n\n";
165 
166  for(unsigned i = 0; i < shardsTopologies.size(); i++){
167  std::cout << shardsTopologies[i].getName() << "\n";
168  }
169  std::cout <<"\n";
170 
171  // Finally, get all shards cell topologies and print them!
172  shards::getTopologies(shardsTopologies);
173  std::cout << "Number of all Shards cell topologies = " << shardsTopologies.size() << "\n\n";
174  for(unsigned i = 0; i < shardsTopologies.size(); i++){
175  std::cout << shardsTopologies[i] << "\n";
176  }
177  std::cout <<"\n";
178 
179 
180 
181 cout \
182 << "===============================================================================\n"\
183 << "| EXAMPLE 2: Using CellTools to get Jacobian, Jacobian inverse & Jacobian det |\n"\
184 << "===============================================================================\n";
185 
186 // 4 triangles with basic triangle topology: number of nodes = number of vertices
187 CellTopology triangle_3(shards::getCellTopologyData<Triangle<3> >() );
188 int numCells = 4;
189 int numNodes = triangle_3.getNodeCount();
190 int spaceDim = triangle_3.getDimension();
191 
192 // Rank-3 array with dimensions (C,N,D) for the node coordinates of 3 traingle cells
193 FieldContainer<double> triNodes(numCells, numNodes, spaceDim);
194 
195 // Initialize node data: accessor is (cellOrd, nodeOrd, coordinateOrd)
196 triNodes(0, 0, 0) = 0.0; triNodes(0, 0, 1) = 0.0; // 1st triangle = the reference tri
197 triNodes(0, 1, 0) = 1.0; triNodes(0, 1, 1) = 0.0;
198 triNodes(0, 2, 0) = 0.0; triNodes(0, 2, 1) = 1.0;
199 
200 triNodes(1, 0, 0) = 1.0; triNodes(1, 0, 1) = 1.0; // 2nd triangle = 1st shifted by (1,1)
201 triNodes(1, 1, 0) = 2.0; triNodes(1, 1, 1) = 1.0;
202 triNodes(1, 2, 0) = 1.0; triNodes(1, 2, 1) = 2.0;
203 
204 triNodes(2, 0, 0) = 0.0; triNodes(2, 0, 1) = 0.0; // 3rd triangle = flip 1st vertical
205 triNodes(2, 1, 0) =-1.0; triNodes(2, 1, 1) = 0.0;
206 triNodes(2, 2, 0) = 0.0; triNodes(2, 2, 1) = 1.0;
207 
208 triNodes(3, 0, 0) = 2.0; triNodes(3, 0, 1) = 1.0; // 4th triangle = just a triangle
209 triNodes(3, 1, 0) = 3.0; triNodes(3, 1, 1) = 0.5;
210 triNodes(3, 2, 0) = 3.5; triNodes(3, 2, 1) = 2.0;
211 
212 
213 // Rank-2 array with dimensions (P,D) for some points on the reference triangle
214 int numRefPoints = 2;
215 FieldContainer<double> refPoints(numRefPoints, spaceDim);
216 refPoints(0,0) = 0.0; refPoints(0,1) = 0.0;
217 refPoints(1,0) = 0.5; refPoints(1,1) = 0.5;
218 
219 
220 // Rank-4 array (C,P,D,D) for the Jacobian and its inverse and Rank-2 array (C,P) for its determinant
221 FieldContainer<double> triJacobian(numCells, numRefPoints, spaceDim, spaceDim);
222 FieldContainer<double> triJacobInv(numCells, numRefPoints, spaceDim, spaceDim);
223 FieldContainer<double> triJacobDet(numCells, numRefPoints);
224 
225 // Rank-4 and Rank-2 auxiliary arrays
226 FieldContainer<double> rank4Aux (numCells, numRefPoints, spaceDim, spaceDim);
227 FieldContainer<double> rank2Aux (numCells, numRefPoints);
228 
229 
230 // Methods to compute cell Jacobians, their inverses and their determinants
231 CellTools::setJacobian(triJacobian, refPoints, triNodes, triangle_3);
232 CellTools::setJacobianInv(triJacobInv, triJacobian );
233 CellTools::setJacobianDet(triJacobDet, triJacobian );
234 
235 // Checks: compute det(Inv(DF)) and Inv(Inv(DF))
236 RealSpaceTools::det(rank2Aux, triJacobInv);
237 RealSpaceTools::inverse(rank4Aux, triJacobInv);
238 
239 // Print data
240 std::cout
241 << std::scientific<< std::setprecision(4)
242 << std::right << std::setw(16) << "DF(P)"
243 << std::right << std::setw(30) << "Inv(DF(P))"
244 << std::right << std::setw(30) << "Inv(Inv(DF(P)))\n";
245 
246 for(int cellOrd = 0; cellOrd < numCells; cellOrd++){
247  std::cout
248  << "===============================================================================\n"
249  << "Cell " << cellOrd << "\n";
250  for(int pointOrd = 0; pointOrd < numRefPoints; pointOrd++){
251  std::cout << "Point = ("
252  << std::setw(4) << std::right << refPoints(pointOrd, 0) << ","<< std::setw(4) << std::right<< refPoints(pointOrd,1) << ")\n";
253  for(int row = 0; row < spaceDim; row++){
254  std::cout
255  << std::setw(11) << std::right << triJacobian(cellOrd, pointOrd, row, 0) << " "
256  << std::setw(11) << std::right << triJacobian(cellOrd, pointOrd, row, 1)
257  //
258  << std::setw(16) << std::right << triJacobInv(cellOrd, pointOrd, row, 0) << " "
259  << std::setw(11) << std::right << triJacobInv(cellOrd, pointOrd, row, 1)
260  //
261  << std::setw(16) << std::right << rank4Aux(cellOrd, pointOrd, row, 0) << " "
262  << std::setw(11) << std::right << rank4Aux(cellOrd, pointOrd, row, 1) << "\n";
263  }
264  std::cout
265  << setw(5)<<std::left<< "Determinant:\n"
266  << std::setw(11) << std::right << triJacobDet(cellOrd, pointOrd)
267  << std::setw(28) << std::right << rank2Aux(cellOrd, pointOrd)
268  << std::setw(28) << std::right << " product = " << triJacobDet(cellOrd, pointOrd)*rank2Aux(cellOrd, pointOrd);
269  std::cout<< "\n\n";
270  }
271 }
272 
273 
274 // 2 Quadrilateral cells with base topology
275 CellTopology quad_4(shards::getCellTopologyData<Quadrilateral<4> >() );
276 numCells = 2;
277 numNodes = quad_4.getNodeCount();
278 spaceDim = quad_4.getDimension();
279 
280 FieldContainer<double> quadNodes(numCells, numNodes, spaceDim);
281 // 1st QUAD
282 quadNodes(0,0,0) = 1.00; quadNodes(0,0,1) = 1.00;
283 quadNodes(0,1,0) = 2.00; quadNodes(0,1,1) = 0.75;
284 quadNodes(0,2,0) = 1.75; quadNodes(0,2,1) = 2.00;
285 quadNodes(0,3,0) = 1.25; quadNodes(0,3,1) = 2.00,
286 // 2ND QUAD
287 quadNodes(1,0,0) = 2.00; quadNodes(1,0,1) = 0.75;
288 quadNodes(1,1,0) = 3.00; quadNodes(1,1,1) = 1.25;
289 quadNodes(1,2,0) = 2.75; quadNodes(1,2,1) = 2.25;
290 quadNodes(1,3,0) = 1.75; quadNodes(1,3,1) = 2.00;
291 
292 
293 
294 // 1 Hexahedron cell with base topology: number of nodes = number of vertices
295 CellTopology hex_8(shards::getCellTopologyData<Hexahedron<8> >() );
296 numCells = 1;
297 numNodes = hex_8.getNodeCount();
298 spaceDim = hex_8.getDimension();
299 
300 FieldContainer<double> hexNodes(numCells, numNodes, spaceDim);
301 hexNodes(0,0,0) =
302 // bottom face vertices
303 hexNodes(0,0,0) = 1.00; hexNodes(0,0,1) = 1.00; hexNodes(0,0,2) = 0.00;
304 hexNodes(0,1,0) = 2.00; hexNodes(0,1,1) = 0.75; hexNodes(0,1,2) =-0.25;
305 hexNodes(0,2,0) = 1.75; hexNodes(0,2,1) = 2.00; hexNodes(0,2,2) = 0.00;
306 hexNodes(0,3,0) = 1.25; hexNodes(0,3,1) = 2.00; hexNodes(0,3,1) = 0.25;
307 // top face vertices
308 hexNodes(0,4,0) = 1.25; hexNodes(0,4,1) = 0.75; hexNodes(0,4,2) = 0.75;
309 hexNodes(0,5,0) = 1.75; hexNodes(0,5,1) = 1.00; hexNodes(0,5,2) = 1.00;
310 hexNodes(0,6,0) = 2.00; hexNodes(0,6,1) = 2.00; hexNodes(0,6,2) = 1.25;
311 hexNodes(0,7,0) = 1.00; hexNodes(0,7,1) = 2.00; hexNodes(0,7,2) = 1.00;
312 
313 
314 
315 std::cout << std::setprecision(16) << "\n" \
316 << "===============================================================================\n"\
317 << "| EXAMPLE 3: Using single point inclusion test method |\n"\
318 << "===============================================================================\n";
319 
320 // Define cell topologies
321 CellTopology edge3(shards::getCellTopologyData<Line<3> >() );
322 CellTopology tri6 (shards::getCellTopologyData<Triangle<6> >() );
323 CellTopology quad9(shards::getCellTopologyData<Quadrilateral<9> >() );
324 CellTopology tet4 (shards::getCellTopologyData<Tetrahedron<> >() );
325 CellTopology hex27(shards::getCellTopologyData<Hexahedron<27> >() );
326 CellTopology wedge(shards::getCellTopologyData<Wedge<> >() );
327 CellTopology pyr (shards::getCellTopologyData<Pyramid<> >() );
328 
329 // Points that are close to the boundaries of their reference cells
330 double point_in_edge[1] = {1.0-INTREPID_EPSILON};
331 double point_in_quad[2] = {1.0, 1.0-INTREPID_EPSILON};
332 double point_in_tri[2] = {0.5-INTREPID_EPSILON, 0.5-INTREPID_EPSILON};
333 double point_in_tet[3] = {0.5-INTREPID_EPSILON, 0.5-INTREPID_EPSILON, 2.0*INTREPID_EPSILON};
334 double point_in_hex[3] = {1.0-INTREPID_EPSILON, 1.0-INTREPID_EPSILON, 1.0-INTREPID_EPSILON};
335 double point_in_wedge[3] = {0.5, 0.25, 1.0-INTREPID_EPSILON};
336 double point_in_pyramid[3] = {-INTREPID_EPSILON, INTREPID_EPSILON, 1.0-INTREPID_EPSILON};
337 
338 // Run the inclusion test for each point and print results
339 int in_edge = CellTools::checkPointInclusion( point_in_edge, 1, edge3, INTREPID_THRESHOLD );
340 int in_quad = CellTools::checkPointInclusion( point_in_quad, 2, quad9 );
341 int in_tri = CellTools::checkPointInclusion( point_in_tri, 2, tri6 );
342 int in_tet = CellTools::checkPointInclusion( point_in_tet, 3, tet4 );
343 int in_hex = CellTools::checkPointInclusion( point_in_hex, 3, hex27 );
344 int in_prism = CellTools::checkPointInclusion( point_in_wedge, 3, wedge );
345 int in_pyramid = CellTools::checkPointInclusion( point_in_pyramid, 3, pyr );
346 
347 if(in_edge) {
348  std::cout << "(" << point_in_edge[0] << ")"
349  << " is inside reference Line " << endl;
350 }
351 if(in_quad) {
352  std::cout << "(" << point_in_quad[0] << "," << point_in_quad[1] << ")"
353  << " is inside reference Quadrilateral " << endl;
354 }
355 if(in_tri) {
356  std::cout << "(" << point_in_tri[0] << "," << point_in_tri[1] << ")"
357  << " is inside reference Triangle " << endl;
358 }
359 if(in_tet) {
360  std::cout << "(" << point_in_tet[0] << "," << point_in_tet[1] << "," << point_in_tet[2]<<")"
361  << " is inside reference Tetrahedron " << endl;
362 }
363 if(in_hex) {
364  std::cout << "(" << point_in_hex[0] << "," << point_in_hex[1] << "," << point_in_hex[2]<<")"
365  << " is inside reference Hexahedron " << endl;
366 }
367 if(in_prism) {
368  std::cout << "(" << point_in_wedge[0] << "," << point_in_wedge[1] << "," << point_in_wedge[2]<<")"
369  << " is inside reference Wedge " << endl;
370 }
371 if(in_pyramid) {
372  std::cout << "(" << point_in_pyramid[0] << "," << point_in_pyramid[1] << "," << point_in_pyramid[2]<<")"
373  << " is inside reference Pyramid " << endl;
374 }
375 
376 // Change the points to be outside their reference cells.
377 double small = 2.0*INTREPID_THRESHOLD;
378 point_in_edge[0] += small;
379 
380 point_in_tri[0] += small;
381 point_in_tri[1] += small;
382 
383 point_in_pyramid[0] += small;
384 point_in_pyramid[1] += small;
385 point_in_pyramid[2] += small;
386 
387 in_edge = CellTools::checkPointInclusion(point_in_edge, 1, edge3);
388 in_tri = CellTools::checkPointInclusion(point_in_tri, 2, tri6);
389 in_pyramid = CellTools::checkPointInclusion(point_in_pyramid, 3, pyr);
390 
391 std::cout << "\nChecking if perturbed Points belong to reference cell: " << endl;
392 if(!in_edge) {
393  std::cout << "(" << point_in_edge[0] << ")" << " is NOT inside reference Line " << endl;
394 }
395 if(!in_tri) {
396  std::cout << "(" << point_in_tri[0] << "," << point_in_tri[1] << ")" << " is NOT inside reference Triangle " << endl;
397 }
398 if(!in_pyramid) {
399  std::cout << "(" << point_in_pyramid[0] << "," << point_in_pyramid[1] << "," << point_in_pyramid[2]<<")"
400  << " is NOT inside reference Pyramid " << endl;
401 }
402 
403 
404 
405 std::cout << std::setprecision(6) << "\n" \
406 << "===============================================================================\n"\
407 << "| EXAMPLE 4-A: Using pointwise inclusion test method for reference cells |\n"\
408 << "===============================================================================\n";
409 
410 
411 // Rank-1 array for one 2D reference point and rank-1 array for the test result
412 FieldContainer<double> onePoint(2);
413 FieldContainer<int> testOnePoint(1);
414 
415 onePoint(0) = 0.2; onePoint(1) = 0.3;
416 
417 std::cout <<"\t Pointwise inclusion test for Triangle<6>: rank-1 array with a single 2D point: \n";
418 
419 CellTools::checkPointwiseInclusion(testOnePoint, onePoint, tri6);
420 
421 std::cout << "point("
422 << std::setw(13) << std::right << onePoint(0) << ","
423 << std::setw(13) << std::right << onePoint(1) << ") ";
424 if( testOnePoint(0) ) {
425  std::cout << " is inside. \n";
426 }
427 else{
428  std::cout << " is not inside. \n";
429 }
430 std::cout << "\n";
431 
432 
433 // Rank-2 array for 4 2D reference points (vector of points) and rank-1 array for the test result
434 FieldContainer<double> fourPoints(4, 2);
435 FieldContainer<int> testFourPoints(4);
436 
437 fourPoints(0,0) = 0.5; fourPoints(0,1) = 0.5;
438 fourPoints(1,0) = 1.0; fourPoints(1,1) = 1.1;
439 fourPoints(2,0) =-1.0; fourPoints(2,1) =-1.1;
440 fourPoints(3,0) =-1.0; fourPoints(3,1) = 0.5;
441 
442 std::cout <<"\t Pointwise inclusion test for Quadrilateral<9>: rank-2 array with 4 2D points: \n";
443 
444 CellTools::checkPointwiseInclusion(testFourPoints, fourPoints, quad9);
445 
446 for(int i1 = 0; i1 < fourPoints.dimension(0); i1++) {
447  std::cout << " point(" << i1 << ") = ("
448  << std::setw(13) << std::right << fourPoints(i1, 0) << ","
449  << std::setw(13) << std::right << fourPoints(i1, 1) << ") ";
450  if( testFourPoints(i1) ) {
451  std::cout << " is inside. \n";
452  }
453  else{
454  std::cout << " is not inside. \n";
455  }
456 }
457 std::cout << "\n";
458 
459 
460 // Rank-3 array for 6 2D points and rank-2 array for the test result
461 FieldContainer<double> sixPoints(2, 3, 2);
462 FieldContainer<int> testSixPoints(2, 3);
463 
464 sixPoints(0,0,0) = -1.0; sixPoints(0,0,1) = 1.0;
465 sixPoints(0,1,0) = 1.0; sixPoints(0,1,1) = 0.0;
466 sixPoints(0,2,0) = 0.0; sixPoints(0,2,1) = 1.0;
467 sixPoints(1,0,0) = -1.0; sixPoints(1,0,1) = -1.0;
468 sixPoints(1,1,0) = 0.1; sixPoints(1,1,1) = 0.2;
469 sixPoints(1,2,0) = 0.2; sixPoints(1,2,1) = 0.3;
470 
471 std::cout <<"\t Pointwise inclusion test for Triangle<6>: rank-3 array with six 2D points: \n";
472 
473 CellTools::checkPointwiseInclusion(testSixPoints, sixPoints, tri6);
474 
475 for(int i0 = 0; i0 < sixPoints.dimension(0); i0++){
476  for(int i1 = 0; i1 < sixPoints.dimension(1); i1++) {
477  std::cout << " point(" << i0 << "," << i1 << ") = ("
478  << std::setw(13) << std::right << sixPoints(i0, i1, 0) << ","
479  << std::setw(13) << std::right << sixPoints(i0, i1, 1) << ") ";
480  if( testSixPoints(i0, i1) ) {
481  std::cout << " is inside. \n";
482  }
483  else{
484  std::cout << " is not inside. \n";
485  }
486 
487  }
488 }
489 std::cout << "\n";
490 
491 
492 // Rank-3 array for 6 3D reference points and rank-2 array for the test results
493 FieldContainer<double> six3DPoints(2, 3, 3);
494 FieldContainer<int> testSix3DPoints(2, 3);
495 
496 six3DPoints(0,0,0) = -1.0; six3DPoints(0,0,1) = 1.0; six3DPoints(0,0,2) = 1.0;
497 six3DPoints(0,1,0) = 1.0; six3DPoints(0,1,1) = 1.0; six3DPoints(0,1,2) = -1.0;
498 six3DPoints(0,2,0) = 0.0; six3DPoints(0,2,1) = 1.1; six3DPoints(0,2,2) = 1.0;
499 six3DPoints(1,0,0) = -1.1; six3DPoints(1,0,1) = -1.0; six3DPoints(1,0,2) = -1.0;
500 six3DPoints(1,1,0) = 0.1; six3DPoints(1,1,1) = 0.2; six3DPoints(1,1,2) = 0.2;
501 six3DPoints(1,2,0) = 1.1; six3DPoints(1,2,1) = 0.3; six3DPoints(1,2,2) = 0.3;
502 
503 std::cout <<"\t Pointwise inclusion test for Hexahedron<27>: rank-3 array with six 3D points: \n";
504 
505 CellTools::checkPointwiseInclusion(testSix3DPoints, six3DPoints, hex27);
506 
507 
508 
509 for(int i0 = 0; i0 < six3DPoints.dimension(0); i0++){
510  for(int i1 = 0; i1 < six3DPoints.dimension(1); i1++) {
511  std::cout << " point(" << i0 << "," << i1 << ") = ("
512  << std::setw(13) << std::right << six3DPoints(i0, i1, 0) << ","
513  << std::setw(13) << std::right << six3DPoints(i0, i1, 1) << ","
514  << std::setw(13) << std::right << six3DPoints(i0, i1, 2) << ") ";
515  if( testSix3DPoints(i0, i1) ) {
516  std::cout << " is inside. \n";
517  }
518  else{
519  std::cout << " is not inside. \n";
520  }
521  }
522 }
523 
524 
525 std::cout << std::setprecision(6) << "\n" \
526 << "===============================================================================\n"\
527 << "| EXAMPLE 4-B: Pointwise inclusion test for a physical cell in cell workset |\n"\
528 << "===============================================================================\n";
529 
530 // Rank-2 array for a single set of 5 2D physical points and rank-1 array for the test results
531 FieldContainer<double> fivePoints(5,2);
532 FieldContainer<int> testFivePoints(5);
533 
534 // These points will be tested for inclusion in the last Triangle cell specified by triNodes
535 fivePoints(0, 0) = 2.1 ; fivePoints(0, 1) = 1.0 ; // in
536 fivePoints(1, 0) = 3.0 ; fivePoints(1, 1) = 0.75; // in
537 fivePoints(2, 0) = 3.5 ; fivePoints(2, 1) = 1.9 ; // out
538 fivePoints(3, 0) = 2.5 ; fivePoints(3, 1) = 1.0 ; // in
539 fivePoints(4, 0) = 2.75; fivePoints(4, 1) = 2.0 ; // out
540 
541 CellTools::checkPointwiseInclusion(testFivePoints, fivePoints, triNodes, triangle_3, 3);
542 
543 std::cout << " Vertices of Triangle #3: \n"
544 << "\t(" << triNodes(3, 0, 0) << ", " << triNodes(3, 0, 1) << ")\n"
545 << "\t(" << triNodes(3, 1, 0) << ", " << triNodes(3, 1, 1) << ")\n"
546 << "\t(" << triNodes(3, 1, 0) << ", " << triNodes(3, 1, 1) << ")\n"
547 << " Inclusion test results for the physical points: \n\n";
548 
549 for(int i1 = 0; i1 < fivePoints.dimension(0); i1++) {
550  std::cout << " point(" << i1 << ") = ("
551  << std::setw(13) << std::right << fivePoints(i1, 0) << ","
552  << std::setw(13) << std::right << fivePoints(i1, 1) << ") ";
553  if( testFivePoints(i1) ) {
554  std::cout << " is inside. \n";
555  }
556  else{
557  std::cout << " is not inside. \n";
558  }
559 }
560 std::cout << "\n";
561 
562 
563 
564 std::cout << std::setprecision(6) << "\n" \
565 << "===============================================================================\n"\
566 << "| EXAMPLE 4-C: Pointwise inclusion test for all physical cells in cell workset|\n"\
567 << "===============================================================================\n";
568 
569 // Rank-3 array for 4 sets of 2 2D physical points and rank-2 array for the test results
570 FieldContainer<double> fourPointSets(4, 2, 2);
571 FieldContainer<int> testFourSets(4, 2);
572 
573 // 1st point set - will be tested for inclusion in Triangle #0
574 fourPointSets(0, 0, 0) = 0.25; fourPointSets(0, 0, 1) = 0.75; // in
575 fourPointSets(0, 1, 0) = 0.00; fourPointSets(0, 1, 1) =-0.01; // out
576 
577 // 2nd point set - will be tested for inclusion in Triangle #1
578 fourPointSets(1, 0, 0) = 1.50; fourPointSets(1, 0, 1) = 1.50; // in
579 fourPointSets(1, 1, 0) = 0.99; fourPointSets(1, 1, 1) = 1.50; // out
580 
581 // 3rd point set - will be tested for inclusion in Triangle #2
582 fourPointSets(2, 0, 0) =-0.25; fourPointSets(2, 0, 1) = 0.70; // in
583 fourPointSets(2, 1, 0) = 0.0001; fourPointSets(2, 1, 1) = 0.50; // out
584 
585 // 4th point set - will be tested for inclusion in Triangle #3
586 fourPointSets(3, 0, 0) = 3.00; fourPointSets(3, 0, 1) = 1.00; // in
587 fourPointSets(3, 1, 0) = 3.50; fourPointSets(3, 1, 1) = 0.50; // out
588 
589 CellTools::checkPointwiseInclusion(testFourSets, fourPointSets, triNodes, triangle_3);
590 
591 for(int cell = 0; cell < triNodes.dimension(0); cell++){
592 
593  std::cout << " Testing point set inclusion for Triangle #" << cell << " with vertices \n"
594  << "\t(" << triNodes(cell, 0, 0) << ", " << triNodes(cell, 0, 1) << ")\n"
595  << "\t(" << triNodes(cell, 1, 0) << ", " << triNodes(cell, 1, 1) << ")\n"
596  << "\t(" << triNodes(cell, 1, 0) << ", " << triNodes(cell, 1, 1) << ")\n"
597  << " Results for physical point set indexed by the cell ordinal " << cell << " \n\n";
598 
599  for(int i1 = 0; i1 < fourPointSets.dimension(1); i1++) {
600  std::cout << " point(" << i1 << ") = ("
601  << std::setw(13) << std::right << fourPointSets(cell, i1, 0) << ","
602  << std::setw(13) << std::right << fourPointSets(cell, i1, 1) << ") ";
603  if( testFourSets(cell, i1) ) {
604  std::cout << " is inside Triangle #" << cell << " \n";
605  }
606  else{
607  std::cout << " is outside Triangle #" << cell << " \n";
608  }
609  }
610  if(cell < triNodes.dimension(0) - 1) {
611  std::cout << "-------------------------------------------------------------------------------\n";
612  }
613  else{
614  std::cout <<" \n";
615  }
616 }// cell
617 
618 
619 
620 std::cout << "\n" \
621 << "===============================================================================\n"\
622 << "| EXAMPLE 5: Using point set inclusion test method |\n"\
623 << "===============================================================================\n";
624 
625 std::cout <<"\t Point set inclusion test for Triangle<6>: rank-2 array with four 2D point: \n";
626 
627 if( CellTools::checkPointsetInclusion(fourPoints, tri6) ) {
628  std::cout << "\t - All points are inside the reference Triangle<6> cell. \n\n ";
629 }
630 else{
631  std::cout << "\t - At least one point is not inside the reference Triangle<6> cell. \n\n";
632 }
633 
634 std::cout <<"\t Point set inclusion test for Hexahedron<27>: rank-3 array with six 3D point: \n";
635 
636 if( CellTools::checkPointsetInclusion(six3DPoints, hex27) ) {
637  std::cout << "\t - All points are inside the reference Hexahedron<27> cell. \n\n ";
638 }
639 else{
640  std::cout << "\t - At least one point is not inside the reference Hexahedron<27> cell. \n\n";
641 }
642 
643 
644 
645 std::cout << std::setprecision(4) << "\n" \
646 << "===============================================================================\n"\
647 << "| EXAMPLE 6: mapping a single point set to physical cells with base topology |\n"\
648 << "===============================================================================\n";
649 
650 // Rank-3 array with dimensions (P, D) for points on the reference triangle
651 FieldContainer<double> refTriPoints(3,triangle_3.getDimension() );
652 refTriPoints(0,0) = 0.2; refTriPoints(0,1) = 0.0; // on edge 0
653 refTriPoints(1,0) = 0.4; refTriPoints(1,1) = 0.6; // on edge 1
654 refTriPoints(2,0) = 0.0; refTriPoints(2,1) = 0.8; // on edge 2
655 
656 // Reference points will be mapped to physical cells with vertices in triNodes: define the appropriate array
657 FieldContainer<double> physTriPoints(triNodes.dimension(0), // cell count
658  refTriPoints.dimension(0), // point count
659  refTriPoints.dimension(1)); // point dimension (=2)
660 
661 CellTools::mapToPhysicalFrame(physTriPoints, refTriPoints, triNodes, triangle_3);
662 
663 for(int cell = 0; cell < triNodes.dimension(0); cell++){
664  std::cout << "====== Triangle " << cell << " ====== \n";
665  for(int pt = 0; pt < refTriPoints.dimension(0); pt++){
666  std::cout
667  << "("
668  << std::setw(13) << std::right << refTriPoints(pt,0) << ","
669  << std::setw(13) << std::right << refTriPoints(pt,1) << ") -> "
670  << "("
671  << std::setw(13) << std::right << physTriPoints(cell, pt, 0) << ","
672  << std::setw(13) << std::right << physTriPoints(cell, pt, 1) << ") \n";
673  }
674  std::cout << "\n";
675 }
676 
677 
678 std::cout << std::setprecision(4) << "\n" \
679 << "===============================================================================\n"\
680 << "| EXAMPLE 7: mapping a single point set to physical cells with ext. topology |\n"\
681 << "===============================================================================\n";
682 /*
683  * This example illustrates reference-to-physical mapping for a triangle with curved sides. The
684  * physical curved triangle is defined as follows:
685  *
686  * - edge 0: starts at (1, -1/2) ends at (1,1) and is a vertical line segment
687  * - edge 1: starts at (1,1) ends at (0,0) and is parabolic segment lying on y=x^2
688  * - edge 2: starts at (0,0) ends at (1,-1/2) and is parabolic segment lying on y = -1/2 x^2
689  *
690  * The triangle is uniquely specified by its 3 vertices and 3 edge points. Therefore, to compute the
691  * map from reference to physical coordinates we specify Triangle<6> topology.
692  */
693 
694 // A (C,V,D) array with the 6 nodes of the physical Triangle<6>
695 FieldContainer<double> tri6Nodes(1,6,2);
696 tri6Nodes(0,0,0) = 1.0; tri6Nodes(0,0,1) = -0.5;
697 tri6Nodes(0,1,0) = 1.0; tri6Nodes(0,1,1) = 1.0;
698 tri6Nodes(0,2,0) = 0.0; tri6Nodes(0,2,1) = 0.0;
699 
700 tri6Nodes(0,3,0) = 1.0; tri6Nodes(0,3,1) = 0.0;
701 tri6Nodes(0,4,0) = 0.5; tri6Nodes(0,4,1) = 0.25;
702 tri6Nodes(0,5,0) = 0.5; tri6Nodes(0,5,1) = -0.125;
703 
704 // A (P, D) array with the 6 nodes of the reference Triangle<6> plus some extra points
705 FieldContainer<double> refTri6Points(9,2);
706 refTri6Points(0,0) = 0.0; refTri6Points(0,1) = 0.0;
707 refTri6Points(1,0) = 1.0; refTri6Points(1,1) = 0.0;
708 refTri6Points(2,0) = 0.0; refTri6Points(2,1) = 1.0;
709 
710 refTri6Points(3,0) = 0.5; refTri6Points(3,1) = 0.0;
711 refTri6Points(4,0) = 0.5; refTri6Points(4,1) = 0.5;
712 refTri6Points(5,0) = 0.0; refTri6Points(5,1) = 0.5;
713 
714 refTri6Points(6,0) = 0.75; refTri6Points(6,1) = 0.0; // on ref edge 0
715 refTri6Points(7,0) = 0.25; refTri6Points(7,1) = 0.75; // on ref edge 1
716 refTri6Points(8,0) = 0.00; refTri6Points(8,1) = 0.25; // on ref edge 2
717 
718 // A (C,P,D) array for the images of the reference points in physical frame
719 FieldContainer<double> physTri6Points(tri6Nodes.dimension(0), // cell count
720  refTri6Points.dimension(0), // point count
721  refTri6Points.dimension(1)); // point dimension (=2)
722 
723 // Define the cell topology: use the extended Triangle<6> topology to fit the curved edges
724 CellTopology triangle_6(shards::getCellTopologyData<Triangle<6> >() );
725 
726 //
727 CellTools::mapToPhysicalFrame(physTri6Points, refTri6Points, tri6Nodes, triangle_6);
728 
729 for(int cell = 0; cell < tri6Nodes.dimension(0); cell++){
730  std::cout << "====== Triangle " << cell << " ====== \n";
731  for(int pt = 0; pt < refTri6Points.dimension(0); pt++){
732  std::cout
733  << "("
734  << std::setw(13) << std::right << refTri6Points(pt,0) << ","
735  << std::setw(13) << std::right << refTri6Points(pt,1) << ") -> "
736  << "("
737  << std::setw(13) << std::right << physTri6Points(cell, pt, 0) << ","
738  << std::setw(13) << std::right << physTri6Points(cell, pt, 1) << ") \n";
739  }
740  std::cout << "\n";
741 }
742 
743 
744 
745 std::cout << "\n" \
746 << "===============================================================================\n"\
747 << "| EXAMPLE 8: mapping a single physical point set to reference frame |\n"\
748 << "===============================================================================\n";
749 /*
750  * This example shows use of mapToReferenceFrame with rank-2 array (P,D) of points in physical frame.
751  * Points are mapped back to reference frame using the mapping for one of the physical cells whose
752  * nodes are passed as an argument. Therefore, this use case requires a valid cell ordinal (relative
753  * to the nodes array) to be specified. The output array for the images of the points is also rank-2 (P,D).
754  *
755  */
756 // Rank-2 arrays with dimensions (P, D) for physical points and their preimages
757 FieldContainer<double> physPoints(5, triangle_3.getDimension() );
758 FieldContainer<double> preImages (5, triangle_3.getDimension() );
759 
760 // First 3 points are the vertices of the last triangle (ordinal = 3) stored in triNodes
761 physPoints(0,0) = triNodes(3, 0, 0); physPoints(0,1) = triNodes(3, 0, 1) ;
762 physPoints(1,0) = triNodes(3, 1, 0); physPoints(1,1) = triNodes(3, 1, 1);
763 physPoints(2,0) = triNodes(3, 2, 0); physPoints(2,1) = triNodes(3, 2, 1);
764 
765 // last 2 points are just some arbitrary points contained in the last triangle
766 physPoints(3,0) = 3.0; physPoints(3,1) = 1.0;
767 physPoints(4,0) = 2.5; physPoints(4,1) = 1.1;
768 
769 
770 // Map physical points from triangle 3 to the reference frame
771 int whichCell = 3;
772 CellTools::mapToReferenceFrame(preImages, physPoints, triNodes, triangle_3, whichCell );
773 
774 std::cout << " Mapping from Triangle #"<< whichCell << " with vertices: \n"
775 << "\t(" << triNodes(whichCell, 0, 0) << ", " << triNodes(whichCell, 0, 1) << ")\n"
776 << "\t(" << triNodes(whichCell, 1, 0) << ", " << triNodes(whichCell, 1, 1) << ")\n"
777 << "\t(" << triNodes(whichCell, 1, 0) << ", " << triNodes(whichCell, 1, 1) << ")\n\n"
778 << " Physical points and their reference cell preimages: \n";
779 
780 for(int pt = 0; pt < physPoints.dimension(0); pt++){
781  std::cout
782  << "(" << std::setw(13) << std::right << physPoints(pt,0) << ","
783  << std::setw(13) << std::right << physPoints(pt,1) << ") -> "
784  << "("
785  << std::setw(13) << std::right << preImages(pt, 0) << ","
786  << std::setw(13) << std::right << preImages(pt, 1) << ") \n";
787 }
788 std::cout << "\n";
789 
790 // As a check, map pre-images back to Triangle #3
791 FieldContainer<double> images(5, triangle_3.getDimension() );
792 CellTools::mapToPhysicalFrame(images, preImages, triNodes, triangle_3, whichCell);
793 
794 std::cout << " Check: map preimages back to Triangle #3: \n";
795 for(int pt = 0; pt < images.dimension(0); pt++){
796  std::cout
797  << "(" << std::setw(13) << std::right << preImages(pt,0) << ","
798  << std::setw(13) << std::right << preImages(pt,1) << ") -> "
799  << "("
800  << std::setw(13) << std::right << images(pt, 0) << ","
801  << std::setw(13) << std::right << images(pt, 1) << ") \n";
802 }
803 std::cout << "\n";
804 
805 
806 std::cout << "\n" \
807 << "===============================================================================\n"\
808 << "| EXAMPLE 9: mapping physical point sets on a cell workset to reference frame |\n"\
809 << "===============================================================================\n";
810 /*
811  * This example shows use of mapToReferenceFrame with rank-3 array (C,P,D) of points in physical frame.
812  * For each cell ordinal (relative to the nodes array), the associated point set is mapped back to
813  * reference frame using the mapping corresponding to the physical cell with that ordinal. This use case
814  * requires the default value -1 for the cell ordinal. The output array for the images of the points
815  * is also rank-3 (C,P,D).
816  *
817  */
818 // Rank-3 arrays with dimensions (C, P, D) for physical points and their preimages
819 FieldContainer<double> physPointSets(triNodes.dimension(0), 2, triangle_3.getDimension() );
820 FieldContainer<double> preImageSets (triNodes.dimension(0), 2, triangle_3.getDimension() );
821 
822 // Point set on Triangle #0
823 physPointSets(0,0,0) = 0.25; physPointSets(0,0,1) = 0.25;
824 physPointSets(0,1,0) = 0.50; physPointSets(0,1,1) = 0.50;
825 
826 // Point set on Triangle #1
827 physPointSets(1,0,0) = 1.00; physPointSets(1,0,1) = 1.00;
828 physPointSets(1,1,0) = 1.25; physPointSets(1,1,1) = 1.75;
829 
830 // Point set on Triangle #2
831 physPointSets(2,0,0) =-0.25; physPointSets(2,0,1) = 0.25;
832 physPointSets(2,1,0) =-0.50; physPointSets(2,1,1) = 0.50;
833 
834 // Point set on Triangle #3
835 physPointSets(3,0,0) = 3.00; physPointSets(3,0,1) = 1.00;
836 physPointSets(3,1,0) = 2.00; physPointSets(3,1,1) = 1.00;
837 
838 
839 // Map physical point sets to reference frame: requires default value of cell ordinal (skip last arg)
840 CellTools::mapToReferenceFrame(preImageSets, physPointSets, triNodes, triangle_3);
841 
842 for(int cell = 0; cell < triNodes.dimension(0); cell++){
843  std::cout << "====== Triangle " << cell << " ====== \n";
844  for(int pt = 0; pt < physPointSets.dimension(1); pt++){
845  std::cout
846  << "("
847  << std::setw(13) << std::right << physPointSets(cell, pt, 0) << ","
848  << std::setw(13) << std::right << physPointSets(cell, pt, 1) << ") -> "
849  << "("
850  << std::setw(13) << std::right << preImageSets(cell, pt, 0) << ","
851  << std::setw(13) << std::right << preImageSets(cell, pt, 1) << ") \n";
852  }
853  std::cout << "\n";
854 }
855 
856 // As a check, map preImageSets back to physical frame
857 FieldContainer<double> postImageSets(triNodes.dimension(0), 2, triangle_3.getDimension() );
858 
859 CellTools::mapToPhysicalFrame(postImageSets, preImageSets, triNodes, triangle_3);
860 
861 std::cout << " Check: map preimages back to Triangles: \n";
862 for(int cell = 0; cell < triNodes.dimension(0); cell++){
863  std::cout << "====== Triangle " << cell << " ====== \n";
864  for(int pt = 0; pt < preImageSets.dimension(1); pt++){
865  std::cout
866  << "("
867  << std::setw(13) << std::right << preImageSets(cell, pt, 0) << ","
868  << std::setw(13) << std::right << preImageSets(cell, pt, 1) << ") -> "
869  << "("
870  << std::setw(13) << std::right << postImageSets(cell, pt, 0) << ","
871  << std::setw(13) << std::right << postImageSets(cell, pt, 1) << ") \n";
872  }
873  std::cout << "\n";
874 }
875 
876 return 0;
877 }
878 
879 
880 
881 
882 
883 
884 
885 
886 
887 
888 
889 
890 
891 
892 
893 
894 
895 
896 
897 
898 
899 
900 
901 
902 
903 
904 
905 
Implementation of basic linear algebra functionality in Euclidean space.
Header file for the Intrepid::CellTools class.
Header file for utility class to provide multidimensional containers.
Header file for classes providing basic linear algebra functionality in 1D, 2D and 3D...
A stateless class for operations on cell data. Provides methods for: