TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Multigrille_Adrien.h
1/****************************************************************************
2* Copyright (c) 2026, 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 Multigrille_Adrien_included
17#define Multigrille_Adrien_included
18
19#include <Grid_Level_Data_template.h>
20#include <Coarsen_Operator_base.h>
21#include <type_traits>
22#include <Multigrille_base.h>
23#include <Equation_base.h>
24#include <TRUSTArray.h>
25
26class Domaine_IJK;
28{
29 Declare_instanciable_sans_constructeur(Multigrille_Adrien);
30public:
32 int completer(const Equation_base& eq);
33 void initialize(const Domaine_IJK&);
34 int nb_grid_levels() const override { return coarsen_operators_.size() + 1; }
35
36 void set_rho(const DoubleVect& rho);
37 template <typename _TYPE_, typename _TYPE_ARRAY_>
39 void set_rho_NoSym(const DoubleVect& rho);
40 template <typename _TYPE_, typename _TYPE_ARRAY_>
42 void reset_rho();
43 template <typename _TYPE_, typename _TYPE_ARRAY_>
45 template <typename _TYPE_, typename _TYPE_ARRAY_>
47 template <typename _TYPE_FUNC_, typename _TYPE_, typename _TYPE_ARRAY_>
48 void set_inv_rho_NoSym_template(const IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& rho, bool set_coarse_matrix_flag, bool use_coeffs_from_double);
49 template <typename _TYPE_FUNC_, typename _TYPE_, typename _TYPE_ARRAY_>
50 void set_inv_rho_template(const IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& rho, bool set_coarse_matrix_flag, bool use_coeffs_from_double);
51
52
53 inline void prepare_secmem(IJK_Field_float& x) const override
54 {
55 prepare_secmem_(x);
56 }
57 inline void prepare_secmem(IJK_Field_double& x) const override
58 {
59 prepare_secmem_(x);
60 }
61
62 inline void alloc_field(IJK_Field_float& x, int level, bool with_additional_k_layers = false) const override
63 {
64 alloc_field_(x,level, with_additional_k_layers);
65 }
66 inline void alloc_field(IJK_Field_double& x, int level, bool with_additional_k_layers = false) const override
67 {
68 alloc_field_(x,level, with_additional_k_layers);
69 }
70 inline void dump_lata(const Nom& field, const IJK_Field_float& data, int tstep) const override
71 {
72 dump_lata_(field, data, tstep);
73 }
74 inline void dump_lata(const Nom& field, const IJK_Field_double& data, int tstep) const override
75 {
76 dump_lata_(field, data, tstep);
77 }
78
79protected:
80 void ajouter_param(Param& param) override;
81 int needed_kshift_for_jacobi(int level) const override;
82
83 template <typename _TYPE_, typename _TYPE_ARRAY_>
85
86 template <typename _TYPE_, typename _TYPE_ARRAY_>
88 template <typename _TYPE_, typename _TYPE_ARRAY_>
90 const int grid_level) const;
91 template <typename _TYPE_FUNC_, typename _TYPE_, typename _TYPE_ARRAY_>
92 void set_rho_template(const IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& rho, bool set_coarse_matrix, bool use_coeffs_from_double);
93 template <typename _TYPE_FUNC_, typename _TYPE_, typename _TYPE_ARRAY_>
94 void set_rho_template_NoSym(const IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& rho, bool set_coarse_matrix, bool use_coeffs_from_double);
95
96 void completer_double_for_residue(const Domaine_IJK& splitting);
97
98 inline void jacobi_residu(IJK_Field_float& x,
99 const IJK_Field_float *secmem, /* if null pointer, take secmem = 0 (to compute A*x) */
100 const int grid_level,
101 const int n_jacobi,
102 IJK_Field_float *residu) const override
103 {
104 jacobi_residu_(x,secmem, grid_level, n_jacobi, residu);
105 }
106 inline void jacobi_residu(IJK_Field_double& x,
107 const IJK_Field_double *secmem,
108 const int grid_level,
109 const int n_jacobi,
110 IJK_Field_double *residu) const override
111 {
112 jacobi_residu_(x,secmem, grid_level, n_jacobi, residu);
113 }
114
115
116 inline void coarsen(const IJK_Field_float& fine, IJK_Field_float& coarse, int fine_level) const override
117 {
118 coarsen_(fine, coarse, fine_level);
119 }
120 inline void coarsen(const IJK_Field_double& fine, IJK_Field_double& coarse, int fine_level) const override
121 {
122 coarsen_(fine, coarse, fine_level);
123 }
124 inline void interpolate_sub_shiftk(const IJK_Field_float& coarse, IJK_Field_float& fine, int fine_level) const override
125 {
126 interpolate_sub_shiftk_(coarse, fine, fine_level);
127 }
128 inline void interpolate_sub_shiftk(const IJK_Field_double& coarse, IJK_Field_double& fine, int fine_level) const override
129 {
130 interpolate_sub_shiftk_(coarse, fine, fine_level);
131 }
132 inline IJK_Field_float& get_storage_float(StorageId si, int level) override
133 {
134 return get_storage_template_<float>(si, level);
135 }
136 inline IJK_Field_double& get_storage_double(StorageId si, int level) override
137 {
138 return get_storage_template_<double>(si, level);
139 }
140
141 double multigrille_failure() override;
142
143private:
144
145 template<typename _TYPE_>
146 inline std::enable_if_t<std::is_same<_TYPE_,double>::value, int>
147 get_grid_data_size() const { return grids_data_double_.size(); }
148
149 template<typename _TYPE_>
150 inline std::enable_if_t<std::is_same<_TYPE_,float>::value, int>
151 get_grid_data_size() const { return grids_data_float_.size(); }
152
153 template<typename _TYPE_>
154 inline std::enable_if_t<std::is_same<_TYPE_,double>::value, const Grid_Level_Data_template<double>&>
155 get_grid_data(int level) const { return grids_data_double_[level]; }
156
157 template<typename _TYPE_>
158 inline std::enable_if_t<std::is_same<_TYPE_,float>::value, const Grid_Level_Data_template<float>&>
159 get_grid_data(int level) const { return grids_data_float_[level]; }
160
161 template<typename _TYPE_>
162 inline std::enable_if_t<std::is_same<_TYPE_,double>::value, Grid_Level_Data_template<double>&>
163 set_grid_data(int level) { return grids_data_double_[level]; }
164
165 template<typename _TYPE_>
166 inline std::enable_if_t<std::is_same<_TYPE_,float>::value, Grid_Level_Data_template<float>&>
167 set_grid_data(int level) { return grids_data_float_[level]; }
168
169 //ToDo: temporary workaround as virtual templates are not possible...
170 // when suppressing mix precision multigrid, move the template on the class
171 template <typename _TYPE_, typename _TYPE_ARRAY_>
172 void prepare_secmem_(IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& x) const;
173 template <typename _TYPE_, typename _TYPE_ARRAY_>
174 void dump_lata_(const Nom& field, const IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& data, int tstep) const;
175 template <typename _TYPE_, typename _TYPE_ARRAY_>
176 void alloc_field_(IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& x, int level, bool with_additional_k_layers = false) const;
177 template <typename _TYPE_, typename _TYPE_ARRAY_>
178 void jacobi_residu_(IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& x,
179 const IJK_Field_template<_TYPE_,_TYPE_ARRAY_> *secmem, /* if null pointer, take secmem = 0 (to compute A*x) */
180 const int grid_level,
181 const int n_jacobi,
182 IJK_Field_template<_TYPE_,_TYPE_ARRAY_> *residu) const;
183
184 template <typename _TYPE_, typename _TYPE_ARRAY_>
185 void coarsen_(const IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& fine, IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& coarse, int fine_level) const;
186 template <typename _TYPE_, typename _TYPE_ARRAY_>
187 void interpolate_sub_shiftk_(const IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& coarse, IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& fine, int fine_level) const;
188 template <typename _TYPE_>
189 IJK_Field_template<_TYPE_,TRUSTArray<_TYPE_>>& get_storage_template_(StorageId, int level);
190
191 // number of isotropic coarsening steps
192 int nb_isotropic_coarsening_ = -10;
193 // Thickness of the ghost domaine: determines the maximum number of sweeps of the Jacobi
194 // smoother that are performed in the same pass (1, 2, 4 or 6 can be efficient depending
195 // on the architecture and the problem)
196 int ghost_size_;
197
198 // Coarsening operators (read in the .data file)
199 VECT(OWN_PTR(Coarsen_Operator_base)) coarsen_operators_;
200
201 // Data for each grid (number of grids = number of coarsening operators + 1)
202 TRUST_Vector<Grid_Level_Data_template<float>> grids_data_float_;
203 TRUST_Vector<Grid_Level_Data_template<double>> grids_data_double_;
204};
205
206#include<Multigrille_Adrien.tpp>
207
208#endif
This class encapsulates all the information related to the eulerian mesh for TrioIJK.
Definition Domaine_IJK.h:47
classe Equation_base Le role d'une equation est le calcul d'un ou plusieurs champs....
: This class is an IJK_Field_local with parallel informations.
void dump_lata(const Nom &field, const IJK_Field_double &data, int tstep) const override
void coarsen(const IJK_Field_float &fine, IJK_Field_float &coarse, int fine_level) const override
int completer(const Equation_base &eq)
void ajouter_param(Param &param) override
void prepare_secmem(IJK_Field_float &x) const override
void set_inv_rho(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &inv_rho)
void set_rho(const DoubleVect &rho)
void completer_double_for_residue(const Domaine_IJK &splitting)
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)
IJK_Field_double & get_storage_double(StorageId si, int level) override
void set_inv_rho_template(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &rho, bool set_coarse_matrix_flag, bool use_coeffs_from_double)
void alloc_field(IJK_Field_double &x, int level, bool with_additional_k_layers=false) const override
int nb_grid_levels() const override
int needed_kshift_for_jacobi(int level) const override
void coarsen(const IJK_Field_double &fine, IJK_Field_double &coarse, int fine_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 prepare_secmem(IJK_Field_double &x) const override
void jacobi_residu(IJK_Field_float &x, const IJK_Field_float *secmem, const int grid_level, const int n_jacobi, IJK_Field_float *residu) const override
void alloc_field(IJK_Field_float &x, int level, bool with_additional_k_layers=false) const override
void dump_lata(const Nom &field, const IJK_Field_float &data, int tstep) const override
double multigrille_failure() override
void interpolate_sub_shiftk(const IJK_Field_double &coarse, IJK_Field_double &fine, int fine_level) const override
IJK_Field_float & get_storage_float(StorageId si, int level) override
void set_rho_template_NoSym(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &rho, bool set_coarse_matrix, bool use_coeffs_from_double)
void initialize(const Domaine_IJK &)
void completer_template(const Domaine_IJK &)
void jacobi_residu(IJK_Field_double &x, const IJK_Field_double *secmem, const int grid_level, const int n_jacobi, IJK_Field_double *residu) const override
void set_inv_rho_NoSym(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &inv_rho)
void interpolate_sub_shiftk(const IJK_Field_float &coarse, IJK_Field_float &fine, int fine_level) const override
void compute_coefficients(IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &coeffs_faces, const int grid_level) const
void setup_coarse_grid(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &fine, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &coarse) const
Matrice_Grossiere & set_coarse_matrix()
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
int size() const