OpenLB 1.8.1
Loading...
Searching...
No Matches
cuboid.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 * 2025 Adrian Kummerlaender
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
25#ifndef CUBOID_H
26#define CUBOID_H
27
28#include "core/vector.h"
29#include "core/serializer.h"
30
32
33#include <optional>
34
35namespace olb {
36
37template <typename T, unsigned D>
38class Cuboid final {
39private:
41 Vector<T,D> _origin;
43 Vector<int,D> _extent;
45 T _delta;
47 std::size_t _weight;
48
49 // Don't want to use concept here as it would have to be repeated for all method implementations
50 static_assert(D == 2 || D == 3, "Only 2D/3D supported");
51
52public:
53 Cuboid() = default;
54 Cuboid(Vector<T,D> origin, T delta, Vector<int,D> extent):
55 _origin(origin),
56 _extent(extent),
57 _delta(delta),
58 _weight(getLatticeVolume()) { }
59 Cuboid(const Cuboid& rhs):
60 _origin(rhs._origin),
61 _extent(rhs._extent),
62 _delta(rhs._delta),
63 _weight(rhs._weight) { }
64 Cuboid(IndicatorF<T,D>& indicatorF, T delta):
65 _origin(indicatorF.getMin()),
66 _extent((indicatorF.getMax() - indicatorF.getMin()) / delta + 1.5),
67 _delta(delta),
68 _weight(getLatticeVolume()) { }
69
70 Cuboid& operator=(const Cuboid& rhs);
71 bool operator==(const Cuboid& rhs) const;
72
74 Vector<T,D> getOrigin() const { return _origin; }
76 T getDeltaR() const { return _delta; }
78 Vector<int,D> getExtent() const { return _extent; }
79
80 int getNx() const { return _extent[0]; }
81 int getNy() const { return _extent[1]; }
82 int getNz() const { return _extent[2]; }
83
85 T getPhysVolume() const;
86
87 std::size_t getWeight() const { return _weight; }
88 void setWeight(std::size_t weight) { _weight = weight; }
89
91 return _origin + latticeR*_delta;
92 }
93
95 return util::floor((physR - _origin) / _delta + 0.5);
96 }
97
99 return util::floor((physR - _origin) / _delta);
100 }
101
103 std::optional<LatticeR<D>> getCloseLatticeR(Vector<T,D> physR, T eps=1e-5) const;
104
106 std::size_t getLatticeVolume() const;
108 T getPhysPerimeter() const requires (D == 2);
110 T getPhysPerimeter() const requires (D == 3);
112 std::size_t getLatticePerimeter() const requires (D == 2);
114 std::size_t getLatticePerimeter() const requires (D == 3);
115
117 bool isInside(Vector<T,D> pos, int overlap = 0) const;
118
120 bool intersects(Vector<T,D> globMin, Vector<T,D> globMax, int overlap = 0) const;
122 bool intersects(const Cuboid<T,D>& cuboid) const;
123
125 void divide(Vector<int,D> division, std::vector<Cuboid<T,D>>& childrenC) const requires (D == 3);
127 void divide(Vector<int,D> division, std::vector<Cuboid<T,D>>& childrenC) const requires (D == 2);
128
130 void divideP(int p, std::vector<Cuboid<T,D>>& childrenC) const requires (D == 2);
132 void divideP(int p, std::vector<Cuboid<T,D>>& childrenC) const requires (D == 3);
133
135 void divideFractional(int iD, std::vector<T> fractions, std::vector<Cuboid<T,D>>& childrenC) const;
136
137 void resize(Vector<int,D> offset, Vector<int,D> extent);
138
139 void refine(int factor);
140
141 void write(std::ostream& cout) const;
142 void print() const;
143
144 void writeAsXML(std::ostream&) const;
145
146};
147
148template <typename T>
149using Cuboid2D = Cuboid<T,2>;
150template <typename T>
151using Cuboid3D = Cuboid<T,3>;
152
153}
154
155#endif
Cuboid(Vector< T, D > origin, T delta, Vector< int, D > extent)
Definition cuboid.h:54
int getNz() const
Definition cuboid.h:82
T getPhysPerimeter() const
Returns the perimeter of the cuboid.
Definition cuboid.hh:71
Vector< T, D > getOrigin() const
Returns lower left corner coordinates.
Definition cuboid.h:74
Cuboid(IndicatorF< T, D > &indicatorF, T delta)
Definition cuboid.h:64
LatticeR< D > getFloorLatticeR(Vector< T, D > physR) const
Definition cuboid.h:98
Cuboid(const Cuboid &rhs)
Definition cuboid.h:59
bool intersects(Vector< T, D > globMin, Vector< T, D > globMax, int overlap=0) const
Checks whether there is an intersection with the cuboid extended by a layer of size overlap*delta.
Definition cuboid.hh:144
std::size_t getLatticeVolume() const
Returns the number of Nodes in the volume.
Definition cuboid.hh:62
Vector< int, D > getExtent() const
Returns extent in number of voxels.
Definition cuboid.h:78
Cuboid & operator=(const Cuboid &rhs)
Definition cuboid.hh:33
std::optional< LatticeR< D > > getCloseLatticeR(Vector< T, D > physR, T eps=1e-5) const
Returns closest latticeR within eps of physR if it exists.
Definition cuboid.hh:42
void print() const
Definition cuboid.hh:122
int getNy() const
Definition cuboid.h:81
bool operator==(const Cuboid &rhs) const
Definition cuboid.hh:129
int getNx() const
Definition cuboid.h:80
T getDeltaR() const
Returns spacing of cuboid nodes.
Definition cuboid.h:76
std::size_t getWeight() const
Definition cuboid.h:87
LatticeR< D > getLatticeR(Vector< T, D > physR) const
Definition cuboid.h:94
bool isInside(Vector< T, D > pos, int overlap=0) const
Checks whether pos is contained in the cuboid extended with an layer of size overlap*delta.
Definition cuboid.hh:137
void resize(Vector< int, D > offset, Vector< int, D > extent)
Definition cuboid.hh:540
void refine(int factor)
Definition cuboid.hh:92
T getPhysVolume() const
Returns the volume of the cuboid.
Definition cuboid.hh:53
void setWeight(std::size_t weight)
Definition cuboid.h:88
Cuboid()=default
std::size_t getLatticePerimeter() const
Returns the number of Nodes at the perimeter.
Definition cuboid.hh:82
void divideP(int p, std::vector< Cuboid< T, D > > &childrenC) const
Divides the cuboid in p cuboids and add them to the given vector.
Definition cuboid.hh:214
Vector< T, D > getPhysR(LatticeR< D > latticeR) const
Definition cuboid.h:90
void divideFractional(int iD, std::vector< T > fractions, std::vector< Cuboid< T, D > > &childrenC) const
Divides the cuboid into fractions along the iDth dimension.
Definition cuboid.hh:546
void writeAsXML(std::ostream &) const
Definition cuboid.hh:577
void write(std::ostream &cout) const
Definition cuboid.hh:106
void divide(Vector< int, D > division, std::vector< Cuboid< T, D > > &childrenC) const
Divides the cuboid in p*q*r cuboids of equal volume and add them to the given vector.
Definition cuboid.hh:161
Plain old scalar vector.
ADf< T, DIM > floor(const ADf< T, DIM > &a)
Definition aDiff.h:869
Top level namespace for all of OpenLB.
std::conditional_t< D==2, IndicatorF2D< T >, IndicatorF3D< T > > IndicatorF
Definition aliases.h:247
efficient implementation of a vector class