SundanceCellType.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #include "SundanceCellType.hpp"
00032 #include "PlayaExceptions.hpp"
00033 
00034 using namespace Sundance;
00035 using namespace Sundance;
00036 
00037 namespace Sundance
00038 {
00039 
00040   std::string toString(const CellType& cellType)
00041   {
00042     switch(cellType)
00043       {
00044       case NullCell:
00045         return "NullCell";
00046       case PointCell:
00047         return "PointCell";
00048       case LineCell:
00049         return "LineCell";
00050       case TriangleCell:
00051         return "TriangleCell";
00052       case QuadCell:
00053         return "QuadCell";
00054       case TetCell:
00055         return "TetCell";
00056       case BrickCell:
00057         return "BrickCell";
00058       case PrismCell:
00059         return "PrismCell";
00060       }
00061     return "NullCell"; // -Wall
00062   }
00063 
00064   int dimension(const CellType& cellType)
00065   {
00066     switch(cellType)
00067       {
00068       case NullCell:
00069         return -1;
00070       case PointCell:
00071         return 0;
00072       case LineCell:
00073         return 1;
00074       case TriangleCell:
00075       case QuadCell:
00076         return 2;
00077       case TetCell:
00078       case BrickCell:
00079       case PrismCell:
00080         return 3;
00081       }
00082     return -1; // -Wall
00083   }
00084 
00085   int numFacets(const CellType& cellType, int facetDim)
00086   {
00087     int d = dimension(cellType);
00088     if (facetDim == d) return 1;
00089 
00090     TEUCHOS_TEST_FOR_EXCEPTION(facetDim > d, std::runtime_error,
00091                        "invalid facet dim " << facetDim << " for cell "
00092                        << toString(cellType));
00093 
00094     switch(cellType)
00095       {
00096       case NullCell:
00097       case PointCell:
00098         return -1;
00099       case LineCell:
00100         return 2;
00101       case TriangleCell:
00102         return 3;
00103       case TetCell:
00104         if (facetDim==0 || facetDim==2) return 4;
00105         return 6;
00106       case QuadCell:
00107         return 4;
00108       case BrickCell:
00109         if (facetDim==0) return 8;
00110         else if (facetDim==1) return 12;
00111         else return 6;
00112       case PrismCell:
00113         if (facetDim==0) return 6;
00114         else if (facetDim==1) return 9;
00115         else return 5;
00116       }
00117     return -1; // -Wall
00118   }
00119 
00120 
00121   CellType facetType(const CellType& cellType, int facetDim, int facetIndex)
00122   {
00123     int d = dimension(cellType);
00124     if (facetDim == d) return cellType;
00125     TEUCHOS_TEST_FOR_EXCEPTION(facetDim > d, std::runtime_error,
00126                        "invalid facet dim " << facetDim << " for cell "
00127                        << toString(cellType));
00128 
00129     if (facetDim==0) return PointCell;
00130     if (facetDim==1) return LineCell;
00131 
00132     switch(cellType)
00133       {
00134       case NullCell:
00135       case PointCell:
00136       case LineCell:
00137       case TriangleCell:
00138       case QuadCell:
00139         return NullCell;
00140 
00141       case TetCell:
00142         return TriangleCell;
00143       case BrickCell:
00144         return QuadCell;
00145       case PrismCell:
00146         if (facetIndex==0 || facetIndex==4) return TriangleCell;
00147         return QuadCell;
00148       }
00149     return NullCell;
00150   }
00151   
00152 }

Site Contact