~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to src/gui/cs_gui_mesh.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-01 17:43:32 UTC
  • mto: (6.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20111101174332-tl4vk45no0x3emc3
Tags: upstream-2.1.0
ImportĀ upstreamĀ versionĀ 2.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*============================================================================
 
2
 * Management of the GUI parameters file: mesh related options
 
3
 *============================================================================*/
 
4
 
 
5
/*
 
6
  This file is part of Code_Saturne, a general-purpose CFD tool.
 
7
 
 
8
  Copyright (C) 1998-2011 EDF S.A.
 
9
 
 
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
 
13
  version.
 
14
 
 
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
 
18
  details.
 
19
 
 
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.
 
23
*/
 
24
 
 
25
/*----------------------------------------------------------------------------*/
 
26
 
 
27
#if defined(HAVE_CONFIG_H)
 
28
#include "cs_config.h"
 
29
#endif
 
30
 
 
31
/*----------------------------------------------------------------------------
 
32
 * Standard C library headers
 
33
 *----------------------------------------------------------------------------*/
 
34
 
 
35
#include <stdio.h>
 
36
#include <stdlib.h>
 
37
#include <math.h>
 
38
#include <string.h>
 
39
#include <fcntl.h>
 
40
#include <unistd.h>
 
41
#include <assert.h>
 
42
 
 
43
/*----------------------------------------------------------------------------
 
44
 * BFT library headers
 
45
 *----------------------------------------------------------------------------*/
 
46
 
 
47
#include <bft_mem.h>
 
48
#include <bft_error.h>
 
49
#include <bft_printf.h>
 
50
 
 
51
/*----------------------------------------------------------------------------
 
52
 * FVM library headers
 
53
 *----------------------------------------------------------------------------*/
 
54
 
 
55
/*----------------------------------------------------------------------------
 
56
 * MEI library headers
 
57
 *----------------------------------------------------------------------------*/
 
58
 
 
59
/*----------------------------------------------------------------------------
 
60
 * Local headers
 
61
 *----------------------------------------------------------------------------*/
 
62
 
 
63
#include "cs_base.h"
 
64
#include "cs_gui_util.h"
 
65
#include "cs_gui_variables.h"
 
66
#include "cs_gui_boundary_conditions.h"
 
67
#include "cs_join.h"
 
68
#include "cs_join_perio.h"
 
69
#include "cs_mesh.h"
 
70
#include "cs_mesh_warping.h"
 
71
#include "cs_prototypes.h"
 
72
 
 
73
/*----------------------------------------------------------------------------
 
74
 * Header for the current file
 
75
 *----------------------------------------------------------------------------*/
 
76
 
 
77
#include "cs_gui_mesh.h"
 
78
 
 
79
/*----------------------------------------------------------------------------*/
 
80
 
 
81
BEGIN_C_DECLS
 
82
 
 
83
/*=============================================================================
 
84
 * Local Macro Definitions
 
85
 *============================================================================*/
 
86
 
 
87
/* debugging switch */
 
88
#define _XML_DEBUG_ 0
 
89
 
 
90
/*============================================================================
 
91
 * Private function definitions
 
92
 *============================================================================*/
 
93
 
 
94
/*-----------------------------------------------------------------------------
 
95
 * Return the value to a face joining markup
 
96
 *
 
97
 * parameters:
 
98
 *   keyword <-- label of the markup
 
99
 *   number  <-- joining number
 
100
 *----------------------------------------------------------------------------*/
 
101
 
 
102
static char *
 
103
_get_face_joining(const char  *keyword,
 
104
                  int          number)
 
105
{
 
106
  char* value = NULL;
 
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);
 
113
  BFT_FREE(path);
 
114
  return value;
 
115
}
 
116
 
 
117
/*-----------------------------------------------------------------------------
 
118
 * Return the value to a face periodicity markup
 
119
 *
 
120
 * parameters:
 
121
 *   keyword <-- label of the markup
 
122
 *   number  <-- joining number
 
123
 *----------------------------------------------------------------------------*/
 
124
 
 
125
static char *
 
126
_get_periodicity(const char  *keyword,
 
127
                 int          number)
 
128
{
 
129
  char* value = NULL;
 
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);
 
136
  BFT_FREE(path);
 
