TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Multigrille_base.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 Multigrille_base_included
17#define Multigrille_base_included
18
19#include <type_traits>
20#include <Matrice_Grossiere.h>
21#include <SolveurSys.h>
22#include <TRUSTLists.h>
23
24class Param;
25
27{
28 Declare_base_sans_constructeur(Multigrille_base);
29public:
31 int get_flag_updated_input() const override;
32 int resoudre_systeme(const Matrice_Base& a, const DoubleVect& b, DoubleVect& x, int ) override;
33 int resoudre_systeme(const Matrice_Base& a, const DoubleVect& b, DoubleVect& x) override;
34 int solveur_direct() const override { return 0 ; };
35
36 template <typename _TYPE_, typename _TYPE_ARRAY_>
38
39 template <typename _TYPE_, typename _TYPE_ARRAY_>
40 void convert_from_ijk(const IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& ijk_x, DoubleVect& x);
41
42 template <typename _TYPE_, typename _TYPE_ARRAY_>
43 void convert_to_ijk(const DoubleVect& x, IJK_Field_template<_TYPE_,_TYPE_ARRAY_>& ijk_x);
44
45 template <typename _TYPE_, typename _TYPE_ARRAY_>
47
48 virtual void prepare_secmem(IJK_Field_float& x) const = 0;
49 virtual void prepare_secmem(IJK_Field_double& x) const = 0;
50
51 virtual void alloc_field(IJK_Field_float& x, int level, bool with_additional_k_layers = false) const = 0;
52 virtual void alloc_field(IJK_Field_double& x, int level, bool with_additional_k_layers = false) const = 0;
53
54 virtual void dump_lata(const Nom& field, const IJK_Field_float& data, int tstep) const = 0;
55 virtual void dump_lata(const Nom& field, const IJK_Field_double& data, int tstep) const = 0;
56
57 virtual int nb_grid_levels() const = 0;
58
59protected:
60 virtual void ajouter_param(Param&);
61
63 {
64 solveur_grossier_->reinit();
65 return coarse_matrix_;
66 }
68 virtual int needed_kshift_for_jacobi(int level) const = 0;
69 int nsweeps_jacobi_residu(int level) const;
70
71 template <typename _TYPE_, typename _TYPE_ARRAY_>
73
74 template <typename _TYPE_, typename _TYPE_ARRAY_>
76
77 template <typename _TYPE_, typename _TYPE_ARRAY_>
79
80 template <typename _TYPE_, typename _TYPE_ARRAY_>
81 void resoudre_systeme_template(const Matrice_Base& a, const DoubleVect& b, DoubleVect& x);
82
83 template <typename _TYPE_FUNC_, typename _TYPE_, typename _TYPE_ARRAY_>
85
86 template <typename _TYPE_>
88
89 virtual IJK_Field_float& get_storage_float(StorageId, int level) = 0;
90 virtual IJK_Field_double& get_storage_double(StorageId, int level) = 0;
91
92 template<typename _TYPE_>
93 std::enable_if_t<std::is_same<_TYPE_, float>::value, IJK_Field_template<_TYPE_, TRUSTArray<_TYPE_>>&>
95 {
96 return get_storage_float(id, level);
97 }
98
99 template<typename _TYPE_>
100 std::enable_if_t<std::is_same<_TYPE_, double>::value, IJK_Field_template<_TYPE_, TRUSTArray<_TYPE_>>&>
102 {
103 return get_storage_double(id, level);
104 }
105
106
107 virtual void jacobi_residu(IJK_Field_float& x,
108 const IJK_Field_float *secmem, /* if null pointer, take secmem = 0 (to compute A*x) */
109 const int grid_level,
110 const int n_jacobi,
111 IJK_Field_float *residu) const = 0;
112 virtual void jacobi_residu(IJK_Field_double& x,
113 const IJK_Field_double *secmem, /* if null pointer, take secmem = 0 (to compute A*x) */
114 const int grid_level,
115 const int n_jacobi,
116 IJK_Field_double *residu) const = 0;
117
118 virtual void coarsen(const IJK_Field_float& fine, IJK_Field_float& coarse, int fine_level) const = 0;
119 virtual void coarsen(const IJK_Field_double& fine, IJK_Field_double& coarse, int fine_level) const = 0;
120
121 virtual void interpolate_sub_shiftk(const IJK_Field_float& coarse, IJK_Field_float& fine, int fine_level) const = 0;
122 virtual void interpolate_sub_shiftk(const IJK_Field_double& coarse, IJK_Field_double& fine, int fine_level) const = 0;
123
124 template <typename _TYPE_, typename _TYPE_ARRAY_>
126 int grid_level, int iter_number);
127 double relax_jacobi(int level) const
128 {
129 int i;
130 if (level < relax_jacobi_.size_array())
131 i = level;
132 else
133 i = relax_jacobi_.size_array()-1;
134 return relax_jacobi_[i];
135 }
136
137 virtual double multigrille_failure() = 0;
138
141 const int precision_mix_;
143private:
144 // Solveur systeme pour la grille grossiere
145 SolveurSys solveur_grossier_;
146 Matrice_Grossiere coarse_matrix_;
147
148 // PARAMETRES MULTIGRILLE
149 // Coefficient de relaxation du lisseur Jacobi
150 // d'apres les publis, l'optimum est 0.71 en 2D et 0.65 en 3D
151 ArrOfDouble relax_jacobi_;
152 // Pour chaque niveau, nombre d'iterations lissage pre/post et multigrille
153 ArrOfInt pre_smooth_steps_;
154 ArrOfInt smooth_steps_;
155 ArrOfInt nb_full_mg_steps_; // number of multigrid iterations at each level
156
157 double seuil_; // exit from main multigrid iterations at fine level if below seuil_
158 int max_iter_gcp_; // if > 0, use gcp solver and fix max iterations
159 int n_krilov_; // number of krilov vectors in gmres
160 int max_iter_gmres_;
161 int solv_jacobi_;
162 bool impr_ = false;
163 int impr_gmres_;
164 int max_iter_mixed_solver_; // maximum number of iterations in mixed precision solver
165 int check_residu_;
166
167};
168
169#include <Multigrille_base.tpp>
170
171#endif
: This class is an IJK_Field_local with parallel informations.
Classe Matrice_Base Classe de base de la hierarchie des matrices.
virtual int needed_kshift_for_jacobi(int level) const =0
virtual void ajouter_param(Param &)
virtual double multigrille_failure()=0
virtual void prepare_secmem(IJK_Field_float &x) const =0
void solve_ijk_in_storage_template()
double relax_jacobi(int level) const
int solveur_direct() const override
virtual IJK_Field_float & get_storage_float(StorageId, int level)=0
std::enable_if_t< std::is_same< _TYPE_, float >::value, IJK_Field_template< _TYPE_, TRUSTArray< _TYPE_ > > & > get_storage_template(StorageId id, int level)
virtual void interpolate_sub_shiftk(const IJK_Field_float &coarse, IJK_Field_float &fine, int fine_level) const =0
std::enable_if_t< std::is_same< _TYPE_, double >::value, IJK_Field_template< _TYPE_, TRUSTArray< _TYPE_ > > & > get_storage_template(StorageId id, int level)
virtual int nb_grid_levels() const =0
void resoudre_systeme_IJK_template(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &rhs, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &x)
void convert_to_ijk(const DoubleVect &x, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &ijk_x)
virtual void coarsen(const IJK_Field_double &fine, IJK_Field_double &coarse, int fine_level) const =0
virtual void dump_lata(const Nom &field, const IJK_Field_float &data, int tstep) const =0
int get_flag_updated_input() const override
virtual IJK_Field_double & get_storage_double(StorageId, int level)=0
virtual void prepare_secmem(IJK_Field_double &x) const =0
const int precision_double_
int resoudre_systeme(const Matrice_Base &a, const DoubleVect &b, DoubleVect &x, int) override
virtual void alloc_field(IJK_Field_double &x, int level, bool with_additional_k_layers=false) const =0
virtual void interpolate_sub_shiftk(const IJK_Field_double &coarse, IJK_Field_double &fine, int fine_level) const =0
void resoudre_avec_gmres(IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &x, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &b, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &residu)
virtual void coarsen(const IJK_Field_float &fine, IJK_Field_float &coarse, int fine_level) const =0
virtual void alloc_field(IJK_Field_float &x, int level, bool with_additional_k_layers=false) const =0
void resoudre_avec_gcp(IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &x, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &b, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &residu)
double multigrille(IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &x, const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &b, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &residu)
void convert_from_ijk(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &ijk_x, DoubleVect &x)
virtual 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 =0
Matrice_Grossiere & set_coarse_matrix()
void resoudre_systeme_template(const Matrice_Base &a, const DoubleVect &b, DoubleVect &x)
double multigrille_(IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &x, const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &b, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &residu, int grid_level, int iter_number)
virtual 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 =0
int nsweeps_jacobi_residu(int level) const
void resoudre_systeme_IJK(const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &rhs, IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &x)
void coarse_solver(IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &x, const IJK_Field_template< _TYPE_, _TYPE_ARRAY_ > &b)
virtual void dump_lata(const Nom &field, const IJK_Field_double &data, int tstep) const =0
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
class SolveurSys Un SolveurSys represente n'importe qu'elle classe
Definition SolveurSys.h:32