9.0
general documentation
Loading...
Searching...
No Matches
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
36/*----------------------------------------------------------------------------*/
37
39
40/*=============================================================================
41 * Macro definitions
42 *============================================================================*/
43
49
50/*
51 * Field property type
52 */
53
55#define CS_FIELD_INTENSIVE (1 << 0)
56
58#define CS_FIELD_EXTENSIVE (1 << 1)
59
60/* Field category */
61
63#define CS_FIELD_VARIABLE (1 << 2)
64
66#define CS_FIELD_PROPERTY (1 << 3)
67
69#define CS_FIELD_POSTPROCESS (1 << 4)
70
72#define CS_FIELD_ACCUMULATOR (1 << 5)
73
75#define CS_FIELD_USER (1 << 6)
76
78#define CS_FIELD_CDO (1 << 7)
79
81
82/*============================================================================
83 * Type definitions
84 *============================================================================*/
85
86/* Field handling error types */
87/*----------------------------*/
88
100
102/*----------------------------------------------------------*/
103
104typedef struct {
105
106 cs_real_t *val_ip; /* variable computed at I' position */
107
108 cs_real_t *val_f; /* face value for gradient */
109 cs_real_t *val_f_lim; /* face value for gradient
110 (limited) */
111
112 cs_real_t *val_f_d; /* face value for diffusion */
113 cs_real_t *val_f_d_lim; /* face value for diffusion
114 (limited) */
115
117
119/*------------------------------------------------------*/
120
121typedef struct {
122
123 int location_id; /* Id of matching location */
124
125 int *icodcl; /* low-level BC type code */
126 cs_real_t *rcodcl1; /* 1st component of low-level BC */
127 cs_real_t *rcodcl2; /* 2nd component of low-level BC */
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 cs_real_t *_hext; /* coefficient for internal coupling
141 (maps to rcodcl2 when present) */
142
143 cs_real_t *val_f; /* face value for gradient */
144 cs_real_t *val_f_lim; /* face value for gradient
145 (limited) */
146
147 cs_real_t *val_f_d; /* face value for diffusion */
148 cs_real_t *val_f_d_lim; /* face value for diffusion
149 (limited) */
150
151 cs_real_t *val_f_pre; /* previous face value for gradient */
152
154
155/* Field descriptor */
156/*------------------*/
157
158typedef struct {
159
160 const char *name; /* Canonical name */
161
162 int id; /* Field id */
163 int type; /* Field type flag */
164
165 int dim; /* Field dimension */
166
167 int location_id; /* Id of matching location */
168
169 int n_time_vals; /* Number of time values */
170
171 cs_real_t **vals; /* For each active location, pointer
172 to matching values arrays
173 vals[0][:] = val
174 vals[1][:] = val_pre
175 vals[p][:] = p ith previous field
176 p < n_time_vals */
177
178
179 cs_real_t *val; /* For each active location, pointer
180 to matching values array */
181
182 cs_real_t *val_pre; /* For each active location, pointer
183 to matching previous values array
184 (if n_time_vals == 2) */
185
186 cs_real_t *grad; /* For each active location, pointer
187 to matching gradient array for
188 variable type fields */
189
190 cs_field_bc_coeffs_t *bc_coeffs; /* Boundary condition coefficients,
191 for variable type fields */
192
193 bool is_owner; /* Ownership flag for values */
194
195} cs_field_t;
196
197/*----------------------------------------------------------------------------
198 * Function pointer for structure associated to field key
199 *
200 * parameters:
201 * t <-- pointer to structure
202 *----------------------------------------------------------------------------*/
203
204typedef void
205(cs_field_log_key_struct_t) (const void *t);
206
207/*----------------------------------------------------------------------------
208 * Function pointer for structure associated to field key
209 *
210 * parameters:
211 * t <-- pointer to structure
212 *----------------------------------------------------------------------------*/
213
214typedef void
216
217/*============================================================================
218 * Global variables
219 *============================================================================*/
220
221/* Names for components */
222
223extern const char *cs_glob_field_comp_name_3[];
224extern const char *cs_glob_field_comp_name_6[];
225extern const char *cs_glob_field_comp_name_9[];
226
227/*=============================================================================
228 * Public function prototypes
229 *============================================================================*/
230
231/*----------------------------------------------------------------------------
232 * Create bc_coeffs structure.
233 *
234 * \param[in] bc_coeffs bc coefficients
235 *----------------------------------------------------------------------------*/
236
237void
239
240/*----------------------------------------------------------------------------
241 * Shallow copy of boundary condition coefficients.
242 *
243 * \param[in] ref source bc coefficients
244 * \param[inout] copy shallow copy of bc coefficients
245 *----------------------------------------------------------------------------*/
246
247void
250
251/*----------------------------------------------------------------------------
252 * \brief Free copy of boundary condition coefficients.
253 *
254 * \param[in] ref reference bc coefficients
255 * \param[inout] copy shallow copy of bc coefficients
256 *----------------------------------------------------------------------------*/
257
258void
261
262/*----------------------------------------------------------------------------
263 * Return the number of defined fields.
264 *
265 * returns:
266 * number of defined fields.
267 *----------------------------------------------------------------------------*/
268
269int
271
272/*----------------------------------------------------------------------------
273 * Create a field descriptor.
274 *
275 * parameters:
276 * name <-- field name
277 * type_flag <-- mask of field property and category values
278 * location_id <-- id of associated location
279 * dim <-- field dimension (number of components)
280 * has_previous <-- maintain values at the previous time step ?
281 *
282 * returns:
283 * pointer to new field.
284 *----------------------------------------------------------------------------*/
285
287cs_field_create(const char *name,
288 int type_flag,
289 int location_id,
290 int dim,
291 bool has_previous);
292
293/*----------------------------------------------------------------------------*/
305/*----------------------------------------------------------------------------*/
306
308cs_field_create_by_composite_name(const char *name_prefix,
309 const char *name_suffix,
310 int type_flag,
311 int location_id,
312 int dim,
313 bool has_previous);
314
315/*----------------------------------------------------------------------------*/
334/*----------------------------------------------------------------------------*/
335
337cs_field_find_or_create(const char *name,
338 int type_flag,
339 int location_id,
340 int dim,
341 bool has_previous);
342
343/*----------------------------------------------------------------------------
344 * Change the number of time values managed by a field.
345 *
346 * The minimum will never be below 1, as the current time is always handled.
347 *
348 * parameters:
349 * f <-> pointer to field structure
350 * n_time_vals <-- number of time values to maintain
351 *----------------------------------------------------------------------------*/
352
353void
355 int n_time_vals);
356
357/*----------------------------------------------------------------------------
358 * Allocate arrays for field values.
359 *
360 * parameters:
361 * f <-- pointer to field structure
362 *----------------------------------------------------------------------------*/
363
364void
366
367/*----------------------------------------------------------------------------
368 * Map existing value arrays to field descriptor.
369 *
370 * parameters:
371 * f <-> pointer to field structure
372 * val <-- pointer to array of values
373 * val_pre <-- pointer to array of previous values, or nullptr
374 *----------------------------------------------------------------------------*/
375
376void
378 cs_real_t *val,
379 cs_real_t *val_pre);
380
381/*----------------------------------------------------------------------------
382 * Allocate boundary condition coefficient arrays.
383 *
384 * For fields on location CS_MESH_LOCATION_CELLS, boundary conditions
385 * are located on CS_MESH_LOCATION_BOUNDARY_FACES.
386 *
387 * Boundary condition coefficients are not currently supported for other
388 * locations (though support could be added by mapping a boundary->location
389 * indirection array in the cs_mesh_location_t structure).
390 *
391 * For multidimensional fields with coupled components, implicit b and bf
392 * coefficient arrays are arrays of block matrices, not vectors, so the
393 * number of entries for each boundary face is dim*dim instead of dim.
394 *
395 * parameters:
396 * f <-- pointer to field structure
397 * have_flux_bc <-- if true, flux BC coefficients (af and bf) are added
398 * have_mom_bc <-- if true, div BC coefficients (ad and bd) are added
399 * have_conv_bc <-- if true, convection BC coefficients (ac and bc) are added
400 * have_exch_bc <-- if true, exchange boundary coefficients (hint and hext)
401 * are added
402 *----------------------------------------------------------------------------*/
403
404void
406 bool have_flux_bc,
407 bool have_mom_bc,
408 bool have_conv_bc,
409 bool have_exch_bc);
410
411/*----------------------------------------------------------------------------*/
412/* Initialize boundary condition coefficients arrays.
413 *
414 * For fields on location CS_MESH_LOCATION_CELLS, boundary conditions
415 * are located on CS_MESH_LOCATION_BOUNDARY_FACES.
416 *
417 * Boundary condition coefficients are not currently supported for other
418 * locations (though support could be added by mapping a boundary->location
419 * indirection array in the cs_mesh_location_t structure).
420 *
421 * For multidimensional fields with coupled components, implicit b and bf
422 * coefficient arrays are arrays of block matrices, not vectors, so the
423 * number of entries for each boundary face is dim*dim instead of dim.
424 *
425 * parameters:
426 * f <-> pointer to field structure
427 *----------------------------------------------------------------------------*/
428
429void
431
432/*----------------------------------------------------------------------------
433 * Allocate arrays for field gradient.
434 *
435 * parameters:
436 * f <-- pointer to field structure
437 *----------------------------------------------------------------------------*/
438
439void
441
442/*----------------------------------------------------------------------------
443 * Set current field values to the given constant.
444 *
445 * parameters:
446 * f <-> pointer to field structure
447 * c <-- assigned value
448 *----------------------------------------------------------------------------*/
449
450void
452 cs_real_t c);
453
454/*----------------------------------------------------------------------------
455 * Copy current field values to previous values if applicable.
456 *
457 * For fields with only one time value, or values not allocated yet,
458 * this is a no-op.
459 *
460 * parameters:
461 * f <-> pointer to field structure
462 *----------------------------------------------------------------------------*/
463
464void
466
467/*----------------------------------------------------------------------------
468 * Destroy all defined fields.
469 *----------------------------------------------------------------------------*/
470
471void
473
474/*----------------------------------------------------------------------------
475 * Allocate arrays for all defined fields based on their location.
476 *
477 * Location sized must thus be known.
478 *
479 * Fields that do not own their data should all have been mapped at this
480 * stage, and are checked.
481 *----------------------------------------------------------------------------*/
482
483void
485
486/*----------------------------------------------------------------------------
487 * Return a pointer to a field based on its id.
488 *
489 * This function requires that a field of the given id is defined.
490 *
491 * parameters:
492 * id <-- field id
493 *
494 * returns:
495 * pointer to the field structure
496 *----------------------------------------------------------------------------*/
497
499cs_field_by_id(int id);
500
501/*----------------------------------------------------------------------------
502 * Return a pointer to a field based on its name.
503 *
504 * This function requires that a field of the given name is defined.
505 *
506 * parameters:
507 * name <-- field name
508 *
509 * returns:
510 * pointer to the field structure
511 *----------------------------------------------------------------------------*/
512
514cs_field_by_name(const char *name);
515
516/*----------------------------------------------------------------------------
517 * Return a pointer to a field based on its name if present.
518 *
519 * If no field of the given name is defined, nullptr is returned.
520 *
521 * parameters:
522 * name <-- field name
523 *
524 * returns:
525 * pointer to the field structure, or nullptr
526 *----------------------------------------------------------------------------*/
527
529cs_field_by_name_try(const char *name);
530
531/*----------------------------------------------------------------------------*/
542/*----------------------------------------------------------------------------*/
543
545cs_field_by_composite_name(const char *name_prefix,
546 const char *name_suffix);
547
548/*----------------------------------------------------------------------------*/
563/*----------------------------------------------------------------------------*/
564
566cs_field_by_composite_name_try(const char *name_prefix,
567 const char *name_suffix);
568
569/*----------------------------------------------------------------------------*/
588/*----------------------------------------------------------------------------*/
589
591cs_field_by_double_composite_name_try(const char *name_part_1,
592 const char *name_part_2,
593 const char *name_part_3);
594
595/*----------------------------------------------------------------------------
596 * Return the id of a defined field based on its name.
597 *
598 * If no field with the given name exists, -1 is returned.
599 *
600 * parameters:
601 * name <-- field name
602 *
603 * returns:
604 * id the field, or -1 if not found
605 *----------------------------------------------------------------------------*/
606
607int
608cs_field_id_by_name(const char *name);
609
610/*----------------------------------------------------------------------------
611 * Return the id of a defined field and an associated component
612 * based on a component name.
613 *
614 * If no field with the given name exists, -1 is returned.
615 *
616 * parameters:
617 * name <-- field or field+component name
618 * f_id --> field id, or -1 if no match was found
619 * c_id --> component id, or -1 for all components
620 *----------------------------------------------------------------------------*/
621
622void
623cs_field_component_id_by_name(const char *name,
624 int *f_id,
625 int *c_id);
626
627/*----------------------------------------------------------------------------
628 * Return an id associated with a given key name.
629 *
630 * The key must have been defined previously.
631 *
632 * parameters:
633 * name <-- key name
634 *
635 * returns:
636 * id associated with key
637 *----------------------------------------------------------------------------*/
638
639int
640cs_field_key_id(const char *name);
641
642/*----------------------------------------------------------------------------
643 * Return an id associated with a given key name if present.
644 *
645 * If the key has not been defined previously, -1 is returned.
646 *
647 * parameters:
648 * name <-- key name
649 *
650 * returns:
651 * id associated with key, or -1
652 *----------------------------------------------------------------------------*/
653
654int
655cs_field_key_id_try(const char *name);
656
657/*----------------------------------------------------------------------------
658 * Define a key for an integer value by its name and return an associated id.
659 *
660 * If the key has already been defined, its previous default value is replaced
661 * by the current value, and its id is returned.
662 *
663 * parameters:
664 * name <-- key name
665 * default_value <-- default value associated with key
666 * type flag <-- mask associated with field types with which the
667 * key may be associated, or 0
668 *
669 * returns:
670 * id associated with key
671 *----------------------------------------------------------------------------*/
672
673int
674cs_field_define_key_int(const char *name,
675 int default_value,
676 int type_flag);
677
678/*----------------------------------------------------------------------------
679 * Define a key for an floating point value by its name and return an
680 * associated id.
681 *
682 * If the key has already been defined, its previous default value is replaced
683 * by the current value, and its id is returned.
684 *
685 * parameters:
686 * name <-- key name
687 * default_value <-- default value associated with key
688 * type flag <-- mask associated with field types with which the
689 * key may be associated, or 0
690 *
691 * returns:
692 * id associated with key
693 *----------------------------------------------------------------------------*/
694
695int
696cs_field_define_key_double(const char *name,
697 double default_value,
698 int type_flag);
699
700/*----------------------------------------------------------------------------
701 * Define a key for an string point value by its name and return an
702 * associated id.
703 *
704 * If the key has already been defined, its previous default value is replaced
705 * by the current value, and its id is returned.
706 *
707 * parameters:
708 * name <-- key name
709 * default_value <-- default value associated with key
710 * type flag <-- mask associated with field types with which the
711 * key may be associated, or 0
712 *
713 * returns:
714 * id associated with key
715 *----------------------------------------------------------------------------*/
716
717int
718cs_field_define_key_str(const char *name,
719 const char *default_value,
720 int type_flag);
721
722/*----------------------------------------------------------------------------
723 * Define a key for a structure value by its name and return an
724 * associated id.
725 *
726 * If the key has already been defined, its previous default value is replaced
727 * by the current value, and its id is returned.
728 *
729 * parameters:
730 * name <-- key name
731 * default_value <-- pointer to default value associated with key
732 * log_funct <-- pointer to logging function
733 * log_func_default <-- pointer to default logging function
734 * clear_func <-- pointer to substructures free function
735 * size <-- sizeof structure
736 * type_flag <-- mask associated with field types with which
737 * the key may be associated, or 0
738 *
739 * returns:
740 * id associated with key
741 *----------------------------------------------------------------------------*/
742
743int
744cs_field_define_key_struct(const char *name,
745 const void *default_value,
747 cs_field_log_key_struct_t *log_func_default,
748 cs_field_clear_key_struct_t *clear_func,
749 size_t size,
750 int type_flag);
751
752/*----------------------------------------------------------------------------
753 * Define a sub key.
754 *
755 * The sub key is the same type as the parent key.
756 *
757 * For a given field, when querying a sub key's value and that value has not
758 * been set, the query will return the value of the parent key.
759 *
760 * parameters:
761 * name <-- key name
762 * parent_id <-- parent key id
763 *
764 * returns:
765 * id associated with key
766 *----------------------------------------------------------------------------*/
767
768int
769cs_field_define_sub_key(const char *name,
770 int parent_id);
771
772/*----------------------------------------------------------------------------
773 * Destroy all defined field keys and associated values.
774 *----------------------------------------------------------------------------*/
775
776void
778
779/*----------------------------------------------------------------------------
780 * Get the type flag associated with a given key id.
781 *
782 * If the key has not been defined previously, -1 is returned.
783 *
784 * parameters:
785 * key_id <-- id of associated key
786 *
787 * returns:
788 * type flag associated with key, or -1
789 *----------------------------------------------------------------------------*/
790
791int
792cs_field_key_flag(int key_id);
793
794/*----------------------------------------------------------------------------
795 * Disable logging setup values associated with a given key.
796 *
797 * This is useful when a key is used not for setup purposes, but to track
798 * values associated with a field, such as convergence or performance data.
799 *
800 * parameters:
801 * key_id <-- id of associated key
802 *----------------------------------------------------------------------------*/
803
804void
806
807/*----------------------------------------------------------------------------
808 * Query if a given key has been set for a field.
809 *
810 * If the key id is not valid, or the field category is not
811 * compatible, a fatal error is provoked.
812 *
813 * parameters:
814 * f <-- pointer to field structure
815 * key_id <-- id of associated key
816 *
817 * returns:
818 * true if the key has been set for this field, false otherwise
819 *----------------------------------------------------------------------------*/
820
821bool
823 int key_id);
824
825/*----------------------------------------------------------------------------
826 * Query if a given key has been locked for a field.
827 *
828 * If the key id is not valid, or the field category is not
829 * compatible, a fatal error is provoked.
830 *
831 * parameters:
832 * f <-- pointer to field structure
833 * key_id <-- id of associated key
834 *
835 * returns:
836 * true if the key has been locked for this field, false otherwise
837 *----------------------------------------------------------------------------*/
838
839bool
841 int key_id);
842
843/*----------------------------------------------------------------------------
844 * Lock a field relative to a given key.
845 *
846 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
847 * If the field category is not compatible with the key (as defined
848 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
849 *
850 * parameters:
851 * f <-- pointer to field structure
852 * key_id <-- id of associated key
853 * value <-- value associated with key
854 *
855 * returns:
856 * 0 in case of success, > 1 in case of error
857 *----------------------------------------------------------------------------*/
858
859int
861 int key_id);
862
863/*----------------------------------------------------------------------------
864 * Assign a integer value for a given key to a field.
865 *
866 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
867 * If the field category is not compatible with the key (as defined
868 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
869 * If the data type does not match, CS_FIELD_INVALID_TYPE is returned.
870 * If the key value has been locked, CS_FIELD_LOCKED is returned.
871 *
872 * parameters:
873 * f <-- pointer to field structure
874 * key_id <-- id of associated key
875 * value <-- value associated with key
876 *
877 * returns:
878 * 0 in case of success, > 1 in case of error
879 *----------------------------------------------------------------------------*/
880
881int
883 int key_id,
884 int value);
885
886/*----------------------------------------------------------------------------
887 * Return a integer value for a given key associated with a field.
888 *
889 * If the key id is not valid, or the value type or field category is not
890 * compatible, a fatal error is provoked.
891 *
892 * parameters:
893 * f <-- pointer to field structure
894 * key_id <-- id of associated key
895 *
896 * returns:
897 * integer value associated with the key id for this field
898 *----------------------------------------------------------------------------*/
899
900int
902 int key_id);
903
904/*----------------------------------------------------------------------------
905 * Set integer bits matching a mask to 1 for a given key for a field.
906 *
907 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
908 * If the field category is not compatible with the key (as defined
909 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
910 * If the data type does not match, CS_FIELD_INVALID_TYPE is returned.
911 * If the key value has been locked, CS_FIELD_LOCKED is returned.
912 *
913 * parameters:
914 * f <-- pointer to field structure
915 * key_id <-- id of associated key
916 * mask <-- mask associated with key
917 *
918 * returns:
919 * 0 in case of success, > 1 in case of error
920 *----------------------------------------------------------------------------*/
921
922int
924 int key_id,
925 int mask);
926
927/*----------------------------------------------------------------------------
928 * Set integer bits matching a mask to 0 for a given key for a field.
929 *
930 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
931 * If the field category is not compatible with the key (as defined
932 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
933 * If the data type does not match, CS_FIELD_INVALID_TYPE is returned.
934 * If the key value has been locked, CS_FIELD_LOCKED is returned.
935 *
936 * parameters:
937 * f <-- pointer to field structure
938 * key_id <-- id of associated key
939 * mask <-- mask associated with key
940 *
941 * returns:
942 * 0 in case of success, > 1 in case of error
943 *----------------------------------------------------------------------------*/
944
945int
947 int key_id,
948 int mask);
949
950/*----------------------------------------------------------------------------
951 * Assign a floating point value for a given key to a field.
952 *
953 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
954 * If the field category is not compatible with the key (as defined
955 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
956 * If the data type does not match, CS_FIELD_INVALID_TYPE is returned.
957 * If the key value has been locked, CS_FIELD_LOCKED is returned.
958 *
959 * parameters:
960 * f <-- pointer to field structure
961 * key_id <-- id of associated key
962 * value <-- value associated with key
963 *
964 * returns:
965 * 0 in case of success, > 1 in case of error
966 *----------------------------------------------------------------------------*/
967
968int
970 int key_id,
971 double value);
972
973/*----------------------------------------------------------------------------
974 * Return a floating point value for a given key associated with a field.
975 *
976 * If the key id is not valid, or the value type or field category is not
977 * compatible, a fatal error is provoked.
978 *
979 * parameters:
980 * f <-- pointer to field structure
981 * key_id <-- id of associated key
982 *
983 * returns:
984 * floating point value associated with the key id for this field
985 *----------------------------------------------------------------------------*/
986
987double
989 int key_id);
990
991/*----------------------------------------------------------------------------
992 * Assign a character string value for a given key to a field.
993 *
994 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
995 * If the field category is not compatible with the key (as defined
996 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
997 * If the data type does not match, CS_FIELD_INVALID_TYPE is returned.
998 * If the key value has been locked, CS_FIELD_LOCKED is returned.
999 *
1000 * parameters:
1001 * f <-- pointer to field structure
1002 * key_id <-- id of associated key
1003 * str <-- string associated with key
1004 *
1005 * returns:
1006 * 0 in case of success, > 1 in case of error
1007 *----------------------------------------------------------------------------*/
1008
1009int
1011 int key_id,
1012 const char *str);
1013
1014/*----------------------------------------------------------------------------
1015 * Return a string for a given key associated with a field.
1016 *
1017 * If the key id is not valid, or the value type or field category is not
1018 * compatible, a fatal error is provoked.
1019 *
1020 * parameters:
1021 * f <-- pointer to field structure
1022 * key_id <-- id of associated key
1023 *
1024 * returns:
1025 * pointer to character string associated with the key id for this field
1026 *----------------------------------------------------------------------------*/
1027
1028const char *
1030 int key_id);
1031
1032
1033/*----------------------------------------------------------------------------
1034 * Assign a simple structure for a given key to a field.
1035 *
1036 * If the key id is not valid, CS_FIELD_INVALID_KEY_ID is returned.
1037 * If the field category is not compatible with the key (as defined
1038 * by its type flag), CS_FIELD_INVALID_CATEGORY is returned.
1039 * If the key value has been locked, CS_FIELD_LOCKED is returned.
1040 *
1041 * parameters:
1042 * f <-- pointer to field structure
1043 * key_id <-- id of associated key
1044 * s <-- structure associated with key
1045 *
1046 * returns:
1047 * 0 in case of success, > 1 in case of error
1048 *----------------------------------------------------------------------------*/
1049
1050int
1052 int key_id,
1053 void *s);
1054
1055/*----------------------------------------------------------------------------
1056 * Return a structure for a given key associated with a field.
1057 *
1058 * If the key id is not valid, or the value type or field category is not
1059 * compatible, a fatal error is provoked.
1060 *
1061 * parameters:
1062 * f <-- pointer to field structure
1063 * key_id <-- id of associated key
1064 * s <-- structure associated with key
1065 *
1066 * returns:
1067 * pointer to structure associated with the key id for this field
1068 * (same as s)
1069 *----------------------------------------------------------------------------*/
1070
1071const void *
1073 int key_id,
1074 void *s);
1075
1076/*----------------------------------------------------------------------------*/
1077/*
1078 * \brief Return a pointer to a simple structure for a given key to a field.
1079 *
1080 * If the key id is not valid, the value type or field category is not
1081 * compatible, or the structure has been locked, a fatal error is provoked.
1082 *
1083 * Note that using this function marks the field's value for this structure
1084 * as set, and if no values have been set yet, the structure is set to
1085 * default values.
1086 *
1087 * \param[in] f pointer to field structure
1088 * \param[in] key_id id of associated key
1089 *
1090 * \return pointer to key structure in case of success,
1091 * nullptr in case of error
1092 */
1093/*----------------------------------------------------------------------------*/
1094
1095void *
1097 int key_id);
1098
1099/*----------------------------------------------------------------------------*/
1100/*
1101 * \brief Return a read-only pointer to a simple structure for a given key
1102 * to a field.
1103 *
1104 * If the key id is not valid, the value type or field category is not
1105 * compatible, a fatal error is provoked.
1106 *
1107 * \param[in] f pointer to field structure
1108 * \param[in] key_id id of associated key
1109 *
1110 * \return pointer to key structure in case of success,
1111 * nullptr in case of error
1112 */
1113/*----------------------------------------------------------------------------*/
1114
1115const void *
1117 int key_id);
1118
1119/*----------------------------------------------------------------------------
1120 * Print info relative to all field definitions to log file.
1121 *----------------------------------------------------------------------------*/
1122
1123void
1124cs_field_log_defs(void);
1125
1126/*----------------------------------------------------------------------------
1127 * Print info relative to a given field to log file.
1128 *
1129 * parameters:
1130 * f <-- pointer to field structure
1131 * log_keywords <-- log level for keywords (0: do not log,
1132 * 1: log non-default values, 2: log all)
1133 *----------------------------------------------------------------------------*/
1134
1135void
1137 int log_keywords);
1138
1139/*----------------------------------------------------------------------------
1140 * Print info relative to all defined fields to log file.
1141 *
1142 * parameters:
1143 * log_keywords <-- log level for keywords (0: do not log,
1144 * 1: log non-default values, 2: log all)
1145 *----------------------------------------------------------------------------*/
1146
1147void
1148cs_field_log_fields(int log_keywords);
1149
1150/*----------------------------------------------------------------------------
1151 * Print info relative to all key definitions to log file.
1152 *----------------------------------------------------------------------------*/
1153
1154void
1156
1157/*----------------------------------------------------------------------------
1158 * Print info relative to a given field key to log file.
1159 *
1160 * parameters:
1161 * int key_id <-- id of associated key
1162 * log_defaults <-- if true, log default field values in addition to
1163 * defined field values
1164 *----------------------------------------------------------------------------*/
1165
1166void
1167cs_field_log_key_vals(int key_id,
1168 bool log_defaults);
1169
1170/*----------------------------------------------------------------------------
1171 * Print info relative to all given field keys to log file.
1172 *
1173 * parameters:
1174 * log_defaults <-- if true, log default field values in addition to
1175 * defined field values
1176 *----------------------------------------------------------------------------*/
1177
1178void
1179cs_field_log_all_key_vals(bool log_defaults);
1180
1181/*----------------------------------------------------------------------------
1182 * Define base keys.
1183 *
1184 * Keys defined by this function are:
1185 * "label" (string)
1186 * "log" (integer)
1187 * "post_vis" (integer)
1188 * "coupled" (integer, restricted to CS_FIELD_VARIABLE)
1189 * "moment_id" (integer, restricted to
1190 * CS_FIELD_ACCUMULATOR | CS_FIELD_POSTPROCESS);
1191 *
1192 * A recommened practice for different submodules would be to use
1193 * "cs_<module>_key_init() functions to define keys specific to those modules.
1194 *----------------------------------------------------------------------------*/
1195
1196void
1198
1199/*----------------------------------------------------------------------------
1200 * Return a label associated with a field.
1201 *
1202 * If the "label" key has been set for this field, its associated string
1203 * is returned. Otherwise, the field's name is returned.
1204 *
1205 * parameters:
1206 * f <-- pointer to field structure
1207 *
1208 * returns:
1209 * pointer to character string associated with label for this field
1210 *----------------------------------------------------------------------------*/
1211
1212const char *
1214
1215/*----------------------------------------------------------------------------*/
1216
1218
1219#endif /* __CS_FIELD_H__ */
#define BEGIN_C_DECLS
Definition cs_defs.h:542
double cs_real_t
Floating-point value.
Definition cs_defs.h:342
#define END_C_DECLS
Definition cs_defs.h:543
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:3250
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:3400
void cs_field_bc_coeffs_init(cs_field_bc_coeffs_t *bc_coeffs)
Definition cs_field.cpp:1502
void cs_field_init_bc_coeffs(cs_field_t *f)
Initialize boundary condition coefficients arrays.
Definition cs_field.cpp:2102
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:2859
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:3298
int cs_field_key_flag(int key_id)
Get the type flag associated with a given key id.
Definition cs_field.cpp:3096
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:3874
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:1793
cs_field_t * cs_field_by_name(const char *name)
Return a pointer to a field based on its name.
Definition cs_field.cpp:2512
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:2644
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:2933
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:2321
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:2562
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:3795
void cs_field_destroy_all_keys(void)
Destroy all defined field keys and associated values.
Definition cs_field.cpp:3064
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:1639
int cs_field_n_fields(void)
Return the number of defined fields.
Definition cs_field.cpp:1619
void cs_field_log_defs(void)
Print info relative to all field definitions to log file.
Definition cs_field.cpp:3933
const char * cs_field_get_label(const cs_field_t *f)
Return a label associated with a field.
Definition cs_field.cpp:4601
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:3173
void cs_field_allocate_values(cs_field_t *f)
Allocate arrays for field values.
Definition cs_field.cpp:1854
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:1541
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:3548
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:3669
cs_field_error_type_t
Definition cs_field.h:89
@ CS_FIELD_INVALID_KEY_NAME
Definition cs_field.h:92
@ CS_FIELD_INVALID_FIELD
Definition cs_field.h:96
@ CS_FIELD_INVALID_TYPE
Definition cs_field.h:95
@ CS_FIELD_INVALID_CATEGORY
Definition cs_field.h:94
@ CS_FIELD_LOCKED
Definition cs_field.h:97
@ CS_FIELD_OK
Definition cs_field.h:91
@ CS_FIELD_INVALID_KEY_ID
Definition cs_field.h:93
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:3600
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:3142
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:2538
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:3369
void cs_field_key_disable_setup_log(int key_id)
Disable logging setup values associated with a given key.
Definition cs_field.cpp:3120
int cs_field_define_sub_key(const char *name, int parent_id)
Define a sub key.
Definition cs_field.cpp:3038
void cs_field_allocate_or_map_all(void)
Allocate arrays for all defined fields based on their location.
Definition cs_field.cpp:2457
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:1570
void cs_field_destroy_all(void)
Destroy all defined fields.
Definition cs_field.cpp:2389
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:1885
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:1676
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:3721
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:4071
void cs_field_log_key_struct_t(const void *t)
Definition cs_field.h:205
void cs_field_log_key_defs(void)
Print info relative to all key definitions to log file.
Definition cs_field.cpp:4266
cs_field_t * cs_field_by_id(int id)
Return a pointer to a field based on its id.
Definition cs_field.cpp:2488
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:3478
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:2985
int cs_field_key_id(const char *name)
Return an id associated with a given key name.
Definition cs_field.cpp:2804
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:2896
void cs_field_define_keys_base(void)
Define base keys.
Definition cs_field.cpp:4575
void cs_field_clear_key_struct_t(void *t)
Definition cs_field.h:215
int cs_field_key_id_try(const char *name)
Return an id associated with a given key name if present.
Definition cs_field.cpp:2831
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:1733
void cs_field_log_fields(int log_keywords)
Print info relative to all defined fields to log file.
Definition cs_field.cpp:4205
void cs_field_current_to_previous(cs_field_t *f)
Copy current field values to previous values if applicable.
Definition cs_field.cpp:2348
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:4544
int cs_field_lock_key(cs_field_t *f, int key_id)
Lock a field relative to a given key.
Definition cs_field.cpp:3205
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:2593
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:1938
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:2715
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:3430
int cs_field_id_by_name(const char *name)
Return the id of a defined field based on its name.
Definition cs_field.cpp:2694
const char * cs_glob_field_comp_name_3[]
void cs_field_allocate_gradient(cs_field_t *f)
Allocate arrays for field gradient.
Definition cs_field.cpp:2297
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:4420
@ t
Definition cs_field_pointer.h:94
Definition cs_field.h:104
cs_real_t * val_f_lim
Definition cs_field.h:109
cs_real_t * val_f_d_lim
Definition cs_field.h:113
cs_real_t * val_f_d
Definition cs_field.h:112
cs_real_t * val_ip
Definition cs_field.h:106
cs_real_t * val_f
Definition cs_field.h:108
Field boundary condition descriptor (for variables)
Definition cs_field.h:121
cs_real_t * b
Definition cs_field.h:131
cs_real_t * rcodcl3
Definition cs_field.h:128
int * icodcl
Definition cs_field.h:125
cs_real_t * a
Definition cs_field.h:130
cs_real_t * val_f_lim
Definition cs_field.h:144
cs_real_t * rcodcl1
Definition cs_field.h:126
cs_real_t * val_f_d_lim
Definition cs_field.h:148
cs_real_t * bf
Definition cs_field.h:133
cs_real_t * hint
Definition cs_field.h:139
cs_real_t * ad
Definition cs_field.h:134
cs_real_t * bc
Definition cs_field.h:137
cs_real_t * val_f_d
Definition cs_field.h:147
int location_id
Definition cs_field.h:123
cs_real_t * bd
Definition cs_field.h:135
cs_real_t * val_f_pre
Definition cs_field.h:151
cs_real_t * ac
Definition cs_field.h:136
cs_real_t * af
Definition cs_field.h:132
cs_real_t * val_f
Definition cs_field.h:143
cs_real_t * rcodcl2
Definition cs_field.h:127
cs_real_t * _hext
Definition cs_field.h:140
Field descriptor.
Definition cs_field.h:158
cs_real_t * grad
Definition cs_field.h:186
int dim
Definition cs_field.h:165
int id
Definition cs_field.h:162
bool is_owner
Definition cs_field.h:193
cs_field_bc_coeffs_t * bc_coeffs
Definition cs_field.h:190
int location_id
Definition cs_field.h:167
const char * name
Definition cs_field.h:160
int type
Definition cs_field.h:163
cs_real_t * val
Definition cs_field.h:179
int n_time_vals
Definition cs_field.h:169
cs_real_t * val_pre
Definition cs_field.h:182
cs_real_t ** vals
Definition cs_field.h:171