programmer's documentation
cs_advection_field.h
Go to the documentation of this file.
1 #ifndef __CS_ADVECTION_FIELD_H__
2 #define __CS_ADVECTION_FIELD_H__
3 
4 /*============================================================================
5  * Manage the definition/setting of advection fields
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2018 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_cdo_connect.h"
35 #include "cs_cdo_local.h"
36 #include "cs_cdo_quantities.h"
37 #include "cs_mesh_location.h"
38 #include "cs_param.h"
39 #include "cs_property.h"
40 #include "cs_xdef.h"
41 #include "cs_xdef_eval.h"
42 
43 /*----------------------------------------------------------------------------*/
44 
46 
47 /*============================================================================
48  * Macro definitions
49  *============================================================================*/
50 
59 #define CS_ADVECTION_FIELD_POST_COURANT (1 << 0)
60 
61 #define CS_ADVECTION_FIELD_STEADY (1 << 1) // steady-state field
62 
65 /*============================================================================
66  * Type definitions
67  *============================================================================*/
68 
82 typedef enum {
83 
88 
90 
105 typedef enum {
106 
111 
113 
118 typedef struct {
119 
157  int id;
158  char *restrict name;
160 
165 
166  /* We assume that there is only one definition associated to an advection
167  field inside the computational domain */
169 
170  /* Optional: Definition(s) for the boundary flux */
173  short int *bdy_def_ids;
174 
176 
177 /*============================================================================
178  * Global variables
179  *============================================================================*/
180 
181 /*============================================================================
182  * Inline public function prototypes
183  *============================================================================*/
184 
185 /*----------------------------------------------------------------------------*/
195 /*----------------------------------------------------------------------------*/
196 
197 static inline cs_field_t *
199  cs_mesh_location_type_t ml_type)
200 {
201  cs_field_t *f = NULL;
202  if (adv == NULL)
203  return f;
204 
205  switch (ml_type) {
207  assert(adv->bdy_field_id > -1);
208  f = cs_field_by_id(adv->bdy_field_id);
209  break;
210 
212  assert(adv->cell_field_id > -1);
213  f = cs_field_by_id(adv->cell_field_id);
214  break;
215 
217  assert(adv->vtx_field_id > -1);
218  f = cs_field_by_id(adv->vtx_field_id);
219  break;
220 
221  default:
222  bft_error(__FILE__, __LINE__, 0,
223  " %s: Invalid mesh location type. Stop retrieving the field.\n",
224  __func__);
225  }
226 
227  return f;
228 }
229 
230 /*============================================================================
231  * Public function prototypes
232  *============================================================================*/
233 
234 /*----------------------------------------------------------------------------*/
241 /*----------------------------------------------------------------------------*/
242 
243 void
245  const cs_cdo_connect_t *connect);
246 
247 /*----------------------------------------------------------------------------*/
253 /*----------------------------------------------------------------------------*/
254 
255 int
257 
258 /*----------------------------------------------------------------------------*/
267 /*----------------------------------------------------------------------------*/
268 
270 cs_advection_field_by_name(const char *name);
271 
272 /*----------------------------------------------------------------------------*/
281 /*----------------------------------------------------------------------------*/
282 
285 
286 /*----------------------------------------------------------------------------*/
294 /*----------------------------------------------------------------------------*/
295 
297 cs_advection_field_add_user(const char *name);
298 
299 /*----------------------------------------------------------------------------*/
308 /*----------------------------------------------------------------------------*/
309 
311 cs_advection_field_add(const char *name,
313 
314 /*----------------------------------------------------------------------------*/
320 /*----------------------------------------------------------------------------*/
321 
322 void
324 
325 /*----------------------------------------------------------------------------*/
334 /*----------------------------------------------------------------------------*/
335 
336 bool
338  const char *ref_name);
339 
340 /*----------------------------------------------------------------------------*/
348 /*----------------------------------------------------------------------------*/
349 
350 bool
352 
353 /*----------------------------------------------------------------------------*/
362 /*----------------------------------------------------------------------------*/
363 
364 bool
366 
367 /*----------------------------------------------------------------------------*/
375 /*----------------------------------------------------------------------------*/
376 
377 const char *
379 
380 /*----------------------------------------------------------------------------*/
389 /*----------------------------------------------------------------------------*/
390 
393 
394 /*----------------------------------------------------------------------------*/
398 /*----------------------------------------------------------------------------*/
399 
400 void
402 
403 /*----------------------------------------------------------------------------*/
410 /*----------------------------------------------------------------------------*/
411 
412 void
415 
416 /*----------------------------------------------------------------------------*/
423 /*----------------------------------------------------------------------------*/
424 
425 void
427  cs_real_t vector[3]);
428 
429 /*----------------------------------------------------------------------------*/
437 /*----------------------------------------------------------------------------*/
438 
439 void
441  cs_analytic_func_t *func,
442  void *input);
443 
444 /*----------------------------------------------------------------------------*/
453 /*----------------------------------------------------------------------------*/
454 
455 void
457  cs_flag_t loc,
458  cs_real_t *array,
459  cs_lnum_t *index);
460 
461 /*----------------------------------------------------------------------------*/
468 /*----------------------------------------------------------------------------*/
469 
470 void
472  cs_field_t *field);
473 
474 /*----------------------------------------------------------------------------*/
483 /*----------------------------------------------------------------------------*/
484 
485 void
487  const char *zname,
488  cs_real_t normal_flux);
489 
490 /*----------------------------------------------------------------------------*/
500 /*----------------------------------------------------------------------------*/
501 
502 void
504  const char *zname,
505  cs_analytic_func_t *func,
506  void *input);
507 
508 /*----------------------------------------------------------------------------*/
519 /*----------------------------------------------------------------------------*/
520 
521 void
523  const char *zname,
524  cs_flag_t loc,
525  cs_real_t *array,
526  cs_lnum_t *index);
527 
528 /*----------------------------------------------------------------------------*/
533 /*----------------------------------------------------------------------------*/
534 
535 void
537 
538 /*----------------------------------------------------------------------------*/
543 /*----------------------------------------------------------------------------*/
544 
545 void
547 
548 /*----------------------------------------------------------------------------*/
556 /*----------------------------------------------------------------------------*/
557 
558 void
560  const cs_adv_field_t *adv,
561  cs_nvec3_t *vect);
562 
563 /*----------------------------------------------------------------------------*/
571 /*----------------------------------------------------------------------------*/
572 
573 void
575  cs_real_t time_eval,
576  cs_real_t *cell_values);
577 
578 /*----------------------------------------------------------------------------*/
586 /*----------------------------------------------------------------------------*/
587 
588 void
590  cs_real_t time_eval,
591  cs_real_t *vtx_values);
592 
593 /*----------------------------------------------------------------------------*/
604 /*----------------------------------------------------------------------------*/
605 
606 void
608  const cs_cell_mesh_t *cm,
609  const cs_real_3_t xyz,
610  cs_real_t time_eval,
611  cs_nvec3_t *eval);
612 
613 /*----------------------------------------------------------------------------*/
622 /*----------------------------------------------------------------------------*/
623 
624 void
626  cs_real_t time_eval,
627  cs_real_t *flx_values);
628 
629 /*----------------------------------------------------------------------------*/
640 /*----------------------------------------------------------------------------*/
641 
642 void
644  const cs_adv_field_t *adv,
645  short int f,
646  cs_real_t time_eval,
647  cs_real_t *fluxes);
648 
649 /*----------------------------------------------------------------------------*/
659 /*----------------------------------------------------------------------------*/
660 
661 void
663  const cs_adv_field_t *adv,
664  cs_real_t time_eval,
665  cs_real_t *fluxes);
666 
667 /*----------------------------------------------------------------------------*/
677 /*----------------------------------------------------------------------------*/
678 
679 void
681  const cs_adv_field_t *adv,
682  cs_real_t time_eval,
683  cs_real_t *fluxes);
684 
685 /*----------------------------------------------------------------------------*/
693 /*----------------------------------------------------------------------------*/
694 
695 void
697  bool cur2prev);
698 
699 /*----------------------------------------------------------------------------*/
708 /*----------------------------------------------------------------------------*/
709 
710 void
712  const cs_property_t *diff,
713  cs_real_t t_eval,
714  cs_real_t peclet[]);
715 
716 /*----------------------------------------------------------------------------*/
724 /*----------------------------------------------------------------------------*/
725 
726 void
728  cs_real_t dt_cur,
729  cs_real_t courant[]);
730 
731 /*----------------------------------------------------------------------------*/
741 /*----------------------------------------------------------------------------*/
742 
743 cs_real_t *
745  cs_real_t t_eval);
746 
747 /*----------------------------------------------------------------------------*/
748 
750 
751 #endif /* __CS_ADVECTION_FIELD_H__ */
#define restrict
Definition: cs_defs.h:122
void() cs_analytic_func_t(cs_real_t time, cs_lnum_t n_elts, const cs_lnum_t *elt_ids, const cs_real_t *coords, bool compact, void *input, cs_real_t *retval)
Generic function pointer for an analytic function elt_ids is optional. If not NULL, it enables to access in coords at the right location and the same thing to fill retval if compact is set to false.
Definition: cs_param.h:66
bool cs_advection_field_is_uniform(const cs_adv_field_t *adv)
returns true if the advection field is uniform, otherwise false
Definition: cs_advection_field.c:415
void cs_advection_field_def_by_array(cs_adv_field_t *adv, cs_flag_t loc, cs_real_t *array, cs_lnum_t *index)
Define a cs_adv_field_t structure thanks to an array of values.
Definition: cs_advection_field.c:667
Definition: cs_advection_field.h:118
void cs_advection_field_def_boundary_flux_by_analytic(cs_adv_field_t *adv, const char *zname, cs_analytic_func_t *func, void *input)
Define the value of the boundary normal flux for the given cs_adv_field_t structure using an analytic...
Definition: cs_advection_field.c:769
cs_adv_field_t * cs_advection_field_by_id(int id)
Search in the array of advection field structures which one has the id given in argument.
Definition: cs_advection_field.c:248
Definition: cs_advection_field.h:109
cs_xdef_t ** bdy_flux_defs
Definition: cs_advection_field.h:172
Definition: cs_mesh_location.h:65
Field descriptor.
Definition: cs_field.h:124
cs_mesh_location_type_t
Definition: cs_mesh_location.h:60
void cs_advection_field_def_by_value(cs_adv_field_t *adv, cs_real_t vector[3])
Define the value of a cs_adv_field_t structure.
Definition: cs_advection_field.c:605
void cs_advection_field_def_by_analytic(cs_adv_field_t *adv, cs_analytic_func_t *func, void *input)
Define a cs_adv_field_t structure thanks to an analytic function.
Definition: cs_advection_field.c:634
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.c:2274
void cs_advection_get_courant(const cs_adv_field_t *adv, cs_real_t dt_cur, cs_real_t courant[])
Compute the Courant number in each cell.
Definition: cs_advection_field.c:2209
const char * cs_advection_field_get_name(const cs_adv_field_t *adv)
Retrieve the name of an advection field.
Definition: cs_advection_field.c:464
cs_real_t * cs_advection_field_divergence_at_vertices(const cs_adv_field_t *adv, cs_real_t t_eval)
Compute the divergence of the advection field at vertices Useful for CDO Vertex-based schemes...
Definition: cs_advection_field.c:2254
#define BEGIN_C_DECLS
Definition: cs_defs.h:462
Definition: cs_advection_field.h:86
void cs_advection_field_finalize_setup(void)
Last stage of the definition of an advection field based on several definitions (i.e. definition by subdomains on the boundary)
Definition: cs_advection_field.c:954
cs_advection_field_key_t
List of available keys for setting an advection field.
Definition: cs_advection_field.h:82
int n_bdy_flux_defs
Definition: cs_advection_field.h:171
Set of local quantities and connectivities related to a mesh cell This is a key structure for all cel...
Definition: cs_cdo_local.h:163
cs_advection_field_type_t type
Definition: cs_advection_field.h:159
Definition: cs_advection_field.h:107
void cs_advection_field_at_vertices(const cs_adv_field_t *adv, cs_real_t time_eval, cs_real_t *vtx_values)
Compute the value of the advection field at vertices.
Definition: cs_advection_field.c:1152
Definition: cs_cdo_connect.h:74
void cs_advection_field_in_cells(const cs_adv_field_t *adv, cs_real_t time_eval, cs_real_t *cell_values)
Compute the mean-value of the advection field inside each cell.
Definition: cs_advection_field.c:1033
Definition: field.f90:27
Definition: cs_mesh_location.h:66
cs_adv_field_t * cs_advection_field_add(const char *name, cs_advection_field_type_t type)
Add and initialize a new advection field structure.
Definition: cs_advection_field.c:288
int id
Definition: cs_advection_field.h:157
void cs_advection_field_set_option(cs_adv_field_t *adv, cs_advection_field_key_t key)
Set optional parameters related to a cs_adv_field_t structure.
Definition: cs_advection_field.c:569
void bft_error(const char *const file_name, const int line_num, const int sys_error_code, const char *const format,...)
Calls the error handler (set by bft_error_handler_set() or default).
Definition: bft_error.c:193
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
int cs_advection_field_get_n_fields(void)
Get the number of allocated cs_adv_field_t structures.
Definition: cs_advection_field.c:203
Definition: cs_cdo_quantities.h:94
cs_flag_t flag
Definition: cs_advection_field.h:161
Definition: cs_defs.h:338
Definition: cs_advection_field.h:85
cs_advection_field_type_t
Type of advection field.
Definition: cs_advection_field.h:105
cs_xdef_t * definition
Definition: cs_advection_field.h:168
Definition: cs_advection_field.h:110
void cs_advection_field_get_cell_vector(cs_lnum_t c_id, const cs_adv_field_t *adv, cs_nvec3_t *vect)
Compute the value of the advection field at the cell center.
Definition: cs_advection_field.c:1005
void cs_advection_field_across_boundary(const cs_adv_field_t *adv, cs_real_t time_eval, cs_real_t *flx_values)
Compute the value of the normal flux of the advection field across the boundary faces.
Definition: cs_advection_field.c:1376
short int * bdy_def_ids
Definition: cs_advection_field.h:173
Definition: cs_advection_field.h:84
cs_xdef_type_t cs_advection_field_get_deftype(const cs_adv_field_t *adv)
Retrieve the type of definition used to set the current advection field structure.
Definition: cs_advection_field.c:484
cs_xdef_type_t
Definition: cs_xdef.h:82
int vtx_field_id
Definition: cs_advection_field.h:162
void cs_advection_field_update(cs_real_t t_eval, bool cur2prev)
For each cs_adv_field_t structures, update the values of the related field(s)
Definition: cs_advection_field.c:2093
static int input(void)
void cs_advection_field_set_shared_pointers(const cs_cdo_quantities_t *quant, const cs_cdo_connect_t *connect)
Set shared pointers to main domain members.
Definition: cs_advection_field.c:186
Definition: cs_mesh_location.h:63
Structure storing medata for defining a quantity in a very flexible way.
Definition: cs_xdef.h:126
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:310
int bdy_field_id
Definition: cs_advection_field.h:164
Definition: cs_advection_field.h:87
cs_adv_field_t * cs_advection_field_by_name(const char *name)
Search in the array of advection field structures which one has the name given in argument...
Definition: cs_advection_field.c:220
cs_adv_field_t * cs_advection_field_add_user(const char *name)
Add and initialize a new user-defined advection field structure.
Definition: cs_advection_field.c:271
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
void cs_advection_field_log_setup(void)
Print all setup information related to cs_adv_field_t structures.
Definition: cs_advection_field.c:499
static cs_field_t * cs_advection_field_get_field(const cs_adv_field_t *adv, cs_mesh_location_type_t ml_type)
Get a cs_field_t structure related to an advection field and a mesh location.
Definition: cs_advection_field.h:198
void cs_advection_field_create_fields(void)
Create all needed cs_field_t structures related to an advection field.
Definition: cs_advection_field.c:850
int cell_field_id
Definition: cs_advection_field.h:163
void cs_advection_field_eval_at_xyz(const cs_adv_field_t *adv, const cs_cell_mesh_t *cm, const cs_real_3_t xyz, cs_real_t time_eval, cs_nvec3_t *eval)
Compute the value of the advection field at a specific location inside a cell.
Definition: cs_advection_field.c:1315
#define END_C_DECLS
Definition: cs_defs.h:463
void cs_advection_field_destroy_all(void)
Free all alllocated cs_adv_field_t structures and its related array.
Definition: cs_advection_field.c:345
unsigned short int cs_flag_t
Definition: cs_defs.h:299
void cs_advection_field_def_boundary_flux_by_value(cs_adv_field_t *adv, const char *zname, cs_real_t normal_flux)
Define the value of the boundary normal flux for the given cs_adv_field_t structure.
Definition: cs_advection_field.c:733
void cs_advection_field_def_boundary_flux_by_array(cs_adv_field_t *adv, const char *zname, cs_flag_t loc, cs_real_t *array, cs_lnum_t *index)
Define the value of the boundary normal flux for the given cs_adv_field_t structure using an array of...
Definition: cs_advection_field.c:809
void cs_advection_field_get_cw_face_flux(const cs_cell_mesh_t *cm, const cs_adv_field_t *adv, cs_real_t time_eval, cs_real_t *fluxes)
Compute the value of the flux of the advection field across the the (primal) faces of a cell...
Definition: cs_advection_field.c:1754
void cs_advection_field_get_f2v_boundary_flux(const cs_cell_mesh_t *cm, const cs_adv_field_t *adv, short int f, cs_real_t time_eval, cs_real_t *fluxes)
Compute the value of the flux of the advection field across the the closure of the dual cell related ...
Definition: cs_advection_field.c:1594
char *restrict name
Definition: cs_advection_field.h:158
bool cs_advection_field_is_cellwise(const cs_adv_field_t *adv)
returns true if the advection field is uniform in each cell otherwise false
Definition: cs_advection_field.c:438
Definition: cs_advection_field.h:108
void cs_advection_field_get_cw_dface_flux(const cs_cell_mesh_t *cm, const cs_adv_field_t *adv, cs_real_t time_eval, cs_real_t *fluxes)
Compute the value of the flux of the advection field across the the dual faces of a cell...
Definition: cs_advection_field.c:1879
Definition: cs_property.h:104
void cs_advection_field_def_by_field(cs_adv_field_t *adv, cs_field_t *field)
Define a cs_adv_field_t structure thanks to an array of values.
Definition: cs_advection_field.c:701
void cs_advection_get_peclet(const cs_adv_field_t *adv, const cs_property_t *diff, cs_real_t t_eval, cs_real_t peclet[])
Compute the Peclet number in each cell.
Definition: cs_advection_field.c:2161
bool cs_advection_field_check_name(const cs_adv_field_t *adv, const char *ref_name)
Check if the given advection field has the name ref_name.
Definition: cs_advection_field.c:385