137
  return value;
 
138
}
 
139
 
 
140
/*-----------------------------------------------------------------------------
 
141
 * Get transformation parameters associated with a translational periodicity
 
142
 *
 
143
 * parameter:
 
144
 *   number <-- number of the syrthes coupling
 
145
 *   trans  --> translation values
 
146
 *----------------------------------------------------------------------------*/
 
147
 
 
148
static void
 
149
_get_periodicity_translation(int     number,
 
150
                             double  trans[3])
 
151
{
 
152
  size_t dir_id = 0;
 
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);
 
159
 
 
160
  if (!cs_gui_get_double(path, trans + 0))
 
161
    trans[0] = 0.0;
 
162
 
 
163
  path[dir_id] = 'y';
 
164
  if (!cs_gui_get_double(path, trans + 1))
 
165
    trans[1] = 0.0;
 
166
 
 
167
  path[dir_id] = 'z';
 
168
  if (!cs_gui_get_double(path, trans + 2))
 
169
    trans[2] = 0.0;
 
170
 
 
171
  BFT_FREE(path);
 
172
 
 
173
#if _XML_DEBUG_
 
174
  bft_printf("==> _get_periodicity_translation\n");
 
175
  bft_printf("--translation = [%f %f %f]\n",
 
176
             trans[0], trans[1], trans[2]);
 
177
#endif
 
178
 
 
179
  return;
 
180
}
 
181
 
 
182
/*-----------------------------------------------------------------------------
 
183
 * Get transformation parameters associated with a rotational periodicity
 
184
 *
 
185
 * parameter:
 
186
 *   number    <-- number of the syrthes coupling
 
187
 *   angle     --> rotation angle
 
188
 *   axis      --> rotation axis
 
189
 *   invariant --> invariant point
 
190
 *----------------------------------------------------------------------------*/
 
191
 
 
192
static void
 
193
_get_periodicity_rotation(int      number,
 
194
                          double  *angle,
 
195
                          double   axis[3],
 
196
                          double   invariant[3])
 
197
{
 
198
  size_t coo_id = 0;
 
199
  char *path = NULL;
 
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");
 
204
 
 
205
  BFT_MALLOC(path, strlen(path_0) + 1, char);
 
206
  strcpy(path, path_0);
 
207
 
 
208
  /* Angle */
 
209
 
 
210
  cs_xpath_add_element(&path, "angle");
 
211
  cs_xpath_add_function_text(&path);
 
212
  if (!cs_gui_get_double(path, angle))
 
213
    *angle = 0.0;
 
214
 
 
215
  /* Axis */
 
216
 
 
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);
 
221
 
 
222
  if (!cs_gui_get_double(path, axis + 0))
 
223
    axis[0] = 0.0;
 
224
 
 
225
  path[coo_id] = 'y';
 
226
  if (!cs_gui_get_double(path, axis + 1))
 
227
    axis[1] = 0.0;
 
228
 
 
229
  path[coo_id] = 'z';
 
230
  if (!cs_gui_get_double(path, axis + 2))
 
231
    axis[2] = 0.0;
 
232
 
 
233
  /* Invariant */
 
234
 
 
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);
 
239
 
 
240
  if (!cs_gui_get_double(path, invariant + 0))
 
241
    invariant[0] = 0.0;
 
242
 
 
243
  path[coo_id] = 'y';
 
244
  if (!cs_gui_get_double(path, invariant + 1))
 
245
    invariant[1] = 0.0;
 
246
 
 
247
  path[coo_id] = 'z';
 
248
  if (!cs_gui_get_double(path, invariant + 2))
 
249
    invariant[2] = 0.0;
 
250
 
 
251
  BFT_FREE(path);
 
252
  BFT_FREE(path_0);
 
253
 
 
254
#if _XML_DEBUG_
 
255
  bft_printf("==> _get_periodicity_translation\n");
 
256
  bft_printf("--angle = %f\n",
 
257
             *angle);
 
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]);
 
262
#endif
 
263
 
 
264
  return;
 
265
}
 
266
 
 
267
/*-----------------------------------------------------------------------------
 
268
 * Get transformation parameters associated with a mixed periodicity
 
269
 *
 
270
 * parameter:
 
271
 *   number <-- number of the syrthes coupling
 
272
 *   matrix --> translation values (m11, m12, m13, m14, ..., m33, m34)
 
273
 *----------------------------------------------------------------------------*/
 
