14 #ifndef PAMGEN_MESH_STRUCTURE
15 #define PAMGEN_MESH_STRUCTURE
17 #ifdef HAVE_ZOLTAN2_PAMGEN
19 #include <Pamgen_config.h>
20 #include <create_inline_mesh.h>
22 #include <pamgen_im_exodusII.h>
23 #include <pamgen_im_ne_nemesisI.h>
37 void createMesh(
char * file_data,
int dimension,
const RCP<
const Comm<int>> &comm);
44 void computeElementCoordinates();
52 int num_node_set_nodes;
54 int num_side_set_elements;
55 int num_side_set_nodes;
57 int num_block_properties;
58 int num_node_set_properties;
59 int num_side_set_properties;
61 char title[MAX_STR_LENGTH];
64 double version_number;
66 double * element_coord;
68 char buffer[3][MAX_STR_LENGTH + 1];
71 int * element_order_map ;
73 int * global_element_numbers ;
74 int * global_node_numbers ;
78 char ** element_types ;
80 int * nodes_per_element ;
81 int * element_attributes ;
82 int ** elmt_node_linkage ;
86 int * num_elements_in_side_set ;
87 int * num_df_in_side_set ;
88 int **side_set_elements ;
89 int **side_set_faces ;
93 int * num_nodes_in_node_set ;
94 int * num_df_in_node_set ;
95 int **node_set_nodes ;
100 char* qaRecord[100][4];
101 char** info_records ;
104 int num_nodes_global;
105 int num_elems_global;
106 int num_elm_blks_global;
107 int num_node_sets_global;
108 int num_side_sets_global;
110 int num_proc_in_file;
116 int * elem_blk_ids_global ;
117 int * elem_blk_cnts_global ;
119 int * ns_ids_global ;
120 int * ns_cnts_global ;
121 int * ns_df_cnts_global ;
122 int * ss_ids_global ;
123 int * ss_cnts_global ;
124 int * ss_df_cnts_global ;
127 int num_internal_nodes;
128 int num_border_nodes;
129 int num_external_nodes;
130 int num_internal_elems;
131 int num_border_elems;
132 int num_node_comm_maps;
133 int num_elem_comm_maps;
135 int * internal_elements ;
136 int * border_elements ;
137 int * internal_nodes ;
139 int * external_nodes ;
141 int * node_cmap_node_cnts ;
142 int * node_cmap_ids ;
143 int * elem_cmap_elem_cnts ;
144 int * elem_cmap_ids ;
146 int ** comm_node_ids ;
147 int ** comm_node_proc_ids ;
148 int ** comm_elem_ids ;
149 int ** comm_side_ids ;
150 int ** comm_elem_proc_ids ;
155 PamgenMesh::~PamgenMesh()
158 Delete_Pamgen_Mesh();
164 for( i = 0; i < 100; i++){
166 free(this->qaRecord[i][j]);
171 free(this->element_coord);
175 free(this->element_order_map);
178 free(this->global_element_numbers);
181 if (this->num_nodes){
182 free(this->global_node_numbers);
187 free(this->block_id);
188 free(this->nodes_per_element);
189 free(this->element_attributes);
190 free(this->elements);
193 for(i = 0; i < this->num_elem_blk; i ++){
194 free(this->element_types[i]);
198 for(b = 0; b < this->num_elem_blk; b++){
199 free(this->elmt_node_linkage[b]);
201 free(this->element_types);
202 free(this->elmt_node_linkage);
205 if(this->num_node_sets){
207 for(i = 0; i < this->num_node_sets; i ++){
208 if(this->num_nodes_in_node_set[i]) {
209 free(this->node_set_nodes[i]);
212 free(this->node_set_id);
213 free(this->num_nodes_in_node_set);
214 free(this->node_set_nodes);
215 free(this->num_df_in_node_set);
220 if(this->num_side_sets){
222 for(i = 0; i < this->num_side_sets; i ++){
224 free(this->side_set_elements[i]);
225 free(this->side_set_faces[i]);
228 free(this->side_set_id);
229 free(this->num_elements_in_side_set);
230 free(this->num_df_in_side_set);
231 free(this->side_set_elements);
232 free(this->side_set_faces);
236 if(this->num_info_records) {
237 for(i = 0; i < this->num_info_records; i ++){
238 free(this->info_records[i]);
240 free(this->info_records);
246 free(this->elem_blk_ids_global);
247 free(this->elem_blk_cnts_global);
249 free(this->ns_ids_global);
250 free(this->ns_cnts_global);
251 free(this->ns_df_cnts_global);
252 free(this->ss_ids_global);
253 free(this->ss_cnts_global);
254 free(this->ss_df_cnts_global);
256 free(this->internal_elements);
257 free(this->border_elements);
258 free(this->internal_nodes);
259 free(this->border_nodes);
260 free(this->external_nodes);
262 if(this->num_node_comm_maps > 0){
264 for(j = 0; j < this->num_node_comm_maps; j++) {
265 free(this->comm_node_ids[j]);
266 free(this->comm_node_proc_ids[j]);
271 for(j = 0; j < this->num_elem_comm_maps; j++) {
272 free(this->comm_elem_ids[j]);
273 free(this->comm_side_ids[j]);
274 free(this->comm_elem_proc_ids[j]);
279 if(this->num_node_comm_maps > 0)
281 free(this->node_cmap_node_cnts);
282 free(this->node_cmap_ids);
283 free(this->comm_node_ids);
284 free(this->comm_node_proc_ids);
286 free(this->elem_cmap_elem_cnts);
287 free(this->elem_cmap_ids);
288 free(this->comm_elem_ids);
289 free(this->comm_side_ids);
290 free(this->comm_elem_proc_ids);
297 void PamgenMesh::storeMesh()
309 this->bptr[0] = this->buffer[0];
310 this->bptr[1] = this->buffer[1];
311 this->bptr[2] = this->buffer[2];
313 for(i = 0; i < 100; i++)
314 for(j=0; j<4; j++) this->qaRecord[i][j] = (
char*)malloc(MAX_STR_LENGTH+1) ;
317 error += im_ex_get_init (
id,
323 &this->num_node_sets,
324 &this->num_side_sets);
327 error += im_ex_inquire(
id, IM_EX_INQ_NS_NODE_LEN, (
int*)&this->num_node_set_nodes,
329 error += im_ex_inquire
330 (
id, IM_EX_INQ_NS_DF_LEN, (
int*)&this->num_node_set_dfs,
332 error += im_ex_inquire(
id, IM_EX_INQ_SS_ELEM_LEN, (
int*)&this->num_side_set_elements,
334 error += im_ex_inquire(
id, IM_EX_INQ_SS_NODE_LEN, (
int*)&this->num_side_set_nodes,
336 error += im_ex_inquire(
id, IM_EX_INQ_SS_DF_LEN, (
int*)&this->num_side_set_dfs,
341 error += im_ex_inquire(
id, IM_EX_INQ_API_VERS, &idum, &fdum, cdum);
343 this->version_number = (double) fdum;
345 this->version = (int) this->version_number;
349 error += im_ex_inquire(
id, IM_EX_INQ_EB_PROP, (
int*)&this->num_block_properties, &fdum, cdum);
351 error += im_ex_inquire(
id, IM_EX_INQ_NS_PROP, (
int*)&this->num_node_set_properties,
354 error += im_ex_inquire(
id, IM_EX_INQ_SS_PROP, (
int*)&this->num_side_set_properties,
357 this->coord = (
double *)malloc(this->num_nodes*this->num_dim*
sizeof(
double));
359 error += im_ex_get_coord(
id,this->coord,this->coord+this->num_nodes,this->coord+2*this->num_nodes);
362 error += im_ex_get_coord_names (
id, this->bptr);
365 this->element_order_map = (
int *)malloc(this->num_elem *
sizeof(
int));
366 error += im_ex_get_map(
id, this->element_order_map);
369 this->global_element_numbers = (
int *)malloc(this->num_elem*
sizeof(
int));
370 error += im_ex_get_elem_num_map(
id, this->global_element_numbers);
373 if (this->num_nodes){
374 this->global_node_numbers = (
int *)malloc(this->num_nodes *
sizeof(
int));
375 error += im_ex_get_node_num_map(
id, this->global_node_numbers);
381 this->block_id = (
int *)malloc(this->num_elem_blk*
sizeof(
int));
382 this->nodes_per_element = (
int *)malloc(this->num_elem_blk*
sizeof(
int));
383 this->element_attributes = (
int *)malloc(this->num_elem_blk*
sizeof(
int));
384 this->elements = (
int *)malloc(this->num_elem_blk*
sizeof(
int));
385 this->element_types = (
char **)malloc(this->num_elem_blk*
sizeof(
char *));
386 this->elmt_node_linkage = (
int **)malloc(this->num_elem_blk*
sizeof(
int*));
388 error += im_ex_get_elem_blk_ids(
id, this->block_id);
390 for(i = 0; i < this->num_elem_blk; i ++){
391 this->element_types[i] = (
char *)malloc((MAX_STR_LENGTH + 1)*
sizeof(char));
392 error += im_ex_get_elem_block(
id,
394 this->element_types[i],
395 (
int*)&(this->elements[i]),
396 (
int*)&(this->nodes_per_element[i]),
397 (
int*)&(this->element_attributes[i]));
401 for(b = 0; b < this->num_elem_blk; b++){
402 this->elmt_node_linkage[b] = (
int*)malloc(this->nodes_per_element[b]*this->elements[b]*
sizeof(
int));
403 error += im_ex_get_elem_conn(
id,this->block_id[b],this->elmt_node_linkage[b]);
407 if(this->num_node_sets){
408 this->node_set_id = (
int *) malloc(this->num_node_sets*
sizeof(
int));
409 this->num_nodes_in_node_set = (
int *) malloc(this->num_node_sets*
sizeof(
int));
410 this->node_set_nodes = (
int **)malloc(this->num_node_sets*
sizeof(
int*));
411 this->num_df_in_node_set = (
int *) malloc(this->num_node_sets*
sizeof(
int*));
413 error += im_ex_get_node_set_ids(
id, this->node_set_id);
416 for(i = 0; i < this->num_node_sets; i ++){
417 error += im_ex_get_node_set_param(
id, this->node_set_id[i],
418 (
int*)&this->num_nodes_in_node_set[i],
419 (
int*)&this->num_df_in_node_set[i]);
421 this->node_set_nodes[i] = NULL;
423 if(this->num_nodes_in_node_set[i]) {
424 this->node_set_nodes[i] = (
int *)malloc(this->num_nodes_in_node_set[i]*
sizeof(
int));
425 error += im_ex_get_node_set(
id, this->node_set_id[i], this->node_set_nodes[i]);
431 if(this->num_side_sets){
432 this->side_set_id = (
int*)malloc(this->num_side_sets*
sizeof(
int));
433 this->num_elements_in_side_set = (
int*)malloc(this->num_side_sets*
sizeof(
int));
434 this->num_df_in_side_set = (
int*)malloc(this->num_side_sets*
sizeof(
int));
435 this->side_set_elements = (
int**)malloc(this->num_side_sets*
sizeof(
int *));
436 this->side_set_faces = (
int **)malloc(this->num_side_sets*
sizeof(
int*));
438 error += im_ex_get_side_set_ids(
id, this->side_set_id);
439 for(i = 0; i < this->num_side_sets; i ++){
441 error += im_ex_get_side_set_param(
id, this->side_set_id[i],
442 (
int*)&this->num_elements_in_side_set[i],
443 (
int*)&this->num_df_in_side_set[i]);
445 ne = this->num_elements_in_side_set[i];
446 this->side_set_elements[i] = (
int*)malloc(ne*
sizeof(
int));
447 this->side_set_faces[i] = (
int*)malloc(ne*
sizeof(
int));
449 error += im_ex_get_side_set(
id, this->side_set_id[i],
450 this->side_set_elements[i],
451 this->side_set_faces[i]);
457 error += im_ex_inquire(
id, IM_EX_INQ_QA, (
int*)&this->num_qa_records, &fdum, cdum);
459 if(this->num_qa_records)error += im_ex_get_qa(
id,this->qaRecord);
462 error += im_ex_inquire(
id, IM_EX_INQ_INFO, (
int*)&this->num_info_records, &fdum, cdum);
463 if(this->num_info_records) {
464 this->info_records = (
char **)malloc(this->num_info_records*
sizeof(
char *));
465 for(i = 0; i < this->num_info_records; i ++){
466 this->info_records[i] = (
char *)malloc(MAX_STR_LENGTH+1);
468 error += im_ex_get_info(
id, this->info_records);
474 if ( im_ne_get_init_global(
id, &this->num_nodes_global, &this->num_elems_global,
475 &this->num_elm_blks_global, &this->num_node_sets_global,
476 &this->num_side_sets_global) < 0 )
481 if ( im_ne_get_init_info(
id, &this->num_total_proc, &this->num_proc_in_file, this->type) < 0 )
484 this->elem_blk_ids_global = (
int*)malloc(this->num_elm_blks_global*
sizeof(
int));
485 this->elem_blk_cnts_global = (
int*)malloc(this->num_elm_blks_global*
sizeof(
int));
487 if ( im_ne_get_eb_info_global(
id,this->elem_blk_ids_global,this->elem_blk_cnts_global) < 0 )
490 this->ns_ids_global = (
int *)malloc(this->num_node_sets_global*
sizeof(
int));
491 this->ns_cnts_global = (
int *)malloc(this->num_node_sets_global*
sizeof(
int));
492 this->ns_df_cnts_global = (
int *)malloc(this->num_node_sets_global*
sizeof(
int));
493 this->ss_ids_global = (
int *)malloc(this->num_side_sets_global*
sizeof(
int));
494 this->ss_cnts_global = (
int *)malloc(this->num_side_sets_global*
sizeof(
int));
495 this->ss_df_cnts_global = (
int *)malloc(this->num_side_sets_global*
sizeof(
int));
498 if ( this->num_node_sets_global > 0 ) {
499 if ( im_ne_get_ns_param_global(
id,this->ns_ids_global,this->ns_cnts_global,
500 this->ns_df_cnts_global) < 0 )++error;
503 if ( this->num_side_sets_global > 0 ) {
504 if ( im_ne_get_ss_param_global(
id,this->ss_ids_global,this->ss_cnts_global,
505 this->ss_df_cnts_global) < 0 ) ++error;
509 if ( im_ne_get_loadbal_param(
id,
510 &this->num_internal_nodes,
511 &this->num_border_nodes,
512 &this->num_external_nodes,
513 &this->num_internal_elems,
514 &this->num_border_elems,
515 &this->num_node_comm_maps,
516 &this->num_elem_comm_maps,
519 this->internal_elements = (
int *)malloc(this->num_internal_elems*
sizeof(
int));
520 this->border_elements = (
int *)malloc(this->num_border_elems*
sizeof(
int));
521 this->internal_nodes = (
int *)malloc(this->num_internal_nodes*
sizeof(
int));
522 this->border_nodes = (
int *)malloc(this->num_border_nodes*
sizeof(
int));
523 this->external_nodes = (
int *)malloc(this->num_external_nodes*
sizeof(
int));
525 if ( im_ne_get_elem_map(
id,
526 this->internal_elements,
527 this->border_elements,
530 if ( im_ne_get_node_map(
id,
531 this->internal_nodes,
533 this->external_nodes,
537 if(this->num_node_comm_maps > 0){
539 this->node_cmap_node_cnts = (
int*) malloc(this->num_node_comm_maps*
sizeof(
int));
540 this->node_cmap_ids = (
int*) malloc(this->num_node_comm_maps*
sizeof(
int));
541 this->comm_node_ids = (
int**)malloc(this->num_node_comm_maps*
sizeof(
int*));
542 this->comm_node_proc_ids = (
int**)malloc(this->num_node_comm_maps*
sizeof(
int*));
544 this->elem_cmap_elem_cnts = (
int*) malloc(this->num_elem_comm_maps*
sizeof(
int));
545 this->elem_cmap_ids = (
int*) malloc(this->num_elem_comm_maps*
sizeof(
int));
546 this->comm_elem_ids = (
int**)malloc(this->num_elem_comm_maps*
sizeof(
int*));
547 this->comm_side_ids = (
int**)malloc(this->num_elem_comm_maps*
sizeof(
int*));
548 this->comm_elem_proc_ids = (
int**)malloc(this->num_elem_comm_maps*
sizeof(
int*));
550 if ( im_ne_get_cmap_params(
id,
552 (
int*)this->node_cmap_node_cnts,
554 (
int*)this->elem_cmap_elem_cnts,
557 for(j = 0; j < this->num_node_comm_maps; j++) {
558 this->comm_node_ids[j] = (
int *)malloc(this->node_cmap_node_cnts[j]*
sizeof(
int));
559 this->comm_node_proc_ids[j] = (
int *)malloc(this->node_cmap_node_cnts[j]*
sizeof(
int));
560 if ( im_ne_get_node_cmap(
id,
561 this->node_cmap_ids[j],
562 this->comm_node_ids[j],
563 this->comm_node_proc_ids[j],
570 for(j = 0; j < this->num_elem_comm_maps; j++) {
571 this->comm_elem_ids[j] = (
int *)malloc(this->elem_cmap_elem_cnts[j]*
sizeof(
int));
572 this->comm_side_ids[j] = (
int *)malloc(this->elem_cmap_elem_cnts[j]*
sizeof(
int));
573 this->comm_elem_proc_ids[j] = (
int *)malloc(this->elem_cmap_elem_cnts[j]*
sizeof(
int));
574 if ( im_ne_get_elem_cmap(
id,
575 this->elem_cmap_ids[j],
576 this->comm_elem_ids[j],
577 this->comm_side_ids[j],
578 this->comm_elem_proc_ids[j],
587 this->computeElementCoordinates();
590 void PamgenMesh::computeElementCoordinates()
592 this->element_coord = (
double * )malloc(this->num_dim * this->num_elem *
sizeof(
double));
593 memset(this->element_coord, 0, this->num_dim * this->num_elem *
sizeof(
double));
599 for(
int i = 0; i < this->num_elem_blk; i++)
601 int els = this->elements[i];
602 int nperel = this->nodes_per_element[i];
604 int * connect = this->elmt_node_linkage[i];
606 for(
int j = 0; j < els; j++)
610 for(
int k = 0; k < nperel; k++)
612 n_id = connect[j*nperel + k]-1;
613 for(
int l = 0; l < this->num_dim; l++)
614 element_coord[el_count + l * this->num_elem] += this->coord[n_id + l *this->num_nodes];
618 for(
int k = 0; k < this->num_dim; k++)
619 element_coord[el_count + k*this->num_elem] /= nperel;
627 void PamgenMesh::createMesh(
char * file_data,
int dimension,
const RCP<
const Comm<int>> &comm)
629 int rank = comm->getRank();
630 int nproc = comm->getSize();
631 long long cr_result = Create_Pamgen_Mesh(file_data, dimension, rank, nproc, INT_MAX);
633 if (cr_result == ERROR_PARSING_DEFINITION){
634 long long essz = getPamgenEchoStreamSize();
635 char * echo_char_array = (
char *)malloc(essz+1);
636 printf(
"PARSE ERROR\n");
637 echo_char_array[essz] =
'\0';
638 echo_char_array = getPamgenEchoStream(echo_char_array);
639 if(echo_char_array)printf(
"%s",echo_char_array);
640 if(cr_result == ERROR_CREATING_IMD)printf(
"ERROR Failure to create Inline_Mesh_Desc creation\n");
641 if(echo_char_array)free(echo_char_array);
644 if(cr_result == ERROR_CREATING_MS){
645 long long essz = getPamgenErrorStreamSize();
646 char * error_char_array = (
char *)malloc(essz+1);
647 error_char_array[essz] =
'\0';
648 error_char_array = getPamgenErrorStream(error_char_array);
649 if(error_char_array)printf(
"%s",error_char_array);
650 printf(
"\nERROR Failure to create Mesh_Specification\n");
651 if(error_char_array)free(error_char_array);
655 long long wssz = getPamgenWarningStreamSize();
657 char * warning_char_array = (
char *)malloc(wssz+1);
658 warning_char_array[wssz] =
'\0';
659 warning_char_array = getPamgenWarningStream(warning_char_array);
660 printf(
"WARNING Records\n");
661 printf(
"%s",warning_char_array);
662 free(warning_char_array);