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

« back to all changes in this revision

Viewing changes to preprocessor/pre-post/ecs_table_post_cgns.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*============================================================================
 
2
 *  Définitions des fonctions
 
3
 *   associées à la structure `ecs_champ_t' décrivant un champ
 
4
 *   et réalisant les sorties pour post-traitement CGNS
 
5
 *============================================================================*/
 
6
 
 
7
/*
 
8
  This file is part of Code_Saturne, a general-purpose CFD tool.
 
9
 
 
10
  Copyright (C) 1998-2011 EDF S.A.
 
11
 
 
12
  This program is free software; you can redistribute it and/or modify it under
 
13
  the terms of the GNU General Public License as published by the Free Software
 
14
  Foundation; either version 2 of the License, or (at your option) any later
 
15
  version.
 
16
 
 
17
  This program is distributed in the hope that it will be useful, but WITHOUT
 
18
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
19
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
20
  details.
 
21
 
 
22
  You should have received a copy of the GNU General Public License along with
 
23
  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
24
  Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
25
*/
 
26
 
 
27
/*----------------------------------------------------------------------------*/
 
28
 
 
29
#include "cs_config.h"
 
30
 
 
31
#if defined(HAVE_CGNS)
 
32
 
 
33
/*============================================================================*
 
34
 *                                 Visibilité
 
35
 *============================================================================*/
 
36
 
 
37
/*----------------------------------------------------------------------------
 
38
 *  Fichiers `include' librairie standard C
 
39
 *---------------------------------------------------------------------------*/
 
40
 
 
41
#include <assert.h>
 
42
#include <string.h>
 
43
 
 
44
#include <cgnslib.h>
 
45
 
 
46
 
 
47
/*----------------------------------------------------------------------------
 
48
 *  Fichiers `include' visibles du  paquetage global "Utilitaire"
 
49
 *---------------------------------------------------------------------------*/
 
50
 
 
51
#include "ecs_def.h"
 
52
#include "ecs_elt_typ_liste.h"
 
53
#include "ecs_fic.h"
 
54
#include "ecs_mem.h"
 
55
 
 
56
 
 
57
/*----------------------------------------------------------------------------
 
58
 *  Fichiers `include' visibles du  paquetage global "Post-Traitement"
 
59
 *---------------------------------------------------------------------------*/
 
60
 
 
61
#include "ecs_post.h"
 
62
#include "ecs_post_cgns.h"
 
63
 
 
64
 
 
65
/*----------------------------------------------------------------------------
 
66
 *  Fichiers `include' visibles des paquetages visibles
 
67
 *---------------------------------------------------------------------------*/
 
68
 
 
69
 
 
70
/*----------------------------------------------------------------------------
 
71
 *  Fichiers `include' visibles du  paquetage courant
 
72
 *---------------------------------------------------------------------------*/
 
73
 
 
74
 
 
75
/*----------------------------------------------------------------------------
 
76
 *  Fichier  `include' du  paquetage courant associé au fichier courant
 
77
 *---------------------------------------------------------------------------*/
 
78
 
 
79
#include "ecs_post_cgns.h"
 
80
#include "ecs_table_post_cgns.h"
 
81
 
 
82
 
 
83
/*----------------------------------------------------------------------------
 
84
 *  Fichiers `include' privés   du  paquetage courant
 
85
 *---------------------------------------------------------------------------*/
 
86
 
 
87
#include "ecs_post_cgns_priv.h"
 
88
#include "ecs_table_priv.h"
 
89
 
 
90
 
 
91
/*============================================================================
 
92
 * Définitions de paramètres et macros
 
93
 *============================================================================*/
 
94
 
 
95
/* Compatibilité avec diverses versions de CGNS */
 
96
 
 
97
#if defined(CGNS_SCOPE_ENUMS)
 
98
#define CS_CG_ENUM(e) CG_ ## e
 
99
#else
 
100
#define CS_CG_ENUM(e) e
 
101
#endif
 
102
 
 
103
#if CGNS_VERSION < 3100
 
104
#define cgsize_t int
 
105
#endif
 
106
 
 
107
 
 
108
/*============================================================================
 
109
 *                              Fonctions privées
 
110
 *============================================================================*/
 
111
 
 
112
/*----------------------------------------------------------------------------
 
113
 *  Fonction qui renvoie un pointeur sur une sous-structure associée
 
114
 *  à un maillage pour un cas de sortie CGNS.
 
115
 *---------------------------------------------------------------------------*/
 
116
 
 
117
static ecs_post_cgns_base_t *
 
118
ecs_loc_table_post_cgns__base(const ecs_post_cgns_t  *cas_cgns,
 
119
                              const char             *nom_maillage)
 
