OpenLB 1.7
Loading...
Searching...
No Matches
blockData.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2015 Mathias J. Krause
4 * 2021 Adrian Kummerlaender
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
25#ifndef BLOCK_DATA_HH
26#define BLOCK_DATA_HH
27
28#include "blockData.h"
29
30#include "geometry/cuboid2D.h"
31#include "geometry/cuboid3D.h"
32
35
37
38namespace olb {
39
40template<unsigned D, typename T, typename U>
41BlockData<D,T,U>::BlockData(Cuboid<T,D>& cuboid, int overlap, int size):
42 BlockStructureD<D>(cuboid.getExtent(), overlap),
43 _size(size),
44 _communicatable(_data)
45{
46 for (unsigned iD=0; iD < _size; ++iD) {
47 _data.emplace_back(this->getNcells());
48 }
49}
50
51template<unsigned D, typename T, typename U>
53 BlockStructureD<D>(block),
54 _size(size),
55 _communicatable(_data)
56{
57 for (unsigned iD=0; iD < _size; ++iD) {
58 _data.emplace_back(this->getNcells());
59 }
60}
62template<unsigned D, typename T, typename U>
64 BlockStructureD<D>(blockF.getBlockStructure()),
65 _size(blockF.getTargetDim())
66{
67 for (unsigned iD=0; iD < _size; ++iD) {
68 _data.emplace_back(this->getNcells());
69 }
70 int input[D];
71 U output[_size];
72 this->forCoreSpatialLocations([&](LatticeR<D> latticeR) {
73 for (unsigned iD=0; iD < D; ++iD) {
74 input[iD] = latticeR[iD];
75 }
76 blockF(output, input);
77 for (unsigned iD=0; iD < _size; ++iD) {
78 get(latticeR,iD) = output[iD];
79 }
80 });
81}
83template<unsigned D, typename T, typename U>
84bool BlockData<D,T,U>::operator()(T output[], const int input[])
85{
86 const std::size_t iCell = this->getCellId(input);
87 for (unsigned iD=0; iD < _size; ++iD) {
88 output[iD] = _data[iD][iCell];
89 }
90 return true;
91}
92
93template<unsigned D, typename T, typename U>
94U& BlockData<D,T,U>::get(std::size_t iCell, int iD)
95{
96 return _data[iD][iCell];
97}
98
99template<unsigned D, typename T, typename U>
101{
102 return get(this->getCellId(latticeR), iD);
103}
104
105template<unsigned D, typename T, typename U>
106U BlockData<D,T,U>::get(LatticeR<D> latticeR, int iD) const
107{
108 return _data[iD][this->getCellId(latticeR)];
109}
110
111template<unsigned D, typename T, typename U>
113{
114 return _data[iD];
115}
116
117template<unsigned D, typename T, typename U>
119{
120 return _size;
121}
122
123template<unsigned D, typename T, typename U>
125{
126 return _data.size() * _data[0].getNblock();
127}
128
129template<unsigned D, typename T, typename U>
131{
132 return _data.size() * _data[0].getSerializableSize();
133}
134
135template<unsigned D, typename T, typename U>
136bool* BlockData<D,T,U>::getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode)
137{
138 std::size_t currentBlock = 0;
139 bool* dataPtr = nullptr;
140
141 for (unsigned iD=0; iD < _size; ++iD) {
142 registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, _data[iD], loadingMode);
143 }
144
145 return dataPtr;
146}
147
148namespace singleton {
149
150#ifdef PARALLEL_MODE_MPI
151
152void MpiManager::bCast(BlockData<2,double,double>& sendData, int root, MPI_Comm comm)
153{
154 if (!ok) {
155 return;
156 }
157 for (unsigned iD=0; iD < sendData.getSize(); ++iD) {
158 MPI_Bcast(static_cast<void*>(sendData.getColumn(iD).data()),
159 sendData.getNcells(), MPI_DOUBLE, root, comm);
160 }
161}
162
163void MpiManager::bCast(BlockData<2,float,float>& sendData, int root, MPI_Comm comm)
164{
165 if (!ok) {
166 return;
167 }
168 for (unsigned iD=0; iD < sendData.getSize(); ++iD) {
169 MPI_Bcast(static_cast<void*>(sendData.getColumn(iD).data()),
170 sendData.getNcells(), MPI_FLOAT, root, comm);
171 }
172}
173
174template <>
175void MpiManager::reduce<BlockData<2,double,int> >(BlockData<2,double,int>& sendVal, BlockData<2,double,int>& recvVal, MPI_Op op, int root, MPI_Comm comm)
176{
177 if (!ok) {
178 return;
179 }
180 for (unsigned iD=0; iD < sendVal.getSize(); ++iD) {
181 MPI_Reduce(static_cast<void*>(sendVal.getColumn(iD).data()),
182 static_cast<void*>(recvVal.getColumn(iD).data()),
183 sendVal.getNcells(), MPI_DOUBLE, op, root, comm);
184 }
185}
186
187template <>
188void MpiManager::reduce<BlockData<2,double,double> >(BlockData<2,double,double>& sendVal, BlockData<2,double,double>& recvVal, MPI_Op op, int root, MPI_Comm comm)
189{
190 if (!ok) {
191 return;
192 }
193 for (unsigned iD=0; iD < sendVal.getSize(); ++iD) {
194 MPI_Reduce(static_cast<void*>(sendVal.getColumn(iD).data()),
195 static_cast<void*>(recvVal.getColumn(iD).data()),
196 sendVal.getNcells(), MPI_DOUBLE, op, root, comm);
197 }
198}
199
200template <>
201void MpiManager::reduce<BlockData<2,float,float> >(BlockData<2,float,float>& sendVal, BlockData<2,float,float>& recvVal, MPI_Op op, int root, MPI_Comm comm)
202{
203 if (!ok) {
204 return;
205 }
206 for (unsigned iD=0; iD < sendVal.getSize(); ++iD) {
207 MPI_Reduce(static_cast<void*>(sendVal.getColumn(iD).data()),
208 static_cast<void*>(recvVal.getColumn(iD).data()),
209 sendVal.getNcells(), MPI_FLOAT, op, root, comm);
210 }
211}
212
213#endif
214
215}
216
217}
218
219#endif
bool operator()(T output[], const int input[])
Definition blockData.hh:84
unsigned getSize() const
Definition blockData.hh:118
bool * getBlock(std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
Returns the address of the i-th block and its size.
Definition blockData.hh:136
std::size_t getSerializableSize() const override
Returns the binary size of the data to be saved.
Definition blockData.hh:130
Column< U > & getColumn(unsigned iD)
Definition blockData.hh:112
std::size_t getNblock() const override
Returns the number of blocks.
Definition blockData.hh:124
std::vector< cpu::sisd::Column< U > > _data
Definition blockData.h:45
const unsigned _size
Definition blockData.h:44
BlockData(Cuboid< T, D > &cuboid, int overlap=0, int size=1)
Definition blockData.hh:41
U & get(std::size_t iCell, int iD=0)
Definition blockData.hh:94
Base of a regular block.
std::size_t getNcells() const
Get number of cells.
Plain old scalar vector.
Definition vector.h:47
Plain column for SISD CPU targets (default)
Definition column.h:45
const T * data() const
Definition column.h:101
std::size_t size() const
Definition column.h:96
void bCast(T *sendBuf, int sendCount, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Broadcast data from one processor to multiple processors.
The description of a single 2D cuboid – header file.
The description of a single 3D cuboid – header file.
Wrapper functions that simplify the use of MPI.
Top level namespace for all of OpenLB.
std::conditional_t< D==2, BlockF2D< T >, BlockF3D< T > > BlockF
Definition aliases.h:188
std::conditional_t< D==2, Cuboid2D< T >, Cuboid3D< T > > Cuboid
Definition aliases.h:37