50 #ifndef PAMGEN_MESH_STRUCTURE 
   51 #define PAMGEN_MESH_STRUCTURE 
   53 #ifdef HAVE_ZOLTAN2_PAMGEN 
   55 #include <Pamgen_config.h> 
   56 #include <create_inline_mesh.h> 
   58 #include <pamgen_im_exodusII.h> 
   59 #include <pamgen_im_ne_nemesisI.h> 
   73   void createMesh(
char * file_data, 
int dimension, 
const RCP<
const Comm<int>> &comm);
 
   80   void computeElementCoordinates();
 
   88   int num_node_set_nodes;
 
   90   int num_side_set_elements;
 
   91   int num_side_set_nodes;
 
   93   int num_block_properties;
 
   94   int num_node_set_properties;
 
   95   int num_side_set_properties;
 
   97   char title[MAX_STR_LENGTH];
 
  100   double version_number;
 
  102   double * element_coord;
 
  104   char buffer[3][MAX_STR_LENGTH + 1];
 
  107   int * element_order_map ;
 
  109   int * global_element_numbers ;
 
  110   int * global_node_numbers ;
 
  114   char ** element_types ;
 
  116   int *   nodes_per_element ;
 
  117   int *   element_attributes ;
 
  118   int ** elmt_node_linkage ;
 
  122   int * num_elements_in_side_set ;
 
  123   int * num_df_in_side_set ;
 
  124   int **side_set_elements ;
 
  125   int **side_set_faces ;
 
  129   int * num_nodes_in_node_set ;
 
  130   int * num_df_in_node_set ;
 
  131   int **node_set_nodes  ;
 
  135   int num_info_records;
 
  136   char* qaRecord[100][4];
 
  137   char** info_records ;
 
  140   int num_nodes_global;
 
  141   int num_elems_global;
 
  142   int num_elm_blks_global;
 
  143   int num_node_sets_global;
 
  144   int num_side_sets_global;
 
  146   int num_proc_in_file;
 
  152   int * elem_blk_ids_global ;
 
  153   int * elem_blk_cnts_global  ;
 
  155   int * ns_ids_global ;
 
  156   int * ns_cnts_global ;
 
  157   int * ns_df_cnts_global ;
 
  158   int * ss_ids_global ;
 
  159   int * ss_cnts_global ;
 
  160   int * ss_df_cnts_global ;
 
  163   int num_internal_nodes;
 
  164   int num_border_nodes;
 
  165   int num_external_nodes;
 
  166   int num_internal_elems;
 
  167   int num_border_elems;
 
  168   int num_node_comm_maps;
 
  169   int num_elem_comm_maps;
 
  171   int * internal_elements ;
 
  172   int * border_elements ;
 
  173   int * internal_nodes ;
 
  175   int * external_nodes ;
 
  177   int * node_cmap_node_cnts ;
 
  178   int * node_cmap_ids       ;
 
  179   int * elem_cmap_elem_cnts ;
 
  180   int * elem_cmap_ids       ;
 
  182   int ** comm_node_ids       ;
 
  183   int ** comm_node_proc_ids  ;
 
  184   int ** comm_elem_ids       ;
 
  185   int ** comm_side_ids       ;
 
  186   int ** comm_elem_proc_ids  ;
 
  191 PamgenMesh::~PamgenMesh()
 
  194   Delete_Pamgen_Mesh();
 
  200   for( i = 0; i < 100; i++){
 
  202       free(this->qaRecord[i][j]);
 
  207   free(this->element_coord);
 
  211     free(this->element_order_map);
 
  214       free(this->global_element_numbers);
 
  217     if (this->num_nodes){
 
  218       free(this->global_node_numbers);
 
  223     free(this->block_id);
 
  224     free(this->nodes_per_element);
 
  225     free(this->element_attributes);
 
  226     free(this->elements);
 
  229     for(i = 0; i < this->num_elem_blk; i ++){
 
  230       free(this->element_types[i]);
 
  234     for(b = 0; b < this->num_elem_blk; b++){
 
  235       free(this->elmt_node_linkage[b]);
 
  237     free(this->element_types);
 
  238     free(this->elmt_node_linkage);
 
  241     if(this->num_node_sets){
 
  243       for(i = 0; i < this->num_node_sets; i ++){
 
  244         if(this->num_nodes_in_node_set[i]) {
 
  245           free(this->node_set_nodes[i]);
 
  248       free(this->node_set_id);
 
  249       free(this->num_nodes_in_node_set);
 
  250       free(this->node_set_nodes);
 
  251       free(this->num_df_in_node_set);
 
  256     if(this->num_side_sets){
 
  258       for(i = 0; i < this->num_side_sets; i ++){
 
  260         free(this->side_set_elements[i]);
 
  261         free(this->side_set_faces[i]);
 
  264       free(this->side_set_id);
 
  265       free(this->num_elements_in_side_set);
 
  266       free(this->num_df_in_side_set);
 
  267       free(this->side_set_elements);
 
  268       free(this->side_set_faces);
 
  272     if(this->num_info_records) {
 
  273       for(i = 0; i < this->num_info_records; i ++){
 
  274         free(this->info_records[i]);
 
  276       free(this->info_records);
 
  282     free(this->elem_blk_ids_global);
 
  283     free(this->elem_blk_cnts_global);
 
  285     free(this->ns_ids_global);
 
  286     free(this->ns_cnts_global);
 
  287     free(this->ns_df_cnts_global);
 
  288     free(this->ss_ids_global);
 
  289     free(this->ss_cnts_global);
 
  290     free(this->ss_df_cnts_global);
 
  292     free(this->internal_elements);
 
  293     free(this->border_elements);
 
  294     free(this->internal_nodes);
 
  295     free(this->border_nodes);
 
  296     free(this->external_nodes);
 
  298     if(this->num_node_comm_maps > 0){
 
  300       for(j = 0; j < this->num_node_comm_maps; j++) {
 
  301         free(this->comm_node_ids[j]);
 
  302         free(this->comm_node_proc_ids[j]);
 
  307       for(j = 0; j < this->num_elem_comm_maps; j++) {
 
  308         free(this->comm_elem_ids[j]);
 
  309         free(this->comm_side_ids[j]);
 
  310         free(this->comm_elem_proc_ids[j]);
 
  315     if(this->num_node_comm_maps > 0)
 
  317       free(this->node_cmap_node_cnts);
 
  318       free(this->node_cmap_ids);
 
  319       free(this->comm_node_ids);
 
  320       free(this->comm_node_proc_ids);
 
  322       free(this->elem_cmap_elem_cnts);
 
  323       free(this->elem_cmap_ids);
 
  324       free(this->comm_elem_ids);
 
  325       free(this->comm_side_ids);
 
  326       free(this->comm_elem_proc_ids);
 
  333 void PamgenMesh::storeMesh()
 
  345   this->bptr[0] = this->buffer[0];
 
  346   this->bptr[1] = this->buffer[1];
 
  347   this->bptr[2] = this->buffer[2];
 
  349   for(i = 0; i < 100; i++)
 
  350     for(j=0; j<4; j++) this->qaRecord[i][j] = (
char*)malloc(MAX_STR_LENGTH+1) ;
 
  353   error += im_ex_get_init (  
id,
 
  359                            &this->num_node_sets,
 
  360                            &this->num_side_sets);
 
  363   error += im_ex_inquire(
id, IM_EX_INQ_NS_NODE_LEN, (
int*)&this->num_node_set_nodes,
 
  365   error += im_ex_inquire
 
  366   (
id, IM_EX_INQ_NS_DF_LEN,   (
int*)&this->num_node_set_dfs,
 
  368   error += im_ex_inquire(
id, IM_EX_INQ_SS_ELEM_LEN, (
int*)&this->num_side_set_elements,
 
  370   error += im_ex_inquire(
id, IM_EX_INQ_SS_NODE_LEN, (
int*)&this->num_side_set_nodes,
 
  372   error += im_ex_inquire(
id, IM_EX_INQ_SS_DF_LEN,   (
int*)&this->num_side_set_dfs,
 
  377   error += im_ex_inquire(
id, IM_EX_INQ_API_VERS, &idum, &fdum, cdum);
 
  379   this->version_number = (double) fdum;
 
  381   this->version = (int) this->version_number;
 
  385   error += im_ex_inquire(
id, IM_EX_INQ_EB_PROP, (
int*)&this->num_block_properties, &fdum, cdum);
 
  387   error += im_ex_inquire(
id, IM_EX_INQ_NS_PROP, (
int*)&this->num_node_set_properties,
 
  390   error += im_ex_inquire(
id, IM_EX_INQ_SS_PROP, (
int*)&this->num_side_set_properties,
 
  393   this->coord = (
double *)malloc(this->num_nodes*this->num_dim*
sizeof(
double));
 
  395   error += im_ex_get_coord(
id,this->coord,this->coord+this->num_nodes,this->coord+2*this->num_nodes);
 
  398   error += im_ex_get_coord_names (
id, this->bptr);
 
  401     this->element_order_map = (
int *)malloc(this->num_elem * 
sizeof(
int));
 
  402     error += im_ex_get_map(
id, this->element_order_map);
 
  405       this->global_element_numbers = (
int *)malloc(this->num_elem*
sizeof(
int));
 
  406       error += im_ex_get_elem_num_map(
id, this->global_element_numbers);
 
  409     if (this->num_nodes){
 
  410       this->global_node_numbers = (
int *)malloc(this->num_nodes * 
sizeof(
int));
 
  411       error += im_ex_get_node_num_map(
id, this->global_node_numbers);
 
  417     this->block_id           = (
int *)malloc(this->num_elem_blk*
sizeof(
int));
 
  418     this->nodes_per_element  = (
int *)malloc(this->num_elem_blk*
sizeof(
int));
 
  419     this->element_attributes = (
int *)malloc(this->num_elem_blk*
sizeof(
int));
 
  420     this->elements           = (
int *)malloc(this->num_elem_blk*
sizeof(
int));
 
  421     this->element_types      = (
char **)malloc(this->num_elem_blk*
sizeof(
char *));
 
  422     this->elmt_node_linkage  = (
int **)malloc(this->num_elem_blk*
sizeof(
int*));
 
  424     error += im_ex_get_elem_blk_ids(
id, this->block_id);
 
  426     for(i = 0; i < this->num_elem_blk; i ++){
 
  427       this->element_types[i] = (
char *)malloc((MAX_STR_LENGTH + 1)*
sizeof(char));
 
  428       error += im_ex_get_elem_block(
id,
 
  430                                     this->element_types[i],
 
  431                                     (
int*)&(this->elements[i]),
 
  432                                     (
int*)&(this->nodes_per_element[i]),
 
  433                                     (
int*)&(this->element_attributes[i]));
 
  437     for(b = 0; b < this->num_elem_blk; b++){
 
  438       this->elmt_node_linkage[b] = (
int*)malloc(this->nodes_per_element[b]*this->elements[b]*
sizeof(
int));
 
  439       error += im_ex_get_elem_conn(
id,this->block_id[b],this->elmt_node_linkage[b]);
 
  443     if(this->num_node_sets){
 
  444       this->node_set_id           = (
int *) malloc(this->num_node_sets*
sizeof(
int));
 
  445       this->num_nodes_in_node_set = (
int *) malloc(this->num_node_sets*
sizeof(
int));
 
  446       this->node_set_nodes        = (
int **)malloc(this->num_node_sets*
sizeof(
int*));
 
  447       this->num_df_in_node_set    = (
int *) malloc(this->num_node_sets*
sizeof(
int*));
 
  449       error += im_ex_get_node_set_ids(
id, this->node_set_id);
 
  452       for(i = 0; i < this->num_node_sets; i ++){
 
  453         error += im_ex_get_node_set_param(
id, this->node_set_id[i],
 
  454                                           (
int*)&this->num_nodes_in_node_set[i],
 
  455                                           (
int*)&this->num_df_in_node_set[i]);
 
  457         this->node_set_nodes[i] = NULL;
 
  459         if(this->num_nodes_in_node_set[i]) {
 
  460           this->node_set_nodes[i] = (
int *)malloc(this->num_nodes_in_node_set[i]*
sizeof(
int));
 
  461           error += im_ex_get_node_set(
id, this->node_set_id[i], this->node_set_nodes[i]);
 
  467     if(this->num_side_sets){
 
  468       this->side_set_id = (
int*)malloc(this->num_side_sets*
sizeof(
int));
 
  469       this->num_elements_in_side_set = (
int*)malloc(this->num_side_sets*
sizeof(
int));
 
  470       this->num_df_in_side_set = (
int*)malloc(this->num_side_sets*
sizeof(
int));
 
  471       this->side_set_elements = (
int**)malloc(this->num_side_sets*
sizeof(
int *));
 
  472       this->side_set_faces = (
int **)malloc(this->num_side_sets*
sizeof(
int*));
 
  474       error += im_ex_get_side_set_ids(
id, this->side_set_id);
 
  475       for(i = 0; i < this->num_side_sets; i ++){
 
  477         error += im_ex_get_side_set_param(
id, this->side_set_id[i],
 
  478                                           (
int*)&this->num_elements_in_side_set[i],
 
  479                                           (
int*)&this->num_df_in_side_set[i]);
 
  481         ne = this->num_elements_in_side_set[i];
 
  482         this->side_set_elements[i] = (
int*)malloc(ne*
sizeof(
int));
 
  483         this->side_set_faces[i] = (
int*)malloc(ne*
sizeof(
int));
 
  485           error += im_ex_get_side_set(
id, this->side_set_id[i],
 
  486                                       this->side_set_elements[i],
 
  487                                       this->side_set_faces[i]);
 
  493     error += im_ex_inquire(
id, IM_EX_INQ_QA, (
int*)&this->num_qa_records, &fdum, cdum);
 
  495     if(this->num_qa_records)error +=  im_ex_get_qa(
id,this->qaRecord);
 
  498     error += im_ex_inquire(
id, IM_EX_INQ_INFO, (
int*)&this->num_info_records, &fdum, cdum);
 
  499     if(this->num_info_records) {
 
  500       this->info_records = (
char **)malloc(this->num_info_records*
sizeof(
char *));
 
  501       for(i = 0; i < this->num_info_records; i ++){
 
  502         this->info_records[i] = (
char *)malloc(MAX_STR_LENGTH+1);
 
  504       error += im_ex_get_info(
id, this->info_records);
 
  510     if ( im_ne_get_init_global(
id, &this->num_nodes_global, &this->num_elems_global,
 
  511                                &this->num_elm_blks_global, &this->num_node_sets_global,
 
  512                                &this->num_side_sets_global) < 0 )
 
  517     if ( im_ne_get_init_info(
id, &this->num_total_proc, &this->num_proc_in_file, this->type) < 0 )
 
  520     this->elem_blk_ids_global = (
int*)malloc(this->num_elm_blks_global*
sizeof(
int));
 
  521     this->elem_blk_cnts_global = (
int*)malloc(this->num_elm_blks_global*
sizeof(
int));
 
  523     if ( im_ne_get_eb_info_global(
id,this->elem_blk_ids_global,this->elem_blk_cnts_global) < 0 )
 
  526     this->ns_ids_global = (
int *)malloc(this->num_node_sets_global*
sizeof(
int));
 
  527     this->ns_cnts_global = (
int *)malloc(this->num_node_sets_global*
sizeof(
int));
 
  528     this->ns_df_cnts_global = (
int *)malloc(this->num_node_sets_global*
sizeof(
int));
 
  529     this->ss_ids_global = (
int *)malloc(this->num_side_sets_global*
sizeof(
int));
 
  530     this->ss_cnts_global = (
int *)malloc(this->num_side_sets_global*
sizeof(
int));
 
  531     this->ss_df_cnts_global = (
int *)malloc(this->num_side_sets_global*
sizeof(
int));
 
  534     if ( this->num_node_sets_global > 0 ) {
 
  535       if ( im_ne_get_ns_param_global(
id,this->ns_ids_global,this->ns_cnts_global,
 
  536                                      this->ns_df_cnts_global) < 0 )++error;
 
  539     if ( this->num_side_sets_global > 0 ) {
 
  540       if ( im_ne_get_ss_param_global(
id,this->ss_ids_global,this->ss_cnts_global,
 
  541                                      this->ss_df_cnts_global) < 0 )  ++error;
 
  545     if ( im_ne_get_loadbal_param( 
id,
 
  546                                  &this->num_internal_nodes,
 
  547                                  &this->num_border_nodes,
 
  548                                  &this->num_external_nodes,
 
  549                                  &this->num_internal_elems,
 
  550                                  &this->num_border_elems,
 
  551                                  &this->num_node_comm_maps,
 
  552                                  &this->num_elem_comm_maps,
 
  555     this->internal_elements = (
int *)malloc(this->num_internal_elems*
sizeof(
int));
 
  556     this->border_elements   = (
int *)malloc(this->num_border_elems*
sizeof(
int));
 
  557     this->internal_nodes    = (
int *)malloc(this->num_internal_nodes*
sizeof(
int));
 
  558     this->border_nodes      = (
int *)malloc(this->num_border_nodes*
sizeof(
int));
 
  559     this->external_nodes    = (
int *)malloc(this->num_external_nodes*
sizeof(
int));
 
  561     if ( im_ne_get_elem_map( 
id,
 
  562                             this->internal_elements,
 
  563                             this->border_elements,
 
  566     if ( im_ne_get_node_map( 
id,
 
  567                             this->internal_nodes,
 
  569                             this->external_nodes,
 
  573     if(this->num_node_comm_maps > 0){
 
  575       this->node_cmap_node_cnts = (
int*) malloc(this->num_node_comm_maps*
sizeof(
int));
 
  576       this->node_cmap_ids       = (
int*) malloc(this->num_node_comm_maps*
sizeof(
int));
 
  577       this->comm_node_ids       = (
int**)malloc(this->num_node_comm_maps*
sizeof(
int*));
 
  578       this->comm_node_proc_ids  = (
int**)malloc(this->num_node_comm_maps*
sizeof(
int*));
 
  580       this->elem_cmap_elem_cnts = (
int*) malloc(this->num_elem_comm_maps*
sizeof(
int));
 
  581       this->elem_cmap_ids       = (
int*) malloc(this->num_elem_comm_maps*
sizeof(
int));
 
  582       this->comm_elem_ids       = (
int**)malloc(this->num_elem_comm_maps*
sizeof(
int*));
 
  583       this->comm_side_ids       = (
int**)malloc(this->num_elem_comm_maps*
sizeof(
int*));
 
  584       this->comm_elem_proc_ids  = (
int**)malloc(this->num_elem_comm_maps*
sizeof(
int*));
 
  586       if ( im_ne_get_cmap_params( 
id,
 
  588                                  (
int*)this->node_cmap_node_cnts,
 
  590                                  (
int*)this->elem_cmap_elem_cnts,
 
  593       for(j = 0; j < this->num_node_comm_maps; j++) {
 
  594         this->comm_node_ids[j]       = (
int *)malloc(this->node_cmap_node_cnts[j]*
sizeof(
int));
 
  595         this->comm_node_proc_ids[j]  = (
int *)malloc(this->node_cmap_node_cnts[j]*
sizeof(
int));
 
  596         if ( im_ne_get_node_cmap( 
id,
 
  597                                  this->node_cmap_ids[j],
 
  598                                  this->comm_node_ids[j],
 
  599                                  this->comm_node_proc_ids[j],
 
  606       for(j = 0; j < this->num_elem_comm_maps; j++) {
 
  607         this->comm_elem_ids[j]       = (
int *)malloc(this->elem_cmap_elem_cnts[j]*
sizeof(
int));
 
  608         this->comm_side_ids[j]       = (
int *)malloc(this->elem_cmap_elem_cnts[j]*
sizeof(
int));
 
  609         this->comm_elem_proc_ids[j]  = (
int *)malloc(this->elem_cmap_elem_cnts[j]*
sizeof(
int));
 
  610         if ( im_ne_get_elem_cmap( 
id,
 
  611                                  this->elem_cmap_ids[j],
 
  612                                  this->comm_elem_ids[j],
 
  613                                  this->comm_side_ids[j],
 
  614                                  this->comm_elem_proc_ids[j],
 
  623   this->computeElementCoordinates();
 
  626 void PamgenMesh::computeElementCoordinates()
 
  628   this->element_coord = (
double * )malloc(this->num_dim * this->num_elem * 
sizeof(
double));
 
  629   memset(this->element_coord, 0, this->num_dim * this->num_elem * 
sizeof(
double));
 
  635   for(
int i = 0; i <  this->num_elem_blk; i++)
 
  637     int els = this->elements[i];
 
  638     int nperel = this->nodes_per_element[i];
 
  640     int * connect = this->elmt_node_linkage[i]; 
 
  642     for(
int j = 0; j < els; j++)
 
  646       for(
int k = 0; k < nperel; k++)
 
  648         n_id = connect[j*nperel + k]-1;
 
  649         for(
int l = 0; l < this->num_dim; l++)
 
  650           element_coord[el_count + l * this->num_elem] += this->coord[n_id + l *this->num_nodes];
 
  654       for(
int k = 0; k < this->num_dim; k++)
 
  655         element_coord[el_count + k*this->num_elem] /= nperel;
 
  663 void PamgenMesh::createMesh(
char * file_data, 
int dimension, 
const RCP<
const Comm<int>> &comm)
 
  665   int rank = comm->getRank();
 
  666   int nproc = comm->getSize();
 
  667   long long cr_result = Create_Pamgen_Mesh(file_data, dimension, rank, nproc, INT_MAX);
 
  669   if (cr_result == ERROR_PARSING_DEFINITION){
 
  670     long long essz = getPamgenEchoStreamSize();
 
  671     char * echo_char_array = (
char *)malloc(essz+1);
 
  672     printf(
"PARSE ERROR\n");
 
  673     echo_char_array[essz] = 
'\0';
 
  674     echo_char_array = getPamgenEchoStream(echo_char_array);
 
  675     if(echo_char_array)printf(
"%s",echo_char_array);
 
  676     if(cr_result == ERROR_CREATING_IMD)printf(
"ERROR Failure to create Inline_Mesh_Desc creation\n");
 
  677     if(echo_char_array)free(echo_char_array);
 
  680   if(cr_result == ERROR_CREATING_MS){
 
  681     long long essz = getPamgenErrorStreamSize();
 
  682     char * error_char_array = (
char *)malloc(essz+1);
 
  683     error_char_array[essz] = 
'\0';
 
  684     error_char_array = getPamgenErrorStream(error_char_array);
 
  685     if(error_char_array)printf(
"%s",error_char_array);
 
  686     printf(
"\nERROR Failure to create Mesh_Specification\n");
 
  687     if(error_char_array)free(error_char_array);
 
  691   long long wssz = getPamgenWarningStreamSize();
 
  693     char * warning_char_array = (
char *)malloc(wssz+1);
 
  694     warning_char_array[wssz] = 
'\0';
 
  695     warning_char_array = getPamgenWarningStream(warning_char_array);
 
  696     printf(
"WARNING Records\n");
 
  697     printf(
"%s",warning_char_array);
 
  698     free(warning_char_array);