120
{
 
121
  ecs_int_t  ind;
 
122
  ecs_post_cgns_base_t  *base_cgns = NULL;
 
123
 
 
124
  /* Recherche du maillage */
 
125
  /*-----------------------*/
 
126
 
 
127
  for (ind = 0; ind < cas_cgns->nbr_bases; ind++) {
 
128
    base_cgns = cas_cgns->tab_bases[ind];
 
129
    if (strcmp(nom_maillage, base_cgns->nom_maillage) == 0)
 
130
      break;
 
131
  }
 
132
 
 
133
  if (ind >= cas_cgns->nbr_bases)
 
134
    ecs_error(__FILE__, __LINE__, 0,
 
135
              _("CGNS: no mesh named \"%s\".\n"
 
136
                "is associated to file: \"%s\"\n"),
 
137
              nom_maillage, base_cgns->nom_fic);
 
138
 
 
139
  /* Réouverture du fichier associé si nécessaire */
 
140
 
 
141
  if (base_cgns->fic_ouvert == false) {
 
142
 
 
143
    if (   cg_open(base_cgns->nom_fic, CG_MODE_MODIFY, &(base_cgns->num_fic))
 
144
        != CG_OK)
 
145
      ecs_error(__FILE__, __LINE__, 0,
 
146
                _("CGNS: error re-opening file \"%s\":\n%s"),
 
147
                base_cgns->nom_fic, cg_get_error());
 
148
 
 
149
    base_cgns->fic_ouvert = true;
 
150
 
 
151
  }
 
152
  return  base_cgns;
 
153
}
 
154
 
 
155
/*============================================================================
 
156
 * Public function definitions
 
157
 *============================================================================*/
 
158
 
 
159
/*----------------------------------------------------------------------------
 
160
 * Write element connectivity based on geometric type.
 
161
 *
 
162
 * Elements must have been previously sorted by type, and polyhedra
 
163
 * are ignored.
 
164
 *---------------------------------------------------------------------------*/
 
165
 
 
166
void
 
167
ecs_table_post_cgns__ecr_connect(const char            *nom_maillage,
 
168
                                 size_t                 n_vertices,
 
169
                                 const ecs_coord_t      vertex_coords[],
 
170
                                 ecs_table_t           *table_def,
 
171
                                 const ecs_tab_int_t   *tab_elt_typ_geo,
 
172
                                 ecs_post_cgns_t       *cas_cgns)
 
