OpenLB 1.7
Loading...
Searching...
No Matches
superLocalAverage3D.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_LOCAL_AVERAGE_3D_HH
25#define SUPER_LOCAL_AVERAGE_3D_HH
26
27#include "superLocalAverage3D.h"
28#include "blockLocalAverage3D.h"
30
31namespace olb {
32
33
34template<typename T, typename W>
37 FunctorPtr<SuperIndicatorF3D<T>>&& indicatorF,
38 T radius)
39 : SuperF3D<T,W>(f->getSuperStructure(), f->getTargetDim()),
40 _f(std::move(f)),
41 _indicatorF(std::move(indicatorF)),
42 _radius(radius)
43{
44 this->getName() = "LocalAverage(" + _f->getName() + ")";
45
46 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
47
48 if ( _f->getBlockFSize() == load.size() &&
49 _indicatorF->getBlockFSize() == load.size() ) {
50 for (int iC = 0; iC < load.size(); ++iC) {
51 this->_blockF.emplace_back(
52 new BlockLocalAverage3D<T,W>(_f->getBlockF(iC),
53 _indicatorF->getBlockIndicatorF(iC),
54 _radius)
55 );
56 }
57 }
58}
59
60template<typename T, typename W>
61bool SuperLocalAverage3D<T,W>::operator() (W output[], const int input[])
62{
63 const auto& geometry = this->getSuperStructure().getCuboidGeometry();
64 const auto& load = this->getSuperStructure().getLoadBalancer();
65
66 for (int i = 0; i < this->getTargetDim(); ++i) {
67 output[i] = 0.;
68 }
69
70 if (!_indicatorF(input)) {
71 return true;
72 }
73
74 T centerOfSphere[3];
75 geometry.getPhysR(centerOfSphere, input);
76 IndicatorSphere3D<T> analyticalSphere(centerOfSphere, _radius);
78 analyticalSphere,
79 _indicatorF->getSuperGeometry());
80
81 std::size_t voxels(0);
82 int inputTmp[4];
83
84 for (int iC = 0; iC < load.size(); ++iC) {
85 inputTmp[0] = load.glob(iC);
86 const auto& cuboid = geometry.get(inputTmp[0]);
87
88 for (inputTmp[1] = 0; inputTmp[1] < cuboid.getNx(); ++inputTmp[1]) {
89 for (inputTmp[2] = 0; inputTmp[2] < cuboid.getNy(); ++inputTmp[2]) {
90 for (inputTmp[3] = 0; inputTmp[3] < cuboid.getNz(); ++inputTmp[3]) {
91 if (latticeSphere(inputTmp) && _indicatorF(inputTmp)) {
92 T outputTmp[_f->getTargetDim()];
93 _f(outputTmp, inputTmp);
94 for (int i = 0; i < this->getTargetDim(); ++i) {
95 output[i] += outputTmp[i];
96 }
97 voxels += 1;
98 }
99 }
100 }
101 }
102 }
103
104#ifdef PARALLEL_MODE_MPI
105 singleton::mpi().reduceAndBcast(voxels, MPI_SUM);
106#endif
107
108 if (voxels > 0) {
109 for (int i = 0; i < this->getTargetDim(); ++i) {
110#ifdef PARALLEL_MODE_MPI
111 singleton::mpi().reduceAndBcast(output[i], MPI_SUM);
112#endif
113 output[i] /= voxels;
114 }
115 }
116
117 return true;
118}
119
120
121}
122
123#endif
Averages given functor inside the local sphere.
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
indicator function for a 3D-sphere
Base class for all LoadBalancer.
represents all functors that operate on a SuperStructure<T,3> in general
std::vector< std::unique_ptr< BlockF3D< W > > > _blockF
Super functors may consist of several BlockF3D<W> derived functors.
Base indicator functor (discrete)
SuperIndicatorF3D from IndicatorF3D.
SuperLocalAverage3D(FunctorPtr< SuperF3D< T > > &&f, FunctorPtr< SuperIndicatorF3D< T > > &&indicatorF, T radius)
Primary constructor.
bool operator()(W output[], const int input[]) override
Returns average of functor _f evaluated on all cells both inside a sphere of _radius around input and...
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.