29#ifndef CUBOID_GEOMETRY_2D_HH
30#define CUBOID_GEOMETRY_2D_HH
45 : _motherCuboid(0,0,0,0,0), _periodicityOn(3, bool(false)), clout(std::cout,
"CuboidGeometry3D")
53 : _motherCuboid(originX, originY, deltaR, nX, nY), _periodicityOn(2, bool(false)),
54 clout(std::cout,
"CuboidGeometry2D")
62 : _motherCuboid(indicatorF.getMin()[0], indicatorF.getMin()[1], voxelSize,
63 (int)((indicatorF.getMax()[0] - indicatorF.getMin()[0]) / voxelSize + 1.5),
64 (int)((indicatorF.getMax()[1] - indicatorF.getMin()[1]) / voxelSize + 1.5)),
65 _periodicityOn(2, bool(false)), clout(std::cout,
"CuboidGeometry2D")
78 _motherCuboid =
Cuboid2D<T>(globPosX, globPosY, delta, nX, nY);
79 Cuboid2D<T> cuboid(globPosX, globPosY, delta, nX, nY);
81 cuboid.
init(0, 0, 1, nX, nY);
104 _periodicityOn[0] = periodicityX;
105 _periodicityOn[1] = periodicityY;
112 int iCtmp = get_iC(physR[0], physR[1]);
113 if (iCtmp < getNc()) {
125 int iCtmp = get_iC(physR[0], physR[1]);
126 if (iCtmp < getNc()) {
138 return getLatticeR(&latticeR[0], &physR[0]);
153 int iCtmp = get_iC(physR[0], physR[1]);
154 if (iCtmp < getNc()) {
156 latticeR[1] = (int)
util::floor( (physR[0] - _cuboids[latticeR[0]].getOrigin()[0] ) / _cuboids[latticeR[0]].getDeltaR() + .5);
157 latticeR[2] = (int)
util::floor( (physR[1] - _cuboids[latticeR[0]].getOrigin()[1] ) / _cuboids[latticeR[0]].getDeltaR() + .5);
169 int iCtmp = get_iC(physR[0], physR[1]);
170 if (iCtmp < getNc()) {
172 latticeR[1] = (int)
util::floor( (physR[0] - _cuboids[latticeR[0]].getOrigin()[0] ) / _cuboids[latticeR[0]].getDeltaR() + .5);
173 latticeR[2] = (int)
util::floor( (physR[1] - _cuboids[latticeR[0]].getOrigin()[1] ) / _cuboids[latticeR[0]].getDeltaR() + .5);
184 int iCtmp = get_iC(physR[0], physR[1]);
185 if (iCtmp < getNc()) {
187 latticeR[1] = (int)
util::floor( (physR[0] - _cuboids[latticeR[0]].getOrigin()[0] ) / _cuboids[latticeR[0]].getDeltaR() );
188 latticeR[2] = (int)
util::floor( (physR[1] - _cuboids[latticeR[0]].getOrigin()[1] ) / _cuboids[latticeR[0]].getDeltaR() );
200 int iCtmp = get_iC(physR[0], physR[1]);
201 if (iCtmp < getNc()) {
203 latticeR[1] = (int)
util::floor( (physR[0] - _cuboids[latticeR[0]].getOrigin()[0] ) / _cuboids[latticeR[0]].getDeltaR() );
204 latticeR[2] = (int)
util::floor( (physR[1] - _cuboids[latticeR[0]].getOrigin()[1] ) / _cuboids[latticeR[0]].getDeltaR() );
215 std::vector<T> physR(2,T());
216 _cuboids[iCglob].getPhysR(&(physR[0]), iX, iY);
217 for (
int iDim = 0; iDim < 2; iDim++) {
218 if (_periodicityOn[iDim]) {
220 physR[iDim] = remainder( physR[iDim] - _motherCuboid.getOrigin()[iDim]
221 + _motherCuboid.getDeltaR() * (_motherCuboid.getExtent()[iDim]),
222 _motherCuboid.getDeltaR() * (_motherCuboid.getExtent()[iDim]));
224 if ( physR[iDim]*physR[iDim] < 0.001 * _motherCuboid.getDeltaR()*_motherCuboid.getDeltaR() ) {
228 if ( physR[iDim] < 0 ) {
229 physR[iDim] += _motherCuboid.getDeltaR() * _motherCuboid.getExtent()[iDim];
232 physR[iDim] += _motherCuboid.getOrigin()[iDim];
241 return getPhysR(latticeR[0], latticeR[1], latticeR[2]);
247 getPhysR(output, latticeR[0], latticeR[1], latticeR[2]);
253 getPhysR(output, latticeR[0], latticeR[1], latticeR[2]);
259 getPhysR(output, iCglob, latticeR[0], latticeR[1]);
266 _cuboids[iCglob].getPhysR(output, iX, iY);
267 for (
int iDim = 0; iDim < 2; iDim++) {
268 if (_periodicityOn[iDim]) {
270 output[iDim] = remainder( output[iDim] - _motherCuboid.getOrigin()[iDim]
271 + _motherCuboid.getDeltaR() * (_motherCuboid.getExtent()[iDim]),
272 _motherCuboid.getDeltaR() * (_motherCuboid.getExtent()[iDim]));
274 if ( output[iDim]*output[iDim] < 0.001 * _motherCuboid.getDeltaR()*_motherCuboid.getDeltaR() ) {
278 if ( output[iDim] < 0 ) {
279 output[iDim] += _motherCuboid.getDeltaR() * _motherCuboid.getExtent()[iDim];
282 output[iDim] += _motherCuboid.getOrigin()[iDim];
290 return _cuboids.size();
297 for (
auto& cuboid : _cuboids ) {
298 if ((T)cuboid.getNx() / (T)cuboid.getNy() < minRatio) {
299 minRatio = (T)cuboid.getNx() / (T)cuboid.getNy();
309 for (
unsigned i = 0; i < _cuboids.size(); i++) {
310 if ((T)_cuboids[i].getNx() / (T)_cuboids[i].getNy() > maxRatio) {
311 maxRatio = (T)_cuboids[i].getNx() / (T)_cuboids[i].getNy();
321 for (
unsigned i = 0; i < _cuboids.size(); i++) {
322 if (_cuboids[i].getOrigin()[0] < output[0]) {
323 output[0] = _cuboids[i].getOrigin()[0];
325 if (_cuboids[i].getOrigin()[1] < output[1]) {
326 output[1] = _cuboids[i].getOrigin()[1];
329 return std::vector<T> {output[0],output[1]};
336 output[0] += _cuboids[0].getNx()*_cuboids[0].getDeltaR();
337 output[1] += _cuboids[0].getNy()*_cuboids[0].getDeltaR();
338 for (
unsigned i = 0; i < _cuboids.size(); i++) {
339 if (_cuboids[i].getOrigin()[0] + _cuboids[i].getNx()*_cuboids[i].getDeltaR() > output[0]) {
340 output[0] = _cuboids[i].getOrigin()[0] + _cuboids[i].getNx()*_cuboids[i].getDeltaR();
342 if (_cuboids[i].getOrigin()[1] + _cuboids[i].getNy()*_cuboids[i].getDeltaR() > output[1]) {
343 output[1] = _cuboids[i].getOrigin()[1] + _cuboids[i].getNy()*_cuboids[i].getDeltaR();
346 return std::vector<T> {output[0],output[1]};
352 T minVolume = _cuboids[0].getPhysVolume();
353 for (
unsigned i = 0; i < _cuboids.size(); i++) {
354 if (_cuboids[i].getPhysVolume() < minVolume) {
355 minVolume = _cuboids[i].getPhysVolume();
364 T maxVolume = _cuboids[0].getPhysVolume();
365 for (
unsigned i = 0; i < _cuboids.size(); i++) {
366 if (_cuboids[i].getPhysVolume() > maxVolume) {
367 maxVolume = _cuboids[i].getPhysVolume();
376 size_t minNodes = _cuboids[0].getLatticeVolume();
377 for (
unsigned i = 0; i < _cuboids.size(); i++) {
378 if (_cuboids[i].getLatticeVolume() < minNodes) {
379 minNodes = _cuboids[i].getLatticeVolume();
388 size_t maxNodes = _cuboids[0].getLatticeVolume();
389 for (
unsigned i = 0; i < _cuboids.size(); i++) {
390 if (_cuboids[i].getLatticeVolume() > maxNodes) {
391 maxNodes = _cuboids[i].getLatticeVolume();
400 T minDelta = _cuboids[0].getDeltaR();
401 for (
unsigned i = 0; i < _cuboids.size(); i++) {
402 if (_cuboids[i].getDeltaR() < minDelta) {
403 minDelta = _cuboids[i].getDeltaR();
412 T maxDelta = _cuboids[0].getDeltaR();
413 for (
unsigned i = 0; i < _cuboids.size(); i++) {
414 if (_cuboids[i].getDeltaR() > maxDelta) {
415 maxDelta = _cuboids[i].getDeltaR();
464 return _motherCuboid;
471 for (i = 0; i < _cuboids.size(); i++) {
472 if (_cuboids[i].checkPoint(globX, globY, offset)) {
483 for (i = 0; i < _cuboids.size(); i++) {
484 if (_cuboids[i].checkPoint(globX, globY) &&
485 _cuboids[i].checkPoint(globX + orientationX / _cuboids[i].getDeltaR(),
486 globY + orientationY / _cuboids[i].getDeltaR())) {
498 _cuboids.push_back(cuboid);
505 _cuboids.erase(_cuboids.begin() + iC);
542 int newX, newY, maxX, maxY;
544 std::vector<int> latticeR(3, 0);
545 std::vector<T> physR(2, T());
547 for (
int iC = nC - 1; iC >= 0; iC--) {
550 int xN = get(iC).getNx();
551 int yN = get(iC).getNy();
556 for (
int iX = 0; iX < xN; iX++) {
557 for (
int iY = 0; iY < yN; iY++) {
560 physR = getPhysR(latticeR);
561 indicatorF(inside,&physR[0]);
572 get(iC).setWeight(fullCells);
573 _cuboids[iC].resize(newX, newY, maxX - newX + 1, maxY - newY + 1);
580 std::vector<T> minPhysR = getMinPhysR();
581 std::vector<T> maxPhysR = getMaxPhysR();
582 T minDelataR = getMinDeltaR();
583 _motherCuboid =
Cuboid2D<T>(minPhysR[0], minPhysR[1], minDelataR, (
int)((maxPhysR[0]-minPhysR[0])/minDelataR + 0.5), (
int)((maxPhysR[1]-minPhysR[1])/minDelataR + 0.5));
590 Cuboid2D<T> temp(_cuboids[iC].get_globPosX(), _cuboids[iC].get_globPosY(),
591 _cuboids[iC].getDeltaR(), _cuboids[iC].getNx(), _cuboids[iC].getNy());
599 for (
int iC = 0; iC < getNc(); iC++) {
603 T globX = get(iC).get_globPosX();
604 T globY = get(iC).get_globPosY();
605 T nX = get(iC).getNx();
606 T nY = get(iC).getNy();
607 if (get(cuboid).checkInters(globX, globX + nX, globY, globY + nY, offset)) {
608 neighbours.push_back(iC);
616 clout <<
"---Cuboid Stucture Statistics---" << std::endl;
617 clout <<
" Number of Cuboids: " <<
"\t" << getNc() << std::endl;
618 clout <<
" Delta (min): " <<
"\t" <<
"\t" << getMinDeltaR() << std::endl;
619 clout <<
" (max): " <<
"\t" <<
"\t" << getMaxDeltaR() << std::endl;
620 clout <<
" Ratio (min): " <<
"\t" <<
"\t" << getMinRatio() << std::endl;
621 clout <<
" (max): " <<
"\t" <<
"\t" << getMaxRatio() << std::endl;
622 clout <<
" Nodes (min): " <<
"\t" <<
"\t" << getMinLatticeVolume() << std::endl;
623 clout <<
" (max): " <<
"\t" <<
"\t" << getMaxLatticeVolume() << std::endl;
624 clout <<
"--------------------------------" << std::endl;
630 clout <<
"Mothercuboid :" << std::endl;
631 getMotherCuboid().print();
633 for (
int iC = 0; iC < getNc(); iC++) {
634 clout <<
"Cuboid #" << iC <<
": " << std::endl;
A regular single 2D cuboid is the basic component of a 2D cuboid structure which defines the grid.
void divide(int p, int q, std::vector< Cuboid2D< T > > &childrenC) const
Divides the cuboid in p*q cuboids and adds them to the given vector.
void resize(int X, int Y, int nX, int nY)
resize the cuboid to the passed size
void init(T globPosX, T globPosY, T delta, int nX, int nY)
Initializes the cuboid.
void reInit(T globPosX, T globPosY, T delta, int nX, int nY, int nC=1)
Re init.
bool getFloorLatticeR(std::vector< T > physR, std::vector< int > &latticeR) const
Returns true and the util::floor lattice position to the given physical position if the physical posi...
void remove(int iC)
Removes the cuboid iC.
void print() const
Prints cuboid geometry details.
T getMaxPhysVolume() const
int getNc() const
Returns the number of cuboids in t < 2he structure.
size_t getMinLatticeVolume() const
Returns the maximum/minimum number of nodes in the structure.
void printExtended()
Prints cuboid geometry details plus details of all cuboids.
CuboidGeometry2D()
Constructs empty Geometry.
void shrink(IndicatorF2D< T > &indicatorF)
Shrink all cuboids so that no empty planes are left.
Cuboid2D< T > getMotherCuboid() const
Returns the smallest cuboid that includes all cuboids of the structure.
void setPeriodicity(bool periodicityX, bool periodicityY)
Set flag to enable/disable periodicity.
size_t getMaxLatticeVolume() const
bool getC(std::vector< T > physR, int &iC) const
Returns true and the cuboid number of the nearest lattice position to the given physical position if ...
Cuboid2D< T > & get(int i)
Read and write access to the cuboids.
T getMinRatio() const
Returns the maximum/minimum of the ratio nX/NY in the structure.
T getMinDeltaR() const
Returns the maximum/minimum delata in the structure.
std::vector< T > getPhysR(int iCglob, int iX, int iY) const
Returns the physical position to the given lattice position respecting periodicity for the overlap no...
std::vector< T > getMinPhysR() const
Returns the minimum coordinate in the structure.
void getNeighbourhood(int cuboid, std::vector< int > &neighbours, int offset=0)
stores the neighbouring cuboids in array neighbours;
bool getLatticeR(std::vector< T > physR, std::vector< int > &latticeR) const
Returns true and the nearest lattice position to the given physical position if the physical position...
T getMinPhysVolume() const
Returns the maximum/minimum volume in the structure.
void add(Cuboid2D< T > cuboid)
Adds a cuboid.
std::vector< T > getMaxPhysR() const
Returns the maximum coordinate in the structure.
void split(int iC, int p)
Removes all cuboids where geometryData = 0.
int get_iC(T globX, T globY, int offset=0) const
for a given point (globX/globY), returns the related cuboidID and _p if the point is not in any of th...
IndicatorF2D is an application from .
The description of a vector of 2D cuboid – header file.
This file contains indicator functions.
ADf< T, DIM > floor(const ADf< T, DIM > &a)
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Top level namespace for all of OpenLB.