Go to the documentation of this file.00001
00002
00003 #ifndef periodicube_hh
00004 #define periodicube_hh
00005
00006 #include "basics/typedefs.hh"
00007 #include "geometry/mesh.hh"
00008
00009 #define DEBUG_SAVE_MESH 0
00010
00011 using concepts::Real;
00012
00018 class PeriodiCube : public concepts::Mesh3 {
00019 public:
00026 PeriodiCube(uint n, Real jitter = 0);
00028 virtual ~PeriodiCube();
00030 unsigned int ncell() const { return 6*n_*n_*n_; }
00032 concepts::Scan3* scan() { return new S(cell_, n_); }
00034 virtual std::ostream& info(std::ostream& os) const;
00036 void saveMesh();
00038 uint n() { return n_; };
00039 private:
00041 class S : public concepts::Scan<concepts::Cell3> {
00043 unsigned int idx_;
00045 unsigned int n_;
00047 concepts::Tetrahedron3d** cell_;
00048 public:
00050 S(concepts::Tetrahedron3d* cell[], uint n) : idx_(0), n_(n), cell_(cell) {}
00052 S(const S& scan) : idx_(scan.idx_), cell_(scan.cell_) {}
00054 bool eos() const { return idx_ == 6*n_*n_*n_; }
00056 concepts::Cell3& operator++(int) { return *cell_[idx_++]; }
00058 concepts::Scan3* clone() const { return new S(*this); }
00059 };
00061 uint ii(uint a, uint b, uint c) {
00062 return 1 + a + (1+n_)*b + (1+n_)*(1+n_)*c;
00063 };
00065 uint j(uint a, uint b, uint c) { return (a%n_) + n_*(b%n_) + n_*n_*(c%n_); };
00067 uint k(uint a, uint b, uint c, uint d) { return d + 7*j(a, b, c); };
00069 uint l(uint a, uint b, uint c, uint e) { return e + 12*j(a, b, c); };
00071 uint m(uint a, uint b, uint c, uint f) { return f + 6*j(a, b, c); };
00073 Real dRand() {
00074 return jitter_*2*((static_cast<Real>(std::rand()) /
00075 static_cast<Real>(RAND_MAX))-0.5);
00076 }
00078 double x(uint a) { return static_cast<double>(a)/static_cast<double>(n_); }
00080 uint n_;
00082 Real jitter_;
00084 concepts::Real3d** coord_;
00086 concepts::Vertex** vtx_;
00088 concepts::Edge** edg_;
00090 concepts::Triangle** tri_;
00092 concepts::Tetrahedron** tet_;
00094 concepts::Tetrahedron3d** cell_;
00095 };
00096
00097 #endif // periodicube_hh