OpenLB 1.7
Loading...
Searching...
No Matches
blockLocalAverage3D.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 BLOCK_LOCAL_AVERAGE_3D_HH
25#define BLOCK_LOCAL_AVERAGE_3D_HH
26
27#include "blockLocalAverage3D.h"
29
30namespace olb {
31
32
33template<typename T, typename W>
35 BlockF3D<W>& f,
36 BlockIndicatorF3D<T>& indicatorF,
37 T radius)
38 : BlockF3D<W>(f.getBlockStructure(), f.getTargetDim()),
39 _f(f),
40 _indicatorF(indicatorF),
41 _radius(radius)
42{
43 this->getName() = "BlockLocalAverage(" + _f.getName() + ")";
44}
45
46template<typename T, typename W>
47bool BlockLocalAverage3D<T,W>::operator() (W output[], const int input[])
48{
49 const auto& geometry = _indicatorF.getBlockGeometry();
50
51 for (int i = 0; i < this->getTargetDim(); ++i) {
52 output[i] = 0.;
53 }
54
55 if (!_indicatorF(input)) {
56 return true;
57 }
58
59 T centerOfSphere[3];
60 geometry.getPhysR(centerOfSphere, input);
61 IndicatorSphere3D<T> analyticalSphere(centerOfSphere, _radius);
63 analyticalSphere,
64 _indicatorF.getBlockGeometry());
65
66 std::size_t voxels(0);
67 int inputTmp[3];
68
69 for (inputTmp[0] = 0; inputTmp[0] < geometry.getNx(); ++inputTmp[0]) {
70 for (inputTmp[1] = 0; inputTmp[1] < geometry.getNy(); ++inputTmp[1]) {
71 for (inputTmp[2] = 0; inputTmp[2] < geometry.getNz(); ++inputTmp[2]) {
72 if (latticeSphere(inputTmp) && _indicatorF(inputTmp)) {
73 T outputTmp[_f.getTargetDim()];
74 _f(outputTmp, inputTmp);
75 for (int i = 0; i < this->getTargetDim(); ++i) {
76 output[i] += outputTmp[i];
77 }
78 voxels += 1;
79 }
80 }
81 }
82 }
83
84 if (voxels > 0) {
85 for (int i = 0; i < this->getTargetDim(); ++i) {
86 output[i] /= voxels;
87 }
88 }
89
90 return true;
91}
92
93
94}
95
96#endif
represents all functors that operate on a cuboid in general, mother class of BlockLatticeF,...
Base block indicator functor.
BlockIndicatorF3D from IndicatorF3D.
BlockLocalAverage3D(BlockF3D< W > &f, BlockIndicatorF3D< 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...
std::string & getName()
read and write access to name
Definition genericF.hh:51
indicator function for a 3D-sphere
Top level namespace for all of OpenLB.