TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
IJK_Field_local_template.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 IJK_Field_local_template_included
17#define IJK_Field_local_template_included
18
19#include <Field_base.h>
20#include <communications.h>
21#include <TRUSTVect.h>
22#include <Domaine_IJK.h>
23
24/*! @brief : This class describes a scalar field in an ijk box without any parallel information.
25 *
26 * The scalar field can be accessed by
27 * - field(i,j,k) with "-ghost() <= i < ni() + ghost()", same for j and k
28 * - field.data()[linear_index(i,j,k)]
29 *
30 * Inherits from Field_base to have access to all the naming logic.
31 */
32template<typename _TYPE_, typename _TYPE_ARRAY_>
34{
35protected:
36 unsigned taille_memoire() const override { throw; }
37
38 int duplique() const override
39 {
41 if (!xxx) Process::exit("Not enough memory !");
42 return xxx->numero();
43 }
44
45 Sortie& printOn(Sortie& os) const override { return os; }
46
47 Entree& readOn(Entree& is) override { return is; }
48
49public:
54
55 void allocate(int ni, int nj, int nk, int ghosts, int additional_k_layers = 0, int nb_compo = 1, bool external_storage = false);
56 void shift_k_origin(int n);
58
59 int linear_index(int i, int j, int k) const
60 {
61 assert(this->nb_compo_ == 1); // otherwise, must specify component
62 assert(i >= -ghost_size_ && i < ni_ + ghost_size_ && j >= -ghost_size_ && j < nj_ + ghost_size_ && k >= -ghost_size_ && k < nk_ + ghost_size_);
63 return offset_ + k * compo_stride_ + j * j_stride_ + i;
64 }
65
66 int linear_index(int i, int j, int k, int compo) const
67 {
68 assert(i >= -ghost_size_ && i < ni_ + ghost_size_ && j >= -ghost_size_ && j < nj_ + ghost_size_ && k >= -ghost_size_ && k < nk_ + ghost_size_ && compo >= 0 && compo < this->nb_compo_);
69 return offset_ + (k * this->nb_compo_ + compo) * compo_stride_ + j * j_stride_ + i;
70 }
71
72 // Operator() checks if the requested i,j,k index lies within the valid range [-ghost,n+ghost-1]
73 _TYPE_& operator()(int i, int j, int k)
74 {
75 int idx = linear_index(i, j, k);
76 return data_[idx];
77 }
78
79 const _TYPE_& operator()(int i, int j, int k) const
80 {
81 int idx = linear_index(i, j, k);
82 return data_[idx];
83 }
84
85 // Operator() checks if the requested i,j,k index lies within the valid range [-ghost,n+ghost-1]
86 _TYPE_& operator()(int i, int j, int k, int compo)
87 {
88 int idx = linear_index(i, j, k, compo);
89 return data_[idx];
90 }
91
92 const _TYPE_& operator()(int i, int j, int k, int compo) const
93 {
94 int idx = linear_index(i, j, k, compo);
95 return data_[idx];
96 }
97
98 int linear_index_relaxed_test(int i, int j, int k) const
99 {
100 assert(this->nb_compo_ == 1); // otherwise, must specify component
102 int x = offset_ + k * compo_stride_ + j * j_stride_ + i;
103 assert(x >= 0 && x < data_.size_array());
104 return x;
105 }
106
107 int linear_index_relaxed_test(int i, int j, int k, int compo) const
108 {
109 assert(compo >= 0 && compo < this->nb_compo_);
111 int x = offset_ + (k * this->nb_compo_ + compo) * compo_stride_ + j * j_stride_ + i;
112 assert(x >= 0 && x < data_.size_array());
113 return x;
114 }
115
116 // This method allows to access padding cells outside of the valid data range but inside the allocated data block.
117 _TYPE_& get_in_allocated_area(int i, int j, int k)
118 {
119 int idx = linear_index_relaxed_test(i, j, k);
120 return data_[idx];
121 }
122
123 const _TYPE_& get_in_allocated_area(int i, int j, int k) const
124 {
125 int idx = linear_index_relaxed_test(i, j, k);
126 return data_[idx];
127 }
128
129 // This method allows to access padding cells outside of the valid data range but inside the allocated data block.
130 _TYPE_& get_in_allocated_area(int i, int j, int k, int compo)
131 {
132 int idx = linear_index_relaxed_test(i, j, k, compo);
133 return data_[idx];
134 }
135
136 const _TYPE_& get_in_allocated_area(int i, int j, int k, int compo) const
137 {
138 int idx = linear_index_relaxed_test(i, j, k, compo);
139 return data_[idx];
140 }
141
142 _TYPE_* k_layer(int k)
143 {
144 assert(this->nb_compo_ == 1);
145 assert(k >= -ghost_size_ && k < nk_ + ghost_size_);
146 return data_.addr() + offset_ + k * compo_stride_;
147 }
148 const _TYPE_* k_layer(int k) const
149 {
150 assert(this->nb_compo_ == 1);
151 assert(k >= -ghost_size_ && k < nk_ + ghost_size_);
152 return data_.addr() + offset_ + k * compo_stride_;
153 }
154 _TYPE_* k_layer(int k, int compo)
155 {
156 assert(compo >= 0 && compo < this->nb_compo_);
157 assert(k >= -ghost_size_ && k < nk_ + ghost_size_);
158 return data_.addr() + offset_ + (k * this->nb_compo_ + compo) * compo_stride_;
159 }
160 const _TYPE_* k_layer(int k, int compo) const
161 {
162 assert(compo >= 0 && compo < this->nb_compo_);
163 assert(k >= -ghost_size_ && k < nk_ + ghost_size_);
164 return data_.addr() + offset_ + (k * this->nb_compo_ + compo) * compo_stride_;
165 }
166
167 int ni() const { return ni_; }
168 int nj() const { return nj_; }
169 int nk() const { return nk_; }
170 int nb_elem_local(int dir) const { return (dir==0)?ni_:((dir==1)?nj_:nk_); }
171 int j_stride() const { return j_stride_; }
172 int compo_stride() const { return compo_stride_; }
173 int k_stride() const { return compo_stride_ * this->nb_compo_; }
174 int ghost() const { return ghost_size_; }
175 int k_shift() const { return k_layer_shift_; }
176 int k_shift_max() const { return additional_k_layers_; }
177 int get_allocated_size() const { return allocated_size_; }
178 _TYPE_ARRAY_& data() { return data_; }
179 const _TYPE_ARRAY_& data() const { return data_; }
180protected:
181 // local size on this proc: (real itemnb_compo_s) : ni_ nj_ nk_ do not include the ghost size
183 int j_stride_; // how to jump to next j
184 int compo_stride_; // how to jump to next component, k_stride is compo_stride_ * nb_compo_
185 int offset_; // offset to first non ghost cell
186 int k_layer_shift_; // current shift value of the origin in the k direction
188 _TYPE_ARRAY_ data_;
189};
190
191using IJK_Field_local_float = IJK_Field_local_template<float,ArrOfFloat>;
192using IJK_Field_local_double = IJK_Field_local_template<double,ArrOfDouble>;
193using IJK_Field_local_int = IJK_Field_local_template<int,ArrOfInt>;
194
195#include <IJK_Field_local_template.tpp>
196
197#endif /* IJK_Field_local_template_included */
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual void fixer_nb_comp(int i)
Fixe le nombre de composantes du champ.
int nb_compo_
Definition Field_base.h:95
: This class describes a scalar field in an ijk box without any parallel information.
void allocate(int ni, int nj, int nk, int ghosts, int additional_k_layers=0, int nb_compo=1, bool external_storage=false)
const _TYPE_ & operator()(int i, int j, int k) const
const _TYPE_ & operator()(int i, int j, int k, int compo) const
int linear_index(int i, int j, int k) const
Sortie & printOn(Sortie &os) const override
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
_TYPE_ & get_in_allocated_area(int i, int j, int k)
_TYPE_ & operator()(int i, int j, int k)
unsigned taille_memoire() const override
int linear_index(int i, int j, int k, int compo) const
_TYPE_ * k_layer(int k, int compo)
Entree & readOn(Entree &is) override
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
const _TYPE_ & get_in_allocated_area(int i, int j, int k) const
int linear_index_relaxed_test(int i, int j, int k) const
const _TYPE_ * k_layer(int k, int compo) const
const _TYPE_ARRAY_ & data() const
void ref_ij(IJK_Field_local_template &src, int k_layer)
_TYPE_ & operator()(int i, int j, int k, int compo)
const _TYPE_ * k_layer(int k) const
_TYPE_ & get_in_allocated_area(int i, int j, int k, int compo)
const _TYPE_ & get_in_allocated_area(int i, int j, int k, int compo) const
int linear_index_relaxed_test(int i, int j, int k, int compo) const
int numero() const
Renvoie l'indice de l'objet dans Memoire::data.
Definition Objet_U.cpp:268
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52