6.3
general documentation
cs_property.h
Go to the documentation of this file.
1 #ifndef __CS_PROPERTY_H__
2 #define __CS_PROPERTY_H__
3 
4 /*============================================================================
5  * Manage the definition/setting of properties
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2020 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_field.h"
35 #include "cs_flag.h"
36 #include "cs_param_types.h"
37 #include "cs_xdef.h"
38 #include "cs_xdef_cw_eval.h"
39 #include "cs_xdef_eval.h"
40 
41 /*----------------------------------------------------------------------------*/
42 
44 
45 /*============================================================================
46  * Macro definitions
47  *============================================================================*/
48 
49 /* Common property names (property which is shared between different module) */
50 
51 #define CS_PROPERTY_MASS_DENSITY "mass_density"
52 
60 #define CS_PROPERTY_POST_FOURIER (1 << 0)
61 
73 #define CS_PROPERTY_ISO (1 << 0)
74 
78 #define CS_PROPERTY_ORTHO (1 << 1)
79 
84 #define CS_PROPERTY_ANISO (1 << 2)
85 
86 
90 #define CS_PROPERTY_BY_PRODUCT (1 << 3)
91 
94 /*============================================================================
95  * Type definitions
96  *============================================================================*/
97 
99 
107 typedef enum {
108 
111 
113 
114 /* ======================================== */
115 /* Set of parameters attached to a property */
116 /* ======================================== */
117 
124 typedef struct _cs_property_t cs_property_t;
125 
127 
128  char *restrict name;
129  int id;
133 
134  /* Reference value wich is used as default when nothing else is set. This
135  * value can also be used to renormalized quantities related to this property
136  * By default, this is set to 1
137  */
139 
140  /* Property is up to now only defined on the whole domain (volume) */
141  int n_definitions; /* Current number of definitions used */
142  cs_xdef_t **defs; /* List of definitions */
143 
144  /* Store the definition id for each cell, NULL if there is only one
145  definition set */
146  short int *def_ids;
147 
148  /* Function pointers to handle generic tasks related to a property. There
149  is one function related to each definition. Some functions may not be
150  allocated according to the kind of property */
151 
152  /* Retrieve the evaluation of the property at the cell center for each
153  definition */
155 
156  /* Same thing as the previous one but now with the usage of cellwise algo.
157  relying on a cs_cell_mesh_t structure */
159 
160  /* For properties relying on other properties for their definition, one
161  * stores the pointers to these related properties */
164 
165 };
166 
167 
174 typedef struct {
175 
176  const cs_property_t *property; /* shared pointer */
177 
178  bool is_iso; /* Detect if this an easier case */
179  bool is_unity; /* Detect if this a simple case */
180 
184 
186  cs_real_t tensor[3][3];
188 
190 
191 /*============================================================================
192  * Global variables
193  *============================================================================*/
194 
195 /*============================================================================
196  * Static inline public function prototypes
197  *============================================================================*/
198 
199 /*----------------------------------------------------------------------------*/
207 /*----------------------------------------------------------------------------*/
208 
209 static inline bool
210 cs_property_is_constant(const cs_property_t *pty)
211 {
212  if (pty == NULL)
213  return true; /* Treated as the "unity" property */
214 
215  if (pty->state_flag & CS_FLAG_STATE_STEADY) {
216  if (pty->state_flag & CS_FLAG_STATE_UNIFORM)
217  return true;
218  else
219  return false;
220  }
221  else
222  return false;
223 }
224 
225 /*----------------------------------------------------------------------------*/
233 /*----------------------------------------------------------------------------*/
234 
235 static inline bool
236 cs_property_is_steady(const cs_property_t *pty)
237 {
238  if (pty == NULL)
239  return true; /* Treated as the "unity" property */
240 
241  if (pty->state_flag & CS_FLAG_STATE_STEADY)
242  return true;
243  else
244  return false;
245 }
246 
247 /*----------------------------------------------------------------------------*/
255 /*----------------------------------------------------------------------------*/
256 
257 static inline bool
258 cs_property_is_uniform(const cs_property_t *pty)
259 {
260  if (pty == NULL)
261  return true; /* Treated as the "unity" property */
262 
263  if (pty->state_flag & CS_FLAG_STATE_UNIFORM)
264  return true;
265  else
266  return false;
267 }
268 
269 /*----------------------------------------------------------------------------*/
277 /*----------------------------------------------------------------------------*/
278 
279 static inline bool
280 cs_property_is_isotropic(const cs_property_t *pty)
281 {
282  if (pty == NULL)
283  return false;
284 
285  if (pty->type & CS_PROPERTY_ISO)
286  return true;
287  else
288  return false;
289 }
290 
291 /*----------------------------------------------------------------------------*/
299 /*----------------------------------------------------------------------------*/
300 
301 static inline const char *
302 cs_property_get_name(const cs_property_t *pty)
303 {
304  if (pty == NULL)
305  return NULL;
306 
307  return pty->name;
308 }
309 
310 /*----------------------------------------------------------------------------*/
318 /*----------------------------------------------------------------------------*/
319 
320 static inline cs_property_type_t
321 cs_property_get_type(const cs_property_t *pty)
322 {
323  if (pty == NULL)
324  return 0; /* means undefined */
325 
326  return pty->type;
327 }
328 
329 /*============================================================================
330  * Public function prototypes
331  *============================================================================*/
332 
333 /*----------------------------------------------------------------------------*/
340 /*----------------------------------------------------------------------------*/
341 
342 void
344  const cs_cdo_connect_t *connect);
345 
346 /*----------------------------------------------------------------------------*/
352 /*----------------------------------------------------------------------------*/
353 
354 int
356 
357 /*----------------------------------------------------------------------------*/
366 /*----------------------------------------------------------------------------*/
367 
369 cs_property_add(const char *name,
370  cs_property_type_t type);
371 
372 /*----------------------------------------------------------------------------*/
386 /*----------------------------------------------------------------------------*/
387 
389 cs_property_add_as_product(const char *name,
390  const cs_property_t *pty_a,
391  const cs_property_t *pty_b);
392 
393 /*----------------------------------------------------------------------------*/
401 /*----------------------------------------------------------------------------*/
402 
404 cs_property_by_name(const char *name);
405 
406 /*----------------------------------------------------------------------------*/
414 /*----------------------------------------------------------------------------*/
415 
417 cs_property_by_id(int id);
418 
419 /*----------------------------------------------------------------------------*/
426 /*----------------------------------------------------------------------------*/
427 
428 void
430  cs_property_key_t key);
431 
432 /*----------------------------------------------------------------------------*/
440 /*----------------------------------------------------------------------------*/
441 
442 void
444  double refval);
445 
446 /*----------------------------------------------------------------------------*/
451 /*----------------------------------------------------------------------------*/
452 
453 void
455 
456 /*----------------------------------------------------------------------------*/
461 /*----------------------------------------------------------------------------*/
462 
463 void
465 
466 /*----------------------------------------------------------------------------*/
476 /*----------------------------------------------------------------------------*/
477 
478 void
479 cs_property_data_init(bool need_tensor,
480  bool need_eigen,
481  const cs_property_t *property,
482  cs_property_data_t *data);
483 
484 /*----------------------------------------------------------------------------*/
496 /*----------------------------------------------------------------------------*/
497 
498 cs_xdef_t *
500  double val);
501 
502 /*----------------------------------------------------------------------------*/
514 /*----------------------------------------------------------------------------*/
515 
516 cs_xdef_t *
518  const char *zname,
519  double val);
520 
521 /*----------------------------------------------------------------------------*/
533 /*----------------------------------------------------------------------------*/
534 
535 cs_xdef_t *
537  const char *zname,
538  double val[]);
539 
540 /*----------------------------------------------------------------------------*/
552 /*----------------------------------------------------------------------------*/
553 
554 cs_xdef_t *
556  const char *zname,
557  cs_real_t tens[3][3]);
558 
559 /*----------------------------------------------------------------------------*/
572 /*----------------------------------------------------------------------------*/
573 
574 cs_xdef_t *
576  const char *zname,
577  cs_time_func_t *func,
578  void *input);
579 
580 /*----------------------------------------------------------------------------*/
593 /*----------------------------------------------------------------------------*/
594 
595 cs_xdef_t *
597  const char *zname,
598  cs_analytic_func_t *func,
599  void *input);
600 
601 /*----------------------------------------------------------------------------*/
616 /*----------------------------------------------------------------------------*/
617 
618 cs_xdef_t *
620  const char *zname,
621  void *context,
622  cs_xdef_eval_t *get_eval_at_cell,
623  cs_xdef_cw_eval_t *get_eval_at_cell_cw);
624 
625 /*----------------------------------------------------------------------------*/
638 /*----------------------------------------------------------------------------*/
639 
640 cs_xdef_t *
642  cs_flag_t loc,
643  cs_real_t *array,
644  bool is_owner,
645  cs_lnum_t *index);
646 
647 /*----------------------------------------------------------------------------*/
654 /*----------------------------------------------------------------------------*/
655 
656 void
658  cs_field_t *field);
659 
660 /*----------------------------------------------------------------------------*/
669 /*----------------------------------------------------------------------------*/
670 
671 void
673  const cs_property_t *pty,
674  cs_real_t *array);
675 
676 /*----------------------------------------------------------------------------*/
687 /*----------------------------------------------------------------------------*/
688 
689 void
691  cs_real_t t_eval,
692  const cs_property_t *pty,
693  bool do_inversion,
694  cs_real_t tensor[3][3]);
695 
696 /*----------------------------------------------------------------------------*/
706 /*----------------------------------------------------------------------------*/
707 
708 cs_real_t
710  cs_real_t t_eval,
711  const cs_property_t *pty);
712 
713 /*----------------------------------------------------------------------------*/
725 /*----------------------------------------------------------------------------*/
726 
727 void
729  const cs_property_t *pty,
730  cs_real_t t_eval,
731  bool do_inversion,
732  cs_real_t tensor[3][3]);
733 
734 /*----------------------------------------------------------------------------*/
745 /*----------------------------------------------------------------------------*/
746 
747 cs_real_t
749  const cs_property_t *pty,
750  cs_real_t t_eval);
751 
752 /*----------------------------------------------------------------------------*/
761 /*----------------------------------------------------------------------------*/
762 
763 void
765  cs_real_t t_eval,
766  double dt,
767  cs_real_t fourier[]);
768 
769 /*----------------------------------------------------------------------------*/
774 /*----------------------------------------------------------------------------*/
775 
776 void
778 
779 /*----------------------------------------------------------------------------*/
780 
782 
783 #endif /* __CS_PROPERTY_H__ */
cs_property_data_t::value
cs_real_t value
Definition: cs_property.h:187
cs_property_data_t::need_eigen
bool need_eigen
Definition: cs_property.h:181
cs_property_def_by_analytic
cs_xdef_t * cs_property_def_by_analytic(cs_property_t *pty, const char *zname, cs_analytic_func_t *func, void *input)
Define a cs_property_t structure thanks to an analytic function in a subdomain attached to the mesh l...
Definition: cs_property.c:1368
cs_property_add_as_product
cs_property_t * cs_property_add_as_product(const char *name, const cs_property_t *pty_a, const cs_property_t *pty_b)
Define a cs_property_t structure thanks to the product of two properties The type is infered from tha...
Definition: cs_property.c:704
CS_FLAG_STATE_STEADY
#define CS_FLAG_STATE_STEADY
Definition: cs_flag.h:90
cs_property_def_ortho_by_value
cs_xdef_t * cs_property_def_ortho_by_value(cs_property_t *pty, const char *zname, double val[])
Define an orthotropic cs_property_t structure by value for entities related to a volume zone.
Definition: cs_property.c:1189
cs_xdef_cw_eval.h
cs_xdef_t
Structure storing medata for defining a quantity in a very flexible way.
Definition: cs_xdef.h:154
cs_analytic_func_t
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 elt_ids is optional....
Definition: cs_param_types.h:94
cs_property_add
cs_property_t * cs_property_add(const char *name, cs_property_type_t type)
Create and initialize a new property structure.
Definition: cs_property.c:655
_cs_property_t::type
cs_property_type_t type
Definition: cs_property.h:132
field
Definition: field.f90:27
restrict
#define restrict
Definition: cs_defs.h:124
cs_property_get_n_properties
int cs_property_get_n_properties(void)
Retrieve the number of properties.
Definition: cs_property.c:638
cs_time_func_t
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:137
cs_property_set_option
void cs_property_set_option(cs_property_t *pty, cs_property_key_t key)
Set optional parameters related to a cs_property_t structure.
Definition: cs_property.c:812
cs_property_log_setup
void cs_property_log_setup(void)
Print a summary of the settings for all defined cs_property_t structures.
Definition: cs_property.c:2067
dt
@ dt
Definition: cs_field_pointer.h:65
CS_FLAG_STATE_UNIFORM
#define CS_FLAG_STATE_UNIFORM
Definition: cs_flag.h:87
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:493
_cs_property_t::name
char *restrict name
Definition: cs_property.h:128
CS_PROPERTY_ISO
#define CS_PROPERTY_ISO
Definition: cs_property.h:73
cs_property_finalize_setup
void cs_property_finalize_setup(void)
Last stage of the definition of a property based on several definitions (i.e. definition by subdomain...
Definition: cs_property.c:904
cs_property_set_shared_pointers
void cs_property_set_shared_pointers(const cs_cdo_quantities_t *quant, const cs_cdo_connect_t *connect)
Set shared pointers to main domain members.
Definition: cs_property.c:621
cs_xdef_cw_eval_t
void() cs_xdef_cw_eval_t(const cs_cell_mesh_t *cm, cs_real_t time_eval, void *input, cs_real_t *eval)
Function pointer for evaluating a quantity defined through a descriptor (cs_xdef_t structure) by a ce...
Definition: cs_xdef_cw_eval.h:70
cs_real_t
double cs_real_t
Floating-point value.
Definition: cs_defs.h:304
cs_property_data_t::need_tensor
bool need_tensor
Definition: cs_property.h:185
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:492
_cs_property_t::state_flag
cs_flag_t state_flag
Definition: cs_property.h:130
cs_property_data_t::eigen_max
cs_real_t eigen_max
Definition: cs_property.h:182
CS_PTYKEY_N_KEYS
@ CS_PTYKEY_N_KEYS
Definition: cs_property.h:110
cs_property_type_t
cs_flag_t cs_property_type_t
Definition: cs_property.h:98
cs_property_set_reference_value
void cs_property_set_reference_value(cs_property_t *pty, double refval)
Set the reference value associated to a cs_property_t structure This is a real number even whatever t...
Definition: cs_property.c:845
cs_property_by_name
cs_property_t * cs_property_by_name(const char *name)
Find the related property definition from its name.
Definition: cs_property.c:765
cs_property_def_by_func
cs_xdef_t * cs_property_def_by_func(cs_property_t *pty, const char *zname, void *context, cs_xdef_eval_t *get_eval_at_cell, cs_xdef_cw_eval_t *get_eval_at_cell_cw)
Define a cs_property_t structure thanks to law depending on one scalar variable in a subdomain attach...
Definition: cs_property.c:1422
cs_property_data_t
Structure storing the evaluation of a property and its related data.
Definition: cs_property.h:174
cs_property_destroy_all
void cs_property_destroy_all(void)
Free all cs_property_t structures and the array storing all the structures.
Definition: cs_property.c:862
cs_xdef.h
_cs_property_t::def_ids
short int * def_ids
Definition: cs_property.h:146
_cs_property_t::get_eval_at_cell
cs_xdef_eval_t ** get_eval_at_cell
Definition: cs_property.h:154
cs_property_data_t::is_unity
bool is_unity
Definition: cs_property.h:179
cs_property_def_by_field
void cs_property_def_by_field(cs_property_t *pty, cs_field_t *field)
Define a cs_property_t structure thanks to a field structure.
Definition: cs_property.c:1541
cs_property_eval_at_cells
void cs_property_eval_at_cells(cs_real_t t_eval, const cs_property_t *pty, cs_real_t *array)
Evaluate the value of the property at each cell. Store the evaluation in the given array.
Definition: cs_property.c:1600
cs_property_def_iso_by_value
cs_xdef_t * cs_property_def_iso_by_value(cs_property_t *pty, const char *zname, double val)
Define an isotropic cs_property_t structure by value for entities related to a volume zone.
Definition: cs_property.c:1135
cs_xdef_eval_t
void() cs_xdef_eval_t(cs_lnum_t n_elts, const cs_lnum_t *elt_ids, bool compact, const cs_mesh_t *mesh, const cs_cdo_connect_t *connect, const cs_cdo_quantities_t *quant, cs_real_t time_eval, void *context, cs_real_t *eval)
Function pointer for evaluating a quantity defined through a descriptor (cs_xdef_t structure)
Definition: cs_xdef_eval.h:66
_cs_property_t::n_related_properties
int n_related_properties
Definition: cs_property.h:162
cs_field.h
cs_property_def_by_time_func
cs_xdef_t * cs_property_def_by_time_func(cs_property_t *pty, const char *zname, cs_time_func_t *func, void *input)
Define a cs_property_t structure thanks to an analytic function in a subdomain attached to the mesh l...
Definition: cs_property.c:1298
_cs_property_t::process_flag
cs_flag_t process_flag
Definition: cs_property.h:131
cs_cdo_quantities_t
Definition: cs_cdo_quantities.h:124
cs_property_t
Structure associated to the definition of a property relying on the cs_xdef_t structure.
cs_property_by_id
cs_property_t * cs_property_by_id(int id)
Find the related property definition from its id.
Definition: cs_property.c:792
CS_PTYKEY_POST_FOURIER
@ CS_PTYKEY_POST_FOURIER
Definition: cs_property.h:109
cs_lnum_t
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:298
cs_cdo_connect_t
Definition: cs_cdo_connect.h:76
cs_property_data_init
void cs_property_data_init(bool need_tensor, bool need_eigen, const cs_property_t *property, cs_property_data_t *data)
Initialize a cs_property_data_t structure. If property is NULL then one considers that this is a unit...
Definition: cs_property.c:1015
_cs_property_t::id
int id
Definition: cs_property.h:129
cs_flag.h
_cs_property_t::defs
cs_xdef_t ** defs
Definition: cs_property.h:142
cs_xdef_eval.h
_cs_property_t
Definition: cs_property.h:126
_cs_property_t::ref_value
cs_real_t ref_value
Definition: cs_property.h:138
cs_property_get_cell_value
cs_real_t cs_property_get_cell_value(cs_lnum_t c_id, cs_real_t t_eval, const cs_property_t *pty)
Compute the value of a property at the cell center.
Definition: cs_property.c:1866
_cs_property_t::get_eval_at_cell_cw
cs_xdef_cw_eval_t ** get_eval_at_cell_cw
Definition: cs_property.h:158
cs_property_def_constant_value
cs_xdef_t * cs_property_def_constant_value(cs_property_t *pty, double val)
Define a single uniform and steady isotropic definition for the given cs_property_t structure....
Definition: cs_property.c:1078
cs_property_tensor_in_cell
void cs_property_tensor_in_cell(const cs_cell_mesh_t *cm, const cs_property_t *pty, cs_real_t t_eval, bool do_inversion, cs_real_t tensor[3][3])
Compute the value of the tensor attached to a property at the cell center Version using a cs_cell_mes...
Definition: cs_property.c:1916
cs_property_def_aniso_by_value
cs_xdef_t * cs_property_def_aniso_by_value(cs_property_t *pty, const char *zname, cs_real_t tens[3][3])
Define an anisotropic cs_property_t structure by value for entities related to a volume zone.
Definition: cs_property.c:1239
cs_property_key_t
cs_property_key_t
List of available keys for setting options on a property.
Definition: cs_property.h:107
cs_property_def_by_array
cs_xdef_t * cs_property_def_by_array(cs_property_t *pty, cs_flag_t loc, cs_real_t *array, bool is_owner, cs_lnum_t *index)
Define a cs_property_t structure thanks to an array of values.
Definition: cs_property.c:1469
cs_property_data_t::eigen_ratio
cs_real_t eigen_ratio
Definition: cs_property.h:183
cs_property_data_t::is_iso
bool is_iso
Definition: cs_property.h:178
cs_flag_t
unsigned short int cs_flag_t
Definition: cs_defs.h:306
cs_param_types.h
cs_property_value_in_cell
cs_real_t cs_property_value_in_cell(const cs_cell_mesh_t *cm, const cs_property_t *pty, cs_real_t t_eval)
Compute the value of a property at the cell center Version using a cs_cell_mesh_t structure.
Definition: cs_property.c:1958
_cs_property_t::n_definitions
int n_definitions
Definition: cs_property.h:141
cs_field_t
Field descriptor.
Definition: cs_field.h:125
cs_cell_mesh_t
Set of local quantities and connectivities related to a mesh cell This is a key structure for all cel...
Definition: cs_cdo_local.h:159
cs_property_data_t::property
const cs_property_t * property
Definition: cs_property.h:176
cs_property_get_fourier
void cs_property_get_fourier(const cs_property_t *pty, cs_real_t t_eval, double dt, cs_real_t fourier[])
Compute the Fourier number in each cell.
Definition: cs_property.c:2002
cs_property_get_cell_tensor
void cs_property_get_cell_tensor(cs_lnum_t c_id, cs_real_t t_eval, const cs_property_t *pty, bool do_inversion, cs_real_t tensor[3][3])
Compute the value of the tensor attached to a property at the cell center.
Definition: cs_property.c:1826
_cs_property_t::related_properties
const cs_property_t ** related_properties
Definition: cs_property.h:163