File: cs_property.c

package info (click to toggle)
code-saturne 4.3.3%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 77,992 kB
  • sloc: ansic: 281,257; f90: 122,305; python: 56,490; makefile: 3,915; xml: 3,285; cpp: 3,183; sh: 1,139; lex: 176; yacc: 101; sed: 16
file content (1382 lines) | stat: -rw-r--r-- 45,034 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
/*============================================================================
 * Manage the definition/setting of properties
 *============================================================================*/

/*
  This file is part of Code_Saturne, a general-purpose CFD tool.

  Copyright (C) 1998-2016 EDF S.A.

  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later
  version.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
  Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/*----------------------------------------------------------------------------*/

#include "cs_defs.h"

/*----------------------------------------------------------------------------
 * Standard C library headers
 *----------------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <math.h>

/*----------------------------------------------------------------------------
 * Local headers
 *----------------------------------------------------------------------------*/

#include <bft_mem.h>
#include <bft_printf.h>

#include "cs_defs.h"
#include "cs_math.h"
#include "cs_mesh_location.h"
#include "cs_reco.h"
#include "cs_timer_stats.h"

/*----------------------------------------------------------------------------
 * Header for the current file
 *----------------------------------------------------------------------------*/

#include "cs_property.h"

/*----------------------------------------------------------------------------*/

BEGIN_C_DECLS

/*=============================================================================
 * Local Macro definitions and structure definitions
 *============================================================================*/

#define CS_PROPERTY_DBG  1

/* Set of parameters attached to a property */
struct _cs_property_t {

  char  *restrict name;

  /* Short descriptor to know where is defined the property and what kind of
     property one considers (mask of bits) */

  cs_desc_t   flag;

  /* The number of values to set depends on the type of property
     - isotropic   = 1 => CS_PARAM_VAR_SCAL
     - orthotropic = 3 => CS_PARAM_VAR_VECT
     - anisotropic = 9 => CS_PARAM_VAR_TENS
  */

  cs_property_type_t   type;  // isotropic, anistotropic...

  /* Members to define the value of the property by subdomains (up to now,
     only subdomains built from an union of cells are considered) */

  int               n_max_subdomains; // requested number of subdomains
  int               n_subdomains;     // current number of subddomains defined
  cs_param_def_t   *defs;             // list of definitions for each subdomain
  short int        *def_ids;          /* id in of the definition related to each
                                         cell.
                                         NULL is only one definition is set */

  /* Useful buffers to deal with more complex definitions */

  cs_real_t   *array1;   // if the property hinges on an array
  cs_desc_t    desc1;    // short description of the related array
  cs_real_t   *array2;   // if the property hinges on a second array
  cs_desc_t    desc2;    // short description of the related array

};

/*============================================================================
 * Private variables
 *============================================================================*/

static const char _err_empty_pty[] =
  " Stop setting an empty cs_property_t structure.\n"
  " Please check your settings.\n";

/* Pointer to shared structures (owned by a cs_domain_t structure) */
static const cs_cdo_quantities_t  *cs_cdo_quant;
static const cs_cdo_connect_t  *cs_cdo_connect;
static const cs_time_step_t  *cs_time_step;

/* Id related to cs_timer_stats structure used for monitoring */
static int  property_ts_id = -1;

/*============================================================================
 * Private function prototypes
 *============================================================================*/

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Check if the settings are valid
 *
 * \param[in]  pty       pointer to a cs_property_t structure
 * \param[in]  get       accessor to the tensor values
 */
/*----------------------------------------------------------------------------*/

