31 enum Grid4dType { TypeNone = 0, TypeReal = 1, TypeInt = 2, TypeVec3 = 4, TypeVec4 = 8 };
36 inline int getSizeX()
const {
return mSize.x; }
38 inline int getSizeY()
const {
return mSize.y; }
40 inline int getSizeZ()
const {
return mSize.z; }
42 inline int getSizeT()
const {
return mSize.t; }
55 inline Real getDx() {
return mDx; }
58 inline void checkIndex(
int i,
int j,
int k,
int t)
const;
71 inline Grid4dType
getType()
const {
return mType; }
73 inline bool is3D()
const {
return true; }
74 inline bool is4D()
const {
return true; }
80 inline IndexInt
index(
int i,
int j,
int k,
int t)
const { DEBUG_ONLY(
checkIndex(i,j,k,t));
return (IndexInt)i + (IndexInt)mSize.x * j + (IndexInt)mStrideZ * k + (IndexInt)mStrideT * t; }
82 inline IndexInt
index(
const Vec4i& pos)
const { DEBUG_ONLY(
checkIndex(pos.x,pos.y,pos.z,pos.t));
return (IndexInt)pos.x + (IndexInt)mSize.x * pos.y + (IndexInt)mStrideZ * pos.z + (IndexInt)mStrideT * pos.t; }
107 PYTHON()
void save(
std::
string name);
108 PYTHON()
void load(
std::
string name);
111 PYTHON()
void clear();
115 inline T get(
int i,
int j,
int k,
int t)
const {
return mData[
index(i,j,k,t)]; }
117 inline T&
get(
int i,
int j,
int k,
int t) {
return mData[
index(i,j,k,t)]; }
119 inline T
get(IndexInt idx)
const { DEBUG_ONLY(
checkIndex(idx));
return mData[idx]; }
121 inline T
get(
const Vec4i& pos)
const {
return mData[
index(pos)]; }
125 inline T
operator()(
int i,
int j,
int k,
int t)
const {
return mData[
index(i, j, k,t)]; }
140 inline T getInterpolated(
const Vec4& pos)
const {
return interpol4d<T>(mData, mSize, mStrideZ, mStrideT, pos); }
155 PYTHON()
void setConst(T s);
157 PYTHON()
void addConst(T s);
159 PYTHON()
void addScaled(
const Grid4d<T>& a,
const T& factor);
163 PYTHON()
void multConst(T s);
165 PYTHON()
void clamp(Real min, Real max);
169 PYTHON() Real getMaxAbs();
171 PYTHON() Real getMax();
173 PYTHON() Real getMin();
175 PYTHON()
void setBound(T value,
int boundaryWidth=1);
177 PYTHON()
void setBoundNeumann(
int boundaryWidth=1);
180 PYTHON()
void printGrid(
int zSlice=-1,
int tSlice=-1,
bool printIndex=
false,
int bnd=0);
184 template<
class S>
Grid4d<T>& operator+=(
const S& a);
186 template<
class S>
Grid4d<T>& operator-=(
const S& a);
188 template<
class S>
Grid4d<T>& operator*=(
const S& a);
190 template<
class S>
Grid4d<T>& operator/=(
const S& a);
209 return Vec4( Real(s1[0])/s2[0], Real(s1[1])/s2[1], Real(s1[2])/s2[2] , Real(s1[3])/s2[3] );
212 return Vec4( s1[0]/s2[0], s1[1]/s2[1], s1[2]/s2[2] , s1[3]/s2[3] );
224 if ( i<0 || j<0 || i>=mSize.x || j>=mSize.y || k<0|| k>= mSize.z ||
225 t<0|| t>= mSize.t ) {
226 std::ostringstream s;
227 s <<
"Grid4d " << mName <<
" dim " << mSize <<
" : index " << i <<
"," << j <<
"," << k <<
","<<t<<
" out of bound ";
233 if (idx<0 || idx >= mSize.x * mSize.y * mSize.z * mSize.t) {
234 std::ostringstream s;
235 s <<
"Grid4d " << mName <<
" dim " << mSize <<
" : index " << idx <<
" out of bound ";
241 return (p.x >= 0 && p.y >= 0 && p.z >= 0 && p.t >= 0 &&
242 p.x < mSize.x && p.y < mSize.y && p.z < mSize.z && p.t < mSize.t);
246 bool ret = (p.x >= bnd && p.y >= bnd && p.x < mSize.x-bnd && p.y < mSize.y-bnd);
247 ret &= (p.z >= bnd && p.z < mSize.z-bnd);
248 ret &= (p.t >= bnd && p.t < mSize.t-bnd);
253 if (idx<0 || idx >= mSize.x * mSize.y * mSize.z * mSize.t) {
274 void Grid4dAddScalar (
Grid4d<T>& me,
const S& other) {}
277 void Grid4dMultScalar(
Grid4d<T>& me,
const S& other) {}
287 void Grid4dSetConst(
Grid4d<T>& me, T value) {}
291 Grid4dAdd<T,S> (*
this, a);
295 Grid4dAddScalar<T,S> (*
this, a);
299 Grid4dSub<T,S> (*
this, a);
303 Grid4dAddScalar<T,S> (*
this, -a);
307 Grid4dMult<T,S> (*
this, a);
311 Grid4dMultScalar<T,S> (*
this, a);
315 Grid4dDiv<T,S> (*
this, a);
320 Grid4dMultScalar<T,S> (*
this, rez);
328 inline Vec4 getGradient4d(
const Grid4d<Real>& data,
int i,
int j,
int k,
int t) {
338 v =
Vec4( data(i+1,j ,k ,t ) - data(i-1,j ,k ,t ) ,
339 data(i ,j+1,k ,t ) - data(i ,j-1,k ,t ) ,
340 data(i ,j ,k+1,t ) - data(i ,j ,k-1,t ) ,
341 data(i ,j ,k ,t+1) - data(i ,j ,k ,t-1) );
Definition: commonkernels.h:22
IndexInt getStrideZ() const
Get Stride in Z dimension.
Definition: grid4d.h:51
bool isInBounds(const Vec4 &p, int bnd=0) const
Check if index is within given boundaries.
Definition: grid4d.h:66
const T operator[](IndexInt idx) const
access data
Definition: grid4d.h:137
bool isInBounds(const Vec4i &p, int bnd) const
Check if index is within given boundaries.
Definition: grid4d.h:245
IndexInt getStrideX() const
Get Stride in X dimension.
Definition: grid4d.h:47
int getSizeZ() const
Get the grids Z dimension.
Definition: grid4d.h:40
T operator()(IndexInt idx) const
access data
Definition: grid4d.h:129
Grid4dType getType() const
Get the type of grid.
Definition: grid4d.h:71
T & operator()(const Vec4i &pos)
access data
Definition: grid4d.h:131
Vec4 calcGridSizeFactor4d(Vec4i s1, Vec4i s2)
helper to compute grid conversion factor between local coordinates of two grids
Definition: grid4d.h:208
IndexInt index(int i, int j, int k, int t) const
Get index into the data.
Definition: grid4d.h:80
T & operator[](IndexInt idx)
access data
Definition: grid4d.h:135
Vec4i getSize() const
Get the grids dimensions.
Definition: grid4d.h:44
int getSizeX() const
Get the grids X dimension.
Definition: grid4d.h:36
int getSizeT() const
Get the grids T dimension.
Definition: grid4d.h:42
T operator()(const Vec4i &pos) const
access data
Definition: grid4d.h:133
void checkIndex(int i, int j, int k, int t) const
Check if indices are within bounds, otherwise error (should only be called when debugging) ...
Definition: grid4d.h:223
T operator()(int i, int j, int k, int t) const
access data
Definition: grid4d.h:125
IndexInt index(const Vec4i &pos) const
Get index into the data.
Definition: grid4d.h:82
IndexInt getStrideT() const
Get Stride in T dimension.
Definition: grid4d.h:53
bool is3D() const
Check dimensionality.
Definition: grid4d.h:73
T & operator()(IndexInt idx)
access data
Definition: grid4d.h:127
IndexInt getStrideY() const
Get Stride in Y dimension.
Definition: grid4d.h:49
T & operator()(int i, int j, int k, int t)
access data
Definition: grid4d.h:123
int getSizeY() const
Get the grids Y dimension.
Definition: grid4d.h:38
bool isInBounds(int i, int j, int k, int t, int bnd) const
3d compatibility
Definition: grid4d.h:77
Definition: fluidsolver.h:28