/* This file is part of the OpenLB library * * Copyright (C) 2017 Adrian Kummerlaender * E-mail contact: info@openlb.net * The most recent release of OpenLB can be downloaded at * * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef BLOCK_INDICATOR_F_2D_HH #define BLOCK_INDICATOR_F_2D_HH #include #include "blockIndicatorF2D.h" #include "core/util.h" namespace olb { template BlockIndicatorFfromIndicatorF2D::BlockIndicatorFfromIndicatorF2D( IndicatorF2D& indicatorF, BlockGeometryStructure2D& blockGeometry) : BlockIndicatorF2D(blockGeometry), _indicatorF(indicatorF) { } template bool BlockIndicatorFfromIndicatorF2D::operator() (bool output[], const int input[]) { T physR[2]; this->_blockGeometryStructure.getPhysR(physR,input); return _indicatorF(output,physR); } template Vector BlockIndicatorFfromIndicatorF2D::getMin() { const Vector min = _indicatorF.getMin(); return Vector { static_cast(floor(min[0])), static_cast(floor(min[1])) }; } template Vector BlockIndicatorFfromIndicatorF2D::getMax() { const Vector max = _indicatorF.getMax(); return Vector { static_cast(ceil(max[0])), static_cast(ceil(max[1])) }; } template BlockIndicatorFfromSmoothIndicatorF2D::BlockIndicatorFfromSmoothIndicatorF2D( SmoothIndicatorF2D& indicatorF, BlockGeometryStructure2D& blockGeometry) : BlockIndicatorF2D(blockGeometry), _indicatorF(indicatorF) { } template bool BlockIndicatorFfromSmoothIndicatorF2D::operator() (bool output[], const int input[]) { T physR[2]; T inside[1]; this->_blockGeometryStructure.getPhysR(physR,input); _indicatorF(inside, physR); return !util::nearZero(inside[0]); } template Vector BlockIndicatorFfromSmoothIndicatorF2D::getMin() { return Vector{0,0}; } template Vector BlockIndicatorFfromSmoothIndicatorF2D::getMax() { return this->_blockGeometryStructure.getExtend() - Vector{1,1}; } template BlockIndicatorMaterial2D::BlockIndicatorMaterial2D( BlockGeometryStructure2D& blockGeometry, std::vector materials) : BlockIndicatorF2D(blockGeometry), _materials(materials) { } template BlockIndicatorMaterial2D::BlockIndicatorMaterial2D( BlockGeometryStructure2D& blockGeometry, std::list materials) : BlockIndicatorMaterial2D(blockGeometry, std::vector(materials.begin(), materials.end())) { } template BlockIndicatorMaterial2D::BlockIndicatorMaterial2D( BlockGeometryStructure2D& blockGeometry, int material) : BlockIndicatorMaterial2D(blockGeometry, std::vector(1,material)) { } template bool BlockIndicatorMaterial2D::operator() (bool output[], const int input[]) { // read material number explicitly using the const version // of BlockGeometry2D::get to avoid resetting geometry // statistics: const BlockGeometryStructure2D& blockGeometry = this->_blockGeometryStructure; const int current = blockGeometry.get(input[0], input[1]); output[0] = std::any_of(_materials.cbegin(), _materials.cend(), [current](int material) { return current == material; }); return true; } template bool BlockIndicatorMaterial2D::isEmpty() { auto& statistics = this->getBlockGeometryStructure().getStatistics(); return std::none_of(_materials.cbegin(), _materials.cend(), [&statistics](int material) -> bool { return statistics.getNvoxel(material) > 0; }); } template Vector BlockIndicatorMaterial2D::getMin() { auto& blockGeometry = this->getBlockGeometryStructure(); auto& statistics = blockGeometry.getStatistics(); Vector globalMin{ blockGeometry.getNx()-1, blockGeometry.getNy()-1 }; for ( int material : _materials ) { if ( statistics.getNvoxel(material) > 0 ) { const Vector localMin = statistics.getMinLatticeR(material); for ( int d = 0; d < 2; ++d ) { globalMin[d] = localMin[d] < globalMin[d] ? localMin[d] : globalMin[d]; } } } return globalMin; } template Vector BlockIndicatorMaterial2D::getMax() { auto& statistics = this->getBlockGeometryStructure().getStatistics(); Vector globalMax{ 0, 0 }; for ( int material : _materials ) { if ( statistics.getNvoxel(material) > 0 ) { const Vector localMax = statistics.getMaxLatticeR(material); for ( int d = 0; d < 2; ++d ) { globalMax[d] = localMax[d] > globalMax[d] ? localMax[d] : globalMax[d]; } } } return globalMax; } template BlockIndicatorIdentity2D::BlockIndicatorIdentity2D(BlockIndicatorF2D& indicatorF) : BlockIndicatorF2D(indicatorF.getBlockGeometryStructure()), _indicatorF(indicatorF) { } template bool BlockIndicatorIdentity2D::operator() (bool output[], const int input[]) { return _indicatorF(output, input); } template Vector BlockIndicatorIdentity2D::getMin() { return _indicatorF.getMin(); } template Vector BlockIndicatorIdentity2D::getMax() { return _indicatorF.getMax(); } } // namespace olb #endif