OpenLB 1.7
Loading...
Searching...
No Matches
superMax3D.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_MAX_3D_HH
25#define SUPER_MAX_3D_HH
26
27#include "superMax3D.h"
29
30namespace olb {
31
32
33template <typename T, typename W>
35 FunctorPtr<SuperIndicatorF3D<T>>&& indicatorF)
36 : SuperF3D<T,W>(f->getSuperStructure(), f->getTargetDim()),
37 _f(std::move(f)),
38 _indicatorF(std::move(indicatorF))
39{
40 this->getName() = "Max("+_f->getName()+")";
41
42 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
43 CuboidGeometry3D<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 BlockMax3D<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,3>& superGeometry,
60 const int material)
61 : SuperMax3D(
62 std::forward<decltype(f)>(f),
63 superGeometry.getMaterialIndicator(material))
64{ }
65
66template <typename T, typename W>
67bool SuperMax3D<T,W>::operator() (W output[], const int input[])
68{
70 CuboidGeometry3D<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>::min();
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 Cuboid3D<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 for (inputTmp[3] = 0; inputTmp[3] < cuboid.getNz(); ++inputTmp[3]) {
87 if (_indicatorF(inputTmp)) {
88 _f(outputTmp,inputTmp);
89 for (int i = 0; i < this->getTargetDim(); ++i) {
90 if (outputTmp[i] > output[i]) {
91 output[i] = outputTmp[i];
92 }
93 }
94 }
95 }
96 }
97 }
98 }
99 }
100 else {
101 for (int iC = 0; iC < load.size(); ++iC) {
102 this->getBlockF(iC)(output, input);
103 }
104 }
105
106#ifdef PARALLEL_MODE_MPI
107 for (int i = 0; i < this->getTargetDim(); ++i) {
108 singleton::mpi().reduceAndBcast(output[i], MPI_MAX);
109 }
110#endif
111 return true;
112}
113
114
115}
116
117#endif
BlockMax3D returns the max in each component of f on a indicated subset.
Definition blockMax3D.h:36
A regular single 3D cuboid is the basic component of a 3D cuboid structure which defines the grid.
Definition cuboid3D.h:58
int getNz() const
Read access to cuboid depth.
Definition cuboid3D.hh:159
int getNy() const
Read access to cuboid height.
Definition cuboid3D.hh:153
int getNx() const
Read access to cuboid width.
Definition cuboid3D.hh:147
A cuboid geometry represents a voxel mesh.
Cuboid3D< T > & get(int iC)
Read and write access to a single cuboid.
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,3> in general
SuperStructure< T, 3 > & getSuperStructure()
std::vector< std::unique_ptr< BlockF3D< W > > > _blockF
Super functors may consist of several BlockF3D<W> derived functors.
Representation of a statistic for a parallel 2D geometry.
Base indicator functor (discrete)
SuperMax3D returns the max in each component of f on a indicated subset.
Definition superMax3D.h:37
SuperMax3D(FunctorPtr< SuperF3D< T, W > > &&f, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF)
Constructor for determining the maximum of f on a indicated subset.
Definition superMax3D.hh:34
bool operator()(W output[], const int input[]) override
Definition superMax3D.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.