7.1
general documentation
cs_iter_algo.h
Go to the documentation of this file.
1 #ifndef __CS_ITER_ALGO_H__
2 #define __CS_ITER_ALGO_H__
3 
4 /*============================================================================
5  * Set of functions to manage high-level iterative algorithms
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2021 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------
29  * Local headers
30  *----------------------------------------------------------------------------*/
31 
32 #include "cs_cdo_blas.h"
33 #include "cs_math.h"
34 #include "cs_param_types.h"
35 #include "cs_sles.h"
36 
37 /*----------------------------------------------------------------------------*/
38 
40 
41 /*============================================================================
42  * Macro definitions
43  *============================================================================*/
44 
45 /*============================================================================
46  * Type definitions
47  *============================================================================*/
48 
53 typedef struct {
54 
83  int verbosity;
85  double atol;
86  double rtol;
87  double dtol;
88 
90 
101 typedef struct {
102 
154 
155  void *context;
156 
159  double tol;
160 
161  double prev_res;
162  double res;
163  double res0;
164 
168 
170 
177 typedef struct {
178 
200  double max_cond;
201  double beta;
203 
205 
212 typedef struct _cs_iter_algo_aa_t cs_iter_algo_aa_t;
213 
214 /*============================================================================
215  * Inline static public function prototypes
216  *============================================================================*/
217 
218 /*----------------------------------------------------------------------------*/
224 /*----------------------------------------------------------------------------*/
225 
226 static inline void
227 cs_iter_algo_reset(cs_iter_algo_t *info)
228 {
229  if (info == NULL)
230  return;
231 
232  info->cvg = CS_SLES_ITERATING;
233  info->res0 = cs_math_big_r;
234  info->prev_res = cs_math_big_r;
235  info->res = cs_math_big_r;
236  info->n_algo_iter = 0;
237  info->n_inner_iter = 0;
238  info->last_inner_iter = 0;
239 }
240 
241 /*============================================================================
242  * Public function prototypes
243  *============================================================================*/
244 
245 /*----------------------------------------------------------------------------*/
253 /*----------------------------------------------------------------------------*/
254 
257 
258 /*----------------------------------------------------------------------------*/
268 /*----------------------------------------------------------------------------*/
269 
270 void
271 cs_iter_algo_post_check(const char *func_name,
272  const char *eq_name,
273  const char *algo_name,
274  cs_iter_algo_t *ia);
275 
276 /*----------------------------------------------------------------------------*/
282 /*----------------------------------------------------------------------------*/
283 
284 void
286 
287 /*----------------------------------------------------------------------------*/
296 /*----------------------------------------------------------------------------*/
297 
300  cs_lnum_t n_elts);
301 
302 /*----------------------------------------------------------------------------*/
310 /*----------------------------------------------------------------------------*/
311 
314 
315 /*----------------------------------------------------------------------------*/
321 /*----------------------------------------------------------------------------*/
322 
323 void
325 
326 /*----------------------------------------------------------------------------*/
332 /*----------------------------------------------------------------------------*/
333 
334 void
336 
337 /*----------------------------------------------------------------------------*/
344 /*----------------------------------------------------------------------------*/
345 
346 void
348 
349 /*----------------------------------------------------------------------------*/
359 /*----------------------------------------------------------------------------*/
360 
361 void
363  cs_real_t *cur_iterate,
364  const cs_real_t *pre_iterate,
365  cs_cdo_blas_dotprod_t *dotprod,
366  cs_cdo_blas_square_norm_t *sqnorm);
367 
368 /*----------------------------------------------------------------------------*/
369 
371 
372 #endif /* __CS_ITER_ALGO_H__ */
cs_param_dotprod_type_t
Definition: cs_param_types.h:920
double dtol
Definition: cs_iter_algo.h:87
double prev_res
Definition: cs_iter_algo.h:161
const cs_real_t cs_math_big_r
int n_inner_iter
Definition: cs_iter_algo.h:166
Structure storing all the parameters to drive the algorithm called Anderson acceleration.
Definition: cs_iter_algo.h:177
int n_max_dir
Definition: cs_iter_algo.h:198
cs_real_t() cs_cdo_blas_dotprod_t(const cs_real_t *a, const cs_real_t *b)
Generic function pointer for computing a dot product. Parallel synchronization is performed...
Definition: cs_cdo_blas.h:64
Definition: cs_sles.h:61
#define BEGIN_C_DECLS
Definition: cs_defs.h:510
void cs_iter_algo_aa_free(cs_iter_algo_t *info)
Free a cs_iter_algo_aa_t structure used to manage the Anderson acceleration.
Definition: cs_iter_algo.c:624
void cs_iter_algo_aa_update(cs_iter_algo_t *ia, cs_real_t *cur_iterate, const cs_real_t *pre_iterate, cs_cdo_blas_dotprod_t *dotprod, cs_cdo_blas_square_norm_t *sqnorm)
Apply one more iteration of the Anderson acceleration.
Definition: cs_iter_algo.c:652
int n_algo_iter
Definition: cs_iter_algo.h:165
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
Context structure for the algorithm called Anderson acceleration.
void cs_iter_algo_aa_free_arrays(cs_iter_algo_aa_t *aa)
Free arrays used during the Anderson acceleration.
Definition: cs_iter_algo.c:597
double res0
Definition: cs_iter_algo.h:163
double res
Definition: cs_iter_algo.h:162
Set of common parameters to manage an iterative algorithm.
Definition: cs_iter_algo.h:101
cs_sles_convergence_state_t
Convergence status indicator.
Definition: cs_sles.h:56
int last_inner_iter
Definition: cs_iter_algo.h:167
Definition: cs_field_pointer.h:222
int n_max_algo_iter
Definition: cs_iter_algo.h:84
cs_real_t() cs_cdo_blas_square_norm_t(const cs_real_t *array)
Generic function pointer for computing a square norm. Parallel synchronization is performed...
Definition: cs_cdo_blas.h:79
void * context
Definition: cs_iter_algo.h:155
void cs_iter_algo_update_cvg(cs_iter_algo_t *ia)
Update the convergence state and the number of iterations.
Definition: cs_iter_algo.c:443
int verbosity
Definition: cs_iter_algo.h:83
int starting_iter
Definition: cs_iter_algo.h:199
cs_iter_algo_aa_t * cs_iter_algo_aa_create(cs_iter_algo_param_aa_t aap, cs_lnum_t n_elts)
Create a new cs_iter_algo_aa_t structure.
Definition: cs_iter_algo.c:482
double atol
Definition: cs_iter_algo.h:85
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:316
cs_iter_algo_param_aa_t cs_iter_algo_get_anderson_param(cs_iter_algo_t *ia)
Retrieve the set of parameters for an Anderson algorithm.
Definition: cs_iter_algo.c:526
double beta
Definition: cs_iter_algo.h:201
cs_iter_algo_param_t param
Definition: cs_iter_algo.h:153
#define END_C_DECLS
Definition: cs_defs.h:511
Definition: cs_iter_algo.h:53
void cs_iter_algo_aa_allocate_arrays(cs_iter_algo_aa_t *aa)
Allocate arrays useful for the Anderson acceleration.
Definition: cs_iter_algo.c:558
void cs_iter_algo_post_check(const char *func_name, const char *eq_name, const char *algo_name, cs_iter_algo_t *ia)
Check if something wrong happens during the iterative process after one new iteration.
Definition: cs_iter_algo.c:405
double max_cond
Definition: cs_iter_algo.h:200
double normalization
Definition: cs_iter_algo.h:158
cs_sles_convergence_state_t cvg
Definition: cs_iter_algo.h:157
cs_iter_algo_t * cs_iter_algo_create(cs_iter_algo_param_t param)
Create and initialize a new cs_iter_algo_t structure.
Definition: cs_iter_algo.c:372
double rtol
Definition: cs_iter_algo.h:86
double tol
Definition: cs_iter_algo.h:159
cs_param_dotprod_type_t dp_type
Definition: cs_iter_algo.h:202