1 #ifndef __CS_SOLIDIFICATION_H__
2 #define __CS_SOLIDIFICATION_H__
3 
4 /*============================================================================
5  * Header to handle the solidification module with CDO schemes
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_base.h"
33 #include "cs_boundary.h"
34 #include "cs_equation.h"
35 #include "cs_iter_algo.h"
36 #include "cs_navsto_param.h"
37 #include "cs_time_plot.h"
38 #include "cs_time_step.h"
39 
40 /*----------------------------------------------------------------------------*/
41 
42 BEGIN_C_DECLS
43 
44 /*============================================================================
45  * Macro definitions
46  *============================================================================*/
47 
48 /*!
49  * @name Flags specifying automatic post-processing for the solidification
50  *        module
51  * @{
52  *
53  * \def CS_SOLIDIFICATION_POST_CELL_STATE
54  * \brief State related to each cell between (solid, mushy, liquid or eutectic)
55  *
56  * \def CS_SOLIDIFICATION_POST_ENTHALPY
57  * \brief Enthalpy in each cell. By default, only the temperature is
58  *        post-processed
59  *
60  * \def CS_SOLIDIFICATION_POST_CBULK_ADIM
61  * \brief Compute and post-process (C_bulk - C_0)/C_0
62  *        Only available if the model \ref CS_SOLIDIFICATION_MODEL_BINARY_ALLOY
63  *        is activated
64  *        C_0 is the reference concentration
65  *
66  * \def CS_SOLIDIFICATION_POST_CLIQ
67  * \brief Post-process Cliq the liquid solute distribution (wt %)
68  *        Only available if the model \ref CS_SOLIDIFICATION_MODEL_BINARY_ALLOY
69  *        is activated.
70  *
71  * \def CS_SOLIDIFICATION_POST_LIQUIDUS_TEMPERATURE
72  * \brief Activate the (volumic) post-processing of the liquidus temperature
73  *        in each cell
74  *
75  * \def CS_SOLIDIFICATION_POST_SEGREGATION_INDEX
76  * \brief Activate the computation and output in the file solidification.dat
77  *        for each time step of the segregation index defined by
78  *        sqrt( 1/|Domaine| * \int_{Domain} ((C_bulk - C_0)/C_0)**2 )
79  *        Only available if the model \ref CS_SOLIDIFICATION_MODEL_BINARY_ALLOY
80  *        is activated
81  *
82  * \def CS_SOLIDIFICATION_POST_SOLIDIFICATION_RATE
83  * \brief Activate the computation and output in the file solidification.dat
84  *        for each time step of the integral over the computational domain
85  *        of the solid fraction divided by the volume of the domain.
86  *
87  * \def CS_SOLIDIFICATION_ADVANCED_ANALYSIS
88  * \brief Activate a set of post-processing (Advanced usage. Only for the
89  * understanding of the solidification process)
90 */
91 
92 #define CS_SOLIDIFICATION_POST_CELL_STATE             (1 << 0) /* =   1 */
93 #define CS_SOLIDIFICATION_POST_ENTHALPY               (1 << 1) /* =   2 */
94 #define CS_SOLIDIFICATION_POST_CBULK_ADIM             (1 << 2) /* =   4 */
95 #define CS_SOLIDIFICATION_POST_CLIQ                   (1 << 3) /* =   8 */
96 #define CS_SOLIDIFICATION_POST_LIQUIDUS_TEMPERATURE   (1 << 4) /* =  16 */
97 #define CS_SOLIDIFICATION_POST_SEGREGATION_INDEX      (1 << 5) /* =  32 */
98 #define CS_SOLIDIFICATION_POST_SOLIDIFICATION_RATE    (1 << 6) /* =  64 */
99 #define CS_SOLIDIFICATION_ADVANCED_ANALYSIS           (1 << 7) /* = 128 */
100 
101 /*!
102  * @name Flags specifying options specific to the solidification module
103  * @{
104  *
105  * \def CS_SOLIDIFICATION_USE_ENTHALPY_VARIABLE
106  * \brief The dynamic system of equations is associated with an energy equation
107  *        solved using the enthalpy as variable (not fully available).
108  *
109  * \def CS_SOLIDIFICATION_NO_VELOCITY_FIELD
110  * \brief The system of equations does not involve the Navier-Stokes equations.
111  *        No velocity is taken into account.
112  *
113  * \def CS_SOLIDIFICATION_WITH_SOLUTE_SOURCE_TERM
114  * \brief The solute equation related to the transport of the bulk concentration
115  *        is treated with a source term related to an explicit advection of the
116  *        quantity (C - Cl). The default behavior is to add a weighting
117  *        coefficient to the (implicit) advection term related to the liquid
118  *        fraction
119  *        This option is related to the LEGACY strategy.
120  *
121  * \def CS_SOLIDIFICATION_USE_EXTRAPOLATION
122  * \brief Use an extrapolation during the computation of different terms
123  *        according to the strategy. This extrapolation of variable at time
124  *        step n+1 uses values at n and n-1: 2*u^n - u^{n-1}
125  *
126  * \def CS_SOLIDIFICATION_WITH_PENALIZED_EUTECTIC
127  * \brief Option related to the PATH strategy.
128  *        Introduce a reaction term and a source term in order to remain on
129  *        the eutectic plateau.
130  */
131 
132 #define CS_SOLIDIFICATION_USE_ENTHALPY_VARIABLE             (1 << 0) /*=    1 */
133 #define CS_SOLIDIFICATION_NO_VELOCITY_FIELD                 (1 << 1) /*=    2 */
134 #define CS_SOLIDIFICATION_WITH_SOLUTE_SOURCE_TERM           (1 << 2) /*=    4 */
135 #define CS_SOLIDIFICATION_USE_EXTRAPOLATION                 (1 << 3) /*=    8 */
136 #define CS_SOLIDIFICATION_WITH_PENALIZED_EUTECTIC           (1 << 4) /*=   16 */
137 
138 /* Automatically set by the code if user functions are used
139  * The following flags are set when calling \ref cs_solidification_set_functions
140  *
141  * \def CS_SOLIDIFICATION_BINARY_ALLOY_M_FUNC
142  * \brief the update of the forcing term (penalization) in the momentum equation
143  *        is defined using a user function
144  *
145  * \def CS_SOLIDIFICATION_BINARY_ALLOY_C_FUNC
146  * \brief the update of the liquid concentration of the binary alloy is defined
147  *        using a user function
148  *
149  * \def CS_SOLIDIFICATION_BINARY_ALLOY_G_FUNC
150  * \brief the update of the liquid fraction is defined using a user function
151  *
152  * \def CS_SOLIDIFICATION_BINARY_ALLOY_T_FUNC
153  * \brief the update of the thermal source term is defined using a user function
154  */
155 #define CS_SOLIDIFICATION_BINARY_ALLOY_M_FUNC               (1 << 7) /*=  128 */
156 #define CS_SOLIDIFICATION_BINARY_ALLOY_C_FUNC               (1 << 8) /*=  256 */
157 #define CS_SOLIDIFICATION_BINARY_ALLOY_G_FUNC               (1 << 9) /*=  512 */
158 #define CS_SOLIDIFICATION_BINARY_ALLOY_T_FUNC               (1 <<10) /*= 1024 */
159 
160 /*!
161  * @}
162  */
163 
164 /*=============================================================================
165  * Structure and type definitions
166  *============================================================================*/
167 
168 /*! \enum cs_solidification_model_t
169  *  \brief Type of physical model used to simulate the solidifcation/fusion
170  *         process
171  *
172  * \var CS_SOLIDIFICATION_MODEL_STEFAN
173  *      Phase change model without advection field. The phase change is assumed
174  *      to be at a given temperature meaning that the liquid fraction is a step
175  *      function w.r.t. the temperature.
176  *
177  * \var CS_SOLIDIFICATION_MODEL_VOLLER_PRAKASH_87
178  *      Modelling introduced in Voller and Prakash entitled: "A fixed grid
179  *      numerical modelling methodology for convection-diffusion mushy region
180  *      phase-change problems" Int. J. Heat Transfer, 30 (8), 1987.  No
181  *      tracer. Only physical constants describing the solidification process
182  *      are used.
183  *
184  * \var CS_SOLIDIFICATION_MODEL_VOLLER_NL
185  *      Modelling based on \ref CS_SOLIDIFICATION_MODEL_VOLLER_PRAKASH_87 but
186  *      the thermal equation and the update of the liquid fraction is non-linear
187  *
188  * \var CS_SOLIDIFICATION_MODEL_BINARY_ALLOY
189  *      The basis is similar to \ref CS_SOLIDIFICATION_MODEL_VOLLER_PRAKASH_87
190  *      A tracer equation is added corresponding to the evolution of the bulk
191  *      concentration in alloy. This alloy has two chemical constituents hence
192  *      the name "binary alloy".
193  */
194 
195 typedef enum {
196 
197   CS_SOLIDIFICATION_MODEL_STEFAN,
198   CS_SOLIDIFICATION_MODEL_VOLLER_PRAKASH_87,
199   CS_SOLIDIFICATION_MODEL_VOLLER_NL,
200   CS_SOLIDIFICATION_MODEL_BINARY_ALLOY,
201 
202   CS_SOLIDIFICATION_N_MODELS
203 
204 } cs_solidification_model_t;
205 
206 /*! \enum cs_solidification_state_t
207  *  \brief Kind of state in which a cell or an entity is
208  *
209  * \var CS_SOLIDIFICATION_STATE_SOLID
210  *      Solid state (the liquid fraction is equal to 0)
211  *
212  * \var CS_SOLIDIFICATION_STATE_MUSHY
213  *      Mushy state meaning that the liquid fraction is strictly below 1 and
214  *      strictly above 0.
215  *
216  * \var CS_SOLIDIFICATION_STATE_LIQUID
217  *      Liquid state (the liquid fraction is equal to 1)
218  *
219  * \var CS_SOLIDIFICATION_STATE_EUTECTIC
220  *      Eutectic state. Only possible with a \ref
221  *      CS_SOLIDIFICATION_MODEL_BINARY_ALLOY model. A rough transition between
222  *      the mushy and solid state occurs when an eutectic transition happens.
223  */
224 
225 typedef enum {
226 
227   CS_SOLIDIFICATION_STATE_SOLID    = 0,
228   CS_SOLIDIFICATION_STATE_MUSHY    = 1,
229   CS_SOLIDIFICATION_STATE_LIQUID   = 2,
230   CS_SOLIDIFICATION_STATE_EUTECTIC = 3,
231 
232   CS_SOLIDIFICATION_N_STATES       = 4,
233 
234 } cs_solidification_state_t;
235 
236 /*! \enum cs_solidification_strategy_t
237  *  \brief Kind of strategy to use to model the segregation/solidification
238  *         process. This implies a setting of functions to update the liquid
239  *         fraction, the thermal source terms, the liquid concentration and its
240  *         related quantities.
241  */
242 
243 typedef enum {
244 
245   CS_SOLIDIFICATION_STRATEGY_LEGACY,
246   CS_SOLIDIFICATION_STRATEGY_TAYLOR,
247   CS_SOLIDIFICATION_STRATEGY_PATH,
248 
249   CS_SOLIDIFICATION_N_STRATEGIES
250 
251 } cs_solidification_strategy_t;
252 
253 /*----------------------------------------------------------------------------*/
254 /*!
255  * \brief  Function pointer associated to a solidification model aiming at
256  *         updating/initializing the solidification variables/properties
257  *         dedicated to the model
258  *
259  * \param[in]  mesh       pointer to a cs_mesh_t structure
260  * \param[in]  connect    pointer to a cs_cdo_connect_t structure
261  * \param[in]  quant      pointer to a cs_cdo_quantities_t structure
262  * \param[in]  ts         pointer to a cs_time_step_t structure
263  */
264 /*----------------------------------------------------------------------------*/
265 
266 typedef void
267 (cs_solidification_func_t)(const cs_mesh_t             *mesh,
268                            const cs_cdo_connect_t      *connect,
269                            const cs_cdo_quantities_t   *quant,
270                            const cs_time_step_t        *ts);
271 
272 /* Structure storing physical parameters related to a choice of solidification
273    modelling */
274 
275 /*----------------------------------------------------------------------------
276  * Stefan model
277  *----------------------------------------------------------------------------
278  *
279  * Neither advection nor segregation is taken into account.
280  * The liquid fraction is a step function w.r.t. the temperature.
281  */
282 
283 typedef struct {
284 
285   /* Physical parameters to specify the law of variation of the liquid fraction
286    * with respect to the temperature
287    *
288    * gl(T) = 1 if T > T_change
289    * Otherwise:
290    * gl(T) = 0
291    */
292 
293   cs_real_t                      t_change;
294 
295   /* Function pointers */
296   /* ----------------- */
297 
298   /* Function to update the liquid fraction */
299 
300   cs_solidification_func_t      *update_gl;
301 
302   /* Function to update the source term for the thermal equation */
303 
304   cs_solidification_func_t      *update_thm_st;
305 
306   /* Numerical parameters */
307   /* -------------------- */
308 
309   int                            n_iter_max;
310   double                         max_delta_h;
311 
312 } cs_solidification_stefan_t;
313 
314 
315 /* Voller and Prakash model "A fixed grid numerical modelling methodology for
316  * convection-diffusion mushy region phase-change problems" Int. J. Heat
317  * Transfer, 30 (8), 1987.
318  * No tracer. Only physical constants describing the solidification process are
319  * used.
320  */
321 
322 /*----------------------------------------------------------------------------
323  * Solidification without segregation (Voller & Prakash'87 model)
324  *----------------------------------------------------------------------------*/
325 
326 typedef struct {
327 
328   /* Secondary dendrite arm spacing */
329 
330   cs_real_t                      s_das;
331 
332   /* Physical parameters to specify the law of variation of the liquid fraction
333    * with respect to the temperature
334    *
335    * gl(T) = 1 if T > t_liquidus and gl(T) = 0 if T < t_solidus
336    * Otherwise:
337    * gl(T) = (T - t_solidus)/(t_liquidus - t_solidus)
338    */
339 
340   cs_real_t                      t_solidus;
341   cs_real_t                      t_liquidus;
342 
343   /* Function pointers */
344   /* ----------------- */
345 
346   /* Function to update the liquid fraction */
347 
348   cs_solidification_func_t      *update_gl;
349 
350   /* Function to update the source term for the thermal equation */
351 
352   cs_solidification_func_t      *update_thm_st;
353 
354   /* Numerical parameters */
355   /* -------------------- */
356 
357   cs_param_nl_algo_t             nl_algo_type;
358   cs_iter_algo_t                *nl_algo;
359 
360 } cs_solidification_voller_t;
361 
362 
363 /*----------------------------------------------------------------------------
364  * Solidification of a binary alloy with segregation (Voller & Prakash'89 model)
365  *----------------------------------------------------------------------------*/
366 
367 typedef struct {
368 
369   /* Alloy features */
370   /* -------------- */
371 
372   /* Reference mixture concentration (used in the Boussinesq approximation and
373    * for normalization */
374 
375   cs_real_t    ref_concentration;
376 
377   /* Phase diagram features for an alloy with the component A and B */
378   /* -------------------------------------------------------------- */
379 
380   /* Secondary dendrite arm spacing */
381 
382   cs_real_t    s_das;
383 
384   /* Physical parameters */
385 
386   cs_real_t    kp;       /* distribution coefficient */
387   cs_real_t    inv_kp;   /* reciprocal of kp */
388   cs_real_t    inv_kpm1; /* 1/(kp - 1) */
389   cs_real_t    ml;       /* Liquidus slope \frac{\partial g_l}{\partial C} */
390   cs_real_t    inv_ml;   /* reciprocal of ml */
391 
392   /* Temperature of phase change for the pure material (conc = 0) */
393 
394   cs_real_t    t_melt;
395 
396   /* Eutectic point: temperature and concentration */
397 
398   cs_real_t    t_eut;
399   cs_real_t    t_eut_inf;
400   cs_real_t    t_eut_sup;
401 
402   cs_real_t    c_eut;
403   cs_real_t    cs1;
404   cs_real_t    dgldC_eut;
405 
406   /* The variable related to this equation in the solute concentration of
407    * the mixture: c_bulk (c_s in the solid phase and c_l in the liquid phase)
408    * c_bulk = gs*c_s + gl*c_l where gs + gl = 1
409    * gl is the liquid fraction and gs the solid fraction
410    * c_s = kp * c_l (lever rule is assumed up to now)
411    *
412    * --> c_bulk = (gs*kp + gl)*c_l
413    */
414 
415   /* Function to update the liquid fraction */
416 
417   cs_solidification_func_t     *update_gl;
418 
419   /* Function to update the source term for the thermal equation */
420 
421   cs_solidification_func_t     *update_thm_st;
422 
423   /* Function to update the velocity forcing in the momentum equation */
424 
425   cs_solidification_func_t     *update_velocity_forcing;
426 
427   /* Function to update c_l in each cell */
428 
429   cs_solidification_func_t     *update_clc;
430 
431   /* Drive the convergence of the coupled system (solute transport and thermal
432    * equation) with respect to the following criteria (taken from Voller and
433    * Swaminathan'91)
434    *   max_{c\in C} |Temp^(k+1) - Temp^(k)| < delta_tolerance
435    *   max_{c\in C} |Cbulk^(k+1) - Cbulk*^(k)| < delta_tolerance
436    *   n_iter < n_iter_max
437    *
438    * eta_relax: add a relaxation in the update of the eta coefficient
439    * conc_liq = eta_coef * conc_bulk
440    * eta_relax = 0. --> No relaxation (default choice)
441    *
442    * gliq_relax: idem but for the liquid fraction
443    */
444 
445   int                              iter;
446   int                              n_iter_max;
447   double                           delta_tolerance;
448   double                           eta_relax;
449   double                           gliq_relax;
450 
451   /* During the non-linear iteration process one needs:
452    *  temp_{n}         --> stored in field->val_pre
453    *  temp_{n+1}^k     --> stored in tk_bulk (in this structure)
454    *  temp_{n+1}^{k+1} --> stored in field->val
455    *
456    * Optionally one may consider an extrapolated temperature and bulk
457    * concentration
458    *  temp_{n+1}^{extrap} = 2*temp_{n} - temp_{n-1}
459    *
460    * Same thing for the bulk concentration.
461    */
462 
463   cs_real_t         *tk_bulk;
464   cs_real_t         *ck_bulk;
465   cs_real_t         *tx_bulk;
466   cs_real_t         *cx_bulk;
467 
468   /* Solute concentration in the liquid phase
469    * 1) array of the last computed values at cells
470    * 2) array of the last computed values at faces (interior and border) */
471 
472   cs_real_t         *c_l_cells;
473   cs_real_t         *c_l_faces;
474 
475   /* Temperature values at faces (this is not owned by the structure) */
476 
477   const cs_real_t   *temp_faces;
478 
479   /* Equation for the solute transport and related quantities */
480 
481   cs_equation_t     *solute_equation;
482   cs_field_t        *c_bulk;
483 
484   /* Diffusion coefficient for the solute in the liquid phase
485    * diff_pty_val = rho * g_l * diff_coef */
486 
487   cs_real_t          diff_coef;
488   cs_property_t     *diff_pty;
489   cs_real_t         *diff_pty_array;
490 
491   cs_property_t     *eta_coef_pty;
492   cs_real_t         *eta_coef_array;
493 
494   /* Optional post-processing arrays */
495   /* ------------------------------ */
496 
497   /* Liquidus temperature (values at cell centers) */
498 
499   cs_real_t         *t_liquidus;
500 
501   /* Quantities for advanced analysis */
502 
503   cs_real_t         *tbulk_minus_tliq;
504   cs_real_t         *cliq_minus_cbulk;
505 
506 } cs_solidification_binary_alloy_t;
507 
508 /*----------------------------------------------------------------------------
509  * Main structure to manage the solidification process
510  *----------------------------------------------------------------------------*/
511 
512 typedef struct  {
513 
514   cs_flag_t        model;       /* Modelling for the solidification module */
515   cs_flag_t        options;     /* Flag dedicated to general options to handle
516                                  * the solidification module*/
517   cs_flag_t        post_flag;   /* Flag dedicated to the post-processing
518                                  * of the solidification module */
519   int              verbosity;   /* Level of verbosity */
520 
521   /* Physical properties common to all models */
522   /* ---------------------------------------- */
523 
524   /* Mass density of the liquid/solid media */
525 
526   cs_property_t   *mass_density;
527 
528   /* Reference value for the heat capacity in the solidification/melting area
529    * (assumed to be uniform) */
530 
531   cs_property_t   *cp;
532 
533   /* Viscosity (pointer to the total viscosity which should be equal to the
534   *  laminar viscosity since no turbulence modelling is usually taken into
535   *  account */
536 
537   cs_property_t   *viscosity;
538 
539   /* Physical parameter for computing the source term in the energy equation
540    * Latent heat between the liquid and solid phase
541    */
542 
543   cs_real_t        latent_heat;
544 
545 
546   /* Liquid fraction of the mixture */
547   /* ------------------------------ */
548 
549   cs_field_t      *g_l_field;   /* field storing the values of the liquid
550                                    fraction at each cell */
551   cs_property_t   *g_l;         /* liquid fraction property */
552 
553   /* array storing the state (solid, mushy, liquid) for each cell */
554 
555   cs_solidification_state_t     *cell_state;
556 
557   /* Plot evolution of the solidification process */
558 
559   cs_time_plot_t                *plot_state;
560 
561   /* Monitoring related to this module */
562 
563   cs_real_t        state_ratio[CS_SOLIDIFICATION_N_STATES];
564   cs_gnum_t        n_g_cells[CS_SOLIDIFICATION_N_STATES];
565 
566   /* Quantities related to the energy equation */
567   /* ----------------------------------------- */
568 
569   cs_thermal_system_t   *thermal_sys;
570 
571   /* Fields associated to this module */
572 
573   cs_field_t      *temperature;
574 
575   /* Enthalpy (by default this a derived field which can be used to update of
576      the liquid fraction) */
577 
578   cs_field_t      *enthalpy;
579 
580 
581   /* A reaction term and source term are introduced in the thermal model */
582 
583   cs_property_t   *thermal_reaction_coef;
584   cs_real_t       *thermal_reaction_coef_array;
585   cs_real_t       *thermal_source_term_array;
586 
587   /* Additional settings related to the choice of solidification modelling */
588 
589   void            *model_context;
590 
591   /* Strategy to update quantities during the solidification process. These
592    * quantities are the liquid fraction, the thermal source term for
593    * instance */
594 
595   cs_solidification_strategy_t   strategy;
596 
597   /* A reaction term is introduced in the momentum equation. This terms tends to
598    * a huge number when the liquid fraction tends to 0 in order to penalize
599    * the velocity to zero when the whole cell is solid
600    */
601 
602   cs_real_t       *forcing_mom_array; /* values of the forcing reaction
603                                          coefficient in each cell */
604   cs_property_t   *forcing_mom;
605 
606   /* Porous media like reaction term in the momentum equation:
607    *
608    * forcing_coef = 180 * visco0 / s_das^2
609    * where visco0 is the laminar viscosity and s_das is the secondary
610    * dendrite arm spacing
611    * F(u) = forcing_coef * (1- gl)^2/(gl^3 + forcing_eps) * u
612    */
613 
614   cs_real_t        forcing_coef;
615 
616   /* First cell associated to a fluid/solid area (i.e. not associated to
617    * a permanent solid zone) */
618 
619   cs_lnum_t        first_cell;
620 
621 } cs_solidification_t;
622 
623 /*============================================================================
624  * Public function prototypes
625  *============================================================================*/
626 
627 /*----------------------------------------------------------------------------*/
628 /*!
629  * \brief  Test if solidification module is activated
630  */
631 /*----------------------------------------------------------------------------*/
632 
633 bool
634 cs_solidification_is_activated(void);
635 
636 /*----------------------------------------------------------------------------*/
637 /*!
638  * \brief  Retrieve the main structure to deal with solidification process
639  *
640  * \return a pointer to a new allocated solidification structure
641  */
642 /*----------------------------------------------------------------------------*/
643 
644 cs_solidification_t *
645 cs_solidification_get_structure(void);
646 
647 /*----------------------------------------------------------------------------*/
648 /*!
649  * \brief  Set the level of verbosity for the solidification module
650  *
651  * \param[in]   verbosity     level of verbosity to set
652  */
653 /*----------------------------------------------------------------------------*/
654 
655 void
656 cs_solidification_set_verbosity(int   verbosity);
657 
658 /*----------------------------------------------------------------------------*/
659 /*!
660  * \brief  Set the value of the epsilon parameter used in the forcing term
661  *         of the momentum equation
662  *
663  * \param[in]  forcing_eps    epsilon used in the penalization term to avoid a
664  *                            division by zero
665  */
666 /*----------------------------------------------------------------------------*/
667 
668 void
669 cs_solidification_set_forcing_eps(cs_real_t    forcing_eps);
670 
671 /*----------------------------------------------------------------------------*/
672 /*!
673  * \brief  Activate the solidification module
674  *
675  * \param[in]  model            type of modelling
676  * \param[in]  options          flag to handle optional parameters
677  * \param[in]  post_flag        predefined post-processings
678  * \param[in]  boundaries       pointer to the domain boundaries
679  * \param[in]  ns_model         model equations for the NavSto system
680  * \param[in]  ns_model_flag    option flag for the Navier-Stokes system
681  * \param[in]  algo_coupling    algorithm used for solving the NavSto system
682  * \param[in]  ns_post_flag     predefined post-processings for Navier-Stokes
683  *
684  * \return a pointer to a new allocated solidification structure
685  */
686 /*----------------------------------------------------------------------------*/
687 
688 cs_solidification_t *
689 cs_solidification_activate(cs_solidification_model_t      model,
690                            cs_flag_t                      options,
691                            cs_flag_t                      post_flag,
692                            const cs_boundary_t           *boundaries,
693                            cs_navsto_param_model_t        ns_model,
694                            cs_navsto_param_model_flag_t   ns_model_flag,
695                            cs_navsto_param_coupling_t     algo_coupling,
696                            cs_navsto_param_post_flag_t    ns_post_flag);
697 
698 /*----------------------------------------------------------------------------*/
699 /*!
700  * \brief  Get the structure defining the Stefan model
701  *
702  * \return a pointer to the structure
703  */
704 /*----------------------------------------------------------------------------*/
705 
706 cs_solidification_stefan_t *
707 cs_solidification_get_stefan_struct(void);
708 
709 /*----------------------------------------------------------------------------*/
710 /*!
711  * \brief  Sanity checks on the consistency of the Stefan's model settings
712  *
713  * \return a pointer to the structure
714  */
715 /*----------------------------------------------------------------------------*/
716 
717 cs_solidification_stefan_t *
718 cs_solidification_check_stefan_model(void);
719 
720 /*----------------------------------------------------------------------------*/
721 /*!
722  * \brief  Set the main physical parameters which describe the Stefan model
723  *
724  * \param[in] t_change     liquidus/solidus temperature (in K)
725  * \param[in] latent_heat  latent heat
726  */
727 /*----------------------------------------------------------------------------*/
728 
729 void
730 cs_solidification_set_stefan_model(cs_real_t    t_change,
731                                    cs_real_t    latent_heat);
732 
733 /*----------------------------------------------------------------------------*/
734 /*!
735  * \brief  Get the structure defining the Voller model
736  *
737  * \return a pointer to the structure
738  */
739 /*----------------------------------------------------------------------------*/
740 
741 cs_solidification_voller_t *
742 cs_solidification_get_voller_struct(void);
743 
744 /*----------------------------------------------------------------------------*/
745 /*!
746  * \brief  Sanity checks on the consistency of the Voller's model settings
747  *
748  * \return a pointer to the structure
749  */
750 /*----------------------------------------------------------------------------*/
751 
752 cs_solidification_voller_t *
753 cs_solidification_check_voller_model(void);
754 
755 /*----------------------------------------------------------------------------*/
756 /*!
757  * \brief  Set the main physical parameters which describe the Voller and
758  *         Prakash modelling
759  *
760  * \param[in]  beta           thermal dilatation coefficient
761  * \param[in]  t_ref          reference temperature (for the Boussinesq approx)
762  * \param[in]  t_solidus      solidus temperature (in K)
763  * \param[in]  t_liquidus     liquidus temperature (in K)
764  * \param[in]  latent_heat    latent heat
765  * \param[in]  s_das          secondary dendrite space arms
766  */
767 /*----------------------------------------------------------------------------*/
768 
769 void
770 cs_solidification_set_voller_model(cs_real_t    beta,
771                                    cs_real_t    t_ref,
772                                    cs_real_t    t_solidus,
773                                    cs_real_t    t_liquidus,
774                                    cs_real_t    latent_heat,
775                                    cs_real_t    s_das);
776 
777 /*----------------------------------------------------------------------------*/
778 /*!
779  * \brief  Set the main physical parameters which describe the Voller and
780  *         Prakash modelling
781  *
782  * \param[in]  beta           thermal dilatation coefficient
783  * \param[in]  t_ref          reference temperature (for the Boussinesq approx)
784  * \param[in]  t_solidus      solidus temperature (in K)
785  * \param[in]  t_liquidus     liquidus temperature (in K)
786  * \param[in]  latent_heat    latent heat
787  */
788 /*----------------------------------------------------------------------------*/
789 
790 void
791 cs_solidification_set_voller_model_no_velocity(cs_real_t    t_solidus,
792                                                cs_real_t    t_liquidus,
793                                                cs_real_t    latent_heat);
794 
795 /*----------------------------------------------------------------------------*/
796 /*!
797  * \brief  Get the structure defining the binary alloy model
798  *
799  * \return a pointer to the structure
800  */
801 /*----------------------------------------------------------------------------*/
802 
803 cs_solidification_binary_alloy_t *
804 cs_solidification_get_binary_alloy_struct(void);
805 
806 /*----------------------------------------------------------------------------*/
807 /*!
808  * \brief  Sanity checks on the consistency of the settings of the binary alloy
809  *         model
810  *
811  * \return a pointer to the structure
812  */
813 /*----------------------------------------------------------------------------*/
814 
815 cs_solidification_binary_alloy_t *
816 cs_solidification_check_binary_alloy_model(void);
817 
818 /*----------------------------------------------------------------------------*/
819 /*!
820  * \brief  Set the main physical parameters which describe a solidification
821  *         process with a binary alloy (with components A and B)
822  *         Add a transport equation for the solute concentration to simulate
823  *         the conv/diffusion of the alloy ratio between the two components of
824  *         the alloy
825  *
826  * \param[in]  name          name of the binary alloy
827  * \param[in]  varname       name of the unknown related to the tracer eq.
828  * \param[in]  beta_t        thermal dilatation coefficient
829  * \param[in]  temp0         reference temperature (Boussinesq term)
830  * \param[in]  beta_c        solutal dilatation coefficient
831  * \param[in]  conc0         reference mixture concentration (Boussinesq term)
832  * \param[in]  kp            value of the distribution coefficient
833  * \param[in]  mliq          liquidus slope for the solute concentration
834  * \param[in]  t_eutec       temperature at the eutectic point
835  * \param[in]  t_melt        phase-change temperature for the pure material (A)
836  * \param[in]  solute_diff   solutal diffusion coefficient in the liquid
837  * \param[in]  latent_heat   latent heat
838  * \param[in]  s_das         secondary dendrite arm spacing
839  */
840 /*----------------------------------------------------------------------------*/
841 
842 void
843 cs_solidification_set_binary_alloy_model(const char     *name,
844                                          const char     *varname,
845                                          cs_real_t       beta_t,
846                                          cs_real_t       temp0,
847                                          cs_real_t       beta_c,
848                                          cs_real_t       conc0,
849                                          cs_real_t       kp,
850                                          cs_real_t       mliq,
851                                          cs_real_t       t_eutec,
852                                          cs_real_t       t_melt,
853                                          cs_real_t       solute_diff,
854                                          cs_real_t       latent_heat,
855                                          cs_real_t       s_das);
856 
857 /*----------------------------------------------------------------------------*/
858 /*!
859  * \brief  Set the strategy to update quantitiess (liquid fraction and
860  *         the thermal source term for the two main quantities)
861  *
862  * \param[in]  strategy     strategy to perform the update of quantities
863  */
864 /*----------------------------------------------------------------------------*/
865 
866 void
867 cs_solidification_set_strategy(cs_solidification_strategy_t  strategy);
868 
869 /*----------------------------------------------------------------------------*/
870 /*!
871  * \brief  Set the functions to perform the update of physical properties
872  *         and/or the computation of the thermal source term or quantities
873  *         and/or the way to perform the coupling between the thermal equation
874  *         and the bulk concentration computation. All this setting defines
875  *         the way to compute the solidification process of a binary alloy.
876  *         If a function is set to NULL then the automatic settings are kept.
877  *
878  *         --Advanced usage-- This enables to finely control the numerical or
879  *         physical modelling aspects.
880  *
881  * \param[in] vel_forcing        pointer to update the velocity forcing
882  * \param[in] cliq_update        pointer to update the liquid concentration
883  * \param[in] gliq_update        pointer to update the liquid fraction
884  * \param[in] thm_st_update      pointer to update thermal source terms
885  */
886 /*----------------------------------------------------------------------------*/
887 
888 void
889 cs_solidification_set_segr_functions(cs_solidification_func_t  *vel_forcing,
890                                      cs_solidification_func_t  *cliq_update,
891                                      cs_solidification_func_t  *gliq_update,
892                                      cs_solidification_func_t  *thm_st_update);
893 
894 /*----------------------------------------------------------------------------*/
895 /*!
896  * \brief  Free the main structure related to the solidification module
897  *
898  * \return a NULL pointer
899  */
900 /*----------------------------------------------------------------------------*/
901 
902 cs_solidification_t *
903 cs_solidification_destroy_all(void);
904 
905 /*----------------------------------------------------------------------------*/
906 /*!
907  * \brief  Setup equations/properties related to the solidification module
908  */
909 /*----------------------------------------------------------------------------*/
910 
911 void
912 cs_solidification_init_setup(void);
913 
914 /*----------------------------------------------------------------------------*/
915 /*!
916  * \brief  Finalize the setup stage for equations related to the solidification
917  *         module
918  *
919  * \param[in]  connect    pointer to a cs_cdo_connect_t structure
920  * \param[in]  quant      pointer to a cs_cdo_quantities_t structure
921  */
922 /*----------------------------------------------------------------------------*/
923 
924 void
925 cs_solidification_finalize_setup(const cs_cdo_connect_t       *connect,
926                                  const cs_cdo_quantities_t    *quant);
927 
928 /*----------------------------------------------------------------------------*/
929 /*!
930  * \brief  Summarize the solidification module in the log file dedicated to
931  *         the setup
932  */
933 /*----------------------------------------------------------------------------*/
934 
935 void
936 cs_solidification_log_setup(void);
937 
938 /*----------------------------------------------------------------------------*/
939 /*!
940  * \brief  Initialize the context structure used to build the algebraic system
941  *         This is done after the setup step.
942  *
943  * \param[in]      mesh       pointer to a cs_mesh_t structure
944  * \param[in]      connect    pointer to a cs_cdo_connect_t structure
945  * \param[in]      quant      pointer to a cs_cdo_quantities_t structure
946  * \param[in]      time_step  pointer to a cs_time_step_t structure
947  */
948 /*----------------------------------------------------------------------------*/
949 
950 void
951 cs_solidification_initialize(const cs_mesh_t              *mesh,
952                              const cs_cdo_connect_t       *connect,
953                              const cs_cdo_quantities_t    *quant,
954                              const cs_time_step_t         *time_step);
955 
956 /*----------------------------------------------------------------------------*/
957 /*!
958  * \brief  Solve equations related to the solidification module
959  *
960  * \param[in]      mesh       pointer to a cs_mesh_t structure
961  * \param[in]      connect    pointer to a cs_cdo_connect_t structure
962  * \param[in]      quant      pointer to a cs_cdo_quantities_t structure
963  * \param[in]      time_step  pointer to a cs_time_step_t structure
964  */
965 /*----------------------------------------------------------------------------*/
966 
967 void
968 cs_solidification_compute(const cs_mesh_t              *mesh,
969                           const cs_cdo_connect_t       *connect,
970                           const cs_cdo_quantities_t    *quant,
971                           const cs_time_step_t         *time_step);
972 
973 /*----------------------------------------------------------------------------*/
974 /*!
975  * \brief  Predefined extra-operations for the solidification module
976  *
977  * \param[in]  connect    pointer to a cs_cdo_connect_t structure
978  * \param[in]  quant      pointer to a cs_cdo_quantities_t structure
979  * \param[in]  ts         pointer to a cs_time_step_t structure
980  */
981 /*----------------------------------------------------------------------------*/
982 
983 void
984 cs_solidification_extra_op(const cs_cdo_connect_t      *connect,
985                            const cs_cdo_quantities_t   *quant,
986                            const cs_time_step_t        *ts);
987 
988 /*----------------------------------------------------------------------------*/
989 /*!
990  * \brief  Predefined post-processing output for the solidification module.
991  *         Prototype of this function is fixed since it is a function pointer
992  *         defined in cs_post.h (\ref cs_post_time_mesh_dep_output_t)
993  *
994  * \param[in, out] input        pointer to an optional structure (here a
995  *                              cs_gwf_t structure)
996  * \param[in]      mesh_id      id of the output mesh for the current call
997  * \param[in]      cat_id       category id of the output mesh for this call
998  * \param[in]      ent_flag     indicate global presence of cells (ent_flag[0]),
999  *                              interior faces (ent_flag[1]), boundary faces
1000  *                              (ent_flag[2]), particles (ent_flag[3]) or probes
1001  *                              (ent_flag[4])
1002  * \param[in]      n_cells      local number of cells of post_mesh
1003  * \param[in]      n_i_faces    local number of interior faces of post_mesh
1004  * \param[in]      n_b_faces    local number of boundary faces of post_mesh
1005  * \param[in]      cell_ids     list of cells (0 to n-1)
1006  * \param[in]      i_face_ids   list of interior faces (0 to n-1)
1007  * \param[in]      b_face_ids   list of boundary faces (0 to n-1)
1008  * \param[in]      time_step    pointer to a cs_time_step_t struct.
1009  */
1010 /*----------------------------------------------------------------------------*/
1011 
1012 void
1013 cs_solidification_extra_post(void                      *input,
1014                              int                        mesh_id,
1015                              int                        cat_id,
1016                              int                        ent_flag[5],
1017                              cs_lnum_t                  n_cells,
1018                              cs_lnum_t                  n_i_faces,
1019                              cs_lnum_t                  n_b_faces,
1020                              const cs_lnum_t            cell_ids[],
1021                              const cs_lnum_t            i_face_ids[],
1022                              const cs_lnum_t            b_face_ids[],
1023                              const cs_time_step_t      *time_step);
1024 
1025 /*----------------------------------------------------------------------------*/
1026 
1027 END_C_DECLS
1028 
1029 #endif /* __CS_SOLIDIFICATION_H__ */
1030