274
 
 
275
static void
 
276
_get_periodicity_mixed(int     number,
 
277
                       double  matrix[3][4])
 
278
{
 
279
  int i, j;
 
280
  size_t coeff_id = 0;
 
281
  char *path = cs_xpath_init_path();
 
282
  const char id_str[] = {'1', '2', '3','4'};
 
283
 
 
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);
 
289
 
 
290
  for (i = 0; i < 3; i++) {
 
291
    path[coeff_id] = id_str[i];
 
292
 
 
293
    for (j = 0; j < 4; j++) {
 
294
      path[coeff_id + 1] = id_str[j];
 
295
 
 
296
      if (!cs_gui_get_double(path, &(matrix[i][j]))) {
 
297
        if (i != j)
 
298
          matrix[i][j] = 0.0;
 
299
        else
 
300
          matrix[i][j] = 1.0;
 
301
      }
 
302
    }
 
303
  }
 
304
 
 
305
  BFT_FREE(path);
 
306
 
 
307
#if _XML_DEBUG_
 
308
  bft_printf("==> _get_periodicity_translation\n");
 
309
  bft_printf("--matrix = [[%f %f %f %f]\n"
 
310
             "            [%f %f %f %f]\n"
 
311
             "            [%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]);
 
315
#endif
 
316
 
 
317
  return;
 
318
}
 
319
 
 
320
/*============================================================================
 
321
 * Public Fortran function definitions
 
322
 *============================================================================*/
 
323
 
 
324
/*-----------------------------------------------------------------------------
 
325
 * Determine whether warped faces should be cut.
 
326
 *
 
327
 * subroutine uicwf
 
328
 * *****************
 
329
 *----------------------------------------------------------------------------*/
 
330
 
 
331
void CS_PROCF (uicwf, UICWF) (void)
 
332
{
 
333
  char  *path = NULL;
 
334
  int cut_warped_faces = 0;
 
335
  double max_warp_angle = -1;
 
336
 
 
337
  path = cs_xpath_init_path();
 
338
  cs_xpath_add_elements(&path, 2, "solution_domain", "faces_cutting");
 
339
  cs_xpath_add_attribute(&path, "status");
 
340
 
 
341
  cs_gui_get_status(path, &cut_warped_faces);
 
342
 
 
343
  if (cut_warped_faces) {
 
344
 
 
345
    BFT_FREE(path);
 
346
 
 
347
    path = cs_xpath_init_path();
 
348
    cs_xpath_add_elements(&path, 3,
 
349
                          "solution_domain",
 
350
                          "faces_cutting",
 
351
                          "warp_angle_max");
 
352
    cs_xpath_add_function_text(&path);
 
353
 
 
354
    if (!cs_gui_get_double(path, &max_warp_angle))
 
355
      max_warp_angle = -1;
 
356
 
 
357
#if _XML_DEBUG_
 
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);
 
362
#endif
 
363
 
 
364
  }
 
365
 
 
366
  BFT_FREE(path);
 
367
 
 
368
  /* Apply warp angle options now */
 
369
 
 
370
  if (cut_warped_faces && max_warp_angle > 0.0)
 
371
    cs_mesh_warping_set_defaults(max_warp_angle, 0);
 
372
}
 
373
 
 
374
/*============================================================================
 
375
 * Public function definitions
 
376
 *============================================================================*/
 
377
 
 
378
/*-----------------------------------------------------------------------------
 
379
 * Define joinings using a GUI-produced XML file.
 
380
 *----------------------------------------------------------------------------*/
 
381
 
 
382
void
 
383
cs_gui_mesh_define_joinings(void)
 
384
{
 
385
  int join_id;
 
386
  int n_join = 0;
 
387
 
 
388
  if (!cs_gui_file_is_loaded())
 
389
    return;
 
390
 
 
391
  n_join = cs_gui_get_tag_number("/solution_domain/joining/face_joining", 1);
 
392
 
 
393
  if (n_join == 0)
 
394
    return;
 
395
 
 
396
  for (join_id = 0; join_id < n_join; join_id++) {
 
397
 
 
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);
 
403
 
 
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;
 
408
 
 
409
    cs_join_add(selector_s,
 
410
                fraction,
 
411
                plane,
 
412
                verbosity,
 
413
                visualization);
 
414
 
 
415
#if _XML_DEBUG_
 
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);
 
