summaryrefslogtreecommitdiff
path: root/src/communication/cuboidNeighbourhood3D.h
blob: 639102c60c5c8ed92ca91caa0e0ca7ca9de8c087 (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
/*  This file is part of the OpenLB library
 *
 *  Copyright (C) 2007, 2014 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 cuboid neighbourhood -- header file.
 */


#ifndef CUBOID_NEIGHBOURHOOD_3D_H
#define CUBOID_NEIGHBOURHOOD_3D_H

#include "communication/mpiManager.h"
#include <vector>
#include "communication/superStructure3D.h"


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

template<typename T> class SuperStructure3D;


/// Single 3D cuboid neighbourhoods are the basic component of a
/// 3D communicator
/** For each cuboid a cuboid neighbourhood is defined. It stores the
 * needed cell coordinates (Cell3D) of other cuboids. Futhermore this
 * class provides basic initialization and communication methods
 * for the class Communicator3D.
 *
 * WARNING: For unstructured grids there is an interpolation needed
 * for the method buffer_outData which is not yet implemented!
 *
 * This class is not intended to be derived from.
 */
template<typename T>
struct Cell3D {
  Cell3D() : latticeR {0,0,0,0} {};
  // local position latticeR: iC, iX, iY, iZ;
  int latticeR[4];
  // global position physR: x, y, z;
  T physR[3];

  bool operator==(Cell3D const& rhs) const
  {
      return latticeR == rhs.latticeR;
  };

  /// Copy constructor
  Cell3D(Cell3D const& rhs) = default;

  /// Copy assignment
  Cell3D& operator=(Cell3D const& rhs) = default;

};


template<typename T>
class CuboidNeighbourhood3D {
private:
  /// Cuboid ID
  int _iCglob;
  /// Number of cubboids in the structure
  int _nC;
  /// Delta of the cuboid
  T _deltaC;
  /// Reference to the super structure
  SuperStructure3D<T>& _superStructure;

  /// Number of data to be transfered
  int _nData;
  /// Size of underlying data type
  int _nDataType;

  /// Internal needed cells
  std::vector<Cell3D<T> > _inCells;
  /// External  needed cells
  std::vector<Cell3D<T> > _outCells;
  /// Internal needed neighbour cuboid and number of cells
  std::vector<int> _inC;
  std::vector<int> _inN;
  /// External needed neighbour cuboid and number of cells
  std::vector<int> _outC;
  std::vector<int> _outN;
  /// Buffer for the internal needed data
  bool **_inData;
  /// Buffer for the external needed data
  bool **_outData;
  /// Buffer for the internal needed data
  T **_inDataCoordinates;
  /// Buffer for the external needed data
  T **_outDataCoordinates;
  /// Indecates if there was an initialization done
  bool _initInCNdone;
  int* _tempInCN;
  /// Indecates if there was an initialization done
  bool _initOutCNdone;
  /// Handels the MPI communication
#ifdef PARALLEL_MODE_MPI
  singleton::MpiNonBlockingHelper _mpiNbHelper;
#endif
public:
  /// Constructor
  //CuboidNeighbourhood2D() {};
  /// Constructor
  CuboidNeighbourhood3D(SuperStructure3D<T>& superStructure, int iC);
  /// Copy construction
  CuboidNeighbourhood3D(CuboidNeighbourhood3D<T> const& rhs);
  /// Copy assignment
  CuboidNeighbourhood3D operator=(CuboidNeighbourhood3D<T> rhs);
  /// Destructor
  ~CuboidNeighbourhood3D();

  /// Read only access to _inCells
  Cell3D<T> const& get_inCell(int i) const;
  /// Returns the number of cells in _inCells
  int get_inCellsSize() const;
  /// Read only access to _inC
  int const& get_inC(int i) const;
  /// Returns the number of cells in _inC
  int get_inCsize() const;
  /// Read and write access to **_inData
  bool** get_inData();
  /// Read and write access to **_outData
  bool** get_outData();

  /// Adds a cell to the vector _inCells
  void add_inCell(Cell3D<T> cell);
  /// Adds a cell to the vector _outCells
  void add_outCell(Cell3D<T> cell);
  /// Adds a cell to the vector _inCells
  ///  if the cell is not already there and
  ///  if there is another cuboid which can deliver the information
  void add_inCell(int iX, int iY, int iZ);
  /// Adds all cells with the distance overlap*_delta to
  /// the vector _inCells
  void add_inCells(int overlap);
  /// Initializes _inC and _inN
  void init_inCN();
  /// Initializes _outC and _outN
  void init_outCN();
  /// Initialization Helper
#ifdef PARALLEL_MODE_MPI
  void bufSend_inCells(singleton::MpiNonBlockingHelper& helper);
#else
  void bufSend_inCells() {}
#endif
  /// Initialization Helper
  void recWrite_outCells();
  /// Finishes a communication step
  void finish_comm();

  /// Buffers data to be send
  // WARNING: Here is interpolation needed if globX, globY
  // are not integers. This needs to be fixed if one will
  // use unstructured grids.
  void buffer_outData();
  /// Sends data (pure mpi method)
  void send_outData();
  /// Receives data (pure mpi method)
  void receive_inData();
  /// Writes all data to the corresponding lattice cells
  void write_inData();
  /// Resets neighbourhood after initialization (init_inCN
  /// and init_outCN)
  void reset();
};

}  // namespace olb

#endif