Code_Saturne
CFD tool
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-2012 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 
37 /*----------------------------------------------------------------------------*/
38 
40 
41 /*============================================================================
42  * Macro definitions
43  *============================================================================*/
44 
45 /*============================================================================
46  * Type definitions
47  *============================================================================*/
48 
49 /*============================================================================
50  * Global variables
51  *============================================================================*/
52 
53 /*============================================================================
54  * Public function prototypes for Fortran API
55  *============================================================================*/
56 
57 /*----------------------------------------------------------------------------
58  * Build a hierarchy of meshes starting from a fine mesh, for an
59  * ACM (Additive Corrective Multigrid) method.
60  *----------------------------------------------------------------------------*/
61 
62 void CS_PROCF(clmlga, CLMLGA)
63 (
64  const char *cname, /* <-- variable name */
65  const cs_int_t *lname, /* <-- variable name length */
66  const cs_int_t *isym, /* <-- Symmetry indicator:
67  1: symmetric; 2: not symmetric */
68  const cs_int_t *ibsize, /* <-- Matrix block size */
69  const cs_int_t *nagmax, /* <-- Agglomeration count limit */
70  const cs_int_t *ncpost, /* <-- If > 0, postprocess coarsening, using
71  coarse cell numbers modulo ncpost */
72  const cs_int_t *iwarnp, /* <-- Verbosity level */
73  const cs_int_t *ngrmax, /* <-- Maximum number of grid levels */
74  const cs_int_t *ncegrm, /* <-- Maximum local number of cells on
75  coarsest grid */
76  const cs_real_t *rlxp1, /* <-- P0/P1 relaxation parameter */
77  const cs_real_t *dam, /* <-- Matrix diagonal */
78  const cs_real_t *xam /* <-- Matrix extra-diagonal terms */
79 );
80 
81 /*----------------------------------------------------------------------------
82  * Destroy a hierarchy of meshes starting from a fine mesh, keeping
83  * the corresponding system information for future calls.
84  *----------------------------------------------------------------------------*/
85 
86 void CS_PROCF(dsmlga, DSMLGA)
87 (
88  const char *cname, /* <-- variable name */
89  const cs_int_t *lname /* <-- variable name length */
90 );
91 
92 /*----------------------------------------------------------------------------
93  * General sparse linear system resolution
94  *----------------------------------------------------------------------------*/
95 
96 void CS_PROCF(resmgr, RESMGR)
97 (
98  const char *cname, /* <-- variable name */
99  const cs_int_t *lname, /* <-- variable name length */
100  const cs_int_t *ncelet, /* <-- Number of cells, halo included */
101  const cs_int_t *ncel, /* <-- Number of local cells */
102  const cs_int_t *nfac, /* <-- Number of faces */
103  const cs_int_t *iresds, /* <-- Descent smoother type:
104  0: pcg; 1: Jacobi; 2: cg-stab */
105  const cs_int_t *iresas, /* <-- Ascent smoother type:
106  0: pcg; 1: Jacobi; 2: cg-stab */
107  const cs_int_t *ireslp, /* <-- Coarse Resolution type:
108  0: pcg; 1: Jacobi; 2: cg-stab */
109  const cs_int_t *ipol, /* <-- Preconditioning polynomial degree
110  (0: diagonal) */
111  const cs_int_t *ncymxp, /* <-- Max number of cycles */
112  const cs_int_t *nitmds, /* <-- Max number of iterations for descent */
113  const cs_int_t *nitmas, /* <-- Max number of iterations for ascent */
114  const cs_int_t *nitmap, /* <-- Max number of iterations for
115  coarsest solution */
116  const cs_int_t *iinvpe, /* <-- Indicator to cancel increments
117  in rotational periodicity (2) or
118  to exchange them as scalars (1) */
119  const cs_int_t *iwarnp, /* <-- Verbosity level */
120  cs_int_t *ncyclf, /* --> Number of cycles done */
121  cs_int_t *niterf, /* --> Number of iterations done */
122  const cs_real_t *epsilp, /* <-- Precision for iterative resolution */
123  const cs_real_t *rnorm, /* <-- Residue normalization */
124  cs_real_t *residu, /* --> Final non normalized residue */
125  const cs_real_t *rhs, /* <-- System right-hand side */
126  cs_real_t *vx /* <-> System solution */
127 );
128 
129 /*=============================================================================
130  * Public function prototypes
131  *============================================================================*/
132 
133 /*----------------------------------------------------------------------------
134  * Initialize multigrid solver API.
135  *----------------------------------------------------------------------------*/
136 
137 void
139 
140 /*----------------------------------------------------------------------------
141  * Finalize multigrid solver API.
142  *----------------------------------------------------------------------------*/
143 
144 void
146 
147 /*----------------------------------------------------------------------------
148  * Build a hierarchy of meshes starting from a fine mesh, for an
149  * ACM (Additive Corrective Multigrid) method.
150  *
151  * parameters:
152  * var_name <-- variable name
153  * verbosity <-- verbosity level
154  * postprocess_block_size <-- if > 0, postprocess coarsening, using
155  * coarse cell numbers modulo ncpost
156  * aggregation_limit <-- maximum allowed fine cells per coarse cell
157  * n_max_levels <-- maximum number of grid levels
158  * n_g_cells_min <-- global number of cells on coarsest grid
159  * under which no merging occurs
160  * p0p1_relax <-- p0/p1 relaxation_parameter
161  * symmetric <-- indicates if matrix coefficients are symmetric
162  * diag_block_size <-- block sizes for diagonal, or NULL
163  * da <-- diagonal values (NULL if zero)
164  * xa <-- extradiagonal values (NULL if zero)
165  *----------------------------------------------------------------------------*/
166 
167 void
168 cs_multigrid_build(const char *var_name,
169  int verbosity,
170  int postprocess_block_size,
171  int aggregation_limit,
172  int n_max_levels,
173  cs_gnum_t n_g_cells_min,
174  double p0p1_relax,
175  bool symmetric,
176  const int *diag_block_size,
177  const cs_real_t *da,
178  const cs_real_t *xa);
179 
180 /*----------------------------------------------------------------------------
181  * Destroy a hierarchy of meshes starting from a fine mesh, keeping
182  * the corresponding system and postprocessing information for future calls.
183  *
184  * parameters:
185  * var_name <-- variable name
186  *----------------------------------------------------------------------------*/
187 
188 void
189 cs_multigrid_destroy(const char *var_name);
190 
191 /*----------------------------------------------------------------------------
192  * Sparse linear system resolution using multigrid.
193  *
194  * parameters:
195  * var_name <-- Variable name
196  * descent_smoother_type <-- Type of smoother for descent (PCG, Jacobi, ...)
197  * ascent_smoother_type <-- Type of smoother for ascent (PCG, Jacobi, ...)
198  * coarse_solver_type <-- Type of solver (PCG, Jacobi, ...)
199  * abort_on_divergence <-- Call errorhandler if divergence is detected
200  * poly_degree <-- Preconditioning polynomial degree (0: diagonal)
201  * rotation_mode <-- Halo update option for rotational periodicity
202  * verbosity <-- Verbosity level
203  * n_max_cycles <-- Maximum number of cycles
204  * n_max_iter_descent <-- Maximum nb. of iterations for descent phases
205  * n_max_iter_ascent <-- Maximum nb. of iterations for ascent phases
206  * n_max_iter_coarse <-- Maximum nb. of iterations for coarsest solution
207  * precision <-- Precision limit
208  * r_norm <-- Residue normalization
209  * n_cycles --> Number of cycles
210  * n_iter --> Number of iterations
211  * residue <-> Residue
212  * rhs <-- Right hand side
213  * vx --> System solution
214  * aux_size <-- Number of elements in aux_vectors
215  * aux_vectors --- Optional working area (allocation otherwise)
216  *
217  * returns:
218  * 1 if converged, 0 if not converged, -1 if not converged and maximum
219  * cycle number reached, -2 if divergence is detected.
220  *----------------------------------------------------------------------------*/
221 
222 int
223 cs_multigrid_solve(const char *var_name,
224  cs_sles_type_t descent_smoother_type,
225  cs_sles_type_t ascent_smoother_type,
226  cs_sles_type_t coarse_solver_type,
227  bool abort_on_divergence,
228  int poly_degree,
229  cs_halo_rotation_t rotation_mode,
230  int verbosity,
231  int n_max_cycles,
232  int n_max_iter_descent,
233  int n_max_iter_ascent,
234  int n_max_iter_coarse,
235  double precision,
236  double r_norm,
237  int *n_cycles,
238  int *n_iter,
239  double *residue,
240  const cs_real_t *rhs,
241  cs_real_t *vx,
242  size_t aux_size,
243  void *aux_vectors);
244 
245 /*----------------------------------------------------------------------------*/
246 
248 
249 #endif /* __CS_MULTIGRID_H__ */
cs_halo_rotation_t
Definition: cs_halo.h:59
void cs_multigrid_destroy(const char *var_name)
Definition: cs_multigrid.c:2273
#define BEGIN_C_DECLS
Definition: cs_defs.h:365
integer, save ngrmax
Definition: mltgrd.f90:49
int cs_multigrid_solve(const char *var_name, cs_sles_type_t descent_smoother_type, cs_sles_type_t ascent_smoother_type, cs_sles_type_t coarse_solver_type, bool abort_on_divergence, int poly_degree, cs_halo_rotation_t rotation_mode, int verbosity, int n_max_cycles, int n_max_iter_descent, int n_max_iter_ascent, int n_max_iter_coarse, double precision, double r_norm, int *n_cycles, int *n_iter, double *residue, const cs_real_t *rhs, cs_real_t *vx, size_t aux_size, void *aux_vectors)
Definition: cs_multigrid.c:2331
void resmgr(const char *cname, const cs_int_t *lname, const cs_int_t *ncelet, const cs_int_t *ncel, const cs_int_t *nfac, const cs_int_t *iresds, const cs_int_t *iresas, const cs_int_t *ireslp, const cs_int_t *ipol, const cs_int_t *ncymxp, const cs_int_t *nitmds, const cs_int_t *nitmas, const cs_int_t *nitmap, const cs_int_t *iinvpe, const cs_int_t *iwarnp, cs_int_t *ncyclf, cs_int_t *niterf, const cs_real_t *epsilp, const cs_real_t *rnorm, cs_real_t *residu, const cs_real_t *rhs, cs_real_t *vx)
Definition: cs_multigrid.c:1843
int cs_int_t
Definition: cs_defs.h:263
BEGIN_C_DECLS void clmlga(const char *cname, const cs_int_t *lname, const cs_int_t *isym, const cs_int_t *ibsize, const cs_int_t *nagmax, const cs_int_t *ncpost, const cs_int_t *iwarnp, const cs_int_t *ngrmax, const cs_int_t *ncegrm, const cs_real_t *rlxp1, const cs_real_t *dam, const cs_real_t *xam)
Definition: cs_multigrid.c:1778
integer, save nfac
Definition: mesh.f90:42
void cs_multigrid_finalize(void)
Definition: cs_multigrid.c:1956
double precision, save rlxp1
Definition: optcal.f90:234
unsigned cs_gnum_t
Definition: cs_defs.h:255
integer, save ncelet
Definition: mesh.f90:42
void cs_multigrid_initialize(void)
Definition: cs_multigrid.c:1947
integer, save ncel
Definition: mesh.f90:42
#define END_C_DECLS
Definition: cs_defs.h:366
double cs_real_t
Definition: cs_defs.h:264
#define CS_PROCF(x, y)
Definition: cs_defs.h:379
cs_sles_type_t
Definition: cs_sles.h:54
void dsmlga(const char *cname, const cs_int_t *lname)
Definition: cs_multigrid.c:1824
void cs_multigrid_build(const char *var_name, int verbosity, int postprocess_block_size, int aggregation_limit, int n_max_levels, cs_gnum_t n_g_cells_min, double p0p1_relax, bool symmetric, const int *diag_block_size, const cs_real_t *da, const cs_real_t *xa)
Definition: cs_multigrid.c:1999
integer, save ncegrm
Definition: mltgrd.f90:49