From 94d3e79a8617f88dc0219cfdeedfa3147833719d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 24 Jun 2019 14:43:36 +0200 Subject: Initialize at openlb-1-3 --- src/functors/lattice/blockLatticeIntegralF2D.hh | 458 ++++++++++++++++++++++++ 1 file changed, 458 insertions(+) create mode 100644 src/functors/lattice/blockLatticeIntegralF2D.hh (limited to 'src/functors/lattice/blockLatticeIntegralF2D.hh') diff --git a/src/functors/lattice/blockLatticeIntegralF2D.hh b/src/functors/lattice/blockLatticeIntegralF2D.hh new file mode 100644 index 0000000..ef0a8be --- /dev/null +++ b/src/functors/lattice/blockLatticeIntegralF2D.hh @@ -0,0 +1,458 @@ +/* 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_LATTICE_INTEGRAL_F_2D_HH +#define BLOCK_LATTICE_INTEGRAL_F_2D_HH + +#include +#include + +#include "blockLatticeIntegralF2D.h" +#include "blockLatticeLocalF2D.h" +#include "blockCalcF2D.h" // for IdentityF +#include "utilities/vectorHelpers.h" +#include "indicator/blockIndicatorBaseF2D.h" + + +namespace olb { + + +template +BlockMax2D::BlockMax2D(BlockLatticeF2D& f, + BlockGeometry2D& blockGeometry, int material) + : BlockLatticeF2D(f.getBlockLattice(), f.getTargetDim()), + _f(f), _blockGeometry(blockGeometry), _material(material) +{ + this->getName() = "Max("+_f.getName()+")"; +} + +template +bool BlockMax2D::operator() (T output[], const int input[]) +{ + + // f.getBlockLattice2D().communicate(); + // CuboidGeometry2D& cGeometry = f.getBlockLattice2D().get_cGeometry(); + // loadBalancer& load = f.getBlockLattice2D().get_load(); + + for (int i=0; igetTargetDim(); ++i) { + output[i]=T(); + // for (int iC=0; iC tmp[i]) { + // tmp[i]=fabs(f(load.glob(iC),iX,iY,iZ)[i]); + // } + // } + // } + // } + // } + // } + //#ifdef PARALLEL_MODE_MPI + // singleton::mpi().reduceAndBcast(tmp[i], MPI_MAX); + //#endif + } + return true; + + +} + +template +BlockSum2D::BlockSum2D(BlockLatticeF2D& f, + BlockGeometry2D& blockGeometry, int material) + : BlockLatticeF2D(f.getBlockLattice(),f.getTargetDim()), + _f(f), _blockGeometry(blockGeometry), _material(material) +{ + this->getName() = "Sum("+_f.getName()+")"; +} + +template +bool BlockSum2D::operator() (T output[], const int input[]) +{ + BlockIdentity2D ff(_f); // exists only to prevent f from being deleted + + for (int i=0; igetTargetDim(); ++i) { + output[i]=T(); + // int nX = f.getBlockLattice2D().getNx(); + // int nY = f.getBlockLattice2D().getNy(); + // int nZ = f.getBlockLattice2D().getNz(); + // for (int iX=0; iXBlockGeometry.getMaterial(iX, iY, iZ) == material) { + // tmp[i]+=f(iX,iY,iZ)[i]; + // } + // } + // } + // } + } + return true; +} + + +template +BlockIntegral2D::BlockIntegral2D(BlockLatticeF2D& f, + BlockGeometry2D& blockGeometry, int material) + : BlockLatticeF2D(f.getBlockLattice(),f.getTargetDim()), + _f(f), _blockGeometry(blockGeometry), _material(material) +{ + this->getName() = "Integral("+_f.getName()+")"; +} + +template +bool BlockIntegral2D::operator() (T output[], const int input[]) +{ + + // f.getBlockLattice2D().communicate(); + // CuboidGeometry2D& cGeometry = f.getBlockLattice2D().get_cGeometry(); + // loadBalancer& load = f.getBlockLattice2D().get_load(); + + output[0]=T(); + // for (int i=0; in; i++) { + // for (int iC=0; iCBlockGeometry.getDeltaR(),3); + // for (int iX=0; iXBlockGeometry.getMaterial(globX, globY, globZ) == material) { + // tmp[i]+=f(load.glob(iC),iX,iY,iZ)[i]*weight; + // } + // } + // } + // } + // } + //#ifdef PARALLEL_MODE_MPI + // singleton::mpi().reduceAndBcast(tmp[i], MPI_SUM); + //#endif + // } + return true; +} + + +template +BlockL1Norm2D::BlockL1Norm2D(BlockLatticeF2D& f, + BlockGeometry2D& blockGeometry, int material) + : BlockLatticeF2D(f.getBlockLattice(),f.getTargetDim()), + _f(f), _blockGeometry(blockGeometry), _material(material) +{ + this->getName() = "L1("+_f.getName()+")"; +} + +template +bool BlockL1Norm2D::operator() (T output[], const int input[]) +{ + + // f.getBlockLattice2D().communicate(); + // CuboidGeometry2D& cGeometry = f.getBlockLattice2D().get_cGeometry(); + // loadBalancer& load = f.getBlockLattice2D().get_load(); + + // int numVoxels(0); + output[0]=T(); + // for (int i=0; in; i++) { + + // for (int iC=0; iCBlockGeometry.getMaterial(globX, globY, globZ) == material) { + // tmp[i]+=fabs(f(load.glob(iC),iX,iY,iZ)[i]); + // numVoxels++; + // } + // } + // } + // } + // } + //#ifdef PARALLEL_MODE_MPI + // singleton::mpi().reduceAndBcast(tmp[i], MPI_SUM); + //#endif + // } + //#ifdef PARALLEL_MODE_MPI + // singleton::mpi().reduceAndBcast(numVoxels, MPI_SUM); + //#endif + return true; +} + + +template +BlockL222D::BlockL222D(BlockLatticeF2D& f, + BlockGeometry2D& blockGeometry, int material) + : BlockLatticeF2D(f.getBlockLattice(),f.getTargetDim()), + _f(f), _blockGeometry(blockGeometry), _material(material) +{ + this->getName() = "L22("+_f.getName()+")"; +} + +template +bool BlockL222D::operator() (T output[], const int input[]) +{ + + // f.getBlockLattice2D().communicate(); + // CuboidGeometry2D& cGeometry = f.getBlockLattice2D().get_cGeometry(); + // loadBalancer& load = f.getBlockLattice2D().get_load(); + + output[0]=T(); + // for (int i=0; in; i++) { + + // for (int iC=0; iCBlockGeometry.getDeltaR(),3); + // for (int iX=0; iXBlockGeometry.getMaterial(globX, globY, globZ) == material) { + // tmp[i]+=f(load.glob(iC),iX,iY,iZ)[i]*f(load.glob(iC),iX,iY,iZ)[i]*weight; + // } + // } + // } + // } + // } + //#ifdef PARALLEL_MODE_MPI + // singleton::mpi().reduceAndBcast(tmp[i], MPI_SUM); + //#endif + // } + return true; +} + + +template +template +BlockGeometryFaces2D::BlockGeometryFaces2D(BlockGeometryStructure2D& blockGeometry, int material, const UnitConverter& converter) + : GenericF(7,4), _blockGeometry(blockGeometry), _material(material), _latticeL(converter.getConversionFactorLength()) +{ + this->getName() = "blockGeometryFaces"; +} + +template +BlockGeometryFaces2D::BlockGeometryFaces2D(BlockGeometryStructure2D& blockGeometry, int material, T latticeL) + : GenericF(7,4), _blockGeometry(blockGeometry), _material(material), _latticeL(latticeL) +{ + this->getName() = "blockGeometryFaces"; +} + +template +bool BlockGeometryFaces2D::operator() (T output[], const int input[]) +{ + int counter[7] = {0,0,0,0,0,0,0}; + if (_blockGeometry.getStatistics().getNvoxel(_material)!=0) { + const int x0 = _blockGeometry.getStatistics().getMinLatticeR(_material)[0]; + const int y0 = _blockGeometry.getStatistics().getMinLatticeR(_material)[1]; + const int x1 = _blockGeometry.getStatistics().getMaxLatticeR(_material)[0]; + const int y1 = _blockGeometry.getStatistics().getMaxLatticeR(_material)[1]; + + // Iterate over all cells and count the cells of the face + for (int iX = x0; iX <= x1; ++iX) { + for (int iY = y0; iY <= y1; ++iY) { + // Lock at solid nodes only + if (_blockGeometry.getMaterial(iX, iY) == _material) { + if (_blockGeometry.getMaterial(iX-1, iY) == 1) { + counter[0]++; + } + if (_blockGeometry.getMaterial(iX, iY-1) == 1) { + counter[1]++; + } + if (_blockGeometry.getMaterial(iX+1, iY) == 1) { + counter[3]++; + } + if (_blockGeometry.getMaterial(iX, iY+1) == 1) { + counter[4]++; + } + } + } + } + + T dx2 = _latticeL*_latticeL; + T total = T(); + for (int i=0; i<6; ++i) { + output[i]=(T) counter[i] * dx2; + total+=(T) counter[i] * dx2; + } + output[6]=total; + return true; + } else { + for (int i=0; i<7; ++i) { + output[i]=T(); + } + return true; + } + return false; +} + + +template +BlockGeometryFacesIndicator2D::BlockGeometryFacesIndicator2D(BlockGeometryStructure2D& blockGeometry, SmoothIndicatorF2D& indicator, int material, T latticeL) + : GenericF(7,0), _blockGeometry(blockGeometry), _indicator(indicator), _material(material), _latticeL(latticeL) +{ + this->getName() = "facesInd"; +} + +template +bool BlockGeometryFacesIndicator2D::operator() (T output[], const int input[]) +{ + int counter[7] = {0,0,0,0,0,0,0}; + T inside[1]; + T physR[2]; + if (_blockGeometry.getStatistics().getNvoxel(_material)!=0) { + const int x0 = _blockGeometry.getStatistics().getMinLatticeR(_material)[0]; + const int y0 = _blockGeometry.getStatistics().getMinLatticeR(_material)[1]; + const int x1 = _blockGeometry.getStatistics().getMaxLatticeR(_material)[0]; + const int y1 = _blockGeometry.getStatistics().getMaxLatticeR(_material)[1]; + + // Iterate over all cells and count the cells of the face + for (int iX = x0; iX <= x1; ++iX) { + for (int iY = y0; iY <= y1; ++iY) { + // Look at solid nodes only + _blockGeometry.getPhysR(physR, iX, iY); + _indicator(inside, physR); + if ( !util::nearZero(inside[0]) ) { + _blockGeometry.getPhysR(physR, iX-1, iY); + _indicator(inside, physR); + if ( !util::nearZero(inside[0]) ) { + counter[0]++; + } + _blockGeometry.getPhysR(physR, iX, iY-1); + _indicator(inside, physR); + if ( !util::nearZero(inside[0]) ) { + counter[1]++; + } + _blockGeometry.getPhysR(physR, iX+1, iY); + _indicator(inside, physR); + if ( !util::nearZero(inside[0]) ) { + counter[3]++; + } + _blockGeometry.getPhysR(physR, iX, iY+1); + _indicator(inside, physR); + if ( !util::nearZero(inside[0]) ) { + counter[4]++; + } + } + } + } + + T total = T(); + for (int i=0; i<6; ++i) { + output[i]=(T) counter[i] * _latticeL; + total+=(T) counter[i] * _latticeL; + } + output[6]=total; + return true; + } else { + for (int i=0; i<7; ++i) { + output[i]=T(); + } + return true; + } + return false; +} + + +template +BlockLatticePhysDrag2D::BlockLatticePhysDrag2D +(BlockLattice2D& blockLattice, BlockGeometry2D& blockGeometry, + int material, const UnitConverter& converter) + : BlockLatticePhysF2D(blockLattice,converter,2), + _blockGeometry(blockGeometry), _material(material) +{ + this->getName() = "physDrag"; +} + +template +bool BlockLatticePhysDrag2D::operator() (T output[], const int input[]) +{ + BlockGeometryFaces2D faces(_blockGeometry, _material, this->_converter); + BlockIndicatorMaterial2D indicator(_blockGeometry, _material); + BlockLatticePhysBoundaryForce2D fTemp(this->_blockLattice, indicator, this->_converter); + BlockSum2D sumF(fTemp, _blockGeometry, _material); + + T factor = 2. / (this->_converter.getPhysDensity() * this->_converter.getCharPhysVelocity() * this->_converter.getCharPhysVelocity()); + + T outputSumF[2] = { T() }; + sumF(outputSumF,input); + T outputFaces[2] = { T() }; + faces(outputFaces,input); + + output[0] = factor * outputSumF[0] / outputFaces[0]; + output[1] = factor * outputSumF[1] / outputFaces[1]; + + return true; +} + + +template +BlockLatticePhysCorrDrag2D::BlockLatticePhysCorrDrag2D +(BlockLattice2D& blockLattice, BlockGeometry2D& blockGeometry, + int material, const UnitConverter& converter) + : BlockLatticePhysF2D(blockLattice,converter,2), + _blockGeometry(blockGeometry), _material(material) +{ + this->getName() = "physCorrDrag"; +} + +template +bool BlockLatticePhysCorrDrag2D::operator() (T output[], const int input[]) +{ + BlockGeometryFaces2D faces(_blockGeometry, _material, this->_converter); + BlockLatticePhysCorrBoundaryForce2D tTemp(this->_blockLattice, _blockGeometry, + _material, this->_converter); + BlockSum2D sumF(tTemp, _blockGeometry, _material); + + T factor = 2. / (this->_converter.getPhysDensity() * this->_converter.getCharPhysVelocity() * this->_converter.getCharPhysVelocity()); + + T outputSumF[2] = { T() }; + sumF(outputSumF,input); + T outputFaces[2] = { T() }; + faces(outputFaces,input); + + output[0] = factor * outputSumF[0] / outputFaces[0]; + output[1] = factor * outputSumF[1] / outputFaces[1]; + + return true; +} + + +} // end namespace olb + +#endif -- cgit v1.2.3