summaryrefslogtreecommitdiff
path: root/src/functors/lattice/blockBaseF2D.hh
blob: e4aa37a2ba2f3974a5989f185e9251b13dccc208 (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
/*  This file is part of the OpenLB library
 *
 *  Copyright (C) 2013 Albert Mink, Lukas Baron, Mathias J. Krause
 *  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_2D_HH
#define BLOCK_BASE_F_2D_HH

#include "blockBaseF2D.h"

namespace olb {


// BlockF2D
template <typename T>
BlockF2D<T>::BlockF2D(BlockStructure2D& blockStructure, int targetDim)
  : GenericF<T,int>(targetDim,2), _blockStructure(&blockStructure) { }

template <typename T>
BlockF2D<T>::BlockF2D(int targetDim)
  : GenericF<T,int>(targetDim,2), _blockStructure(nullptr) { }

template <typename T>
BlockStructure2D& BlockF2D<T>::getBlockStructure()
{
  return *_blockStructure;
}

template <typename T>
void BlockF2D<T>::setBlockStructure(BlockStructure2D* blockStructure)
{
  _blockStructure = blockStructure;
}

//template <typename T>
//std::vector<T> BlockF2D<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) {
//      this->operator()(minTmp,iX,iY);
//      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> BlockF2D<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) {
//      this->operator()(maxTmp,iX,iY);
//      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>
BlockDataF2D<T,BaseType>::BlockDataF2D(BlockData2D<T,BaseType>& blockData)
  : BlockF2D<T>(blockData, blockData.getSize()),
    _blockData(blockData)
{ }

template <typename T,typename BaseType>
BlockDataF2D<T,BaseType>::BlockDataF2D(BlockF2D<BaseType>& f)
  : BlockF2D<T>(f.getBlockStructure(), f.getTargetDim()),
    _blockDataStorage(new BlockData2D<T,BaseType>(f)),
    _blockData(*_blockDataStorage)
{ }

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

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

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


template <typename T,typename BaseType>
BlockDataViewF2D<T,BaseType>::BlockDataViewF2D(BlockData2D<T,BaseType>& blockData, int overlap)
  : BlockDataF2D<T,BaseType>(blockData),
    _overlap(overlap)
{ }

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


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

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


// BlockLatticeF2D
template <typename T, typename DESCRIPTOR>
BlockLatticeF2D<T,DESCRIPTOR>::BlockLatticeF2D
(BlockLatticeStructure2D<T,DESCRIPTOR>& blockStructure, int targetDim)
  : BlockF2D<T>(blockStructure, targetDim), _blockLattice(blockStructure) { }

template <typename T, typename DESCRIPTOR>
BlockLatticeStructure2D<T,DESCRIPTOR>& BlockLatticeF2D<T,DESCRIPTOR>::getBlockLattice()
{
  return _blockLattice;
}


template <typename T, typename DESCRIPTOR>
BlockLatticePhysF2D<T,DESCRIPTOR>::BlockLatticePhysF2D
(BlockLatticeStructure2D<T,DESCRIPTOR>& blockLattice, const UnitConverter<T,DESCRIPTOR>& converter, int targetDim)
  : BlockLatticeF2D<T,DESCRIPTOR>(blockLattice, targetDim), _converter(converter)
{ }

template <typename T, typename DESCRIPTOR, typename TDESCRIPTOR>
BlockLatticeThermalPhysF2D<T,DESCRIPTOR,TDESCRIPTOR>::BlockLatticeThermalPhysF2D
(BlockLatticeStructure2D<T,TDESCRIPTOR>& blockLattice, const ThermalUnitConverter<T,DESCRIPTOR,TDESCRIPTOR>& converter, int targetDim)
  : BlockLatticeF2D<T,TDESCRIPTOR>(blockLattice, targetDim), _converter(converter)
{ }

} // end namespace olb

#endif