1
/*============================================================================
2
* Management of the GUI parameters file: mesh related options
3
*============================================================================*/
6
This file is part of Code_Saturne, a general-purpose CFD tool.
8
Copyright (C) 1998-2011 EDF S.A.
10
This program is free software; you can redistribute it and/or modify it under
11
the terms of the GNU General Public License as published by the Free Software
12
Foundation; either version 2 of the License, or (at your option) any later
15
This program is distributed in the hope that it will be useful, but WITHOUT
16
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20
You should have received a copy of the GNU General Public License along with
21
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22
Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
/*----------------------------------------------------------------------------*/
27
#if defined(HAVE_CONFIG_H)
28
#include "cs_config.h"
31
/*----------------------------------------------------------------------------
32
* Standard C library headers
33
*----------------------------------------------------------------------------*/
43
/*----------------------------------------------------------------------------
45
*----------------------------------------------------------------------------*/
48
#include <bft_error.h>
49
#include <bft_printf.h>
51
/*----------------------------------------------------------------------------
53
*----------------------------------------------------------------------------*/
55
/*----------------------------------------------------------------------------
57
*----------------------------------------------------------------------------*/
59
/*----------------------------------------------------------------------------
61
*----------------------------------------------------------------------------*/
64
#include "cs_gui_util.h"
65
#include "cs_gui_variables.h"
66
#include "cs_gui_boundary_conditions.h"
68
#include "cs_join_perio.h"
70
#include "cs_mesh_warping.h"
71
#include "cs_prototypes.h"
73
/*----------------------------------------------------------------------------
74
* Header for the current file
75
*----------------------------------------------------------------------------*/
77
#include "cs_gui_mesh.h"
79
/*----------------------------------------------------------------------------*/
83
/*=============================================================================
84
* Local Macro Definitions
85
*============================================================================*/
87
/* debugging switch */
90
/*============================================================================
91
* Private function definitions
92
*============================================================================*/
94
/*-----------------------------------------------------------------------------
95
* Return the value to a face joining markup
98
* keyword <-- label of the markup
99
* number <-- joining number
100
*----------------------------------------------------------------------------*/
103
_get_face_joining(const char *keyword,
107
char *path = cs_xpath_init_path();
108
cs_xpath_add_elements(&path, 2, "solution_domain", "joining");
109
cs_xpath_add_element_num(&path, "face_joining", number);
110
cs_xpath_add_element(&path, keyword);
111
cs_xpath_add_function_text(&path);
112
value = cs_gui_get_text_value(path);
117
/*-----------------------------------------------------------------------------
118
* Return the value to a face periodicity markup
121
* keyword <-- label of the markup
122
* number <-- joining number
123
*----------------------------------------------------------------------------*/
126
_get_periodicity(const char *keyword,
130
char *path = cs_xpath_init_path();
131
cs_xpath_add_elements(&path, 2, "solution_domain", "periodicity");
132
cs_xpath_add_element_num(&path, "face_periodicity", number);
133
cs_xpath_add_element(&path, keyword);
134
cs_xpath_add_function_text(&path);
135
value = cs_gui_get_text_value(path);
140
/*-----------------------------------------------------------------------------
141
* Get transformation parameters associated with a translational periodicity
144
* number <-- number of the syrthes coupling
145
* trans --> translation values
146
*----------------------------------------------------------------------------*/
149
_get_periodicity_translation(int number,
153
char *path = cs_xpath_init_path();
154
cs_xpath_add_elements(&path, 2, "solution_domain", "periodicity");
155
cs_xpath_add_element_num(&path, "face_periodicity", number);
156
cs_xpath_add_elements(&path, 2, "translation", "translation_x");
157
dir_id = strlen(path) - 1;
158
cs_xpath_add_function_text(&path);
160
if (!cs_gui_get_double(path, trans + 0))
164
if (!cs_gui_get_double(path, trans + 1))
168
if (!cs_gui_get_double(path, trans + 2))
174
bft_printf("==> _get_periodicity_translation\n");
175
bft_printf("--translation = [%f %f %f]\n",
176
trans[0], trans[1], trans[2]);
182
/*-----------------------------------------------------------------------------
183
* Get transformation parameters associated with a rotational periodicity
186
* number <-- number of the syrthes coupling
187
* angle --> rotation angle
188
* axis --> rotation axis
189
* invariant --> invariant point
190
*----------------------------------------------------------------------------*/
193
_get_periodicity_rotation(int number,
200
char *path_0 = cs_xpath_init_path();
201
cs_xpath_add_elements(&path_0, 2, "solution_domain", "periodicity");
202
cs_xpath_add_element_num(&path_0, "face_periodicity", number);
203
cs_xpath_add_element(&path_0, "rotation");
205
BFT_MALLOC(path, strlen(path_0) + 1, char);
206
strcpy(path, path_0);
210
cs_xpath_add_element(&path, "angle");
211
cs_xpath_add_function_text(&path);
212
if (!cs_gui_get_double(path, angle))
217
strcpy(path, path_0);
218
cs_xpath_add_element(&path, "axis_x");
219
coo_id = strlen(path) - 1;
220
cs_xpath_add_function_text(&path);
222
if (!cs_gui_get_double(path, axis + 0))
226
if (!cs_gui_get_double(path, axis + 1))
230
if (!cs_gui_get_double(path, axis + 2))
235
strcpy(path, path_0);
236
cs_xpath_add_element(&path, "invariant_x");
237
coo_id = strlen(path) - 1;
238
cs_xpath_add_function_text(&path);
240
if (!cs_gui_get_double(path, invariant + 0))
244
if (!cs_gui_get_double(path, invariant + 1))
248
if (!cs_gui_get_double(path, invariant + 2))
255
bft_printf("==> _get_periodicity_translation\n");
256
bft_printf("--angle = %f\n",
258
bft_printf("--axis = [%f %f %f]\n",
259
axis[0], axis[1], axis[2]);
260
bft_printf("--invariant = [%f %f %f]\n",
261
invariant[0], invariant[1], invariant[2]);
267
/*-----------------------------------------------------------------------------
268
* Get transformation parameters associated with a mixed periodicity
271
* number <-- number of the syrthes coupling
272
* matrix --> translation values (m11, m12, m13, m14, ..., m33, m34)
273
*----------------------------------------------------------------------------*/
276
_get_periodicity_mixed(int number,
281
char *path = cs_xpath_init_path();
282
const char id_str[] = {'1', '2', '3','4'};
284
cs_xpath_add_elements(&path, 2, "solution_domain", "periodicity");
285
cs_xpath_add_element_num(&path, "face_periodicity", number);
286
cs_xpath_add_elements(&path, 2, "mixed", "matrix_11");
287
coeff_id = strlen(path) - 2;
288
cs_xpath_add_function_text(&path);
290
for (i = 0; i < 3; i++) {
291
path[coeff_id] = id_str[i];
293
for (j = 0; j < 4; j++) {
294
path[coeff_id + 1] = id_str[j];
296
if (!cs_gui_get_double(path, &(matrix[i][j]))) {
308
bft_printf("==> _get_periodicity_translation\n");
309
bft_printf("--matrix = [[%f %f %f %f]\n"
312
matrix[0][0], matrix[0][1] ,matrix[0][2], matrix[0][3],
313
matrix[1][0], matrix[1][1] ,matrix[1][2], matrix[1][3],
314
matrix[2][0], matrix[2][1] ,matrix[2][2], matrix[2][3]);
320
/*============================================================================
321
* Public Fortran function definitions
322
*============================================================================*/
324
/*-----------------------------------------------------------------------------
325
* Determine whether warped faces should be cut.
329
*----------------------------------------------------------------------------*/
331
void CS_PROCF (uicwf, UICWF) (void)
334
int cut_warped_faces = 0;
335
double max_warp_angle = -1;
337
path = cs_xpath_init_path();
338
cs_xpath_add_elements(&path, 2, "solution_domain", "faces_cutting");
339
cs_xpath_add_attribute(&path, "status");
341
cs_gui_get_status(path, &cut_warped_faces);
343
if (cut_warped_faces) {
347
path = cs_xpath_init_path();
348
cs_xpath_add_elements(&path, 3,
352
cs_xpath_add_function_text(&path);
354
if (!cs_gui_get_double(path, &max_warp_angle))
358
bft_printf("==> uicwf\n");
359
bft_printf("--cut_warped_faces = %d\n"
360
"--warp_angle_max = %f\n",
361
cut_warped_faces, max_warp_angle);
368
/* Apply warp angle options now */
370
if (cut_warped_faces && max_warp_angle > 0.0)
371
cs_mesh_warping_set_defaults(max_warp_angle, 0);
374
/*============================================================================
375
* Public function definitions
376
*============================================================================*/
378
/*-----------------------------------------------------------------------------
379
* Define joinings using a GUI-produced XML file.
380
*----------------------------------------------------------------------------*/
383
cs_gui_mesh_define_joinings(void)
388
if (!cs_gui_file_is_loaded())
391
n_join = cs_gui_get_tag_number("/solution_domain/joining/face_joining", 1);
396
for (join_id = 0; join_id < n_join; join_id++) {
398
char *selector_s = _get_face_joining("selector", join_id+1);
399
char *fraction_s = _get_face_joining("fraction", join_id+1);
400
char *plane_s = _get_face_joining("plane", join_id+1);
401
char *verbosity_s = _get_face_joining("verbosity", join_id+1);
402
char *visu_s = _get_face_joining("visualization", join_id+1);
404
double fraction = (fraction_s != NULL) ? atof(fraction_s) : 0.1;
405
double plane = (plane_s != NULL) ? atof(plane_s) : 25.0;
406
int verbosity = (verbosity_s != NULL) ? atoi(verbosity_s) : 1;
407
int visualization = (visu_s != NULL) ? atoi(visu_s) : 1;
409
cs_join_add(selector_s,
416
bft_printf("==> cs_gui_mesh_define_joinings\n");
417
bft_printf("--selector = %s\n", selector_s);
418
bft_printf("--fraction = %s\n", fraction_s);
419
bft_printf("--plane = %s\n", plane_s);
420
bft_printf("--verbosity = %s\n", verbosity_s);
421
bft_printf("--visualization = %s\n", visu_s);
424
BFT_FREE(selector_s);
425
BFT_FREE(fraction_s);
431
/*-----------------------------------------------------------------------------
432
* Define periodicities using a GUI-produced XML file.
433
*----------------------------------------------------------------------------*/
436
cs_gui_mesh_define_periodicities(void)
439
double angle, trans[3], axis[3], invariant[3], matrix[3][4];
446
if (!cs_gui_file_is_loaded())
450
= cs_gui_get_tag_number("/solution_domain/periodicity/face_periodicity",
455
/* Get modes associated with each periodicity */
457
path = cs_xpath_init_path();
458
cs_xpath_add_elements(&path, 3,
460
"periodicity", "face_periodicity");
461
cs_xpath_add_attribute(&path, "mode");
462
modes = cs_gui_get_attribute_values(path, &n_modes);
464
if (n_modes != n_perio)
465
bft_error(__FILE__, __LINE__, 0,
466
_("Number of periodicities (%d) and modes (%) do not match."),
471
/* loop on periodicities */
473
for (perio_id = 0; perio_id < n_perio; perio_id++) {
475
char *selector_s = _get_periodicity("selector", perio_id+1);
476
char *fraction_s = _get_periodicity("fraction", perio_id+1);
477
char *plane_s = _get_periodicity("plane", perio_id+1);
478
char *verbosity_s = _get_periodicity("verbosity", perio_id+1);
479
char *visu_s = _get_periodicity("visualization", perio_id+1);
481
double fraction = (fraction_s != NULL) ? atof(fraction_s) : 0.1;
482
double plane = (plane_s != NULL) ? atof(plane_s) : 25.0;
483
int verbosity = (verbosity_s != NULL) ? atoi(verbosity_s) : 1;
484
int visualization = (visu_s != NULL) ? atoi(visu_s) : 1;
486
if (!strcmp(modes[perio_id], "translation")) {
487
_get_periodicity_translation(perio_id+1, trans);
488
cs_join_perio_add_translation(selector_s,
496
else if (!strcmp(modes[perio_id], "rotation")) {
497
_get_periodicity_rotation(perio_id+1, &angle, axis, invariant);
498
cs_join_perio_add_rotation(selector_s,
508
else if (!strcmp(modes[perio_id], "mixed")) {
509
_get_periodicity_mixed(perio_id+1, matrix);
510
cs_join_perio_add_mixed(selector_s,
519
bft_error(__FILE__, __LINE__, 0,
520
_("Periodicity mode \"%s\" unknown."), modes[perio_id]);
523
bft_printf("==> cs_gui_mesh_define_periodicities\n");
524
bft_printf("--selector = %s\n", selector_s);
525
bft_printf("--fraction = %s\n", fraction_s);
526
bft_printf("--plane = %s\n", plane_s);
527
bft_printf("--verbosity = %s\n", verbosity_s);
528
bft_printf("--visualization = %s\n", visu_s);
531
BFT_FREE(selector_s);
532
BFT_FREE(fraction_s);
534
BFT_FREE(verbosity_s);
538
for (perio_id = 0; perio_id < n_perio; perio_id++)
539
BFT_FREE(modes[perio_id]);
543
/*----------------------------------------------------------------------------*/