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 #include <iostream>
00027 #include <iomanip>
00028
00029 #include <IndexType.H>
00030
00031 IndexType::IndexType (const IntVect& iv)
00032 {
00033 itype = D_TERM((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2));
00034 }
00035
00036 IndexType::IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k))
00037 {
00038 itype = D_TERM(i, | (j<<1), | (k<<2));
00039 }
00040
00041 void
00042 IndexType::setType (int dir,
00043 CellIndex t)
00044 {
00045 t == CELL ? unset(dir) : set(dir);
00046 }
00047
00048 IndexType::CellIndex
00049 IndexType::ixType (int dir) const
00050 {
00051 return (CellIndex) ((itype & (1<<dir)) >> dir);
00052 }
00053
00054 IntVect
00055 IndexType::ixType () const
00056 {
00057 return IntVect(D_DECL(itype&1, (itype>>1)&1, (itype>>2)&1));
00058 }
00059
00060 IndexType
00061 IndexType::TheCellType ()
00062 {
00063 static const IndexType Cell(D_DECL(IndexType::CELL,
00064 IndexType::CELL,
00065 IndexType::CELL));
00066 return Cell;
00067 }
00068
00069 IndexType
00070 IndexType::TheNodeType ()
00071 {
00072 static const IndexType Node(D_DECL(IndexType::NODE,
00073 IndexType::NODE,
00074 IndexType::NODE));
00075 return Node;
00076 }
00077
00078
00079 IndexType
00080 IndexType::TheUMACType ()
00081 {
00082 static const IndexType Node(D_DECL(IndexType::NODE,
00083 IndexType::CELL,
00084 IndexType::CELL));
00085 return Node;
00086 }
00087 IndexType
00088 IndexType::TheVMACType ()
00089 {
00090 static const IndexType Node(D_DECL(IndexType::CELL,
00091 IndexType::NODE,
00092 IndexType::CELL));
00093 return Node;
00094 }
00095 IndexType
00096 IndexType::TheWMACType ()
00097 {
00098 static const IndexType Node(D_DECL(IndexType::CELL,
00099 IndexType::CELL,
00100 IndexType::NODE));
00101 return Node;
00102 }
00103
00104 std::ostream&
00105 operator<< (std::ostream& os,
00106 const IndexType& it)
00107 {
00108 os << '('
00109 << D_TERM( (it.test(0)?'N':'C'),
00110 << ',' << (it.test(1)?'N':'C'),
00111 << ',' << (it.test(2)?'N':'C')) << ')' << std::flush;
00112
00113 if (os.fail())
00114 BoxLib::Error("operator<<(ostream&,IndexType&) failed");
00115
00116 return os;
00117 }
00118
00119
00120
00121
00122 #define BL_IGNORE_MAX 100000
00123
00124 std::istream&
00125 operator>> (std::istream& is,
00126 IndexType& it)
00127 {
00128 char D_DECL(t0,t1,t2);
00129
00130 D_EXPR( is.ignore(BL_IGNORE_MAX, '(') >> t0,
00131 is.ignore(BL_IGNORE_MAX, ',') >> t1,
00132 is.ignore(BL_IGNORE_MAX, ',') >> t2);
00133 is.ignore(BL_IGNORE_MAX, ')');
00134 D_TERM(
00135 BL_ASSERT(t0 == 'C' || t0 == 'N'); t0=='N'?it.set(0):it.unset(0); ,
00136 BL_ASSERT(t1 == 'C' || t1 == 'N'); t1=='N'?it.set(1):it.unset(1); ,
00137 BL_ASSERT(t2 == 'C' || t2 == 'N'); t2=='N'?it.set(2):it.unset(2));
00138
00139 if (is.fail())
00140 BoxLib::Error("operator>>(ostream&,IndexType&) failed");
00141
00142 return is;
00143 }