173
{
 
174
  size_t     ielt;
 
175
  size_t     ival_deb;
 
176
  size_t     isom;
 
177
  int        icoo;
 
178
  ecs_int_t  ind;
 
179
  ecs_int_t  ind_typ;
 
180
 
 
181
  size_t     cpt_elt;
 
182
  size_t     cpt_elt_fin;
 
183
  size_t     nbr_elt;
 
184
  size_t     nbr_som;
 
185
  size_t     nbr_som_elt;
 
186
  size_t     nbr_val;
 
187
  int        elt_typ_ref;
 
188
 
 
189
  ecs_size_t * def_pos_tab;
 
190
  ecs_int_t  * def_val_tab;
 
191
 
 
192
  int         cpt_section;
 
193
  size_t      nbr_elt_typ;
 
194
  cgsize_t    isize[3];
 
195
  int         num_coord;
 
196
  int         num_section;
 
197
  int         num_zone;
 
198
  int         ret_cgns;
 
199
 
 
200
  int         type_cgns[ECS_ELT_TYP_FIN];
 
201
  int         type_cgns_loc;
 
202
 
 
203
  cgsize_t   *def_elt;
 
204
 
 
205
  double     *coo_temp;
 
206
 
 
207
  char        nom_section[32 + 1];
 
208
 
 
209
  char const  *nom_coord[3] = {"CoordinateX",
 
210
                               "CoordinateY",
 
211
                               "CoordinateZ"};
 
212
 
 
213
  ecs_post_cgns_base_t  *base_cgns;
 
214
 
 
215
  /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
 
216
 
 
217
  assert(vertex_coords != NULL);
 
218
  assert(table_def != NULL);
 
219
 
 
220
  assert(cas_cgns != NULL);
 
221
 
 
222
  /* Recherche de la base CGNS */
 
223
  /*---------------------------*/
 
224
 
 
225
  base_cgns = ecs_loc_table_post_cgns__base(cas_cgns,
 
226
                                            nom_maillage);
 
227
 
 
228
  /* Dimensions */
 
229
  /*------------*/
 
230
 
 
231
  nbr_som = n_vertices;
 
232
  nbr_elt = table_def->nbr;
 
233
 
 
234
  isize[0] = nbr_som;
 
235
  isize[1] = nbr_elt - tab_elt_typ_geo->val[ECS_ELT_TYP_CEL_POLY];
 
236
 
 
237
  isize[2] = 0;       /* éléments de bord non triés */
 
238
 
 
239
  ret_cgns = cg_zone_write(base_cgns->num_fic,
 
240
                           1,
 
241
                           "Zone 1",
 
242
                           isize,
 
243
                           CS_CG_ENUM(Unstructured),
 
244
                           &num_zone);
 
245
 
 
246
  if (ret_cgns != CG_OK)
 
247
    ecs_error(__FILE__, __LINE__, 0,
 
248
              _("CGNS: error writing file \"%s\":\n"
 
249
                "Name of mesh to write: \"%s\"\n%s"),
 
250
              base_cgns->nom_fic, base_cgns->nom_maillage, cg_get_error());
 
251
 
 
252
  assert (num_zone == 1);
 
253
 
 
254
  /* Écriture des coordonnées */
 
255
  /*--------------------------*/
 
256
 
 
257
  /* Remplissage du tableau temporaire et écriture */
 
258
 
 
259
  ECS_MALLOC(coo_temp, nbr_som, double);
 
260
 
 
261
  for (icoo = 0; icoo < base_cgns->dim_espace; icoo++) {
 
262
 
 
263
    for (isom = 0; isom < nbr_som; isom++)
 
264
      coo_temp[isom] = vertex_coords[isom * 3 + icoo];
 
265
 
 
266
    ret_cgns = cg_coord_write(base_cgns->num_fic,
 
267
                              1,
 
268
                              1,
 
269
                              CS_CG_ENUM(RealDouble),
 
270
                              nom_coord[icoo],
 
271
                              coo_temp,
 
272
                              &num_coord);
 
273
 
 
274
    if (ret_cgns != CG_OK)
 
275
      ecs_error(__FILE__, __LINE__, 0,
 
276
                _("CGNS: error writing coordinates\n"
 
277
                  "Name of mesh to write: \"%s\"\n%s"),
 
278
                base_cgns->nom_maillage, cg_get_error());
 
279
 
 
280
  }
 
281
 
 
282
  ECS_FREE(coo_temp);
 
283
 
 
284
  /* Écriture des éléments */
 
285
  /*------------------------*/
 
286
 
 
287
  ecs_table__regle_en_pos(table_def);
 
288
 
 
289
  def_pos_tab = table_def->pos;
 
290
  def_val_tab = table_def->val;
 
291
 
 
292
  cpt_section = 0;
 
293
 
 
294
  cpt_elt = 0;
 
295
 
 
296
  elt_typ_ref = -1;
 
297
 
 
298
  for (ind_typ = ECS_ELT_TYP_NUL; ind_typ < ECS_ELT_TYP_FIN; ind_typ++)
 
299
    type_cgns[ind_typ] = -2;
 
300
 
 
301
  type_cgns[ECS_ELT_TYP_NUL] = -1;
 
302
  type_cgns[ECS_ELT_TYP_FAC_TRIA] = CS_CG_ENUM(TRI_3);
 
303
  type_cgns[ECS_ELT_TYP_FAC_QUAD] = CS_CG_ENUM(QUAD_4);
 
304
  type_cgns[ECS_ELT_TYP_CEL_TETRA] = CS_CG_ENUM(TETRA_4);
 
305
  type_cgns[ECS_ELT_TYP_CEL_PYRAM] = CS_CG_ENUM(PYRA_5);
 
306
  type_cgns[ECS_ELT_TYP_CEL_PRISM] = CS_CG_ENUM(PENTA_6);
 
307
  type_cgns[ECS_ELT_TYP_CEL_HEXA] = CS_CG_ENUM(HEXA_8);
 
308
  type_cgns[ECS_ELT_TYP_FAC_POLY] = CS_CG_ENUM(NGON_n);
 
309
  type_cgns[ECS_ELT_TYP_CEL_POLY] = - 1;
 
310
 
 
311
#if defined(DEBUG) && !defined(NDEBUG)
 
312
  for (ind_typ = ECS_ELT_TYP_NUL; ind_typ < ECS_ELT_TYP_FIN; ind_typ++)
 
313
    assert(type_cgns[ind_typ] != -2);
 
314
#endif
 
315
 
 
316
  while (cpt_elt < nbr_elt) {
 
317
 
 
318
    /* Recherche du prochain type d'élément utilisé */
 
319
 
 
320
    elt_typ_ref += 1;
 
321
 
 
322
    while (tab_elt_typ_geo->val[elt_typ_ref] == 0)
 
323
      elt_typ_ref++;
 
324
 
 
325
    nbr_elt_typ = tab_elt_typ_geo->val[elt_typ_ref];
 
326
    cpt_elt_fin = cpt_elt + nbr_elt_typ;
 
327
 
 
328
    /* Création des connectivités */
 
329
    /*----------------------------*/
 
330
 
 
331
    ind = 0;
 
332
    nbr_val = def_pos_tab[cpt_elt_fin] - def_pos_tab[cpt_elt];
 
333
 
 
334
    if (   elt_typ_ref != ECS_ELT_TYP_FAC_POLY
 
335
        && elt_typ_ref != ECS_ELT_TYP_CEL_POLY) {
 
336
 
 
337
      type_cgns_loc = type_cgns[elt_typ_ref];
 
338
 
 
339
      ECS_MALLOC(def_elt, nbr_val, cgsize_t);
 
340
 
 
341
      for (ielt = cpt_elt; ielt < cpt_elt_fin; ielt++) {
 
342
 
 
343
        ival_deb = def_pos_tab[ielt] - 1;
 
344
 
 
345
        nbr_som_elt = def_pos_tab[ielt + 1] - def_pos_tab[ielt];
 
346
 
 
347
        /* Numérotation locale CGNS identique à la numéoration
 
348
           locale interne pour les éléments linéaires */
 
349
 
 
350
        for (isom = 0; isom < nbr_som_elt; isom++)
 
351
          def_elt[ind++] = def_val_tab[ival_deb + isom];
 
352
 
 
353
      }
 
354
 
 
355
    }
 
356
    else if (elt_typ_ref == ECS_ELT_TYP_FAC_POLY) { /* Cas des polygones */
 
357
 
 
358
#if 0
 
359
 
 
360
      type_cgns_loc = CS_CG_ENUM(MIXED);
 
361
 
 
362
      ECS_MALLOC(def_elt, nbr_val + cpt_elt_fin - cpt_elt, cgsize_t);
 
363
 
 
364
      for (ielt = cpt_elt; ielt < cpt_elt_fin; ielt++) {
 
365
 
 
366
        def_elt[ind++]
 
367
          = def_pos_tab[ielt + 1] - def_pos_tab[ielt] + CS_CG_ENUM(NGON_n);
 
368
 
 
369
        for (ival = def_pos_tab[ielt    ] - 1;
 
370
             ival < def_pos_tab[ielt + 1] - 1;
 
371
             ival++)
 
372
          def_elt[ind++] = def_val_tab[ival];
 
373
 
 
374
      }
 
375
 
 
376
#else
 
377
 
 
378
      cpt_elt += nbr_elt_typ;
 
379
 
 
380
      ecs_warn();
 
381
      printf(_("CGNS: in mesh: \"%s\",\n"
 
382
               "%d polygonal faces are ignored.\n"),
 
383
             base_cgns->nom_maillage, (int)nbr_elt_typ);
 
384
 
 
385
      break;
 
386
 
 
387
#endif
 
388
 
 
389
    }
 
390
 
 
391
    else { /* Cas des polyèdres (ignorés) */
 
392
 
 
393
      cpt_elt += nbr_elt_typ;
 
394
 
 
395
      ecs_warn();
 
396
      printf(_("CGNS: in mesh: \"%s\",\n"
 
397
               "%d polyhedral cells are ignored.\n"),
 
398
             base_cgns->nom_maillage, (int)nbr_elt_typ);
 
399
 
 
400
      break;
 
401
 
 
402
    }
 
403
 
 
404
    /* Écriture de la section (sections séparées) */
 
405
 
 
406
    cpt_section += 1;
 
407
    sprintf(nom_section, "Section %2d", cpt_section);
 
408
 
 
409
    ret_cgns = cg_section_write(base_cgns->num_fic,
 
410
                                1,
 
411
                                1,
 
412
                                nom_section,
 
413
                                type_cgns_loc,
 
414
                                (int)(cpt_elt + 1),
 
415
                                (int)(cpt_elt + nbr_elt_typ),
 
416
                                0,
 
417
                                def_elt,
 
418
                                &num_section);
 
419
 
 
420
    ECS_FREE(def_elt);
 
421
 
 
422
    /* On s'apprête à passer au type d'élément suivant */
 
423
 
 
424
    cpt_elt += nbr_elt_typ;
 
425
  }
 
426
 
 
427
  /* Nettoyage avant la sortie */
 
428
  /*---------------------------*/
 
429
 
 
430
  ecs_table__libere_pos_tab(table_def, def_pos_tab);
 
431
}
 
432
 
 
433
#endif /* HAVE_CGNS */
 
434
 
 
435
/*----------------------------------------------------------------------------*/
 
436