00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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";
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;
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;
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 }