OpenLB 1.7
Loading...
Searching...
No Matches
superLatticeTimeAveraged3D.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2018 Mathias J. Krause, Benedict Hasenauer
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_LATTICE_TIME_AVERAGED_F3_D_HH
25#define SUPER_LATTICE_TIME_AVERAGED_F3_D_HH
26
27#include<vector> // for generic i/o
28#include<cmath> // for lpnorm
29#include<limits>
31
32
33namespace olb {
34
35template <typename T>
37 : SuperF3D<T,T>(sFunctor.getSuperStructure(),sFunctor.getTargetDim()*2),
38 _ensembles(0),
39 _sFunctor(sFunctor),
40 _sData(_sFunctor.getSuperStructure().getCuboidGeometry(),
41 _sFunctor.getSuperStructure().getLoadBalancer(),
42 _sFunctor.getSuperStructure().getOverlap(),
43 _sFunctor.getTargetDim()),
44 _sDataP2(_sFunctor.getSuperStructure().getCuboidGeometry(),
45 _sFunctor.getSuperStructure().getLoadBalancer(),
46 _sFunctor.getSuperStructure().getOverlap(),
47 _sFunctor.getTargetDim())
48{
49 this->getName() = "Time Averaged " + _sFunctor.getName();
50};
51
52template <typename T>
54 : SuperF3D<T,T>(sFunctor.getSuperStructure(),sFunctor.getTargetDim()),
55 _ensembles(0),
56 _sFunctor(sFunctor),
57 _sData(_sFunctor.getSuperStructure().getCuboidGeometry(),
58 _sFunctor.getSuperStructure().getLoadBalancer(),
59 _sFunctor.getSuperStructure().getOverlap(),
60 _sFunctor.getTargetDim()),
61 _sDataP2(_sFunctor.getSuperStructure().getCuboidGeometry(),
62 _sFunctor.getSuperStructure().getLoadBalancer(),
63 _sFunctor.getSuperStructure().getOverlap(),
64 _sFunctor.getTargetDim())
65{
66 this->getName() = "Time Averaged Magnitudes" + _sFunctor.getName();
67};
68
69template <typename T>
70bool SuperLatticeTimeAveragedF3D<T>::operator() (T output[], const int input[])
71{
72 T iCloc = _sData.getLoadBalancer().loc(input[0]);
73 for ( int iDim = 0; iDim < _sData.getDataSize(); iDim++) {
74 output[iDim] = _sData.getBlock(iCloc).get(input+1,iDim) / _ensembles;
75 }
76 for (int iDim = _sData.getDataSize(); iDim < _sData.getDataSize()*2; iDim++)
77 if (_sDataP2.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())/_ensembles - _sData.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())*_sData.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())/_ensembles/_ensembles<0) {
78 output[iDim]=0;
79 }
80 else {
81 output[iDim] = util::sqrt(_sDataP2.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())/_ensembles - _sData.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())*_sData.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())/_ensembles/_ensembles);
82 }
83 return true;
84};
85
86template <typename T>
88{
89 T iCloc = _sData.getLoadBalancer().loc(input[0]);
90 for ( int iDim = 0; iDim < _sData.getDataSize(); iDim++) {
91 output[iDim] = _sData.getBlock(iCloc).get(input+1,iDim) / _ensembles;
92 }
93 for (int iDim = _sData.getDataSize(); iDim < _sData.getDataSize()*2; iDim++)
94 if (_sDataP2.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())/_ensembles - _sData.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())*_sData.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())/_ensembles/_ensembles<0) {
95 output[iDim]=0;
96 }
97 else {
98 output[iDim] = util::sqrt(_sDataP2.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())/_ensembles - _sData.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())*_sData.getBlock(iCloc).get(input+1,(int) iDim-_sDataP2.getDataSize())/_ensembles/_ensembles);
99 }
100 return true;
101};
102
103template <typename T>
105{
106 return _ensembles;
107};
108
109template <typename T>
111{
112 return _ensembles;
113};
114
115template <typename T>
117{
118 int i[4];
119 for (int iCloc=0; iCloc < _sData.getLoadBalancer().size(); ++iCloc) {
120 i[0] = _sData.getLoadBalancer().glob(iCloc);
121 _sData.getBlock(iCloc).forSpatialLocations([&](auto iX, auto iY, auto iZ) {
122 i[1] = iX;
123 i[2] = iY;
124 i[3] = iZ;
125 //BaseType<T> tmp[_sFunctor.getTargetDim()];
126 T tmp[_sFunctor.getTargetDim()];
127 _sFunctor(tmp, i);
128 for (int iDim=0; iDim<_sFunctor.getTargetDim(); iDim++) {
129 _sData.getBlock(iCloc).get({iX, iY, iZ}, iDim) += (BaseType<T>)(tmp[iDim]) ;
130 _sDataP2.getBlock(iCloc).get({iX, iY, iZ}, iDim) += (BaseType<T>)(tmp[iDim]) *(BaseType<T>)(tmp[iDim]) ;
131 }
132 });
133 }
134 _ensembles++;
135};
136
137template <typename T>
139{
140 int i[4];
141 for (int iCloc=0; iCloc < _sData.getLoadBalancer().size(); ++iCloc) {
142 i[0] = _sData.getLoadBalancer().glob(iCloc);
143 _sData.getBlock(iCloc).forSpatialLocations([&](auto iX, auto iY, auto iZ) {
144 i[1] = iX;
145 i[2] = iY;
146 i[3] = iZ;
147 BaseType<T> tmp[_sFunctor.getTargetDim()];
148 _sFunctor(tmp, i);
149 for (int iDim=0; iDim<_sFunctor.getTargetDim(); iDim++) {
150 _sData.getBlock(iCloc).get({iX, iY, iZ}, iDim) += util::sqrt((BaseType<T>)(tmp[0])*(BaseType<T>)(tmp[0])+(BaseType<T>)(tmp[1])*(BaseType<T>)(tmp[1])+(BaseType<T>)(tmp[2])*(BaseType<T>)(tmp[2])) ;
151 _sDataP2.getBlock(iCloc).get({iX, iY, iZ}, iDim) += (BaseType<T>)(tmp[0]) *(BaseType<T>)(tmp[0]) +(BaseType<T>)(tmp[1]) *(BaseType<T>)(tmp[1])+(BaseType<T>)(tmp[2]) *(BaseType<T>)(tmp[2]) ;
152 }
153 });
154 }
155 _ensembles++;
156};
157
158template <typename T>
160{
161 return 0;
162};
163
164template <typename T>
169
170
171template <typename T>
173 : SuperF3D<T,T>(sFunctorM.getSuperStructure(),sFunctorM.getTargetDim()*sFunctorN.getTargetDim()),_ensembles(0), _sFunctorM(sFunctorM), _sFunctorN(sFunctorN), _sDataM(_sFunctorM.getSuperStructure().getCuboidGeometry(),_sFunctorM.getSuperStructure().getLoadBalancer(),_sFunctorM.getSuperStructure().getOverlap(),_sFunctorM.getTargetDim()),_sDataN(_sFunctorN.getSuperStructure().getCuboidGeometry(),_sFunctorN.getSuperStructure().getLoadBalancer(),_sFunctorN.getSuperStructure().getOverlap(),_sFunctorN.getTargetDim()),_sDataMN(_sFunctorM.getSuperStructure().getCuboidGeometry(),_sFunctorM.getSuperStructure().getLoadBalancer(),_sFunctorM.getSuperStructure().getOverlap(),_sFunctorM.getTargetDim()*_sFunctorN.getTargetDim())
174{
175 this->getName() = "Time Averaged Corss Correlation " + _sFunctorM.getName()+"-"+_sFunctorN.getName();
176};
177
178template <typename T>
180{
181 int i[4];
182 int iX,iY,iZ;
183 int iDimMN;
184
185 for (int iCloc=0; iCloc < _sDataMN.getLoadBalancer().size(); ++iCloc) {
186 i[0] = _sDataMN.getLoadBalancer().glob(iCloc);
187 for (iX=0; iX < _sDataMN.getBlock(iCloc).getNx(); iX++) {
188 for (iY=0; iY < _sDataMN.getBlock(iCloc).getNy(); iY++) {
189 for (iZ=0; iZ < _sDataMN.getBlock(iCloc).getNz(); iZ++) {
190 i[1] = iX;
191 i[2] = iY;
192 i[3] = iZ;
193 BaseType<T> tmpN[_sFunctorN.getTargetDim()];
194 BaseType<T> tmpM[_sFunctorM.getTargetDim()];
195 _sFunctorN(tmpN, i);
196 _sFunctorM(tmpM, i);
197 iDimMN=0;
198 for (int iDimM=0; iDimM<_sFunctorM.getTargetDim(); iDimM++) {
199 for (int iDimN=0; iDimN<_sFunctorN.getTargetDim(); iDimN++) {
200 _sDataMN.getBlock(iCloc).get({iX, iY, iZ}, iDimMN) += (BaseType<T>)(tmpM[iDimM])*(BaseType<T>)(tmpN[iDimN]) ;
201 iDimMN++;
202 }
203 }
204 for (int iDim=0; iDim<_sFunctorN.getTargetDim(); iDim++) {
205 _sDataN.getBlock(iCloc).get({iX, iY, iZ}, iDim) += (BaseType<T>)(tmpN[iDim]) ;
206 }
207 for (int iDim=0; iDim<_sFunctorM.getTargetDim(); iDim++) {
208 _sDataM.getBlock(iCloc).get({iX, iY, iZ}, iDim) += (BaseType<T>)(tmpM[iDim]) ;
209 }
210 }
211 }
212 }
213 }
214
215 _ensembles++;
216};
217
218template <typename T>
220{
221 int iDim =0;
222 T iCloc = _sDataMN.getLoadBalancer().loc(input[0]);
223 for (int iDimM=0; iDimM<_sFunctorM.getTargetDim(); iDimM++) {
224 for (int iDimN=0; iDimN<_sFunctorN.getTargetDim(); iDimN++) {
225 output[iDim] = _sDataMN.getBlock(iCloc).get(input+1,iDim)-_sDataM.getBlock(iCloc).get(input+1,iDimM) *_sDataN.getBlock(iCloc).get(input+1,iDimN)/_ensembles/_ensembles;
226 iDim++;
227 }
228 }
229
230 return true;
231};
232
233template <typename T>
235 : SuperF3D<T,T>(sFunctorM.getSuperStructure(),sFunctorM.getTargetDim()), _sFunctorM(sFunctorM), _sFunctorN(sFunctorN), _sGeometry(sGeometry),_material(material)
236{
237 this->getName() = "SuperLatticeTimeAveraged3DL2Norm";
238};
239
240template <typename T>
241bool SuperLatticeTimeAveraged3DL2Norm<T>::operator() (T output[], const int input[])
242{
243 output[0]=0;
244 CuboidGeometry3D<T>& geometry = _sFunctorM.getSuperStructure().getCuboidGeometry();
245
246 int inputTmp[4];
247 T tmpM[_sFunctorM.getTargetDim()];
248 T tmpN[_sFunctorN.getTargetDim()];
249 for (int iC = 0; iC < _sFunctorM.getSuperStructure().getLoadBalancer().size(); ++iC) {
250 Cuboid3D<T>& cuboid = geometry.get(_sFunctorM.getSuperStructure().getLoadBalancer().glob(iC));
251
252 const int nX = cuboid.getNx();
253 const int nY = cuboid.getNy();
254 const int nZ = cuboid.getNz();
255
256 inputTmp[0] = _sFunctorM.getSuperStructure().getLoadBalancer().glob(iC);
257
258 for (inputTmp[1] = 0; inputTmp[1] < nX; ++inputTmp[1]) {
259 for (inputTmp[2] = 0; inputTmp[2] < nY; ++inputTmp[2]) {
260 for (inputTmp[3] = 0; inputTmp[3] < nZ; ++inputTmp[3]) {
261 _sFunctorM(tmpM, inputTmp);
262 _sFunctorN(tmpN, inputTmp);
263 for (int iDim = 0; iDim < _sFunctorM.getTargetDim()/2; ++iDim) {
264 output[0] += (tmpM[iDim]-tmpN[iDim])*(tmpM[iDim]-tmpN[iDim]);
265 }
266 }
267
268 }
269 }
270 }
271
272#ifdef PARALLEL_MODE_MPI
273 singleton::mpi().reduceAndBcast(output[0],MPI_SUM);
274#endif
275
276 Cuboid3D<T>& cuboid = geometry.get(_sFunctorM.getSuperStructure().getLoadBalancer().glob(0));
277 const T weight = cuboid.getDeltaR();
278
279 output[0]=util::sqrt(output[0])*weight;
280 return true;
281
282};
283}
284
285#endif
A regular single 3D cuboid is the basic component of a 3D cuboid structure which defines the grid.
Definition cuboid3D.h:58
T getDeltaR() const
Read only access to the distance of cuboid nodes.
Definition cuboid3D.hh:141
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.
std::string & getName()
read and write access to name
Definition genericF.hh:51
represents all functors that operate on a SuperStructure<T,3> in general
Representation of a statistic for a parallel 2D geometry.
bool operator()(T output[], const int input[])
SuperLatticeTimeAveraged3DL2Norm(SuperF3D< T, T > &sFunctorM, SuperF3D< T, T > &sFunctorN, SuperGeometry< T, 3 > &sGeometry, int material)
SuperLatticeTimeAveragedCrossCorrelationF3D(SuperF3D< T, T > &sFunctorM, SuperF3D< T, T > &sFunctorN)
SuperLatticeTimeAveragedF3D(SuperF3D< T, T > &sFunctor)
bool operator()(T output[], const int input[])
SuperLatticeTimeAveragedMagnitudesF3D(SuperF3D< T, T > &sFunctor)
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
Top level namespace for all of OpenLB.
typename util::BaseTypeHelper< T >::type BaseType
Definition baseType.h:59