OpenLB 1.7
Loading...
Searching...
No Matches
superAverage2D.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_AVERAGE_2D_HH
25#define SUPER_AVERAGE_2D_HH
26
27#include "superAverage2D.h"
29
30namespace olb {
31
32
33template <typename T, typename W>
35 FunctorPtr<SuperIndicatorF2D<T>>&& indicatorF)
36 : SuperF2D<T,W>(f->getSuperStructure(), f->getTargetDim()+1),
37 _f(std::move(f)),
38 _indicatorF(std::move(indicatorF))
39{
40 this->getName() = "Average("+_f->getName()+")";
41
42 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
43
44 if ( _f->getBlockFSize() == load.size() &&
45 _indicatorF->getBlockFSize() == load.size() ) {
46 for (int iC = 0; iC < load.size(); ++iC) {
47 this->_blockF.emplace_back(
48 new BlockAverage2D<T,W>(_f->getBlockF(iC),
49 _indicatorF->getBlockIndicatorF(iC))
50 );
51 }
52 }
53}
54
55template <typename T, typename W>
57 SuperGeometry<T,2>& superGeometry,
58 const int material)
60 std::forward<decltype(f)>(f),
61 superGeometry.getMaterialIndicator(material))
62{ }
63
64template <typename T, typename W>
65bool SuperAverage2D<T,W>::operator() (W output[], const int input[])
66{
68 CuboidGeometry2D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
69 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
70
71 for (int i = 0; i < _f->getTargetDim(); ++i) {
72 output[i] = W(0);
73 }
74
75 W outputTmp[_f->getTargetDim()];
76 int inputTmp[_f->getSourceDim()];
77 std::size_t voxels(0);
78
79 for (int iC = 0; iC < load.size(); ++iC) {
80 const Cuboid2D<T>& cuboid = geometry.get(load.glob(iC));
81 inputTmp[0] = load.glob(iC);
82 for (inputTmp[1] = 0; inputTmp[1] < cuboid.getNx(); ++inputTmp[1]) {
83 for (inputTmp[2] = 0; inputTmp[2] < cuboid.getNy(); ++inputTmp[2]) {
84 if (_indicatorF(inputTmp)) {
85 _f(outputTmp,inputTmp);
86 for (int i = 0; i < _f->getTargetDim(); ++i) {
87 output[i] += outputTmp[i];
88 }
89 voxels += 1;
90 }
91
92 }
93 }
94 }
95
96#ifdef PARALLEL_MODE_MPI
97 for (int i = 0; i < _f->getTargetDim(); ++i) {
98 singleton::mpi().reduceAndBcast(output[i], MPI_SUM);
99 }
100 singleton::mpi().reduceAndBcast(voxels, MPI_SUM);
101#endif
102
103 output[_f->getTargetDim()] = voxels;
104 for (int i = 0; i < _f->getTargetDim(); ++i) {
105 output[i] /= output[_f->getTargetDim()];
106 }
107
108 return true;
109}
110
111
112}
113
114#endif
BlockAverage2D returns the average in each component of f on a indicated subset.
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
SuperAverage2D returns the average in each component of f on a indicated subset.
bool operator()(W output[], const int input[]) override
Global average operator.
SuperAverage2D(FunctorPtr< SuperF2D< T, W > > &&f, FunctorPtr< SuperIndicatorF2D< T > > &&indicatorF)
Constructor for determining the average of f on a indicated subset.
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.
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.