/* This file is part of the OpenLB library * * Copyright (C) 2012 Lukas Baron, Mathias J. Krause, Albert Mink * 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_BASE_F_3D_HH #define BLOCK_BASE_F_3D_HH #include "blockBaseF3D.h" namespace olb { template BlockF3D::BlockF3D(BlockStructure3D& blockStructure, int targetDim) : GenericF(targetDim,3), _blockStructure(blockStructure) { } template BlockStructure3D& BlockF3D::getBlockStructure() const { return _blockStructure; } template std::vector BlockF3D::getMinValue() { T min[this->getTargetDim()]; T minTmp[this->getTargetDim()]; this->operator()(min,0,0); for (int iX = 1; iX < _blockStructure.getNx(); ++iX) { for (int iY = 1; iY < _blockStructure.getNy(); ++iY) { for (int iZ = 1; iZ < _blockStructure.getNz(); ++iZ) { this->operator()(minTmp,iX,iY,iZ); for (int iDim = 0; iDim < this->getTargetDim(); ++iDim) { if (min[iDim] > minTmp[iDim] ) { min[iDim] = minTmp[iDim]; } } } } } std::vector minV(min,min+this->getTargetDim()); return minV; } template std::vector BlockF3D::getMaxValue() { T max[this->getTargetDim()]; T maxTmp[this->getTargetDim()]; this->operator()(max,0,0); for (int iX = 1; iX < _blockStructure.getNx(); ++iX) { for (int iY = 1; iY < _blockStructure.getNy(); ++iY) { for (int iZ = 1; iZ < _blockStructure.getNz(); ++iZ) { this->operator()(maxTmp,iX,iY,iZ); for (int iDim = 0; iDim < this->getTargetDim(); ++iDim) { if (max[iDim] > maxTmp[iDim] ) { max[iDim] = maxTmp[iDim]; } } } } } std::vector maxV(max,max+this->getTargetDim()); return maxV; } template BlockDataF3D::BlockDataF3D(BlockData3D& blockData) : BlockF3D(blockData, blockData.getSize()), _blockData(blockData) { } template BlockDataF3D::BlockDataF3D(BlockF3D& f) : BlockF3D(f.getBlockStructure(), f.getTargetDim()), _blockDataStorage(new BlockData3D(f)), _blockData(*_blockDataStorage) { } template BlockDataF3D::BlockDataF3D(int nx, int ny, int nz, int size) // hacky solution to both managing BlockData3D using std::unique_ptr and // passing it down the line to the base class : BlockF3D(*(new BlockData3D(nx, ny, nz, size)), size), _blockDataStorage(static_cast*>(&(this->getBlockStructure()))), _blockData(*_blockDataStorage) { } template BlockData3D& BlockDataF3D::getBlockData() { return _blockData; } template bool BlockDataF3D::operator() (BaseType output[], const int input[]) { for (int iDim = 0; iDim < this->getTargetDim(); ++iDim) { output[iDim] = _blockData.get(input[0], input[1], input[2], iDim); } return true; } template BlockDataViewF3D::BlockDataViewF3D(BlockData3D& blockData, int overlap) : BlockDataF3D(blockData), _overlap(overlap) { } template bool BlockDataViewF3D::operator() (BaseType output[], const int input[]) { for (int iDim = 0; iDim < this->getTargetDim(); ++iDim) { output[iDim] = this->_blockData.get(input[0] + _overlap, input[1] + _overlap, input[2] + _overlap, iDim); } return true; } template BlockIdentity3D::BlockIdentity3D(BlockF3D& f) : BlockF3D(f.getBlockStructure(),f.getTargetDim() ), _f(f) { this->getName() = _f.getName(); std::swap( _f._ptrCalcC, this->_ptrCalcC ); } template bool BlockIdentity3D::operator()(T output[], const int input[]) { return _f(output,input); } template BlockExtractComponentF3D::BlockExtractComponentF3D(BlockF3D& f, int extractDim) : BlockF3D(f.getBlockStructure(),1 ), _f(f), _extractDim(extractDim) { this->getName() = _f.getName(); } template int BlockExtractComponentF3D::getExtractDim() { return _extractDim; } template bool BlockExtractComponentF3D::operator()(T output[], const int input[]) { std::vector outTmp(_f.getTargetDim(), T{}); _f(outTmp.data(), input); output[0] = outTmp[_extractDim]; return true; } template BlockExtractComponentIndicatorF3D::BlockExtractComponentIndicatorF3D( BlockF3D& f, int extractDim, BlockIndicatorF3D& indicatorF) : BlockExtractComponentF3D(f, extractDim), _indicatorF(indicatorF) { this->getName() = f.getName(); } template bool BlockExtractComponentIndicatorF3D::operator()(T output[], const int input[]) { output[0] = T{}; if (_indicatorF(input)) { return BlockExtractComponentF3D::operator()(output, input); } return true; } template BlockExtractIndicatorF3D::BlockExtractIndicatorF3D( BlockF3D& f, BlockIndicatorF3D& indicatorF) : BlockF3D(f.getBlockStructure(), f.getTargetDim()), _f(f), _indicatorF(indicatorF) { this->getName() = f.getName(); } template bool BlockExtractIndicatorF3D::operator()(T output[], const int input[]) { for (int i = 0; i < this->getTargetDim(); ++i) { output[i] = T{}; } if (_indicatorF(input)) { _f(output, input); } return true; } template BlockDotProductF3D::BlockDotProductF3D(BlockF3D& f, T vector[]) : BlockF3D(f.getBlockStructure(),1 ), _f(f), _vector(vector) { this->getName() = _f.getName(); /*if ( (sizeof(_vector)/sizeof(T)) != _f.getTargetDim() ) { std::cout << "WARNING: dimension of vectors do not match!" << std::endl; exit(-1); }*/ } template bool BlockDotProductF3D::operator()(T output[], const int input[]) { T outTmp[3]; output[0] = T(); _f(outTmp, input); for (int iDim=0; iDim<_f.getTargetDim(); iDim++) { output[0] += outTmp[iDim]*_vector[iDim]; } return true; } template BlockLatticeF3D::BlockLatticeF3D (BlockLatticeStructure3D& blockStructure, int targetDim) : BlockF3D(blockStructure, targetDim), _blockLattice(blockStructure) { } /* template BlockLatticeF3D::BlockLatticeF3D(BlockLatticeF3D const& rhs) : BlockF3D(rhs.getBlockStructure(), rhs.getTargetDim() ), _blockLattice(rhs.getBlockLattice()) { } template BlockLatticeF3D& BlockLatticeF3D::operator=(BlockLatticeF3D const& rhs) { BlockLatticeF3D tmp(rhs); return tmp; } */ template BlockLatticeStructure3D& BlockLatticeF3D::getBlockLattice() { return _blockLattice; } template BlockLatticeIdentity3D::BlockLatticeIdentity3D( BlockLatticeF3D& f) : BlockLatticeF3D(f.getBlockLattice(),f.getTargetDim()), _f(f) { this->getName() = _f.getName(); std::swap( _f._ptrCalcC, this->_ptrCalcC ); } template bool BlockLatticeIdentity3D::operator()(T output[], const int input[]) { return _f(output,input); } template BlockLatticePhysF3D::BlockLatticePhysF3D (BlockLatticeStructure3D& blockLattice, const UnitConverter& converter, int targetDim) : BlockLatticeF3D(blockLattice, targetDim), _converter(converter) { } template BlockLatticeThermalPhysF3D::BlockLatticeThermalPhysF3D (BlockLatticeStructure3D& blockLattice, const ThermalUnitConverter& converter, int targetDim) : BlockLatticeF3D(blockLattice, targetDim), _converter(converter) { } } // end namespace olb #endif