OpenLB 1.7
Loading...
Searching...
No Matches
cuboidGeometry3D.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
29#ifndef CUBOID_GEOMETRY_3D_H
30#define CUBOID_GEOMETRY_3D_H
31
32#include <vector>
33#include <fstream>
34
35#include "core/singleton.h"
36#include "core/serializer.h"
37#include "core/vector.h"
38
39#include "io/ostreamManager.h"
40#include "io/xmlReader.h"
41
42#include "cuboid3D.h"
44
45// All OpenLB code is contained in this namespace.
46namespace olb {
47
48
49template< typename T> class Cuboid3D;
50template <typename T> class IndicatorF3D;
51template <typename T> class LoadBalancer;
52
53
55
71template<typename T>
73
74private:
76 std::vector<Cuboid3D<T> > _cuboids;
78 Cuboid3D<T> _motherCuboid;
80 Vector<bool,3> _periodicityOn;
82 mutable OstreamManager clout;
83
84public:
88 CuboidGeometry3D(T originX, T originY, T originZ, T deltaR, int nX, int nY, int nZ, int nC=1);
90 CuboidGeometry3D(std::vector<T> origin, T deltaR, std::vector<int> extent, int nC=1);
91 CuboidGeometry3D(Vector<T,3> origin, T deltaR, Vector<int,3> extent, int nC=1);
93 CuboidGeometry3D(const Cuboid3D<T>& motherCuboid, int nC);
95 CuboidGeometry3D(IndicatorF3D<T>& indicatorF, T voxelSize, int nC=1);
96 CuboidGeometry3D(std::shared_ptr<IndicatorF3D<T>> indicator_sharedPtrF, T voxelSize, int nC=1);
98 CuboidGeometry3D(IndicatorF3D<T>& indicatorF, T voxelSize, int nC, std::string minimizeBy);
99 CuboidGeometry3D(std::shared_ptr<IndicatorF3D<T>> indicator_sharedPtrF, T voxelSize, int nC, std::string minimizeBy);
101 virtual ~CuboidGeometry3D();
102
103
105 Cuboid3D<T>& get(int iC);
107 Cuboid3D<T> const& get(int iC) const;
110 Cuboid3D<T> const& getMotherCuboid() const;
112 void setPeriodicity(bool periodicityX, bool periodicityY, bool periodicityZ);
113
114 std::vector<Cuboid3D<T>>& cuboids() {
115 return _cuboids;
116 }
117
120 int get_iC(T globX, T globY, T globZ, int offset = 0) const; //TODO old ones
121 int get_iC(Vector<T,3>, int offset = 0) const;
129 int get_iC(T globX, T globY, T globZ, int orientationX, int orientationY, int orientationZ) const; //TODO old ones
131 bool getC(T physR[3], int& iC) const;
133 bool getC(std::vector<T> physR, int& iC) const; //TODO new one
135 bool getC(const Vector<T,3>& physR, int& iC) const;
137 bool getLatticeR(int latticeR[4], const T physR[3]) const;
139 bool getFloorLatticeR(const std::vector<T>& physR, std::vector<int>& latticeR) const;
141 bool getFloorLatticeR(const Vector<T,3>& physR, Vector<int,4>& latticeR) const;
143 void getPhysR(T physR[3], const int& iCglob, const int& iX, const int& iY, const int& iZ) const;
145 void getPhysR(T physR[3], const int latticeR[4]) const;
146 void getPhysR(T physR[3], LatticeR<4> latticeR) const;
147 void getPhysR(T output[3], const int iCglob, LatticeR<3> latticeR) const;
148
150 void getNeighbourhood(int cuboid, std::vector<int>& neighbours, int overlap = 0);
152 int getNc() const;
154 T getMinRatio() const;
156 T getMaxRatio() const;
158 Vector<T,3> getMinPhysR() const;
160 Vector<T,3> getMaxPhysR() const;
162 T getMinPhysVolume() const;
164 T getMaxPhysVolume() const;
166 size_t getMinLatticeVolume() const;
168 size_t getMaxLatticeVolume() const;
170 size_t getMinLatticeWeight() const;
172 size_t getMaxLatticeWeight() const;
174 T getMinDeltaR() const;
176 T getMaxDeltaR() const;
177
180
182 void swap(CuboidGeometry3D<T>& rhs);
184 void swapCuboids(std::vector< Cuboid3D<T> >& cuboids);
186 void replaceCuboids(std::vector< Cuboid3D<T> >& cuboids);
187
188 std::size_t replaceContainedBy(Cuboid3D<T> mother);
190
192 void setWeights(IndicatorF3D<T>& indicatorF);
195 {
196 _cuboids.clear();
197 }
199 void add(Cuboid3D<T> cuboid);
201 void split(int iC, int p);
203 void splitRegular(int iC, int width);
205 void splitByWeight(int iC, int p, IndicatorF3D<T>& indicatorF);
207 void splitFractional(int iC, int iD, std::vector<T> fractions);
209 void remove(int iC);
211 void remove(IndicatorF3D<T>& indicatorF);
213 void removeByWeight();
215 void shrink(int iC, IndicatorF3D<T>& indicatorF);
217 void shrink(IndicatorF3D<T>& indicatorF);
218
220 void refine(int factor);
222 bool tryRefineTo(T deltaR);
223
225 size_t getNblock() const override;
227 size_t getSerializableSize() const override;
229 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
230
232 void print() const;
234 void printExtended();
235
237 void writeToExistingFile(std::string completeFileName, LoadBalancer<T>& loadBalancer);
239 void writeToFile(std::string fileName, LoadBalancer<T>& loadBalancer);
240
241private:
243 std::string _cuboidParameters(Cuboid3D<T> const& cub);
244};
245
246
247
248
249
250
252template<typename S>
253std::vector<S> getDataFromTag(XMLreader const& reader, std::string attrName, int nData)
254{
255 std::vector<S> values(nData, S());
256 std::stringstream extstr(reader.getAttribute(attrName));
257 for (auto& valueI: values) {
258 extstr >> valueI;
259 }
260 return values;
261}
262
263
265template<typename T>
267{
268 OstreamManager clout("saveCuboidGeometry3D");
269 XMLreader reader(fileName);
270
271 std::vector<T> origin = getDataFromTag<T>(reader["CuboidGeometry"], "origin", 3);
272 std::vector<int> extent = getDataFromTag<int>(reader["CuboidGeometry"], "extent", 3);
273 T deltaR = getDataFromTag<T>(reader["CuboidGeometry"], "deltaR", 1)[0];
274 size_t weight = getDataFromTag<size_t>(reader["CuboidGeometry"], "weight", 1)[0];
275
276 CuboidGeometry3D<T>* cGeo = new CuboidGeometry3D<T> (origin, deltaR, extent);
277 cGeo->getMotherCuboid().setWeight(weight);
278 cGeo->clearCuboids();
279
280 for ( XMLreader* cub: reader["CuboidGeometry"] ) {
281 origin = getDataFromTag<T>(*cub, "origin", 3);
282 extent = getDataFromTag<int>(*cub, "extent", 3);
283 deltaR = getDataFromTag<T>(*cub, "deltaR", 1)[0];
284 weight = getDataFromTag<int>(*cub, "weight", 1)[0];
285
286 cGeo->add( Cuboid3D<T>(origin, deltaR, extent) );
287 cGeo->get(cGeo->getNc() - 1).setWeight(weight);
288 }
289
290 return cGeo;
291}
292
294template<typename T>
296 CuboidGeometry3D<T>& cuboidGeometry,
297 std::map<int,std::vector<int>>& neighbourhood,
298 int offset=0 )
299{
300 for (int iC=0; iC<cuboidGeometry.getNc(); ++iC){
301 //Retrieve neighbours of iC
302 std::vector<int> neighbours;
303 cuboidGeometry.getNeighbourhood(iC, neighbours, offset);
304 neighbourhood[iC]=neighbours;
305 }
306}
307
308
309
313 std::map<int,std::vector<int>>& neighbourhood,
314 bool correct = false,
315 bool verbose = false)
316{
317 bool consistent = true;
318 for ( auto cuboidNeighbourPair : neighbourhood){
319 //Retrieve iC and neighbours
320 int iC = cuboidNeighbourPair.first;
321 std::vector<int>& neighbours = cuboidNeighbourPair.second;
322 //Loop over neighbours
323 for (int iCN : neighbours){
324 //Retreive neighbour's neighbours
325 std::vector<int>& neighboursNeighbours = neighbourhood[iCN];
326 bool iCfound = false;
327 //Loop over neighbour's neighbours
328 for (int iCNN : neighboursNeighbours ){
329 if (iCNN == iC){
330 iCfound=true;
331 break;
332 }
333 }
334 if (!iCfound){
335 //Set consistency boolean to false
336 consistent = false;
337 //Output, if desired
338 if (verbose){
339 std::cout << "iC " << iC << " not found in list of neighbour iC "
340 << iCN << std::endl;
341 }
342 //Correct, if desired
343 if (correct){
344 neighbourhood[iCN].push_back(iC);
345 }
346 }
347 }
348 }
349 //Return whether consistent
350 return consistent;
351}
352
353
354
355
356} // namespace olb
357
358#endif
Base class for serializable objects of dynamic size
Definition serializer.h:299
A regular single 3D cuboid is the basic component of a 3D cuboid structure which defines the grid.
Definition cuboid3D.h:58
A cuboid geometry represents a voxel mesh.
void splitByWeight(int iC, int p, IndicatorF3D< T > &indicatorF)
Splits cuboid iC, removes it and adds p cuboids of same weight.
std::size_t replaceContainedBy(Cuboid3D< T > mother)
T getMinRatio() const
Returns the minimum of the ratio nX/NY in the structure.
Cuboid3D< T > & get(int iC)
Read and write access to a single cuboid.
void swap(CuboidGeometry3D< T > &rhs)
Swaps data from input into object.
size_t getSerializableSize() const override
Binary size for the serializer interface.
bool operator==(CuboidGeometry3D< T > &rhs)
Compares two CuboidGeometries.
T getMaxRatio() const
Returns the maximum of the ratio nX/NY in the structure.
void refine(int factor)
Refines mesh by splitting each cell into factor^3 cells.
bool getFloorLatticeR(const 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 writeToFile(std::string fileName, LoadBalancer< T > &loadBalancer)
Save CuboidGeometry into XML File.
void shrink(int iC, IndicatorF3D< T > &indicatorF)
Shrink cuboid iC so that no empty planes are left.
size_t getNblock() const override
Number of data blocks for the serializer interface.
std::vector< Cuboid3D< T > > & cuboids()
void swapCuboids(std::vector< Cuboid3D< T > > &cuboids)
Swaps the vector of cuboids.
void replaceCuboids(std::vector< Cuboid3D< T > > &cuboids)
Replace the vector of cuboids.
int get_iC(T globX, T globY, T globZ, int offset=0) const
Gives for a given point (globX/globY/globZ) the related cuboidID and _p if the point is not in any of...
bool * getBlock(std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
Return a pointer to the memory of the current block and its size for the serializable interface.
T getMaxDeltaR() const
Returns the maximum delta in the structure.
void print() const
Prints cuboid geometry details.
bool getC(T physR[3], int &iC) const
Returns true and the cuboid number of the nearest lattice position to the given physical position if ...
void split(int iC, int p)
Splits cuboid iC, removes it and adds p cuboids of same volume.
bool tryRefineTo(T deltaR)
Tries to refine mesh to given deltaR.
Vector< T, 3 > getMinPhysR() const
Returns the minimum coordinate in the structure.
virtual ~CuboidGeometry3D()
Destructs CuboidGeometry.
size_t getMaxLatticeVolume() const
Returns the maximum number of nodes in the structure.
bool getLatticeR(int latticeR[4], const T physR[3]) const
Returns true and the nearest lattice position to the given physical position if the physical position...
void remove(int iC)
Removes the cuboid iC.
void writeToExistingFile(std::string completeFileName, LoadBalancer< T > &loadBalancer)
Save CuboidGeometry into an existing XML File.
T getMinPhysVolume() const
Returns the minimum volume in the structure.
int getNc() const
Returns the number of cuboids in the structure.
std::size_t hypotheticalReplaceContainedBy(Cuboid3D< T > mother)
void setWeights(IndicatorF3D< T > &indicatorF)
Sets the number of full cells of each cuboid.
Vector< T, 3 > getMaxPhysR() const
Returns the maximum coordinate in the structure.
void splitRegular(int iC, int width)
Splits cuboid iC, removes it, adds approx. width^3 sized new cuboids.
Cuboid3D< T > getMotherCuboid()
Returns the smallest cuboid that includes all cuboids of the structure.
CuboidGeometry3D()
Constructs empty Geometry.
void add(Cuboid3D< T > cuboid)
Adds a cuboid.
size_t getMinLatticeVolume() const
Returns the minimum number of nodes in the structure.
void clearCuboids()
Resets the cuboid array.
void removeByWeight()
Removes all cuboids where weight = 0.
void printExtended()
Prints cuboid geometry details plus details of all cuboids.
size_t getMaxLatticeWeight() const
Returns the maximum number of nodes in the structure inside the indicator.
T getMinDeltaR() const
Returns the minimum delta in the structure.
size_t getMinLatticeWeight() const
Returns the minimum number of nodes in the structure inside the indicator.
void getPhysR(T physR[3], const int &iCglob, const int &iX, const int &iY, const int &iZ) const
Returns the physical position to the given lattice position respecting periodicity for the overlap no...
void splitFractional(int iC, int iD, std::vector< T > fractions)
Splits cuboid iC along dimension iD into cuboids of fractions.
T getMaxPhysVolume() const
Returns the maximum volume in the structure.
void getNeighbourhood(int cuboid, std::vector< int > &neighbours, int overlap=0)
Stores the iC of the neighbouring cuboids in a vector;.
void setPeriodicity(bool periodicityX, bool periodicityY, bool periodicityZ)
Set flag to enable/disable periodicity depending of direction. Be aware that not all directions are t...
IndicatorF3D is an application from .
Base class for all LoadBalancer.
class for marking output with some text
Plain old scalar vector.
Definition vector.h:47
std::string getAttribute(const std::string &aName) const
Definition xmlReader.h:541
The description of a single 3D cuboid – header file.
Top level namespace for all of OpenLB.
std::vector< S > getDataFromTag(XMLreader const &reader, std::string attrName, int nData)
Helper Function to retrieve nData-dimensional std::vector of type S from space separated tag.
void evaluateCuboidGeometryNeighbourhood(CuboidGeometry2D< T > &cuboidGeometry, std::map< int, std::vector< int > > &neighbourhood, int offset=0)
Evaluate complete neighbourhood and store in std::map.
CuboidGeometry3D< T > * createCuboidGeometry(std::string fileName)
Load CuboidGeometry from XML File.
bool checkCuboidNeighbourhoodConsistency(std::map< int, std::vector< int > > &neighbourhood, bool correct=false, bool verbose=false)
Consistency check for neighbour retrieval.
Definition of singletons: global, publicly available information.
efficient implementation of a vector class
Input/Output in XML format – header file.