summaryrefslogtreecommitdiff
path: root/src/core/superLattice3D.h
blob: b6a36d5fbc9a5ef53f115a47e1f5a246745196e2 (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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*  This file is part of the OpenLB library
 *
 *  Copyright (C) 2007 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.
 */

/** \file
 * The description of a 3D super lattice -- header file.
 */

#ifndef SUPER_LATTICE_3D_H
#define SUPER_LATTICE_3D_H

#include <vector>

#include "blockLattice3D.h"
#include "blockLatticeView3D.h"
#include "superData3D.h"
#include "communication/communicator3D.h"
#include "postProcessing.h"
#include "serializer.h"
#include "communication/superStructure3D.h"
#include "utilities/functorPtr.h"

/// All OpenLB code is contained in this namespace.
namespace olb {

template<typename T, typename DESCRIPTOR> class SuperLatticeF3D;
template<typename T, typename S> class AnalyticalF3D;
template<typename T> class SuperGeometry3D;
template<typename T> class SuperIndicatorF3D;
template<typename T> class LoadBalancer;
template<typename T> class CuboidGeometry3D;
template <typename T> class IndicatorSphere3D;
template<typename T> class Communicator3D;
template<typename T, typename DESCRIPTOR> class BlockLatticeView3D;


/// A super lattice combines a number of block lattices that are ordered
/// in a cuboid geometry.
/** The communication between the block lattices is done by two
 * communicators. One (_commStream) is responsible to provide the data for
 * the streaming the other (_commBC) for the non-local boundary conditions.
 * To simplify the code structure ghost cells in an overlap of size
 * (_overlap) is introduced. It depends on the non-locality of the
 * boundary conditions but is at least one because of the streaming
 *
 * The algorithm is parallelized with mpi. The load balancer (_loadBalancer)
 * distributes the block lattices to processes.
 *
 * WARNING: For unstructured grids there is an interpolation needed
 * for the method buffer_outData in cuboidNeighbourhood which is not
 * yet implemented! Moreover this class needs to be changed so
 * that the number of times steps for the collision and streaming is
 * is dependent of the refinement level.
 *
 * This class is not intended to be derived from.
 */
template<typename T, typename DESCRIPTOR>
class SuperLattice3D : public SuperStructure3D<T>, public BufferSerializable {

private:
  /// Lattices with ghost cell layer of size overlap
  std::vector<BlockLattice3D<T, DESCRIPTOR> > _extendedBlockLattices;
  /// View of the lattices without overlap
  std::vector<BlockLatticeView3D<T, DESCRIPTOR> > _blockLattices;

  /// This communicator handles the communication for the streaming
  Communicator3D<T> _commStream;
  /// This communicator handles the communication for the postprocessors
  Communicator3D<T> _commBC;
  /// Specifies if there is communication for non local boundary conditions
  /// needed. It is automatically switched on if overlapBC >= 1 by
  /// calling the constructor. (default =false)
  bool _commBC_on;
  /// Statistic of the super structure
  LatticeStatistics<T> *_statistics;
  /// Specifies if there is statistic calculated. It is always
  /// needed for the ConstRhoBGK dynamics. (default =true)
  bool _statistics_on;

public:
  /// Construction of a super lattice
  SuperLattice3D(SuperGeometry3D<T>& superGeometry);
  SuperLattice3D(const SuperLattice3D&) = delete;
  ~SuperLattice3D() override;
  /// Read and write access to a block lattice
  BlockLattice3D<T, DESCRIPTOR>& getExtendedBlockLattice(int locIC)
  {
    return _extendedBlockLattices[locIC];
  }
  ;
  /// Read only access to a block lattice
  BlockLattice3D<T, DESCRIPTOR> const& getExtendedBlockLattice(int locIC) const
  {
    return _extendedBlockLattices[locIC];
  }
  ;
  /// Read and write access to a lattice (block lattice view, one
  /// without overlap).
  BlockLatticeView3D<T, DESCRIPTOR>& getBlockLattice(int locIC)
  {
    return _blockLattices[locIC];
  }
  ;
  /// Read only access to a lattice
  BlockLatticeView3D<T, DESCRIPTOR> const& getBlockLattice(int locIC) const
  {
    return _blockLattices[locIC];
  }
  ;

  /// Read and write access to the boundary communicator
  Communicator3D<T>& get_commBC()
  {
    return _commBC;
  }
  ;
  /// Read only access to the boundary communicator
  Communicator3D<T> const& get_commBC() const
  {
    return _commBC;
  }
  ;

  /// Return a handle to the LatticeStatistics object
  LatticeStatistics<T>& getStatistics();
  /// Return a constant handle to the LatticeStatistics object
  LatticeStatistics<T> const& getStatistics() const;

  /// Write access to lattice cells that returns false if
  /// (iX/iY/iZ) is not in any of the cuboids
  bool set(T iX, T iY, T iZ, Cell<T, DESCRIPTOR> const& cell);
  /// Read only access to lattice cells that returns false if
  /// (iX/iY/iZ) is not in any of the cuboids
  bool get(T iX, T iY, T iZ, Cell<T, DESCRIPTOR>& cell) const;
  /// Read only access to lattice cells over the cuboid number
  /// and local coordinates   WARNING!!! NO ERROR HANDLING IMPLEMENTED!!!
  Cell<T,DESCRIPTOR> get(int iC, int locX, int locY, int locZ) const;
  Cell<T,DESCRIPTOR> get(std::vector<int> latticeR) const;

  /// Write access to the memory of the data of the super structure
  bool* operator() (int iCloc, int iX, int iY, int iZ, int iData) override
  {
    return (bool*)&getExtendedBlockLattice(iCloc).get(iX+this->_overlap, iY+this->_overlap, iZ+this->_overlap)[iData];
  };
  /// Read only access to the dim of the data of the super structure
  int getDataSize() const override
  {
    return DESCRIPTOR::q;
  };
  /// Read only access to the data type dim of the data of the super structure
  int getDataTypeSize() const override
  {
    return sizeof(T);
  };

  /// Initialize all lattice cells to become ready for simulation
  void initialize();

  /// Define the dynamics on a domain described by an indicator
  void defineDynamics(FunctorPtr<SuperIndicatorF3D<T>>&& indicator, Dynamics<T, DESCRIPTOR>* dynamics);
  /// Define the dynamics on a domain with a particular material number
  void defineDynamics(SuperGeometry3D<T>& sGeometry, int material,
                      Dynamics<T, DESCRIPTOR>* dynamics);

  /// Define rho on a domain described by an indicator
  /**
   * \param indicator Indicator describing the target domain
   * \param rho       Analytical functor
   **/
  void defineRho(FunctorPtr<SuperIndicatorF3D<T>>&&, AnalyticalF3D<T,T>& rho);
  /// Define rho on a domain with a particular material number
  void defineRho(SuperGeometry3D<T>& sGeometry, int material, AnalyticalF3D<T,T>& rho);

  /// Define u on a domain described by an indicator
  /**
   * \param indicator Indicator describing the target domain
   * \param u         Analytical functor
   **/
  void defineU(FunctorPtr<SuperIndicatorF3D<T>>&& indicator, AnalyticalF3D<T,T>& u);
  /// Define u on a domain with a particular material number
  void defineU(SuperGeometry3D<T>& sGeometry, int material, AnalyticalF3D<T,T>& u);

  /// Define rho and u on a domain described by an indicator
  /**
   * \param indicator Indicator describing the target domain
   * \param rho       Analytical functor
   * \param u         Analytical functor
   **/
  void defineRhoU(FunctorPtr<SuperIndicatorF3D<T>>&& indicator,
                  AnalyticalF3D<T,T>& rho, AnalyticalF3D<T,T>& u);
  /// Define rho and u on a domain with a particular material number
  void defineRhoU(SuperGeometry3D<T>& sGeometry, int material,
                  AnalyticalF3D<T,T>& rho, AnalyticalF3D<T,T>& u);

  /// Define a population on a domain described by an indicator
  /**
   * \param indicator Indicator describing the target domain
   * \param Pop       Analytical functor, target dimension DESCRIPTOR::q
   **/
  void definePopulations(FunctorPtr<SuperIndicatorF3D<T>>&& indicator,
                         AnalyticalF3D<T,T>& Pop);
  /// Define a population on a domain with a particular material number
  void definePopulations(SuperGeometry3D<T>& sGeometry, int material,
                         AnalyticalF3D<T,T>& Pop);
  /**
   * \param indicator Indicator describing the target domain
   * \param Pop       Super functor, target dimension DESCRIPTOR::q
   **/
  void definePopulations(FunctorPtr<SuperIndicatorF3D<T>>&& indicator,
                         SuperF3D<T,T>& Pop);
  /// Define a population on a domain with a particular material number
  void definePopulations(SuperGeometry3D<T>& sGeometry, int material,
                         SuperF3D<T,T>& Pop);

  /// Define an external field on a domain with a particular material number
  template <typename FIELD>
  void defineField(SuperGeometry3D<T>& sGeometry, int material,
                   SuperF3D<T,T>& field);

  /// Defines a field on a domain described by an indicator
  template <typename FIELD>
  void defineField(FunctorPtr<SuperIndicatorF3D<T>>&& indicator,
                   AnalyticalF3D<T,T>& field)
  {
    for (int iC = 0; iC < this->_loadBalancer.size(); ++iC) {
      _extendedBlockLattices[iC].template defineField<FIELD>(
        indicator->getExtendedBlockIndicatorF(iC), field);
    }
  }
  /// Defines a field on a domain with a particular material number
  template <typename FIELD>
  void defineField(SuperGeometry3D<T>& sGeometry, int material,
                   AnalyticalF3D<T,T>& field)

  {
    defineField<FIELD>(sGeometry.getMaterialIndicator(material), field);
  }
  /// Defines a field on a indicated domain
  template <typename FIELD>
  void defineField(SuperGeometry3D<T>& sGeometry, IndicatorF3D<T>& indicator,
                   AnalyticalF3D<T,T>& field);

  /// Initialize by equilibrium on a domain described by an indicator
  /**
   * \param indicator Indicator describing the target domain
   * \param rho       Analytical functor (global)
   * \param u         Analytical functor (global)
   **/
  void iniEquilibrium(FunctorPtr<SuperIndicatorF3D<T>>&& indicator,
                      AnalyticalF3D<T,T>& rho, AnalyticalF3D<T,