422
#endif
 
423
 
 
424
    BFT_FREE(selector_s);
 
425
    BFT_FREE(fraction_s);
 
426
    BFT_FREE(plane_s);
 
427
    BFT_FREE(visu_s);
 
428
  }
 
429
}
 
430
 
 
431
/*-----------------------------------------------------------------------------
 
432
 * Define periodicities using a GUI-produced XML file.
 
433
 *----------------------------------------------------------------------------*/
 
434
 
 
435
void
 
436
cs_gui_mesh_define_periodicities(void)
 
437
{
 
438
  int perio_id;
 
439
  double angle, trans[3], axis[3], invariant[3], matrix[3][4];
 
440
 
 
441
  int  n_perio = 0;
 
442
  int  n_modes = 0;
 
443
  char  **modes = NULL;
 
444
  char  *path = NULL;
 
445
 
 
446
  if (!cs_gui_file_is_loaded())
 
447
    return;
 
448
 
 
449
  n_perio
 
450
    = cs_gui_get_tag_number("/solution_domain/periodicity/face_periodicity",
 
451
                            1);
 
452
  if (n_perio == 0)
 
453
    return;
 
454
 
 
455
  /* Get modes associated with each periodicity */
 
456
 
 
457
  path = cs_xpath_init_path();
 
458
  cs_xpath_add_elements(&path, 3,
 
459
                        "solution_domain",
 
460
                        "periodicity", "face_periodicity");
 
461
  cs_xpath_add_attribute(&path, "mode");
 
462
  modes = cs_gui_get_attribute_values(path, &n_modes);
 
463
 
 
464
  if (n_modes != n_perio)
 
465
    bft_error(__FILE__, __LINE__, 0,
 
466
              _("Number of periodicities (%d) and modes (%) do not match."),
 
467
              n_perio, n_modes);
 
468
 
 
469
  BFT_FREE(path);
 
470
 
 
471
  /* loop on periodicities */
 
472
 
 
473
  for (perio_id = 0; perio_id < n_perio; perio_id++) {
 
474
 
 
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);
 
480
 
 
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;
 
485
 
 
486
    if (!strcmp(modes[perio_id], "translation")) {
 
487
      _get_periodicity_translation(perio_id+1, trans);
 
488
      cs_join_perio_add_translation(selector_s,
 
489
                                    fraction,
 
490
                                    plane,
 
491
                                    verbosity,
 
492
                                    visualization,
 
493
                                    trans);
 
494
    }
 
495
 
 
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,
 
499
                                 fraction,
 
500
                                 plane,
 
501
                                 verbosity,
 
502
                                 visualization,
 
503
                                 angle,
 
504
                                 axis,
 
505
                                 invariant);
 
506
    }
 
507
 
 
508
    else if (!strcmp(modes[perio_id], "mixed")) {
 
509
      _get_periodicity_mixed(perio_id+1, matrix);
 
510
      cs_join_perio_add_mixed(selector_s,
 
511
                              fraction,
 
512
                              plane,
 
513
                              verbosity,
 
514
                              visualization,
 
515
                              matrix);
 
516
    }
 
517
 
 
518
    else
 
519
      bft_error(__FILE__, __LINE__, 0,
 
520
                _("Periodicity mode \"%s\" unknown."), modes[perio_id]);
 
521
 
 
522
#if _XML_DEBUG_
 
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);
 
529
#endif
 
530
 
 
531
    BFT_FREE(selector_s);
 
532
    BFT_FREE(fraction_s);
 
533
    BFT_FREE(plane_s);
 
534
    BFT_FREE(verbosity_s);
 
535
    BFT_FREE(visu_s);
 
536
  }
 
537
 
 
538
  for (perio_id = 0; perio_id < n_perio; perio_id++)
 
539
    BFT_FREE(modes[perio_id]);
 
540
  BFT_FREE(modes);
 
541
}
 
542
 
 
543
/*----------------------------------------------------------------------------*/
 
544
 
 
545
END_C_DECLS