OpenLB 1.7
Loading...
Searching...
No Matches
blockStdDeviationF3D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2019 Jakob Mangold, Mathias J. Krause
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_STDDEVIATION_F3D_HH
25#define BLOCK_STDDEVIATION_F3D_HH
26
28
29namespace olb {
30
31
32template <typename T, typename W>
34 BlockIndicatorF3D<T>& indicatorF,
35 Cuboid3D<T>& cuboid,
36 T expectedValue)
37 : BlockAverage3D<T,W>(f, indicatorF),
38 _f(f),
39 _indicatorF(indicatorF),
40 _cuboid(cuboid),
41 _expectedValue(expectedValue)
42{
43 this->getName() = "BlockStdDeviation("+_f.getName()+")";
44}
45
46template <typename T, typename W>
47bool BlockStdDeviationF3D<T,W>::operator() (W output[], const int input[])
48{
49 OLB_ASSERT(_f.getSourceDim() == _indicatorF.getSourceDim(),
50 "functor source dimension equals indicator source dimension");
51
52 std::size_t voxels(0);
53
54 W outputTmp[_f.getTargetDim()];
55
56 int inputTmp[_f.getSourceDim()];
57
58 for (int i = 0; i < this->getTargetDim(); ++i) {
59 output[i] = W(0);
60 }
61
62
63 for (inputTmp[0] = 0; inputTmp[0] < _cuboid.getNx(); ++inputTmp[0]) {
64 for (inputTmp[1] = 0; inputTmp[1] < _cuboid.getNy(); ++inputTmp[1]) {
65 for (inputTmp[2] = 0; inputTmp[2] < _cuboid.getNz(); ++inputTmp[2]) {
66 if (_indicatorF(inputTmp)) {
67 _f(outputTmp,inputTmp);
68 for (int i = 0; i < _f.getTargetDim(); ++i) {
69 output[i] += util::pow((outputTmp[i] - _expectedValue), 2);
70 }
71 voxels += 1;
72 }
73 }
74 }
75 }
76
77// std::cout << output[0] << " " << voxels << " " << _expectedValue << "\n";
78
79 output[_f.getTargetDim()] += voxels;
80
81 return true;
82}
83
84}
85
86#endif
BlockStdDeviationF3D(BlockF3D< W > &f, BlockIndicatorF3D< T > &indicatorF, Cuboid3D< T > &cuboid, T expectedValue)
Top level namespace for all of OpenLB.
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45