programmer's documentation
cs_multigrid.h
Go to the documentation of this file.
1 #ifndef __CS_MULTIGRID_H__
2 #define __CS_MULTIGRID_H__
3 
4 /*============================================================================
5  * Multigrid solver.
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2016 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 
30 /*----------------------------------------------------------------------------
31  * Local headers
32  *----------------------------------------------------------------------------*/
33 
34 #include "cs_base.h"
35 #include "cs_sles.h"
36 #include "cs_sles_it.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
41 
42 /*============================================================================
43  * Macro definitions
44  *============================================================================*/
45 
46 /*============================================================================
47  * Type definitions
48  *============================================================================*/
49 
50 /* Multigrid linear solver context (opaque) */
51 
52 typedef struct _cs_multigrid_t cs_multigrid_t;
53 
54 /*============================================================================
55  * Global variables
56  *============================================================================*/
57 
58 /*=============================================================================
59  * Public function prototypes
60  *============================================================================*/
61 
62 /*----------------------------------------------------------------------------
63  * Initialize multigrid solver API.
64  *----------------------------------------------------------------------------*/
65 
66 void
68 
69 /*----------------------------------------------------------------------------
70  * Finalize multigrid solver API.
71  *----------------------------------------------------------------------------*/
72 
73 void
75 
76 /*----------------------------------------------------------------------------
77  * Indicate if multigrid solver API is used for at least one system.
78  *
79  * returns:
80  * true if at least one system uses a multigrid solver, false otherwise
81  *----------------------------------------------------------------------------*/
82 
83 bool
85 
86 /*----------------------------------------------------------------------------
87  * Define and associate a multigrid sparse linear system solver
88  * for a given field or equation name.
89  *
90  * If this system did not previously exist, it is added to the list of
91  * "known" systems. Otherwise, its definition is replaced by the one
92  * defined here.
93  *
94  * This is a utility function: if finer control is needed, see
95  * cs_sles_define() and cs_multigrid_create().
96  *
97  * Note that this function returns a pointer directly to the multigrid solver
98  * management structure. This may be used to set further options, for
99  * example calling cs_multigrid_set_coarsening_options() and
100  * cs_multigrid_set_solver_options().
101  * If needed, cs_sles_find() may be used to obtain a pointer to the
102  * matching cs_sles_t container.
103  *
104  * parameters:
105  * f_id <-- associated field id, or < 0
106  * name <-- associated name if f_id < 0, or NULL
107  *
108  * \return pointer to new multigrid info and context
109  */
110 /*----------------------------------------------------------------------------*/
111 
113 cs_multigrid_define(int f_id,
114  const char *name);
115 
116 /*----------------------------------------------------------------------------
117  * Create multigrid linear system solver info and context.
118  *
119  * The multigrid variant is an ACM (Additive Corrective Multigrid) method.
120  *
121  * returns:
122  * pointer to new multigrid info and context
123  *----------------------------------------------------------------------------*/
124 
126 cs_multigrid_create(void);
127 
128 /*----------------------------------------------------------------------------
129  * Destroy multigrid linear system solver info and context.
130  *
131  * parameters:
132  * context <-> pointer to multigrid linear solver info
133  * (actual type: cs_multigrid_t **)
134  *----------------------------------------------------------------------------*/
135 
136 void
137 cs_multigrid_destroy(void **context);
138 
139 /*----------------------------------------------------------------------------
140  * Create multigrid sparse linear system solver info and context
141  * based on existing info and context.
142  *
143  * parameters:
144  * context <-- pointer to reference info and context
145  * (actual type: cs_multigrid_t *)
146  *
147  * returns:
148  * pointer to newly created solver info object
149  * (actual type: cs_multigrid_t *)
150  *----------------------------------------------------------------------------*/
151 
152 void *
153 cs_multigrid_copy(const void *context);
154 
155 /*----------------------------------------------------------------------------
156  * Set multigrid coarsening parameters.
157  *
158  * parameters:
159  * mg <-> pointer to multigrid info and context
160  * aggregation_limit <-- maximum allowed fine cells per coarse cell
161  * coarsening_type <-- coarsening type:
162  * 0: algebraic, natural face traversal;
163  * 1: algebraic, face traveral by criteria;
164  * 2: algebraic, Hilbert face traversal;
165  * n_max_levels <-- maximum number of grid levels
166  * min_g_cells <-- global number of cells on coarse grids
167  * under which no coarsening occurs
168  * p0p1_relax <-- p0/p1 relaxation_parameter
169  * verbosity <-- verbosity level
170  * postprocess <-- if > 0, postprocess coarsening
171  * (using coarse cell numbers modulo this value)
172  *----------------------------------------------------------------------------*/
173 
174 void
176  int aggregation_limit,
177  int coarsening_type,
178  int n_max_levels,
179  cs_gnum_t min_g_cells,
180  double p0p1_relax,
181  int postprocess_block_size);
182 
183 /*----------------------------------------------------------------------------
184  * Set multigrid parameters for associated iterative solvers.
185  *
186  * parameters:
187  * mg <-> pointer to multigrid info and context
188  * descent_smoother_type <-- type of smoother for descent
189  * ascent_smoother_type <-- type of smoother for ascent
190  * coarse_solver_type <-- type of solver
191  * n_max_cycles <-- maximum number of cycles
192  * n_max_iter_descent <-- maximum iterations per descent phase
193  * n_max_iter_ascent <-- maximum iterations per descent phase
194  * n_max_iter_coarse <-- maximum iterations per coarsest solution
195  * poly_degree_descent <-- preconditioning polynomial degree
196  * for descent phases (0: diagonal)
197  * poly_degree_ascent <-- preconditioning polynomial degree
198  * for ascent phases (0: diagonal)
199  * poly_degree_coarse <-- preconditioning polynomial degree
200  * for coarse solver (0: diagonal)
201  * precision_mult_descent <-- precision multiplier for descent phases
202  * (levels >= 1)
203  * precision_mult_ascent <-- precision multiplier for ascent phases
204  * precision_mult_coarse <-- precision multiplier for coarsest grid
205  *----------------------------------------------------------------------------*/
206 
207 void
209  cs_sles_it_type_t descent_smoother_type,
210  cs_sles_it_type_t ascent_smoother_type,
211  cs_sles_it_type_t coarse_solver_type,
212  int n_max_cycles,
213  int n_max_iter_descent,
214  int n_max_iter_ascent,
215  int n_max_iter_coarse,
216  int poly_degree_descent,
217  int poly_degree_ascent,
218  int poly_degree_coarse,
219  double precision_mult_descent,
220  double precision_mult_ascent,
221  double precision_mult_coarse);
222 
223 /*----------------------------------------------------------------------------
224  * Setup multigrid sparse linear equation solver.
225  *
226  * parameters:
227  * context <-> pointer to multigrid info and context
228  * (actual type: cs_multigrid_t *)
229  * name <-- pointer to name of linear system
230  * a <-- associated matrix
231  * verbosity <-- associated verbosity
232  *----------------------------------------------------------------------------*/
233 
234 void
235 cs_multigrid_setup(void *context,
236  const char *name,
237  const cs_matrix_t *a,
238  int verbosity);
239 
240 /*----------------------------------------------------------------------------
241  * Call multigrid sparse linear equation solver.
242  *
243  * parameters:
244  * context <-> pointer to iterative sparse linear solver info
245  * (actual type: cs_multigrid_t *)
246  * name <-- pointer to name of linear system
247  * a <-- matrix
248  * verbosity <-- associated verbosity
249  * rotation_mode <-- halo update option for rotational periodicity
250  * precision <-- solver precision
251  * r_norm <-- residue normalization
252  * n_iter --> number of iterations
253  * residue --> residue
254  * rhs <-- right hand side
255  * vx <-> system solution
256  * aux_size <-- number of elements in aux_vectors
257  * aux_vectors --- optional working area (internal allocation if NULL)
258  *
259  * returns:
260  * convergence state
261  *----------------------------------------------------------------------------*/
262 
264 cs_multigrid_solve(void *context,
265  const char *name,
266  const cs_matrix_t *a,
267  int verbosity,
268  cs_halo_rotation_t rotation_mode,
269  double precision,
270  double r_norm,
271  int *n_iter,
272  double *residue,
273  const cs_real_t *rhs,
274  cs_real_t *vx,
275  size_t aux_size,
276  void *aux_vectors);
277 
278 /*----------------------------------------------------------------------------
279  * Free iterative sparse linear equation solver setup context.
280  *
281  * Note that this function should free resolution-related data, such as
282  * buffers and preconditioning but doesd not free the whole context,
283  * as info used for logging (especially performance data) is maintained.
284 
285  * parameters:
286  * context <-> pointer to iterative sparse linear solver info
287  * (actual type: cs_multigrid_t *)
288  *----------------------------------------------------------------------------*/
289 
290 void
291 cs_multigrid_free(void *context);
292 
293 /*----------------------------------------------------------------------------
294  * Log sparse linear equation solver info.
295  *
296  * parameters:
297  * context <-> pointer to iterative sparse linear solver info
298  * (actual type: cs_multigrid_t *)
299  * log_type <-- log type
300  *----------------------------------------------------------------------------*/
301 
302 void
303 cs_multigrid_log(const void *context,
304  cs_log_t log_type);
305 
306 /*----------------------------------------------------------------------------
307  * Error handler for multigrid sparse linear equation solver.
308  *
309  * In case of divergence or breakdown, this error handler outputs
310  * postprocessing data to assist debugging, then aborts the run.
311  * It does nothing in case the maximum iteration count is reached.
312  *
313  * parameters:
314  * context <-> pointer to multigrid sparse linear system solver info
315  * (actual type: cs_multigrid_t *)
316  * name <-- pointer to name of linear system
317  * state <-- convergence status
318  * a <-- matrix
319  * rotation_mode <-- halo update option for rotational periodicity
320  * rhs <-- right hand side
321  * vx <-> system solution
322  */
323 /*----------------------------------------------------------------------------*/
324 
325 void
328  const char *name,
329  const cs_matrix_t *a,
330  cs_halo_rotation_t rotation_mode,
331  const cs_real_t *rhs,
332  cs_real_t *vx);
333 
334 /*----------------------------------------------------------------------------*/
335 
337 
338 #endif /* __CS_MULTIGRID_H__ */
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:280
cs_halo_rotation_t
Definition: cs_halo.h:59
cs_sles_it_type_t
Iterative solver types.
Definition: cs_sles_it.h:54
cs_multigrid_t * cs_multigrid_define(int f_id, const char *name)
Define and associate a multigrid sparse linear system solver for a given field or equation name...
Definition: cs_multigrid.c:1850
void * cs_multigrid_copy(const void *context)
Create multigrid sparse linear system solver info and context based on existing info and context...
Definition: cs_multigrid.c:1977
#define BEGIN_C_DECLS
Definition: cs_defs.h:419
void cs_multigrid_destroy(void **context)
Destroy multigrid linear system solver info and context.
Definition: cs_multigrid.c:1932
void cs_multigrid_setup(void *context, const char *name, const cs_matrix_t *a, int verbosity)
Setup multigrid sparse linear equation solver.
Definition: cs_multigrid.c:2144
bool cs_multigrid_needed(void)
Indicate if multigrid solver API is used for at least one system.
Definition: cs_multigrid.c:1818
void cs_multigrid_log(const void *context, cs_log_t log_type)
Log multigrid solver info.
Definition: cs_multigrid.c:2005
struct _cs_matrix_t cs_matrix_t
Definition: cs_matrix.h:86
void cs_multigrid_error_post_and_abort(void *context, cs_sles_convergence_state_t state, const char *name, const cs_matrix_t *a, cs_halo_rotation_t rotation_mode, const cs_real_t *rhs, cs_real_t *vx)
cs_multigrid_t * cs_multigrid_create(void)
Create multigrid linear system solver info and context.
Definition: cs_multigrid.c:1884
cs_sles_convergence_state_t
Convergence status indicator.
Definition: cs_sles.h:55
void cs_multigrid_finalize(void)
Finalize multigrid solver API.
Definition: cs_multigrid.c:1802
double precision, save a
Definition: cs_fuel_incl.f90:146
cs_sles_convergence_state_t cs_multigrid_solve(void *context, const char *name, const cs_matrix_t *a, int verbosity, cs_halo_rotation_t rotation_mode, double precision, double r_norm, int *n_iter, double *residue, const cs_real_t *rhs, cs_real_t *vx, size_t aux_size, void *aux_vectors)
Call multigrid sparse linear equation solver.
Definition: cs_multigrid.c:2427
struct _cs_multigrid_t cs_multigrid_t
Definition: cs_multigrid.h:52
void cs_multigrid_free(void *context)
Free multigrid sparse linear equation solver setup context.
Definition: cs_multigrid.c:2569
cs_log_t
Definition: cs_log.h:47
void cs_multigrid_initialize(void)
Initialize multigrid solver API.
Definition: cs_multigrid.c:1791
#define END_C_DECLS
Definition: cs_defs.h:420
void cs_multigrid_set_coarsening_options(cs_multigrid_t *mg, int aggregation_limit, int coarsening_type, int n_max_levels, cs_gnum_t min_g_cells, double p0p1_relax, int postprocess_block_size)
Set multigrid coarsening parameters.
Definition: cs_multigrid.c:2039
double cs_real_t
Definition: cs_defs.h:296
void cs_multigrid_set_solver_options(cs_multigrid_t *mg, cs_sles_it_type_t descent_smoother_type, cs_sles_it_type_t ascent_smoother_type, cs_sles_it_type_t coarse_solver_type, int n_max_cycles, int n_max_iter_descent, int n_max_iter_ascent, int n_max_iter_coarse, int poly_degree_descent, int poly_degree_ascent, int poly_degree_coarse, double precision_mult_descent, double precision_mult_ascent, double precision_mult_coarse)
Set multigrid parameters for associated iterative solvers.
Definition: cs_multigrid.c:2092