# PhasicFlow: src/Interaction/contactSearch/cells.hpp Source File

cells.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __cells_hpp__
#define __cells_hpp__
#include "types.hpp"
#include "box.hpp"
namespace pFlow
{
template<typename indexType>
class cells
{
public:
using CellType = triple<indexType>;
protected:
// - domain
box domain_{realx3(0.0), realx3(1.0)};
// - cell size
realx3 cellSize_{1,1,1};
CellType numCells_{1,1,1};
// - protected methods
INLINE_FUNCTION_H
void calculate()
{
numCells_ = (domain_.maxPoint()-domain_.minPoint())/cellSize_ + realx3(1.0);
numCells_ = max( numCells_ , CellType(static_cast<indexType>(1)) );
}
public:
INLINE_FUNCTION_HD
cells()
{}
INLINE_FUNCTION_H
cells(const box& domain, real cellSize)
:
domain_(domain),
cellSize_(cellSize)
{
calculate();
}
INLINE_FUNCTION_H
cells(const box& domain, int32 nx, int32 ny, int32 nz)
:
domain_(domain),
cellSize_(
(domain_.maxPoint() - domain_.minPoint())/realx3(nx, ny, nz)
),
numCells_(nx, ny, nz)
{}
INLINE_FUNCTION_HD
cells(const cells&) = default;
INLINE_FUNCTION_HD
cells& operator = (const cells&) = default;
INLINE_FUNCTION_HD
cells(cells &&) = default;
INLINE_FUNCTION_HD
cells& operator=(cells&&) = default;
cells getCells()const
{
return *this;
}
INLINE_FUNCTION_H
void setCellSize(real cellSize)
{
cellSize_ = cellSize;
calculate();
}
INLINE_FUNCTION_H
void setCellSize(realx3 cellSize)
{
cellSize_ = cellSize;
calculate();
}
INLINE_FUNCTION_HD
realx3 cellSize()const
{
return cellSize_;
}
INLINE_FUNCTION_HD
const CellType& numCells()const
{
return numCells_;
}
INLINE_FUNCTION_HD
indexType nx()const
{
return numCells_.x();
}
INLINE_FUNCTION_HD
indexType ny()const
{
return numCells_.y();
}
INLINE_FUNCTION_HD
indexType nz()const
{
return numCells_.z();
}
INLINE_FUNCTION_HD
int64 totalCells()const
{
return static_cast< int64 >(numCells_.x())*
static_cast< int64 >(numCells_.y())*
static_cast< int64 >(numCells_.z());
}
const auto& domain()const
{
return domain_;
}
INLINE_FUNCTION_HD
CellType pointIndex(const realx3& p)const
{
return CellType( (p - domain_.minPoint())/cellSize_ );
}
INLINE_FUNCTION_HD
bool pointIndexInDomain(const realx3 p, CellType& index)const
{
if( !domain_.isInside(p) ) return false;
index = this->pointIndex(p);
return true;
}
INLINE_FUNCTION_HD
bool inDomain(const realx3& p)const
{
return domain_.isInside(p);
}
INLINE_FUNCTION_HD
bool isInRange(const CellType& cell)const
{
if(cell.x()<0)return false;
if(cell.y()<0)return false;
if(cell.z()<0)return false;
if(cell.x()>numCells_.x()-1) return false;
if(cell.y()>numCells_.y()-1) return false;
if(cell.z()>numCells_.z()-1) return false;
return true;
}
INLINE_FUNCTION_HD
bool isInRange(indexType i, indexType j, indexType k)const
{
if(i<0)return false;
if(j<0)return false;
if(k<0)return false;
if(i>numCells_.x()-1) return false;
if(j>numCells_.y()-1) return false;
if(k>numCells_.z()-1) return false;
return true;
}
INLINE_FUNCTION_HD
void extendBox(
const CellType& p1,
const CellType& p2,
const CellType& p3,
indexType extent,
CellType& minP,
CellType& maxP)const
{
minP = min( min( p1, p2), p3)-extent;
maxP = max( max( p1, p2), p3)+extent;
minP = bound(minP);
maxP = bound(maxP);
}
INLINE_FUNCTION_HD
void extendBox(
const realx3& p1,
const realx3& p2,
const realx3& p3,
real extent,
realx3& minP,
realx3& maxP)const
{
minP = min(min(p1,p2),p3) - extent*cellSize_ ;
maxP = max(max(p1,p2),p3) + extent*cellSize_ ;
minP = bound(minP);
maxP = bound(maxP);
}
INLINE_FUNCTION_HD
CellType bound(CellType p)const
{
return CellType(
min( numCells_.x()-1, max(0,p.x())),
min( numCells_.y()-1, max(0,p.y())),
min( numCells_.z()-1, max(0,p.z()))
);
}
INLINE_FUNCTION_HD
realx3 bound(realx3 p)const
{
return realx3(
min( domain_.maxPoint().x(), max(domain_.minPoint().x(),p.x())),
min( domain_.maxPoint().y(), max(domain_.minPoint().y(),p.y())),
min( domain_.maxPoint().z(), max(domain_.minPoint().z(),p.z()))
);
}
};
}
#endif
pFlow::cells::setCellSize
INLINE_FUNCTION_H void setCellSize(realx3 cellSize)
Definition: cells.hpp:108
pFlow::cells::nz
INLINE_FUNCTION_HD indexType nz() const
Definition: cells.hpp:139
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::cells::numCells_
CellType numCells_
Definition: cells.hpp:46
pFlow::cells::isInRange
INLINE_FUNCTION_HD bool isInRange(indexType i, indexType j, indexType k) const
Definition: cells.hpp:191
types.hpp
pFlow::cells::operator=
INLINE_FUNCTION_HD cells & operator=(const cells &)=default
box.hpp
pFlow::cells::cells
INLINE_FUNCTION_H cells(const box &domain, real cellSize)
Definition: cells.hpp:64
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::cells::extendBox
INLINE_FUNCTION_HD void extendBox(const CellType &p1, const CellType &p2, const CellType &p3, indexType extent, CellType &minP, CellType &maxP) const
Definition: cells.hpp:203
pFlow::cells::nx
INLINE_FUNCTION_HD indexType nx() const
Definition: cells.hpp:127
pFlow::cells::isInRange
INLINE_FUNCTION_HD bool isInRange(const CellType &cell) const
Definition: cells.hpp:179
pFlow::cells::extendBox
INLINE_FUNCTION_HD void extendBox(const realx3 &p1, const realx3 &p2, const realx3 &p3, real extent, realx3 &minP, realx3 &maxP) const
Definition: cells.hpp:219
pFlow::box::maxPoint
INLINE_FUNCTION_HD realx3 maxPoint() const
Definition: box.hpp:94
pFlow::realx3
triple< real > realx3
Definition: types.hpp:48
pFlow::cells::pointIndexInDomain
INLINE_FUNCTION_HD bool pointIndexInDomain(const realx3 p, CellType &index) const
Definition: cells.hpp:164
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
Definition: triple.hpp:141
pFlow
Definition: demComponent.hpp:28
pFlow::cells::CellType
triple< indexType > CellType
Definition: cells.hpp:36
pFlow::cells::calculate
INLINE_FUNCTION_H void calculate()
Definition: cells.hpp:51
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::cells::domain_
box domain_
Definition: cells.hpp:41
pFlow::cells::bound
INLINE_FUNCTION_HD CellType bound(CellType p) const
Definition: cells.hpp:235
pFlow::cells::domain
const auto & domain() const
Definition: cells.hpp:152
pFlow::cells::cellSize_
realx3 cellSize_
Definition: cells.hpp:44
pFlow::cells::cells
INLINE_FUNCTION_HD cells()
Definition: cells.hpp:60
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::cells::inDomain
INLINE_FUNCTION_HD bool inDomain(const realx3 &p) const
Definition: cells.hpp:173
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
Definition: triple.hpp:144
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::box
Definition: box.hpp:32
pFlow::cells::ny
INLINE_FUNCTION_HD indexType ny() const
Definition: cells.hpp:133
pFlow::cells::bound
INLINE_FUNCTION_HD realx3 bound(realx3 p) const
Definition: cells.hpp:245
pFlow::cells::cellSize
INLINE_FUNCTION_HD realx3 cellSize() const
Definition: cells.hpp:115
pFlow::box::minPoint
INLINE_FUNCTION_HD realx3 minPoint() const
Definition: box.hpp:88
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
Definition: triple.hpp:138
pFlow::cells
Definition: cells.hpp:32
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple< int32 >
pFlow::cells::setCellSize
INLINE_FUNCTION_H void setCellSize(real cellSize)
Definition: cells.hpp:101
pFlow::cells::pointIndex
INLINE_FUNCTION_HD CellType pointIndex(const realx3 &p) const
Definition: cells.hpp:158
pFlow::box::isInside
INLINE_FUNCTION_HD bool isInside(const realx3 &point) const
Definition: box.hpp:82
pFlow::cells::totalCells
INLINE_FUNCTION_HD int64 totalCells() const
Definition: cells.hpp:145
pFlow::cells::cells
INLINE_FUNCTION_H cells(const box &domain, int32 nx, int32 ny, int32 nz)
Definition: cells.hpp:74
pFlow::cells::numCells
const INLINE_FUNCTION_HD CellType & numCells() const
Definition: cells.hpp:121
pFlow::min
T min(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:138
pFlow::cells::getCells
cells getCells() const
Definition: cells.hpp:95