OpenLB 1.7
Loading...
Searching...
No Matches
blockStatisticF3D.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_STATISTIC_F3D_HH
25#define BLOCK_STATISTIC_F3D_HH
26
27#include "blockStatisticF3D.h"
28
29namespace olb {
30
31
32template <typename T, typename W>
34 BlockIndicatorF3D<T>& indicatorF,
35 Cuboid3D<T>& cuboid,
36 T expectedValue)
37 : BlockSum3D<T,W>(f, indicatorF),
38 _f(f),
39 _indicatorF(indicatorF),
40 _cuboid(cuboid),
41 _expectedValue(expectedValue)
42{
43 this->getName() = "BlockVariance("+_f.getName()+")";
44}
45
46template <typename T, typename W>
47bool BlockVarianceF3D<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 for(unsigned i=0; i<_f.getTargetDim(); ++i) {
56 outputTmp[i] = W(0);
57 }
58 int inputTmp[_f.getSourceDim()];
59
60 for (inputTmp[0] = 0; inputTmp[0] < _cuboid.getNx(); ++inputTmp[0]) {
61 for (inputTmp[1] = 0; inputTmp[1] < _cuboid.getNy(); ++inputTmp[1]) {
62 for (inputTmp[2] = 0; inputTmp[2] < _cuboid.getNz(); ++inputTmp[2]) {
63 if (_indicatorF(inputTmp)) {
64 _f(outputTmp,inputTmp);
65 for (int i = 0; i < _f.getTargetDim(); ++i) {
66 output[i] += util::pow(outputTmp[i] - _expectedValue, 2);
67 }
68 voxels += 1;
69 }
70 }
71 }
72 }
73
74
75 output[_f.getTargetDim()] += voxels;
76
77 return true;
78}
79
80
81template <typename T, typename W>
83 BlockIndicatorF3D<T>& indicatorF,
84 Cuboid3D<T>& cuboid,
85 T expectedValue)
86 : BlockSum3D<T,W>(f, indicatorF),
87 _f(f),
88 _indicatorF(indicatorF),
89 _cuboid(cuboid),
90 _expectedValue(expectedValue)
91{
92 this->getName() = "BlockStdDeviation("+_f.getName()+")";
93}
94
95template <typename T, typename W>
96bool BlockStdDeviationF3D<T,W>::operator() (W output[], const int input[])
97{
98 OLB_ASSERT(_f.getSourceDim() == _indicatorF.getSourceDim(),
99 "functor source dimension equals indicator source dimension");
100
101 std::size_t voxels(0);
102
103 W outputTmp[_f.getTargetDim()];
104 for(int i=0; i<_f.getTargetDim(); ++i) {
105 outputTmp[i] = W(0);
106 }
107 int inputTmp[_f.getSourceDim()];
108
109 for (inputTmp[0] = 0; inputTmp[0] < _cuboid.getNx(); ++inputTmp[0]) {
110 for (inputTmp[1] = 0; inputTmp[1] < _cuboid.getNy(); ++inputTmp[1]) {
111 for (inputTmp[2] = 0; inputTmp[2] < _cuboid.getNz(); ++inputTmp[2]) {
112 if (_indicatorF(inputTmp)) {
113 _f(outputTmp,inputTmp);
114 for (int i = 0; i < _f.getTargetDim(); ++i) {
115 output[i] += util::pow(outputTmp[i] - _expectedValue, 2);
116 }
117 voxels += 1;
118 }
119 }
120 }
121 }
122
123
124 output[_f.getTargetDim()] += voxels;
125
126 return true;
127}
128
129}
130
131#endif
represents all functors that operate on a cuboid in general, mother class of BlockLatticeF,...
Base block indicator functor.
bool operator()(W output[], const int input[]) override
BlockStdDeviationF3D(BlockF3D< W > &f, BlockIndicatorF3D< T > &indicatorF, Cuboid3D< T > &cuboid, T expectedValue)
BlockSum3D sums all components of f over a indicated subset.
bool operator()(W output[], const int input[]) override
BlockVarianceF3D(BlockF3D< W > &f, BlockIndicatorF3D< T > &indicatorF, Cuboid3D< T > &cuboid, T expectedValue)
A regular single 3D cuboid is the basic component of a 3D cuboid structure which defines the grid.
Definition cuboid3D.h:58
std::string & getName()
read and write access to name
Definition genericF.hh:51
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Definition pack.h:112
Top level namespace for all of OpenLB.
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45