FiberVISH 0.2
Fish - The Fiber Bundle API for the Vish Visualization Shell
Cell.hpp
1#ifndef __FIBER_FIELD_CELL_HPP
2#define __FIBER_FIELD_CELL_HPP
3
4#include "FiberType.hpp"
5#include <vector/MultiIndex.hpp>
6#include <eagle/FixedArray.hpp>
7
8namespace Fiber
9{
10
16{
17static const char*ComponentName(int i)
18 {
19 static const char IJ[2][2] = { "i", "j" };
20 return IJ[i];
21 }
22};
23
24
40template <Eagle::dimension_t DIMS, Eagle::dimension_t Elements, class IndexType>
41struct Cell : public Eagle::FixedArray<IndexType, Elements>
42{
43 enum { Dims = DIMS };
44
47
48// using FixedArray_t::operator=;
49
51 Cell()
52 {}
53
54 Cell(const Cell&C)
56 {}
57
61 {}
62};
63
64
68template <Eagle::dimension_t Dims, class IndexType, class NamingConvention = IJ_CellNamingConvention>
69struct SimplexCell : Cell<Dims, Dims+1, IndexType>
70{
72
73// using Base_t::operator=;
74
77 {}
78
80 : Base_t(SC)
81 {}
82
85 : Base_t(Init)
86 {}
87
88
89static std::string coordinate_name(int i)
90 {
91 return ( (i<=Dims-1)? NamingConvention::ComponentName(0) : NamingConvention::ComponentName(1) )
92 +
94
95 }
96};
97
98template <class IndexType>
99struct SimplexCell<0, IndexType> : Cell<0, 1, IndexType>
100{
102
105 {}
106
108 : Base_t(SC)
109 {}
110
113 : Base_t(Init)
114 {}
115
116
117static std::string coordinate_name(int i)
118 {
119 return "";
120 }
121};
122
123
127template <int Dims, class IndexType, class NamingConvention = IJ_CellNamingConvention>
128struct RegularCell : Cell<Dims, (1<<Dims), IndexType>
129{
130 typedef Cell<Dims, (1<<Dims), IndexType > Base_t;
131
132// using Base_t::operator=;
133
135 RegularCell()
136 {}
137
138 RegularCell(const RegularCell&RC)
139 : Base_t(RC)
140 {}
141
143 RegularCell(const std::initializer_list<IndexType>&Init)
144 : Base_t(Init)
145 {}
146
147
148static std::string coordinate_name(int i)
149 {
150 return RegularCell<Dims-1, IndexType>::coordinate_name(i>>1) +
151 NamingConvention::ComponentName( i & 1 );
152 }
153};
154
155template <class IndexType, class NamingConvention>
156struct RegularCell<0, IndexType, NamingConvention>
157{
158static std::string coordinate_name(int i)
159 {
160 return "";
161 }
162};
163
164
165
167template <class IndexType>
168union uEdge
169{
170 SimplexCell<1,IndexType> Cell;
171
172 struct NamedEdge
173 {
174 IndexType i,j;
175 }
176 Named;
177};
178
179
181template <class IndexType>
182union uTriangle
183{
184 SimplexCell<2,IndexType> Cell;
185
186 struct NamedTriangle
187 {
188 IndexType ii,ij,jj;
189 }
190 Named;
191
192 struct ijkTriangle
193 {
194 IndexType i,j,k;
195
196 }
197 ijk;
198};
199
201template <class IndexType>
202union uTetrahedron
203{
204 SimplexCell<3,IndexType> Cell;
205
206 struct NamedTetrahedron
207 {
208 IndexType iii,iij,ijj,jjj;
209 }
210 Named;
211};
212
213
215template <class IndexType>
216union uQuad
217{
218 RegularCell<2, IndexType> Cell;
219
220 struct NamedQuad
221 {
222 IndexType ii,ij,ji,jj;
223 }
224 Named;
225
226};
227
228
230template <class IndexType>
231union uHexaHedron
232{
233 RegularCell<3, IndexType> Cell;
234
235 struct NamedHexaHedron
236 {
237 IndexType iii,iij,iji,ijj,jii,jij,jji,jjj;
238 }
239 Named;
240};
241
242
243template<class IndexType, class NamingConvention = IJ_CellNamingConvention>
244struct DihedralCell : Cell< 1, 4, IndexType>
245{
246 typedef Cell<1, 4, IndexType> Base_t;
247
248 DihedralCell(){}
249
250 DihedralCell(const DihedralCell&SC)
251 : Base_t(SC)
252 {}
253
254 DihedralCell(const std::initializer_list<IndexType>&Init)
255 : Base_t(Init)
256 {}
257
258
259static std::string coordinate_name(int i)
260 {
261 if( i == 0 ) return "i";
262 else if( i == 1 ) return "j";
263 else if( i == 2 ) return "k";
264 else if( i == 3 ) return "l";
265 }
266
267 // Flip dihedral values if first index is not lower than the last
268 void unify()
269 {
270 if( (*this)[0] > (*this)[3] )
271 {
272 IndexType tmp = (*this)[0];
273 (*this)[0] = (*this)[3];
274 (*this)[3] = tmp;
275
276 tmp = (*this)[1];
277 (*this)[1] = (*this)[2];
278 (*this)[2] = tmp;
279 }
280 }
281
282 bool operator == (DihedralCell const& rhs) const
283 {
284 for( unsigned i = 0; i < 4; ++i)
285 if( (*this)[i] != rhs[i] )
286 return false;
287 return true;
288 }
289};
290
291
292template <class IndexType>
293union uDihedral
294{
295 DihedralCell<IndexType> Cell;
296
297 struct Name
298 {
299 IndexType iii, iij, ijj, jjj;
300 } Named;
301
302 struct ijklName
303 {
304 IndexType i,j,k,l;
305 } ijkl;
306};
307
308//typedef DihedralCell<uint32_t> Dihedral32;
309//typedef DihedralCell<uint64_t> Dihedral64;
310
311
313typedef SimplexCell<1, uint32_t> EdgeCell32;
315typedef SimplexCell<2, uint32_t> TriangleCell32;
317typedef SimplexCell<3, uint32_t> TetrahedronCell32;
318
320typedef RegularCell<2, uint32_t> QuadCell32;
322typedef RegularCell<3, uint32_t> HexahedronCell32;
323
324
325typedef SimplexCell<1, uint64_t> EdgeCell64;
326typedef SimplexCell<2, uint64_t> TriangleCell64;
327typedef SimplexCell<3, uint64_t> TetrahedronCell64;
328
329typedef RegularCell<2, uint64_t> QuadCell64;
330typedef RegularCell<3, uint64_t> HexahedronCell64;
331
332
334typedef EdgeCell32 EdgeCell;
336typedef TriangleCell32 TriangleCell;
338typedef TetrahedronCell32 TetrahedronCell;
339
341typedef QuadCell32 QuadCell;
343typedef HexahedronCell32 HexahedronCell;
344
346//typedef Dihedral32 Dihedral;
347
348
350typedef SimplexCell<1, uint32_t> EdgeCell32_t;
351
353typedef SimplexCell<2, uint32_t> TriangleCell32_t;
354
356typedef SimplexCell<3, uint32_t> TetrahedronCell32_t;
357
358typedef RegularCell<2, uint32_t> QuadCell32_t;
359typedef RegularCell<3, uint32_t> HexahedronCell32_t;
360
361
362
363typedef SimplexCell<1, uint64_t> EdgeCell64_t;
364typedef SimplexCell<2, uint64_t> TriangleCell64_t;
365typedef SimplexCell<3, uint64_t> TetrahedronCell64_t;
366
367typedef RegularCell<2, uint64_t> QuadCell64_t;
368typedef RegularCell<3, uint64_t> HexahedronCell64_t;
369
370
371typedef DihedralCell<uint32_t> Dihedral32_t;
372typedef DihedralCell<uint64_t> Dihedral64_t;
373
375typedef EdgeCell32_t EdgeCell_t;
377typedef TriangleCell32_t TriangleCell_t;
379typedef TetrahedronCell32_t TetrahedronCell_t;
380
382typedef QuadCell32_t QuadCell_t;
384typedef HexahedronCell32_t HexahedronCell_t;
385
386typedef Dihedral32_t Dihedral_t;
387
388} // namespace Fiber
389
390
391
392namespace Eagle
393{
394
395template <Eagle::dimension_t Dims, int Elements, class IndexType>
396struct MetaInfo<Fiber::Cell<Dims, Elements, IndexType> >
397{
398 enum
399 {
401 MULTIPLICITY = Elements,
402/*12.12.14
403 Was: RANK = Dims
404 But rank should be 0 to indicate that these
405 cell types are point-types, not vectorial types.
406 */
407 RANK = 0,
408 GRADE = 0
409 };
410
412 typedef IndexType element_t;
413
414 // An eventually associated coordinate system
415 typedef void Chart_t;
416
417static const element_t&getComponent(const Fiber::Cell<Dims, Elements, IndexType>&t, int i)
418 {
419 return t[i];
420 }
421};
422
423
424template <Eagle::dimension_t Dims, class IndexType, class NamingConvention>
425struct MetaInfo<Fiber::SimplexCell<Dims,IndexType,NamingConvention> > : MetaInfo<typename Fiber::SimplexCell<Dims,IndexType,NamingConvention>::Base_t>
426{
427 typedef Fiber::SimplexCell<Dims,IndexType> Chart_t;
428};
429
430template <int Dims, class IndexType, class NamingConvention>
431struct MetaInfo<Fiber::RegularCell<Dims,IndexType,NamingConvention> > : MetaInfo<typename Fiber::RegularCell<Dims,IndexType,NamingConvention>::Base_t>
432{
433 typedef Fiber::RegularCell<Dims,IndexType,NamingConvention> Chart_t;
434};
435
436} // Eagle
437
438
439
440namespace META
441{
442
443template <Eagle::dimension_t DIMS, int Elements, class IndexType>
444struct BaseClass<Fiber::Cell<DIMS, Elements, IndexType> >
445{
446// typedef Fiber::FixedArray<IndexType, Elements> result;
447 typedef typename Fiber::Cell<DIMS, Elements, IndexType>::Base_t result;
448};
449
450template <Eagle::dimension_t Dims, class IndexType, class NamingConvention>
451struct BaseClass<Fiber::SimplexCell<Dims, IndexType, NamingConvention> >
452{
453// typedef Fiber::Cell<Dims, Dims+1, IndexType> result;
454
455 typedef typename Fiber::SimplexCell<Dims, IndexType, NamingConvention>::Base_t result;
456};
457
458template <Eagle::dimension_t Dims, class IndexType, class NamingConvention>
459struct BaseClass<Fiber::RegularCell<Dims, IndexType, NamingConvention> >
460{
461// typedef Fiber::Cell<Dims, (1<<Dims), IndexType> result;
462
463 typedef typename Fiber::RegularCell<Dims, IndexType, NamingConvention>::Base_t result;
464};
465
466
467} // namespace META
468
469
470
471namespace std
472{
473
475template <Eagle::dimension_t Dims, class IndexType, class NamingConvention>
476inline string to_string(const Fiber::SimplexCell<Dims, IndexType, NamingConvention>&C,
477 const char*OpenBrace = "<", const char*CloseBrace = ">",
478 const char*Separator = ",")
479{
480 return std::to_string( C.getFixedArray(), OpenBrace, CloseBrace, Separator);
481}
482
486template <Eagle::dimension_t Dims, class IndexType, class NamingConvention>
487inline string to_string(const Fiber::RegularCell<Dims, IndexType, NamingConvention>&C, const char*OpenBrace = "",
488 const char*CloseBrace = "", const char*Separator = "x")
489{
490 return to_string( C.getFixedArray(), OpenBrace, CloseBrace, Separator);
491}
492
493} // namespace
494
495namespace std
496{
497 string to_string( const Fiber::Dihedral_t& dihedral );
498
499 template <> struct hash<Fiber::Dihedral32_t>
500 {
501 size_t operator()(const Fiber::Dihedral32_t & x) const
502 {
503#if 1
504 constexpr uint32_t dim_max = 512;
505#else
506 // should be like this, but sqrt() is not a compile-time function, so can't be used in a constexpr.
507 constexpr uint32_t dim_max = static_cast<uint32_t>( sqrt( sqrt( std::numeric_limits<uint32_t>::max() ) ) );
508#endif
509 const Fiber::MultiIndex<4> max_size = { dim_max, dim_max, dim_max, dim_max };
510 Fiber::MultiIndex<4> tmp { x[0], x[1], x[2], x[3] };
511 return tmp.linear( max_size );
512 }
513 };
514} /* namespace std */
515
516#endif // __FIBER_FIELD_CELL_HPP
basic_string< char > string
An iterator with an optional DataCreator, which is just a class to intercept creation of data along a...
Definition CreativeIterator.hpp:34
Given a fragmented field of curvilinear coordinates, (3D array of coordinates), build a uniform Grid ...
Definition FAQ.dox:2
A type describing a cell in a cell complex.
Definition Cell.hpp:42
A naming convention for cell components using "i" and "j".
Definition Cell.hpp:16
A type describing an n-dimensional regular cell.
Definition Cell.hpp:129
A type describing an n-dimensional simplex cell.
Definition Cell.hpp:70
Definition geospeed.cpp:55