7.3
general documentation
cs_xdef.h
Go to the documentation of this file.
1 #ifndef __CS_XDEF_H__
2 #define __CS_XDEF_H__
3 
4 /*============================================================================
5  * Functions to handle extended definitions of quantities
6  *============================================================================*/
7 
8 /*
9  This file is part of code_saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2022 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 <string.h>
35 
36 #include "cs_base.h"
37 #include "cs_boundary_zone.h"
38 #include "cs_field.h"
39 #include "cs_param_types.h"
40 #include "cs_quadrature.h"
41 #include "cs_volume_zone.h"
42 
43 /*----------------------------------------------------------------------------*/
44 
46 
47 /*============================================================================
48  * Macro definitions
49  *============================================================================*/
50 
51 /*============================================================================
52  * Type definitions
53  *============================================================================*/
54 
55 /*----------------------------------------------------------------------------*/
68 /*----------------------------------------------------------------------------*/
69 
70 typedef void *
71 (cs_xdef_free_input_t)(void *input);
72 
109 typedef enum {
110 
120 
122 
124 
139 typedef enum {
140 
141  CS_XDEF_SUPPORT_TIME, /* support for time step description */
142  CS_XDEF_SUPPORT_BOUNDARY, /* zones attached to boundary faces */
144 
146 
148 
155 typedef struct {
156 
189  int dim;
190  cs_xdef_type_t type;
191  int z_id;
192  cs_xdef_support_t support;
193 
196 
198 
199  void *context;
200 
201 } cs_xdef_t;
202 
208 typedef struct {
209 
240  int z_id;
241  int stride;
244  bool is_owner;
245 
246  const cs_lnum_t *index;
247  const cs_lnum_t *ids;
248 
250 
256 typedef struct {
257 
262  int z_id;
263 
269 
275  void *input;
276 
282 
284 
290 typedef struct {
291 
296  int z_id;
297 
304 
310 
315  void *input;
316 
322 
324 
330 typedef struct {
331 
337 
343  void *input;
344 
350 
352 
353 /*============================================================================
354  * Public function prototypes
355  *============================================================================*/
356 
357 /*----------------------------------------------------------------------------*/
366 /*----------------------------------------------------------------------------*/
367 
368 static inline int
369 cs_get_vol_zone_id(const char *z_name)
370 {
371  if (z_name != NULL) {
372  if (strlen(z_name) > 0) {
373  const cs_zone_t *z = cs_volume_zone_by_name(z_name);
374  assert(z != NULL);
375  return z->id;
376  }
377  }
378 
379  return 0; /* Return the default zone by default */
380 }
381 
382 /*----------------------------------------------------------------------------*/
391 /*----------------------------------------------------------------------------*/
392 
393 static inline int
394 cs_get_bdy_zone_id(const char *z_name)
395 {
396  if (z_name != NULL) {
397  if (strlen(z_name) > 0) {
398  const cs_zone_t *z = cs_boundary_zone_by_name(z_name);
399  assert(z != NULL);
400  return z->id;
401  }
402  }
403 
404  return 0; /* Return the default zone by default */
405 }
406 
407 /*----------------------------------------------------------------------------*/
417 /*----------------------------------------------------------------------------*/
418 
419 static inline cs_real_t
421 {
422  assert(def != NULL);
423  assert(def->dim == 1);
424  assert(def->type == CS_XDEF_BY_VALUE);
425 
426  cs_real_t *value = (cs_real_t *)def->context;
427 
428  return value[0];
429 }
430 
431 /*----------------------------------------------------------------------------*/
440 /*----------------------------------------------------------------------------*/
441 
442 static inline cs_real_t *
444 {
445  if (def == NULL)
446  return NULL;
447 
448  assert(def->type == CS_XDEF_BY_ARRAY);
449 
451 
452  return ai->values;
453 }
454 
455 /*----------------------------------------------------------------------------*/
464 /*----------------------------------------------------------------------------*/
465 
466 static inline cs_field_t *
468 {
469  if (def == NULL)
470  return NULL;
471 
472  assert(def->type == CS_XDEF_BY_FIELD);
473 
474  return (cs_field_t *)def->context;
475 }
476 
477 /*============================================================================
478  * Public function prototypes
479  *============================================================================*/
480 
481 /*----------------------------------------------------------------------------*/
495 /*----------------------------------------------------------------------------*/
496 
497 cs_xdef_t *
498 cs_xdef_volume_create(cs_xdef_type_t type,
499  int dim,
500  int z_id,
501  cs_flag_t state,
502  cs_flag_t meta,
503  void *context);
504 
505 /*----------------------------------------------------------------------------*/
519 /*----------------------------------------------------------------------------*/
520 
521 cs_xdef_t *
522 cs_xdef_boundary_create(cs_xdef_type_t type,
523  int dim,
524  int z_id,
525  cs_flag_t state,
526  cs_flag_t meta,
527  void *context);
528 
529 /*----------------------------------------------------------------------------*/
542 /*----------------------------------------------------------------------------*/
543 
544 cs_xdef_t *
545 cs_xdef_timestep_create(cs_xdef_type_t type,
546  cs_flag_t state,
547  cs_flag_t meta,
548  void *context);
549 
550 /*----------------------------------------------------------------------------*/
558 /*----------------------------------------------------------------------------*/
559 
560 cs_xdef_t *
562 
563 /*----------------------------------------------------------------------------*/
571 /*----------------------------------------------------------------------------*/
572 
573 cs_xdef_t *
574 cs_xdef_copy(cs_xdef_t *src);
575 
576 /*----------------------------------------------------------------------------*/
587 /*----------------------------------------------------------------------------*/
588 
589 void
591  void *input);
592 
593 /*----------------------------------------------------------------------------*/
604 /*----------------------------------------------------------------------------*/
605 
606 void
608  cs_xdef_free_input_t *free_input);
609 
610 /*----------------------------------------------------------------------------*/
619 /*----------------------------------------------------------------------------*/
620 
621 void
623  bool is_owner,
624  cs_real_t *array);
625 
626 /*----------------------------------------------------------------------------*/
636 /*----------------------------------------------------------------------------*/
637 
638 void
640  int z_id);
641 
642 /*----------------------------------------------------------------------------*/
651 /*----------------------------------------------------------------------------*/
652 
653 void
655  const cs_lnum_t *index,
656  const cs_lnum_t *ids);
657 
658 /*----------------------------------------------------------------------------*/
666 /*----------------------------------------------------------------------------*/
667 
668 void
670  cs_quadrature_type_t qtype);
671 
672 /*----------------------------------------------------------------------------*/
681 /*----------------------------------------------------------------------------*/
682 
685 
686 /*----------------------------------------------------------------------------*/
694 /*----------------------------------------------------------------------------*/
695 
696 cs_xdef_type_t
697 cs_xdef_get_type(const cs_xdef_t *d);
698 
699 /*----------------------------------------------------------------------------*/
707 /*----------------------------------------------------------------------------*/
708 
709 cs_flag_t
711 
712 /*----------------------------------------------------------------------------*/
720 /*----------------------------------------------------------------------------*/
721 
722 cs_real_t *
724 
725 /*----------------------------------------------------------------------------*/
733 /*----------------------------------------------------------------------------*/
734 
735 void
736 cs_xdef_log_setup(const char *prefix,
737  const cs_xdef_t *d);
738 
739 /*----------------------------------------------------------------------------*/
747 /*----------------------------------------------------------------------------*/
748 
749 void
750 cs_xdef_log(cs_log_t log_type,
751  const char *prefix,
752  const cs_xdef_t *d);
753 
754 /*----------------------------------------------------------------------------*/
762 /*----------------------------------------------------------------------------*/
763 
764 const char *
765 cs_xdef_type_get_name(cs_xdef_type_t xdef_type);
766 
767 /*----------------------------------------------------------------------------*/
768 
770 
771 #endif /* __CS_XDEF_H__ */
cs_xdef_t * cs_xdef_boundary_create(cs_xdef_type_t type, int dim, int z_id, cs_flag_t state, cs_flag_t meta, void *context)
Allocate and initialize a new cs_xdef_t structure based on boundary elements.
Definition: cs_xdef.c:287
cs_analytic_func_t * func
Definition: cs_xdef.h:268
cs_xdef_t * cs_xdef_timestep_create(cs_xdef_type_t type, cs_flag_t state, cs_flag_t meta, void *context)
Allocate and initialize a new cs_xdef_t structure for setting the time step.
Definition: cs_xdef.c:445
cs_quadrature_type_t cs_xdef_get_quadrature(cs_xdef_t *d)
Get the type of quadrature to use for evaluating the given description.
Definition: cs_xdef.c:883
cs_time_func_t * func
Definition: cs_xdef.h:336
cs_xdef_t * cs_xdef_free(cs_xdef_t *d)
Free a cs_xdef_t structure.
Definition: cs_xdef.c:515
Field descriptor.
Definition: cs_field.h:130
void cs_xdef_set_input_context(cs_xdef_t *d, void *input)
In the case of a definition by an analytic function, a time function or a function relying on degrees...
Definition: cs_xdef.c:655
Definition: cs_xdef.h:119
const cs_zone_t * cs_boundary_zone_by_name(const char *name)
Return a pointer to a boundary zone based on its name if present.
Definition: cs_boundary_zone.c:711
int id
Definition: cs_zone.h:59
Definition: cs_xdef.h:141
cs_real_t * values
Definition: cs_xdef.h:243
cs_real_t * cs_xdef_get_field_values(cs_xdef_t *def)
Get the current field values in case of definition by field.
Definition: cs_xdef.c:940
#define BEGIN_C_DECLS
Definition: cs_defs.h:512
Definition: cs_xdef.h:114
Context structure when a time step function is used for the definition.
Definition: cs_xdef.h:330
cs_xdef_free_input_t * free_input
Definition: cs_xdef.h:321
const cs_zone_t * cs_volume_zone_by_name(const char *name)
Return a pointer to a volume zone based on its name if present.
Definition: cs_volume_zone.c:680
void * context
Definition: cs_xdef.h:199
cs_flag_t state
Definition: cs_xdef.h:194
Definition: cs_xdef.h:112
cs_xdef_type_t cs_xdef_get_type(const cs_xdef_t *d)
Retrieve the flag dedicated to the state.
Definition: cs_xdef.c:902
Definition: cs_xdef.h:143
Definition: cs_xdef.h:117
void cs_xdef_set_array_pointers(cs_xdef_t *d, const cs_lnum_t *index, const cs_lnum_t *ids)
In case of definition by array, set the optional index and ids arrays that may be useful when operati...
Definition: cs_xdef.c:833
cs_xdef_t * cs_xdef_copy(cs_xdef_t *src)
copy a cs_xdef_t structure
Definition: cs_xdef.c:594
void cs_xdef_set_array(cs_xdef_t *d, bool is_owner, cs_real_t *array)
In case of definition by array, set the array after having added this definition. ...
Definition: cs_xdef.c:767
cs_xdef_free_input_t * free_input
Definition: cs_xdef.h:349
int z_id
Definition: cs_xdef.h:296
static cs_real_t * cs_xdef_get_array(cs_xdef_t *def)
Retrieve the values associated to the given definition. This should be a definition by array...
Definition: cs_xdef.h:443
cs_flag_t cs_xdef_get_state_flag(const cs_xdef_t *d)
Retrieve the flag dedicated to the state.
Definition: cs_xdef.c:921
double cs_real_t
Floating-point value.
Definition: cs_defs.h:322
int dim
Definition: cs_xdef.h:189
cs_xdef_type_t type
Definition: cs_xdef.h:190
void * input
Definition: cs_xdef.h:315
static cs_real_t cs_xdef_get_scalar_value(cs_xdef_t *def)
Retrieve the value associated to the given definition. This should be a definition by value and the d...
Definition: cs_xdef.h:420
Context structure when a definition by analytic function is used.
Definition: cs_xdef.h:256
const cs_lnum_t * ids
Definition: cs_xdef.h:247
Definition: cs_xdef.h:116
cs_xdef_support_t
Definition: cs_xdef.h:139
void() cs_dof_func_t(cs_lnum_t n_elts, const cs_lnum_t *elt_ids, bool dense_output, void *input, cs_real_t *retval)
Generic function pointer for computing a quantity at predefined locations such as degrees of freedom ...
Definition: cs_param_types.h:154
int z_id
Definition: cs_xdef.h:240
cs_quadrature_type_t
Definition: cs_quadrature.h:52
void cs_xdef_set_quadrature(cs_xdef_t *d, cs_quadrature_type_t qtype)
Set the type of quadrature to use for evaluating the given description.
Definition: cs_xdef.c:862
cs_flag_t loc
Definition: cs_xdef.h:242
Context structure when a definition by DoF function is used.
Definition: cs_xdef.h:290
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 dense_output, void *input, cs_real_t *retval)
Generic function pointer for an evaluation relying on an analytic function.
Definition: cs_param_types.h:127
cs_dof_func_t * func
Definition: cs_xdef.h:309
cs_quadrature_type_t qtype
Definition: cs_xdef.h:197
cs_xdef_type_t
Definition: cs_xdef.h:109
Definition: cs_xdef.h:111
int z_id
Definition: cs_xdef.h:262
Definition: cs_xdef.h:118
void * input
Definition: cs_xdef.h:275
int stride
Definition: cs_xdef.h:241
Structure storing medata for defining a quantity in a very flexible way.
Definition: cs_xdef.h:155
cs_log_t
Definition: cs_log.h:48
void cs_xdef_set_free_input_function(cs_xdef_t *d, cs_xdef_free_input_t *free_input)
In case of a definition by an analytic function, a time function or a function relying on degrees of ...
Definition: cs_xdef.c:712
Definition: cs_xdef.h:145
static int cs_get_vol_zone_id(const char *z_name)
Retrieve the volume zone if from the zone name (If name = NULL or has an empty length, all entities are selected)
Definition: cs_xdef.h:369
void cs_xdef_log_setup(const char *prefix, const cs_xdef_t *d)
Output the settings related to a cs_xdef_t structure in the setup logging file.
Definition: cs_xdef.c:967
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:316
cs_xdef_support_t support
Definition: cs_xdef.h:192
Definition: cs_xdef.h:115
#define END_C_DECLS
Definition: cs_defs.h:513
void cs_xdef_set_array_zone_id(cs_xdef_t *d, int z_id)
In case of definition by array, set the zone id related to the size of the array. By default...
Definition: cs_xdef.c:805
unsigned short int cs_flag_t
Definition: cs_defs.h:324
void() cs_time_func_t(double time, void *input, cs_real_t *retval)
Function which defines the evolution of a quantity according to the current time and any structure gi...
Definition: cs_param_types.h:172
cs_xdef_free_input_t * free_input
Definition: cs_xdef.h:281
bool is_owner
Definition: cs_xdef.h:244
cs_flag_t meta
Definition: cs_xdef.h:195
Definition: cs_xdef.h:113
const cs_lnum_t * index
Definition: cs_xdef.h:246
int z_id
Definition: cs_xdef.h:191
void * input
Definition: cs_xdef.h:343
Context structure when an array is used for the definition.
Definition: cs_xdef.h:208
const char * cs_xdef_type_get_name(cs_xdef_type_t xdef_type)
Retrieve a pointer to the cs_xdef_type&#39;s name string.
Definition: cs_xdef.c:1124
static int cs_get_bdy_zone_id(const char *z_name)
Retrieve the boundary zone if from the zone name (If name = NULL or has an empty length, all entities are selected)
Definition: cs_xdef.h:394
Definition: cs_xdef.h:121
Definition: cs_xdef.h:142
cs_xdef_t * cs_xdef_volume_create(cs_xdef_type_t type, int dim, int z_id, cs_flag_t state, cs_flag_t meta, void *context)
Allocate and initialize a new cs_xdef_t structure based on volumic elements.
Definition: cs_xdef.c:115
void *() cs_xdef_free_input_t(void *input)
Destroy an input data structure. Complex data structure can be used when a cs_xdef_t structure is def...
Definition: cs_xdef.h:71
void cs_xdef_log(cs_log_t log_type, const char *prefix, const cs_xdef_t *d)
Output the settings related to a cs_xdef_t structure.
Definition: cs_xdef.c:984
cs_flag_t loc
Definition: cs_xdef.h:303
static cs_field_t * cs_xdef_get_field(cs_xdef_t *def)
When the definition relies on a cs_field_t structure, return the pointer to the field structure...
Definition: cs_xdef.h:467
Definition: cs_zone.h:55