1
/*============================================================================
2
* Read mesh from STAR-CCM+ format file
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
#include "cs_config.h"
31
/*----------------------------------------------------------------------------
32
* Standard C library headers
33
*----------------------------------------------------------------------------*/
40
/*----------------------------------------------------------------------------
42
*----------------------------------------------------------------------------*/
45
#include "ecs_elt_typ_liste.h"
49
#include "ecs_descr.h"
50
#include "ecs_descr_chaine.h"
51
#include "ecs_maillage.h"
52
#include "ecs_maillage_priv.h"
54
/*----------------------------------------------------------------------------
55
* Fichiers `include' visibles du paquetage courant
56
*----------------------------------------------------------------------------*/
58
#include "ecs_maillage_pre.h"
60
/*----------------------------------------------------------------------------
61
* Header for the current file
62
*----------------------------------------------------------------------------*/
64
#include "ecs_pre_ccm.h"
66
/*----------------------------------------------------------------------------*/
72
#include <libccmio/ccmio.h>
73
#include <libccmio/ccmioversion.h>
79
/*=============================================================================
80
* Local Macro Definitions
81
*============================================================================*/
83
#if (kCCMIOVersion == 20601)
84
typedef CCMIOSize CCMIOSize_t;
87
/*=============================================================================
88
* Local Type Definitions
89
*============================================================================*/
91
/* Vertices definition */
94
size_t n_nodes; /* Number of vertices */
95
ecs_int_t *id; /* Vertex labels */
96
ecs_coord_t *coord; /* Coordinates (interlaced) */
100
/* Face definitions (boundary and internal) */
103
size_t n_faces; /* Number of */
104
ecs_int_t *nbr_n; /* Number of vertices/face */
105
size_t taille_connect; /* Connectivity size */
106
ecs_int_t *connect; /* Vertices connectivity */
107
ecs_int_t *icel1; /* Cell on positive face side */
108
ecs_int_t *icel2; /* Cell on negative face side */
109
ecs_int_t *icoul; /* Face colors */
112
/* Cell definitions */
115
size_t n_cells; /* Number of cells */
116
ecs_int_t *id; /* Cell ids */
117
ecs_int_t *icoul; /* Cell colors (types) */
120
/*============================================================================
121
* Private function definitions
122
*============================================================================*/
124
/*----------------------------------------------------------------------------
126
*----------------------------------------------------------------------------*/
129
_read_vertices(CCMIOID vertices,
136
#if (kCCMIOVersion == 20601)
138
CCMIOSize n_vertices = 0, size;
140
CCMIOSize_t dims = 1, n_vertices = 0, size;
143
CCMIOError err = kCCMIONoErr;
145
/* Get description */
147
CCMIOEntityDescription(&err, vertices, &size, NULL);
149
if (err == kCCMIONoErr && size > 0) {
151
ECS_MALLOC(s_descr, size + 1, char);
152
CCMIOEntityDescription(&err, vertices, &size, s_descr);
153
if (err == kCCMIONoErr)
154
printf(_("\n Vertex coordinates set: %s\n"), s_descr);
160
CCMIOEntitySize(&err, vertices, &n_vertices, NULL);
161
if (err != kCCMIONoErr)
162
ecs_error(__FILE__, __LINE__, 0,
163
_("Error %d reading vertex information in STAR-CCM+ file."),
166
nodes->n_nodes = (ecs_int_t)n_vertices;
168
ECS_MALLOC(verts_coo, 3*nodes->n_nodes, double);
169
ECS_MALLOC(map_data, nodes->n_nodes, int);
171
CCMIOReadVerticesd(&err, vertices, &dims, &scale, &map_id, verts_coo,
173
CCMIOReadMap(&err, map_id, map_data, 0, n_vertices);
175
/* Transfer to local node structure */
177
ECS_MALLOC(nodes->id, nodes->n_nodes, ecs_int_t);
178
ECS_MALLOC(nodes->coord, 3*nodes->n_nodes, ecs_coord_t);
180
for (i = 0; i < n_vertices; i++) {
182
nodes->id[i] = map_data[i];
184
nodes->coord[dims*i ] = scale*verts_coo[dims*i];
185
nodes->coord[dims*i+1] = scale*verts_coo[dims*i+1];
186
nodes->coord[dims*i+2] = scale*verts_coo[dims*i+2];
194
/*----------------------------------------------------------------------------
196
*----------------------------------------------------------------------------*/
199
_read_cells(CCMIOID topology,
206
CCMIOError err = kCCMIONoErr;
211
static const int k_cell_inc = 4;
213
CCMIOGetEntity(&err, topology, kCCMIOCells, 0, &id);
214
CCMIOEntitySize(&err, id, &n_cells, NULL);
216
ECS_MALLOC(cell_type, n_cells, int);
217
ECS_MALLOC(map_data, n_cells, int);
219
for (i = 0; i < n_cells; i += k_cell_inc) {
220
CCMIOReadCells(&err, id, &map_id, &cell_type[i], i, i + k_cell_inc);
221
CCMIOReadMap(&err, map_id, &map_data[i], i, i + k_cell_inc);
224
/* Transfer to local cell structure */
226
cells->n_cells = (ecs_int_t) n_cells;
228
ECS_MALLOC(cells->id, n_cells, ecs_int_t);
229
ECS_MALLOC(cells->icoul, n_cells, ecs_int_t);
231
for (i = 0; i < n_cells; i++) {
232
cells->id[i] = map_data[i];
233
cells->icoul[i] = cell_type[i];
240
/*----------------------------------------------------------------------------
242
*----------------------------------------------------------------------------*/
245
_read_mesh(CCMIOID vertices,
255
CCMIOError err = kCCMIONoErr;
256
CCMIOSize_t n_faces, size;
257
int *face_nverts; int *face_cells;
260
_read_vertices(vertices,
263
_read_cells(topology,
266
/* Read the topology description. */
268
CCMIOEntityDescription(&err, topology, &size, NULL);
270
if (err == kCCMIONoErr && size > 0) {
272
ECS_MALLOC(s_descr, size + 1, char);
273
CCMIOEntityDescription(&err, topology, &size, s_descr);
274
if (err == kCCMIONoErr)
275
printf(_(" Face-based topology: %s\n"), s_descr);
279
/* Read the internal faces. */
281
CCMIOGetEntity(&err, topology, kCCMIOInternalFaces, 0, &id);
283
CCMIOEntityDescription(&err, id, &size, NULL);
285
if (err == kCCMIONoErr && size > 0) {
287
ECS_MALLOC(s_descr, size + 1, char);
288
CCMIOEntityDescription(&err, id, &size, s_descr);
289
if (err == kCCMIONoErr)
290
printf(_(" Faces: %s\n"), s_descr);
294
/* Read internal faces data */
296
CCMIOEntitySize(&err, id, &n_faces, NULL);
298
ECS_MALLOC(face_cells, 2*n_faces, int);
300
CCMIOReadFaces(&err, id, kCCMIOInternalFaces, NULL, &size, NULL,
301
kCCMIOStart, kCCMIOEnd);
303
if (err != kCCMIONoErr)
304
ecs_error(__FILE__, __LINE__, 0,
305
_("Error %d reading faces information in STAR-CCM+ file."),
308
ECS_MALLOC(face_nverts, size, int);
310
CCMIOReadFaces(&err, id, kCCMIOInternalFaces, &map_id, NULL, face_nverts,
311
kCCMIOStart, kCCMIOEnd);
313
if (err != kCCMIONoErr)
314
ecs_error(__FILE__, __LINE__, 0,
315
_("Error %d reading internal faces in STAR-CCM+ file."),
318
CCMIOReadFaceCells(&err, id, kCCMIOInternalFaces, face_cells,
319
kCCMIOStart, kCCMIOEnd);
321
if (err != kCCMIONoErr)
322
ecs_error(__FILE__, __LINE__, 0,
323
_("Error %d reading face->cell connectivity in STAR-CCM+ file."),
326
/* Map data is not used here; if it were necessary, we would have:
330
* ECS_MALLOC(map_data, n_faces, int);
331
* CCMIOReadMap(&err, map_id, map_data, kCCMIOStart, kCCMIOEnd);
332
* ECS_FREE(map_data);
335
if (err != kCCMIONoErr)
336
ecs_error(__FILE__, __LINE__, 0,
337
_("Error %d reading map in STAR-CCM+ file."),
340
/* Transfer to local face structure */
342
i_faces->n_faces = n_faces;
343
i_faces->taille_connect = size;
345
ECS_MALLOC(i_faces->nbr_n, n_faces, ecs_int_t);
347
ECS_MALLOC(i_faces->icel1, n_faces, ecs_int_t);
348
ECS_MALLOC(i_faces->icel2, n_faces, ecs_int_t);
349
ECS_MALLOC(i_faces->icoul, n_faces, ecs_int_t);
351
i_faces->taille_connect = size - n_faces;
353
ECS_MALLOC(i_faces->connect, i_faces->taille_connect, ecs_int_t);
355
for (i = 0, pos = 0, cpt = 0; i < i_faces->n_faces; i++) {
357
i_faces->nbr_n[i] = face_nverts[pos];
358
i_faces->icel1[i] = face_cells[2*i];
359
i_faces->icel2[i] = face_cells[2*i+1];
360
assert(i_faces->icel1[i] > 0);
361
assert(i_faces->icel2[i] > 0);
362
i_faces->icoul[i] = 0;
364
for (j = 0; j < i_faces->nbr_n[i]; j++)
365
i_faces->connect[cpt + j] = (ecs_int_t) face_nverts[pos + j + 1];
367
cpt += i_faces->nbr_n[i];
368
pos += face_nverts[pos] + 1;
371
ECS_FREE(face_nverts);
372
ECS_FREE(face_cells);
374
/* Read the boundary faces */
377
#if (kCCMIOVersion == 20601)
380
CCMIOSize_t _index = 0;
385
b_faces->n_faces = 0;
386
b_faces->taille_connect = 0;
388
while ( CCMIONextEntity(NULL, topology, kCCMIOBoundaryFaces, &_index, &id)
393
CCMIOEntityDescription(&err, id, &size, NULL);
395
if (err == kCCMIONoErr && size > 0) {
397
ECS_MALLOC(s_descr, size + 1, char);
398
CCMIOEntityDescription(&err, id, &size, s_descr);
399
if (err == kCCMIONoErr)
400
printf(_(" Faces: %s\n"), s_descr);
404
CCMIOEntitySize(&err, id, &n_faces, NULL);
406
ECS_REALLOC(face_cells, 2*n_faces, int);
408
CCMIOReadFaces(&err, id, kCCMIOBoundaryFaces, NULL, &size, NULL,
409
kCCMIOStart, kCCMIOEnd);
411
ECS_MALLOC(face_nverts, size, int);
413
CCMIOReadFaces(&err, id, kCCMIOBoundaryFaces, &map_id, NULL,
414
face_nverts, kCCMIOStart, kCCMIOEnd);
415
CCMIOReadFaceCells(&err, id, kCCMIOBoundaryFaces, face_cells,
416
kCCMIOStart, kCCMIOEnd);
418
/* Map data is not used here; if it were necessary, we would have:
422
* ECS_MALLOC(map_data, n_faces, int);
423
* CCMIOReadMap(&err, map_id, map_data, kCCMIOStart, kCCMIOEnd);
424
* ECS_FREE(map_data);
427
CCMIOGetEntityIndex(&err, id, &boundary_id);
429
/* Transfer to local face structure */
431
b_faces->n_faces += n_faces;
432
b_faces->taille_connect += (size - n_faces);
435
ECS_MALLOC(b_faces->nbr_n, b_faces->n_faces, ecs_int_t);
436
ECS_MALLOC(b_faces->icel1, b_faces->n_faces, ecs_int_t);
437
ECS_MALLOC(b_faces->icel2, b_faces->n_faces, ecs_int_t);
438
ECS_MALLOC(b_faces->connect, b_faces->taille_connect, ecs_int_t);
439
ECS_MALLOC(b_faces->icoul, b_faces->n_faces, ecs_int_t);
442
ECS_REALLOC(b_faces->nbr_n, b_faces->n_faces, ecs_int_t);
443
ECS_REALLOC(b_faces->icel1, b_faces->n_faces, ecs_int_t);
444
ECS_REALLOC(b_faces->icel2, b_faces->n_faces, ecs_int_t);
445
ECS_REALLOC(b_faces->connect, b_faces->taille_connect, ecs_int_t);
446
ECS_REALLOC(b_faces->icoul, b_faces->n_faces, ecs_int_t);
449
for (i = 0, pos = 0, cpt = 0; i < (size_t)n_faces; i++) {
451
b_faces->nbr_n[i_beg + i] = face_nverts[pos];
452
b_faces->icel1[i_beg + i] = face_cells[i];
453
b_faces->icel2[i_beg + i] = -1;
454
assert(b_faces->icel1[i_beg + i] > 0);
455
b_faces->icoul[i_beg + i] = boundary_id;
457
for (j = 0; j < b_faces->nbr_n[i_beg + i]; j++)
458
b_faces->connect[i_beg_c + cpt + j] = face_nverts[pos + j + 1];
460
cpt += b_faces->nbr_n[i_beg + i];
461
pos += face_nverts[pos] + 1;
465
i_beg_c += (size - n_faces);
467
ECS_FREE(face_nverts);
468
ECS_FREE(face_cells);
475
/*----------------------------------------------------------------------------
476
* Extract a mesh's cell -> faces connectivity.
478
* We consider a common numbering for interior and boundary faces, in which
479
* boundary faces are defined first. The common id of the i-th boundary
480
* face is thus i, while that of the j-th interior face is nbr_fbr + j.
481
*----------------------------------------------------------------------------*/
484
ecs_pre_ccm__cel_fac(const _faces_t *faces,
485
const _cells_t *cels,
486
ecs_int_t **const p_pos_cel_fac,
487
ecs_int_t **const p_val_cel_fac)
489
ecs_int_t icel, icel1, icel2, n_cells_loc;
492
ecs_int_t * cpt_cel_fac = NULL;
493
ecs_int_t * pos_cel_fac = NULL;
494
ecs_int_t * val_cel_fac = NULL;
496
/* Allocate and initialize position index */
498
n_cells_loc = cels->n_cells;
500
ECS_MALLOC(pos_cel_fac, n_cells_loc + 1, ecs_int_t);
502
for (icel = 0; icel < n_cells_loc + 1; icel++)
503
pos_cel_fac[icel] = 0;
505
/* Count number of faces per cell
506
* (we assign the temporary counter for icel to pos_cel_fac[icel + 1]
507
* instead of pos_cel_fac[icel] so as to simplify the next step) */
509
for (ifac = 0; ifac < faces->n_faces; ifac++) {
510
icel1 = faces->icel1[ifac] - 1;
511
icel2 = faces->icel2[ifac] - 1;
512
pos_cel_fac[icel1 + 1] += 1;
514
pos_cel_fac[icel2 + 1] += 1;
517
/* Build position index */
520
for (icel = 0; icel < n_cells_loc; icel++)
521
pos_cel_fac[icel + 1] = pos_cel_fac[icel] + pos_cel_fac[icel + 1];
523
/* Build array of values */
525
ECS_MALLOC(val_cel_fac, pos_cel_fac[n_cells_loc] - 1, ecs_int_t);
526
ECS_MALLOC(cpt_cel_fac, n_cells_loc, ecs_int_t);
528
for (icel = 0; icel < n_cells_loc; icel++)
529
cpt_cel_fac[icel] = 0;
531
for (ifac = 0; ifac < faces->n_faces; ifac++) {
532
icel1 = faces->icel1[ifac] - 1;
533
icel2 = faces->icel2[ifac] - 1;
535
val_cel_fac[pos_cel_fac[icel1] + cpt_cel_fac[icel1] - 1] = (ifac + 1);
536
cpt_cel_fac[icel1] += 1;
538
val_cel_fac[pos_cel_fac[icel2] + cpt_cel_fac[icel2] - 1] = -(ifac + 1);
539
cpt_cel_fac[icel2] += 1;
543
ECS_FREE(cpt_cel_fac);
547
*p_pos_cel_fac = pos_cel_fac;
548
*p_val_cel_fac = val_cel_fac;
550
#if 0 && defined(DEBUG) && !defined(NDEBUG)
552
ecs_int_t ipos, ival;
554
printf("dbg : cs_loc_maillage_ret_cel_fac\n"
555
"nombre de cellules extraites = %d\n", n_cells_extr);
556
for (ipos = 0; ipos < n_cells_extr; ipos++) {
557
printf(" cellule %d\n", ipos);
558
printf(" pos_cel_fac[%d] = %d\n", ipos, pos_cel_fac[ipos]);
559
for (ival = pos_cel_fac[ipos] - 1;
560
ival < pos_cel_fac[ipos + 1] - 1;
562
printf(" val_cel_fac[%d] = %d\n", ival, val_cel_fac[ival]);
564
printf(" pos_cel_fac[%d] = %d\n", ipos, pos_cel_fac[ipos]);
570
/*----------------------------------------------------------------------------
571
* Build mesh structure
572
*----------------------------------------------------------------------------*/
574
static ecs_maillage_t *
575
ecs_pre_ccm__prepa_mail(_nodes_t *noeuds,
578
ecs_int_t *pos_cel_fac,
579
ecs_int_t *val_cel_fac)
581
/* Temporary arrays used before transfer to mesh structure */
583
size_t cpt_elt_ent [ECS_N_ENTMAIL]; /* N. elts per entity */
584
ecs_int_t cpt_coul_ent [ECS_N_ENTMAIL]; /* Color counter */
585
size_t cpt_val_som_ent [ECS_N_ENTMAIL]; /* Connectivity size */
586
ecs_int_t * val_coul_ent [ECS_N_ENTMAIL]; /* Array of colors */
587
ecs_size_t * cpt_elt_coul_ent [ECS_N_ENTMAIL];
588
ecs_size_t * elt_pos_som_ent [ECS_N_ENTMAIL]; /* Vertex positions */
589
ecs_int_t * elt_val_som_ent [ECS_N_ENTMAIL]; /* Vertex numbers */
590
ecs_int_t * elt_val_color_ent [ECS_N_ENTMAIL]; /* Element colors */
593
ecs_int_t nbr_som_elt;
596
ecs_entmail_t entmail_e;
604
ecs_int_t nbr_som_fac;
605
ecs_int_t num_som_deb_fac;
607
/* Create intially empty mesh (return value) */
609
ecs_maillage_t *maillage = ecs_maillage__cree_nodal();
611
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
615
ecs_maillage_pre__cree_som(maillage,
621
for (ient = 0; ient < ECS_N_ENTMAIL; ient++) {
623
cpt_elt_ent [ient] = 0;
624
cpt_val_som_ent [ient] = 0;
626
elt_pos_som_ent [ient] = NULL;
627
elt_val_som_ent [ient] = NULL;
628
elt_val_color_ent [ient] = NULL;
630
cpt_coul_ent [ient] = 0;
631
val_coul_ent [ient] = NULL;
632
cpt_elt_coul_ent [ient] = NULL;
636
/* Faces (polygons) */
638
entmail_e = ECS_ENTMAIL_FAC;
640
cpt_elt_ent[entmail_e] = faces->n_faces;
641
cpt_val_som_ent[entmail_e] = faces->taille_connect;
642
elt_val_som_ent[entmail_e] = faces->connect;
644
if (cpt_elt_ent[entmail_e] > 0) {
646
ECS_MALLOC(elt_pos_som_ent[entmail_e],
647
cpt_elt_ent[entmail_e] + 1,
650
elt_pos_som_ent[entmail_e][0] = 1;
652
ECS_MALLOC(elt_val_color_ent[entmail_e],
653
cpt_elt_ent[entmail_e],
657
for (ifac = 0; ifac < faces->n_faces; ifac++) {
659
/* Test if color is assigned */
662
icoul < cpt_coul_ent[entmail_e]
663
&& val_coul_ent[entmail_e][icoul] != faces->icoul[ifac];
666
if (icoul == cpt_coul_ent[entmail_e]) {
668
/* This color value has not been saved yet */
670
ECS_REALLOC(val_coul_ent[entmail_e],
671
cpt_coul_ent[entmail_e] + 1,
673
ECS_REALLOC(cpt_elt_coul_ent[entmail_e],
674
cpt_coul_ent[entmail_e] + 1,
677
cpt_elt_coul_ent[entmail_e][icoul] = 0;
678
val_coul_ent[entmail_e][icoul] = faces->icoul[ifac];
679
cpt_coul_ent[entmail_e]++;
685
cpt_elt_coul_ent[entmail_e][icoul]++;
686
elt_val_color_ent[entmail_e][ifac] = icoul + 1;
688
nbr_som_elt = faces->nbr_n[ifac];
690
/* Build connectivity */
692
pos_elt = elt_pos_som_ent[entmail_e][ifac];
694
elt_pos_som_ent[entmail_e][ifac + 1] = pos_elt + nbr_som_elt;
698
/* Cells (polyhedra) */
700
entmail_e = ECS_ENTMAIL_CEL;
702
cpt_elt_ent[entmail_e] = cels->n_cells;
704
n_faces = pos_cel_fac[cels->n_cells] - 1;
706
cpt_val_som_ent[entmail_e] = 0;
708
for (ifac = 0; ifac < n_faces; ifac++)
709
cpt_val_som_ent[entmail_e] += faces->nbr_n[abs(val_cel_fac[ifac])-1] + 1;
711
if (cpt_elt_ent[entmail_e] > 0) {
713
ECS_MALLOC(elt_pos_som_ent[entmail_e],
714
cpt_elt_ent[entmail_e] + 1,
717
elt_pos_som_ent[entmail_e][0] = 1;
719
ECS_MALLOC(elt_val_som_ent[entmail_e],
720
cpt_val_som_ent[entmail_e],
723
ECS_MALLOC(elt_val_color_ent[entmail_e],
724
cpt_elt_ent[entmail_e],
729
for (icel = 0; icel < cels->n_cells; icel++){
731
/* Position in connectivity */
733
cpt_val_som_ent[entmail_e] = 0;
735
for (ifac = pos_cel_fac[icel] - 1;
736
ifac < (size_t)(pos_cel_fac[icel + 1] - 1);
738
cpt_val_som_ent[entmail_e]
739
+= faces->nbr_n[abs(val_cel_fac[ifac]) - 1] + 1;
741
elt_pos_som_ent[entmail_e][icel + 1]
742
= elt_pos_som_ent[entmail_e][icel] + cpt_val_som_ent[entmail_e];
744
/* Test if color is assigned */
747
icoul < cpt_coul_ent[entmail_e]
748
&& val_coul_ent[entmail_e][icoul] != cels->icoul[icel];
751
if (icoul == cpt_coul_ent[entmail_e]) {
753
/* This color value has not been saved yet */
755
ECS_REALLOC(val_coul_ent[entmail_e],
756
cpt_coul_ent[entmail_e] + 1,
758
ECS_REALLOC(cpt_elt_coul_ent[entmail_e],
759
cpt_coul_ent[entmail_e] + 1,
762
cpt_elt_coul_ent[entmail_e][icoul] = 0;
763
val_coul_ent[entmail_e][icoul] = cels->icoul[icel];
764
cpt_coul_ent[entmail_e]++;
770
cpt_elt_coul_ent[entmail_e][icoul]++;
771
elt_val_color_ent[entmail_e][icel] = icoul + 1;
777
/* Loop on all faces of val_cel_fac */
779
cpt_val_som_ent[entmail_e] = 0;
781
for (ifac = 0; ifac < n_faces; ifac++) {
783
pos_fac = elt_pos_som_ent[ECS_ENTMAIL_FAC][abs(val_cel_fac[ifac])-1];
785
nbr_som_fac = faces->nbr_n[abs(val_cel_fac[ifac])-1];
789
if (val_cel_fac[ifac] < 0) {
791
num_som_deb_fac = faces->connect[pos_fac + (nbr_som_fac - 1) -1];
793
for (isom = 0; isom < nbr_som_fac; isom++)
794
elt_val_som_ent[entmail_e][cpt_val_som_ent[entmail_e] + isom]
795
= faces->connect[pos_fac -1 + ((nbr_som_fac - 1) - isom)];
801
num_som_deb_fac = faces->connect[pos_fac - 1];
803
for (isom = 0; isom < nbr_som_fac; isom++)
804
elt_val_som_ent[entmail_e][cpt_val_som_ent[entmail_e] + isom]
805
= faces->connect[pos_fac -1 + isom];
809
elt_val_som_ent[entmail_e][cpt_val_som_ent[entmail_e] + isom]
812
cpt_val_som_ent[entmail_e] += nbr_som_fac + 1;
816
/* Transfer values read to mesh entity structures */
818
ecs_maillage_pre__cree_elt(maillage,
828
ECS_FREE(pos_cel_fac);
829
ECS_FREE(val_cel_fac);
834
/*============================================================================
835
* Public function definitions
836
*============================================================================*/
838
/*----------------------------------------------------------------------------
839
* Read of mesh from a STAR-CCM+ format file.
842
* nom_fic_maillage <-- mesh file name
843
* num_maillage <-- mesh number
844
*----------------------------------------------------------------------------*/
847
ecs_pre_ccm__lit_maillage(const char *nom_fic_maillage,
850
ecs_maillage_t * maillage = NULL;
852
CCMIOID root, state, processor, vertices, topology;
855
#if (kCCMIOVersion == 20601)
860
CCMIOSize_t size = 0;
864
_faces_t *liste_faces_bord;
865
_faces_t *liste_faces_internes;
866
_faces_t *liste_faces;
867
_cells_t *liste_cels;
869
ecs_tab_int_t tab_connect;
870
ecs_tab_int_t tab_label;
877
ecs_int_t *pos_cel_fac;
878
ecs_int_t *val_cel_fac;
881
size_t taille_connect_bord = 0;
882
size_t taille_connect_interne = 0;
883
size_t taille_connect = 0;
885
int version = 0, maj_ver = 0, min_ver = 0, rel_ver = 0;
887
CCMIOID *states = NULL;
890
/*Xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
892
err = CCMIOOpenFile(NULL, nom_fic_maillage, kCCMIORead, &root);
894
CCMIOGetVersion(&err, root.node, &version);
896
maj_ver = version / 10000;
897
min_ver = (version % 10000)/ 100;
898
rel_ver = (version % 100);
900
CCMIOGetTitle(&err, root.node, &title);
903
"Reading mesh from file in STAR-CCM+ format\n"
904
"----------------------\n"));
906
printf(_(" Mesh file: %s\n\n\n"
907
" STAR-CCM+ format version: %1d.%1d.%1d\n"
909
nom_fic_maillage, maj_ver, min_ver, rel_ver, title);
911
/* The string 'title' has been allocated inside CCMIOGetTitle */
915
/* Initialisations */
918
liste_faces_bord = NULL;
919
liste_faces_internes = NULL;
922
ECS_MALLOC(nodes, 1, _nodes_t);
923
ECS_MALLOC(liste_faces_bord, 1, _faces_t);
924
ECS_MALLOC(liste_faces_internes, 1, _faces_t);
925
ECS_MALLOC(liste_cels, 1, _cells_t);
927
/* Search for available states */
931
printf(_(" Available meshes:\n"));
933
while (err == kCCMIONoErr) {
935
char name[kCCMIOMaxStringLength + 1];
937
CCMIONextEntity(&err, root, kCCMIOState, &i, &state);
939
if (err != kCCMIONoErr)
942
CCMIOEntityName(&err, state, name);
944
if (err != kCCMIONoErr)
945
ecs_error(__FILE__, __LINE__, 0,
946
_("Error %d reading state name in STAR-CCM+ file."),
949
printf(" %2d: \"%s\"\n", n_states + 1, name);
951
ECS_REALLOC(states, n_states + 1, CCMIOID);
952
states[n_states] = state;
959
if (num_maillage == 0) {
960
printf(_("\n No mesh was specified; the first is read.\n\n"));
964
printf(_("\n Mesh number %d was specified.\n\n"), num_maillage);
965
if (num_maillage > 0 && num_maillage <= n_states)
966
state = states[num_maillage - 1];
967
else if (num_maillage > 0)
968
ecs_error(__FILE__, __LINE__, 0,
969
_("The specified mesh number (%d) is greater than\n"
970
"the number of meshes defined (%d) in file\n%s.\n"),
971
num_maillage, n_states, nom_fic_maillage);
973
ecs_error(__FILE__, __LINE__, 0,
974
_("The specified mesh number (%d) is negative."),
980
CCMIOEntityDescription(&err, state, &size, NULL);
982
if (err != kCCMIONoErr)
983
ecs_error(__FILE__, __LINE__, 0,
984
_("Error %d reading entity description in STAR-CCM+ file."),
989
ECS_MALLOC(desc, size + 1, char);
990
CCMIOEntityDescription(&err, state, NULL, desc);
991
printf(" Mesh/state description: %s)\n", desc);
996
CCMIONextEntity(&err, state, kCCMIOProcessor, &i, &processor);
998
if (err != kCCMIONoErr)
999
ecs_error(__FILE__, __LINE__, 0,
1000
_("Error %d reading processor information in STAR-CCM+ file."),
1003
CCMIOReadProcessor(&err, processor, &vertices, &topology, NULL, NULL);
1005
if (err != kCCMIONoErr)
1006
ecs_error(__FILE__, __LINE__, 0,
1007
_("Error %d reading vertices and topology information\n"
1008
"in STAR-CCM+ file."), (int)err);
1010
_read_mesh(vertices,
1013
liste_faces_internes,
1019
CCMIOCloseFile(&err, vertices);
1020
CCMIOCloseFile(&err, topology);
1022
CCMIOCloseFile(&err, root);
1024
/* Switch to preprocessor type structure */
1026
/* switching to indexes is done before appending faces so as to keep
1027
icel2 = -1 for boundary faces */
1031
/* boundary faces */
1033
tab_connect.nbr = liste_faces_bord->taille_connect;
1034
tab_connect.val = liste_faces_bord->connect;
1036
tab_label.nbr = nodes->n_nodes;
1037
tab_label.val = nodes->id;
1039
ecs_tab_int__ref_en_indice(tab_connect, tab_label, false);
1040
liste_faces_bord->connect = tab_connect.val;
1042
/* interior faces */
1044
tab_connect.nbr = liste_faces_internes->taille_connect;
1045
tab_connect.val = liste_faces_internes->connect;
1047
ecs_tab_int__ref_en_indice(tab_connect, tab_label, false);
1048
liste_faces_internes->connect = tab_connect.val;
1052
tab_label.nbr = liste_cels->n_cells;
1053
tab_label.val = liste_cels->id;
1054
tab_connect.nbr = liste_faces_bord->n_faces;
1056
/* For boundary faces, only icel1 is handled (icel2 = -1) */
1058
tab_connect.val = liste_faces_bord->icel1;
1059
ecs_tab_int__ref_en_indice(tab_connect, tab_label, false);
1060
liste_faces_bord->icel1 = tab_connect.val;
1062
/* Interior faces */
1064
tab_connect.nbr = liste_faces_internes->n_faces;
1066
tab_connect.val = liste_faces_internes->icel1;
1067
ecs_tab_int__ref_en_indice(tab_connect, tab_label, false);
1068
liste_faces_internes->icel1 = tab_connect.val;
1070
tab_connect.val = liste_faces_internes->icel2;
1071
ecs_tab_int__ref_en_indice(tab_connect, tab_label, false);
1072
liste_faces_internes->icel2 = tab_connect.val;
1074
/* shift ... n-1 to 1 ... n */
1076
for (isom = 0; isom < liste_faces_internes->taille_connect; isom++)
1077
liste_faces_internes->connect[isom] += 1;
1079
for (isom = 0; isom < liste_faces_bord->taille_connect; isom++)
1080
liste_faces_bord->connect[isom] += 1;
1082
for (ifac = 0; ifac < liste_faces_internes->n_faces; ifac++){
1083
assert(liste_faces_internes->icel1[ifac] > -1);
1084
liste_faces_internes->icel1[ifac] += 1;
1085
if (liste_faces_internes->icel2[ifac] != -1)
1086
liste_faces_internes->icel2[ifac] += 1;
1089
for (ifac = 0; ifac < liste_faces_bord->n_faces; ifac++)
1090
liste_faces_bord->icel1[ifac] += 1;
1092
/* Append boundary and interior faces, with interior faces first */
1094
taille_connect_bord = liste_faces_bord->taille_connect;
1095
taille_connect_interne = liste_faces_internes->taille_connect;
1097
taille_connect = taille_connect_bord + taille_connect_interne;
1099
nbr_fabord = liste_faces_bord->n_faces;
1100
nbr_faint = liste_faces_internes->n_faces;
1102
n_faces = nbr_fabord + nbr_faint;
1104
ECS_REALLOC(liste_faces_bord->connect, taille_connect, ecs_int_t);
1105
ECS_REALLOC(liste_faces_bord->icoul, n_faces, ecs_int_t);
1106
ECS_REALLOC(liste_faces_bord->icel1, n_faces, ecs_int_t);
1107
ECS_REALLOC(liste_faces_bord->icel2, n_faces, ecs_int_t);
1108
ECS_REALLOC(liste_faces_bord->nbr_n, n_faces, ecs_int_t);
1110
liste_faces = liste_faces_bord;
1112
for (isom = 0; isom < taille_connect_interne; isom++)
1113
liste_faces->connect[taille_connect_bord + isom ]
1114
= liste_faces_internes->connect[isom];
1116
for (ifac = 0; ifac < nbr_faint; ifac ++){
1117
liste_faces->icoul[nbr_fabord + ifac] = liste_faces_internes->icoul[ifac];
1118
liste_faces->icel1[nbr_fabord + ifac] = liste_faces_internes->icel1[ifac];
1119
liste_faces->icel2[nbr_fabord + ifac] = liste_faces_internes->icel2[ifac];
1120
liste_faces->nbr_n[nbr_fabord + ifac] = liste_faces_internes->nbr_n[ifac];
1123
liste_faces->taille_connect = taille_connect;
1124
liste_faces->n_faces = n_faces;
1126
/* Libération de la memoire */
1128
ECS_FREE(liste_faces_internes->icoul);
1129
ECS_FREE(liste_faces_internes->icel1);
1130
ECS_FREE(liste_faces_internes->icel2);
1131
ECS_FREE(liste_faces_internes->nbr_n);
1132
ECS_FREE(liste_faces_internes->connect);
1134
ECS_FREE(liste_faces_internes);
1136
/* Préparation de la connectivité cellule */
1138
ecs_pre_ccm__cel_fac(liste_faces,
1143
/* Remplissage des tableaux */
1145
maillage = ecs_pre_ccm__prepa_mail(nodes,
1151
ECS_FREE(nodes->id);
1154
ECS_FREE(liste_faces->icel1);
1155
ECS_FREE(liste_faces->icel2);
1156
ECS_FREE(liste_faces->nbr_n);
1157
ECS_FREE(liste_faces->icoul);
1159
ECS_FREE(liste_faces);
1161
ECS_FREE(liste_cels->icoul);
1162
ECS_FREE(liste_cels->id);
1164
ECS_FREE(liste_cels);
1166
/* Renvoi de la structure de maillage */
1171
/*----------------------------------------------------------------------------*/
1173
#endif /* HAVE_CCM */