static inline void
_check_tensor_symmetry(const cs_property_t    *pty,
                       cs_get_t                get)
{
  if ((get.tens[0][1] - get.tens[1][0]) > cs_math_zero_threshold ||
      (get.tens[0][2] - get.tens[2][0]) > cs_math_zero_threshold ||
      (get.tens[1][2] - get.tens[2][1]) > cs_math_zero_threshold)
    bft_error(__FILE__, __LINE__, 0,
              _(" The definition of the tensor related to the"
                " property %s is not symmetric.\n"
                " This case is not handled. Please check your settings.\n"),
              pty->name);
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Add a new definition to a cs_property_t structure defined by domain
 *         Sanity checks on the settings related to this definition.

 * \param[in, out]  pty       pointer to a cs_property_t structure
 * \param[in]       ml_name   name of the related mesh location
 *
 * \return a pointer to a new definition to set
 */
/*----------------------------------------------------------------------------*/

static cs_param_def_t *
_init_new_def(cs_property_t     *pty,
              const char        *ml_name)
{
  if (pty == NULL)
    bft_error(__FILE__, __LINE__, 0, _(_err_empty_pty));

  int  new_id = pty->n_subdomains;

  if (new_id == pty->n_max_subdomains)
    bft_error(__FILE__, __LINE__, 0,
              _(" Max. number of subdomains has been reached for property %s.\n"
                " Please check your settings."), pty->name);

  int  ml_id = cs_mesh_location_get_id_by_name(ml_name);

  if (ml_id == -1)
    bft_error(__FILE__, __LINE__, 0,
              _(" mesh location %s has not been found.\n"
                " Please check your settings."), ml_name);

  if (cs_mesh_location_get_type(ml_id) != CS_MESH_LOCATION_CELLS)
    bft_error(__FILE__, __LINE__, 0,
              _(" Invalid type of mesh location for mesh location  %s.\n"
                " The expected type is CS_MESH_LOCATION_CELLS.\n"), ml_name);

  if (pty->n_max_subdomains > 1) { /* Assign new id to the selected cells */

    const cs_lnum_t  n_cells = cs_cdo_quant->n_cells;
    const cs_lnum_t  *n_elts = cs_mesh_location_get_n_elts(ml_id);
    const cs_lnum_t  *elt_ids = cs_mesh_location_get_elt_list(ml_id);

    if (elt_ids == NULL) {

      assert(n_elts[0] == n_cells); // Sanity check. Only this case is handled
# pragma omp parallel for if (n_elts[0] > CS_THR_MIN)
      for (cs_lnum_t i = 0; i < n_elts[0]; i++)
        pty->def_ids[i] = new_id;

    }
    else {

# pragma omp parallel for if (n_elts[0] > CS_THR_MIN)
      for (cs_lnum_t i = 0; i < n_elts[0]; i++)
        pty->def_ids[elt_ids[i]] = new_id;

    }

  } // n_max_subdomains > 1

  pty->n_subdomains += 1;

  cs_param_def_t  *new_def = pty->defs + new_id;

  /* Copy mesh location name */
  int  len = strlen(ml_name) + 1;
  BFT_MALLOC(new_def->ml_name, len, char);
  strncpy(new_def->ml_name, ml_name, len);

  return new_def;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute the value using a law with one argument
 *
 * \param[in]       pty     pointer to a cs_property_t structure
 * \param[in]       get     accessor to the value
 * \param[in, out]  tensor  result stored in a 3x3 tensor
 */
/*----------------------------------------------------------------------------*/

static void
_get_tensor_by_value(const cs_property_t      *pty,
                     cs_get_t                  get,
                     cs_real_3_t              *tensor)
{
  int  k, l;

  switch (pty->type) {

  case CS_PROPERTY_ISO:
    tensor[0][0] = tensor[1][1] = tensor[2][2] = get.val;
    break;

  case CS_PROPERTY_ORTHO:
    for (k = 0; k < 3; k++)
      tensor[k][k] = get.vect[k];
    break;

  case CS_PROPERTY_ANISO:
    for (k = 0; k < 3; k++)
      for (l = 0; l < 3; l++)
        tensor[k][l] = get.tens[k][l];
    break;

  default:
    assert(0);
    break;

  } // Property type
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Retrieve the value at the cell center of cell c_id from an array
 *
 * \param[in]  c_id      if of the cell to treat
 * \param[in]  desc      information about the array to handle
 * \param[in]  array     values
 */
/*----------------------------------------------------------------------------*/

static double
_get_cell_value_from_array(cs_lnum_t         c_id,
                           const cs_desc_t   desc,
                           const cs_real_t   array[])
{
  double  cell_val = 0.;

  if ((desc.location & CS_FLAG_SCAL) != CS_FLAG_SCAL)
    bft_error(__FILE__, __LINE__, 0,
              " Invalid type of variable. Stop computing the cell value.");

  /* Test if flag has the pattern of a reference support */
  if ((desc.location & cs_cdo_primal_cell) == cs_cdo_primal_cell)
    cell_val = array[c_id];

  else if ((desc.location & cs_cdo_primal_vtx) == cs_cdo_primal_vtx)

    /* Reconstruct (or interpolate) value at the current cell center */
    cs_reco_pv_at_cell_center(c_id,
                              cs_cdo_connect->c2v,
                              cs_cdo_quant,
                              array,
                              &cell_val);

  else
    bft_error(__FILE__, __LINE__, 0,
              " Invalid support for evaluating the value of an array");

  return cell_val;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Retrieve the vector at the cell center of cell c_id from an array
 *
 * \param[in]       c_id      if of the cell to treat
 * \param[in]       desc      information about the array to handle
 * \param[in]       array     values
 * \param[in, out]  vect_val  vector at the cell center
 */
/*----------------------------------------------------------------------------*/

static void
_get_cell_vector_from_array(cs_lnum_t         c_id,
                            const cs_desc_t   desc,
                            const cs_real_t   array[],
                            cs_real_3_t       vect_val)
{
  /* Test if flag has the pattern of a reference support */
  if ((desc.location & cs_cdo_primal_cell) == cs_cdo_primal_cell)
    for (int k = 0; k < 3; k++)
      vect_val[k] = array[3*c_id+k];

  else if ((desc.location & cs_cdo_dual_face_byc) == cs_cdo_dual_face_byc)

    /* Reconstruct (or interpolate) value at the current cell center */
    cs_reco_dfbyc_at_cell_center(c_id,
                                 cs_cdo_connect->c2e, cs_cdo_quant, array,
                                 vect_val);

  else
    bft_error(__FILE__, __LINE__, 0,
              " Invalid support for evaluating the vector from an array.");
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute the value using a law with one scalar variable
 *
 * \param[in]       c_id     cell id
 * \param[in]       pty      pointer to a cs_property_t structure
 * \param[in]       law      function pointer to the law
 * \param[in]       context  pointer to a structure
 * \param[in, out]  get      pointer to a union used to retrieve the result
 */
/*----------------------------------------------------------------------------*/

static void
_get_result_by_onevar_law(cs_lnum_t                 c_id,
                          const cs_property_t      *pty,
                          cs_onevar_law_func_t     *law,
                          const void               *context,
                          cs_get_t                 *get)
{
  assert(pty->array1 != NULL); /* Sanity check */

  cs_real_t  val_xc = _get_cell_value_from_array(c_id, pty->desc1, pty->array1);

  law(val_xc, context, get);
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute the value using a law with two scalar variables
 *
 * \param[in]       c_id     cell id
 * \param[in]       pty      pointer to a cs_property_t structure
 * \param[in]       law      function pointer to the law
 * \param[in]       context  pointer to a structure
 * \param[in, out]  get      pointer to a union used to retrieve the result
 */
/*----------------------------------------------------------------------------*/

static void
_get_result_by_twovar_law(cs_lnum_t                 c_id,
                          const cs_property_t      *pty,
                          cs_twovar_law_func_t     *law,
                          const void               *context,
                          cs_get_t                 *get)
{
  assert(pty->array1 != NULL && pty->array2 != NULL); /* Sanity check */

  cs_real_t  val1 = _get_cell_value_from_array(c_id, pty->desc1, pty->array1);
  cs_real_t  val2 = _get_cell_value_from_array(c_id, pty->desc2, pty->array2);

  /* Compute the value of the law for this cell */
  law(val1, val2, context, get);
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute the value using a law with two arguments: one scalar and
 *         one vector-valued
 *
 * \param[in]       c_id    cell id
 * \param[in]       pty     pointer to a cs_property_t structure
 * \param[in]       law     function pointer to the law
 * \param[in]       context   pointer to a structure
 * \param[in, out]  get     pointer to a union used to retrieve the result
 */
/*----------------------------------------------------------------------------*/

static void
_get_result_by_scavec_law(cs_lnum_t                 c_id,
                          const cs_property_t      *pty,
                          cs_scavec_law_func_t     *law,
                          const void               *context,
                          cs_get_t                 *get)
{
  /* Sanity checks */
  assert(pty->array1 != NULL && pty->array2 != NULL);

  cs_real_t  scal_val = _get_cell_value_from_array(c_id,
                                                   pty->desc1, pty->array1);
  cs_real_t  vect_val[3] = {0, 0, 0};
  _get_cell_vector_from_array(c_id, pty->desc2, pty->array2, vect_val);

  /* Retrieve the result of the law function */
  law(scal_val, vect_val, context, get);
}

/*============================================================================
 * Public function prototypes
 *============================================================================*/

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Set shared pointers to main domain members
 *
 * \param[in]  quant       additional mesh quantities struct.
 * \param[in]  connect     pointer to a cs_cdo_connect_t struct.
 * \param[in]  time_step   pointer to a time step structure
 */
/*----------------------------------------------------------------------------*/

void
cs_property_set_shared_pointers(const cs_cdo_quantities_t    *quant,
                                const cs_cdo_connect_t       *connect,
                                const cs_time_step_t         *time_step)
{
  /* Assign static const pointers */
  cs_cdo_quant = quant;
  cs_cdo_connect = connect;
  cs_time_step = time_step;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief   Initialize cs_timer_stats_t structure for monitoring purpose
 *
 * \param[in]  level      level of details requested
 */
/*----------------------------------------------------------------------------*/

void
cs_property_set_timer_stats(int   level)
{
  if (level < 1)
    return;

  /* Timer statistics */
  property_ts_id = cs_timer_stats_create("operations", "property", "property");

}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Create and initialize a new property structure
 *
 * \param[in]  name          name of the property
 * \param[in]  key_type      keyname of the type of property
 * \param[in]  n_subdomains  piecewise definition on n_subdomains
 *
 * \return a pointer to a new allocated cs_property_t structure
 */
/*----------------------------------------------------------------------------*/

cs_property_t *
cs_property_create(const char    *name,
                   const char    *key_type,
                   int            n_subdomains)
{
  cs_property_t  *pty = NULL;

  BFT_MALLOC(pty, 1, cs_property_t);

  /* Copy name */
  int  len = strlen(name) + 1;
  BFT_MALLOC(pty->name, len, char);
  strncpy(pty->name, name, len);

  /* Assign a type */
  if (strcmp(key_type, "isotropic") == 0)
    pty->type = CS_PROPERTY_ISO;
  else if (strcmp(key_type, "orthotropic") == 0)
    pty->type = CS_PROPERTY_ORTHO;
  else if (strcmp(key_type, "anisotropic") == 0)
    pty->type = CS_PROPERTY_ANISO;
  else
    bft_error(__FILE__, __LINE__, 0,
              _(" Invalid key \"%s\" for setting the type of property.\n"
                " Valid keys: \"isotropic\", \"orthotropic\" and"
                " \"anisotropic\".\n"
                " Please modify your settings."), key_type);

  /* Default initialization */
  pty->flag.location = 0;
  pty->flag.state = 0;

  /* Members useful to define the property by subdomain */
  assert(n_subdomains > 0);
  pty->n_max_subdomains = n_subdomains;
  pty->n_subdomains = 0; // No definition set by default

  BFT_MALLOC(pty->defs, n_subdomains, cs_param_def_t);

  pty->def_ids = NULL;
  if (n_subdomains > 1) { /* Initialization of def_ids */

    BFT_MALLOC(pty->def_ids, cs_cdo_quant->n_cells, short int);

# pragma omp parallel for if (cs_cdo_quant->n_cells > CS_THR_MIN)
    for (cs_lnum_t i = 0; i < cs_cdo_quant->n_cells; i++)
      pty->def_ids[i] = -1; // Unset by default

  }

  /* Specific members for more complex definitions */
  pty->desc1.location = pty->desc1.state = 0;
  pty->array1 = NULL;
  pty->desc2.location = pty->desc2.state = 0;
  pty->array2 = NULL;

  return pty;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Free a cs_property_t structure
 *
 * \param[in, out]  pty      pointer to a cs_property_t structure to free
 *
 * \return a NULL pointer
 */
/*----------------------------------------------------------------------------*/

cs_property_t *
cs_property_free(cs_property_t   *pty)
{
  if (pty == NULL)
    return pty;

  BFT_FREE(pty->name);
  BFT_FREE(pty->def_ids);
  for (int i = 0; i < pty->n_subdomains; i++)
    BFT_FREE(pty->defs[i].ml_name);
  BFT_FREE(pty->defs);

  if (pty->desc1.state & CS_FLAG_STATE_OWNER)
    if (pty->array1 != NULL)
      BFT_FREE(pty->array1);

  if (pty->desc2.state & CS_FLAG_STATE_OWNER)
    if (pty->array2 != NULL)
      BFT_FREE(pty->array2);

  BFT_FREE(pty);

  return NULL;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Check if the given property has the name ref_name
 *
 * \param[in]  pty         pointer to a cs_property_t structure to test
 * \param[in]  ref_name    name of the property to find
 *
 * \return true if the name of the property is ref_name otherwise false
 */
/*----------------------------------------------------------------------------*/

bool
cs_property_check_name(const cs_property_t   *pty,
                       const char            *ref_name)
{
  if (pty == NULL)
    return false;

  int  reflen = strlen(ref_name);
  int  len = strlen(pty->name);

  if (reflen == len) {
    if (strcmp(ref_name, pty->name) == 0)
      return true;
    else
      return false;
  }
  else
    return false;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  returns true if the property is uniform, otherwise false
 *
 * \param[in]    pty    pointer to a property to test
 *
 * \return  true or false
 */
/*----------------------------------------------------------------------------*/

bool
cs_property_is_uniform(const cs_property_t   *pty)
{
  if (pty == NULL)
    return false;

  if (pty->flag.state & CS_FLAG_STATE_UNIFORM)
    return true;
  else
    return false;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Retrieve the name of a property
 *
 * \param[in]    pty    pointer to a property
 *
 * \return  the name of the related property
 */
/*----------------------------------------------------------------------------*/

const char *
cs_property_get_name(const cs_property_t   *pty)
{
  if (pty == NULL)
    return NULL;

  return pty->name;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Retrieve the type of a property
 *
 * \param[in]    pty    pointer to a property
 *
 * \return  the type of the related property
 */
/*----------------------------------------------------------------------------*/

cs_property_type_t
cs_property_get_type(const cs_property_t   *pty)
{
  if (pty == NULL)
    return CS_PROPERTY_N_TYPES;

  return pty->type;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Print a summary of a cs_property_t structure
 *
 * \param[in]  pty      pointer to a cs_property_t structure to summarize
 */
/*----------------------------------------------------------------------------*/

void
cs_property_summary(const cs_property_t   *pty)
{
  if (pty == NULL)
    return;

  _Bool  is_uniform = false, is_steady = true;

  if (pty->flag.state & CS_FLAG_STATE_UNIFORM)  is_uniform = true;
  if (pty->flag.state & CS_FLAG_STATE_UNSTEADY) is_steady = false;

  bft_printf("  %s >> uniform [%s], steady [%s], ",
             pty->name, cs_base_strtf(is_uniform), cs_base_strtf(is_steady));

  switch(pty->type) {
  case CS_PROPERTY_ISO:
    bft_printf("type: isotropic\n");
    break;
  case CS_PROPERTY_ORTHO:
    bft_printf("type: orthotropic\n");
    break;
  case CS_PROPERTY_ANISO:
    bft_printf("type: anisotropic\n");
    break;
  default:
    bft_error(__FILE__, __LINE__, 0,
              _(" Invalid type of property."));
    break;
  }

  /* Definition */
  bft_printf("  %s >> n_subdomains    %d\n", pty->name, pty->n_subdomains);

  for (int i = 0; i < pty->n_subdomains; i++) {

    cs_param_def_t  *pdef  = pty->defs + i;

    bft_printf("  %s >> location  %s,", pty->name, pdef->ml_name);

    switch (pdef->def_type) {

    case CS_PARAM_DEF_BY_VALUE:
      {
        const cs_get_t  mat = pdef->def.get;

        switch(pty->type) {

        case CS_PROPERTY_ISO:
          bft_printf(" definition by value: % 5.3e\n", mat.val);
          break;
        case CS_PROPERTY_ORTHO:
          bft_printf(" definition by value: (% 5.3e, % 5.3e, % 5.3e)\n",
                     mat.vect[0], mat.vect[1], mat.vect[2]);
          break;
        case CS_PROPERTY_ANISO:
          bft_printf("\n                       |% 5.3e, % 5.3e, % 5.3e|\n"
                     "  definition by value: |% 5.3e, % 5.3e, % 5.3e|\n"
                     "                       |% 5.3e, % 5.3e, % 5.3e|\n",
                     mat.tens[0][0], mat.tens[0][1], mat.tens[0][2],
                     mat.tens[1][0], mat.tens[1][1], mat.tens[1][2],
                     mat.tens[2][0], mat.tens[2][1], mat.tens[2][2]);
          break;
        default:
          break;

        } // pty->type
      }
      break; // BY_VALUE

    case CS_PARAM_DEF_BY_ANALYTIC_FUNCTION:
      bft_printf("  definition by an analytical function\n");
      break;

    case CS_PARAM_DEF_BY_LAW_ONESCA:
      bft_printf("  definition by a law based on one scalar\n");
      break;

    case CS_PARAM_DEF_BY_LAW_SCAVEC:
      bft_printf("  definition by law based on one scalar + one vector\n");
      break;

    default:
      bft_error(__FILE__, __LINE__, 0,
                _(" Invalid type of definition for a property."));
      break;

    } /* switch on def_type */

  } // Loop on subdomains

}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Define a cs_property_t structure by value for entities attached to
 *         the mesh location named ml_name
 *
 * \param[in, out]  pty       pointer to a cs_property_t structure
 * \param[in]       ml_name   name of the related mesh location
 * \param[in]       keyval    accessor to the value to set
 */
/*----------------------------------------------------------------------------*/

void
cs_property_def_by_value(cs_property_t    *pty,
                         const char       *ml_name,
                         const char       *key_val)
{
  cs_param_def_t  *new_def = _init_new_def(pty, ml_name);

  new_def->def_type = CS_PARAM_DEF_BY_VALUE;
  if (pty->n_max_subdomains == 1)
    pty->flag.state |= CS_FLAG_STATE_UNIFORM;

  switch (pty->type) {

  case CS_PROPERTY_ISO:
    cs_param_set_get(CS_PARAM_VAR_SCAL, (const void *)key_val,
                     &(new_def->def.get));
    break;

  case CS_PROPERTY_ORTHO:
    cs_param_set_get(CS_PARAM_VAR_VECT, (const void *)key_val,
                     &(new_def->def.get));
    break;

  case CS_PROPERTY_ANISO:
    cs_param_set_get(CS_PARAM_VAR_TENS, (const void *)key_val,
                     &(new_def->def.get));

    /* Check the symmetry */
    _check_tensor_symmetry(pty, new_def->def.get);
    break;

  default:
    bft_error(__FILE__, __LINE__, 0, _(" Invalid type of property."));
    break;

  } /* switch on property type */

}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Define an isotropic cs_property_t structure by value for entities
 *         attached to the mesh location named ml_name
 *
 * \param[in, out]  pty       pointer to a cs_property_t structure
 * \param[in]       ml_name   name of the related mesh location
 * \param[in]       val       value to set
 */
/*----------------------------------------------------------------------------*/

void
cs_property_iso_def_by_value(cs_property_t    *pty,
                             const char       *ml_name,
                             double            val)
{
  cs_param_def_t  *new_def = _init_new_def(pty, ml_name);

  if (pty->type != CS_PROPERTY_ISO)
    bft_error(__FILE__, __LINE__, 0,
              " Invalid setting: property %s is not isotropic.\n"
              " Please check your settings.", pty->name);

  new_def->def_type = CS_PARAM_DEF_BY_VALUE;
  if (pty->n_max_subdomains == 1)
    pty->flag.state |= CS_FLAG_STATE_UNIFORM;
  new_def->def.get.val = val;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Define orthotropic cs_property_t structure by value for entities
 *         attached to the mesh location named ml_name
 *
 * \param[in, out]  pty       pointer to a cs_property_t structure
 * \param[in]       ml_name   name of the related mesh location
 * \param[in]       val       values to set (vector of size 3)
 */
/*----------------------------------------------------------------------------*/

void
cs_property_ortho_def_by_value(cs_property_t    *pty,
                               const char       *ml_name,
                               const double      val[])
{
  cs_param_def_t  *new_def = _init_new_def(pty, ml_name);

  if (pty->type != CS_PROPERTY_ORTHO)
    bft_error(__FILE__, __LINE__, 0,
              " Invalid setting: property %s is not orthotropic.\n"
              " Please check your settings.", pty->name);

  new_def->def_type = CS_PARAM_DEF_BY_VALUE;
  if (pty->n_max_subdomains == 1)
    pty->flag.state |= CS_FLAG_STATE_UNIFORM;

  new_def->def.get.vect[0] = val[0];
  new_def->def.get.vect[1] = val[1];
  new_def->def.get.vect[2] = val[2];
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Define an anisotropic cs_property_t structure by value for entities
 *         attached to the mesh location named ml_name
 *
 * \param[in, out]  pty       pointer to a cs_property_t structure
 * \param[in]       ml_name   name of the related mesh location
 * \param[in]       tens      values to set (3x3 tensor)
 */
/*----------------------------------------------------------------------------*/

void
cs_property_aniso_def_by_value(cs_property_t    *pty,
                               const char       *ml_name,
                               const double      tens[3][3])
{
  cs_param_def_t  *new_def = _init_new_def(pty, ml_name);

  if (pty->type != CS_PROPERTY_ANISO)
    bft_error(__FILE__, __LINE__, 0,
              " Invalid setting: property %s is not anisotropic.\n"
              " Please check your settings.", pty->name);

  new_def->def_type = CS_PARAM_DEF_BY_VALUE;
  if (pty->n_max_subdomains == 1)
    pty->flag.state |= CS_FLAG_STATE_UNIFORM;

  new_def->def.get.tens[0][0] = tens[0][0];
  new_def->def.get.tens[0][1] = tens[0][1];
  new_def->def.get.tens[0][2] = tens[0][2];
  new_def->def.get.tens[1][0] = tens[1][0];
  new_def->def.get.tens[1][1] = tens[1][1];
  new_def->def.get.tens[1][2] = tens[1][2];
  new_def->def.get.tens[2][0] = tens[2][0];
  new_def->def.get.tens[2][1] = tens[2][1];
  new_def->def.get.tens[2][2] = tens[2][2];

  /* Check the symmetry */
  _check_tensor_symmetry(pty, new_def->def.get);
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Define a cs_property_t structure thanks to an analytic function in
 *         a subdomain attached to the mesh location named ml_name
 *
 * \param[in, out]  pty       pointer to a cs_property_t structure
 * \param[in]       ml_name   name of the related mesh location
 * \param[in]       func      pointer to a cs_analytic_func_t function
 */
/*----------------------------------------------------------------------------*/

void
cs_property_def_by_analytic(cs_property_t        *pty,
                            const char           *ml_name,
                            cs_analytic_func_t   *func)
{
  cs_param_def_t  *new_def = _init_new_def(pty, ml_name);

  new_def->def_type = CS_PARAM_DEF_BY_ANALYTIC_FUNCTION;
  new_def->def.analytic = func;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Define a cs_property_t structure thanks to law depending on one
 *         scalar variable in a subdomain attached to the mesh location named
 *         ml_name
 *
 * \param[in, out]  pty       pointer to a cs_property_t structure
 * \param[in]       ml_name   name of the related mesh location
 * \param[in]       context   pointer to a structure (may be NULL)
 * \param[in]       func      pointer to a law function defined by subdomain
 */
/*----------------------------------------------------------------------------*/

void
cs_property_def_by_law(cs_property_t             *pty,
                       const char                *ml_name,
                       const void                *context,
                       cs_onevar_law_func_t      *func)
{
  cs_param_def_t  *new_def = _init_new_def(pty, ml_name);

  new_def->def_type = CS_PARAM_DEF_BY_LAW_ONESCA;
  new_def->def.law1_func = func;
  new_def->context = context;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Define a cs_property_t structure thanks to a law depending on
 *         two scalars variables in a subdomain attached to the mesh location
 *         named ml_name
 *
 * \param[in, out]  pty       pointer to a cs_property_t structure
 * \param[in]       ml_name   name of the related mesh location
 * \param[in]       context   pointer to a structure (may be NULL)
 * \param[in]       func      pointer to a function
 */
/*----------------------------------------------------------------------------*/

void
cs_property_def_by_twovar_law(cs_property_t          *pty,
                              const char             *ml_name,
                              const void             *context,
                              cs_twovar_law_func_t   *func)
{
  cs_param_def_t  *new_def = _init_new_def(pty, ml_name);

  new_def->def_type = CS_PARAM_DEF_BY_LAW_TWOSCA;
  new_def->def.law2_func = func;
  new_def->context = context;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Define a cs_property_t structure thanks to a law depending on
 *         a scalar and a vector variables in a subdomain attached to the mesh
 *         location named ml_name
 *
 * \param[in, out]  pty       pointer to a cs_property_t structure
 * \param[in]       ml_name   name of the related mesh location
 * \param[in]       context   pointer to a structure (may be NULL)
 * \param[in]       func      pointer to a law function defined by subdomain
 */
/*----------------------------------------------------------------------------*/

void
cs_property_def_by_scavec_law(cs_property_t             *pty,
                              const char                *ml_name,
                              const void                *context,
                              cs_scavec_law_func_t      *func)
{
  cs_param_def_t  *new_def = _init_new_def(pty, ml_name);

  new_def->def_type = CS_PARAM_DEF_BY_LAW_SCAVEC;
  new_def->def.law_scavec_func = func;
  new_def->context = context;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Define a cs_property_t structure thanks to an array of values
 *
 * \param[in, out]  pty       pointer to a cs_property_t structure
 * \param[in]       desc      information about this array
 * \param[in]       array     pointer to an array
 */
/*----------------------------------------------------------------------------*/

void
cs_property_def_by_array(cs_property_t    *pty,
                         cs_desc_t         desc,
                         cs_real_t        *array)
{
  cs_param_def_t  *new_def = _init_new_def(pty, N_("cells"));

  if (pty->n_max_subdomains != 1)
    bft_error(__FILE__, __LINE__, 0,
              " When a definition by array is requested, the max. number"
              " of subdomains to consider should be equal to 1.\n"
              " Current value is %d for property %s.\n"
              " Please modify your settings.",
              pty->n_max_subdomains, pty->name);

  new_def->def_type = CS_PARAM_DEF_BY_ARRAY;
  pty->desc1.location = desc.location;
  pty->desc1.state = desc.state;
  pty->array1 = array;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Set the "array" member of a cs_property_t structure
 *
 * \param[in, out]  pty          pointer to a cs_property_t structure
 * \param[in]       desc         information about this array
 * \param[in]       array        pointer to an array of values
 */
/*----------------------------------------------------------------------------*/

void
cs_property_set_array(cs_property_t    *pty,
                      cs_desc_t         desc,
                      cs_real_t        *array)
{
  if (pty == NULL)
    bft_error(__FILE__, __LINE__, 0, _(_err_empty_pty));

  pty->desc1.location = desc.location;
  pty->desc1.state = desc.state;
  pty->array1 = array;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Set the second "array" member of a cs_property_t structure
 *
 * \param[in, out]  pty        pointer to a cs_property_t structure
 * \param[in]       desc       information about this array
 * \param[in]       array      pointer to an array of values
 */
/*----------------------------------------------------------------------------*/

void
cs_property_set_second_array(cs_property_t    *pty,
                             cs_desc_t         desc,
                             cs_real_t        *array)
{
  if (pty == NULL)
    bft_error(__FILE__, __LINE__, 0, _(_err_empty_pty));

  pty->desc2.location = desc.location;
  pty->desc2.state = desc.state;
  pty->array2 = array;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute the value of the tensor attached a property at the cell
 *         center
 *
 * \param[in]      c_id           id of the current cell
 * \param[in]      pty            pointer to a cs_property_t structure
 * \param[in]      do_inversion   true or false
 * \param[in, out] tensor         3x3 matrix
 */
/*----------------------------------------------------------------------------*/

void
cs_property_get_cell_tensor(cs_lnum_t             c_id,
                            const cs_property_t  *pty,
                            bool                  do_inversion,
                            cs_real_3_t          *tensor)
{
  cs_get_t  get;

  if (pty == NULL)
    return;

  if (property_ts_id > -1)
    cs_timer_stats_start(property_ts_id);

  /* Initialize extra-diag. values of the tensor */
  for (int k = 0; k < 3; k++)
    for (int l = k+1; l < 3; l++)
      tensor[k][l] = 0;

  int  def_id = -1;
  if (pty->n_max_subdomains == 1)
    def_id = 0;
  else
    def_id = pty->def_ids[c_id];

  cs_param_def_t  *sub = pty->defs + def_id;

  switch (sub->def_type) {

  case CS_PARAM_DEF_BY_VALUE:
    _get_tensor_by_value(pty, sub->def.get, tensor);
    break;

  case CS_PARAM_DEF_BY_ANALYTIC_FUNCTION:
    {
      const cs_real_t  *xc = cs_cdo_quant->cell_centers + 3*c_id;
      const double  t_cur = cs_time_step->t_cur;

      /* Call the analytic function. result is stored in get and then converted
         into a 3x3 tensor */
      sub->def.analytic(t_cur, xc, &get);
      _get_tensor_by_value(pty, get, tensor);

    }
    break;

  case CS_PARAM_DEF_BY_LAW_ONESCA:
    _get_result_by_onevar_law(c_id, pty, sub->def.law1_func, sub->context,
                              &get);
    _get_tensor_by_value(pty, get, tensor);
    break;

  case CS_PARAM_DEF_BY_LAW_TWOSCA:
    _get_result_by_twovar_law(c_id, pty, sub->def.law2_func, sub->context,
                              &get);
    _get_tensor_by_value(pty, get, tensor);
    break;

  case CS_PARAM_DEF_BY_LAW_SCAVEC:
    _get_result_by_scavec_law(c_id, pty, sub->def.law_scavec_func, sub->context,
                              &get);
    _get_tensor_by_value(pty, get, tensor);
    break;

  default:
    bft_error(__FILE__, __LINE__, 0,
              " Stop computing the cell tensor related to property %s.\n"
              " Type of definition not handled yet.", pty->name);
    break;

  } /* type of definition */

  if (do_inversion) {

#if defined(DEBUG) && !defined(NDEBUG) && CS_PROPERTY_DBG > 0 /* Sanity check */
    for (int k = 0; k < 3; k++)
      if (fabs(tensor[k][k]) < cs_math_zero_threshold)
        bft_error(__FILE__, __LINE__, 0,
                  " Potential problem in the inversion of the tensor attached"
                  " to property %s in cell %d.\n"
                  " Tensor[%d][%d] = %5.3e",
                  pty->name, c_id, k, k, tensor[k][k]);
#endif

    if (pty->type == CS_PROPERTY_ISO || pty->type == CS_PROPERTY_ORTHO)
      for (int k = 0; k < 3; k++)
        tensor[k][k] /= 1.0;

    else { /* anisotropic */

      cs_real_33_t  invmat;

      cs_math_33_inv((const cs_real_3_t (*))tensor, invmat);
      for (int k = 0; k < 3; k++)
        for (int l = 0; l < 3; l++)
          tensor[k][l] = invmat[k][l];

    }

  } /* Inversion of the tensor */

#if defined(DEBUG) && !defined(NDEBUG) && CS_PROPERTY_DBG > 1
  bft_printf("\n  Tensor property for cell %d\n"
             "   | % 10.6e  % 10.6e  % 10.6e |\n"
             "   | % 10.6e  % 10.6e  % 10.6e |\n"
             "   | % 10.6e  % 10.6e  % 10.6e |\n", c_id,
             tensor[0][0], tensor[0][1], tensor[0][2],
             tensor[1][0], tensor[1][1], tensor[1][2],
             tensor[2][0], tensor[2][1], tensor[2][2]);
#endif

  if (property_ts_id > -1)
    cs_timer_stats_stop(property_ts_id);
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute the value of a property at the cell center
 *
 * \param[in]   c_id           id of the current cell
 * \param[in]   pty            pointer to a cs_property_t structure
 *
 * \return the value of the property for the given cell
 */
/*----------------------------------------------------------------------------*/

cs_real_t
cs_property_get_cell_value(cs_lnum_t              c_id,
                           const cs_property_t   *pty)
{
  cs_real_t  result = 0;
  cs_get_t  get;

  if (pty == NULL)
    return result;

  if (property_ts_id > -1)
    cs_timer_stats_start(property_ts_id);

  if (pty->type != CS_PROPERTY_ISO)
    bft_error(__FILE__, __LINE__, 0,
              " Invalid type of property for this function.\n"
              " Property %s has to be isotropic.", pty->name);

  int  def_id = -1;
  if (pty->n_max_subdomains == 1)
    def_id = 0;
  else
    def_id = pty->def_ids[c_id];

  cs_param_def_t  *sub = pty->defs + def_id;

  switch (sub->def_type) {

  case CS_PARAM_DEF_BY_VALUE:
    result = sub->def.get.val;
    break;

  case CS_PARAM_DEF_BY_ANALYTIC_FUNCTION:
    {
      const cs_real_t  *xc = cs_cdo_quant->cell_centers + 3*c_id;
      const double  t_cur = cs_time_step->t_cur;

      /* Call the analytic function. result is stored in get */
      sub->def.analytic(t_cur, xc, &get);
      result = get.val;
    }
    break;

  case CS_PARAM_DEF_BY_LAW_ONESCA:
    _get_result_by_onevar_law(c_id, pty, sub->def.law1_func, sub->context,
                              &get);
    result = get.val;
    break;

  case CS_PARAM_DEF_BY_LAW_TWOSCA:
    _get_result_by_twovar_law(c_id, pty, sub->def.law2_func, sub->context,
                              &get);
    result = get.val;
    break;

  case CS_PARAM_DEF_BY_ARRAY:
    result = _get_cell_value_from_array(c_id, pty->desc1, pty->array1);
    break;

  case CS_PARAM_DEF_BY_LAW_SCAVEC:
    _get_result_by_scavec_law(c_id,
                              pty, sub->def.law_scavec_func, sub->context,
                              &get);
    result = get.val;
    break;

  default:
    bft_error(__FILE__, __LINE__, 0,
              " Stop computing the cell value related to property %s.\n"
              " Type of definition not handled yet.", pty->name);
    break;

  } /* type of definition */

  if (property_ts_id > -1)
    cs_timer_stats_stop(property_ts_id);

  return result;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief   Compute the Fourier number in each cell
 *
 * \param[in]      pty        pointer to the diffusive property struct.
 * \param[in]      dt         value of the current time step
 * \param[in, out] fourier    pointer to an array storing Fourier numbers
 */
/*----------------------------------------------------------------------------*/

void
cs_property_get_fourier(const cs_property_t     *pty,
                        double                   dt,
                        cs_real_t                fourier[])
{
  assert(fourier != NULL); // Sanity check
  assert(dt > 0.);

  const bool  pty_uniform = cs_property_is_uniform(pty);
  const cs_cdo_quantities_t  *cdoq = cs_cdo_quant;

  if (pty->type == CS_PROPERTY_ISO) {

    cs_real_t  ptyval = 0.;
    if (pty_uniform)
      ptyval = cs_property_get_cell_value(0, pty);

    for (cs_lnum_t c_id = 0; c_id < cdoq->n_cells; c_id++) {

      if (!pty_uniform)
        ptyval = cs_property_get_cell_value(c_id, pty);

      const cs_real_t  hc = pow(cdoq->cell_vol[c_id], cs_math_onethird);

      fourier[c_id] = dt * ptyval / (hc * hc);

    } // Loop on cells

  }
  else { // Property is orthotropic or anisotropic

    cs_real_t  eig_max, eig_ratio;
    cs_real_t  ptymat[3][3];

    /* Get the value of the material property at the first cell center */
    if (pty_uniform) {
      cs_property_get_cell_tensor(0, pty, false, ptymat);
      cs_math_33_eigen((const cs_real_t (*)[3])ptymat, &eig_ratio, &eig_max);
    }

    for (cs_lnum_t c_id = 0; c_id < cdoq->n_cells; c_id++) {

      /* Get the value of the material property at the cell center */
      if (!pty_uniform) {
        cs_property_get_cell_tensor(c_id, pty, false, ptymat);
        cs_math_33_eigen((const cs_real_t (*)[3])ptymat, &eig_ratio, &eig_max);
      }

      const cs_real_t  hc = pow(cdoq->cell_vol[c_id], cs_math_onethird);

      fourier[c_id] = dt * eig_max / (hc * hc);

    } // Loop on cells

  } // Type of property

}

/*----------------------------------------------------------------------------*/

END_C_DECLS