-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathcs_gui.c
5360 lines (4367 loc) · 166 KB
/
cs_gui.c
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
/*============================================================================
* Management of the GUI parameters file: main parameters
*============================================================================*/
/*
This file is part of Code_Saturne, a general-purpose CFD tool.
Copyright (C) 1998-2019 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 <math.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
/*----------------------------------------------------------------------------
* Local headers
*----------------------------------------------------------------------------*/
#include "bft_mem.h"
#include "bft_error.h"
#include "bft_printf.h"
#include "fvm_selector.h"
#include "mei_evaluate.h"
#include "cs_base.h"
#include "cs_boundary_zone.h"
#include "cs_equation.h"
#include "cs_equation_param.h"
#include "cs_field.h"
#include "cs_field_pointer.h"
#include "cs_file.h"
#include "cs_log.h"
#include "cs_gui_util.h"
#include "cs_gui_variables.h"
#include "cs_gui_boundary_conditions.h"
#include "cs_gui_specific_physics.h"
#include "cs_gui_mobile_mesh.h"
#include "cs_geom.h"
#include "cs_math.h"
#include "cs_mesh.h"
#include "cs_mesh_quantities.h"
#include "cs_mesh_location.h"
#include "cs_multigrid.h"
#include "cs_order.h"
#include "cs_parall.h"
#include "cs_parameters.h"
#include "cs_partition.h"
#include "cs_physical_model.h"
#include "cs_prototypes.h"
#include "cs_rotation.h"
#include "cs_selector.h"
#include "cs_timer.h"
#include "cs_time_moment.h"
#include "cs_thermal_model.h"
#include "cs_physical_properties.h"
#include "cs_time_step.h"
#include "cs_turbomachinery.h"
#include "cs_sles.h"
#include "cs_sles_it.h"
#include "cs_turbulence_model.h"
#include "cs_wall_functions.h"
#include "cs_physical_constants.h"
#include "cs_stokes_model.h"
#include "cs_balance_by_zone.h"
#include "cs_fan.h"
#include "cs_volume_zone.h"
#include "cs_gwf_physical_properties.h"
/*----------------------------------------------------------------------------
* Header for the current file
*----------------------------------------------------------------------------*/
#include "cs_gui.h"
/*----------------------------------------------------------------------------*/
BEGIN_C_DECLS
/*! \cond DOXYGEN_SHOULD_SKIP_THIS */
/*=============================================================================
* Local Macro Definitions
*============================================================================*/
/* debugging switch */
#define _XML_DEBUG_ 0
/*============================================================================
* Local Structure Definitions
*============================================================================*/
/*============================================================================
* External global variables
*============================================================================*/
/*============================================================================
* Private global variables
*============================================================================*/
/*============================================================================
* Static global variables
*============================================================================*/
/* Pointer on the main variable structure */
cs_var_t *cs_glob_var = NULL;
/*============================================================================
* Static local variables
*============================================================================*/
static char _rij_c_names[6][4] = {"r11", "r22", "r33", "r12", "r23", "r13"};
/*============================================================================
* Private function definitions
*============================================================================*/
/*----------------------------------------------------------------------------
* Remove a node inside a tree.
*
* The node is removed from the tree but not destroyed, so it may be inserted
* in another position.
*
* \param[in, out] tn tree node to remove
*----------------------------------------------------------------------------*/
static void
_tree_node_remove(cs_tree_node_t *tn)
{
if (tn->prev != NULL)
tn->prev->next = tn->next;
if (tn->next != NULL)
tn->next->prev = tn->prev;
if (tn->parent != NULL) {
if (tn->parent->children == tn)
tn->parent->children = tn->next;
}
tn->prev = NULL;
tn->next = NULL;
}
/*-----------------------------------------------------------------------------
* Modify double numerical parameters.
*
* parameters:
* param <-- label of the numerical parameter
* value <-- value of the numerical parameter
*----------------------------------------------------------------------------*/
static void
_numerical_double_parameters(const char *param,
double *value)
{
cs_tree_node_t *tn = NULL;
char *path0 = NULL;
BFT_MALLOC(path0, strlen("numerical_parameters/") + strlen(param) + 1, char);
strcpy(path0, "numerical_parameters/");
strcat(path0, param);
tn = cs_tree_get_node(cs_glob_tree, path0);
BFT_FREE(path0);
/* value not changed if path not found */
cs_gui_node_get_real(tn, value);
}
/*----------------------------------------------------------------------------
* Return the value of the choice attribute for material, method, ...
*
* parameters:
* name <-- name of the property
*----------------------------------------------------------------------------*/
static const char*
_thermal_table_choice(const char *name)
{
cs_tree_node_t *tn
= cs_tree_get_node(cs_glob_tree, "physical_properties/fluid_properties");
tn = cs_tree_node_get_child(tn, name);
const char *choice = cs_tree_node_get_tag(tn, "choice");
return choice;
}
/*----------------------------------------------------------------------------
* Return the value of the choice attribute from a property name.
*
* parameters:
* property_name <-- name of the property
*----------------------------------------------------------------------------*/
static const char*
_properties_choice(const char *property_name)
{
const char *choice = NULL;
cs_tree_node_t *tn
= cs_tree_get_node(cs_glob_tree,
"physical_properties/fluid_properties/property");
tn = cs_tree_node_get_sibling_with_tag(tn, "name", property_name);
choice = cs_tree_node_get_child_value_str(tn, "choice");
return choice;
}
/*----------------------------------------------------------------------------
* Return 0 if default value is needed
*
* parameters:
* name <-- name of the property
*----------------------------------------------------------------------------*/
static int
_thermal_table_needed(const char *name)
{
int choice = 0;
const char *prop_choice = _properties_choice(name);
if (cs_gui_strcmp(prop_choice, "thermal_law"))
choice = 1;
return choice;
}
/*-----------------------------------------------------------------------------
* use MEI for physical property
*----------------------------------------------------------------------------*/
static void
_physical_property(cs_field_t *c_prop,
const cs_zone_t *z)
{
int user_law = 0;
const char *law = NULL;
const char *prop_choice = _properties_choice(c_prop->name);
if (cs_gui_strcmp(prop_choice, "user_law"))
user_law = 1;
if (user_law) {
/* search the formula for the law */
cs_tree_node_t *tn = cs_tree_find_node(cs_glob_tree, "property");
while (tn != NULL) {
const char *name = cs_tree_node_get_child_value_str(tn, "name");
if (cs_gui_strcmp(name, c_prop->name))
break;
else
tn = cs_tree_find_node_next(cs_glob_tree, tn, "property");
}
tn = cs_tree_get_node(tn, "formula");
law = cs_tree_node_get_value_str(tn);
if (law != NULL) {
cs_field_t *fmeg[1] = {c_prop};
cs_meg_volume_function(fmeg, z);
}
}
else if (cs_gui_strcmp(prop_choice, "thermal_law")) {
cs_phys_prop_type_t property = -1;
if (cs_gui_strcmp(c_prop->name, "density"))
property = CS_PHYS_PROP_DENSITY;
else if (cs_gui_strcmp(c_prop->name, "molecular_viscosity"))
property = CS_PHYS_PROP_DYNAMIC_VISCOSITY;
else if (cs_gui_strcmp(c_prop->name, "specific_heat"))
property = CS_PHYS_PROP_ISOBARIC_HEAT_CAPACITY;
else if (cs_gui_strcmp(c_prop->name, "thermal_conductivity"))
property = CS_PHYS_PROP_THERMAL_CONDUCTIVITY;
else
bft_error(__FILE__, __LINE__, 0,
_("Error: can not evaluate property: %s using a thermal law\n"),
c_prop->name);
/* For incompressible flows, the thermodynamic pressure is constant over
* time and is the reference pressure. */
cs_lnum_t thermodynamic_pressure_stride = 0;
cs_lnum_t thermal_f_val_stride = 1;
cs_real_t _p0 = cs_glob_fluid_properties->p0;
cs_real_t _t0 = cs_glob_fluid_properties->t0;
const cs_real_t *thermodynamic_pressure = &_p0;
const cs_real_t *_thermal_f_val = NULL;
if (CS_F_(t) != NULL) {
if (CS_F_(t)->type & CS_FIELD_VARIABLE)
_thermal_f_val = CS_F_(t)->val;
}
else if (CS_F_(h) != NULL) {
if (CS_F_(h)->type & CS_FIELD_VARIABLE)
_thermal_f_val = CS_F_(h)->val;
}
else if (CS_F_(e_tot) != NULL) {
if (CS_F_(h)->type & CS_FIELD_VARIABLE) {
_thermal_f_val = CS_F_(e_tot)->val;
thermodynamic_pressure = CS_F_(p)->val;
thermodynamic_pressure_stride = 1;
}
}
else {
thermal_f_val_stride = 0;
_thermal_f_val = &_t0;
}
const cs_lnum_t ncel = z->n_elts;
cs_phys_prop_compute(property,
ncel,
thermodynamic_pressure_stride,
thermal_f_val_stride,
thermodynamic_pressure,
_thermal_f_val,
c_prop->val);
}
}
/*-----------------------------------------------------------------------------
* Return the value of choice for user scalar's property
*
* parameters:
* f_name <-- field name
* choice <-> choice for property
*----------------------------------------------------------------------------*/
static int
_scalar_properties_choice(const char *f_name,
int *choice)
{
const char *buff = NULL;
int ichoice;
cs_tree_node_t *tn;
for (tn = cs_tree_get_node(cs_glob_tree, "additional_scalars/variable");
tn != NULL;) {
if (!cs_gui_strcmp(f_name, cs_tree_node_get_tag(tn, "name")))
tn = cs_tree_node_get_next_of_name(tn);
else
break;
}
tn = cs_tree_get_node(tn, "property/choice");
buff = cs_tree_node_get_value_str(tn);
if (buff == NULL) {
ichoice = 0;
} else {
ichoice = 1;
if (cs_gui_strcmp(buff, "variable"))
*choice = 1;
else if (cs_gui_strcmp(buff, "constant"))
*choice = 0;
else
bft_error(__FILE__, __LINE__, 0, _("Invalid node in function %s\n"),
__func__);
}
return ichoice;
}
/*-----------------------------------------------------------------------------
* Return value of diffusion coefficient for user scalars
* return 1 if value exists
* return 0 if not
*
* parameters:
* num_sca <-- number of scalar
* value <-- value of diffusion coefficient
*----------------------------------------------------------------------------*/
static void
_scalar_diffusion_value(int num_sca,
cs_real_t *value)
{
cs_tree_node_t *tn
= cs_tree_get_node(cs_glob_tree, "additional_scalars/variable");
for (int i = 1;
tn != NULL && i < num_sca ;
i++) {
tn = cs_tree_node_get_next_of_name(tn);
}
tn = cs_tree_get_node(tn, "property/initial_value");
cs_gui_node_get_real(tn, value);
}
/*-----------------------------------------------------------------------------
* Find the node associated with a given variable.
*
* parameters:
* variable_name <-- name of variable
*
* return:
* pointer to associated tree node (NULL if not present)
*----------------------------------------------------------------------------*/
static cs_tree_node_t *
_find_node_variable(const char *variable_name)
{
cs_tree_node_t *tn = cs_tree_find_node(cs_glob_tree, "variable");
while (tn != NULL) {
const char *name = cs_tree_node_get_child_value_str(tn, "name");
if (cs_gui_strcmp(name, variable_name))
break;
else
tn = cs_tree_find_node_next(cs_glob_tree, tn, "variable");
}
return tn;
}
/*-----------------------------------------------------------------------------
* Return value of turbulent flux model
*
* parameters:
* tn_v <-- tree node associated with variable
* value --> value of turbulent flux model
*----------------------------------------------------------------------------*/
static void
_variable_turbulent_flux_model(cs_tree_node_t *tn_v,
int *value)
{
const char *result
= cs_tree_node_get_child_value_str(tn_v, "turbulent_flux_model");
if (cs_gui_strcmp(result, "SGDH"))
*value = 0;
else if (cs_gui_strcmp(result, "GGDH"))
*value = 10;
else if (cs_gui_strcmp(result, "EB-GGDH"))
*value = 11;
else if (cs_gui_strcmp(result, "AFM"))
*value = 20;
else if (cs_gui_strcmp(result, "EB-AFM"))
*value = 21;
else if (cs_gui_strcmp(result, "DFM"))
*value = 30;
else if (cs_gui_strcmp(result, "EB-DFM"))
*value = 31;
else
*value = 0; /* assign default */
}
/*----------------------------------------------------------------------------
* Get the attribute value from the scheme order
*
* parameters:
* tn_v <-- node assocaited with variable
* keyword --> value of attribute node
*----------------------------------------------------------------------------*/
static void
_order_scheme_value(cs_tree_node_t *tn_v,
int *keyword)
{
cs_tree_node_t *tn = cs_tree_node_get_child(tn_v, "order_scheme");
const char *choice = cs_tree_node_get_child_value_str(tn, "choice");
if (cs_gui_strcmp(choice, "centered"))
*keyword = 1;
else if (cs_gui_strcmp(choice, "solu"))
*keyword = 0;
}
/*----------------------------------------------------------------------------
* Get the attribute value from the cs_tree query.
*
* parameters:
* node <--
* child <-- child markup
* keyword --> value of attribute node
*----------------------------------------------------------------------------*/
static void
_slope_test_value(cs_tree_node_t *tn,
int *keyword)
{
int result = -999;
cs_gui_node_get_child_status_int(tn, "slope_test", &result);
if (result == 1)
*keyword = 0;
if (result == 0)
*keyword = 1;
}
/*----------------------------------------------------------------------------
* Return the attribute choice associated to a child markup from a variable.
*
* parameters:
* tn_v <-- tree node associated with the choice
* child <-- child markup
*----------------------------------------------------------------------------*/
static const char *
_variable_choice(cs_tree_node_t *tn_v,
const char *child)
{
cs_tree_node_t *tn = cs_tree_get_node(tn_v, child);
const char *choice = cs_tree_node_get_child_value_str(tn, "choice");
return choice;
}
/*-----------------------------------------------------------------------------
* Modify integer numerical parameters.
*
* parameters:
* param <-- label of the numerical parameter
* keyword <-- value of the numerical parameter
*----------------------------------------------------------------------------*/
static void
_numerical_int_parameters(const char *param,
int *keyword)
{
int choice = *keyword;
int result = *keyword;
cs_tree_node_t *tn = cs_tree_get_node(cs_glob_tree, "numerical_parameters");
if (cs_gui_strcmp(param, "gradient_reconstruction")) {
tn = cs_tree_get_node(tn, param);
tn = cs_tree_get_node(tn, "choice");
cs_gui_node_get_int(tn, &choice);
*keyword = choice;
} else if (cs_gui_strcmp(param,"piso_sweep_number")) {
tn = cs_tree_get_node(tn, "velocity_pressure_algo");
tn = cs_tree_get_node(tn, param);
cs_gui_node_get_int(tn, &result);
*keyword = result;
} else {
tn = cs_tree_get_node(tn, param);
cs_gui_node_get_status_int(tn, &result);
*keyword = result;
}
}
/*-----------------------------------------------------------------------------
* Modify gravity parameters.
*
* parameters:
* param <-- gravity parameter (GX, GY, GZ)
* keyword <<-- new value of the gravity parameter
*----------------------------------------------------------------------------*/
static void
_gravity_value(const char *param,
double *value)
{
cs_tree_node_t *tn
= cs_tree_get_node(cs_glob_tree, "physical_properties/gravity");
tn = cs_tree_get_node(tn, param);
cs_gui_node_get_real(tn, value);
}
/*-----------------------------------------------------------------------------
* Modify coriolis source terms parameters.
*
* parameters:
* param <-- coriolis parameter (omegax, omegay, omegaz)
* value --> new value of the coriolis parameter
*----------------------------------------------------------------------------*/
static void
_coriolis_value(const char *param,
double *value)
{
cs_tree_node_t *tn
= cs_tree_get_node(cs_glob_tree, "physical_properties/omega");
tn = cs_tree_get_node(tn, param);
cs_gui_node_get_real(tn, value);
}
/*----------------------------------------------------------------------------
* Get the value of the choice attribute from a property markup.
* Return 1 if the cs_tree request has succeeded, 0 otherwise.
*
* parameters:
* property_name <-- name of the property
* choice --> value of the attribute choice
*----------------------------------------------------------------------------*/
static int
_properties_choice_id(const char *property_name,
int *choice)
{
const char *buff = NULL;
int iok = 0;
buff = _properties_choice(property_name);
*choice = 0; /* default */
if (buff)
{
iok = 1;
if (cs_gui_strcmp(buff, "user_law") ||
cs_gui_strcmp(buff, "predefined_law") ||
cs_gui_strcmp(buff, "thermal_law") )
*choice = 1;
else if (cs_gui_strcmp(buff, "constant"))
*choice = 0;
}
else
iok = 0;
return iok;
}
/*----------------------------------------------------------------------------
* Return the length choice for initialize turbulence
*----------------------------------------------------------------------------*/
static const char *
_reference_length_initialization_choice(void)
{
cs_tree_node_t *tn
= cs_tree_get_node(cs_glob_tree,
"thermophysical_models/turbulence/"
"reference_length/choice");
const char *initialization_choice
= cs_tree_node_get_value_str(tn);
return initialization_choice;
}
/*----------------------------------------------------------------------------
* Return the initialization choice of the turbulence variables.
*
* parameters:
* zone_id <-- zone number
*----------------------------------------------------------------------------*/
static const char *
_turbulence_initialization_choice(const char* zone_id)
{
cs_tree_node_t *tn
= cs_tree_get_node(cs_glob_tree,
"thermophysical_models/turbulence/initialization");
tn = cs_tree_node_get_sibling_with_tag(tn, "zone_id", zone_id);
tn = cs_tree_get_node(tn, "choice");
const char *initialization_choice
= cs_tree_node_get_value_str(tn);
return initialization_choice;
}
/*==========================
* FOR VOLUMIC ZONES
*==========================*/
/*----------------------------------------------------------------------------
* Check if a given zone type attribute is active
*
* parameters:
* z_id <-- zone id
* attr <-- attribute checked for
*
* return:
* true if attribute checked for is active, false otherwise
*----------------------------------------------------------------------------*/
static bool
_zone_id_is_type(int z_id,
const char *attr)
{
bool retval = false;
const char *status = NULL;
cs_tree_node_t *tn
= cs_tree_get_node(cs_glob_tree, "solution_domain/volumic_conditions/zone");
for (int i = 1; tn != NULL && i < z_id; i++) {
tn = cs_tree_node_get_next_of_name(tn);
}
tn = cs_tree_get_node(tn, attr);
status = cs_tree_node_get_value_str(tn);
if (status != NULL) {
if (cs_gui_strcmp(status, "on"))
retval = true;
}
return retval;
}
/*----------------------------------------------------------------------------
* Indicate if a given zone type attribute is active
*
* parameters:
* tn <-- tree node associated with the zone variable
* type_str <-- string describing the type
*----------------------------------------------------------------------------*/
static bool
_zone_is_type(cs_tree_node_t *tn,
const char *type_str)
{
bool retval = false;
const char *type_s = cs_tree_node_get_tag(tn, type_str);
if (type_s != NULL) {
if (strcmp(type_s, "on") == 0)
retval = true;
}
return retval;
}
/*----------------------------------------------------------------------------
* Add a test attribute to an cs_tree query for a given zone id.
*
* This should dissapear in the future, when zone names replace ids
* in the XML file.
*
* Note that ids in the zone model are 0-based, while those in the XML
* are 1-based. The shift is handled by adding a default zone in
* the base model.
*
* parameters:
* tn <-- parent tree node
* z_id <-- zone id (O-based)
*
* return:
* sibling node matching attribute
*----------------------------------------------------------------------------*/
static cs_tree_node_t *
_add_zone_id_test_attribute(cs_tree_node_t *tn,
int z_id)
{
char z_id_str[32];
snprintf(z_id_str, 31, "%d", z_id);
return cs_tree_node_get_sibling_with_tag(tn, "zone_id", z_id_str);
}
/*----------------------------------------------------------------------------
* Return the component of variables or properties or scalar for 1D profile
*
* parameters:
* tn <-- tree node associated with profile variable
*----------------------------------------------------------------------------*/
static int
_get_profile_v_component(cs_tree_node_t *tn)
{
int comp_id = -1;
const char *c_name = cs_tree_node_get_tag(tn, "component");
if (c_name != NULL) {
int n = sscanf(c_name, "%d", &comp_id);
if (n != 1)
bft_error(__FILE__, __LINE__, 0,
_("Error converting profile component tag %s to integer."),
c_name);
}
return comp_id;
}
/*----------------------------------------------------------------------------
* Return associated field for a node referring to a field.
*
* A node referring to a field must have a "name" tag (i.e. child with a
* string value).
*
* In the case of NEPTUNE_CFD, an additional "field_id" tag requiring
* addition of the "_<field_id>" extension to match the field's name
* may be present, so this is tested also.
*
* parameters:
* tn <-- tree node associated with profile variable
* name <-- value of node's "name" tag (already determined)
*
* return:
* pointer to field if match, NULL otherwise
*----------------------------------------------------------------------------*/
static const cs_field_t *
_tree_node_get_field(cs_tree_node_t *tn)
{
const cs_field_t *f = NULL;
const char *name = cs_gui_node_get_tag(tn, "name");
const char *id_name = cs_tree_node_get_tag(tn, "field_id");
/* Handle phase id (field_id tag in xml) for NEPTUNE_CFD */
if (id_name != NULL) {
if (strcmp(id_name, "none") != 0) {
char buffer[128];
snprintf(buffer, 127, "%s_%s", name, id_name);
buffer[127] = '\0';
if (strlen(buffer) >= 127)
bft_error(__FILE__, __LINE__, 0,
"Local buffer too small to assemble field name with:\n"
"name: %s\n"
"field_id: %s\n", name, id_name);
f = cs_field_by_name_try(buffer);
}
}
/* Handle segregated Reynolds tensor solver */
const cs_turb_rans_model_t *rans_model = cs_glob_turb_rans_model;
if (f == NULL && rans_model != NULL) {
if (rans_model->irijco == 0 && strcmp(name, "rij") == 0) {
int idim = _get_profile_v_component(tn);
f = cs_field_by_name_try(_rij_c_names[idim]);
}
}
/* General case */
if (f == NULL)
f = cs_field_by_name_try(name);
if (f == NULL)
bft_error(__FILE__, __LINE__, 0,
_("Field with name \"%s\" not found"), name);
return f;
}
/*----------------------------------------------------------------------------
* Return the label of variables or properties or scalar for 1D profile
*
* parameters:
* tn_vp <-- tree node associated with profile variable
*----------------------------------------------------------------------------*/
static void
_write_profile_v_label_name(cs_tree_node_t *tn_vp,
FILE *file,
int opf)
{
char *label = NULL;
const cs_field_t *f = _tree_node_get_field(tn_vp);
int idim = _get_profile_v_component(tn_vp);
if (f != NULL) {
const char *f_label = cs_field_get_label(f);
char buf[16] = "";
size_t buf_len = 0;
if(f->dim == 3)
buf_len = 3;
else if (f->dim > 3)
buf_len = 4;
size_t len = strlen(f_label) + buf_len;
BFT_MALLOC(label, len+1, char);
if (f->dim > 1) {
int s_id = 0;
int e_id = f->dim;
if (idim > -1) {
s_id = idim;
e_id = s_id+1;
}
switch(f->dim) {
case 3:
for (int ldim = s_id; ldim < e_id; ldim ++) {
strncpy(buf, cs_glob_field_comp_name_3[ldim], 15);
sprintf(label, "%s%s", f_label, buf);
if (opf == 0)
fprintf(file, " | %s", label);
else
fprintf(file, ", %s", label);
}
break;
case 6:
for (int ldim = s_id ; ldim < e_id ; ldim ++) {
strncpy(buf, cs_glob_field_comp_name_6[ldim], 15);
sprintf(label, "%s%s", f_label, buf);
if (opf == 0)
fprintf(file, " | %s", label);
else
fprintf(file, ", %s", label);
}
break;
case 9:
for (int ldim = s_id ; ldim < e_id ; ldim ++) {
strncpy(buf, cs_glob_field_comp_name_9[ldim], 15);
sprintf(label, "%s%s", f_label, buf);
if (opf == 0)
fprintf(file, " | %s", label);
else
fprintf(file, ", %s", label);
}
break;
default:
snprintf(buf, 15, "[%d]", idim); buf[15] = '\0';
}
}
/*Dimension 1*/
else {
sprintf(label, "%s%s", f_label, buf);
if (opf == 0)
fprintf(file, " | %s", label);
else
fprintf(file, ", %s", label);
}
}
}
/*----------------------------------------------------------------------------
* Return a string value associated with a child node for a profile.
*
* If the matching child node is not present, an error is produced
*
* parameters:
* tn <-- tree node associated with profile
*
* return:
* pointer to matching child string
*----------------------------------------------------------------------------*/
static const char *
_get_profile_child_str(cs_tree_node_t *tn,
const char *child_name)
{
const char *name = cs_tree_node_get_child_value_str(tn, child_name);
if (name == NULL) {
cs_base_warn(__FILE__, __LINE__);
bft_printf(_("Incorrect setup tree definition for the following node:\n"));
cs_tree_dump(CS_LOG_DEFAULT, 2, tn);
bft_error(__FILE__, __LINE__, 0,
_("Missing child node: %s"), child_name);
}
return name;
}
/*----------------------------------------------------------------------------
* Return an array of integers associated with a child node for a profile.
*
* If the matching child node is not present, an error is produced
*
* parameters:
* tn <-- tree node associated with profile
*
* return:
* pointer to matching child values
*----------------------------------------------------------------------------*/