00001 #pragma once 00002 00003 #include <algorithm> 00004 #include <assert.h> 00005 #include "gfemOverlapCondition.h" 00006 #include "unitcell.h" 00007 #include "hp2D/quadFunctions.hh" 00008 00009 namespace concepts { 00010 namespace gfem { 00011 00012 struct GfemDofIterator 00013 { 00014 GfemDofIterator(const GfemOverlapCondition& overC, const Unitcell& uc, const int p_macro[2]) 00015 : overC(overC) 00016 , uc(uc) 00017 , i_t(0) 00018 , i_macroX(0) 00019 , i_macroY(0) 00020 , i_micro(0) 00021 { 00022 this->p_macro[0] = p_macro[0]; 00023 this->p_macro[1] = p_macro[1]; 00024 } 00025 00026 void print() const; 00027 00029 GfemDofIterator& operator++() 00030 { 00031 #if 0 00032 ++i_macroY; 00033 if(i_macroY > nMacroY()) { 00034 i_macroY = 0; 00035 ++i_macroX; 00036 if(i_macroX > nMacroX()) { 00037 i_macroX = 0; 00038 } 00039 } 00040 #endif 00041 00042 ++i_t; 00043 update(i_t); 00044 00045 return *this; 00046 } 00047 00052 void updateLdof(int i_micro, int i_macroX, int i_macroY) { 00053 i_t = overC.nDofs(); 00054 00055 int i_macro = i_macroY * nMacroX() + i_macroX; 00056 i_t += i_macro * numUC() + i_micro; 00057 } 00058 00059 void updateLdof(int i_vert) { 00060 i_t = overC.disabledVertDof(i_vert); 00061 } 00062 00069 void updateLdof(int i_edge, int i_shape) { 00070 assert(i_shape < overC.edgeDofs(i_edge) ); 00071 00072 i_t = overC.nVertDofs(); 00073 00074 for(int i=0; i < i_edge; ++i) 00075 if(overC.edgeDisabled(i)) 00076 i_t += overC.edgeDofs(i); 00077 00078 i_t += i_shape; 00079 } 00080 00081 bool update(int i_t) { 00082 this->i_t = i_t; 00083 if(i_t < overC.nDofs()) { 00084 i_micro = i_t; 00085 i_macroX = -1; 00086 i_macroY = -1; 00087 00088 return true; 00089 } 00090 00091 i_t -= overC.nDofs(); 00092 00093 int i_macro = i_t / numUC(); 00094 i_micro = i_t % numUC() + overC.nMicro(); 00095 00096 i_macroY = i_macro / nMacroX(); 00097 i_macroX = i_macro % nMacroX(); 00098 00099 return i_macroY < nMacroY(); 00100 } 00101 00102 void updateVertMacro(int i_vert) 00103 { 00104 uint ll[2]; 00105 hp2D::QuadFunctions::vertexIndex(i_vert, ll); 00106 00107 i_macroX = ll[0]; 00108 i_macroY = ll[1]; 00109 } 00110 00111 void updateEdgeMacro(int i_edge, int i_t) 00112 { 00113 uint pIndex = 0, qIndex = 0; 00114 uint ll[2]; 00115 hp2D::QuadFunctions::edgeOrientation(i_edge, pIndex, qIndex); 00116 hp2D::QuadFunctions::edgeIndex(i_edge, qIndex, ll); 00117 00118 ll[pIndex] = i_t + 2; 00119 00120 i_macroX = ll[0]; 00121 i_macroY = ll[1]; 00122 } 00123 00124 void setPMax(int p_max[2]) { 00125 p_macro[0] = p_max[0]; 00126 p_macro[1] = p_max[1]; 00127 } 00128 00129 int numUC() const { 00130 return uc.size(); 00131 } 00132 00133 int nMacroX() const { 00134 return p_macro[0]+1; 00135 } 00136 00137 int nMacroY() const { 00138 return p_macro[1]+1; 00139 } 00140 00141 bool isFinished() const { 00142 return i_t >= numLdofs(); 00143 } 00144 00145 int nDofs() const { 00146 return numLdofs(); 00147 } 00148 00149 int numLdofs() const { 00150 return nMacroX() * nMacroY() * numUC() + overC.nDofs(); 00151 } 00152 00153 //private: 00154 00155 const GfemOverlapCondition& overC; 00156 const Unitcell& uc; 00157 int i_t; 00158 int i_macroX; 00159 int i_macroY; 00160 int i_micro; 00161 int p_macro[2]; 00162 }; 00163 00164 } // namespace 00165 } // namespace