1 /*============================================================================
2  * Base thermal model data.
3  *============================================================================*/
4 
5 /*
6   This file is part of Code_Saturne, a general-purpose CFD tool.
7 
8   Copyright (C) 1998-2021 EDF S.A.
9 
10   This program is free software; you can redistribute it and/or modify it under
11   the terms of the GNU General Public License as published by the Free Software
12   Foundation; either version 2 of the License, or (at your option) any later
13   version.
14 
15   This program is distributed in the hope that it will be useful, but WITHOUT
16   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18   details.
19 
20   You should have received a copy of the GNU General Public License along with
21   this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22   Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 */
24 
25 /*----------------------------------------------------------------------------*/
26 
27 #include "cs_defs.h"
28 
29 /*----------------------------------------------------------------------------*/
30 
31 /*----------------------------------------------------------------------------
32  * Standard C library headers
33  *----------------------------------------------------------------------------*/
34 
35 #include <assert.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 
40 /*----------------------------------------------------------------------------
41  * Local headers
42  *----------------------------------------------------------------------------*/
43 
44 #include "bft_mem.h"
45 #include "bft_error.h"
46 #include "bft_printf.h"
47 
48 #include "cs_field.h"
49 #include "cs_field_pointer.h"
50 #include "cs_log.h"
51 #include "cs_map.h"
52 #include "cs_parall.h"
53 #include "cs_mesh_location.h"
54 
55 /*----------------------------------------------------------------------------
56  * Header for the current file
57  *----------------------------------------------------------------------------*/
58 
59 #include "cs_thermal_model.h"
60 
61 /*----------------------------------------------------------------------------*/
62 
63 BEGIN_C_DECLS
64 
65 /*=============================================================================
66  * Additional doxygen documentation
67  *============================================================================*/
68 
69 /*!
70   \file cs_thermal_model.c
71         base thermal model data.
72 
73   \struct cs_thermal_model_t
74 
75   \brief Thermal model descriptor.
76 
77   Members of this thermal model are publicly accessible, to allow for concise
78   syntax, as it is expected to be used in many places.
79 
80   \var  cs_thermal_model_t::itherm
81         Thermal model
82            - 0: no thermal model
83            - 1: temperature
84            - 2: enthalpy
85            - 3: total energy (only for compressible module)\n
86         When a particular physics module is activated (gas combustion,
87         pulverised coal, electricity or compressible), the user must not
88         modify \ref itherm (the choice is made automatically: the solved
89         variable is either the enthalpy or the total energy). The user is
90         also reminded that, in the case of a coupling with SYRTHES, the
91         solved thermal variable should be the temperature (\ref itherm = 1).
92         More precisely, everything is designed in the code to allow for the
93         running of a calculation coupled with SYRTHES with the enthalpy as
94         thermal variable. With the compressible model, it is possible to
95         carry out calculations coupled with SYRTHES, although the thermal
96         scalar represents the total energy and not the temperature.
97   \var  cs_thermal_model_t::itpscl
98         Temperature scale
99         - 0: none
100         - 1: Kelvin
101         - 2: Celsius
102         The distinction between \ref itpscl = 1 or 2 is useful only in case of
103         radiation modelling. For calculations without radiation modelling,
104         use \ref itpscl = 1 for the temperature.\n
105         Useful if and only if \ref dimens::nscal "nscal" \f$\geqslant\f$ 1.
106   \var  cs_thermal_model_t::iscalt
107         Index of the thermal scalar (temperature, energy or enthalpy).\n
108 
109         The index of the corresponding variable is isca(iscalt)
110         If \ref iscalt = -1, neither the temperature nor the enthalpy is
111         represented by a scalar. When a specific physics module is activated
112         (gas combustion, pulverised coal, electricity or compressible), the user
113         must not modify \ref iscalt (the choice is made automatically). In the
114         case of the compressible module, \ref iscalt does not correspond to
115         the temperature nor enthalpy but to the total energy}.
116 
117         \deprecated
118         This should only be used to set Fortran mappings. In C, use of
119         \ref cs_thermal_model_field is recommended instead.
120 
121 */
122 
123 /*! \cond DOXYGEN_SHOULD_SKIP_THIS */
124 
125 /*=============================================================================
126  * Macro definitions
127  *============================================================================*/
128 
129 /*============================================================================
130  * Type definitions
131  *============================================================================*/
132 
133 /*============================================================================
134  * Static global variables
135  *============================================================================*/
136 
137 /* main thermal model structure and associated pointer */
138 
139 static cs_thermal_model_t  _thermal_model = {
140   .itherm = -999,
141   .itpscl = 1,
142   .iscalt = -1};
143 
144 const cs_thermal_model_t  *cs_glob_thermal_model = &_thermal_model;
145 
146 /*============================================================================
147  * Prototypes for functions intended for use only by Fortran wrappers.
148  * (descriptions follow, with function bodies).
149  *============================================================================*/
150 
151 void
152 cs_f_thermal_model_get_pointers(int     **itherm,
153                                 int     **itpscl,
154                                 int     **iscalt);
155 
156 /*! (DOXYGEN_SHOULD_SKIP_THIS) \endcond */
157 
158 /*============================================================================
159  * Private function definitions
160  *============================================================================*/
161 
162 /*============================================================================
163  * Fortran wrapper function definitions
164  *============================================================================*/
165 
166 /*! \cond DOXYGEN_SHOULD_SKIP_THIS */
167 
168 /*----------------------------------------------------------------------------
169  * Get pointers to members of the global thermal model structure.
170  *
171  * This function is intended for use by Fortran wrappers, and
172  * enables mapping to Fortran global pointers.
173  *
174  * parameters:
175  *   itherm --> pointer to cs_glob_thermal_model->itherm
176  *   itpscl --> pointer to cs_glob_thermal_model->itpscl
177  *   iscalt --> pointer to cs_glob_thermal_model->iscalt
178  *----------------------------------------------------------------------------*/
179 
180 void
cs_f_thermal_model_get_pointers(int ** itherm,int ** itpscl,int ** iscalt)181 cs_f_thermal_model_get_pointers(int     **itherm,
182                                 int     **itpscl,
183                                 int     **iscalt)
184 {
185   *itherm = &(_thermal_model.itherm);
186   *itpscl = &(_thermal_model.itpscl);
187   *iscalt = &(_thermal_model.iscalt);
188 }
189 
190 /*! (DOXYGEN_SHOULD_SKIP_THIS) \endcond */
191 
192 /*=============================================================================
193  * Public function definitions
194  *============================================================================*/
195 
196 /*----------------------------------------------------------------------------
197  *!
198  * \brief Return thermal field (temperature, enthalpy, total energy according to
199  *        thermal model).
200  *
201  * \return   pointer to thermal field
202  *----------------------------------------------------------------------------*/
203 
204 cs_field_t *
cs_thermal_model_field(void)205 cs_thermal_model_field(void)
206 {
207   cs_field_t *th_f;
208   switch (_thermal_model.itherm) {
209   case CS_THERMAL_MODEL_TEMPERATURE:
210     th_f = CS_F_(t);
211     break;
212   case CS_THERMAL_MODEL_ENTHALPY:
213     th_f = CS_F_(h);
214     break;
215   case CS_THERMAL_MODEL_TOTAL_ENERGY:
216     th_f = CS_F_(e_tot);
217     break;
218   default:
219     th_f = NULL;
220   }
221 
222   return th_f;
223 }
224 
225 /*----------------------------------------------------------------------------
226  *!
227  * \brief Provide access to cs_glob_thermal_model
228  *
229  * needed to initialize structure with GUI
230  *----------------------------------------------------------------------------*/
231 
232 cs_thermal_model_t *
cs_get_glob_thermal_model(void)233 cs_get_glob_thermal_model(void)
234 {
235   return &_thermal_model;
236 }
237 
238 /*----------------------------------------------------------------------------
239  *!
240  * \brief Print the thermal model structure to setup.log.
241  *
242  *----------------------------------------------------------------------------*/
243 
244 void
cs_thermal_model_log_setup(void)245 cs_thermal_model_log_setup(void)
246 {
247   int itherm = cs_glob_thermal_model->itherm;
248   int itpscl = cs_glob_thermal_model->itpscl;
249 
250   cs_log_printf(CS_LOG_SETUP,
251                 ("\n"
252                  "Thermal model options\n"
253                  "---------------------\n\n"
254                  "  Continuous phase:\n\n"));
255 
256   const char *itherm_value_str[]
257     = {N_("no thermal model"),
258        N_("temperature)"),
259        N_("enthalpy"),
260        N_("total energy")};
261 
262   const char *itpscl_value_str[]
263     = {N_("none"),
264        N_("temperature in Kelvin"),
265        N_("temperature in Celsius")};
266 
267   cs_log_printf(CS_LOG_SETUP,
268                 ("    Thermal model\n"));
269   cs_log_printf(CS_LOG_SETUP,
270                 _("    itherm:    %d (%s)\n"),
271                 itherm, _(itherm_value_str[itherm]));
272 
273   cs_log_printf(CS_LOG_SETUP,
274                 ("    Temperature scale\n"));
275   cs_log_printf(CS_LOG_SETUP,
276                 _("    itpscl:    %d (%s)\n"),
277                 itpscl, _(itpscl_value_str[itpscl]));
278 
279   cs_field_t *tf = cs_thermal_model_field();
280   if (tf != NULL)
281     cs_log_printf
282       (CS_LOG_SETUP,
283        _("    Thermal variable solved: %s (field id %d)\n"),
284        tf->name, tf->id);
285 }
286 
287 /*----------------------------------------------------------------------------*/
288 
289 END_C_DECLS
290