OpenLB 1.7
Loading...
Searching...
No Matches
cuboid3D.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2007, 2014 Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
28#ifndef CUBOID_3D_H
29#define CUBOID_3D_H
30
31#include <vector>
32#include <math.h>
33
34#include "core/serializer.h"
35#include "core/blockStructure.h"
36#include "io/ostreamManager.h"
38
39
40// All OpenLB code is contained in this namespace.
41namespace olb {
42
43
44template<typename T> class IndicatorF3D;
45
46
49
57template<typename T>
58class Cuboid3D final : public Serializable {
59private:
61 T _globPosX, _globPosY, _globPosZ;
63 T _delta;
65 int _nX, _nY, _nZ;
67 size_t _weight;
68
70 mutable OstreamManager clout;
71
72public:
75
77 Cuboid3D();
79 Cuboid3D(T globPosX, T globPosY, T globPosZ, T delta, int nX, int nY, int nZ);
81 Cuboid3D(std::vector<T> origin, T delta, std::vector<int> extend);
82 Cuboid3D(Vector<T,3> origin, T delta, Vector<int,3> extend);
84 Cuboid3D(IndicatorF3D<T>& indicatorF, T voxelSize);
86 Cuboid3D(Cuboid3D<T> const& rhs, int overlap=0);
88 Cuboid3D& operator=(Cuboid3D const& rhs);
90 void init(T globPosX, T globPosY, T globPosZ, T delta, int nX, int nY, int nZ);
91
93 Vector<T,3> getOrigin() const;
95 T getDeltaR() const;
97 int getNx() const;
99 int getNy() const;
101 int getNz() const;
103 Vector<int,3> const getExtent() const;
105 T getPhysVolume() const;
107 int getWeightValue() const;
109 std::size_t getWeight() const;
111 std::size_t getWeightIn(IndicatorF3D<T>& indicator) const;
113 void setWeight(size_t fullCells);
115 T getFraction() const {
116 return T(getWeight()) / getLatticeVolume();
117 }
119 size_t getLatticeVolume() const;
121 T getPhysPerimeter() const;
123 int getLatticePerimeter() const;
124
126 void refine(int factor);
127
128 bool getLatticeR(Vector<T,3> physR, Vector<int,3>& latticeR, T eps=1e-5) {
129 auto globR = Vector<T,3>{_globPosX, _globPosY, _globPosZ};
130 auto physLatticeR = (physR - globR) / _delta;
131 if ( std::fabs(std::roundf(physLatticeR[0]) - physLatticeR[0]) <= eps
132 && std::fabs(std::roundf(physLatticeR[1]) - physLatticeR[1]) <= eps
133 && std::fabs(std::roundf(physLatticeR[2]) - physLatticeR[2]) <= eps) {
134 latticeR[0] = std::roundf(physLatticeR[0]);
135 latticeR[1] = std::roundf(physLatticeR[1]);
136 latticeR[2] = std::roundf(physLatticeR[2]);
137 return true;
138 } else {
139 return false;
140 }
141 }
142
144 bool operator==(const Cuboid3D<T>& rhs) const;
145
147 std::size_t getNblock() const override;
149 std::size_t getSerializableSize() const override;
151 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
152
154 void print() const;
155
156 void getPhysR(T physR[3], const int latticeR[3]) const;
157 void getPhysR(T physR[3], const int& iX, const int& iY, const int& iZ) const;
158 void getPhysR(T physR[3], LatticeR<3> latticeR) const;
159
160 void getLatticeR(int latticeR[3], const T physR[3]) const;
161 void getLatticeR(int latticeR[3], const Vector<T,3>& physR) const;
162
163 void getFloorLatticeR(const std::vector<T>& physR, std::vector<int>& latticeR) const;
164 void getFloorLatticeR(int latticeR[3], const T physR[3]) const;
165
168 bool checkPoint(T globX, T globY, T globZ, int overlap = 0) const; //TODO globX-> x + additional interface: with (std::vector<T> physR, int overlap=0)
169 bool checkPoint(Vector<T,3>& globXYZ, int overlap = 0) const;
171 bool physCheckPoint(T globX, T globY, T globZ, double overlap = 0) const;
175 // TODO: adapt to use only sum operation (cf. #204)
176 [[deprecated]] bool checkPoint(T globX, T globY, T globZ, int &locX, int &locY, int &locZ, int overlap = 0) const; //TODO globX-> x + additional interface: with (std::vector<T> physR, std::vector<int>& latticeR, int overlap=0)
179 bool checkInters(T globX0, T globX1, T globY0, T globY1, T globZ0, T globZ1, int overlap = 0) const;
182 bool checkInters(T globX, T globY, T globZ, int overlap = 0) const;
187 bool checkInters(T globX0, T globX1, T globY0, T globY1, T globZ0, T globZ1,
188 int &locX0, int &locX1, int &locY0, int &locY1, int &locZ0, int &locZ1,
189 int overlap = 0) const;
191 bool checkInters(Cuboid3D<T>& child) const;
193 void divide(int p, int q, int r, std::vector<Cuboid3D<T> > &childrenC) const;
195 void divide(int p, std::vector<Cuboid3D<T> > &childrenC) const;
196
198 void divideFractional(int iD, std::vector<T> fractions, std::vector<Cuboid3D<T>>& childrenC) const;
199
201 void resize(int X, int Y, int Z, int nX, int nY, int nZ);
202
203};
204
205} // namespace olb
206
207#endif
A regular single 3D cuboid is the basic component of a 3D cuboid structure which defines the grid.
Definition cuboid3D.h:58
void divideFractional(int iD, std::vector< T > fractions, std::vector< Cuboid3D< T > > &childrenC) const
Divides the cuboid into fractions along the iDth dimension.
Definition cuboid3D.hh:530
std::size_t getWeightIn(IndicatorF3D< T > &indicator) const
Returns the number of full cells w.r.t. indicator.
Definition cuboid3D.hh:194
size_t getLatticeVolume() const
Returns the number of Nodes in the volume.
Definition cuboid3D.hh:221
std::size_t getNblock() const override
Number of data blocks for the serializable interface.
Definition cuboid3D.hh:123
Cuboid3D & operator=(Cuboid3D const &rhs)
Copy assignment.
Definition cuboid3D.hh:102
Vector< T, 3 > getOrigin() const
Read only access to left lower corner coordinates.
Definition cuboid3D.hh:135
Vector< int, 3 > const getExtent() const
Read only access to the number of voxels in every dimension.
Definition cuboid3D.hh:165
T getPhysVolume() const
Returns the volume of the cuboid.
Definition cuboid3D.hh:171
Cuboid3D()
Construction of an empty cuboid at position 0, 0, 0 with delta 0 and nX = nY = nZ = 0.
Definition cuboid3D.hh:50
int getWeightValue() const
Returns the actual value of weight (-1 for getLatticeVolume())
Definition cuboid3D.hh:177
bool checkInters(T globX0, T globX1, T globY0, T globY1, T globZ0, T globZ1, int overlap=0) const
Checks whether there is an intersection with the cuboid extended with an layer of size overlap*delta.
Definition cuboid3D.hh:409
T getDeltaR() const
Read only access to the distance of cuboid nodes.
Definition cuboid3D.hh:141
bool physCheckPoint(T globX, T globY, T globZ, double overlap=0) const
Same for physical overlap.
Definition cuboid3D.hh:378
bool * getBlock(std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
Definition cuboid3D.hh:266
static Cuboid3D< T > motherOf(Cuboid3D< T > a, Cuboid3D< T > b)
Return minimum bounding cuboid encompassing both a and b.
void divide(int p, int q, int r, std::vector< Cuboid3D< T > > &childrenC) const
Divides the cuboid in p*q*r cuboids of equal volume and add them to the given vector.
Definition cuboid3D.hh:488
void init(T globPosX, T globPosY, T globPosZ, T delta, int nX, int nY, int nZ)
Initializes the cuboid.
Definition cuboid3D.hh:111
void getFloorLatticeR(const std::vector< T > &physR, std::vector< int > &latticeR) const
Definition cuboid3D.hh:347
int getLatticePerimeter() const
Returns the number of Nodes at the perimeter.
Definition cuboid3D.hh:233
int getNz() const
Read access to cuboid depth.
Definition cuboid3D.hh:159
T getFraction() const
Returns fraction of full cells (weight / volume)
Definition cuboid3D.h:115
int getNy() const
Read access to cuboid height.
Definition cuboid3D.hh:153
bool operator==(const Cuboid3D< T > &rhs) const
equal operator
Definition cuboid3D.hh:252
void setWeight(size_t fullCells)
Sets the number of full cells.
Definition cuboid3D.hh:215
T getPhysPerimeter() const
Returns the perimeter of the cuboid.
Definition cuboid3D.hh:227
int getNx() const
Read access to cuboid width.
Definition cuboid3D.hh:147
void print() const
Prints cuboid details.
Definition cuboid3D.hh:284
bool getLatticeR(Vector< T, 3 > physR, Vector< int, 3 > &latticeR, T eps=1e-5)
Definition cuboid3D.h:128
bool checkPoint(T globX, T globY, T globZ, int overlap=0) const
Checks whether a point (globX/gloxY/globZ) is contained in the cuboid extended with an layer of size ...
Definition cuboid3D.hh:361
void getPhysR(T physR[3], const int latticeR[3]) const
Definition cuboid3D.hh:307
std::size_t getSerializableSize() const override
Binary size for the serializer interface.
Definition cuboid3D.hh:129
std::size_t getWeight() const
Returns the number of full cells.
Definition cuboid3D.hh:183
void refine(int factor)
Refines by splitting each cell into factor^3 cells.
Definition cuboid3D.hh:239
void resize(int X, int Y, int Z, int nX, int nY, int nZ)
resize the cuboid to the passed size
Definition cuboid3D.hh:518
IndicatorF3D is an application from .
class for marking output with some text
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
Definition serializer.h:145
Plain old scalar vector.
Definition vector.h:47
This file contains indicator functions.
Top level namespace for all of OpenLB.