OpenLB 1.7
Loading...
Searching...
No Matches
blockLocalAverage2D.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_2D_HH
25#define BLOCK_LOCAL_AVERAGE_2D_HH
26
27#include "blockLocalAverage2D.h"
30
31namespace olb {
32
33
34template<typename T, typename W>
36 BlockF2D<W>& f,
37 BlockIndicatorF2D<T>& indicatorF,
38 T radius)
39 : BlockF2D<W>(f.getBlockStructure(), f.getTargetDim()),
40 _f(f),
41 _indicatorF(indicatorF),
42 _radius(radius)
43{
44 this->getName() = "BlockLocalAverage(" + _f.getName() + ")";
45}
46
47template<typename T, typename W>
48bool BlockLocalAverage2D<T,W>::operator() (W output[], const int input[])
49{
50 const auto& geometry = _indicatorF.getBlockGeometry();
51
52 for (int i = 0; i < this->getTargetDim(); ++i) {
53 output[i] = 0.;
54 }
55
56 if (!_indicatorF(input)) {
57 return true;
58 }
59
60 T centerOfCircle[2];
61 geometry.getPhysR(centerOfCircle, input);
62 IndicatorCircle2D<T> analyticalCircle(centerOfCircle, _radius);
64 analyticalCircle,
65 _indicatorF.getBlockGeometry());
66
67 std::size_t voxels(0);
68 int inputTmp[2];
69
70 for (inputTmp[0] = 0; inputTmp[0] < geometry.getNx(); ++inputTmp[0]) {
71 for (inputTmp[1] = 0; inputTmp[1] < geometry.getNy(); ++inputTmp[1]) {
72 if (latticeCircle(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 if (voxels > 0) {
84 for (int i = 0; i < this->getTargetDim(); ++i) {
85 output[i] /= voxels;
86 }
87 }
88
89 return true;
90}
91
92
93}
94
95#endif
represents all functors that operate on a cuboid in general, mother class of BlockLatticeF,...
Base block indicator functor (discrete)
BlockIndicatorF2D from IndicatorF2D.
BlockLocalAverage2D(BlockF2D< W > &f, BlockIndicatorF2D< 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 2D circle
This file contains indicator functions.
Top level namespace for all of OpenLB.