9.1
general documentation
cs_field.h
Go to the documentation of this file.
1#ifndef __CS_FIELD_H__
2#define __CS_FIELD_H__
3
4/*============================================================================
5 * Field management.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2025 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 "base/cs_defs.h"
35#include "base/cs_array.h"
36
37/*----------------------------------------------------------------------------*/
38
40
41/*=============================================================================
42 * Macro definitions
43 *============================================================================*/
44
51/*
52 * Field property type
53 */
54
56#define CS_FIELD_INTENSIVE (1 << 0)
57
59#define CS_FIELD_EXTENSIVE (1 << 1)
60
61/* Field category */
62
64#define CS_FIELD_VARIABLE (1 << 2)
65
67#define CS_FIELD_PROPERTY (1 << 3)
68
70#define CS_FIELD_POSTPROCESS (1 << 4)
71
73#define CS_FIELD_ACCUMULATOR (1 << 5)
74
76#define CS_FIELD_USER (1 << 6)
77
79#define CS_FIELD_CDO (1 << 7)
80
83/*============================================================================
84 * Type definitions
85 *============================================================================*/
86
87/* Field handling error types */
88/*----------------------------*/
89
90typedef enum {
91
99
101
103/*----------------------------------------------------------*/
104
105typedef struct {
106
107 cs_real_t *val_ip; /* variable computed at I' position */
108
109 cs_real_t *val_f; /* face value for gradient */
110
111 cs_real_t *flux; /* face value for diffusion */
112 cs_real_t *flux_lim; /* face value for diffusion
113 (limited) */
114
116
118/*------------------------------------------------------*/
119
120typedef struct {
121
122 int location_id; /* Id of matching location */
123
124 int *icodcl; /* low-level BC type code */
125 cs_real_t *rcodcl1; /* 1st component of low-level BC */
126 cs_real_t *rcodcl2; /* 2nd component of low-level BC
127 (a.k.a. hext Exterior exchange coefficient */
128 cs_real_t *rcodcl3; /* 3rd component of low-level BC */
129
130 cs_real_t *a; /* Explicit coefficient */
131 cs_real_t *b; /* Implicit coefficient */
132 cs_real_t *af; /* Explicit coefficient for flux */
133 cs_real_t *bf; /* Implicit coefficient for flux */
134 cs_real_t *ad; /* Explicit coefficient for divergence */
135 cs_real_t *bd; /* Implicit coefficient for divergence */
136 cs_real_t *ac; /* Explicit coefficient for convection */
137 cs_real_t *bc; /* Implicit coefficient for convection */
138
139 cs_real_t *hint; /* coefficient for internal coupling */
140
141 cs_real_t *val_f; /* face value for gradient */
142 cs_real_t *val_f_lim; /* face value for gradient
143 (limited) */
144
145 cs_real_t *flux; /* face value for diffusion */
146 cs_real_t *flux_lim; /* face value for diffusion
147 (limited) */
148
149 cs_real_t *val_f_pre; /* previous face value for gradient */
150
152
153/* Field descriptor */
154/*------------------*/
155
156typedef struct {
157
158 const char *name; /* Canonical name */
159
160 int id; /* Field id */
161 int type; /* Field type flag */
162
163 int dim; /* Field dimension */
164
165 int location_id; /* Id of matching location */
166
167 int n_time_vals; /* Number of time values */
168
169 cs_real_t **vals; /* For each active location, pointer
170 to matching values arrays
171 vals[0][:] = val
172 vals[1][:] = val_pre
173 vals[p][:] = p ith previous field
174 p < n_time_vals */
175
176
177 cs_real_t *val; /* For each active location, pointer
178 to matching values array */
179
180 cs_real_t *val_pre; /* For each active location, pointer
181 to matching previous values array
182 (if n_time_vals == 2) */
183
184 cs_real_t *grad; /* For each active location, pointer
185 to matching gradient array for
186 variable type fields */
187
188 cs_field_bc_coeffs_t *bc_coeffs; /* Boundary condition coefficients,
189 for variable type fields */
190
191 bool is_owner; /* Ownership flag for values */
192
193#if defined(__cplusplus)
194
195 /* Setter and getter methods for key-based values
196 ---------------------------------------------- */
197
198 int
199 set_key_int(int key_id,
200 int value);
201
202 int
203 set_key_int(const char *key,
204 int value);
205
206 int
207 get_key_int(int key_id);
208
209 int
210 get_key_int(const char *key);
211
212 int
213 set_key_int_bits(int key_id,
214 int mask);
215
216 int
217 set_key_int_bits(const char *key,
218 int mask);
219
220 int
221 clear_key_int_bits(int key_id,
222 int mask);
223
224 int
225 clear_key_int_bits(const char *key,
226 int mask);
227
228 int
229 set_key_double(int key_id,
230 double value);
231
232 int
233 set_key_double(const char *key,
234 double value);
235
236 double
237 get_key_double(int key_id);
238
239 double
240 get_key_double(const char *key);
241
242 int
243 set_key_str(int key_id,
244 const char *str);
245
246 int
247 set_key_str(const char *key,
248 const char *str);
249
250 const char *
251 get_key_str(int key_id);
252
253 const char *
254 get_key_str(const char *key);
255
257 get_vals_s
258 (
259 const int time_id = 0
260 ) const;
261
263 get_vals_v
264 (
265 const int time_id = 0
266 ) const;
267
269 get_vals_t
270 (
271 const int time_id = 0
272 ) const;
273
275 get_vals_alloc_mode
276 (
277 const int time_id = 0
278 ) const;
279
280 void
281 update_size(void);
282
284
285#endif
286
287} cs_field_t;
288
289/*----------------------------------------------------------------------------
290 * Function pointer for structure associated to field key
291 *
292 * parameters:
293 * t <-- pointer to structure
294 *----------------------------------------------------------------------------*/
295
296typedef void
297(cs_field_log_key_struct_t) (const void *t);
298
299/*----------------------------------------------------------------------------
300 * Function pointer for structure associated to field key
301 *
302 * parameters:
303 * t <-- pointer to structure
304 *----------------------------------------------------------------------------*/
305
306typedef void
308
309/*============================================================================
310 * Global variables
311 *============================================================================*/
312
313/* Names for components */
314
315extern const char *cs_glob_field_comp_name_3[];
316extern const char *cs_glob_field_comp_name_6[];
317extern const char *cs_glob_field_comp_name_9[];
318
319/*=============================================================================
320 * Public function prototypes
321 *============================================================================*/
322
323/*----------------------------------------------------------------------------
324 * Create bc_coeffs structure.
325 *
326 * \param[in] bc_coeffs bc coefficients
327 *----------------------------------------------------------------------------*/
328
329void
331
332/*----------------------------------------------------------------------------
333 * Shallow copy of boundary condition coefficients.
334 *
335 * \param[in] ref source bc coefficients
336 * \param[inout] copy shallow copy of bc coefficients
337 *----------------------------------------------------------------------------*/
338
339void
342
343/*----------------------------------------------------------------------------
344 * \brief Free copy of boundary condition coefficients.
345 *
346 * \param[in] ref reference bc coefficients
347 * \param[inout] copy shallow copy of bc coefficients
348 *----------------------------------------------------------------------------*/
349
350void
353
354/*----------------------------------------------------------------------------
355 * Return the number of defined fields.
356 *
357 * returns:
358 * number of defined fields.
359 *----------------------------------------------------------------------------*/
360
361int
363
364/*----------------------------------------------------------------------------
365 * Create a field descriptor.
366 *
367 * parameters:
368 * name <-- field name
369 * type_flag <-- mask of field property and category values
370 * location_id <-- id of associated location
371 * dim <-- field dimension (number of components)
372 * has_previous <-- maintain values at the previous time step ?
373 *
374 * returns:
375 * pointer to new field.
376 *----------------------------------------------------------------------------*/
377
379cs_field_create(const char *name,
380 int type_flag,
381 int location_id,
382 int dim,
383 bool has_previous);
384
385/*----------------------------------------------------------------------------*/
397/*----------------------------------------------------------------------------*/
398
400cs_field_create_by_composite_name(const char *name_prefix,
401 const char *name_suffix,
402 int type_flag,
403 int location_id,
404 int dim,
405 bool has_previous);
406
407/*----------------------------------------------------------------------------*/
426/*----------------------------------------------------------------------------*/
427
429cs_field_find_or_create(const char *name,
430 int type_flag,
431 int location_id,
432 int dim,
433 bool has_previous);
434
435/*----------------------------------------------------------------------------
436 * Change the number of time values managed by a field.
437 *
438 * The minimum will never be below 1, as the current time is always handled.
439 *
440 * parameters:
441 * f <-> pointer to field structure
442 * n_time_vals <-- number of time values to maintain
443 *----------------------------------------------------------------------------*/
444
445void
447 int n_time_vals);
448
449/*----------------------------------------------------------------------------
450 * Allocate arrays for field values.
451 *
452 * parameters:
453 * f <-- pointer to field structure
454 *----------------------------------------------------------------------------*/
455
456void
458
459/*----------------------------------------------------------------------------
460 * Map existing value arrays to field descriptor.
461 *
462 * parameters:
463 * f <-> pointer to field structure
464 * val <-- pointer to array of values
465 * val_pre <-- pointer to array of previous values, or nullptr
466 *----------------------------------------------------------------------------*/
467
468void
470 cs_real_t *val,
471 cs_real_t *val_pre);
472
473/*----------------------------------------------------------------------------
474 * Allocate boundary condition coefficient arrays.
475 *
476 * For fields on location CS_MESH_LOCATION_CELLS, boundary conditions
477 * are located on CS_MESH_LOCATION_BOUNDARY_FACES.
478 *
479 * Boundary condition coefficients are not currently supported for other
480 * locations (though support could be added by mapping a boundary->location
481 * indirection array in the cs_mesh_location_t structure).
482 *
483 * For multidimensional fields with coupled components, implicit b and bf
484 * coefficient arrays are arrays of block matrices, not vectors, so the
485 * number of entries for each boundary face is dim*dim instead of dim.
486 *
487 * parameters:
488 * f <-- pointer to field structure
489 * have_flux_bc <-- if true, flux BC coefficients (af and bf) are added
490 * have_mom_bc <-- if true, div BC coefficients (ad and bd) are added
491 * have_conv_bc <-- if true, convection BC coefficients (ac and bc) are added
492 * have_exch_bc <-- if true, exchange boundary coefficients (hint and hext)
493 * are added
494 *----------------------------------------------------------------------------*/
495
496void
498 bool have_flux_bc,
499 bool have_mom_bc,
500 bool have_conv_bc,
501 bool have_exch_bc);
502
503/*----------------------------------------------------------------------------*/
504/* Initialize boundary condition coefficients arrays.
505 *
506 * For fields on location CS_MESH_LOCATION_CELLS, boundary conditions
507 * are located on CS_MESH_LOCATION_BOUNDARY_FACES.
508 *
509 * Boundary condition coefficients are not currently supported for other
510 * locations (though support could be added by mapping a boundary->location
511 * indirection array in the cs_mesh_location_t structure).
512 *
513 * For multidimensional fields with coupled components, implicit b and bf
514 * coefficient arrays are arrays of block matrices, not vectors, so the
515 * number of entries for each boundary face is dim*dim instead of dim.
516 *
517 * parameters:
518 * f <-> pointer to field structure
519 *----------------------------------------------------------------------------*/
520
521void
523
524/*----------------------------------------------------------------------------
525 * Allocate arrays for field gradient.
526 *
527 * parameters:
528 * f <-- pointer to field structure
529 *----------------------------------------------------------------------------*/
530
531void
533
534/*----------------------------------------------------------------------------
535 * Set current field values to the given constant.
536 *
537 * parameters:
538 * f <-> pointer to field structure
539 * c <-- assigned value
540 *----------------------------------------------------------------------------*/
541
542void
544 cs_real_t c);
545
546/*----------------------------------------------------------------------------
547 * Copy current field values to previous values if applicable.
548 *
549 * For fields with only one time value, or values not allocated yet,
550 * this is a no-op.
551 *
552 * parameters:
553 * f <-> pointer to field structure
554 *----------------------------------------------------------------------------*/
555
556void
558
559/*----------------------------------------------------------------------------
560 * Destroy all defined fields.
561 *----------------------------------------------------------------------------*/
562
563void
565
566/*----------------------------------------------------------------------------
567 * Allocate arrays for all defined fields based on their location.
568 *
569 * Location sized must thus be known.
570 *
571 * Fields that do not own their data should all have been mapped at this
572 * stage, and are checked.
573 *----------------------------------------------------------------------------*/
574
575void
577
578/*----------------------------------------------------------------------------
579 * Return a pointer to a field based on its id.
580 *
581 * This function requires that a field of the given id is defined.
582 *
583 * parameters:
584 * id <-- field id
585 *
586 * returns:
587 * pointer to the field structure
588 *----------------------------------------------------------------------------*/
589
591cs_field_by_id(int id);
592
593/*----------------------------------------------------------------------------
594 * Return a pointer to a field based on its name.
595 *
596 * This function requires that a field of the given name is defined.
597 *
598 * parameters:
599 * name <-- field name
600 *
601 * returns:
602 * pointer to the field structure
603 *----------------------------------------------------------------------------*/
604
606cs_field_by_name(const char *name);
607
608/*----------------------------------------------------------------------------
609 * Return a pointer to a field based on its name if present.
610 *
611 * If no field of the given name is defined, nullptr is returned.
612 *
613 * parameters:
614 * name <-- field name
615 *
616 * returns:
617 * pointer to the field structure, or nullptr
618 *----------------------------------------------------------------------------*/
619
621cs_field_by_name_try(const char *name);
622
623/*----------------------------------------------------------------------------*/
634/*----------------------------------------------------------------------------*/
635
637cs_field_by_composite_name(const char *name_prefix,
638 const char *name_suffix);
639
640/*----------------------------------------------------------------------------*/
655/*----------------------------------------------------------------------------*/
656
658cs_field_by_composite_name_try(const char *name_prefix,
659 const char *name_suffix);
660
661/*----------------------------------------------------------------------------*/
680/*----------------------------------------------------------------------------*/
681
683cs_field_by_double_composite_name_try(const char *name_part_1,
684 const char *name_part_2,
685 const char *name_part_3);
686
687/*----------------------------------------------------------------------------
688 * Return the id of a defined field based on its name.
689 *
690 * If no field with the given name exists, -1 is returned.
691 *
692 * parameters:
693 * name <-- field name
694 *
695 * returns:
696 * id the field, or -1 if not found
697 *----------------------------------------------------------------------------*/
698
699int
700cs_field_id_by_name(const char *name);
701
702/*----------------------------------------------------------------------------
703 * Return the id of a defined field and an associated component
704 * based on a component name.
705 *
706 * If no field with the given name exists, -1 is returned.
707 *
708 * parameters:
709 * name <-- field or field+component name
710 * f_id --> field id, or -1 if no match was found
711 * c_id --> component id, or -1 for all components
712 *----------------------------------------------------------------------------*/
713
714void
715cs_field_component_id_by_name(const char *name,
716 int *f_id,
717 int *c_id);
718
719/*----------------------------------------------------------------------------
720 * Return an id associated with a given key name.
721 *
722 * The key must have been defined previously.
723 *
724 * parameters:
725 * name <-- key name
726 *
727 * returns:
728 * id associated with key
729 *----------------------------------------------------------------------------*/
730
731int
732cs_field_key_id(const char *name);
733
734/*----------------------------------------------------------------------------
735 * Return an id associated with a given key name if present.
736 *
737 * If the key has not been defined previously, -1 is returned.
738 *
739 * parameters:
740 * name <-- key name
741 *
742 * returns:
743 * id associated with key, or -1
744 *----------------------------------------------------------------------------*/
745
746int
747cs_field_key_id_try(const char *name);
748
749/*----------------------------------------------------------------------------
750 * Define a key for an integer value by its name and return an associated id.
751 *
752 * If the key has already been defined, its previous default value is replaced
753 * by the current value, and its id is returned.
754 *
755 * parameters:
756 * name <-- key name
757 * default_value <-- default value associated with key
758 * type flag <-- mask associated with field types with which the
759 * key may be associated, or 0
760 *
761 * returns:
762 * id associated with key
763 *----------------------------------------------------------------------------*/
764
765int
766cs_field_define_key_int(const char *name,
767 int default_value,
768 int type_flag);
769
770/*----------------------------------------------------------------------------
771 * Define a key for an floating point value by its name and return an
772 * associated id.
773 *
774 * If the key has already been defined, its previous default value is replaced
775 * by the current value, and its id is returned.
776 *
777 * parameters:
778 * name <-- key name
779 * default_value <-- default value associated with key
780 * type flag <-- mask associated with field types with which the
781 * key may be associated, or 0
782 *
783 * returns:
784 * id associated with key
785 *----------------------------------------------------------------------------*/
786
787int
788cs_field_define_key_double(const char *name,
789 double default_value,
790 int type_flag);
791
792/*----------------------------------------------------------------------------
793 * Define a key for an string point value by its name and return an
794 * associated id.
795 *
796 * If the key has already been defined, its previous default value is replaced
797 * by the current value, and its id is returned.
798 *
799 * parameters:
800 * name <-- key name
801 * default_value <-- default value associated with key
802 * type flag <-- mask associated with field types with which the
803 * key may be associated, or 0
804 *
805 * returns:
806 * id associated with key
807 *----------------------------------------------------------------------------*/
808
809int
810cs_field_define_key_str(const char *name,
811 const char *default_value,
812 int type_flag);
813
814/*----------------------------------------------------------------------------
815 * Define a key for a structure value by its name and return an
816 * associated id.
817 *
818 * If the key has already been defined, its previous default value is replaced
819 * by the current value, and its id is returned.
820 *
821 * parameters:
822 * name <-- key name
823 * default_value <-- pointer to default value associated with key
824 * log_funct <-- pointer to logging function
825 * log_func_default <-- pointer to default logging function
826 * clear_func <-- pointer to substructures free function
827 * size <-- sizeof structure
828 * type_flag <-- mask associated with field types with which
829 * the key may be associated, or 0
830 *
831 * returns:
832 * id associated with key
833 *----------------------------------------------------------------------------*/
834
835int
836cs_field_define_key_struct(const char *name,
837 const void *default_value,
839 cs_field_log_key_struct_t *log_func_default,
840 cs_field_clear_key_struct_t *clear_func,
841 size_t size,
842 int type_flag);
843
844/*----------------------------------------------------------------------------
845 * Define a sub key.
846 *
847 * The sub key is the same type as the parent key.
848 *
849 * For a given field, when querying a sub key's value and that value has not
850 * been set, the query will return the value of the parent key.
851 *
852 * parameters:
853 * name <-- key name
854 * parent_id <-- parent key id
855 *
856 * returns:
857 * id associated with key
858 *----------------------------------------------------------------------------*/
859
860int
861cs_field_define_sub_key(const char *name,
862 int parent_id);
863
864/*----------------------------------------------------------------------------
865 * Destroy all defined field keys and associated values.
866 *----------------------------------------------------------------------------*/
867
868void
870
871/*----------------------------------------------------------------------------
872 * Get the type flag associated with a given key id.
873 *
874 * If the key has not been defined previously, -1 is returned.
875 *
876 * parameters:
877 * key_id <-- id of associated key
878 *
879 * returns:
880 * type flag associated with key, or -1
881 *----------------------------------------------------------------------------*/
882
883int
884cs_field_key_flag(int key_id);
885
886/*----------------------------------------------------------------------------
887 * Disable logging setup values associated with a given key.
888 *
889 * This is useful when a key is used not for setup purposes, but to track
890 * values associated with a field, such as convergence or performance data.
891 *
892 * parameters:
893 * key_id <-- id of associated key
894 *----------------------------------------------------------------------------*/
895
896void
898
899/*----------------------------------------------------------------------------
900 * Query if a given key has been set for a field.
901 *
902 * If the key id is not valid, or the field category is not
903 * compatible, a fatal error is provoked.
904 *
905 * parameters:
906 * f <-- pointer to field structure
907 * key_id <-- id of associated key
908 *
909 * returns:
910 * true if the key has been set for this field, false otherwise
911 *----------------------------------------------------------------------------*/
912
913bool
915 int key_id);
916
917/*----------------------------------------------------------------------------
918 * Query if a given key has been locked for a field.
919 *
920 * If the key id is not valid, or the field category is not
921 * compatible, a fatal error is provoked.
922 *
923 * parameters:
924 * f <-- pointer to field structure
925 * key_id <-- id of associated key
926 *
927 * returns:
928 * true if the key has been locked for this field, false otherwise
929 *----------------------------------------------------------------------------*/
930
931bool
933 int key_id);
934
935/*----------------------------------------------------------------------------
936 * Lock a field relative to a given key.
937 *
938 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
939 * If the field category is not compatible with the key (as defined
940 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
941 *
942 * parameters:
943 * f <-- pointer to field structure
944 * key_id <-- id of associated key
945 * value <-- value associated with key
946 *
947 * returns:
948 * 0 in case of success, > 1 in case of error
949 *----------------------------------------------------------------------------*/
950
951int
953 int key_id);
954
955/*----------------------------------------------------------------------------
956 * Assign a integer value for a given key to a field.
957 *
958 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
959 * If the field category is not compatible with the key (as defined
960 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
961 * If the data type does not match, CS_FIELD_INVALID_TYPE is returned.
962 * If the key value has been locked, CS_FIELD_LOCKED is returned.
963 *
964 * parameters:
965 * f <-- pointer to field structure
966 * key_id <-- id of associated key
967 * value <-- value associated with key
968 *
969 * returns:
970 * 0 in case of success, > 1 in case of error
971 *----------------------------------------------------------------------------*/
972
973int
975 int key_id,
976 int value);
977
978/*----------------------------------------------------------------------------
979 * Return a integer value for a given key associated with a field.
980 *
981 * If the key id is not valid, or the value type or field category is not
982 * compatible, a fatal error is provoked.
983 *
984 * parameters:
985 * f <-- pointer to field structure
986 * key_id <-- id of associated key
987 *
988 * returns:
989 * integer value associated with the key id for this field
990 *----------------------------------------------------------------------------*/
991
992int
994 int key_id);
995
996/*----------------------------------------------------------------------------
997 * Set integer bits matching a mask to 1 for a given key for a field.
998 *
999 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
1000 * If the field category is not compatible with the key (as defined
1001 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
1002 * If the data type does not match, CS_FIELD_INVALID_TYPE is returned.
1003 * If the key value has been locked, CS_FIELD_LOCKED is returned.
1004 *
1005 * parameters:
1006 * f <-- pointer to field structure
1007 * key_id <-- id of associated key
1008 * mask <-- mask associated with key
1009 *
1010 * returns:
1011 * 0 in case of success, > 1 in case of error
1012 *----------------------------------------------------------------------------*/
1013
1014int
1016 int key_id,
1017 int mask);
1018
1019/*----------------------------------------------------------------------------
1020 * Set integer bits matching a mask to 0 for a given key for a field.
1021 *
1022 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
1023 * If the field category is not compatible with the key (as defined
1024 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
1025 * If the data type does not match, CS_FIELD_INVALID_TYPE is returned.
1026 * If the key value has been locked, CS_FIELD_LOCKED is returned.
1027 *
1028 * parameters:
1029 * f <-- pointer to field structure
1030 * key_id <-- id of associated key
1031 * mask <-- mask associated with key
1032 *
1033 * returns:
1034 * 0 in case of success, > 1 in case of error
1035 *----------------------------------------------------------------------------*/
1036
1037int
1039 int key_id,
1040 int mask);
1041
1042/*----------------------------------------------------------------------------
1043 * Assign a floating point value for a given key to a field.
1044 *
1045 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
1046 * If the field category is not compatible with the key (as defined
1047 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
1048 * If the data type does not match, CS_FIELD_INVALID_TYPE is returned.
1049 * If the key value has been locked, CS_FIELD_LOCKED is returned.
1050 *
1051 * parameters:
1052 * f <-- pointer to field structure
1053 * key_id <-- id of associated key
1054 * value <-- value associated with key
1055 *
1056 * returns:
1057 * 0 in case of success, > 1 in case of error
1058 *----------------------------------------------------------------------------*/
1059
1060int
1062 int key_id,
1063 double value);
1064
1065/*----------------------------------------------------------------------------
1066 * Return a floating point value for a given key associated with a field.
1067 *
1068 * If the key id is not valid, or the value type or field category is not
1069 * compatible, a fatal error is provoked.
1070 *
1071 * parameters:
1072 * f <-- pointer to field structure
1073 * key_id <-- id of associated key
1074 *
1075 * returns:
1076 * floating point value associated with the key id for this field
1077 *----------------------------------------------------------------------------*/
1078
1079double
1081 int key_id);
1082
1083/*----------------------------------------------------------------------------
1084 * Assign a character string value for a given key to a field.
1085 *
1086 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
1087 * If the field category is not compatible with the key (as defined
1088 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
1089 * If the data type does not match, CS_FIELD_INVALID_TYPE is returned.
1090 * If the key value has been locked, CS_FIELD_LOCKED is returned.
1091 *
1092 * parameters:
1093 * f <-- pointer to field structure
1094 * key_id <-- id of associated key
1095 * str <-- string associated with key
1096 *
1097 * returns:
1098 * 0 in case of success, > 1 in case of error
1099 *----------------------------------------------------------------------------*/
1100
1101int
1103 int key_id,
1104 const char *str);
1105
1106/*----------------------------------------------------------------------------
1107 * Return a string for a given key associated with a field.
1108 *
1109 * If the key id is not valid, or the value type or field category is not
1110 * compatible, a fatal error is provoked.
1111 *
1112 * parameters:
1113 * f <-- pointer to field structure
1114 * key_id <-- id of associated key
1115 *
1116 * returns:
1117 * pointer to character string associated with the key id for this field
1118 *----------------------------------------------------------------------------*/
1119
1120const char *
1122 int key_id);
1123
1124/*----------------------------------------------------------------------------
1125 * Assign a simple structure for a given key to a field.
1126 *
1127 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
1128 * If the field category is not compatible with the key (as defined
1129 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
1130 * If the key value has been locked, CS_FIELD_LOCKED is returned.
1131 *
1132 * parameters:
1133 * f <-- pointer to field structure
1134 * key_id <-- id of associated key
1135 * s <-- structure associated with key
1136 *
1137 * returns:
1138 * 0 in case of success, > 1 in case of error
1139 *----------------------------------------------------------------------------*/
1140
1141int
1143 int key_id,
1144 void *s);
1145
1146/*----------------------------------------------------------------------------
1147 * Return a structure for a given key associated with a field.
1148 *
1149 * If the key id is not valid, or the value type or field category is not
1150 * compatible, a fatal error is provoked.
1151 *
1152 * parameters:
1153 * f <-- pointer to field structure
1154 * key_id <-- id of associated key
1155 * s <-- structure associated with key
1156 *
1157 * returns:
1158 * pointer to structure associated with the key id for this field
1159 * (same as s)
1160 *----------------------------------------------------------------------------*/
1161
1162const void *
1164 int key_id,
1165 void *s);
1166
1167/*----------------------------------------------------------------------------*/
1168/*
1169 * \brief Return a pointer to a simple structure for a given key to a field.
1170 *
1171 * If the key id is not valid, the value type or field category is not
1172 * compatible, or the structure has been locked, a fatal error is provoked.
1173 *
1174 * Note that using this function marks the field's value for this structure
1175 * as set, and if no values have been set yet, the structure is set to
1176 * default values.
1177 *
1178 * \param[in] f pointer to field structure
1179 * \param[in] key_id id of associated key
1180 *
1181 * \return pointer to key structure in case of success,
1182 * nullptr in case of error
1183 */
1184/*----------------------------------------------------------------------------*/
1185
1186void *
1188 int key_id);
1189
1190/*----------------------------------------------------------------------------*/
1191/*
1192 * \brief Return a read-only pointer to a simple structure for a given key
1193 * to a field.
1194 *
1195 * If the key id is not valid, the value type or field category is not
1196 * compatible, a fatal error is provoked.
1197 *
1198 * \param[in] f pointer to field structure
1199 * \param[in] key_id id of associated key
1200 *
1201 * \return pointer to key structure in case of success,
1202 * nullptr in case of error
1203 */
1204/*----------------------------------------------------------------------------*/
1205
1206const void *
1208 int key_id);
1209
1210/*----------------------------------------------------------------------------
1211 * Print info relative to all field definitions to log file.
1212 *----------------------------------------------------------------------------*/
1213
1214void
1215cs_field_log_defs(void);
1216
1217/*----------------------------------------------------------------------------
1218 * Print info relative to a given field to log file.
1219 *
1220 * parameters:
1221 * f <-- pointer to field structure
1222 * log_keywords <-- log level for keywords (0: do not log,
1223 * 1: log non-default values, 2: log all)
1224 *----------------------------------------------------------------------------*/
1225
1226void
1228 int log_keywords);
1229
1230/*----------------------------------------------------------------------------
1231 * Print info relative to all defined fields to log file.
1232 *
1233 * parameters:
1234 * log_keywords <-- log level for keywords (0: do not log,
1235 * 1: log non-default values, 2: log all)
1236 *----------------------------------------------------------------------------*/
1237
1238void
1239cs_field_log_fields(int log_keywords);
1240
1241/*----------------------------------------------------------------------------
1242 * Print info relative to all key definitions to log file.
1243 *----------------------------------------------------------------------------*/
1244
1245void
1247
1248/*----------------------------------------------------------------------------
1249 * Print info relative to a given field key to log file.
1250 *
1251 * parameters:
1252 * int key_id <-- id of associated key
1253 * log_defaults <-- if true, log default field values in addition to
1254 * defined field values
1255 *----------------------------------------------------------------------------*/
1256
1257void
1258cs_field_log_key_vals(int key_id,
1259 bool log_defaults);
1260
1261/*----------------------------------------------------------------------------
1262 * Print info relative to all given field keys to log file.
1263 *
1264 * parameters:
1265 * log_defaults <-- if true, log default field values in addition to
1266 * defined field values
1267 *----------------------------------------------------------------------------*/
1268
1269void
1270cs_field_log_all_key_vals(bool log_defaults);
1271
1272/*----------------------------------------------------------------------------
1273 * Define base keys.
1274 *
1275 * Keys defined by this function are:
1276 * "label" (string)
1277 * "log" (integer)
1278 * "post_vis" (integer)
1279 * "coupled" (integer, restricted to CS_FIELD_VARIABLE)
1280 * "moment_id" (integer, restricted to
1281 * CS_FIELD_ACCUMULATOR | CS_FIELD_POSTPROCESS);
1282 *
1283 * A recommened practice for different submodules would be to use
1284 * "cs_<module>_key_init() functions to define keys specific to those modules.
1285 *----------------------------------------------------------------------------*/
1286
1287void
1289
1290/*----------------------------------------------------------------------------
1291 * Return a label associated with a field.
1292 *
1293 * If the "label" key has been set for this field, its associated string
1294 * is returned. Otherwise, the field's name is returned.
1295 *
1296 * parameters:
1297 * f <-- pointer to field structure
1298 *
1299 * returns:
1300 * pointer to character string associated with label for this field
1301 *----------------------------------------------------------------------------*/
1302
1303const char *
1305
1306/*----------------------------------------------------------------------------*/
1307
1309
1310/*=============================================================================
1311 * C++ functions
1312 *============================================================================*/
1313
1314#if defined(__cplusplus)
1315
1316/*----------------------------------------------------------------------------*/
1317/* Getter function based on field name, raises error if fails */
1318/*----------------------------------------------------------------------------*/
1319
1320cs_field_t *
1321cs_field(const char *name);
1322
1323/*----------------------------------------------------------------------------*/
1324/* Getter function based on field id, raises error if fails */
1325/*----------------------------------------------------------------------------*/
1326
1327cs_field_t *
1328cs_field(const int id);
1329
1330/*----------------------------------------------------------------------------*/
1331/* Getter function based on field name, returns nullptr if fails */
1332/*----------------------------------------------------------------------------*/
1333
1334cs_field_t *
1335cs_field_try(const char *name);
1336
1337/*----------------------------------------------------------------------------*/
1338/* Getter function based on field id, returns nullptr if fails */
1339/*----------------------------------------------------------------------------*/
1340
1341cs_field_t *
1342cs_field_try(const int id);
1343
1344/*----------------------------------------------------------------------------*/
1345
1346#endif /* __cplusplus */
1347
1348/*----------------------------------------------------------------------------*/
1349
1350#endif /* __CS_FIELD_H__ */
Definition: cs_array.h:1111
Definition: cs_mdspan.h:69
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
#define END_C_DECLS
Definition: cs_defs.h:555
int cs_field_set_key_int(cs_field_t *f, int key_id, int value)
Assign a integer value for a given key to a field.
Definition: cs_field.cpp:3109
int cs_field_clear_key_int_bits(cs_field_t *f, int key_id, int mask)
Set integer bits matching a mask to 0 for a given key for a field.
Definition: cs_field.cpp:3259
void cs_field_bc_coeffs_init(cs_field_bc_coeffs_t *bc_coeffs)
Definition: cs_field.cpp:1365
void cs_field_init_bc_coeffs(cs_field_t *f)
Initialize boundary condition coefficients arrays.
Definition: cs_field.cpp:2016
int cs_field_define_key_int(const char *name, int default_value, int type_flag)
Define a key for an integer value by its name and return an associated id.
Definition: cs_field.cpp:2718
int cs_field_get_key_int(const cs_field_t *f, int key_id)
Return a integer value for a given key associated with a field.
Definition: cs_field.cpp:3157
int cs_field_key_flag(int key_id)
Get the type flag associated with a given key id.
Definition: cs_field.cpp:2955
const void * cs_field_get_key_struct_const_ptr(const cs_field_t *f, int key_id)
Return a read-only pointer to a simple structure for a given key to a field.
Definition: cs_field.cpp:3733
void cs_field_set_n_time_vals(cs_field_t *f, int n_time_vals)
Change the number of time values managed by a field.
Definition: cs_field.cpp:1668
cs_field_t * cs_field_by_name(const char *name)
Return a pointer to a field based on its name.
Definition: cs_field.cpp:2371
cs_field_t * cs_field_by_double_composite_name_try(const char *name_part_1, const char *name_part_2, const char *name_part_3)
Return pointer to a field based on a double composite name if present.
Definition: cs_field.cpp:2503
int cs_field_define_key_str(const char *name, const char *default_value, int type_flag)
Define a key for a string value by its name and return an associated id.
Definition: cs_field.cpp:2792
void cs_field_set_values(cs_field_t *f, cs_real_t c)
Set current field values to the given constant.
Definition: cs_field.cpp:2176
cs_field_t * cs_field_by_composite_name(const char *name_prefix, const char *name_suffix)
Return a pointer to a field based on a composite name.
Definition: cs_field.cpp:2421
void * cs_field_get_key_struct_ptr(cs_field_t *f, int key_id)
Return a pointer to a simple structure for a given key to a field.
Definition: cs_field.cpp:3654
void cs_field_destroy_all_keys(void)
Destroy all defined field keys and associated values.
Definition: cs_field.cpp:2923
cs_field_t * cs_field_create(const char *name, int type_flag, int location_id, int dim, bool has_previous)
Create a field descriptor.
Definition: cs_field.cpp:1506
int cs_field_n_fields(void)
Return the number of defined fields.
Definition: cs_field.cpp:1486
void cs_field_log_defs(void)
Print info relative to all field definitions to log file.
Definition: cs_field.cpp:3792
const char * cs_field_get_label(const cs_field_t *f)
Return a label associated with a field.
Definition: cs_field.cpp:4460
bool cs_field_is_key_locked(const cs_field_t *f, int key_id)
Query if a given key has been locked for a field.
Definition: cs_field.cpp:3032
void cs_field_allocate_values(cs_field_t *f)
Allocate arrays for field values.
Definition: cs_field.cpp:1742
void cs_field_bc_coeffs_shallow_copy(const cs_field_bc_coeffs_t *ref, cs_field_bc_coeffs_t *copy)
Shallow copy of boundary condition coefficients.
Definition: cs_field.cpp:1403
int cs_field_set_key_str(cs_field_t *f, int key_id, const char *str)
Assign a character string for a given key to a field.
Definition: cs_field.cpp:3407
int cs_field_set_key_struct(cs_field_t *f, int key_id, void *s)
Assign a simple structure for a given key to a field.
Definition: cs_field.cpp:3528
cs_field_error_type_t
Definition: cs_field.h:90
@ CS_FIELD_INVALID_KEY_NAME
Definition: cs_field.h:93
@ CS_FIELD_INVALID_FIELD
Definition: cs_field.h:97
@ CS_FIELD_INVALID_TYPE
Definition: cs_field.h:96
@ CS_FIELD_INVALID_CATEGORY
Definition: cs_field.h:95
@ CS_FIELD_LOCKED
Definition: cs_field.h:98
@ CS_FIELD_OK
Definition: cs_field.h:92
@ CS_FIELD_INVALID_KEY_ID
Definition: cs_field.h:94
void() cs_field_clear_key_struct_t(void *t)
Definition: cs_field.h:307
const char * cs_field_get_key_str(const cs_field_t *f, int key_id)
Return a string for a given key associated with a field.
Definition: cs_field.cpp:3459
bool cs_field_is_key_set(const cs_field_t *f, int key_id)
Query if a given key has been set for a field.
Definition: cs_field.cpp:3001
cs_field_t * cs_field_by_name_try(const char *name)
Return a pointer to a field based on its name if present.
Definition: cs_field.cpp:2397
cs_field_t * cs_field(const char *name)
Return a pointer to a field based on its name. This function requires that a field of the given name ...
Definition: cs_field.cpp:4513
int cs_field_set_key_int_bits(cs_field_t *f, int key_id, int mask)
Set integer bits matching a mask to 1 for a given key for a field.
Definition: cs_field.cpp:3228
void cs_field_key_disable_setup_log(int key_id)
Disable logging setup values associated with a given key.
Definition: cs_field.cpp:2979
int cs_field_define_sub_key(const char *name, int parent_id)
Define a sub key.
Definition: cs_field.cpp:2897
void cs_field_allocate_or_map_all(void)
Allocate arrays for all defined fields based on their location.
Definition: cs_field.cpp:2316
void cs_field_bc_coeffs_free_copy(const cs_field_bc_coeffs_t *ref, cs_field_bc_coeffs_t *copy)
Free copy of boundary condition coefficients.
Definition: cs_field.cpp:1425
void cs_field_destroy_all(void)
Destroy all defined fields.
Definition: cs_field.cpp:2243
void cs_field_map_values(cs_field_t *f, cs_real_t *val, cs_real_t *val_pre)
Map existing value arrays to field descriptor.
Definition: cs_field.cpp:1781
cs_field_t * cs_field_create_by_composite_name(const char *name_prefix, const char *name_suffix, int type_flag, int location_id, int dim, bool has_previous)
Create a field descriptor.
Definition: cs_field.cpp:1547
const void * cs_field_get_key_struct(const cs_field_t *f, int key_id, void *s)
Return a structure for a given key associated with a field.
Definition: cs_field.cpp:3580
void cs_field_log_info(const cs_field_t *f, int log_keywords)
Print info relative to a given field to log file.
Definition: cs_field.cpp:3930
void cs_field_log_key_defs(void)
Print info relative to all key definitions to log file.
Definition: cs_field.cpp:4125
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition: cs_field.cpp:2347
double cs_field_get_key_double(const cs_field_t *f, int key_id)
Return a floating point value for a given key associated with a field.
Definition: cs_field.cpp:3337
const char * cs_glob_field_comp_name_9[]
const char * cs_glob_field_comp_name_6[]
int cs_field_define_key_struct(const char *name, const void *default_value, cs_field_log_key_struct_t *log_func, cs_field_log_key_struct_t *log_func_default, cs_field_clear_key_struct_t *clear_func, size_t size, int type_flag)
Define a key for a structure value by its name and return an associated id.
Definition: cs_field.cpp:2844
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition: cs_field.cpp:2663
int cs_field_define_key_double(const char *name, double default_value, int type_flag)
Define a key for an floating point value by its name and return an associated id.
Definition: cs_field.cpp:2755
void cs_field_define_keys_base(void)
Define base keys.
Definition: cs_field.cpp:4434
int cs_field_key_id_try(const char *name)
Return an id associated with a given key name if present.
Definition: cs_field.cpp:2690
cs_field_t * cs_field_find_or_create(const char *name, int type_flag, int location_id, int dim, bool has_previous)
Return a field matching a given name and attributes, creating it if necessary.
Definition: cs_field.cpp:1604
void cs_field_log_fields(int log_keywords)
Print info relative to all defined fields to log file.
Definition: cs_field.cpp:4064
void cs_field_current_to_previous(cs_field_t *f)
Copy current field values to previous values if applicable.
Definition: cs_field.cpp:2202
void cs_field_log_all_key_vals(bool log_defaults)
Print info relative to all given field keys to log file.
Definition: cs_field.cpp:4403
int cs_field_lock_key(cs_field_t *f, int key_id)
Lock a field relative to a given key.
Definition: cs_field.cpp:3064
cs_field_t * cs_field_by_composite_name_try(const char *name_prefix, const char *name_suffix)
Return a pointer to a field based on a composite name if present.
Definition: cs_field.cpp:2452
void cs_field_allocate_bc_coeffs(cs_field_t *f, bool have_flux_bc, bool have_mom_bc, bool have_conv_bc, bool have_exch_bc)
Allocate boundary condition coefficients arrays.
Definition: cs_field.cpp:1839
void cs_field_component_id_by_name(const char *name, int *f_id, int *c_id)
Return the id of a defined field and an associated component based on a component name.
Definition: cs_field.cpp:2574
int cs_field_set_key_double(cs_field_t *f, int key_id, double value)
Assign a floating point value for a given key to a field.
Definition: cs_field.cpp:3289
int cs_field_id_by_name(const char *name)
Return the id of a defined field based on its name.
Definition: cs_field.cpp:2553
void() cs_field_log_key_struct_t(const void *t)
Definition: cs_field.h:297
const char * cs_glob_field_comp_name_3[]
cs_field_t * cs_field_try(const char *name)
Return a pointer to a field based on its name. If no field of the given name is defined,...
Definition: cs_field.cpp:4560
void cs_field_allocate_gradient(cs_field_t *f)
Allocate arrays for field gradient.
Definition: cs_field.cpp:2152
void cs_field_log_key_vals(int key_id, bool log_defaults)
Print info relative to a given field key to log file.
Definition: cs_field.cpp:4279
@ t
Definition: cs_field_pointer.h:95
cs_alloc_mode_t
Definition: cs_mem.h:50
Definition: cs_field.h:105
cs_real_t * val_ip
Definition: cs_field.h:107
cs_real_t * val_f
Definition: cs_field.h:109
cs_real_t * flux
Definition: cs_field.h:111
cs_real_t * flux_lim
Definition: cs_field.h:112
Field boundary condition descriptor (for variables)
Definition: cs_field.h:120
cs_real_t * rcodcl2
Definition: cs_field.h:126
cs_real_t * af
Definition: cs_field.h:132
int location_id
Definition: cs_field.h:122
cs_real_t * bc
Definition: cs_field.h:137
cs_real_t * rcodcl3
Definition: cs_field.h:128
cs_real_t * val_f_lim
Definition: cs_field.h:142
cs_real_t * b
Definition: cs_field.h:131
cs_real_t * a
Definition: cs_field.h:130
cs_real_t * ad
Definition: cs_field.h:134
cs_real_t * hint
Definition: cs_field.h:139
cs_real_t * ac
Definition: cs_field.h:136
cs_real_t * rcodcl1
Definition: cs_field.h:125
cs_real_t * bf
Definition: cs_field.h:133
cs_real_t * bd
Definition: cs_field.h:135
cs_real_t * val_f_pre
Definition: cs_field.h:149
cs_real_t * val_f
Definition: cs_field.h:141
cs_real_t * flux
Definition: cs_field.h:145
int * icodcl
Definition: cs_field.h:124
cs_real_t * flux_lim
Definition: cs_field.h:146
Field descriptor.
Definition: cs_field.h:156
cs_array_2d< cs_real_t > ** _vals
Definition: cs_field.h:283
int location_id
Definition: cs_field.h:165
cs_real_t * grad
Definition: cs_field.h:184
cs_real_t ** vals
Definition: cs_field.h:169
int type
Definition: cs_field.h:161
int n_time_vals
Definition: cs_field.h:167
cs_real_t * val_pre
Definition: cs_field.h:180
const char * name
Definition: cs_field.h:158
bool is_owner
Definition: cs_field.h:191
cs_real_t * val
Definition: cs_field.h:177
int id
Definition: cs_field.h:160
cs_field_bc_coeffs_t * bc_coeffs
Definition: cs_field.h:188
int dim
Definition: cs_field.h:163