OpenLB 1.7
Loading...
Searching...
No Matches
blockIndicatorF2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2017 Adrian Kummerlaender
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
24#ifndef BLOCK_INDICATOR_F_2D_HH
25#define BLOCK_INDICATOR_F_2D_HH
26
27#include <algorithm>
28
29#include "blockIndicatorF2D.h"
30#include "core/util.h"
31
32namespace olb {
33
34template <typename T>
36 IndicatorF2D<T>& indicatorF, BlockGeometry<T,2>& blockGeometry)
37 : BlockIndicatorF2D<T>(blockGeometry),
38 _indicatorF(indicatorF)
39{ }
40
41template <typename T>
42bool BlockIndicatorFfromIndicatorF2D<T>::operator() (bool output[], const int input[])
43{
44 T physR[2];
45 this->_blockGeometryStructure.getPhysR(physR,input);
46 return _indicatorF(output,physR);
47}
48
49template <typename T>
51{
52 const Vector<T,2> min = _indicatorF.getMin();
53 return Vector<int,2> {
54 static_cast<int>(util::floor(min[0])),
55 static_cast<int>(util::floor(min[1]))
56 };
57}
58
59template <typename T>
61{
62 const Vector<T,2> max = _indicatorF.getMax();
63 return Vector<int,2> {
64 static_cast<int>(util::ceil(max[0])),
65 static_cast<int>(util::ceil(max[1]))
66 };
67}
68
69
70template <typename T, bool HLBM>
76
77template <typename T, bool HLBM>
79{
80 T physR[2];
81 T inside[1];
82 this->_blockGeometryStructure.getPhysR(physR,input);
83 _indicatorF(inside, physR);
84 return !util::nearZero(inside[0]);
85}
86
87template <typename T, bool HLBM>
92
93template <typename T, bool HLBM>
95{
96 return this->_blockGeometryStructure.getExtent() - Vector<int,2> {1,1};
97}
98
99
100template <typename T>
102 BlockGeometry<T,2>& blockGeometry, std::vector<int> materials)
103 : BlockIndicatorF2D<T>(blockGeometry),
104 _materials(materials)
105{ }
106
107template <typename T>
109 BlockGeometry<T,2>& blockGeometry, std::list<int> materials)
110 : BlockIndicatorMaterial2D(blockGeometry,
111 std::vector<int>(materials.begin(), materials.end()))
112{ }
113
114template <typename T>
116 BlockGeometry<T,2>& blockGeometry, int material)
117 : BlockIndicatorMaterial2D(blockGeometry, std::vector<int>(1,material))
118{ }
119
120template <typename T>
121bool BlockIndicatorMaterial2D<T>::operator() (bool output[], const int input[])
122{
123 // read material number explicitly using the const version
124 // of BlockGeometry<T,2>::get to avoid resetting geometry
125 // statistics:
126 const BlockGeometry<T,2>& blockGeometry = this->_blockGeometryStructure;
127 const int current = blockGeometry.getMaterial({input[0], input[1]});
128 output[0] = std::any_of(_materials.cbegin(),
129 _materials.cend(),
130 [current](int material) {
131 return current == material;
132 });
133
134 return true;
135}
136
137template <typename T>
139{
140 const auto& statistics = this->getBlockGeometry().getStatistics();
141 return std::none_of(_materials.cbegin(), _materials.cend(),
142 [&statistics](int material) -> bool {
143 return statistics.getNvoxel(material) > 0;
144 });
145}
146
147template <typename T>
149{
150 const auto& blockGeometry = this->getBlockGeometry();
151 const auto& statistics = blockGeometry.getStatistics();
152
153 Vector<int,2> globalMin{
154 blockGeometry.getNx()+blockGeometry.getPadding()-1,
155 blockGeometry.getNy()+blockGeometry.getPadding()-1
156 };
157
158 for ( int material : _materials ) {
159 if ( statistics.getNvoxel(material) > 0 ) {
160 const Vector<int,2> localMin = statistics.getMinLatticeR(material);
161 for ( int d = 0; d < 2; ++d ) {
162 globalMin[d] = localMin[d] < globalMin[d] ? localMin[d] : globalMin[d];
163 }
164 }
165 }
166
167 return globalMin;
168}
169
170template <typename T>
172{
173 const auto& statistics = this->getBlockGeometry().getStatistics();
174
175 Vector<int,2> globalMax = -this->getBlockGeometry().getPadding();
176
177 for ( int material : _materials ) {
178 if ( statistics.getNvoxel(material) > 0 ) {
179
180 const Vector<int,2> localMax = statistics.getMaxLatticeR(material);
181 for ( int d = 0; d < 2; ++d ) {
182 globalMax[d] = localMax[d] > globalMax[d] ? localMax[d] : globalMax[d];
183 }
184 }
185 }
186
187 return globalMax;
188}
189
190
191template <typename T>
193 : BlockIndicatorF2D<T>(indicatorF.getBlockGeometry()),
194 _indicatorF(indicatorF)
195{ }
196
197template <typename T>
198bool BlockIndicatorIdentity2D<T>::operator() (bool output[], const int input[])
199{
200 return _indicatorF(output, input);
201}
202
203template <typename T>
205{
206 return _indicatorF.getMin();
207}
208
209template <typename T>
211{
212 return _indicatorF.getMax();
213}
214
215
216template <typename T>
218 : BlockIndicatorF2D<T>(indicatorF.getBlockGeometry()),
219 _indicatorF(indicatorF),
220 _overlap(overlap)
221{ }
222
223template <typename T>
224bool BlockIndicatorBoundaryNeighbor2D<T>::operator() (bool output[], const int input[])
225{
226 // check if current position is not solid
227 if ( this->getBlockGeometry().getMaterial(input[0],input[1]) != 0 ) {
228 // check all neighbors if they are part of boundary via indicator
229 for ( int iXo = -_overlap; iXo <= _overlap; ++iXo ) {
230 for ( int iYo = -_overlap; iYo <= _overlap; ++iYo ) {
231 const int neighborPos[2] = {iXo + input[0], iYo + input[1]};
232 bool partOfBoundary[1] = {false};
233 // material-indicator to check if part of boundary
234 _indicatorF( partOfBoundary, neighborPos );
235 if ( partOfBoundary[0] ) {
236 return true;
237 }
238 }
239 }
240 }
241 return false;
242}
243
244template <typename T>
246{
247 return _indicatorF.getMin() - _overlap;
248}
249
250template <typename T>
252{
253 return _indicatorF.getMax() + _overlap;
254}
255
256} // namespace olb
257
258#endif
Representation of a block geometry.
int getMaterial(LatticeR< D > latticeR) const
returns the (iX,iY) entry in the 2D scalar field
Vector< int, 2 > getMax() override
Returns max lattice position of the indicated domain's bounding box.
BlockIndicatorBoundaryNeighbor2D(BlockIndicatorF2D< T > &indicatorF, int overlap)
bool operator()(bool output[], const int input[]) override
Vector< int, 2 > getMin() override
Returns min lattice position of the indicated domain's bounding box.
Base block indicator functor (discrete)
Vector< int, 2 > getMax() override
Returns max lattice position of the indicated domain's bounding box.
BlockIndicatorFfromIndicatorF2D(IndicatorF2D< T > &indicatorF, BlockGeometry< T, 2 > &blockGeometry)
Vector< int, 2 > getMin() override
Returns min lattice position of the indicated domain's bounding box.
bool operator()(bool output[], const int input[]) override
bool operator()(bool output[], const int input[]) override
Vector< int, 2 > getMin() override
Returns a min lattice position of the indicated domain's bounding box.
Vector< int, 2 > getMax() override
Returns a max lattice position of the indicated domain's bounding box.
BlockIndicatorFfromSmoothIndicatorF2D(SmoothIndicatorF2D< T, T, HLBM > &indicatorF, BlockGeometry< T, 2 > &blockGeometry)
bool operator()(bool output[], const int input[]) override
BlockIndicatorIdentity2D(BlockIndicatorF2D< T > &indicatorF)
Vector< int, 2 > getMin() override
Returns min lattice position of the indicated domain's bounding box.
Vector< int, 2 > getMax() override
Returns max lattice position of the indicated domain's bounding box.
Block indicator functor from material numbers.
Vector< int, 2 > getMax() override
Returns max lattice position of the indicated domain's bounding box.
bool operator()(bool output[], const int input[]) override
bool isEmpty() override
Returns true iff indicated domain subset is empty.
BlockIndicatorMaterial2D(BlockGeometry< T, 2 > &blockGeometry, std::vector< int > materials)
Vector< int, 2 > getMin() override
Returns min lattice position of the indicated domain's bounding box.
IndicatorF2D is an application from .
Plain old scalar vector.
Definition vector.h:47
ADf< T, DIM > ceil(const ADf< T, DIM > &a)
Definition aDiff.h:900
ADf< T, DIM > floor(const ADf< T, DIM > &a)
Definition aDiff.h:869
bool nearZero(const ADf< T, DIM > &a)
Definition aDiff.h:1087
Top level namespace for all of OpenLB.
Set of functions commonly used in LB computations – header file.