1 #ifndef __CS_THERMAL_SYSTEM_H__ 2 #define __CS_THERMAL_SYSTEM_H__ 3 4 /*============================================================================ 5 * Functions to handle cs_thermal_system_t structure 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_advection_field.h" 33 #include "cs_equation.h" 34 #include "cs_field.h" 35 #include "cs_property.h" 36 #include "cs_mesh.h" 37 #include "cs_source_term.h" 38 #include "cs_time_step.h" 39 #include "cs_xdef.h" 40 41 /*----------------------------------------------------------------------------*/ 42 43 BEGIN_C_DECLS 44 45 /*============================================================================ 46 * Macro definitions 47 *============================================================================*/ 48 49 /* Generic name given to fields and equations related to this module */ 50 51 #define CS_THERMAL_EQNAME "thermal_equation" 52 #define CS_THERMAL_CP_NAME "thermal_capacity" 53 #define CS_THERMAL_LAMBDA_NAME "thermal_conductivity" 54 55 /*! 56 * @name Flags specifying automatic post-processing for the thermal module 57 * @{ 58 * 59 * \def CS_THERMAL_POST_ENTHALPY 60 * \brief Create a field storing the enthalpy for post-processing and 61 * extra-operation 62 * 63 * 64 */ 65 66 #define CS_THERMAL_POST_ENTHALPY (1 << 0) /* 1 */ 67 68 /*! 69 * @} 70 */ 71 72 /*============================================================================= 73 * Structure and type definitions 74 *============================================================================*/ 75 76 typedef cs_flag_t cs_thermal_model_type_t; 77 78 /*! \enum cs_thermal_model_type_bit_t 79 * \brief Bit values for physical modelling related to thermal system 80 * 81 * \def CS_THERMAL_MODEL_STEADY 82 * \brief Disable the unsteady term of the thermal equation 83 * 84 * \def CS_THERMAL_MODEL_NAVSTO_ADVECTION 85 * \brief Add an advection term arising from the velocity field solution 86 * of the Navier-Stokes equations 87 * 88 * \def CS_THERMAL_MODEL_USE_TEMPERATURE 89 * \brief The thermal equation solved using the temperature variable 90 * (the default choice) 91 * 92 * \def CS_THERMAL_MODEL_USE_ENTHALPY 93 * \brief The thermal equation solved using the enthalpy variable 94 * instead of the temperature (the default choice) 95 * 96 * \def CS_THERMAL_MODEL_USE_TOTAL_ENERGY 97 * \brief The thermal equation solved using the total energy variable 98 * instead of the temperature (the default choice) 99 * 100 * \def CS_THERMAL_MODEL_ANISOTROPIC_CONDUCTIVITY 101 * \brief The thermal equation solved using an anisotropic conductivity 102 * instead of an isotropic one (the default choice) 103 * 104 */ 105 106 typedef enum { 107 108 CS_THERMAL_MODEL_STEADY = 1<<0, /* = 1 */ 109 CS_THERMAL_MODEL_NAVSTO_ADVECTION = 1<<1, /* = 2 */ 110 111 /* Main variable to consider (by default the temperature in Kelvin) 112 ---------------------------------------------------------------- */ 113 114 CS_THERMAL_MODEL_USE_TEMPERATURE = 1<<2, /* = 4 */ 115 CS_THERMAL_MODEL_USE_ENTHALPY = 1<<3, /* = 8 */ 116 CS_THERMAL_MODEL_USE_TOTAL_ENERGY = 1<<4, /* = 16 */ 117 118 /* Treatment of the diffusion term 119 ------------------------------- */ 120 121 CS_THERMAL_MODEL_ANISOTROPIC_CONDUCTIVITY = 1<<5, /* = 32 */ 122 123 /* Additional bit settings 124 ----------------------- */ 125 126 CS_THERMAL_MODEL_IN_CELSIUS = 1<<7 /* = 128 */ 127 128 } cs_thermal_model_type_bit_t; 129 130 /* Set of parameters related to the thermal module */ 131 132 typedef struct { 133 134 cs_flag_t model; /* Choice of modelling */ 135 cs_flag_t numeric; /* General numerical options */ 136 cs_flag_t post; /* Post-processing options */ 137 138 /* Equation associated to this module */ 139 /* ---------------------------------- */ 140 141 cs_equation_t *thermal_eq; 142 143 /* Properties associated to this module */ 144 /* ------------------------------------ */ 145 146 cs_property_t *unsteady_property; /* Property of the unsteady term: rho.cp */ 147 cs_property_t *lambda; /* Thermal conductivity */ 148 cs_property_t *cp; /* Heat capacity */ 149 cs_property_t *rho; /* Mass density (may be shared) */ 150 cs_property_t *kappa; /* lambda/cp may be NULL*/ 151 152 /* value of lambda/cp in each cell (allocated if the related property kappa 153 * is not NULL and defined by array) */ 154 cs_real_t *kappa_array; 155 156 /* Fields associated to this module */ 157 /* -------------------------------- */ 158 159 cs_field_t *temperature; 160 cs_field_t *enthalpy; 161 cs_field_t *total_energy; 162 163 /* Additional members */ 164 /* ------------------ */ 165 166 cs_real_t ref_temperature; 167 168 /* N.B.: Other reference values for properties are stored within each 169 * property structure */ 170 171 } cs_thermal_system_t; 172 173 /*============================================================================ 174 * Public function prototypes 175 *============================================================================*/ 176 177 /*----------------------------------------------------------------------------*/ 178 /*! 179 * \brief Retrieve the value of the reference temperature associated to a 180 * thermal system. 181 * 182 * \return the value of the reference temperature 183 */ 184 /*----------------------------------------------------------------------------*/ 185 186 cs_real_t 187 cs_thermal_system_get_reference_temperature(void); 188 189 /*----------------------------------------------------------------------------*/ 190 /*! 191 * \brief Set the value of the reference temperature associated to the 192 * thermal system. 193 * 194 * \param[in] ref value of the reference temperature 195 */ 196 /*----------------------------------------------------------------------------*/ 197 198 void 199 cs_thermal_system_set_reference_temperature(cs_real_t ref); 200 201 /*----------------------------------------------------------------------------*/ 202 /*! 203 * \brief Retrieve the model flag related to a thermal system 204 * 205 * \return a flag 206 */ 207 /*----------------------------------------------------------------------------*/ 208 209 cs_flag_t 210 cs_thermal_system_get_model(void); 211 212 /*----------------------------------------------------------------------------*/ 213 /*! 214 * \brief Does the thermal system rely on the advection field associated to 215 * the Navier-Stokes equations ? 216 * 217 * \return true or false 218 */ 219 /*----------------------------------------------------------------------------*/ 220 221 bool 222 cs_thermal_system_needs_navsto(void); 223 224 /*----------------------------------------------------------------------------*/ 225 /*! 226 * \brief Check if the resolution of the thermal system has been activated 227 * 228 * \return true or false 229 */ 230 /*----------------------------------------------------------------------------*/ 231 232 bool 233 cs_thermal_system_is_activated(void); 234 235 /*----------------------------------------------------------------------------*/ 236 /*! 237 * \brief Allocate and initialize the thermal system 238 * 239 * \param[in] model model flag related to the thermal system 240 * \param[in] numeric (optional) numerical flag settings 241 * \param[in] post (optional) post-processing flag settings 242 * 243 * \return a pointer to a new allocated cs_thermal_system_t structure 244 */ 245 /*----------------------------------------------------------------------------*/ 246 247 cs_thermal_system_t * 248 cs_thermal_system_activate(cs_flag_t model, 249 cs_flag_t numeric, 250 cs_flag_t post); 251 252 /*----------------------------------------------------------------------------*/ 253 /*! 254 * \brief Free the main structure related to the thermal system 255 */ 256 /*----------------------------------------------------------------------------*/ 257 258 void 259 cs_thermal_system_destroy(void); 260 261 /*----------------------------------------------------------------------------*/ 262 /*! 263 * \brief Retrieve the main equation related to the thermal system 264 */ 265 /*----------------------------------------------------------------------------*/ 266 267 cs_equation_t * 268 cs_thermal_system_get_equation(void); 269 270 /*----------------------------------------------------------------------------*/ 271 /*! 272 * \brief Retrieve the current temperature at face values 273 * 274 * \return the pointer to the array of face values. 275 */ 276 /*----------------------------------------------------------------------------*/ 277 278 cs_real_t * 279 cs_thermal_system_get_face_temperature(void); 280 281 /*----------------------------------------------------------------------------*/ 282 /*! 283 * \brief Start setting-up the thermal system 284 * At this stage, numerical settings should be completely determined 285 * but connectivity and geometrical information is not yet available. 286 */ 287 /*----------------------------------------------------------------------------*/ 288 289 void 290 cs_thermal_system_init_setup(void); 291 292 /*----------------------------------------------------------------------------*/ 293 /*! 294 * \brief Last step of the setup of the thermal system 295 * 296 * \param[in] connect pointer to a cs_cdo_connect_t structure 297 * \param[in] quant pointer to a cs_cdo_quantities_t structure 298 * \param[in] time_step pointer to a cs_time_step_t structure 299 */ 300 /*----------------------------------------------------------------------------*/ 301 302 void 303 cs_thermal_system_finalize_setup(const cs_cdo_connect_t *connect, 304 const cs_cdo_quantities_t *quant, 305 const cs_time_step_t *time_step); 306 307 /*----------------------------------------------------------------------------*/ 308 /*! 309 * \brief Build and solve a steady-state thermal system 310 * 311 * \param[in] mesh pointer to a cs_mesh_t structure 312 * \param[in] connect pointer to a cs_cdo_connect_t structure 313 * \param[in] quant pointer to a cs_cdo_quantities_t structure 314 * \param[in] time_step pointer to a cs_time_step_t structure 315 */ 316 /*----------------------------------------------------------------------------*/ 317 318 void 319 cs_thermal_system_compute_steady_state(const cs_mesh_t *mesh, 320 const cs_cdo_connect_t *connect, 321 const cs_cdo_quantities_t *quant, 322 const cs_time_step_t *time_step); 323 324 /*----------------------------------------------------------------------------*/ 325 /*! 326 * \brief Build and solve the thermal system 327 * 328 * \param[in] cur2prev true="current to previous" operation is performed 329 * \param[in] mesh pointer to a cs_mesh_t structure 330 * \param[in] connect pointer to a cs_cdo_connect_t structure 331 * \param[in] quant pointer to a cs_cdo_quantities_t structure 332 * \param[in] time_step pointer to a cs_time_step_t structure 333 */ 334 /*----------------------------------------------------------------------------*/ 335 336 void 337 cs_thermal_system_compute(bool cur2prev, 338 const cs_mesh_t *mesh, 339 const cs_cdo_connect_t *connect, 340 const cs_cdo_quantities_t *quant, 341 const cs_time_step_t *time_step); 342 343 /*----------------------------------------------------------------------------*/ 344 /*! 345 * \brief Update/initialize the thermal module according to the settings 346 * 347 * \param[in] mesh pointer to a cs_mesh_t structure 348 * \param[in] connect pointer to a cs_cdo_connect_t structure 349 * \param[in] quant pointer to a cs_cdo_quantities_t structure 350 * \param[in] ts pointer to a cs_time_step_t structure 351 * \param[in] cur2prev true or false 352 */ 353 /*----------------------------------------------------------------------------*/ 354 355 void 356 cs_thermal_system_update(const cs_mesh_t *mesh, 357 const cs_cdo_connect_t *connect, 358 const cs_cdo_quantities_t *quant, 359 const cs_time_step_t *ts, 360 bool cur2prev); 361 362 /*----------------------------------------------------------------------------*/ 363 /*! 364 * \brief Predefined extra-operations for the thermal system 365 * 366 * \param[in] connect pointer to a cs_cdo_connect_t structure 367 * \param[in] cdoq pointer to a cs_cdo_quantities_t structure 368 */ 369 /*----------------------------------------------------------------------------*/ 370 371 void 372 cs_thermal_system_extra_op(const cs_cdo_connect_t *connect, 373 const cs_cdo_quantities_t *cdoq); 374 375 /*----------------------------------------------------------------------------*/ 376 /*! 377 * \brief Predefined post-processing output for the thermal system. 378 * The prototype of this function is fixed since it is a function 379 * pointer defined in cs_post.h (\ref cs_post_time_mesh_dep_output_t) 380 * 381 * \param[in, out] input pointer to a optional structure (here a 382 * cs_thermal_system_t structure) 383 * \param[in] mesh_id id of the output mesh for the current call 384 * \param[in] cat_id category id of the output mesh for this call 385 * \param[in] ent_flag indicate global presence of cells (ent_flag[0]), 386 * interior faces (ent_flag[1]), boundary faces 387 * (ent_flag[2]), particles (ent_flag[3]) or probes 388 * (ent_flag[4]) 389 * \param[in] n_cells local number of cells of post_mesh 390 * \param[in] n_i_faces local number of interior faces of post_mesh 391 * \param[in] n_b_faces local number of boundary faces of post_mesh 392 * \param[in] cell_ids list of cells (0 to n-1) 393 * \param[in] i_face_ids list of interior faces (0 to n-1) 394 * \param[in] b_face_ids list of boundary faces (0 to n-1) 395 * \param[in] time_step pointer to a cs_time_step_t struct. 396 */ 397 /*----------------------------------------------------------------------------*/ 398 399 void 400 cs_thermal_system_extra_post(void *input, 401 int mesh_id, 402 int cat_id, 403 int ent_flag[5], 404 cs_lnum_t n_cells, 405 cs_lnum_t n_i_faces, 406 cs_lnum_t n_b_faces, 407 const cs_lnum_t cell_ids[], 408 const cs_lnum_t i_face_ids[], 409 const cs_lnum_t b_face_ids[], 410 const cs_time_step_t *time_step); 411 412 /*----------------------------------------------------------------------------*/ 413 /*! 414 * \brief Summary of the main options related to cs_thermal_system_t structure 415 */ 416 /*----------------------------------------------------------------------------*/ 417 418 void 419 cs_thermal_system_log_setup(void); 420 421 /*----------------------------------------------------------------------------*/ 422 423 END_C_DECLS 424 425 #endif /* __CS_THERMAL_SYSTEM_H__ */ 426