OpenLB 1.7
Loading...
Searching...
No Matches
superStatisticF3D.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 SUPER_STATISTIC_F3D_HH
25#define SUPER_STATISTIC_F3D_HH
26
27#include "superStatisticF3D.h"
29
30namespace olb {
31
32
33template <typename T, typename W>
35 FunctorPtr<SuperIndicatorF3D<T>>&& indicatorF,
36 T expectedValue)
37 : SuperF3D<T,W>(f->getSuperStructure(), f->getTargetDim()+1),
38 _f(std::move(f)),
39 _indicatorF(std::move(indicatorF)),
40 _expectedValue(expectedValue)
41{
42 this->getName() = "Variance("+_f->getName()+")";
43
44 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
45 CuboidGeometry3D<T>& cuboid = _f->getSuperStructure().getCuboidGeometry();
46
47 if ( _f->getBlockFSize() == load.size() &&
48 _indicatorF->getBlockFSize() == load.size() ) {
49 for (int iC = 0; iC < load.size(); ++iC) {
50 this->_blockF.emplace_back(
51 new BlockVarianceF3D<T,W>(_f->getBlockF(iC),
52 _indicatorF->getBlockIndicatorF(iC),
53 cuboid.get(load.glob(iC)),
54 _expectedValue)
55 );
56 }
57 }
58}
59
60template <typename T, typename W>
62 SuperGeometry<T,3>& superGeometry,
63 const int material,
64 T expectedValue)
66 std::forward<decltype(f)>(f),
67 superGeometry.getMaterialIndicator(material),
68 expectedValue)
69{ }
70
71template <typename T, typename W>
72bool SuperVarianceF3D<T,W>::operator() (W output[], const int input[])
73{
75 CuboidGeometry3D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
76 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
77
78 std::size_t voxels(0);
79
80 for (int i = 0; i <= _f->getTargetDim(); ++i) {
81 output[i] = W(0);
82 }
83
84 if (this->_blockF.empty()) {
85 W outputTmp[_f->getTargetDim()];
86 for(unsigned i=0; i<_f->getTargetDim(); ++i) {
87 outputTmp[i] = W(0);
88 }
89 int inputTmp[_f->getSourceDim()];
90
91 for (int iC = 0; iC < load.size(); ++iC) {
92 const Cuboid3D<T> cuboid = geometry.get(load.glob(iC));
93 inputTmp[0] = load.glob(iC);
94 for (inputTmp[1] = 0; inputTmp[1] < cuboid.getNx(); ++inputTmp[1]) {
95 for (inputTmp[2] = 0; inputTmp[2] < cuboid.getNy(); ++inputTmp[2]) {
96 for (inputTmp[3] = 0; inputTmp[3] < cuboid.getNz(); ++inputTmp[3]) {
97 if (_indicatorF(inputTmp)) {
98 _f(outputTmp,inputTmp);
99 for (int i = 0; i < _f->getTargetDim(); ++i) {
100 output[i] += util::pow(outputTmp[i] - _expectedValue, 2);
101 }
102 voxels += 1;
103 }
104 }
105 }
106 }
107 output[_f->getTargetDim()] += voxels;
108 }
109 }
110 else {
111 for (int iC = 0; iC < load.size(); ++iC) {
112 this->getBlockF(iC)(output, input);
113 }
114 }
115
116#ifdef PARALLEL_MODE_MPI
117 for (int i = 0; i <= this->getTargetDim(); ++i) {
118 singleton::mpi().reduceAndBcast(output[i], MPI_SUM);
119 }
120#endif
121
122 for (int i = 0; i < _f->getTargetDim(); ++i) {
123 output[i] = output[i] / output[_f->getTargetDim()];
124 }
125
126 return true;
127}
128
129
131
132
133
134template <typename T, typename W>
136 FunctorPtr<SuperIndicatorF3D<T>>&& indicatorF,
137 T expectedValue)
138 : SuperF3D<T,W>(f->getSuperStructure(), f->getTargetDim()+1),
139 _f(std::move(f)),
140 _indicatorF(std::move(indicatorF)),
141 _expectedValue(expectedValue)
142{
143 this->getName() = "Variance("+_f->getName()+")";
144
145 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
146 CuboidGeometry3D<T>& cuboid = _f->getSuperStructure().getCuboidGeometry();
147
148 if ( _f->getBlockFSize() == load.size() &&
149 _indicatorF->getBlockFSize() == load.size() ) {
150 for (int iC = 0; iC < load.size(); ++iC) {
151 this->_blockF.emplace_back(
152 new BlockStdDeviationF3D<T,W>(_f->getBlockF(iC),
153 _indicatorF->getBlockIndicatorF(iC),
154 cuboid.get(load.glob(iC)),
155 _expectedValue)
156 );
157 }
158 }
159}
160
161template <typename T, typename W>
163 SuperGeometry<T,3>& superGeometry,
164 const int material,
165 T expectedValue)
167 std::forward<decltype(f)>(f),
168 superGeometry.getMaterialIndicator(material),
169 expectedValue)
170{ }
171
172template <typename T, typename W>
173bool SuperStdDeviationF3D<T,W>::operator() (W output[], const int input[])
174{
176 CuboidGeometry3D<T>& geometry = _f->getSuperStructure().getCuboidGeometry();
177 LoadBalancer<T>& load = _f->getSuperStructure().getLoadBalancer();
178
179 std::size_t voxels(0);
180
181 for (int i = 0; i <= _f->getTargetDim(); ++i) {
182 output[i] = W(0);
183 }
184
185 if (this->_blockF.empty()) {
186 W outputTmp[_f->getTargetDim()];
187 for(int i=0; i<_f->getTargetDim(); ++i) {
188 outputTmp[i] = W(0);
189 }
190 int inputTmp[_f->getSourceDim()];
191
192 for (int iC = 0; iC < load.size(); ++iC) {
193 const Cuboid3D<T> cuboid = geometry.get(load.glob(iC));
194 inputTmp[0] = load.glob(iC);
195 for (inputTmp[1] = 0; inputTmp[1] < cuboid.getNx(); ++inputTmp[1]) {
196 for (inputTmp[2] = 0; inputTmp[2] < cuboid.getNy(); ++inputTmp[2]) {
197 for (inputTmp[3] = 0; inputTmp[3] < cuboid.getNz(); ++inputTmp[3]) {
198 if (_indicatorF(inputTmp)) {
199 _f(outputTmp,inputTmp);
200 for (int i = 0; i < _f->getTargetDim(); ++i) {
201 output[i] += util::pow(outputTmp[i] - _expectedValue, 2);
202 }
203 voxels += 1;
204 }
205 }
206 }
207 }
208 output[_f->getTargetDim()] += voxels;
209 }
210 }
211 else {
212 for (int iC = 0; iC < load.size(); ++iC) {
213 this->getBlockF(iC)(output, input);
214 }
215 }
216
217#ifdef PARALLEL_MODE_MPI
218 for (int i = 0; i <= this->getTargetDim(); ++i) {
219 singleton::mpi().reduceAndBcast(output[i], MPI_SUM);
220 }
221#endif
222
223 for (int i = 0; i < _f->getTargetDim(); ++i) {
224 output[i] = util::sqrt(output[i] / output[_f->getTargetDim()]);
225 }
226
227
228 return true;
229}
230
231
232
233}
234
235#endif
236
BlockStdDeviationF3D returns the Deviation in each component of f on a indicated subset calcutalted w...
BlockVarianceF3D returns the Variance in each component of f on a indicated subset calcutalted with S...
A regular single 3D cuboid is the basic component of a 3D cuboid structure which defines the grid.
Definition cuboid3D.h:58
int getNz() const
Read access to cuboid depth.
Definition cuboid3D.hh:159
int getNy() const
Read access to cuboid height.
Definition cuboid3D.hh:153
int getNx() const
Read access to cuboid width.
Definition cuboid3D.hh:147
A cuboid geometry represents a voxel mesh.
Cuboid3D< T > & get(int iC)
Read and write access to a single cuboid.
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
Base class for all LoadBalancer.
int glob(int loc) const
represents all functors that operate on a SuperStructure<T,3> in general
SuperStructure< T, 3 > & getSuperStructure()
std::vector< std::unique_ptr< BlockF3D< W > > > _blockF
Super functors may consist of several BlockF3D<W> derived functors.
Representation of a statistic for a parallel 2D geometry.
Base indicator functor (discrete)
SuperStdDeviaitonF3D returns the standard deviation in each component of f on a indicated subset calc...
SuperStdDeviationF3D(FunctorPtr< SuperF3D< T, W > > &&f, SuperGeometry< T, 3 > &superGeometry, const int material, T expectedValue)
Constructor for determining the standard deviation of f on a indicated subset.
bool operator()(W output[], const int input[]) override
virtual void communicate()
SuperVarianceF3D returns the Variance in each component of f on a indicated subset calcutalted with S...
bool operator()(W output[], const int input[]) override
Global average operator.
SuperVarianceF3D(FunctorPtr< SuperF3D< T, W > > &&f, SuperGeometry< T, 3 > &superGeometry, const int material, T expectedValue)
Constructor for determining the standard deviation of f on a indicated subset.
void reduceAndBcast(T &reductVal, MPI_Op op, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Reduction operation, followed by a broadcast.
MpiManager & mpi()
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
Definition pack.h:100
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.