summaryrefslogtreecommitdiff
path: root/src/functors/lattice/blockBaseF3D.hh
blob: a8cf79df788bd71e57a649c5887723d7d3d64683 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/*  This file is part of the OpenLB library
 *
 *  Copyright (C) 2012 Lukas Baron, Mathias J. Krause, Albert Mink
 *  E-mail contact: info@openlb.net
 *  The most recent release of OpenLB can be downloaded at
 *  <http://www.openlb.net/>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA  02110-1301, USA.
*/

#ifndef BLOCK_BASE_F_3D_HH
#define BLOCK_BASE_F_3D_HH

#include "blockBaseF3D.h"

namespace olb {


template <typename T>
BlockF3D<T>::BlockF3D(BlockStructure3D& blockStructure, int targetDim)
  : GenericF<T,int>(targetDim,3), _blockStructure(blockStructure) { }

template <typename T>
BlockStructure3D& BlockF3D<T>::getBlockStructure() const
{
  return _blockStructure;
}

template <typename T>
std::vector<T> BlockF3D<T>::getMinValue()
{
  T min[this->getTargetDim()];
  T minTmp[this->getTargetDim()];
  this->operator()(min,0,0);
  for (int iX = 1; iX < _blockStructure.getNx(); ++iX) {
    for (int iY = 1; iY < _blockStructure.getNy(); ++iY) {
      for (int iZ = 1; iZ < _blockStructure.getNz(); ++iZ) {
        this->operator()(minTmp,iX,iY,iZ);
        for (int iDim = 0; iDim < this->getTargetDim(); ++iDim) {
          if (min[iDim] > minTmp[iDim] ) {
            min[iDim] = minTmp[iDim];
          }
        }
      }
    }
  }
  std::vector<T> minV(min,min+this->getTargetDim());
  return minV;
}


template <typename T>
std::vector<T> BlockF3D<T>::getMaxValue()
{
  T max[this->getTargetDim()];
  T maxTmp[this->getTargetDim()];
  this->operator()(max,0,0);
  for (int iX = 1; iX < _blockStructure.getNx(); ++iX) {
    for (int iY = 1; iY < _blockStructure.getNy(); ++iY) {
      for (int iZ = 1; iZ < _blockStructure.getNz(); ++iZ) {
        this->operator()(maxTmp,iX,iY,iZ);
        for (int iDim = 0; iDim < this->getTargetDim(); ++iDim) {
          if (max[iDim] > maxTmp[iDim] ) {
            max[iDim] = maxTmp[iDim];
          }
        }
      }
    }
  }
  std::vector<T> maxV(max,max+this->getTargetDim());
  return maxV;
}


template <typename T,typename BaseType>
BlockDataF3D<T,BaseType>::BlockDataF3D(BlockData3D<T,BaseType>& blockData)
  : BlockF3D<T>(blockData, blockData.getSize()),
    _blockData(blockData)
{ }

template <typename T,typename BaseType>
BlockDataF3D<T,BaseType>::BlockDataF3D(BlockF3D<BaseType>& f)
  : BlockF3D<T>(f.getBlockStructure(), f.getTargetDim()),
    _blockDataStorage(new BlockData3D<T,BaseType>(f)),
    _blockData(*_blockDataStorage)
{ }

template <typename T,typename BaseType>
BlockDataF3D<T,BaseType>::BlockDataF3D(int nx, int ny, int nz, int size)
// hacky solution to both managing BlockData3D using std::unique_ptr and
// passing it down the line to the base class
  : BlockF3D<T>(*(new BlockData3D<T,BaseType>(nx, ny, nz, size)), size),
    _blockDataStorage(static_cast<BlockData3D<T,BaseType>*>(&(this->getBlockStructure()))),
    _blockData(*_blockDataStorage)
{ }

template <typename T,typename BaseType>
BlockData3D<T,BaseType>& BlockDataF3D<T,BaseType>::getBlockData()
{
  return _blockData;
}

template <typename T, typename BaseType>
bool BlockDataF3D<T,BaseType>::operator() (BaseType output[], const int input[])
{
  for (int iDim = 0; iDim < this->getTargetDim(); ++iDim) {
    output[iDim] = _blockData.get(input[0], input[1], input[2], iDim);
  }
  return true;
}


template <typename T,typename BaseType>
BlockDataViewF3D<T,BaseType>::BlockDataViewF3D(BlockData3D<T,BaseType>& blockData, int overlap)
  : BlockDataF3D<T,BaseType>(blockData),
    _overlap(overlap)
{ }

template <typename T, typename BaseType>
bool BlockDataViewF3D<T,BaseType>::operator() (BaseType output[], const int input[])
{
  for (int iDim = 0; iDim < this->getTargetDim(); ++iDim) {
    output[iDim] = this->_blockData.get(input[0] + _overlap,
                                        input[1] + _overlap,
                                        input[2] + _overlap,
                                        iDim);
  }
  return true;
}


template <typename T>
BlockIdentity3D<T>::BlockIdentity3D(BlockF3D<T>& f)
  : BlockF3D<T>(f.getBlockStructure(),f.getTargetDim() ), _f(f)
{
  this->getName() = _f.getName();
  std::swap( _f._ptrCalcC, this->_ptrCalcC );
}

template <typename T>
bool BlockIdentity3D<T>::operator()(T output[], const int input[])
{
  return _f(output,input);
}


template <typename T>
BlockExtractComponentF3D<T>::BlockExtractComponentF3D(BlockF3D<T>& f, int extractDim)
  : BlockF3D<T>(f.getBlockStructure(),1 ), _f(f), _extractDim(extractDim)
{
  this->getName() = _f.getName();
}

template <typename T>
int BlockExtractComponentF3D<T>::getExtractDim()
{
  return _extractDim;
}

template <typename T>
bool BlockExtractComponentF3D<T>::operator()(T output[], const int input[])
{
  std::vector<T> outTmp(_f.getTargetDim(), T{});
  _f(outTmp.data(), input);
  output[0] = outTmp[_extractDim];
  return true;
}


template <typename T>
BlockExtractComponentIndicatorF3D<T>::BlockExtractComponentIndicatorF3D(
  BlockF3D<T>& f, int extractDim, BlockIndicatorF3D<T>& indicatorF)
  : BlockExtractComponentF3D<T>(f, extractDim),
    _indicatorF(indicatorF)
{
  this->getName() = f.getName();
}

template <typename T>
bool BlockExtractComponentIndicatorF3D<T>::operator()(T output[], const int input[])
{
  output[0] = T{};
  if (_indicatorF(input)) {
    return BlockExtractComponentF3D<T>::operator()(output, input);
  }
  return true;
}


template <typename T>
BlockExtractIndicatorF3D<T>::BlockExtractIndicatorF3D(
  BlockF3D<T>& f, BlockIndicatorF3D<T>& indicatorF)
  : BlockF3D<T>(f.getBlockStructure(), f.getTargetDim()),
    _f(f),
    _indicatorF(indicatorF)
{
  this->getName() = f.getName();
}

template <typename T>
bool BlockExtractIndicatorF3D<T>::operator()(T output[], const int input[])
{
  for (int i = 0; i < this->getTargetDim(); ++i) {
    output[i] = T{};
  }
  if (_indicatorF(input)) {
    _f(output, input);
  }
  return true;
}


template <typename T>
BlockDotProductF3D<T>::BlockDotProductF3D(BlockF3D<T>& f, T vector[])
  : BlockF3D<T>(f.getBlockStructure(),1 </