OpenLB 1.7
Loading...
Searching...
No Matches
superMin2D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2018 Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef SUPER_MIN_2D_HH
25#define SUPER_MIN_2D_HH
26
27#include "superMin2D.h"
29
30namespace olb {
31
32
33template <typename T, typename W>
35 FunctorPtr<SuperIndicatorF2D<T>>&& indicatorF)
36 : SuperF2D<T,W>(f->getSuperStructure(), f->getTargetDim()),
37 _f(std::move(f)),
38 _indicatorF(std::move(indicatorF))
39{
40 this->getName() = "Min("+_f->getName()+")";
41
42 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
43 CuboidGeometry2D<T>& cuboid = _f->getSuperStructure().getCuboidGeometry();
44
45 if ( _f->getBlockFSize() == load.size() &&
46 _indicatorF->getBlockFSize() == load.size() ) {
47 for (int iC = 0; iC < load.size(); ++iC) {
48 this->_blockF.emplace_back(
49 new BlockMin2D<T,W>(_f->getBlockF(iC),
50 _indicatorF->getBlockIndicatorF(iC),
51 cuboid.get(load.glob(iC)))
52 );
53 }
54 }
55}
56
57template <typename T, typename W>
59 SuperGeometry<T,2>& superGeometry,
60 const int material)
61 : SuperMin2D(
62 std::forward<decltype(f)>(f),
63 superGeometry.getMaterialIndicator(material))
64{ }
65
66template <typename T, typename W>
67bool SuperMin2D<T,W>::operator() (W output[], const int input[])
68{
70 CuboidGeometry2D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
71 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
72
73 for (int i = 0; i < this->getTargetDim(); ++i) {
74 output[i] = std::numeric_limits<W>::max();
75 }
76
77 if (this->_blockF.empty()) {
78 W outputTmp[_f->getTargetDim()];
79 int inputTmp[_f->getSourceDim()];
80
81 for (int iC = 0; iC < load.size(); ++iC) {
82 const Cuboid2D<T> cuboid = geometry.get(load.glob(iC));
83 inputTmp[0] = load.glob(iC);
84 for (inputTmp[1] = 0; inputTmp[1] < cuboid.getNx(); ++inputTmp[1]) {
85 for (inputTmp[2] = 0; inputTmp[2] < cuboid.getNy(); ++inputTmp[2]) {
86 if (_indicatorF(inputTmp)) {
87 _f(outputTmp,inputTmp);
88 for (int i = 0; i < this->getTargetDim(); ++i) {
89 if (outputTmp[i] < output[i]) {
90 output[i] = outputTmp[i];
91 }
92 }
93 }
94 }
95 }
96 }
97 }
98 else {
99 for (int iC = 0; iC < load.size(); ++iC) {
100 this->getBlockF(iC)(output, input);
101 }
102 }
103
104#ifdef PARALLEL_MODE_MPI
105 for (int i = 0; i < this->getTargetDim(); ++i) {
106 singleton::mpi().reduceAndBcast(output[i], MPI_MIN);
107 }
108#endif
109 return true;
110}
111
112
113}
114
115#endif
BlockMin2D returns the min in each component of f on a indicated subset.
Definition blockMin2D.h:36
A regular single 2D cuboid is the basic component of a 2D cuboid structure which defines the grid.
Definition cuboid2D.h:54
int getNx() const
Read access to cuboid width.
Definition cuboid2D.hh:112
int getNy() const
Read access to cuboid height.
Definition cuboid2D.hh:118
A cuboid structure represents the grid of a considered domain.
Cuboid2D< T > & get(int i)
Read and write access to the cuboids.
Smart pointer for managing the various ways of passing functors around.
Definition functorPtr.h:60
std::string & getName()
read and write access to name
Definition genericF.hh:51
Base class for all LoadBalancer.
int glob(int loc) const
represents all functors that operate on a SuperStructure<T,2> in general
std::vector< std::unique_ptr< BlockF2D< W > > > _blockF
Super functors may consist of several BlockF2D<W> derived functors.
SuperStructure< T, 2 > & getSuperStructure()
Representation of a statistic for a parallel 2D geometry.
SuperMin2D returns the min in each component of f on a indicated subset.
Definition superMin2D.h:37
SuperMin2D(FunctorPtr< SuperF2D< T, W > > &&f, FunctorPtr< SuperIndicatorF2D< T > > &&indicatorF)
Constructor for determining the minimum of f on a indicated subset.
Definition superMin2D.hh:34
bool operator()(W output[], const int input[]) override
Definition superMin2D.hh:67
virtual void communicate()
void reduceAndBcast(T &reductVal, MPI_Op op, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Reduction operation, followed by a broadcast.
MpiManager & mpi()
Top level namespace for all of OpenLB.