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 auto physR = this->_blockGeometryStructure.getPhysR(input);
45 return _indicatorF(output, physR.data());
46}
47
48template <typename T>
50{
51 const Vector<T,2> min = _indicatorF.getMin();
52 return Vector<int,2> {
53 static_cast<int>(util::floor(min[0])),
54 static_cast<int>(util::floor(min[1]))
55 };
56}
57
58template <typename T>
60{
61 const Vector<T,2> max = _indicatorF.getMax();
62 return Vector<int,2> {
63 static_cast<int>(util::ceil(max[0])),
64 static_cast<int>(util::ceil(max[1]))
65 };
66}
67
68
69template <typename T, bool HLBM>
75
76template <typename T, bool HLBM>
78{
79 T inside[1];
80 auto physR = this->_blockGeometryStructure.getPhysR(input);
81 _indicatorF(inside, physR.data());
82 return !util::nearZero(inside[0]);
83}
84
85template <typename T, bool HLBM>
90
91template <typename T, bool HLBM>
93{
94 return this->_blockGeometryStructure.getExtent() - Vector<int,2> {1,1};
95}
96
97
98template <typename T>
100 BlockGeometry<T,2>& blockGeometry, std::vector<int> materials)
101 : BlockIndicatorF2D<T>(blockGeometry),
102 _materials(materials)
103{ }
104
105template <typename T>
107 BlockGeometry<T,2>& blockGeometry, std::list<int> materials)
108 : BlockIndicatorMaterial2D(blockGeometry,
109 std::vector<int>(materials.begin(), materials.end()))
110{ }
111
112template <typename T>
114 BlockGeometry<T,2>& blockGeometry, int material)
115 : BlockIndicatorMaterial2D(blockGeometry, std::vector<int>(1,material))
116{ }
117
118template <typename T>
119bool BlockIndicatorMaterial2D<T>::operator() (bool output[], const int input[])
120{
121 // read material number explicitly using the const version
122 // of BlockGeometry<T,2>::get to avoid resetting geometry
123 // statistics:
124 const BlockGeometry<T,2>& blockGeometry = this->_blockGeometryStructure;
125 const int current = blockGeometry.getMaterial({input[0], input[1]});
126 output[0] = std::any_of(_materials.cbegin(),
127 _materials.cend(),
128 [current](int material) {
129 return current == material;
130 });
131
132 return true;
133}
134
135template <typename T>
137{
138 const auto& statistics = this->getBlockGeometry().getStatistics();
139 return std::none_of(_materials.cbegin(), _materials.cend(),
140 [&statistics](int material) -> bool {
141 return statistics.getNvoxel(material) > 0;
142 });
143}
144
145template <typename T>
147{
148 const auto& blockGeometry = this->getBlockGeometry();
149 const auto& statistics = blockGeometry.getStatistics();
150
151 Vector<int,2> globalMin{
152 blockGeometry.getNx()+blockGeometry.getPadding()-1,
153 blockGeometry.getNy()+blockGeometry.getPadding()-1
154 };
155
156 for ( int material : _materials ) {
157 if ( statistics.getNvoxel(material) > 0 ) {
158 const Vector<int,2> localMin = statistics.getMinLatticeR(material);
159 for ( int d = 0; d < 2; ++d ) {
160 globalMin[d] = localMin[d] < globalMin[d] ? localMin[d] : globalMin[d];
161 }
162 }
163 }
164
165 return globalMin;
166}
167
168template <typename T>
170{
171 const auto& statistics = this->getBlockGeometry().getStatistics();
172
173 Vector<int,2> globalMax = -this->getBlockGeometry().getPadding();
174
175 for ( int material : _materials ) {
176 if ( statistics.getNvoxel(material) > 0 ) {
177
178 const Vector<int,2> localMax = statistics.getMaxLatticeR(material);
179 for ( int d = 0; d < 2; ++d ) {
180 globalMax[d] = localMax[d] > globalMax[d] ? localMax[d] : globalMax[d];
181 }
182 }
183 }
184
185 return globalMax;
186}
187
188
189template <typename T>
191 : BlockIndicatorF2D<T>(indicatorF.getBlockGeometry()),
192 _indicatorF(indicatorF)
193{ }
194
195template <typename T>
196bool BlockIndicatorIdentity2D<T>::operator() (bool output[], const int input[])
197{
198 return _indicatorF(output, input);
199}
200
201template <typename T>
203{
204 return _indicatorF.getMin();
205}
206
207template <typename T>
209{
210 return _indicatorF.getMax();
211}
212
213
214template <typename T>
216 : BlockIndicatorF2D<T>(indicatorF.getBlockGeometry()),
217 _indicatorF(indicatorF),
218 _overlap(overlap)
219{ }
220
221template <typename T>
222bool BlockIndicatorBoundaryNeighbor2D<T>::operator() (bool output[], const int input[])
223{
224 // check if current position is not solid
225 if ( this->getBlockGeometry().getMaterial(input[0],input[1]) != 0 ) {
226 // check all neighbors if they are part of boundary via indicator
227 for ( int iXo = -_overlap; iXo <= _overlap; ++iXo ) {
228 for ( int iYo = -_overlap; iYo <= _overlap; ++iYo ) {
229 const int neighborPos[2] = {iXo + input[0], iYo + input[1]};
230 if ( _indicatorF ( neighborPos ) &&
231 this->getBlockGeometry().isInside( neighborPos ) ) {
232 output[0] = true;
233 return true;
234 }
235 }
236 }
237 }
238 return true;
239}
240
241template <typename T>
243{
244 return _indicatorF.getMin() - _overlap;
245}
246
247template <typename T>
249{
250 return _indicatorF.getMax() + _overlap;
251}
252
253} // namespace olb
254
255#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
has to be implemented for 'every' derived class
Vector< int, 2 > getMin() override
Returns min lattice position of the indicated domain's bounding box.
Base block indicator functor (discrete)
Definition aliases.h:203
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
has to be implemented for 'every' derived class
bool operator()(bool output[], const int input[]) override
has to be implemented for 'every' derived class
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
has to be implemented for 'every' derived class
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.
Definition aliases.h:213
Vector< int, 2 > getMax() override
Returns max lattice position of the indicated domain's bounding box.
bool operator()(bool output[], const int input[]) override
has to be implemented for 'every' derived class
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 .
Definition aliases.h:243
Plain old scalar vector.
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(T a) any_platform
return true if a is close to zero
Definition util.h:402
Top level namespace for all of OpenLB.
Set of functions commonly used in LB computations – header file.