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/integral/MakeHeader | 37 +++ src/functors/lattice/integral/blockIntegralF3D.cpp | 35 +++ src/functors/lattice/integral/blockIntegralF3D.h | 61 ++++ src/functors/lattice/integral/blockIntegralF3D.hh | 117 ++++++++ src/functors/lattice/integral/blockLpNorm2D.cpp | 33 +++ src/functors/lattice/integral/blockLpNorm2D.h | 53 ++++ src/functors/lattice/integral/blockLpNorm2D.hh | 77 +++++ src/functors/lattice/integral/blockLpNorm3D.cpp | 33 +++ src/functors/lattice/integral/blockLpNorm3D.h | 50 ++++ src/functors/lattice/integral/blockLpNorm3D.hh | 80 +++++ src/functors/lattice/integral/integral2D.h | 32 ++ src/functors/lattice/integral/integral2D.hh | 32 ++ src/functors/lattice/integral/integral3D.h | 34 +++ src/functors/lattice/integral/integral3D.hh | 34 +++ .../lattice/integral/latticeIntegralCommon.h | 94 ++++++ src/functors/lattice/integral/module.mk | 27 ++ src/functors/lattice/integral/superIntegralF3D.cpp | 35 +++ src/functors/lattice/integral/superIntegralF3D.h | 95 ++++++ src/functors/lattice/integral/superIntegralF3D.hh | 200 +++++++++++++ src/functors/lattice/integral/superLpNorm2D.cpp | 33 +++ src/functors/lattice/integral/superLpNorm2D.h | 106 +++++++ src/functors/lattice/integral/superLpNorm2D.hh | 133 +++++++++ src/functors/lattice/integral/superLpNorm3D.cpp | 33 +++ src/functors/lattice/integral/superLpNorm3D.h | 106 +++++++ src/functors/lattice/integral/superLpNorm3D.hh | 137 +++++++++ .../lattice/integral/superPlaneIntegralF2D.cpp | 31 ++ .../lattice/integral/superPlaneIntegralF2D.h | 203 +++++++++++++ .../lattice/integral/superPlaneIntegralF2D.hh | 222 ++++++++++++++ .../lattice/integral/superPlaneIntegralF3D.cpp | 31 ++ .../lattice/integral/superPlaneIntegralF3D.h | 279 ++++++++++++++++++ .../lattice/integral/superPlaneIntegralF3D.hh | 322 +++++++++++++++++++++ .../lattice/integral/superPlaneIntegralFluxF2D.cpp | 90 ++++++ .../lattice/integral/superPlaneIntegralFluxF2D.h | 127 ++++++++ .../lattice/integral/superPlaneIntegralFluxF2D.hh | 191 ++++++++++++ .../lattice/integral/superPlaneIntegralFluxF3D.cpp | 144 +++++++++ .../lattice/integral/superPlaneIntegralFluxF3D.h | 173 +++++++++++ .../lattice/integral/superPlaneIntegralFluxF3D.hh | 317 ++++++++++++++++++++ .../integral/superPlaneIntegralFluxMass2D.cpp | 31 ++ .../integral/superPlaneIntegralFluxMass2D.h | 200 +++++++++++++ .../integral/superPlaneIntegralFluxMass2D.hh | 203 +++++++++++++ .../integral/superPlaneIntegralFluxMass3D.cpp | 31 ++ .../integral/superPlaneIntegralFluxMass3D.h | 240 +++++++++++++++ .../integral/superPlaneIntegralFluxMass3D.hh | 249 ++++++++++++++++ 43 files changed, 4791 insertions(+) create mode 100644 src/functors/lattice/integral/MakeHeader create mode 100644 src/functors/lattice/integral/blockIntegralF3D.cpp create mode 100644 src/functors/lattice/integral/blockIntegralF3D.h create mode 100644 src/functors/lattice/integral/blockIntegralF3D.hh create mode 100644 src/functors/lattice/integral/blockLpNorm2D.cpp create mode 100644 src/functors/lattice/integral/blockLpNorm2D.h create mode 100644 src/functors/lattice/integral/blockLpNorm2D.hh create mode 100644 src/functors/lattice/integral/blockLpNorm3D.cpp create mode 100644 src/functors/lattice/integral/blockLpNorm3D.h create mode 100644 src/functors/lattice/integral/blockLpNorm3D.hh create mode 100644 src/functors/lattice/integral/integral2D.h create mode 100644 src/functors/lattice/integral/integral2D.hh create mode 100644 src/functors/lattice/integral/integral3D.h create mode 100644 src/functors/lattice/integral/integral3D.hh create mode 100644 src/functors/lattice/integral/latticeIntegralCommon.h create mode 100644 src/functors/lattice/integral/module.mk create mode 100644 src/functors/lattice/integral/superIntegralF3D.cpp create mode 100644 src/functors/lattice/integral/superIntegralF3D.h create mode 100644 src/functors/lattice/integral/superIntegralF3D.hh create mode 100644 src/functors/lattice/integral/superLpNorm2D.cpp create mode 100644 src/functors/lattice/integral/superLpNorm2D.h create mode 100644 src/functors/lattice/integral/superLpNorm2D.hh create mode 100644 src/functors/lattice/integral/superLpNorm3D.cpp create mode 100644 src/functors/lattice/integral/superLpNorm3D.h create mode 100644 src/functors/lattice/integral/superLpNorm3D.hh create mode 100644 src/functors/lattice/integral/superPlaneIntegralF2D.cpp create mode 100644 src/functors/lattice/integral/superPlaneIntegralF2D.h create mode 100644 src/functors/lattice/integral/superPlaneIntegralF2D.hh create mode 100644 src/functors/lattice/integral/superPlaneIntegralF3D.cpp create mode 100644 src/functors/lattice/integral/superPlaneIntegralF3D.h create mode 100644 src/functors/lattice/integral/superPlaneIntegralF3D.hh create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxF2D.cpp create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxF2D.h create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxF2D.hh create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxF3D.cpp create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxF3D.h create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxF3D.hh create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxMass2D.cpp create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxMass2D.h create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxMass2D.hh create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxMass3D.cpp create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxMass3D.h create mode 100644 src/functors/lattice/integral/superPlaneIntegralFluxMass3D.hh (limited to 'src/functors/lattice/integral') diff --git a/src/functors/lattice/integral/MakeHeader b/src/functors/lattice/integral/MakeHeader new file mode 100644 index 0000000..11f679c --- /dev/null +++ b/src/functors/lattice/integral/MakeHeader @@ -0,0 +1,37 @@ +# 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. + + +generic := + +precompiled := superIntegralF3D \ + blockIntegralF3D \ + superPlaneIntegralF3D \ + superPlaneIntegralFluxF3D \ + superPlaneIntegralFluxMass3D \ + superLpNorm3D \ + blockLpNorm3D \ + superLpNorm2D \ + blockLpNorm2D \ + superPlaneIntegralF2D \ + superPlaneIntegralFluxF2D \ + superPlaneIntegralFluxMass2D diff --git a/src/functors/lattice/integral/blockIntegralF3D.cpp b/src/functors/lattice/integral/blockIntegralF3D.cpp new file mode 100644 index 0000000..c82a1cb --- /dev/null +++ b/src/functors/lattice/integral/blockIntegralF3D.cpp @@ -0,0 +1,35 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2018 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. +*/ + +#include "blockIntegralF3D.h" +#include "blockIntegralF3D.hh" + +namespace olb { + +template class BlockSum3D; +template class BlockSum3D; + +template class BlockIntegral3D; +template class BlockIntegral3D; + +} diff --git a/src/functors/lattice/integral/blockIntegralF3D.h b/src/functors/lattice/integral/blockIntegralF3D.h new file mode 100644 index 0000000..d986106 --- /dev/null +++ b/src/functors/lattice/integral/blockIntegralF3D.h @@ -0,0 +1,61 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2018 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_INTEGRAL_F_3D_H +#define BLOCK_INTEGRAL_F_3D_H + +#include "geometry/cuboid3D.h" +#include "functors/lattice/blockBaseF3D.h" + +namespace olb { + + +/// BlockSum3D sums all components of f over a indicated subset +template +class BlockSum3D : public BlockF3D { +private: + BlockF3D& _f; + BlockIndicatorF3D& _indicatorF; +public: + BlockSum3D(BlockF3D& f, + BlockIndicatorF3D& indicatorF); + bool operator() (W output[], const int input[]) override; +}; + + +/// BlockIntegral3D integrates f on a indicated subset +template +class BlockIntegral3D final : public BlockF3D { +private: + BlockF3D& _f; + BlockIndicatorF3D& _indicatorF; +public: + BlockIntegral3D(BlockF3D& f, + BlockIndicatorF3D& indicatorF); + bool operator() (W output[], const int input[]) override; +}; + + +} + +#endif diff --git a/src/functors/lattice/integral/blockIntegralF3D.hh b/src/functors/lattice/integral/blockIntegralF3D.hh new file mode 100644 index 0000000..c5d11e4 --- /dev/null +++ b/src/functors/lattice/integral/blockIntegralF3D.hh @@ -0,0 +1,117 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2018 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_INTEGRAL_F_3D_HH +#define BLOCK_INTEGRAL_F_3D_HH + +#include "blockIntegralF3D.h" +#include "core/olbDebug.h" +#include "functors/lattice/indicator/blockIndicatorBaseF3D.h" + +namespace olb { + + +template +BlockSum3D::BlockSum3D(BlockF3D& f, + BlockIndicatorF3D& indicatorF) + : BlockF3D(f.getBlockStructure(), f.getTargetDim()+1), + _f(f), + _indicatorF(indicatorF) +{ + this->getName() = "BlockSum("+_f.getName()+")"; +} + +template +bool BlockSum3D::operator() (W output[], const int input[]) +{ + OLB_ASSERT(_f.getSourceDim() == _indicatorF.getSourceDim(), + "functor source dimension equals indicator source dimension"); + + W outputTmp[_f.getTargetDim()]; + int inputTmp[_f.getSourceDim()]; + std::size_t voxels(0); + + const auto& blockStructure = this->getBlockStructure(); + + for (inputTmp[0] = 0; inputTmp[0] < blockStructure.getNx(); ++inputTmp[0]) { + for (inputTmp[1] = 0; inputTmp[1] < blockStructure.getNy(); ++inputTmp[1]) { + for (inputTmp[2] = 0; inputTmp[2] < blockStructure.getNz(); ++inputTmp[2]) { + if (_indicatorF(inputTmp)) { + _f(outputTmp,inputTmp); + for (int i = 0; i < _f.getTargetDim(); ++i) { + output[i] += outputTmp[i]; + } + voxels += 1; + } + } + } + } + output[_f.getTargetDim()] += voxels; + + return true; +} + + +template +BlockIntegral3D::BlockIntegral3D(BlockF3D& f, + BlockIndicatorF3D& indicatorF) + : BlockF3D(f.getBlockStructure(), f.getTargetDim()), + _f(f), + _indicatorF(indicatorF) +{ + this->getName() = "BlockIntegral("+_f.getName()+")"; +} + +template +bool BlockIntegral3D::operator() (W output[], const int input[]) +{ + OLB_ASSERT(_f.getSourceDim() == _indicatorF.getSourceDim(), + "functor source dimension equals indicator source dimension"); + + const W weight = pow(_indicatorF.getBlockGeometryStructure().getDeltaR(), 3); + + W outputTmp[_f.getTargetDim()]; + int inputTmp[_f.getSourceDim()]; + + const auto& blockStructure = this->getBlockStructure(); + + for (inputTmp[0] = 0; inputTmp[0] < blockStructure.getNx(); ++inputTmp[0]) { + for (inputTmp[1] = 0; inputTmp[1] < blockStructure.getNy(); ++inputTmp[1]) { + for (inputTmp[2] = 0; inputTmp[2] < blockStructure.getNz(); ++inputTmp[2]) { + if (_indicatorF(inputTmp)) { + _f(outputTmp,inputTmp); + for (int i = 0; i < this->getTargetDim(); ++i) { + output[i] += outputTmp[i] * weight; + } + } + } + } + } + + return true; +} + + +} + +#endif diff --git a/src/functors/lattice/integral/blockLpNorm2D.cpp b/src/functors/lattice/integral/blockLpNorm2D.cpp new file mode 100644 index 0000000..781245b --- /dev/null +++ b/src/functors/lattice/integral/blockLpNorm2D.cpp @@ -0,0 +1,33 @@ +/* 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. +*/ + +#include "blockLpNorm2D.h" +#include "blockLpNorm2D.hh" + +namespace olb { + +template class BlockLpNorm2D; +template class BlockLpNorm2D; +template class BlockLpNorm2D; + +} diff --git a/src/functors/lattice/integral/blockLpNorm2D.h b/src/functors/lattice/integral/blockLpNorm2D.h new file mode 100644 index 0000000..2f2ade6 --- /dev/null +++ b/src/functors/lattice/integral/blockLpNorm2D.h @@ -0,0 +1,53 @@ +/* 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_LP_NORM_2D_H +#define BLOCK_LP_NORM_2D_H + +namespace olb { + +template class BlockF2D; +template class Cuboid2D; +template class BlockIndicatorF2D; + +/// Block level functor that returns the Lp norm over omega of the euklid norm of the input block functor. +/** + * Instances are contained in SuperLpNorm2D::_blockF. + **/ +template +class BlockLpNorm2D final : public BlockF2D { +protected: + BlockF2D& _f; + BlockIndicatorF2D& _indicatorF; +public: + /** + * \param f data functor + * \param indicatorF indicator functor describing the subset to be integrated + **/ + BlockLpNorm2D(BlockF2D& f, BlockIndicatorF2D& indicatorF); + bool operator() (W output[], const int input[]) override; +}; + +} + +#endif diff --git a/src/functors/lattice/integral/blockLpNorm2D.hh b/src/functors/lattice/integral/blockLpNorm2D.hh new file mode 100644 index 0000000..9739fde --- /dev/null +++ b/src/functors/lattice/integral/blockLpNorm2D.hh @@ -0,0 +1,77 @@ +/* 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_LP_NORM_2D_HH +#define BLOCK_LP_NORM_2D_HH + +#include "blockLpNorm2D.h" +#include "functors/lattice/indicator/blockIndicatorBaseF2D.h" +#include "geometry/cuboid2D.h" +#include "latticeIntegralCommon.h" + +namespace olb { + +template +BlockLpNorm2D::BlockLpNorm2D(BlockF2D& f, + BlockIndicatorF2D& indicatorF) + : BlockF2D(f.getBlockStructure(), f.getTargetDim()), + _f(f), + _indicatorF(indicatorF) +{ + OLB_ASSERT(_f.getSourceDim() == _indicatorF.getSourceDim(), + "functor source dimension equals indicator source dimension"); + + this->getName() = "BlockL" + std::to_string(P) + "Norm(" + _f.getName() + ")"; +} + +template +bool BlockLpNorm2D::operator()(W output[], const int input[]) +{ + const auto& blockGeometry = _indicatorF.getBlockGeometryStructure(); + const int nX = blockGeometry.getNx(); + const int nY = blockGeometry.getNy(); + const T weight = pow(blockGeometry.getDeltaR(), 2); + + output[0] = W(0); + W outputTmp[_f.getTargetDim()]; + int inputTmp[_f.getSourceDim()]; + + for (inputTmp[0] = 0; inputTmp[0] < nX; ++inputTmp[0]) { + for (inputTmp[1] = 0; inputTmp[1] < nY; ++inputTmp[1]) { + if (_indicatorF(inputTmp)) { + _f(outputTmp, inputTmp); + for (int iDim = 0; iDim < _f.getTargetDim(); ++iDim) { + output[0] = LpNormImpl()(output[0], outputTmp[iDim], weight); + } + } + } + } + + output[0] = LpNormImpl().enclose(output[0]); + + return true; +} + +} + +#endif diff --git a/src/functors/lattice/integral/blockLpNorm3D.cpp b/src/functors/lattice/integral/blockLpNorm3D.cpp new file mode 100644 index 0000000..24145dc --- /dev/null +++ b/src/functors/lattice/integral/blockLpNorm3D.cpp @@ -0,0 +1,33 @@ +/* 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. +*/ + +#include "blockLpNorm3D.h" +#include "blockLpNorm3D.hh" + +namespace olb { + +template class BlockLpNorm3D; +template class BlockLpNorm3D; +template class BlockLpNorm3D; + +} diff --git a/src/functors/lattice/integral/blockLpNorm3D.h b/src/functors/lattice/integral/blockLpNorm3D.h new file mode 100644 index 0000000..302cfdd --- /dev/null +++ b/src/functors/lattice/integral/blockLpNorm3D.h @@ -0,0 +1,50 @@ +/* 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_LP_NORM_3D_H +#define BLOCK_LP_NORM_3D_H + +namespace olb { + +template class BlockF3D; +template class Cuboid3D; +template class BlockIndicatorF3D; + +/// Block level functor that returns the Lp norm over omega of the euklid norm of the input block functor. +template +class BlockLpNorm3D final : public BlockF3D { +protected: + BlockF3D& _f; + BlockIndicatorF3D& _indicatorF; +public: + /** + * \param f data functor + * \param indicatorF indicator functor describing the subset to be integrated + **/ + BlockLpNorm3D(BlockF3D& f, BlockIndicatorF3D& indicatorF); + bool operator() (W output[], const int input[]) override; +}; + +} + +#endif diff --git a/src/functors/lattice/integral/blockLpNorm3D.hh b/src/functors/lattice/integral/blockLpNorm3D.hh new file mode 100644 index 0000000..301d3ee --- /dev/null +++ b/src/functors/lattice/integral/blockLpNorm3D.hh @@ -0,0 +1,80 @@ +/* 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_LP_NORM_3D_HH +#define BLOCK_LP_NORM_3D_HH + +#include "blockLpNorm3D.h" +#include "functors/lattice/indicator/blockIndicatorBaseF3D.h" +#include "geometry/cuboid3D.h" +#include "latticeIntegralCommon.h" + +namespace olb { + +template +BlockLpNorm3D::BlockLpNorm3D(BlockF3D& f, + BlockIndicatorF3D& indicatorF) + : BlockF3D(f.getBlockStructure(), f.getTargetDim()), + _f(f), + _indicatorF(indicatorF) +{ + OLB_ASSERT(_f.getSourceDim() == _indicatorF.getSourceDim(), + "functor source dimension equals indicator source dimension"); + + this->getName() = "BlockL" + std::to_string(P) + "Norm(" + _f.getName() + ")"; +} + +template +bool BlockLpNorm3D::operator()(W output[], const int input[]) +{ + const auto& blockGeometry = _indicatorF.getBlockGeometryStructure(); + const int nX = blockGeometry.getNx(); + const int nY = blockGeometry.getNy(); + const int nZ = blockGeometry.getNz(); + const T weight = pow(blockGeometry.getDeltaR(), 3); + + output[0] = W(0); + W outputTmp[_f.getTargetDim()]; + int inputTmp[_f.getSourceDim()]; + + for (inputTmp[0] = 0; inputTmp[0] < nX; ++inputTmp[0]) { + for (inputTmp[1] = 0; inputTmp[1] < nY; ++inputTmp[1]) { + for (inputTmp[2] = 0; inputTmp[2] < nZ; ++inputTmp[2]) { + if (_indicatorF(inputTmp)) { + _f(outputTmp, inputTmp); + for (int iDim = 0; iDim < _f.getTargetDim(); ++iDim) { + output[0] = LpNormImpl()(output[0], outputTmp[iDim], weight); + } + } + } + } + } + + output[0] = LpNormImpl().enclose(output[0]); + + return true; +} + +} + +#endif diff --git a/src/functors/lattice/integral/integral2D.h b/src/functors/lattice/integral/integral2D.h new file mode 100644 index 0000000..fc21c9b --- /dev/null +++ b/src/functors/lattice/integral/integral2D.h @@ -0,0 +1,32 @@ +/* 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. +*/ + +/** \file + * Groups all include files for the directory functors/lattice/integral. + */ + +#include "superLpNorm2D.h" +#include "blockLpNorm2D.h" +#include "superPlaneIntegralF2D.h" +#include "superPlaneIntegralFluxF2D.h" +#include "superPlaneIntegralFluxMass2D.h" diff --git a/src/functors/lattice/integral/integral2D.hh b/src/functors/lattice/integral/integral2D.hh new file mode 100644 index 0000000..ab70bc6 --- /dev/null +++ b/src/functors/lattice/integral/integral2D.hh @@ -0,0 +1,32 @@ +/* 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. +*/ + +/** \file + * Groups all include files for the directory functors/lattice/integral. + */ + +#include "superLpNorm2D.hh" +#include "blockLpNorm2D.hh" +#include "superPlaneIntegralF2D.hh" +#include "superPlaneIntegralFluxF2D.hh" +#include "superPlaneIntegralFluxMass2D.hh" diff --git a/src/functors/lattice/integral/integral3D.h b/src/functors/lattice/integral/integral3D.h new file mode 100644 index 0000000..c4426f4 --- /dev/null +++ b/src/functors/lattice/integral/integral3D.h @@ -0,0 +1,34 @@ +/* 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. +*/ + +/** \file + * Groups all include files for the directory functors/lattice/integral. + */ + +#include "superIntegralF3D.h" +#include "blockIntegralF3D.h" +#include "superPlaneIntegralF3D.h" +#include "superPlaneIntegralFluxF3D.h" +#include "superPlaneIntegralFluxMass3D.h" +#include "superLpNorm3D.h" +#include "blockLpNorm3D.h" diff --git a/src/functors/lattice/integral/integral3D.hh b/src/functors/lattice/integral/integral3D.hh new file mode 100644 index 0000000..d3ca816 --- /dev/null +++ b/src/functors/lattice/integral/integral3D.hh @@ -0,0 +1,34 @@ +/* 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. +*/ + +/** \file + * Groups all include files for the directory functors/lattice/integral. + */ + +#include "superIntegralF3D.hh" +#include "blockIntegralF3D.hh" +#include "superPlaneIntegralF3D.hh" +#include "superPlaneIntegralFluxF3D.hh" +#include "superPlaneIntegralFluxMass3D.hh" +#include "superLpNorm3D.hh" +#include "blockLpNorm3D.hh" diff --git a/src/functors/lattice/integral/latticeIntegralCommon.h b/src/functors/lattice/integral/latticeIntegralCommon.h new file mode 100644 index 0000000..dd019c8 --- /dev/null +++ b/src/functors/lattice/integral/latticeIntegralCommon.h @@ -0,0 +1,94 @@ +/* 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 LATTICE_INTEGRAL_COMMON_H +#define LATTICE_INTEGRAL_COMMON_H + +namespace olb { + + +/// Lp norm functor implementation details specific to the P parameter +/** + * Used in BlockLpNorm2D, BlockLpNorm3D, SuperLpNorm2D and SuperLpNorm3D. + **/ +template +struct LpNormImpl { + inline W operator()(W output, W tmp, T weight); + inline W enclose(W output); +}; + +template +inline W LpNormImpl::operator()(W output, W tmp, T weight) +{ + return output + pow(fabs(tmp), P)*weight; +} + +template +inline W LpNormImpl::enclose(W output) +{ + return pow(output, 1. / P); +} + +/// Linf norm functor implementation details +template +struct LpNormImpl { + inline W operator()(W output, W tmp, T weight) + { + return std::max(output, fabs(tmp)); + } + inline W enclose(W output) + { + return output; + } +}; + +/// L1 norm functor implementation details +template +struct LpNormImpl { + inline W operator()(W output, W tmp, T weight) + { + return output + fabs(tmp)*weight; + } + inline W enclose(W output) + { + return output; + } +}; + +/// L2 norm functor implementation details +template +struct LpNormImpl { + inline W operator()(W output, W tmp, T weight) + { + return output + tmp*tmp*weight; + } + inline W enclose(W output) + { + return sqrt(output); + } +}; + + +} // end namespace olb + +#endif diff --git a/src/functors/lattice/integral/module.mk b/src/functors/lattice/integral/module.mk new file mode 100644 index 0000000..6e42e3e --- /dev/null +++ b/src/functors/lattice/integral/module.mk @@ -0,0 +1,27 @@ +# This file is part of the OpenLB library +# +# Copyright (C) 2017 Markus Mohrhard +# 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. + +current_dir := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))) + +include $(addsuffix /MakeHeader, $(current_dir)) + +LIB_OBJECTS += $(foreach file, $($(BUILDTYPE)), $(OBJDIR)/$(current_dir)$(file).o) diff --git a/src/functors/lattice/integral/superIntegralF3D.cpp b/src/functors/lattice/integral/superIntegralF3D.cpp new file mode 100644 index 0000000..8cd6b2d --- /dev/null +++ b/src/functors/lattice/integral/superIntegralF3D.cpp @@ -0,0 +1,35 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2018 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. +*/ + +#include "superIntegralF3D.h" +#include "superIntegralF3D.hh" + +namespace olb { + +template class SuperSum3D; +template class SuperSum3D; + +template class SuperIntegral3D; +template class SuperIntegral3D; + +} diff --git a/src/functors/lattice/integral/superIntegralF3D.h b/src/functors/lattice/integral/superIntegralF3D.h new file mode 100644 index 0000000..a60a2e8 --- /dev/null +++ b/src/functors/lattice/integral/superIntegralF3D.h @@ -0,0 +1,95 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2018 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_INTEGRAL_F_3D_H +#define SUPER_INTEGRAL_F_3D_H + +#include "functors/lattice/superBaseF3D.h" +#include "functors/lattice/indicator/superIndicatorBaseF3D.h" +#include "functors/analytical/indicator/indicatorBaseF3D.h" +#include "functors/lattice/indicator/superIndicatorF3D.h" +#include "geometry/superGeometry3D.h" +#include "utilities/functorPtr.h" + +namespace olb { + + +/// SuperSum3D sums all components of f over a indicated subset +template +class SuperSum3D final : public SuperF3D { +private: + FunctorPtr> _f; + FunctorPtr> _indicatorF; +public: + /// Constructor for summing f on a indicated subset + /** + * \param f functor to be summed + * \param indicatorF indicator describing the subset on which to evaluate f + **/ + SuperSum3D(FunctorPtr>&& f, + FunctorPtr>&& indicatorF); + /// Constructor for summing f on a given material + /** + * \param f functor to be summed + * \param superGeometry super geometry for constructing material indicator + * \param material number of the relevant material + **/ + SuperSum3D(FunctorPtr>&& f, + SuperGeometry3D& superGeometry, + const int material); + + bool operator() (W output[], const int input[]) override; +}; + + +/// SuperIntegral3D integrates f on a indicated subset +template +class SuperIntegral3D final : public SuperF3D { +private: + FunctorPtr> _f; + FunctorPtr> _indicatorF; +public: + /// Constructor for integrating f on a indicated subset + /** + * \param f functor to be integrated + * \param indicatorF indicator describing the subset on which to evaluate f + **/ + SuperIntegral3D(FunctorPtr>&& f, + FunctorPtr>&& indicatorF); + /// Constructor for integrating f on a given material + /** + * \param f functor to be integrated + * \param superGeometry super geometry for constructing material indicator + * \param material number of the relevant material + **/ + SuperIntegral3D(FunctorPtr>&& f, + SuperGeometry3D& superGeometry, + const int material); + + bool operator() (W output[], const int input[]) override; +}; + + +} + +#endif diff --git a/src/functors/lattice/integral/superIntegralF3D.hh b/src/functors/lattice/integral/superIntegralF3D.hh new file mode 100644 index 0000000..20407a2 --- /dev/null +++ b/src/functors/lattice/integral/superIntegralF3D.hh @@ -0,0 +1,200 @@ +/* This file is part of the OpenLB library + * + * Copyright (C) 2018 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_INTEGRAL_F_3D_HH +#define SUPER_INTEGRAL_F_3D_HH + +#include +#include + +#include "superIntegralF3D.h" +#include "blockIntegralF3D.h" +#include "functors/analytical/indicator/indicatorBaseF3D.hh" +#include "utilities/functorPtr.hh" + +namespace olb { + + +template +SuperSum3D::SuperSum3D(FunctorPtr>&& f, + FunctorPtr>&& indicatorF) + : SuperF3D(f->getSuperStructure(), f->getTargetDim()+1), + _f(std::move(f)), + _indicatorF(std::move(indicatorF)) +{ + this->getName() = "Sum("+_f->getName()+")"; + + LoadBalancer& load = _f->getSuperStructure().getLoadBalancer(); + + if ( _f->getBlockFSize() == load.size() && + _indicatorF->getBlockFSize() == load.size() ) { + for (int iC = 0; iC < load.size(); ++iC) { + this->_blockF.emplace_back( + new BlockSum3D(_f->getBlockF(iC), + _indicatorF->getBlockIndicatorF(iC)) + ); + } + } +} + +template +SuperSum3D::SuperSum3D(FunctorPtr>&& f, + SuperGeometry3D& superGeometry, + const int material) + : SuperSum3D( + std::forward(f), + superGeometry.getMaterialIndicator(material)) +{ } + +template +bool SuperSum3D::operator() (W output[], const int input[]) +{ + _f->getSuperStructure().communicate(); + CuboidGeometry3D& geometry = _f->getSuperStructure().getCuboidGeometry(); + LoadBalancer& load = _f->getSuperStructure().getLoadBalancer(); + + for (int i = 0; i < this->getTargetDim(); ++i) { + output[i] = W(0); + } + + if (this->_blockF.empty()) { + W outputTmp[_f->getTargetDim()]; + int inputTmp[_f->getSourceDim()]; + std::size_t voxels(0); + + for (int iC = 0; iC < load.size(); ++iC) { + const Cuboid3D cuboid = geometry.get(load.glob(iC)); + inputTmp[0] = load.glob(iC); + for (inputTmp[1] = 0; inputTmp[1] < cuboid.getNx(); ++inputTmp[1]) { + for (inputTmp[2] = 0; inputTmp[2] < cuboid.getNy(); ++inputTmp[2]) { + for (inputTmp[3] = 0; inputTmp[3] < cuboid.getNz(); ++inputTmp[3]) { + if (_indicatorF(inputTmp)) { + _f(outputTmp,inputTmp); + for (int i = 0; i < _f->getTargetDim(); ++i) { + output[i] += outputTmp[i]; + } + voxels += 1; + } + } + } + } + } + output[_f->getTargetDim()] = voxels; + } + else { + for (int iC = 0; iC < load.size(); ++iC) { + this->getBlockF(iC)(output, input); + } + } + +#ifdef PARALLEL_MODE_MPI + for (int i = 0; i < this->getTargetDim(); ++i) { + singleton::mpi().reduceAndBcast(output[i], MPI_SUM); + } +#endif + return true; +} + + +template +SuperIntegral3D::SuperIntegral3D(FunctorPtr>&& f, + FunctorPtr>&& indicatorF) + : SuperF3D(f->getSuperStructure(), f->getTargetDim()), + _f(std::move(f)), + _indicatorF(std::move(indicatorF)) +{ + this->getName() = "Integral("+_f->getName()+")"; + + LoadBalancer& load = _f->getSuperStructure().getLoadBalancer(); + + if ( _f->getBlockFSize() == load.size() && + _indicatorF->getBlockFSize() == load.size() ) { + for (int iC = 0; iC < load.size(); ++iC) { + this->_blockF.emplace_back( + new BlockIntegral3D(_f->getBlockF(iC), + _indicatorF->getBlockIndicatorF(iC)) + ); + } + } +} + +template +SuperIntegral3D::SuperIntegral3D(FunctorPtr>&& f, + SuperGeometry3D& superGeometry, + const int material) + : SuperIntegral3D( + std::forward(f), + superGeometry.getMaterialIndicator(material)) +{ } + +template +bool SuperIntegral3D::operator() (W output[], const int input[]) +{ + _f->getSuperStructure().communicate(); + CuboidGeometry3D& geometry = _f->getSuperStructure().getCuboidGeometry(); + LoadBalancer& load = _f->getSuperStructure().getLoadBalancer(); + + for (int i = 0; i < this->getTargetDim(); ++i) { + output[i] = W(0); + } + + if (this->_blockF.empty()) { + W outputTmp[_f->getTargetDim()]; + int inputTmp[_f->getSourceDim()]; + + for (int iC = 0; iC < load.size(); ++iC) { + const Cuboid3D cuboid = geometry.get(load.glob(iC)); + const W weight = pow(cuboid.getDeltaR(), 3); + inputTmp[0] = load.glob(iC); + for (inputTmp[1] = 0; inputTmp[1] < cuboid.getNx(); ++inputTmp[1]) { + for (inputTmp[2] = 0; inputTmp[2] < cuboid.getNy(); ++inputTmp[2]) { + for (inputTmp[3] = 0; inputTmp[3] < cuboid.getNz(); ++inputTmp[3]) { + if (_indicatorF(inputTmp)) { + _f(outputTmp,inputTmp); + for (int i = 0; i < this->getTargetDim(); ++i) { + output[i] += outputTmp[i] * weight; + } + } + } + } + } + } + } + else { + for (int iC = 0; iC < load.size(); ++iC) { + this->getBlockF(iC)(output, input); + } + } + +#ifdef PARALLEL_MODE_MPI + for (int i = 0; i < this->getTargetDim(); ++i) { + singleton::mpi().reduceAndBcast(output[i], MPI_SUM); + } +#endif + return true; +} + + +} + +#endif diff --git a/src/functors/lattice/integral/superLpNorm2D.cpp b/src/functors/lattice/integral/superLpNorm2D.cpp new file mode 100644 index 0000000..9701607 --- /dev/null +++ b/src/functors/lattice/integral/superLpNorm2D.cpp @@ -0,0 +1,33 @@ +/* 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. +*/ + +#include "superLpNorm2D.h" +#include "superLpNorm2D.hh" + +namespace olb { + +template class SuperLpNorm2D; +template class SuperLpNorm2D; +template class SuperLpNorm2D; + +} diff --git a/src/functors/lattice/integral/superLpNorm2D.h b/src/functors/lattice/integral/superLpNorm2D.h new file mode 100644 index 0000000..a033fd3 --- /dev/null +++ b/src/functors/lattice/integral/superLpNorm2D.h @@ -0,0 +1,106 @@ +/* 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 SUPER_LP_NORM_2D_H +#define SUPER_LP_NORM_2D_H + +#include +#include + +#include "utilities/functorPtr.h" + +namespace olb { + +template class SuperF2D; +template class SuperIndicatorF2D; +template class SuperGeometry2D; + +/// Functor that returns the Lp norm over omega of the the euklid norm of the input functor +/** + * Maintains block level BlockLpNorm2D functors as required. + * + * P == 0: inf norm + * P >= 1: p norm + */ +template +class SuperLpNorm2D : public SuperF2D { +private: + FunctorPtr> _f; + FunctorPtr> _indicatorF; +public: + /** + * \param f (non-)owning pointer or reference to SuperF2D + * \param indicatorF (non-)owning pointer or reference to SuperIndicatorF2D. + * Describes the subset to be integrated. + **/ + SuperLpNorm2D(FunctorPtr>&& f, + FunctorPtr>&& indicatorF); + + /** + * Legacy constructor accepting super geometry reference. + * + * \param f (non-)owning pointer or reference to SuperF2D + * \param indicatorF (non-)owning pointer or reference to SuperIndicatorF2D. + * Describes the subset to be integrated. + **/ + SuperLpNorm2D(FunctorPtr>&& f, + SuperGeometry2D&, + FunctorPtr>&& indicatorF); + + /** + * \param f (non-)owning pointer or reference to SuperF2D + * \param geometry super geometry required to construct SuperIndicatorMaterial2D using materials + * \param materials vector of material numbers to be included in the Lp norm + **/ + SuperLpNorm2D(FunctorPtr>&& f, + SuperGeometry2D& geometry, + std::vector materials); + + /** + * \param f (non-)owning pointer or reference to SuperF2D + * \param geometry super geometry required to construct SuperIndicatorMaterial2D using material + * \param material single material number to be included in the Lp norm + **/ + SuperLpNorm2D(FunctorPtr>&& f, + SuperGeometry2D& geometry, + int material); + + bool operator() (W output[], const int input[]) override; +}; + + +/// Functor that returns the L1 norm over omega of the the euklid norm of the input functor +template +using SuperL1Norm2D = SuperLpNorm2D; + +/// Functor that returns the L2 norm over omega of the the euklid norm of the input functor +template +using SuperL2Norm2D = SuperLpNorm2D; + +/// Functor that returns the Linf norm over omega of the the euklid norm of the input functor +template +using SuperLinfNorm2D = SuperLpNorm2D; + +} + +#endif diff --git a/src/functors/lattice/integral/superLpNorm2D.hh b/src/functors/lattice/integral/superLpNorm2D.hh new file mode 100644 index 0000000..c6e02ac --- /dev/null +++ b/src/functors/lattice/integral/superLpNorm2D.hh @@ -0,0 +1,133 @@ +/* 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 SUPER_LP_NORM_2D_HH +#define SUPER_LP_NORM_2D_HH + +#include "superLpNorm2D.h" +#include "blockLpNorm2D.h" +#include "functors/lattice/superBaseF2D.h" +#include "functors/lattice/indicator/superIndicatorF2D.h" +#include "geometry/superGeometry2D.h" +#include "latticeIntegralCommon.h" + +namespace olb { + +template +SuperLpNorm2D::SuperLpNorm2D(FunctorPtr>&& f, + FunctorPtr>&& indicatorF) + : SuperF2D(f->getSuperStructure(),1), + _f(std::move(f)), + _indicatorF(std::move(indicatorF)) +{ + OLB_ASSERT(_f->getSourceDim() == _indicatorF->getSourceDim(), + "functor source dimension equals indicator source dimension"); + + this->getName() = "L" + std::to_string(P) + "Norm(" + _f->getName() + ")"; + + LoadBalancer& load = _f->getSuperStructure().getLoadBalancer(); + + if ( _f->getBlockFSize() == load.size() && + _indicatorF->getBlockFSize() == load.size() ) { + for (int iC = 0; iC < load.size(); ++iC) { + this->_blockF.emplace_back( + new BlockLpNorm2D(_f->getBlockF(iC), + _indicatorF->getBlockIndicatorF(iC)) + ); + } + } +} + +template +SuperLpNorm2D::SuperLpNorm2D(FunctorPtr>&& f, + SuperGeometry2D& geometry, + FunctorPtr>&& indicatorF) + : SuperLpNorm2D(std::forward(f), + std::forward(indicatorF)) +{ } + +template +SuperLpNorm2D::SuperLpNorm2D(FunctorPtr>&& f, + SuperGeometry2D& geometry, + std::vector materials) + : SuperLpNorm2D(std::forward(f), + geometry.getMaterialIndicator(std::move(materials))) +{ } + +template +SuperLpNorm2D::SuperLpNorm2D(FunctorPtr>&& f, + SuperGeometry2D& geometry, + int material) + : SuperLpNorm2D(std::forward(f), + geometry.getMaterialIndicator(material)) +{ } + +template +bool SuperLpNorm2D::operator() (W output[], const int input[]) +{ + _f->getSuperStructure().communicate(); + CuboidGeometry2D& geometry = _f->getSuperStructure().getCuboidGeometry(); + LoadBalancer& load = _f->getSuperStructure().getLoadBalancer(); + + output[0] = W(0); + W outputTmp[_f->getTargetDim()]; + int inputTmp[3]; + + for (int iC = 0; iC < load.size(); ++iC) { + Cuboid2D& cuboid = geometry.get(load.glob(iC)); + + const int nX = cuboid.getNx(); + const int nY = cuboid.getNy(); + const T weight = pow(cuboid.getDeltaR(), 2); + + inputTmp[0] = load.glob(iC); + + for (inputTmp[1] = 0; inputTmp[1] < nX; ++inputTmp[1]) { + for (inputTmp[2] = 0; inputTmp[2] < nY; ++inputTmp[2]) { + if (_indicatorF(inputTmp)) { + _f(outputTmp, inputTmp); + for (int iDim = 0; iDim < _f->getTargetDim(); ++iDim) { + output[0] = LpNormImpl()(output[0], outputTmp[iDim], weight); + } + } + } + } + } + +#ifdef PARALLEL_MODE_MPI + if (P == 0) { + singleton::mpi().reduceAndBcast(output[0], MPI_MAX); + } + else { + singleton::mpi().reduceAndBcast(output[0], MPI_SUM); + } +#endif + + output[0] = LpNormImpl().enclose(output[0]); + + return true; +} + +} + +#endif diff --git a/src/functors/lattice/integral/superLpNorm3D.cpp b/src/functors/lattice/integral/superLpNorm3D.cpp new file mode 100644 index 0000000..37044ee --- /dev/null +++ b/src/functors/lattice/integral/superLpNorm3D.cpp @@ -0,0 +1,33 @@ +/* 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. +*/ + +#include "superLpNorm3D.h" +#include "superLpNorm3D.hh" + +namespace olb { + +template class SuperLpNorm3D; +template class SuperLpNorm3D; +template class SuperLpNorm3D; + +} diff --git a/src/functors/lattice/integral/superLpNorm3D.h b/src/functors/lattice/integral/superLpNorm3D.h new file mode 100644 index 0000000..c526ec1 --- /dev/null +++ b/src/functors/lattice/integral/superLpNorm3D.h @@ -0,0 +1,106 @@ +/* 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 SUPER_LP_NORM_3D_H +#define SUPER_LP_NORM_3D_H + +#include +#include + +#include "utilities/functorPtr.h" + +namespace olb { + +template class SuperF3D; +template class SuperIndicatorF3D; +template class SuperGeometry3D; + +/// Functor that returns the Lp norm over omega of the the euklid norm of the input functor +/** + * Maintains block level BlockLpNorm3D functors as required. + * + * P == 0: inf norm + * P >= 1: p norm + */ +template +class SuperLpNorm3D : public SuperF3D { +private: + FunctorPtr> _f; + FunctorPtr> _indicatorF; +public: + /** + * \param f (non-)owning pointer or reference to SuperF3D + * \param indicatorF (non-)owning pointer or reference to SuperIndicatorF3D. + * Describes the subset to be integrated. + **/ + SuperLpNorm3D(FunctorPtr>&& f, + FunctorPtr>&& indicatorF); + + /** + * Legacy constructor accepting super geometry reference. + * + * \param f (non-)owning pointer or reference to SuperF3D + * \param indicatorF (non-)owning pointer or reference to SuperIndicatorF3D. + * Describes the subset to be integrated. + **/ + SuperLpNorm3D(FunctorPtr>&&