00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef STUCTURED_3D_MESH_SHAPE_HPP
00022 #define STUCTURED_3D_MESH_SHAPE_HPP
00023
00024 #include <TinyVector.hpp>
00025 #include <Array3DShape.hpp>
00026
00027 #include <StreamCenter.hpp>
00028
00037 class Structured3DMeshShape
00038 {
00039 private:
00041 Array3DShape __shape;
00042 TinyVector<3,real_t> __stepSize;
00043
00044 TinyVector<3> __a;
00045 TinyVector<3> __b;
00046
00047 TinyVector<3> __dimensions;
00048 public:
00049
00050 inline size_t operator()(const size_t& i, const size_t& j, const size_t& k) const
00051 {
00052 return __shape(i,j,k);
00053 }
00054
00055 inline const Array3DShape& shape() const
00056 {
00057 return __shape;
00058 }
00059
00060 inline const TinyVector<3>& a() const
00061 {
00062 return __a;
00063 }
00064
00065 inline const real_t& a(const size_t& i) const
00066 {
00067 return __a[i];
00068 }
00069
00070 const TinyVector<3>& b() const
00071 {
00072 return __b;
00073 }
00074
00075 inline const real_t& b(const size_t& i) const
00076 {
00077 return __b[i];
00078 }
00079
00080 inline const real_t& dimension(const size_t& i) const
00081 {
00082 return __dimensions[i];
00083 }
00084
00085 const real_t& hx() const
00086 {
00087 return __stepSize[0];
00088 }
00089
00090 const real_t& hy() const
00091 {
00092 return __stepSize[1];
00093 }
00094 const real_t& hz() const
00095 {
00096 return __stepSize[2];
00097 }
00098
00099 bool operator==(const Structured3DMeshShape& s) const
00100 {
00101 return ((__shape==s.__shape)&&
00102 (__a==s.__a)&&
00103 (__b==s.__b));
00104 }
00105
00107 inline size_t nx() const
00108 {
00109 return __shape.nx();
00110 }
00111
00113 inline size_t ny() const
00114 {
00115 return __shape.ny();
00116 }
00117
00119 inline size_t nz() const
00120 {
00121 return __shape.nz();
00122 }
00123
00125 size_t numberOfVertices() const
00126 {
00127 return __shape.nx()*__shape.ny()*__shape.nz();
00128 }
00129
00131 size_t numberOfEdges() const
00132 {
00133 return ((__shape.nx()-1)*__shape.ny()*__shape.nz()
00134 +__shape.nx()*(__shape.ny()-1)*__shape.nz()
00135 +__shape.nx()*__shape.ny()*(__shape.nz()-1));
00136 }
00137
00139 size_t numberOfCells() const
00140 {
00141 return (__shape.nx()-1)*(__shape.ny()-1)*(__shape.nz()-1);
00142 }
00143
00145 const Structured3DMeshShape& operator=(const Structured3DMeshShape& s)
00146 {
00147 __shape=s.__shape;
00148 __stepSize=s.__stepSize;
00149 __a=s.__a;
00150 __b=s.__b;
00151 __dimensions=s.__dimensions;
00152
00153 return *this;
00154 }
00155
00163 Structured3DMeshShape(const TinyVector<3,size_t>& shape,
00164 const TinyVector<3,real_t>& a,
00165 const TinyVector<3,real_t>& b)
00166 : __shape(shape),
00167 __a(std::min(a[0],b[0]),
00168 std::min(a[1],b[1]),
00169 std::min(a[2],b[2])),
00170 __b(std::max(a[0],b[0]),
00171 std::max(a[1],b[1]),
00172 std::max(a[2],b[2])),
00173 __dimensions(std::abs(a[0]-b[0]),
00174 std::abs(a[1]-b[1]),
00175 std::abs(a[2]-b[2]))
00176 {
00177 for (size_t n=0; n<3; ++n)
00178 __stepSize[n] = (__b[n]-__a[n])/(__shape[n]-1.);
00179 }
00180
00182 Structured3DMeshShape(const Structured3DMeshShape& s)
00183 : __shape(s.__shape),
00184 __stepSize(s.__stepSize),
00185 __a(s.__a),
00186 __b(s.__b),
00187 __dimensions(s.__dimensions)
00188 {
00189 if ((nx()<=1)||(ny()<=1)||nz()<=1)
00190 fferr(2) << "\nthe mesh shape is not valid: "
00191 << __shape << '\n';
00192 }
00193
00194 ~Structured3DMeshShape()
00195 {
00196 ;
00197 }
00198 };
00199
00200 #endif // STUCTURED_3D_MESH_SHAPE_HPP