1 #ifndef __CS_CDOVB_SCALEQ_H__
2 #define __CS_CDOVB_SCALEQ_H__
3 
4 /*============================================================================
5  * Build an algebraic CDO vertex-based system for unsteady convection diffusion
6  * reaction of scalar-valued equations with source terms
7  *============================================================================*/
8 
9 /*
10   This file is part of Code_Saturne, a general-purpose CFD tool.
11 
12   Copyright (C) 1998-2021 EDF S.A.
13 
14   This program is free software; you can redistribute it and/or modify it under
15   the terms of the GNU General Public License as published by the Free Software
16   Foundation; either version 2 of the License, or (at your option) any later
17   version.
18 
19   This program is distributed in the hope that it will be useful, but WITHOUT
20   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
22   details.
23 
24   You should have received a copy of the GNU General Public License along with
25   this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
26   Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 */
28 
29 /*----------------------------------------------------------------------------
30  *  Local headers
31  *----------------------------------------------------------------------------*/
32 
33 #include "cs_base.h"
34 #include "cs_cdo_connect.h"
35 #include "cs_cdo_local.h"
36 #include "cs_cdo_quantities.h"
37 #include "cs_equation_common.h"
38 #include "cs_equation_param.h"
39 #include "cs_field.h"
40 #include "cs_matrix.h"
41 #include "cs_mesh.h"
42 #include "cs_source_term.h"
43 #include "cs_time_step.h"
44 
45 /*----------------------------------------------------------------------------*/
46 
47 BEGIN_C_DECLS
48 
49 /*============================================================================
50  * Macro definitions
51  *============================================================================*/
52 
53 /*============================================================================
54  * Public function prototypes
55  *============================================================================*/
56 
57 /*----------------------------------------------------------------------------*/
58 /*!
59  * \brief    Check if the generic structures for building a CDO-Vb scheme are
60  *           allocated
61  *
62  * \return  true or false
63  */
64 /*----------------------------------------------------------------------------*/
65 
66 bool
67 cs_cdovb_scaleq_is_initialized(void);
68 
69 /*----------------------------------------------------------------------------*/
70 /*!
71  * \brief    Allocate work buffer and general structures related to CDO
72  *           vertex-based schemes
73  *           Set shared pointers.
74  *
75  * \param[in]  quant       additional mesh quantities struct.
76  * \param[in]  connect     pointer to a cs_cdo_connect_t struct.
77  * \param[in]  time_step   pointer to a time step structure
78  * \param[in]  ms          pointer to a cs_matrix_structure_t structure
79  */
80 /*----------------------------------------------------------------------------*/
81 
82 void
83 cs_cdovb_scaleq_init_common(const cs_cdo_quantities_t    *quant,
84                             const cs_cdo_connect_t       *connect,
85                             const cs_time_step_t         *time_step,
86                             const cs_matrix_structure_t  *ms);
87 
88 /*----------------------------------------------------------------------------*/
89 /*!
90  * \brief  Retrieve work buffers used for building a CDO system cellwise
91  *
92  * \param[out]  csys   pointer to a pointer on a cs_cell_sys_t structure
93  * \param[out]  cb     pointer to a pointer on a cs_cell_builder_t structure
94  */
95 /*----------------------------------------------------------------------------*/
96 
97 void
98 cs_cdovb_scaleq_get(cs_cell_sys_t       **csys,
99                     cs_cell_builder_t   **cb);
100 
101 /*----------------------------------------------------------------------------*/
102 /*!
103  * \brief  Free work buffer and general structure related to CDO vertex-based
104  *         schemes
105  */
106 /*----------------------------------------------------------------------------*/
107 
108 void
109 cs_cdovb_scaleq_finalize_common(void);
110 
111 /*----------------------------------------------------------------------------*/
112 /*!
113  * \brief  Initialize a cs_cdovb_scaleq_t structure storing data useful
114  *         for building and managing such a scheme
115  *
116  * \param[in]      eqp         pointer to a \ref cs_equation_param_t structure
117  * \param[in]      var_id      id of the variable field
118  * \param[in]      bflux_id    id of the boundary flux field
119  * \param[in, out] eqb         pointer to a \ref cs_equation_builder_t struct.
120  *
121  * \return a pointer to a new allocated cs_cdovb_scaleq_t structure
122  */
123 /*----------------------------------------------------------------------------*/
124 
125 void  *
126 cs_cdovb_scaleq_init_context(const cs_equation_param_t   *eqp,
127                              int                          var_id,
128                              int                          bflux_id,
129                              cs_equation_builder_t       *eqb);
130 
131 /*----------------------------------------------------------------------------*/
132 /*!
133  * \brief  Destroy a cs_cdovb_scaleq_t structure
134  *
135  * \param[in, out]  builder   pointer to a cs_cdovb_scaleq_t structure
136  *
137  * \return a NULL pointer
138  */
139 /*----------------------------------------------------------------------------*/
140 
141 void *
142 cs_cdovb_scaleq_free_context(void   *builder);
143 
144 /*----------------------------------------------------------------------------*/
145 /*!
146  * \brief  Set the initial values of the variable field taking into account
147  *         the boundary conditions.
148  *         Case of scalar-valued CDO-Vb schemes.
149  *
150  * \param[in]      t_eval     time at which one evaluates BCs
151  * \param[in]      field_id   id related to the variable field of this equation
152  * \param[in]      mesh       pointer to a cs_mesh_t structure
153  * \param[in]      eqp        pointer to a cs_equation_param_t structure
154  * \param[in, out] eqb        pointer to a cs_equation_builder_t structure
155  * \param[in, out] context    pointer to the scheme context (cast on-the-fly)
156  */
157 /*----------------------------------------------------------------------------*/
158 
159 void
160 cs_cdovb_scaleq_init_values(cs_real_t                     t_eval,
161                             const int                     field_id,
162                             const cs_mesh_t              *mesh,
163                             const cs_equation_param_t    *eqp,
164                             cs_equation_builder_t        *eqb,
165                             void                         *context);
166 
167 /*----------------------------------------------------------------------------*/
168 /*!
169  * \brief  Build and solve the linear system arising from a scalar steady-state
170  *         convection/diffusion/reaction equation with a CDO-Vb scheme
171  *         One works cellwise and then process to the assembly
172  *
173  * \param[in]      cur2prev   true="current to previous" operation is performed
174  * \param[in]      mesh       pointer to a cs_mesh_t structure
175  * \param[in]      field_id   id of the variable field related to this equation
176  * \param[in]      eqp        pointer to a cs_equation_param_t structure
177  * \param[in, out] eqb        pointer to a cs_equation_builder_t structure
178  * \param[in, out] context    pointer to cs_cdovb_scaleq_t structure
179  */
180 /*----------------------------------------------------------------------------*/
181 
182 void
183 cs_cdovb_scaleq_solve_steady_state(bool                        cur2prev,
184                                    const cs_mesh_t            *mesh,
185                                    const int                   field_id,
186                                    const cs_equation_param_t  *eqp,
187                                    cs_equation_builder_t      *eqb,
188                                    void                       *context);
189 
190 /*----------------------------------------------------------------------------*/
191 /*!
192  * \brief  Build and solve the linear system arising from a scalar unsteady
193  *         convection/diffusion/reaction equation with a CDO-Vb scheme
194  *         Implicit time scheme is used to progress in time.
195  *         One works cellwise and then process to the assembly
196  *
197  * \param[in]      cur2prev   true="current to previous" operation is performed
198  * \param[in]      mesh       pointer to a cs_mesh_t structure
199  * \param[in]      field_id   id of the variable field related to this equation
200  * \param[in]      eqp        pointer to a cs_equation_param_t structure
201  * \param[in, out] eqb        pointer to a cs_equation_builder_t structure
202  * \param[in, out] context    pointer to cs_cdovb_scaleq_t structure
203  */
204 /*----------------------------------------------------------------------------*/
205 
206 void
207 cs_cdovb_scaleq_solve_implicit(bool                        cur2prev,
208                                const cs_mesh_t            *mesh,
209                                const int                   field_id,
210                                const cs_equation_param_t  *eqp,
211                                cs_equation_builder_t      *eqb,
212                                void                       *context);
213 
214 /*----------------------------------------------------------------------------*/
215 /*!
216  * \brief  Build and solve the linear system arising from a scalar unsteady
217  *         convection/diffusion/reaction equation with a CDO-Vb scheme
218  *         Theta time scheme is used to progress in time.
219  *         One works cellwise and then process to the assembly
220  *
221  * \param[in]      cur2prev   true="current to previous" operation is performed
222  * \param[in]      mesh       pointer to a cs_mesh_t structure
223  * \param[in]      field_id   id of the variable field related to this equation
224  * \param[in]      eqp        pointer to a cs_equation_param_t structure
225  * \param[in, out] eqb        pointer to a cs_equation_builder_t structure
226  * \param[in, out] context    pointer to cs_cdovb_scaleq_t structure
227  */
228 /*----------------------------------------------------------------------------*/
229 
230 void
231 cs_cdovb_scaleq_solve_theta(bool                        cur2prev,
232                             const cs_mesh_t            *mesh,
233                             const int                   field_id,
234                             const cs_equation_param_t  *eqp,
235                             cs_equation_builder_t      *eqb,
236                             void                       *context);
237 
238 /*----------------------------------------------------------------------------*/
239 /*!
240  * \brief  Retrieve an array of values at mesh vertices for the variable field
241  *         associated to the given context
242  *         The lifecycle of this array is managed by the code. So one does not
243  *         have to free the return pointer.
244  *
245  * \param[in, out]  context    pointer to a data structure cast on-the-fly
246  * \param[in]       previous   retrieve the previous state (true/false)
247  *
248  * \return  a pointer to an array of cs_real_t (size: n_vertices)
249  */
250 /*----------------------------------------------------------------------------*/
251 
252 cs_real_t *
253 cs_cdovb_scaleq_get_vertex_values(void        *context,
254                                   bool         previous);
255 
256 /*----------------------------------------------------------------------------*/
257 /*!
258  * \brief  Compute an array of values at mesh cells by interpolating the
259  *         variable field associated to the given context located at mesh
260  *         vertices
261  *         The lifecycle of this array is managed by the code. So one does not
262  *         have to free the return pointer.
263  *
264  * \param[in, out]  context    pointer to a data structure cast on-the-fly
265  * \param[in]       previous   retrieve the previous state (true/false)
266  *
267  * \return  a pointer to an array of cs_real_t (size: n_cells)
268  */
269 /*----------------------------------------------------------------------------*/
270 
271 cs_real_t *
272 cs_cdovb_scaleq_get_cell_values(void      *context,
273                                 bool       previous);
274 
275 /*----------------------------------------------------------------------------*/
276 /*!
277  * \brief  Compute the balance for an equation over the full computational
278  *         domain between time t_cur and t_cur + dt_cur
279  *         Case of scalar-valued CDO vertex-based scheme
280  *
281  * \param[in]      eqp      pointer to a \ref cs_equation_param_t structure
282  * \param[in, out] eqb      pointer to a \ref cs_equation_builder_t structure
283  * \param[in, out] context  pointer to a scheme builder structure
284  *
285  * \return a pointer to a \ref cs_equation_balance_t structure
286  */
287 /*----------------------------------------------------------------------------*/
288 
289 cs_equation_balance_t *
290 cs_cdovb_scaleq_balance(const cs_equation_param_t     *eqp,
291                         cs_equation_builder_t         *eqb,
292                         void                          *context);
293 
294 /*----------------------------------------------------------------------------*/
295 /*!
296  * \brief  Compute for each vertex of a boundary face, the portion of diffusive
297  *         flux across the boundary face. The surface attached to each vertex
298  *         corresponds to the intersection of its dual cell (associated to
299  *         a vertex of the face) with the face.
300  *         Case of scalar-valued CDO-Vb schemes
301  *
302  * \param[in]       t_eval     time at which one performs the evaluation
303  * \param[in]       eqp        pointer to a cs_equation_param_t structure
304  * \param[in]       pdi        pointer to an array of field values
305  * \param[in, out]  eqb        pointer to a cs_equation_builder_t structure
306  * \param[in, out]  context    pointer to a scheme builder structure
307  * \param[in, out]  vf_flux    pointer to the values of the diffusive flux
308  */
309 /*----------------------------------------------------------------------------*/
310 
311 void
312 cs_cdovb_scaleq_boundary_diff_flux(const cs_real_t              t_eval,
313                                    const cs_equation_param_t   *eqp,
314                                    const cs_real_t             *pdi,
315                                    cs_equation_builder_t       *eqb,
316                                    void                        *context,
317                                    cs_real_t                   *vf_flux);
318 
319 /*----------------------------------------------------------------------------*/
320 /*!
321  * \brief  Compute the diffusive and convective flux across a list of faces
322  *         Case of scalar-valued CDO-Vb schemes
323  *
324  * \param[in]       normal     indicate in which direction flux is > 0
325  * \param[in]       pdi        pointer to an array of field values
326  * \param[in]       eqp        pointer to a cs_equation_param_t structure
327  * \param[in]       ml_id      id related to a cs_mesh_location_t struct.
328  * \param[in, out]  eqb        pointer to a cs_equation_builder_t structure
329  * \param[in, out]  context    pointer to data specific for this scheme
330  * \param[in, out]  d_flux     pointer to the value of the diffusive flux
331  * \param[in, out]  c_flux     pointer to the value of the convective flux
332  */
333 /*----------------------------------------------------------------------------*/
334 
335 void
336 cs_cdovb_scaleq_flux_across_plane(const cs_real_t             normal[],
337                                   const cs_real_t            *pdi,
338                                   const cs_equation_param_t  *eqp,
339                                   int                         ml_id,
340                                   cs_equation_builder_t      *eqb,
341                                   void                       *context,
342                                   double                     *d_flux,
343                                   double                     *c_flux);
344 
345 /*----------------------------------------------------------------------------*/
346 /*!
347  * \brief  Cellwise computation of an approximation of a constant diffusive
348  *         flux (a vector) in each cell.
349  *         Case of scalar-valued CDO-Vb schemes
350  *
351  * \param[in]       values      discrete values for the potential
352  * \param[in]       eqp         pointer to a cs_equation_param_t structure
353  * \param[in]       t_eval      time at which one performs the evaluation
354  * \param[in, out]  eqb         pointer to a cs_equation_builder_t structure
355  * \param[in, out]  context     pointer to cs_cdovb_scaleq_t structure
356  * \param[in, out]  diff_flux   value of the diffusive flux
357   */
358 /*----------------------------------------------------------------------------*/
359 
360 void
361 cs_cdovb_scaleq_diff_flux_in_cells(const cs_real_t             *values,
362                                    const cs_equation_param_t   *eqp,
363                                    cs_real_t                    t_eval,
364                                    cs_equation_builder_t       *eqb,
365                                    void                        *context,
366                                    cs_real_t                   *diff_flux);
367 
368 /*----------------------------------------------------------------------------*/
369 /*!
370  * \brief  Cellwise computation of the diffusive flux accross dual faces
371  *         (a scalar) in each cell.
372  *         Case of scalar-valued CDO-Vb schemes
373  *
374  * \param[in]       values      discrete values for the potential
375  * \param[in]       eqp         pointer to a cs_equation_param_t structure
376  * \param[in]       t_eval      time at which one performs the evaluation
377  * \param[in, out]  eqb         pointer to a cs_equation_builder_t structure
378  * \param[in, out]  context     pointer to cs_cdovb_scaleq_t structure
379  * \param[in, out]  diff_flux   value of the diffusive flux
380   */
381 /*----------------------------------------------------------------------------*/
382 
383 void
384 cs_cdovb_scaleq_diff_flux_dfaces(const cs_real_t             *values,
385                                  const cs_equation_param_t   *eqp,
386                                  cs_real_t                    t_eval,
387                                  cs_equation_builder_t       *eqb,
388                                  void                        *context,
389                                  cs_real_t                   *diff_flux);
390 
391 /*----------------------------------------------------------------------------*/
392 /*!
393  * \brief  Operate a current to previous operation for the field associated to
394  *         this equation and potentially for related fields/arrays.
395  *
396  * \param[in]       eqp        pointer to a cs_equation_param_t structure
397  * \param[in, out]  eqb        pointer to a cs_equation_builder_t structure
398  * \param[in, out]  context    pointer to cs_cdovb_scaleq_t structure
399  */
400 /*----------------------------------------------------------------------------*/
401 
402 void
403 cs_cdovb_scaleq_current_to_previous(const cs_equation_param_t  *eqp,
404                                     cs_equation_builder_t      *eqb,
405                                     void                       *context);
406 
407 /*----------------------------------------------------------------------------*/
408 /*!
409  * \brief  Predefined extra-operations related to this equation
410  *
411  * \param[in]       eqp        pointer to a cs_equation_param_t structure
412  * \param[in, out]  eqb        pointer to a cs_equation_builder_t structure
413  * \param[in, out]  context    pointer to cs_cdovb_scaleq_t structure
414  */
415 /*----------------------------------------------------------------------------*/
416 
417 void
418 cs_cdovb_scaleq_extra_post(const cs_equation_param_t  *eqp,
419                            cs_equation_builder_t      *eqb,
420                            void                       *context);
421 
422 /*----------------------------------------------------------------------------*/
423 
424 END_C_DECLS
425 
426 #endif /* __CS_CDOVB_SCALEQ_H__ */
427