00001 #ifndef ES_HPP 00002 #define ES_HPP 00003 00007 00008 00009 #include <cinttypes> 00010 #include <omp.h> 00011 #include <vector> 00012 00013 #include "dbg.h" 00014 #include "compressed_mesh.hpp" 00015 00016 namespace fpcm 00017 { 00018 00019 template< typename F, template<class T, class = std::allocator<T> > class container_type = std::vector > 00020 int container_in_memory_size (const container_type<F> & c) { 00021 return sizeof(c) + c.size()*sizeof(typename container_type<F>::value_type); 00022 } 00023 00030 namespace ES { 00031 00032 typedef int ID; 00033 00034 typedef int GUID; 00035 00036 typedef void* pType; 00037 00038 typedef unsigned char ComponentFlag; 00039 00040 typedef unsigned char Assemblage; 00041 00042 // Components 00043 typedef int Materialable; 00044 //struct Materialable { 00045 // static const int ComponentNo = 0; 00046 // int material_id; 00047 //}; 00048 00049 struct SubTypeable { 00050 static const int ComponentNo = 1; 00051 pType type; 00052 }; 00053 00054 struct Hierarchical { 00055 static const int ComponentNo = 2; 00056 ID parent; 00057 }; 00058 00059 struct Adaptable { 00060 static const int ComponentNo = 3; 00061 int8_t n_sons; 00062 ID first_son; 00063 }; 00064 template<int8_t Tmax_vert> 00065 struct Verticable { 00066 static const int ComponentNo = 4; 00067 ID v[Tmax_vert]; 00068 //ID* vts_offset; 00069 }; 00070 00071 struct Neigborable{ 00072 static const int ComponentNo = 5; 00073 ID neigs[2]; 00074 }; 00075 00076 struct CrossLinkable { 00077 static const int ComponentNo = 6; 00078 int other_subdomain; 00079 int elem_on_other_side; 00080 }; 00081 00082 //struct Patterable { 00083 // static const int ComponentNo = 7; 00084 // int base; 00085 // int pattern; 00086 //}; 00087 00088 template<typename TComp> 00089 ComponentFlag flagOf() { 00090 return 1<<TComp::ComponentNo; 00091 } 00092 00093 00095 //struct Storages{ 00096 // std::vector<Verticable> verticables; 00097 // std::vector<Neigborable> neigborables; 00098 // std::vector<Adaptable> adaptables; 00099 //}; 00100 00101 //using CompressedMesh::PTID; 00102 //struct Mesh { 00103 // std::vector<PTID> points; 00104 // std::vector<GUID> edges; 00105 // std::vector<GUID> faces; 00106 // std::vector<GUID> elements; 00107 //}; 00108 00109 00110 // Assemblages 00111 //static const Assemblage 00112 //VertexAssemblage = flagOf<Coordinable>() & flagOf<Hierarchical>(), // VertexAssemblage 00113 //EdgeAssemblage = flagOf<Hierarchical>() & flagOf<Adaptable>() & flagOf<Verticable>(),// EdgeAssemblage 00114 //FaceAssemblage = flagOf<Hierarchical>() & flagOf<Adaptable>() & flagOf<Verticable>() & flagOf<SubTypeable>() & flagOf<Neigborable>(), // Face assemblage 00115 //ElementAssemblage = flagOf<Hierarchical>() & flagOf<Adaptable>() & flagOf<Verticable>() & flagOf<SubTypeable>(); // Elements assemblage 00116 00117 //int PatterableProcessor(const ID *toCategorize[], const int n_entities, const int max_length, Patterable* categorized) { 00118 // for(int i=0; i < n_entities; ++i) { 00119 // categorized[i].base = std::min_element(toCategorize[i],toCategorize[i]+max_length); 00120 // categorized[i].pattern = GetPattern(toCategorize[i]+1,max_length-1); 00121 // } 00122 //} 00123 00124 //inline int GetPattern(const ID* sequence,int length) { 00125 // int patternID=0; 00126 00127 // assert(length > 0); 00128 00129 // while(--length) { 00130 // patterns[sequence] 00131 // } 00132 00133 // return patternID; 00134 //} 00135 00136 //template<typename TComponent> 00137 //TComponent& getAs(GUID id) { 00138 // storages[TComponent::ComponentNo][GUID]; 00139 //} 00140 00141 //GUID newGUID(const size_t count) { 00142 // static GUID lastGUID = 1; 00143 // const GUID ret; 00144 //#pragma omp atomic capture 00145 // ret=(lastGUID+=count); 00146 00147 // return (ret-count); 00148 //} 00149 00150 //int CreationProcessor(const GUID* toCreateEntities, const size_t count, const Assemblage& entitiesAssemblage) { 00151 // GUID* toCreatePtr = toCreateEntities; 00152 // const GUID* endPtr = toCreateEntities+count; 00153 00154 // for(;toCreatePtr != endPtr; ++toCreatePtr) { 00155 00156 // } 00157 //} 00158 00159 //struct AdaptationScheme { 00160 // size_t n_entities; 00161 // Adaptable* toAdaptStorage; 00162 // Assemblage newEntityAssemblage; 00163 00164 // int newPerAdaptable=8; 00165 //}; 00166 00167 00168 00169 //int AdaptationProcessor(const int count) 00170 //{ 00171 // // toAdapt -> undivided + adopted 00172 // Hierarchical* toAdapt; 00173 00174 // const Hierarchical* hPtr = undivided.add(count*8); 00175 // const Adaptable* aPtr = adopted.add(count); 00176 00177 //#pragma omp parallel for 00178 // for(int a=0;a < n;++a) { 00179 // hPtr[a].parent = GUID(toAdapt[a]); 00180 // aPtr[a].first_son = GUID(hPtr[a]); 00181 // aPtr[a].n_sons = 00182 // } 00183 //} 00184 00186 //int AdaptationProcessor2(const GUID* toAdaptEntities, GUID* adoptedEntities, GUID* createdEntities, const AdaptationScheme & scheme) 00187 //{ 00188 // const int limit = scheme.n_entities*scheme.newPerAdaptable; 00189 // GUID baseGUID = newGUID(limit); 00190 00191 // GUID* toAdaptPtr = toAdaptEntities; 00192 00193 // for(int a=0; a < limit; ++a) { 00194 // getAs<Adaptable>(toAdaptEntities[a]).first_son = baseGUID; 00195 // getAs<Adaptable>(toAdaptEntities[a]).n_sons = scheme.newPerAdaptable; 00196 // } 00197 // return 0; 00198 //} 00199 00200 00202 00203 00204 00205 } 00206 } 00207 00208 00209 #endif // ES_HPP