OpenLB 1.7
Loading...
Searching...
No Matches
superLatticeTimeAveraged2D.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_F2_D_HH
25#define SUPER_LATTICE_TIME_AVERAGED_F2_D_HH
26
27#include<vector> // for generic i/o
28#include<cmath> // for lpnorm
29#include<limits>
31
32
33namespace olb {
34template <typename T>
36 : SuperF2D<T,T>(sFunctor.getSuperStructure(),sFunctor.getTargetDim()*2), _ensembles(0), _sFunctor(sFunctor),
37 _sData(_sFunctor.getSuperStructure().getCuboidGeometry(),
38 _sFunctor.getSuperStructure().getLoadBalancer(),
39 _sFunctor.getSuperStructure().getOverlap(),
40 _sFunctor.getTargetDim()),
41 _sDataP2(_sFunctor.getSuperStructure().getCuboidGeometry(),
42 _sFunctor.getSuperStructure().getLoadBalancer(),
43 _sFunctor.getSuperStructure().getOverlap(),
44 _sFunctor.getTargetDim())
45{
46 this->getName() = "Time Averaged " + _sFunctor.getName();
47};
48template <typename T>
49bool SuperLatticeTimeAveragedF2D<T>::operator() (T output[], const int input[])
50{
51 T iCloc = _sData.getLoadBalancer().loc(input[0]);
52 for ( int iDim = 0; iDim < _sData.getDataSize(); iDim++) {
53 output[iDim] = _sData.getBlock(iCloc).get(input+1,iDim) / _ensembles;
54 }
55 for (int iDim = _sData.getDataSize(); iDim < _sData.getDataSize()*2; iDim++)
56 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) {
57 output[iDim]=0;
58 }
59 else {
60 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);
61 }
62 return true;
63};
64template <typename T>
66{
67 return _ensembles;
68};
69template <typename T>
71{
72 int i[3];
73 for (int iCloc=0; iCloc < _sData.getLoadBalancer().size(); ++iCloc) {
74 i[0] = _sData.getLoadBalancer().glob(iCloc);
75 _sData.getBlock(iCloc).forSpatialLocations([&](auto iX, auto iY) {
76 i[1] = iX;
77 i[2] = iY;
78 std::vector<BaseType<T>> tmp(_sFunctor.getTargetDim(), 0);
79 _sFunctor(tmp.data(), i);
80 for (int iDim=0; iDim<_sFunctor.getTargetDim(); iDim++) {
81 _sData.getBlock(iCloc).get({iX, iY}, iDim) += (BaseType<T>)(tmp[iDim]) ;
82 _sDataP2.getBlock(iCloc).get({iX, iY}, iDim) += (BaseType<T>)(tmp[iDim]) *(BaseType<T>)(tmp[iDim]) ;
83 }
84 });
85 }
86 _ensembles++;
87};
88template <typename T>
90{
91 return 0;
92};
93
94template <typename T>
96 : SuperF2D<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())
97{
98 this->getName() = "Time Averaged Corss Correlation " + _sFunctorM.getName()+"-"+_sFunctorN.getName();
99};
100
101template <typename T>
103{
104 int i[3];
105 int iX,iY;
106 int iDimMN;
107
108
109 for (int iCloc=0; iCloc < _sDataMN.getLoadBalancer().size(); ++iCloc) {
110 i[0] = _sDataMN.getLoadBalancer().glob(iCloc);
111 for (iX=0; iX < _sDataMN.getBlock(iCloc).getNx(); iX++) {
112 for (iY=0; iY < _sDataMN.getBlock(iCloc).getNy(); iY++) {
113 i[1] = iX;
114 i[2] = iY;
115 BaseType<T> tmpN[_sFunctorN.getTargetDim()];
116 BaseType<T> tmpM[_sFunctorM.getTargetDim()];
117 _sFunctorN(tmpN, i);
118 _sFunctorM(tmpM, i);
119 iDimMN=0;
120 for (int iDimM=0; iDimM<_sFunctorM.getTargetDim(); iDimM++) {
121 for (int iDimN=0; iDimN<_sFunctorN.getTargetDim(); iDimN++) {
122 _sDataMN.getBlock(iCloc).get({iX, iY}, iDimMN) += (BaseType<T>)(tmpM[iDimM])*(BaseType<T>)(tmpN[iDimN]) ;
123 iDimMN++;
124 }
125 }
126 for (int iDim=0; iDim<_sFunctorN.getTargetDim(); iDim++) {
127 _sDataN.getBlock(iCloc).get({iX, iY}, iDim) += (BaseType<T>)(tmpN[iDim]) ;
128 }
129 for (int iDim=0; iDim<_sFunctorM.getTargetDim(); iDim++) {
130 _sDataM.getBlock(iCloc).get({iX, iY}, iDim) += (BaseType<T>)(tmpM[iDim]) ;
131 }
132 }
133 }
134 }
135
136 _ensembles++;
137};
138template <typename T>
140{
141 int iDim =0;
142 T iCloc = _sDataMN.getLoadBalancer().loc(input[0]);
143 for (int iDimM=0; iDimM<_sFunctorM.getTargetDim(); iDimM++) {
144 for (int iDimN=0; iDimN<_sFunctorN.getTargetDim(); iDimN++) {
145 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;
146 iDim++;
147 }
148 }
149
150 return true;
151
152};
153template <typename T>
155 : SuperF2D<T,T>(sFunctorM.getSuperStructure(),sFunctorM.getTargetDim()), _sFunctorM(sFunctorM), _sFunctorN(sFunctorN), _sGeometry(sGeometry),_material(material)
156{
157 this->getName() = "SuperLatticeTimeAveraged2DL2Norm";
158};
159
160template <typename T>
161bool SuperLatticeTimeAveraged2DL2Norm<T>::operator() (T output[], const int input[])
162{
163 output[0]=0;
164 CuboidGeometry2D<T>& geometry = _sFunctorM.getSuperStructure().getCuboidGeometry();
165
166 int inputTmp[3];
167 T tmpM[_sFunctorM.getTargetDim()];
168 T tmpN[_sFunctorN.getTargetDim()];
169 for (int iC = 0; iC < _sFunctorM.getSuperStructure().getLoadBalancer().size(); ++iC) {
170 Cuboid2D<T>& cuboid = geometry.get(_sFunctorM.getSuperStructure().getLoadBalancer().glob(iC));
171
172 const int nX = cuboid.getNx();
173 const int nY = cuboid.getNy();
174
175 inputTmp[0] = _sFunctorM.getSuperStructure().getLoadBalancer().glob(iC);
176
177 for (inputTmp[1] = 0; inputTmp[1] < nX; ++inputTmp[1]) {
178 for (inputTmp[2] = 0; inputTmp[2] < nY; ++inputTmp[2]) {
179 _sFunctorM(tmpM, inputTmp);
180 _sFunctorN(tmpN, inputTmp);
181 for (int iDim = 0; iDim < _sFunctorM.getTargetDim()/2; ++iDim) {
182 output[0] += (tmpM[iDim]-tmpN[iDim])*(tmpM[iDim]-tmpN[iDim]);
183 }
184
185 }
186 }
187 }
188
189#ifdef PARALLEL_MODE_MPI
190 singleton::mpi().reduceAndBcast(output[0],MPI_SUM);
191#endif
192
193 Cuboid2D<T>& cuboid = geometry.get(_sFunctorM.getSuperStructure().getLoadBalancer().glob(0));
194 const T weight = cuboid.getDeltaR();
195
196 output[0]=util::sqrt(output[0])*weight;
197 return true;
198
199};
200}
201
202#endif
A regular single 2D cuboid is the basic component of a 2D cuboid structure which defines the grid.
Definition cuboid2D.h:54
T getDeltaR() const
Read access to the distance of cuboid nodes.
Definition cuboid2D.hh:106
int getNx() const
Read access to cuboid width.
Definition cuboid2D.hh:112
int getNy() const
Read access to cuboid height.
Definition cuboid2D.hh:118
A cuboid structure represents the grid of a considered domain.
Cuboid2D< T > & get(int i)
Read and write access to the cuboids.
std::string & getName()
read and write access to name
Definition genericF.hh:51
represents all functors that operate on a SuperStructure<T,2> in general
Representation of a statistic for a parallel 2D geometry.
bool operator()(T output[], const int input[])
SuperLatticeTimeAveraged2DL2Norm(SuperF2D< T, T > &sFunctorM, SuperF2D< T, T > &sFunctorN, SuperGeometry< T, 2 > &sGeometry, int material)
SuperLatticeTimeAveragedCrossCorrelationF2D(SuperF2D< T, T > &sFunctorM, SuperF2D< T, T > &sFunctorN)
SuperLatticeTimeAveragedF2D(SuperF2D< T, T > &sFunctor)
bool operator()(T output[], const int input[])
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