TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
TRUSTTabFT_cut_cell.cpp
1/****************************************************************************
2* Copyright (c) 2019, 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#include <Cut_cell_FT_Disc.h>
17#include <TRUSTTabFT_cut_cell.h>
18#include <IJK_Interfaces.h>
19#include <IJK_Navier_Stokes_tools.h>
20
21template <typename _TYPE_>
22void compare_second_column(_TYPE_* ptr, int sz)
23{
24 using pair = std::array<_TYPE_, 2>;
25 pair* tmp = reinterpret_cast<pair*>(ptr);
26 std::sort(tmp, tmp+sz, [&](const pair& p1, const pair& p2)
27 {
28 return (p1[1] < p2[1]);
29 });
30}
31
32template <typename _TYPE_>
33void compare_second_then_third_column(_TYPE_* ptr, int sz)
34{
35 using triplet = std::array<_TYPE_, 3>;
36 triplet* tmp = reinterpret_cast<triplet*>(ptr);
37 std::sort(tmp, tmp+sz, [&](const triplet& p1, const triplet& p2)
38 {
39 if(p1[1] == p2[1])
40 return (p1[2] < p2[2]);
41 else
42 return (p1[1] < p2[1]);
43 });
44}
45
46template<typename _TYPE_>
48{
49 cut_cell_disc_ = cut_cell_disc;
50 cut_cell_disc_->add_to_persistent_data(*this, dimension);
51}
52
53template<typename _TYPE_>
55{
56 cut_cell_disc_ = cut_cell_disc;
57 cut_cell_disc_->add_to_transient_data(*this, dimension);
58}
59
60template<typename _TYPE_>
62{
63 cut_cell_disc_ = cut_cell_disc;
64 cut_cell_disc_->add_to_lazy_data(*this, dimension);
65}
66
67template<>
69{
70 if (dimension(1) == 2)
71 {
72 if (column == 1)
73 {
74 compare_second_column<int>(addr(), cut_cell_disc_->get_n_tot());
75 }
76 else
77 {
78 Cerr << "NotImplementedError: TRUSTTabFT_cut_cell<int>::sort_tot(int) with sorting other than the second column." << finl;
80 }
81 }
82 else
83 {
84 Cerr << "NotImplementedError: TRUSTTabFT_cut_cell<int>::sort_tot(int) with other than 2 columns." << finl;
86 }
87}
88
89template<>
91{
92 if (dimension(1) == 2)
93 {
94 if (column == 1)
95 {
96 compare_second_column<double>(addr(), cut_cell_disc_->get_n_tot());
97 }
98 else
99 {
100 Cerr << "NotImplementedError: TRUSTTabFT_cut_cell<double>::sort_tot(double) with sorting other than the second column." << finl;
102 }
103 }
104 else
105 {
106 Cerr << "NotImplementedError: TRUSTTabFT_cut_cell<double>::sort_tot(double) with other than 2 columns." << finl;
108 }
109}
110
111template<>
112void TRUSTTabFT_cut_cell<int>::sort_tot(int column_1, int column_2)
113{
114 if (dimension(1) == 3)
115 {
116 if (column_1 == 1 && column_2 == 2)
117 {
118 compare_second_then_third_column<int>(addr(), cut_cell_disc_->get_n_tot());
119 }
120 else
121 {
122 Cerr << "NotImplementedError: TRUSTTabFT_cut_cell<int>::sort_tot(int,int) with sorting other than the second, then third column." << finl;
124 }
125 }
126 else
127 {
128 Cerr << "NotImplementedError: TRUSTTabFT_cut_cell<int>::sort_tot(int,int) with other than 3 columns." << finl;
130 }
131}
132
133template<>
134void TRUSTTabFT_cut_cell<double>::sort_tot(int column_1, int column_2)
135{
136 if (dimension(1) == 3)
137 {
138 if (column_1 == 1 && column_2 == 2)
139 {
140 compare_second_then_third_column<double>(addr(), cut_cell_disc_->get_n_tot());
141 }
142 else
143 {
144 Cerr << "NotImplementedError: TRUSTTabFT_cut_cell<double>::sort_tot(double,double) with sorting other than the second, then third column." << finl;
146 }
147 }
148 else
149 {
150 Cerr << "NotImplementedError: TRUSTTabFT_cut_cell<double>::sort_tot(double,double) with other than 3 columns." << finl;
152 }
153}
154
155template<typename _TYPE_>
156void TRUSTTabFT_cut_cell<_TYPE_>::echange_espace_virtuel(IsExchangeBlocking exchange_type, const std::string kernel_name)
157{
158 cut_cell_disc_->get_desc_structure().echange_espace_virtuel(*this);
159}
160
161template<typename _TYPE_>
163{
164 cut_cell_disc_->get_desc_structure().echange_espace_virtuel(*this, op);
165}
166
167
168void Cut_cell_data::associer_persistant(Cut_cell_FT_Disc& cut_cell_disc, int dimension)
169{
170 cut_cell_disc_ = cut_cell_disc;
171 diph_l_.associer_persistant(cut_cell_disc_, dimension);
172 diph_v_.associer_persistant(cut_cell_disc_, dimension);
173}
174
175void Cut_cell_data::associer_ephemere(Cut_cell_FT_Disc& cut_cell_disc, int dimension)
176{
177 cut_cell_disc_ = cut_cell_disc;
178 diph_l_.associer_ephemere(cut_cell_disc_, dimension);
179 diph_v_.associer_ephemere(cut_cell_disc_, dimension);
180}
181
182void Cut_cell_data::associer_paresseux(Cut_cell_FT_Disc& cut_cell_disc, int dimension)
183{
184 cut_cell_disc_ = cut_cell_disc;
185 diph_l_.associer_paresseux(cut_cell_disc_, dimension);
186 diph_v_.associer_paresseux(cut_cell_disc_, dimension);
187}
188
190{
191 diph_l_.echange_espace_virtuel();
192 diph_v_.echange_espace_virtuel();
193}
194
196{
197 diph_l_.echange_espace_virtuel(op);
198 diph_v_.echange_espace_virtuel(op);
199}
200
205
210
215
216// Verifie que le champ pure_, suppose etre localise sur une surface, est coherent avec
217// le champ diph_v_ ou diph_l_ si la dite surface appartient a une cellule pure.
218bool Cut_cell_double::verify_consistency_within_layer(int dir, int k_layer, const IJK_Field_local_double& flux)
219{
220 int ni = (dir == 0) ? flux.ni() : flux.ni() - 1;
221 int nj = (dir == 1) ? flux.nj() : flux.nj() - 1;
222 int di = (dir == 0)*(-1);
223 int dj = (dir == 1)*(-1);
224 int dk = (dir == 2)*(-1);
225 for (int j = 0; j < nj; j++)
226 {
227 for (int i = 0; i < ni; i++)
228 {
229 int n = cut_cell_disc_->get_n(i, j, k_layer);
230 if (n >= 0)
231 {
232 int n_decale = cut_cell_disc_->get_n(i+di, j+dj, k_layer+dk);
233 if (n_decale < 0)
234 {
235 // Surface between a pure and non-pure cells
236 // There should be a consistency
237 int phase = IJK_Interfaces::convert_indicatrice_to_phase(cut_cell_disc_->indic_pure(i+di, j+dj, k_layer+dk));
238
239 if (phase == 0)
240 {
241 if (flux(i,j,0) != diph_v_(n))
242 {
243 assert(0);
244 return 0;
245 }
246 }
247 else
248 {
249 if (flux(i,j,0) != diph_l_(n))
250 {
251 assert(0);
252 return 0;
253 }
254 }
255 }
256 }
257 }
258 }
259
260 return 1;
261}
262
263
264// Explicit instantiations
265
266template class TRUSTTabFT_cut_cell<int>;
267template class TRUSTTabFT_cut_cell<double>;
268
void add_to_lazy_data(DoubleTabFT_cut_cell &field, int dimension)
void add_to_transient_data(DoubleTabFT_cut_cell &field, int dimension)
void add_to_persistent_data(DoubleTabFT_cut_cell &field, int dimension)
void associer_ephemere(Cut_cell_FT_Disc &cut_cell_disc, int dimension)
DoubleTabFT_cut_cell diph_v_
DoubleTabFT_cut_cell diph_l_
void associer_persistant(Cut_cell_FT_Disc &cut_cell_disc, int dimension)
void associer_paresseux(Cut_cell_FT_Disc &cut_cell_disc, int dimension)
void associer_ephemere(Cut_cell_FT_Disc &cut_cell_disc)
void associer_persistant(Cut_cell_FT_Disc &cut_cell_disc)
void associer_paresseux(Cut_cell_FT_Disc &cut_cell_disc)
bool verify_consistency_within_layer(int dir, int k_layer, const IJK_Field_local_double &flux)
static int convert_indicatrice_to_phase(double indicatrice)
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
_TYPE_ * addr()
: class TRUSTTabFT_cut_cell
void associer_paresseux(Cut_cell_FT_Disc &cut_cell_disc, int dimension)
void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname") override
void associer_persistant(Cut_cell_FT_Disc &cut_cell_disc, int dimension)
void associer_ephemere(Cut_cell_FT_Disc &cut_cell_disc, int dimension)
void sort_tot(int colum)
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133