16#ifndef Multigrille_Adrien_TPP_H
17#define Multigrille_Adrien_TPP_H
19#include <Multigrille_Adrien.h>
20#include <SSE_kernels.h>
21#include <Perf_counters.h>
24static long long flop_count = 0;
27template <
typename _TYPE_,
typename _TYPE_ARRAY_>
30 double moyenne = somme_ijk(x);
34 double val = moyenne / nb_elem_tot;
35 const int m = x.
data().size_array();
36 for (
int i = 0; i < m; i++)
37 x.
data()[i] -= (_TYPE_)val;
40template <
typename _TYPE_,
typename _TYPE_ARRAY_>
46template <
typename _TYPE_,
typename _TYPE_ARRAY_>
60template <
typename _TYPE_,
typename _TYPE_ARRAY_>
75template <
typename _TYPE_,
typename _TYPE_ARRAY_>
89template <
typename _TYPE_,
typename _TYPE_ARRAY_>
103template <
typename _TYPE_FUNC_,
typename _TYPE_,
typename _TYPE_ARRAY_>
106 constexpr bool IS_DOUBLE = std::is_same<_TYPE_FUNC_, double>::value;
109 const int nlevels = get_grid_data_size<_TYPE_FUNC_>();
110 const int ghost = get_grid_data<_TYPE_FUNC_>(0).get_rho().ghost();
112 for (
int l = 0; l < nlevels; l++)
121 for (
int k = 0; k < nk; k++)
122 for (
int j = 0; j < nj; j++)
123 for (
int i = 0; i < ni; i++)
124 r(i,j,k) = (_TYPE_FUNC_)rho(i,j,k);
135 coarsen_operators_[l-1]->coarsen(set_grid_data<_TYPE_FUNC_>(l-1).get_rho(),
136 set_grid_data<_TYPE_FUNC_>(l).get_update_rho(),
139 set_grid_data<_TYPE_FUNC_>(l).get_update_rho().echange_espace_virtuel(ghost);
143 grids_data_double_[l].compute_faces_coefficients_from_rho();
146 if (use_coeffs_from_double && l < grids_data_double_.size())
147 grids_data_float_[l].compute_faces_coefficients_from_double_coeffs(grids_data_double_[l]);
149 grids_data_float_[l].compute_faces_coefficients_from_rho();
154 if (set_coarse_matrix_flag)
156 const int coarse_level = nlevels - 1;
161template <
typename _TYPE_FUNC_,
typename _TYPE_,
typename _TYPE_ARRAY_>
164 constexpr bool IS_DOUBLE = std::is_same<_TYPE_FUNC_, double>::value;
167 const int nlevels = get_grid_data_size<_TYPE_FUNC_>();
168 const int ghost = get_grid_data<_TYPE_FUNC_>(0).get_rho().ghost();
170 int monophasique = 1;
171 const double test_mono = (_TYPE_FUNC_)rho(0,0,0);
173 for (
int l = 0; l < nlevels; l++)
182 for (
int k = 0; k < nk; k++)
184 for (
int j = 0; j < nj; j++)
186 for (
int i = 0; i < ni; i++)
188 r(i,j,k) = (_TYPE_FUNC_)rho(i,j,k);
189 if (r(i,j,k) != test_mono)
204 coarsen_operators_[l-1].valeur().coarsen(set_grid_data<_TYPE_FUNC_>(l-1).get_rho(),
205 set_grid_data<_TYPE_FUNC_>(l).get_update_rho(),
208 set_grid_data<_TYPE_FUNC_>(l).get_update_rho().echange_espace_virtuel(ghost);
212 grids_data_double_[l].compute_faces_coefficients_from_rho();
215 if (use_coeffs_from_double && l < grids_data_double_.size())
216 grids_data_float_[l].compute_faces_coefficients_from_double_coeffs(grids_data_double_[l]);
218 grids_data_float_[l].compute_faces_coefficients_from_rho();
223 if (set_coarse_matrix_flag)
225 const int coarse_level = nlevels - 1;
230template <
typename _TYPE_FUNC_,
typename _TYPE_,
typename _TYPE_ARRAY_>
233 constexpr bool IS_DOUBLE = std::is_same<_TYPE_FUNC_, double>::value;
236 const int nlevels = get_grid_data_size<_TYPE_FUNC_>();
239 const int ghost = get_grid_data<_TYPE_FUNC_>(0).get_rho().ghost();
241 for (
int i = 0; i < nlevels; i++)
250 for (
int k = 0; k < nk; k++)
251 for (
int j = 0; j < nj; j++)
252 for (
int i2 = 0; i2 < ni; i2++)
253 r(i2,j,k) = (_TYPE_FUNC_)rho(i2,j,k);
264 coarsen_operators_[i-1]->coarsen(set_grid_data<_TYPE_FUNC_>(i-1).get_rho(),
265 set_grid_data<_TYPE_FUNC_>(i).get_update_rho(),
269 set_grid_data<_TYPE_FUNC_>(i).get_update_rho().echange_espace_virtuel(ghost);
273 grids_data_double_[i].compute_faces_coefficients_from_inv_rho();
278 if (use_coeffs_from_double && i < grids_data_double_.size())
279 grids_data_float_[i].compute_faces_coefficients_from_double_coeffs(grids_data_double_[i]);
281 grids_data_float_[i].compute_faces_coefficients_from_inv_rho();
286 if (set_coarse_matrix_flag)
288 const int coarse_level = nlevels - 1;
293template <
typename _TYPE_FUNC_,
typename _TYPE_,
typename _TYPE_ARRAY_>
296 constexpr bool IS_DOUBLE = std::is_same<_TYPE_FUNC_, double>::value;
299 const int nlevels = get_grid_data_size<_TYPE_FUNC_>();
301 const int ghost = get_grid_data<_TYPE_FUNC_>(0).get_rho().ghost();
303 for (
int i = 0; i < nlevels; i++)
312 for (
int k = 0; k < nk; k++)
313 for (
int j = 0; j < nj; j++)
314 for (
int i2 = 0; i2 < ni; i2++)
315 r(i2,j,k) = (_TYPE_FUNC_)rho(i2,j,k);
326 coarsen_operators_[i-1].valeur().coarsen(set_grid_data<_TYPE_FUNC_>(i-1).get_rho(),
327 set_grid_data<_TYPE_FUNC_>(i).get_update_rho(),
331 set_grid_data<_TYPE_FUNC_>(i).get_update_rho().echange_espace_virtuel(ghost);
335 grids_data_double_[i].compute_faces_coefficients_from_inv_rho();
340 if (use_coeffs_from_double && i < grids_data_double_.size())
341 grids_data_float_[i].compute_faces_coefficients_from_double_coeffs(grids_data_double_[i]);
343 grids_data_float_[i].compute_faces_coefficients_from_inv_rho();
348 if (set_coarse_matrix_flag)
350 const int coarse_level = nlevels - 1;
362template <
typename _TYPE_,
typename _TYPE_ARRAY_>
365 const int grid_level,
366 const int n_jacobi_tot,
369 statistics().create_custom_counter(
"multigrid: jacobi residual",2,
"IJK");
370 statistics().begin_count(
"multigrid: jacobi residual",statistics().get_last_opened_counter_level()+1);
377 const int nb_passes_max_per_sweep = x.
ghost();
379 const int nb_passes_to_do_total = n_jacobi_tot + (residu ? 1 : 0);
380 int nb_passes_done = 0;
383 while (nb_passes_done < nb_passes_to_do_total)
386 int nb_passes_to_do = nb_passes_to_do_total - nb_passes_done;
387 if (nb_passes_to_do > nb_passes_max_per_sweep)
388 nb_passes_to_do = nb_passes_max_per_sweep;
399 const bool last_pass_is_residue = (nb_passes_done + nb_passes_to_do == n_jacobi_tot + 1);
400 Multipass_Jacobi_template<_TYPE_, _TYPE_ARRAY_, SSE_Kernels::GENERIC_STRIDE, SSE_Kernels::GENERIC_STRIDE>(x, *residu, coeffs_face, *secmem, nb_passes_to_do, last_pass_is_residue, relax);
402 nb_passes_done += nb_passes_to_do;
410 statistics().
end_count(
"multigrid: jacobi residual",1, (
int)flop_count);
413template <
typename _TYPE_,
typename _TYPE_ARRAY_>
416 coarsen_operators_[fine_level]->coarsen(fine, coarse);
420template <
typename _TYPE_,
typename _TYPE_ARRAY_>
425 coarsen_operators_[fine_level]->interpolate_sub_shiftk(coarse, fine, shift);
429template <
typename _TYPE_,
typename _TYPE_ARRAY_>
432 Cerr <<
"Multigrille_Adrien::completer_template" << finl;
434 const int nb_operators = coarsen_operators_.size();
435 const int nb_grids = nb_operators + 1;
436 constexpr bool IS_DOUBLE = std::is_same<_TYPE_, double>::value;
438 grids_data_double_.dimensionner(nb_grids);
440 grids_data_float_.dimensionner(nb_grids);
444 for (
int i = 0; i < nb_operators; i++)
446 coarsen_operators_[i]->initialize_grid_data(set_grid_data<_TYPE_>(i), set_grid_data<_TYPE_>(i+1),
449 for (
int i = 0; i < nb_grids; i++)
452 Journal() <<
"Grid level " << i <<
" local size: " << g.
ni() <<
"x" << g.
nj() <<
"x" << g.
nk() << finl;
459template <
typename _TYPE_,
typename _TYPE_ARRAY_>
462 if (level < 0 || level > get_grid_data_size<_TYPE_>())
464 Cerr <<
"Fatal: wrong level in alloc_field" << finl;
467 const int n = with_additional_layers ? ghost_size_ : 0;
475template <
typename _TYPE_>
481 return set_grid_data<_TYPE_>(level).get_update_rhs();
483 return set_grid_data<_TYPE_>(level).get_update_x();
485 return set_grid_data<_TYPE_>(level).get_update_residue();
487 Cerr <<
"Error in Multigrille_Adrien::get_storage_float" << finl;
490 return set_grid_data<_TYPE_>(level).get_update_rhs();
This class encapsulates all the information related to the eulerian mesh for TrioIJK.
int get_nb_items_global(Localisation loc, int direction) const
Returns the number of local items (on this processor) for the given localisation in the requested dir...
: This class describes a scalar field in an ijk box without any parallel information.
: This class is an IJK_Field_local with parallel informations.
void allocate(const Domaine_IJK &d, Domaine_IJK::Localisation l, int ghost_size, int additional_k_layers=0, int nb_compo=1, const Nom &name=Nom(), bool external_storage=false, int monofluide=0, double rov=0., double rol=0., int use_inv_rho_in_pressure_solver=0)
void echange_espace_virtuel(int ghost)
Exchange data over "ghost" number of cells.
IJK_Shear_Periodic_helpler & get_shear_BC_helpler()
const Domaine_IJK & get_domaine() const
const IJK_Field_local_template< double, ArrOfDouble > & get_indicatrice_ghost_zmax_() const
const IJK_Field_local_template< double, ArrOfDouble > & get_indicatrice_ghost_zmin_() const
void build_matrix_test(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &coeffs_face)
void build_matrix(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &coeffs_face)
void set_inv_rho(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &inv_rho)
void set_rho(const DoubleVect &rho)
void set_rho_template(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &rho, bool set_coarse_matrix, bool use_coeffs_from_double)
void set_rho_NoSym(const DoubleVect &rho)
void set_inv_rho_template(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &rho, bool set_coarse_matrix_flag, bool use_coeffs_from_double)
int needed_kshift_for_jacobi(int level) const override
void set_inv_rho_NoSym_template(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &rho, bool set_coarse_matrix_flag, bool use_coeffs_from_double)
void set_rho_template_NoSym(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &rho, bool set_coarse_matrix, bool use_coeffs_from_double)
void completer_template(const Domaine_IJK &)
void set_inv_rho_NoSym(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &inv_rho)
double relax_jacobi(int level) const
const int precision_double_
const int precision_float_
Matrice_Grossiere & set_coarse_matrix()
int nsweeps_jacobi_residu(int level) const
class Nom Une chaine de caractere pour nommer les objets de TRUST
void end_count(const std::string &custom_count_name, int count_increment=1, long int quantity_increment=0)
End the count of a counter and update the counter values.
static Sortie & Journal(int message_level=0)
Renvoie un objet statique de type Sortie qui sert de journal d'evenements.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.