Saras
Finite   Difference   Solver   for   Fluid   Dynamics   Simulations
grid.h
Go to the documentation of this file.
1/********************************************************************************************************************************************
2 * Saras
3 *
4 * Copyright (C) 2019, Mahendra K. Verma
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 ********************************************************************************************************************************************
31 */
43#ifndef GRID_H
44#define GRID_H
45
46#include <math.h>
47#include <string>
48#include <vector>
49#include <blitz/array.h>
50
51#include "parallel.h"
52
53class grid {
54 private:
56 blitz::TinyVector<real, 3> thBeta;
57
59 blitz::Array<real, 1> xi;
61 blitz::Array<real, 1> et;
63 blitz::Array<real, 1> zt;
64
66 blitz::Array<real, 1> xiGlo;
68 blitz::Array<real, 1> etGlo;
70 blitz::Array<real, 1> ztGlo;
71
72 void resizeGrid();
73 void makeSizeArray();
74 void setDomainSizes();
75 void globalXiEtaZeta();
76
77 void createUniformGrid();
78 void createTanHypGrid(int dim);
79
80 void checkAnisotropy();
81 void gatherGlobal();
82
83 void computeGlobalLimits();
84
85 public:
88
91
93 blitz::TinyVector<int, 3> collocCoreSize;
94
96 blitz::TinyVector<int, 3> collocFullSize;
97
99 blitz::TinyVector<int, 3> staggrCoreSize;
100
102 blitz::TinyVector<int, 3> staggrFullSize;
103
105 blitz::TinyVector<int, 3> padWidths;
106
108 blitz::TinyVector<int, 3> globalSize;
109
111 blitz::TinyVector<int, 3> subarrayEnds;
112
114 blitz::TinyVector<int, 3> subarrayStarts;
115
117 real dXi;
118
120 real dEt;
121
123 real dZt;
124
126 real xLen;
127
129 real yLen;
130
132 real zLen;
133
135 blitz::Array<int, 1> sizeArray;
136
138 blitz::TinyVector<int, 3> sizeIndex;
139
141 blitz::RectDomain<3> collocCoreDomain;
142
144 blitz::RectDomain<3> collocFullDomain;
145
147 blitz::RectDomain<3> staggrCoreDomain;
148
150 blitz::RectDomain<3> staggrFullDomain;
151
152 /*****************************************************************************************************************************************************/
153
155 blitz::Array<real, 1> xColloc;
156
158 blitz::Array<real, 1> yColloc;
159
161 blitz::Array<real, 1> zColloc;
162
164 blitz::Array<real, 1> xStaggr;
165
167 blitz::Array<real, 1> yStaggr;
168
170 blitz::Array<real, 1> zStaggr;
171
172 /*****************************************************************************************************************************************************/
173
175 blitz::Array<real, 1> xCollocGlobal;
176
178 blitz::Array<real, 1> yCollocGlobal;
179
181 blitz::Array<real, 1> zCollocGlobal;
182
184 blitz::Array<real, 1> xStaggrGlobal;
185
187 blitz::Array<real, 1> yStaggrGlobal;
188
190 blitz::Array<real, 1> zStaggrGlobal;
191
192 /*****************************************************************************************************************************************************/
193
195 blitz::Array<real, 1> xi_xColloc;
196
198 blitz::Array<real, 1> xi_xStaggr;
199
201 blitz::Array<real, 1> xixxColloc;
202
204 blitz::Array<real, 1> xixxStaggr;
205
207 blitz::Array<real, 1> xix2Colloc;
208
210 blitz::Array<real, 1> xix2Staggr;
211
212 /*****************************************************************************************************************************************************/
213
215 blitz::Array<real, 1> et_yColloc;
216
218 blitz::Array<real, 1> et_yStaggr;
219
221 blitz::Array<real, 1> etyyColloc;
222
224 blitz::Array<real, 1> etyyStaggr;
225
227 blitz::Array<real, 1> ety2Colloc;
228
230 blitz::Array<real, 1> ety2Staggr;
231
232 /*****************************************************************************************************************************************************/
233
235 blitz::Array<real, 1> zt_zColloc;
236
238 blitz::Array<real, 1> zt_zStaggr;
239
241 blitz::Array<real, 1> ztzzColloc;
242
244 blitz::Array<real, 1> ztzzStaggr;
245
247 blitz::Array<real, 1> ztz2Colloc;
248
250 blitz::Array<real, 1> ztz2Staggr;
251
252 grid(const parser &solParam, parallel &parallelData);
253
266 inline bool pointInDomain(blitz::TinyVector<int, 3> gloIndex) const {
267 if ((gloIndex(0) < subarrayEnds(0)) and (gloIndex(0) >= subarrayStarts(0)) and (gloIndex(1) < subarrayEnds(1)) and (gloIndex(1) >= subarrayStarts(1))) return true;
268
269 return false;
270 };
271
284 inline blitz::TinyVector<int, 3> glo2loc(blitz::TinyVector<int, 3> gloIndex) const {
285 blitz::TinyVector<int, 3> locIndex;
286
287 if (pointInDomain(gloIndex)) {
288 locIndex(0) = gloIndex(0) % collocCoreSize(0);
289 locIndex(1) = gloIndex(1) % collocCoreSize(1);
290 locIndex(2) = gloIndex(2);
291 } else {
292 locIndex = 0, 0, 0;
293 }
294
295 return locIndex;
296 };
297
310 inline blitz::TinyVector<int, 3> loc2glo(blitz::TinyVector<int, 3> locIndex) const {
311 blitz::TinyVector<int, 3> gloIndex;
312
313 gloIndex(0) = rankData.xRank*collocCoreSize(0) + locIndex(0);
314 gloIndex(1) = rankData.yRank*collocCoreSize(1) + locIndex(1);
315 gloIndex(2) = locIndex(2);
316
317 return gloIndex;
318 };
319};
320
329#endif
Contains all the global variables related to the grid, its slices, limits, and grid derivatives used ...
Definition: grid.h:53
blitz::Array< real, 1 > etyyColloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:221
blitz::Array< real, 1 > xixxColloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:201
blitz::RectDomain< 3 > staggrFullDomain
RectDomain object that defines the slice for the full extent of the local MPI decomposed sub-domain (...
Definition: grid.h:150
blitz::TinyVector< int, 3 > subarrayEnds
The end indices of the MPI decomposed sub-domains within the global indexing of the full staggered gr...
Definition: grid.h:111
const parser & inputParams
A const reference to the global variables stored in the parser class to access user set parameters.
Definition: grid.h:87
real xLen
Length of the physical computational domain along the x direction.
Definition: grid.h:126
blitz::Array< real, 1 > xColloc
Collocated grid along the x-direction defined locally within MPI decomposed sub-domains.
Definition: grid.h:155
grid(const parser &solParam, parallel &parallelData)
Constructor of the grid class.
Definition: grid.cc:59
blitz::TinyVector< int, 3 > loc2glo(blitz::TinyVector< int, 3 > locIndex) const
Function to obtain global indices from local indices.
Definition: grid.h:310
blitz::Array< real, 1 > xi_xColloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:195
blitz::Array< real, 1 > xCollocGlobal
Collocated grid along the x-direction for the full global domain.
Definition: grid.h:175
blitz::Array< real, 1 > zStaggrGlobal
Staggered grid along the z-direction for the full global domain.
Definition: grid.h:190
blitz::Array< real, 1 > yCollocGlobal
Collocated grid along the y-direction for the full global domain.
Definition: grid.h:178
blitz::TinyVector< int, 3 > collocCoreSize
The sizes of the core of MPI decomposed sub-domains without the pads (collocated points) - localNx,...
Definition: grid.h:93
blitz::Array< real, 1 > et_yColloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:215
blitz::Array< real, 1 > xStaggrGlobal
Staggered grid along the x-direction for the full global domain.
Definition: grid.h:184
blitz::Array< real, 1 > ety2Staggr
Array of the grid derivatives at staggered grid points, defined locally within each sub-domain.
Definition: grid.h:230
blitz::Array< real, 1 > ztzzColloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:241
const parallel & rankData
A const reference to the global variables stored in the parallel class to access MPI related paramete...
Definition: grid.h:90
blitz::Array< real, 1 > zStaggr
Staggered grid along the z-direction defined locally within MPI decomposed sub-domains.
Definition: grid.h:170
blitz::TinyVector< int, 3 > padWidths
The sizes of the pad widths along the three directions - padX, padY, padZ.
Definition: grid.h:105
real dEt
Grid spacing in the transformed plane along the direction.
Definition: grid.h:120
blitz::Array< int, 1 > sizeArray
Array of collocated grid sizes such that the corresponding staggered grid will be multi-grid compatib...
Definition: grid.h:135
blitz::Array< real, 1 > xStaggr
Staggered grid along the x-direction defined locally within MPI decomposed sub-domains.
Definition: grid.h:164
blitz::Array< real, 1 > zColloc
Collocated grid along the z-direction defined locally within MPI decomposed sub-domains.
Definition: grid.h:161
blitz::Array< real, 1 > zt_zStaggr
Array of the grid derivatives at staggered grid points, defined locally within each sub-domain.
Definition: grid.h:238
blitz::TinyVector< int, 3 > collocFullSize
The sizes of the MPI decomposed sub-domains including the pads on all sides (collocated points) - col...
Definition: grid.h:96
blitz::RectDomain< 3 > collocFullDomain
RectDomain object that defines the slice for the full extent of the local MPI decomposed sub-domain (...
Definition: grid.h:144
blitz::Array< real, 1 > xi_xStaggr
Array of the grid derivatives at staggered grid points, defined locally within each sub-domain.
Definition: grid.h:198
blitz::Array< real, 1 > ztz2Colloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:247
blitz::TinyVector< int, 3 > staggrCoreSize
The sizes of the core of MPI decomposed sub-domains without the pads (staggered points)
Definition: grid.h:99
blitz::TinyVector< int, 3 > staggrFullSize
The sizes of the MPI decomposed sub-domains including the pads on all sides (staggered points) - stag...
Definition: grid.h:102
blitz::Array< real, 1 > ety2Colloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:227
blitz::Array< real, 1 > ztz2Staggr
Array of the grid derivatives at staggered grid points, defined locally within each sub-domain.
Definition: grid.h:250
real dXi
Grid spacing in the transformed plane along the direction.
Definition: grid.h:117
real zLen
Length of the physical computational domain along the z direction.
Definition: grid.h:132
blitz::Array< real, 1 > xix2Staggr
Array of the grid derivatives at staggered grid points, defined locally within each sub-domain.
Definition: grid.h:210
real dZt
Grid spacing in the transformed plane along the direction.
Definition: grid.h:123
blitz::TinyVector< int, 3 > globalSize
The size of the entire computational domain excluding the pads at the boundary of full domain - globa...
Definition: grid.h:108
blitz::Array< real, 1 > et_yStaggr
Array of the grid derivatives at staggered grid points, defined locally within each sub-domain.
Definition: grid.h:218
blitz::Array< real, 1 > ztzzStaggr
Array of the grid derivatives at staggered grid points, defined locally within each sub-domain.
Definition: grid.h:244
blitz::Array< real, 1 > yStaggrGlobal
Staggered grid along the y-direction for the full global domain.
Definition: grid.h:187
blitz::RectDomain< 3 > staggrCoreDomain
RectDomain object that defines the slice for the core of the local MPI decomposed sub-domain (stagger...
Definition: grid.h:147
blitz::RectDomain< 3 > collocCoreDomain
RectDomain object that defines the slice for the core of the local MPI decomposed sub-domain (colloca...
Definition: grid.h:141
blitz::Array< real, 1 > yStaggr
Staggered grid along the y-direction defined locally within MPI decomposed sub-domains.
Definition: grid.h:167
blitz::TinyVector< int, 3 > subarrayStarts
The start indices of the MPI decomposed sub-domains within the global indexing of the full staggered ...
Definition: grid.h:114
blitz::Array< real, 1 > xix2Colloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:207
blitz::TinyVector< int, 3 > glo2loc(blitz::TinyVector< int, 3 > gloIndex) const
Function to obtain local indices from global indices.
Definition: grid.h:284
real yLen
Length of the physical computational domain along the y direction.
Definition: grid.h:129
bool pointInDomain(blitz::TinyVector< int, 3 > gloIndex) const
Function to check if a given set of global indices lie within a rank.
Definition: grid.h:266
blitz::Array< real, 1 > xixxStaggr
Array of the grid derivatives at staggered grid points, defined locally within each sub-domain.
Definition: grid.h:204
blitz::Array< real, 1 > yColloc
Collocated grid along the y-direction defined locally within MPI decomposed sub-domains.
Definition: grid.h:158
blitz::TinyVector< int, 3 > sizeIndex
Vector of indices pointing to the sizeArray that determines the global full domain size along the 3 d...
Definition: grid.h:138
blitz::Array< real, 1 > zCollocGlobal
Collocated grid along the z-direction for the full global domain.
Definition: grid.h:181
blitz::Array< real, 1 > etyyStaggr
Array of the grid derivatives at staggered grid points, defined locally within each sub-domain.
Definition: grid.h:224
blitz::Array< real, 1 > zt_zColloc
Array of the grid derivatives at collocated grid points, defined locally within each sub-domain.
Definition: grid.h:235
Class for all the global variables and functions related to parallelization.
Definition: parallel.h:51
int xRank
xRank and yRank indicates the rank in terms of sub-domain divisions along the X and Y directions resp...
Definition: parallel.h:78
Contains all the global variables set by the user through the yaml file.
Definition: parser.h:63
Class declaration of parallel.