OpenLB 1.7
Loading...
Searching...
No Matches
blockStructure2D.h
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 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
27#ifndef BLOCK_STRUCTURE_2D_H
28#define BLOCK_STRUCTURE_2D_H
29
30#include <cstdint>
31#include <array>
32
33#include "core/olbDebug.h"
34#include "core/vector.h"
35
36namespace olb {
37
45 static int foo_x = 0;
46 static int foo_y = 0;
48protected:
50 int _nx;
52 int _ny;
53public:
54 BlockStructure2D(int nx, int ny) : _nx(nx), _ny(ny) {};
55 BlockStructure2D(int nx, int ny, int overlap):
56 _nx(nx+2*overlap), _ny(ny+2*overlap) { };
59 int getNx() const
60 {
61 return _nx;
62 };
64 int getNy() const
65 {
66 return _ny;
67 };
69 std::size_t getNcells() const
70 {
71 // The conversions to std::size_t ensure 64-bit compatibility. Note that
72 // Nx and Ny are of type int, which might be 32-bit types, even on
73 // 64-bit platforms. Therefore, Nx*Ny may lead to a type overflow.
74 return static_cast<std::size_t>(getNx())
75 * static_cast<std::size_t>(getNy());
76 }
77
79 std::size_t getCellId(int iX, int iY) const
80 {
81
82
83 if(!(iX >= 0 && iX < this->_nx && iY >= 0 && iY < this->_ny)){
84 throw std::runtime_error{"Bad access at: " + std::to_string(iX) + " " + std::to_string(iY) + " " + std::to_string(foo_x) + " " + std::to_string(foo_y) + " "+ std::to_string(_nx) + " " + std::to_string(_ny)};
85
86 }
87
88 foo_x = iX;
89 foo_y = iY;
90
91 OLB_PRECONDITION(iX >= 0 && iX < this->_nx);
92 OLB_PRECONDITION(iY >= 0 && iY < this->_ny);
93 return iX*_ny + iY;
94 }
96 std::ptrdiff_t getNeighborDistance(int iX, int iY) const
97 {
98 return iX*_ny + iY;
99 }
101 std::ptrdiff_t getNeighborDistance(Vector<int,2> c) const
102 {
103 return getNeighborDistance(c[0], c[1]);
104 }
106 bool isInside(int iX, int iY) const
107 {
108 return 0 <= iX && iX < getNx() &&
109 0 <= iY && iY < getNy();
110 };
111};
112
113} // namespace olb
114
115#endif
bool isInside(int iX, int iY) const
Return whether location is valid.
int getNx() const
Read only access to block width.
BlockStructure2D(int nx, int ny, int overlap)
BlockStructure2D(int nx, int ny)
std::ptrdiff_t getNeighborDistance(Vector< int, 2 > c) const
Get 1D neighbor distance.
std::size_t getCellId(int iX, int iY) const
Get 1D cell ID.
std::size_t getNcells() const
Get number of cells.
int getNy() const
Read only access to block height.
std::ptrdiff_t getNeighborDistance(int iX, int iY) const
Get 1D neighbor distance.
Plain old scalar vector.
Definition vector.h:47
Top level namespace for all of OpenLB.
#define OLB_PRECONDITION(COND)
Definition olbDebug.h:46
efficient implementation of a vector class