/* This file is part of the OpenLB library
*
* Copyright (C) 2014 Albert Mink, Mathias J. Krause, 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 SUPER_LATTICE_INTEGRAL_F_2D_HH
#define SUPER_LATTICE_INTEGRAL_F_2D_HH
#include
#include
#include "superLatticeIntegralF2D.h"
#include "blockLatticeIntegralF2D.h"
#include "indicator/superIndicatorF2D.h"
#include "utilities/vectorHelpers.h"
#include "core/vector.h"
using namespace olb::util;
namespace olb {
template
SuperMax2D::SuperMax2D(SuperF2D& f, SuperGeometry2D& superGeometry, const int material)
: SuperF2D(f.getSuperStructure(),f.getTargetDim()),
_f(f), _superGeometry(superGeometry), _material(material)
{
this->getName() = "Max("+_f.getName()+")";
}
template
bool SuperMax2D::operator() (T output[], const int input[])
{
_f.getSuperStructure().communicate();
CuboidGeometry2D& cGeometry = _f.getSuperStructure().getCuboidGeometry();
LoadBalancer& load = _f.getSuperStructure().getLoadBalancer();
for (int i = 0; i < this->getTargetDim(); ++i) {
output[i]=T();
for (int iC = 0; iC < load.size(); ++iC) {
int nX = cGeometry.get(load.glob(iC)).getNx();
int nY = cGeometry.get(load.glob(iC)).getNy();
for (int iX = 0; iX < nX; iX++) {
for (int iY = 0; iY < nY; iY++) {
if (_superGeometry.get(load.glob(iC), iX, iY) == _material) {
T outputTmp[_f.getTargetDim()];
_f(outputTmp,load.glob(iC),iX,iY);
if (fabs(outputTmp[i]) > output[i]) {
output[i] = fabs(outputTmp[i]);
}
}
}
}
}
#ifdef PARALLEL_MODE_MPI
singleton::mpi().reduceAndBcast(output[i], MPI_MAX);
#endif
}
return true;
}
template
SuperMin2D::SuperMin2D(SuperF2D& f, SuperGeometry2D& superGeometry, const int material)
: SuperF2D(f.getSuperStructure(),f.getTargetDim()),
_f(f), _superGeometry(superGeometry), _material(material)
{
this->getName() = "Min("+_f.getName()+")";
}
template
bool SuperMin2D::operator() (T output[], const int input[])
{
_f.getSuperStructure().communicate();
CuboidGeometry2D& cGeometry = _f.getSuperStructure().getCuboidGeometry();
LoadBalancer& load = _f.getSuperStructure().getLoadBalancer();
for (int i = 0; i < this->getTargetDim(); ++i) {
output[i]=T();
for (int iC = 0; iC < load.size(); ++iC) {
int nX = cGeometry.get(load.glob(iC)).getNx();
int nY = cGeometry.get(load.glob(iC)).getNy();
for (int iX = 0; iX < nX; iX++) {
for (int iY = 0; iY < nY; iY++) {
if (_superGeometry.get(load.glob(iC), iX, iY) == _material) {
T outputTmp[_f.getTargetDim()];
_f(outputTmp,load.glob(iC),iX,iY);
if (fabs(outputTmp[i]) < output[i]) {
output[i] = fabs(outputTmp[i]);
}
}
}
}
}
#ifdef PARALLEL_MODE_MPI
singleton::mpi().reduceAndBcast(output[i], MPI_MAX);
#endif
}
return true;
}
template
SuperSum2D::SuperSum2D(SuperF2D& f, SuperGeometry2D& superGeometry, const int material)
: SuperF2D(f.getSuperStructure(),f.getTargetDim()+1),
_f(f), _superGeometry(superGeometry), _material(material)
{
this->getName() = "Sum("+_f.getName()+")";
}
template
bool SuperSum2D::operator() (T output[], const int input[])
{
_f.getSuperStructure().communicate();
CuboidGeometry2D& cGeometry = _f.getSuperStructure().getCuboidGeometry();
LoadBalancer& load = _f.getSuperStructure().getLoadBalancer();
int numVoxels(0);
for (int i = 0; i < this->getTargetDim(); ++i) {
output[i]=T();
}
for (int iC=0; iC_superGeometry.get(load.glob(iC), iX, iY) == _material) {
T outputTmp[_f.getTargetDim()];
_f(outputTmp,load.glob(iC),iX,iY);
for (int i = 0; i < this->getTargetDim()-1 /*f.getTargetDim()*/; ++i) {
output[i] += outputTmp[i];
}
numVoxels++;
}
}
}
}
#ifdef PARALLEL_MODE_MPI
for (int i = 0; i < this->getTargetDim()-1; ++i) {
singleton::mpi().reduceAndBcast(output[i], MPI_SUM);
}
singleton::mpi().reduceAndBcast(numVoxels, MPI_SUM);
#endif
output[this->getTargetDim()-1] = numVoxels;
return true;
}
template
SuperIntegral2D::SuperIntegral2D(SuperF2D& f, SuperGeometry2D& superGeometry, const int material)
: SuperF2D(f.getSuperStructure(),f.getTargetDim()), _f(f), _superGeometry(superGeometry), _material(material)
{
this->getName() = "Integral("+_f.getName()+")";
}
template
bool SuperIntegral2D::operator() (T output[], const int input[])
{
// f.getSuperStructure().communicate();
// CuboidGeometry2D& cGeometry = f.getSuperStructure().getCuboidGeometry();
// LoadBalancer& load = f.getSuperStructure().getLoadBalancer();
// std::vector tmp(this->_n, T() );
// for (int i=0; i_n; ++i) {
// for (int iC=0; iCsuperGeometry.getDeltaR(),3);
// for (int iX=0; iXsuperGeometry.getMaterial(globX, globY) == material) {
//// tmp[i]+=f(load.glob(iC),iX,iY)[i]*weight;
//// }
//// if (this->superGeometry.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 tmp;
return false;
}
template
template
SuperGeometryFaces2D::SuperGeometryFaces2D(SuperGeometry2D& superGeometry,
const int material, const UnitConverter& converter)
: GenericF(7,3), _superGeometry(superGeometry), _material(material), _latticeL(converter.getConversionFactorLength())
{
this->getName() = "superGeometryFaces";
}
template
SuperGeometryFaces2D::SuperGeometryFaces2D(SuperGeometry2D& superGeometry,
const int material, T latticeL)
: GenericF(7,3), _superGeometry(superGeometry), _material(material), _latticeL(latticeL)
{
this->getName() = "superGeometryFaces";
}
template
bool SuperGeometryFaces2D::operator() (T output[], const int input[])
{
for (int iDim = 0; iDim < 7; ++iDim) {
output[iDim]=T();
}
_superGeometry.communicate();
for (int iC = 0; iC < _superGeometry.getLoadBalancer().size(); ++iC) {
BlockGeometryFaces2D f(_superGeometry.getBlockGeometry(iC), _material, _latticeL);
T outputTmp[f.getTargetDim()];
f(outputTmp,input);
for (int iDim = 0; iDim < 7; ++iDim) {
output[iDim] += outputTmp[iDim];
}
}
#ifdef PARALLEL_MODE_MPI
for (int iDim = 0; iDim < 7; ++iDim) {
singleton::mpi().reduceAndBcast( output[iDim], MPI_SUM);
}
#endif
return true;
}
template
SuperGeometryFacesIndicator2D::SuperGeometryFacesIndicator2D(SuperGeometry2D& superGeometry,
SmoothIndicatorF2D& indicator, const int material, T deltaX)
: GenericF(7,0), _superGeometry(superGeometry), _indicator(indicator), _material(material), _latticeL(deltaX)
{
this->getName() = "superGeometryFacesInd";
}
template
bool SuperGeometryFacesIndicator2D::operator() (T output[], const int input[])
{
_superGeometry.communicate();
for (int iDim = 0; iDim < 7; ++iDim) {
output[iDim]=T();
}
for (int iC = 0; iC < _superGeometry.getLoadBalancer().size(); ++iC) {
BlockGeometryFacesIndicator2D f(_superGeometry.getBlockGeometry(iC), _indicator, _material, _latticeL);
T outputTmp[f.getTargetDim()];
f(outputTmp,input);
for (int iDim = 0; iDim < 7; ++iDim) {
output[iDim] += outputTmp[iDim];
}
}
#ifdef PARALLEL_MODE_MPI
for (int iDim = 0; iDim < 7; ++iDim) {
singleton::mpi().reduceAndBcast( output[iDim], MPI_SUM);
}
#endif
return true;
}
template
SuperLatticePhysDrag2D::SuperLatticePhysDrag2D
(SuperLattice2D& sLattice, SuperGeometry2D& superGeometry,
const int material, const UnitConverter& converter)
: SuperLatticePhysF2D(sLattice,converter,2),
_superGeometry(superGeometry), _material(material)
{
this->getName() = "physDrag";
}
template
bool SuperLatticePhysDrag2D::operator() (T output[], const int input[])
{
SuperGeometryFaces2D faces(_superGeometry, _material, this->_converter.getConversionFactorLength());
SuperLatticePhysBoundaryForce2D f(this->_sLattice, _superGeometry, _material, this->_converter);
SuperSum2D sumF(f, _superGeometry, _material);
T factor = 2. / (this->_converter.getPhysDensity() * this->_converter.getCharPhysVelocity() * this->_converter.getCharPhysVelocity());
T facesTmp[faces.getTargetDim()], sumFTmp[sumF.getTargetDim()];
sumF(sumFTmp, input);
faces(facesTmp, input);
output[0] = factor * sumFTmp[0] / facesTmp[0];
output[1] = factor * sumFTmp[1] / facesTmp[1];
return true;
}
template
SuperLatticePhysCorrDrag2D::SuperLatticePhysCorrDrag2D
(SuperLattice2D& sLattice, SuperGeometry2D& superGeometry,
const int material, const UnitConverter& converter)
: SuperLatticePhysF2D(sLattice,converter,2),
_superGeometry(superGeometry), _material(material)
{
this->getName() = "physCorrDrag";
}
template
bool SuperLatticePhysCorrDrag2D::operator() (T output[], const int input[])
{
// SuperGeometryFaces2D faces(superGeometry, material, this->converter);
// SuperLatticePhysCorrBoundaryForce2D f(this->sLattice, superGeometry, material, this->converter);
// SuperSum2D sumF(f, superGeometry, material);
// T factor = 2. / (this->converter.getCharRho() * this->converter.getCharU() * this->converter.getCharU());
// std::vector drag(2,T());
// drag[0] = factor * sumF(input)[0] / faces(input)[0];
// drag[1] = factor * sumF(input)[1] / faces(input)[1];
//// drag[2] = factor * sumF(input)[2] / faces(input)[2];
// return drag;
return false;
}
} //end namespace olb
#endif