TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
IJ_layout.h
1/****************************************************************************
2* Copyright (c) 2025, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef IJ_layout_included
17#define IJ_layout_included
18
19
20/*! @brief : This class describes an IJ plane of an IJK_Field_local.
21 *
22 * It just encapsulates the offset computation: j * j_stride_ + i
23 * with bound checking in debug... This class is usefull to safely optimize the code !
24 *
25 */
27{
28public:
29 int ni() const { return ni_; }
30 int nj() const { return nj_; }
31 int ghost() const { return ghost_; }
32 int j_stride() const { return j_stride_; }
33
34 template <typename T>
35 IJ_layout(const T& f) : ni_(f.ni()), nj_(f.nj()), ghost_(f.ghost()), j_stride_(f.j_stride()) { }
36
37 // origin points to x(0,0,k) for an IJK_Field
38 template <typename T>
39 T& operator()(T *origin, int i, int j) const
40 {
41 assert(i >= -ghost_ && i < ni_ + ghost_);
42 assert(j >= -ghost_ && j < nj_ + ghost_);
43 return origin[j * j_stride_ + i];
44 }
45
46 // origin points to x(0,0,k) for an IJK_Field
47 template <typename T>
48 const T& operator()(const T *origin, int i, int j) const
49 {
50 assert(i >= -ghost_ && i < ni_ + ghost_);
51 assert(j >= -ghost_ && j < nj_ + ghost_);
52 return origin[j * j_stride_ + i];
53 }
54
55 // linear index of cell (i=0,j=0) is zero origin points to x(0,0,k) for an IJK_Field
56 template <typename T>
57 T& linear(T *origin, int linear_index) const
58 {
59 assert(linear_index >= -ghost_ * (j_stride_ + 1));
60 assert(linear_index < (ni_ + ghost_) + j_stride_ * (nj_ + ghost_ - 1));
61 return origin[linear_index];
62 }
63
64 template <typename T>
65 const T& linear(const T *origin, int linear_index) const
66 {
67 assert(linear_index >= -ghost_ * (j_stride_ + 1));
68 assert(linear_index < (ni_ + ghost_) + j_stride_ * (nj_ + ghost_ - 1));
69 return origin[linear_index];
70 }
71
72 void linear_to_ij(int linear_index, int& i, int& j) const
73 {
74 assert(linear_index >= -ghost_ * (j_stride_ + 1));
75 assert(linear_index < (ni_ + ghost_) + j_stride_ * (nj_ + ghost_ - 1));
76 int l = linear_index + ghost_ * (j_stride_ + 1);
77 j = (l / j_stride_) - ghost_;
78 i = (l % j_stride_) - ghost_;
79 }
80
81 // ghost_ is the number of ghost cells allocated in memory in I and J directions
83};
84
85
86#endif /* IJ_layout_included */
IJ_layout(const T &f)
Definition IJ_layout.h:35
const T & operator()(const T *origin, int i, int j) const
Definition IJ_layout.h:48
int nj() const
Definition IJ_layout.h:30
int ghost() const
Definition IJ_layout.h:31
const T & linear(const T *origin, int linear_index) const
Definition IJ_layout.h:65
int j_stride() const
Definition IJ_layout.h:32
void linear_to_ij(int linear_index, int &i, int &j) const
Definition IJ_layout.h:72
int ghost_
Definition IJ_layout.h:82
int ni() const
Definition IJ_layout.h:29
T & linear(T *origin, int linear_index) const
Definition IJ_layout.h:57
T & operator()(T *origin, int i, int j) const
Definition IJ_layout.h:39
int j_stride_
Definition IJ_layout.h:82