FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
hec2rcap.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 
6 #include <stdio.h>
7 #include <string.h>
8 #include "hecmw.h"
9 
10 #define DEF_MESH_ID "fstrMSH"
11 #define DEF_RCAP_ID "revocap"
12 
13 static
14 char* rcap_fname_header = NULL;
15 
16 
17 /*=============================================================================
18  * convert
19  *===========================================================================*/
20 
21 
22 static
23 int conv_node( struct hecmwST_local_mesh* mesh, FILE* fp )
24 {
25  int i, j;
26  int node_n = mesh->n_node;
27 
28  fprintf( fp, "Number_of_Node_Ids %d\n", node_n );
29  j = 0;
30  for( i=0; i<node_n; i++, j+=3) {
31  int nid = mesh->global_node_ID[i];
32  double x = mesh->node[j];
33  double y = mesh->node[j+1];
34  double z = mesh->node[j+2];
35  fprintf( fp,"%d %lf %lf %lf\n", nid, x, y, z );
36  }
37  return 0;
38 }
39 
40 static
41 int conv_elem( struct hecmwST_local_mesh* mesh, FILE* fp )
42 {
43  int i, j;
44  int is,ie, icel;
45  int etype;
46  char* rcap_etype;
47  int nn, elem_n;
48  int etype_count;
49 
50  int tbl341[] = { 0,1,2,3 };
51  int tbl342[] = { 0,1,2,3,6,5,7,4,9,8 };
52  int tbl361[] = { 0,1,2,3,4,5,6,7 };
53  int tbl362[] = { 0,1,2,3,4,5,6,7,8,9,10,11,16,17,18,19,12,13,14,15 };
54  int tbl351[] = { 0,1,2,3,4,5 };
55  int tbl371[] = { 4,0,3,2,1 };
56  int* tbl;
57 
58  for( i= 0, etype_count= 0, elem_n= 0; i<mesh->n_elem_type; i++ ) {
59  is = mesh->elem_type_index[i];
60  ie = mesh->elem_type_index[i+1];
61  etype = mesh->elem_type[is];
62  if( etype >= 900 ) {
63  /* no structural element */
64  continue;
65  }
66  etype_count++;
67  elem_n += ie - is;
68  }
69  if( etype_count == 1 ) {
70  switch( etype ) {
71  case 341: nn = 4; rcap_etype = "Tet4"; tbl=tbl341; break;
72  case 342: nn = 10; rcap_etype = "Tet10"; tbl=tbl342; break;
73  case 361: nn = 8; rcap_etype = "Hex8"; tbl=tbl361; break;
74  case 362: nn = 20; rcap_etype = "Hex20"; tbl=tbl362; break;
75  case 351: nn = 6; rcap_etype = "Wed6"; tbl=tbl351; break;
76  case 371: nn = 5; rcap_etype = "Pyr5"; tbl=tbl371; break;
77  default:
78  fprintf( stderr, "#Error : not supported element type %d\n", etype );
79  return 1;
80  }
81  fprintf( fp, "Element_Type %s\n", rcap_etype );
82  } else {
83  fprintf( fp, "Element_Type Multi\n" );
84  }
85  fprintf( fp, "Number_of_Elemen_Ids %d\n", elem_n );
86 
87  for( i= 0; i<mesh->n_elem_type; i++ ) {
88  is = mesh->elem_type_index[i];
89  ie = mesh->elem_type_index[i+1];
90  etype = mesh->elem_type[is];
91  if( etype >= 900 ) {
92  /* no structural element */
93  continue;
94  }
95  for( icel = is; icel<ie; icel++ ) {
96  int eid = mesh->global_elem_ID[icel];
97  int n0 = mesh->elem_node_index[icel];
98  fprintf( fp, "%d", eid );
99  if( etype_count > 1 ) {
100  switch( etype ) {
101  case 341: nn = 4; rcap_etype = "Tet4"; tbl=tbl341; break;
102  case 342: nn = 10; rcap_etype = "Tet10"; tbl=tbl342; break;
103  case 361: nn = 8; rcap_etype = "Hex8"; tbl=tbl361; break;
104  case 362: nn = 20; rcap_etype = "Hex20"; tbl=tbl362; break;
105  case 351: nn = 6; rcap_etype = "Wed6"; tbl=tbl351; break;
106  case 371: nn = 5; rcap_etype = "Pyr5"; tbl=tbl371; break;
107  default:
108  fprintf( stderr, "#Error : not supported element type %d\n", etype );
109  return 1;
110  }
111  fprintf( fp, " %s", rcap_etype);
112  }
113  for( j=0; j<nn; j++) {
114  int id = mesh->elem_node_item[n0+tbl[j]];
115  int nid = mesh->global_node_ID[id-1];
116  fprintf( fp, " %d", nid );
117  }
118  fprintf( fp, "\n" );
119  }
120  }
121  return 0;
122 }
123 
124 
125 static
126 int convert( struct hecmwST_local_mesh* mesh, FILE* fp )
127 {
128  fprintf( fp, "Solid_PartID %d\n", mesh->my_rank );
129  if( conv_elem( mesh, fp ) ) return 1;
130  if( conv_node( mesh, fp ) ) return 1;
131  return 0;
132 }
133 
134 
135 /*=============================================================================
136  * main & etc
137  *===========================================================================*/
138 
139 /*
140 static
141 void help(void)
142 {
143 }
144 */
145 
146 static
147 int set_param( int argc, char** argv )
148 {
149  if( argc < 2 ) {
150  fprintf( stderr, "#Error : revocap mesh file name is required\n" );
151  return 1;
152  }
153  rcap_fname_header = argv[1];
154  return 0;
155 }
156 
157 
158 int main( int argc, char** argv )
159 {
160  /* input mesh */
161  char* name_ID = DEF_MESH_ID;
162  struct hecmwST_local_mesh* mesh = NULL;
163 
164  /* output mesh */
165  char rcap_fname[HECMW_FILENAME_LEN +1];
166  struct hecmw_ctrl_meshfiles *files;
167  char dirname[HECMW_HEADER_LEN+1];
168  char buff[HECMW_HEADER_LEN+1];
169  char *ptoken, *ntoken;
170  FILE* fp;
171 
172  if( HECMW_init(&argc, &argv) ) return 1;
173  if( set_param(argc,argv) ) {
175  }
176 
177  mesh = HECMW_get_mesh( name_ID );
178  if( mesh == NULL ) {
180  }
181  printf( "domain #%d : get_mesh ok\n", mesh->my_rank );
182 
183  files = HECMW_ctrl_get_meshfiles_header( name_ID );
184  if( files == NULL ) {
186  }
187  strcpy( buff, files->meshfiles[0].filename );
188  strcpy( dirname, "" );
189  ptoken = strtok (buff, "/" );
190  ntoken = strtok( NULL, "/" );
191  while( ntoken ) {
192  strcat( dirname, ptoken );
193  strcat( dirname, "/" );
194  ptoken = ntoken;
195  ntoken = strtok( NULL, "/" );
196  }
197  sprintf( rcap_fname, "%s%s.%d", dirname, rcap_fname_header, mesh->my_rank );
198 
199  fp = fopen( rcap_fname, "w" );
200  if( !fp ) {
201  fprintf( stderr, "#Error at domain #%d : Cannot open revocap file %s\n",
202  mesh->my_rank, rcap_fname );
204  }
205 
206  if( convert( mesh, fp ) ) {
208  }
209 
210  fclose( fp );
211  printf( "completed\n" );
212  HECMW_finalize();
213  return 0;
214 }
hecmwST_local_mesh::my_rank
int my_rank
Definition: hecmw_struct.h:212
hecmwST_local_mesh::global_node_ID
int * global_node_ID
Definition: hecmw_struct.h:168
hecmwST_local_mesh::elem_node_item
int * elem_node_item
Definition: hecmw_struct.h:196
mesh
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
HECMW_comm_get_comm
HECMW_Comm HECMW_comm_get_comm(void)
Definition: hecmw_comm.c:699
HECMW_ctrl_get_meshfiles_header
struct hecmw_ctrl_meshfiles * HECMW_ctrl_get_meshfiles_header(char *name_ID)
Definition: hecmw_control.c:2209
hecmwST_local_mesh
Definition: hecmw_struct.h:139
hecmwST_local_mesh::elem_type
int * elem_type
Definition: hecmw_struct.h:191
hecmw.h
HECMW_finalize
int HECMW_finalize(void)
Definition: hecmw_finalize.c:9
hecmwST_local_mesh::n_node
int n_node
Definition: hecmw_struct.h:161
hecmwST_local_mesh::node
double * node
Definition: hecmw_struct.h:170
DEF_MESH_ID
#define DEF_MESH_ID
Definition: hec2rcap.c:10
hecmwST_local_mesh::elem_node_index
int * elem_node_index
Definition: hecmw_struct.h:195
HECMW_init
int HECMW_init(int *argc, char ***argv)
Definition: hecmw_init.c:24
hecmwST_local_mesh::n_elem_type
int n_elem_type
Definition: hecmw_struct.h:192
HECMW_get_mesh
struct hecmwST_local_mesh * HECMW_get_mesh(char *name_ID)
Definition: hecmw_io_get_mesh.c:62
hecmwST_local_mesh::elem_type_index
int * elem_type_index
Definition: hecmw_struct.h:193
hecmw_ctrl_meshfiles
Definition: hecmw_control.h:39
main
int main(int argc, char **argv)
Definition: hec2rcap.c:158
hecmw_ctrl_meshfile::filename
char * filename
Definition: hecmw_control.h:34
hecmw_ctrl_meshfiles::meshfiles
struct hecmw_ctrl_meshfile * meshfiles
Definition: hecmw_control.h:42
NULL
#define NULL
Definition: hecmw_io_nastran.c:30
HECMW_FILENAME_LEN
#define HECMW_FILENAME_LEN
Definition: hecmw_config.h:72
hecmwST_local_mesh::global_elem_ID
int * global_elem_ID
Definition: hecmw_struct.h:190
HECMW_abort
void HECMW_abort(HECMW_Comm comm)
Definition: hecmw_util.c:88
HECMW_HEADER_LEN
#define HECMW_HEADER_LEN
Definition: hecmw_config.h:68