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
*============================================================================*/
8
This file is part of Code_Saturne, a general-purpose CFD tool.
10
Copyright (C) 1998-2011 EDF S.A.
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
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
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.
27
/*----------------------------------------------------------------------------*/
29
#include "cs_config.h"
31
#if defined(HAVE_CGNS)
33
/*============================================================================*
35
*============================================================================*/
37
/*----------------------------------------------------------------------------
38
* Fichiers `include' librairie standard C
39
*---------------------------------------------------------------------------*/
47
/*----------------------------------------------------------------------------
48
* Fichiers `include' visibles du paquetage global "Utilitaire"
49
*---------------------------------------------------------------------------*/
52
#include "ecs_elt_typ_liste.h"
57
/*----------------------------------------------------------------------------
58
* Fichiers `include' visibles du paquetage global "Post-Traitement"
59
*---------------------------------------------------------------------------*/
62
#include "ecs_post_cgns.h"
65
/*----------------------------------------------------------------------------
66
* Fichiers `include' visibles des paquetages visibles
67
*---------------------------------------------------------------------------*/
70
/*----------------------------------------------------------------------------
71
* Fichiers `include' visibles du paquetage courant
72
*---------------------------------------------------------------------------*/
75
/*----------------------------------------------------------------------------
76
* Fichier `include' du paquetage courant associé au fichier courant
77
*---------------------------------------------------------------------------*/
79
#include "ecs_post_cgns.h"
80
#include "ecs_table_post_cgns.h"
83
/*----------------------------------------------------------------------------
84
* Fichiers `include' privés du paquetage courant
85
*---------------------------------------------------------------------------*/
87
#include "ecs_post_cgns_priv.h"
88
#include "ecs_table_priv.h"
91
/*============================================================================
92
* Définitions de paramètres et macros
93
*============================================================================*/
95
/* Compatibilité avec diverses versions de CGNS */
97
#if defined(CGNS_SCOPE_ENUMS)
98
#define CS_CG_ENUM(e) CG_ ## e
100
#define CS_CG_ENUM(e) e
103
#if CGNS_VERSION < 3100
108
/*============================================================================
110
*============================================================================*/
112
/*----------------------------------------------------------------------------
113
* Fonction qui renvoie un pointeur sur une sous-structure associée
114
* à un maillage pour un cas de sortie CGNS.
115
*---------------------------------------------------------------------------*/
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)
122
ecs_post_cgns_base_t *base_cgns = NULL;
124
/* Recherche du maillage */
125
/*-----------------------*/
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)
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);
139
/* Réouverture du fichier associé si nécessaire */
141
if (base_cgns->fic_ouvert == false) {
143
if ( cg_open(base_cgns->nom_fic, CG_MODE_MODIFY, &(base_cgns->num_fic))
145
ecs_error(__FILE__, __LINE__, 0,
146
_("CGNS: error re-opening file \"%s\":\n%s"),
147
base_cgns->nom_fic, cg_get_error());
149
base_cgns->fic_ouvert = true;
155
/*============================================================================
156
* Public function definitions
157
*============================================================================*/
159
/*----------------------------------------------------------------------------
160
* Write element connectivity based on geometric type.
162
* Elements must have been previously sorted by type, and polyhedra
164
*---------------------------------------------------------------------------*/
167
ecs_table_post_cgns__ecr_connect(const char *nom_maillage,
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)
189
ecs_size_t * def_pos_tab;
190
ecs_int_t * def_val_tab;
200
int type_cgns[ECS_ELT_TYP_FIN];
207
char nom_section[32 + 1];
209
char const *nom_coord[3] = {"CoordinateX",
213
ecs_post_cgns_base_t *base_cgns;
215
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
217
assert(vertex_coords != NULL);
218
assert(table_def != NULL);
220
assert(cas_cgns != NULL);
222
/* Recherche de la base CGNS */
223
/*---------------------------*/
225
base_cgns = ecs_loc_table_post_cgns__base(cas_cgns,
231
nbr_som = n_vertices;
232
nbr_elt = table_def->nbr;
235
isize[1] = nbr_elt - tab_elt_typ_geo->val[ECS_ELT_TYP_CEL_POLY];
237
isize[2] = 0; /* éléments de bord non triés */
239
ret_cgns = cg_zone_write(base_cgns->num_fic,
243
CS_CG_ENUM(Unstructured),
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());
252
assert (num_zone == 1);
254
/* Écriture des coordonnées */
255
/*--------------------------*/
257
/* Remplissage du tableau temporaire et écriture */
259
ECS_MALLOC(coo_temp, nbr_som, double);
261
for (icoo = 0; icoo < base_cgns->dim_espace; icoo++) {
263
for (isom = 0; isom < nbr_som; isom++)
264
coo_temp[isom] = vertex_coords[isom * 3 + icoo];
266
ret_cgns = cg_coord_write(base_cgns->num_fic,
269
CS_CG_ENUM(RealDouble),
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());
284
/* Écriture des éléments */
285
/*------------------------*/
287
ecs_table__regle_en_pos(table_def);
289
def_pos_tab = table_def->pos;
290
def_val_tab = table_def->val;
298
for (ind_typ = ECS_ELT_TYP_NUL; ind_typ < ECS_ELT_TYP_FIN; ind_typ++)
299
type_cgns[ind_typ] = -2;
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;
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);
316
while (cpt_elt < nbr_elt) {
318
/* Recherche du prochain type d'élément utilisé */
322
while (tab_elt_typ_geo->val[elt_typ_ref] == 0)
325
nbr_elt_typ = tab_elt_typ_geo->val[elt_typ_ref];
326
cpt_elt_fin = cpt_elt + nbr_elt_typ;
328
/* Création des connectivités */
329
/*----------------------------*/
332
nbr_val = def_pos_tab[cpt_elt_fin] - def_pos_tab[cpt_elt];
334
if ( elt_typ_ref != ECS_ELT_TYP_FAC_POLY
335
&& elt_typ_ref != ECS_ELT_TYP_CEL_POLY) {
337
type_cgns_loc = type_cgns[elt_typ_ref];
339
ECS_MALLOC(def_elt, nbr_val, cgsize_t);
341
for (ielt = cpt_elt; ielt < cpt_elt_fin; ielt++) {
343
ival_deb = def_pos_tab[ielt] - 1;
345
nbr_som_elt = def_pos_tab[ielt + 1] - def_pos_tab[ielt];
347
/* Numérotation locale CGNS identique à la numéoration
348
locale interne pour les éléments linéaires */
350
for (isom = 0; isom < nbr_som_elt; isom++)
351
def_elt[ind++] = def_val_tab[ival_deb + isom];
356
else if (elt_typ_ref == ECS_ELT_TYP_FAC_POLY) { /* Cas des polygones */
360
type_cgns_loc = CS_CG_ENUM(MIXED);
362
ECS_MALLOC(def_elt, nbr_val + cpt_elt_fin - cpt_elt, cgsize_t);
364
for (ielt = cpt_elt; ielt < cpt_elt_fin; ielt++) {
367
= def_pos_tab[ielt + 1] - def_pos_tab[ielt] + CS_CG_ENUM(NGON_n);
369
for (ival = def_pos_tab[ielt ] - 1;
370
ival < def_pos_tab[ielt + 1] - 1;
372
def_elt[ind++] = def_val_tab[ival];
378
cpt_elt += nbr_elt_typ;
381
printf(_("CGNS: in mesh: \"%s\",\n"
382
"%d polygonal faces are ignored.\n"),
383
base_cgns->nom_maillage, (int)nbr_elt_typ);
391
else { /* Cas des polyèdres (ignorés) */
393
cpt_elt += nbr_elt_typ;
396
printf(_("CGNS: in mesh: \"%s\",\n"
397
"%d polyhedral cells are ignored.\n"),
398
base_cgns->nom_maillage, (int)nbr_elt_typ);
404
/* Écriture de la section (sections séparées) */
407
sprintf(nom_section, "Section %2d", cpt_section);
409
ret_cgns = cg_section_write(base_cgns->num_fic,
415
(int)(cpt_elt + nbr_elt_typ),
422
/* On s'apprête à passer au type d'élément suivant */
424
cpt_elt += nbr_elt_typ;
427
/* Nettoyage avant la sortie */
428
/*---------------------------*/
430
ecs_table__libere_pos_tab(table_def, def_pos_tab);
433
#endif /* HAVE_CGNS */
435
/*----------------------------------------------------------------------------*/