/* * Copyright (c) 1994 Sandia Corporation. Under the terms of Contract * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Governement * retains certain rights in this software. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * * Neither the name of Sandia Corporation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ /***************************************************************************** * * exgsnl - ex_get_side_set_node_list_len * * author - Sandia National Laboratories * Vic Yarberry - Original * * * environment - UNIX * * entry conditions - * input parameters: * int exoid exodus file id * int side_set_id side set id * * exit conditions - * int *side_set_node_list_len length of node list * * revision history - * * $Id: exgsnl.c,v 1.3 2005/07/19 23:40:10 andy Exp $ * *****************************************************************************/ #include #include #include #include "exodusII.h" #include "exodusII_int.h" /* * This routine is designed to read the Exodus II V 2.0 side set side * definition and return the length of a ExodusI style side set node list. */ int ex_get_side_set_node_list_len(int exoid, int side_set_id, int *side_set_node_list_len) { int i, j, m; int num_side_sets, num_elem_blks, num_df, ndim; int tot_num_elem = 0, tot_num_ss_elem = 0; int *elem_blk_ids; int *ss_elem_ndx; int *side_set_elem_list, *side_set_side_list; int elem_ctr; int num_elem_in_blk, num_nodes_per_elem, num_attr; float fdum; char *cdum, elem_type[MAX_STR_LENGTH+1]; struct elem_blk_parm { char elem_type[MAX_STR_LENGTH+1]; int elem_blk_id; int num_elem_in_blk; int num_nodes_per_elem; int num_nodes_per_side; int num_attr; int elem_ctr; int elem_type_val; } *elem_blk_parms; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ cdum = 0; /* initialize even though it is not used */ *side_set_node_list_len = 0; /* default value */ /* first check if any side sets are specified */ /* inquire how many side sets have been stored */ if ((ex_inquire(exoid, EX_INQ_SIDE_SETS, &num_side_sets, &fdum, cdum)) == -1) { sprintf(errmsg, "Error: failed to get number of side sets in file id %d",exoid); ex_err("ex_get_side_set_node_list_len",errmsg,exerrval); return(EX_FATAL); } if (num_side_sets == 0) { sprintf(errmsg, "Warning: no side sets defined in file id %d",exoid); ex_err("ex_get_side_set_node_list_len",errmsg,EX_WARN); return(EX_WARN); } if ((ex_inquire(exoid, EX_INQ_ELEM_BLK, &num_elem_blks, &fdum, cdum)) == -1) { sprintf(errmsg, "Error: failed to get number of element blocks in file id %d",exoid); ex_err("ex_get_side_set_node_list_len",errmsg,exerrval); return(EX_FATAL); } if ((ex_inquire(exoid, EX_INQ_ELEM, &tot_num_elem, &fdum, cdum)) == -1) { sprintf(errmsg, "Error: failed to get total number of elements in file id %d",exoid); ex_err("ex_get_side_set_node_list_len",errmsg,exerrval); return(EX_FATAL); } /* get the dimensionality of the coordinates; this is necessary to distinguish between 2d TRIs and 3d TRIs */ if ((ex_inquire(exoid, EX_INQ_DIM, &ndim, &fdum, cdum)) == -1) { sprintf(errmsg, "Error: failed to get dimensionality in file id %d",exoid); ex_err("ex_get_side_set_node_list_len",errmsg,exerrval); return(EX_FATAL); } /* First determine the # of elements in the side set*/ if ((ex_get_side_set_param(exoid,side_set_id,&tot_num_ss_elem,&num_df)) == -1) { sprintf(errmsg, "Error: failed to get number of elements in side set %d in file id %d", side_set_id, exoid); ex_err("ex_get_side_set_node_list_len",errmsg,exerrval); return(EX_FATAL); } if (tot_num_ss_elem == 0) /* NULL side set? */ return (EX_NOERR); /* return zero */ /* Allocate space for the side set element list */ if (!(side_set_elem_list=malloc(tot_num_ss_elem*sizeof(int)))) { exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for side set element list for file id %d", exoid); ex_err("ex_get_side_set_node_list_len",errmsg,exerrval); return (EX_FATAL); } /* Allocate space for the side set side list */ if (!(side_set_side_list=malloc(tot_num_ss_elem*sizeof(int)))) { free(side_set_elem_list); exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for side set side list for file id %d", exoid); ex_err("ex_get_side_set_node_list_len",errmsg,exerrval); return (EX_FATAL); } if (ex_get_side_set(exoid, side_set_id, side_set_elem_list, side_set_side_list) == -1) { free(side_set_elem_list); free(side_set_side_list); sprintf(errmsg, "Error: failed to get side set %d in file id %d", side_set_id, exoid); ex_err("ex_get_side_set_node_list_len",errmsg,exerrval); return (EX_FATAL); } /* Allocate space for the ss element index array */ if (!(ss_elem_ndx=malloc(tot_num_ss_elem*sizeof(int)))) { free(side_set_elem_list); free(side_set_side_list); exerrval = EX_MEMFAIL; sprintf(errmsg, "Error: failed to allocate space for side set elem sort array for file id %d", exoid); ex_err("ex_get_side_set_node_list_len",errmsg,exerrval); return (EX_FATAL); } /* Sort side set element list into index array - non-destructive */ for (i=0;i= num_elem_blks) { exerrval = EX_BADPARAM; sprintf(errmsg, "Error: Invalid element number %d found in side set %d in file %d", side_set_elem_list[i], side_set_id, exoid); free(elem_blk_parms); free(elem_blk_ids); free(ss_elem_ndx); free(side_set_side_list); free(side_set_elem_list); ex_err("ex_get_side_set_node_list_len",errmsg,EX_MSG); return (EX_FATAL); } /* Update *side_set_node_list_len (which points to next node in chain */ /* WEDGEs with 3 node sides (side 4 or 5) are special cases */ if (elem_blk_parms[j].elem_type_val == WEDGE && (side_set_side_list[i] == 4 || side_set_side_list[i] == 5)) { if (elem_blk_parms[j].num_nodes_per_elem == 6) *side_set_node_list_len += 3; /* 3 node side */ else *side_set_node_list_len += 6; /* 6 node side */ } /* PYRAMIDSs with 3 node sides (sides 1,2,3,4) are also special */ else if (elem_blk_parms[j].elem_type_val == PYRAMID && (side_set_side_list[i] < 5)) { if (elem_blk_parms[j].num_nodes_per_elem == 5) *side_set_node_list_len += 3; /* 3 node side */ else *side_set_node_list_len += 6; /* 6 node side */ } /* side numbers 3,4,5,6 for SHELLs are also special */ else if (elem_blk_parms[j].elem_type_val == SHELL && (side_set_side_list[i] > 2 )) { if (elem_blk_parms[j].num_nodes_per_elem == 4) *side_set_node_list_len += 2; /* 2 node side */ else *side_set_node_list_len += 3; /* 3 node side */ } /* sides 3, 4, and 5 of 3d TRIs are special cases */ else if (elem_blk_parms[j].elem_type_val == TRIANGLE && ndim == 3 && side_set_side_list[i] > 2 ) { if (elem_blk_parms[j].num_nodes_per_elem == 3) /* 3-node TRI */ *side_set_node_list_len += 2; /* 2 node side */ else /* 6-node TRI */ *side_set_node_list_len += 3; /* 3 node side */ } else if (elem_blk_parms[j].elem_type_val == UNK) { exerrval = EX_BADPARAM; sprintf(errmsg, "Error: %s in elem block %d is an unsupported element type", elem_blk_parms[i].elem_type, elem_blk_parms[i].elem_blk_id); free(elem_blk_parms); free(elem_blk_ids); free(ss_elem_ndx); free(side_set_side_list); free(side_set_elem_list); ex_err("ex_get_side_set_node_list_len",errmsg,EX_MSG); return (EX_FATAL); } else /* all other element types */ *side_set_node_list_len += elem_blk_parms[j].num_nodes_per_side; } /* All done: release element block ids array, element block parameters array, and side set element index array */ free(elem_blk_ids); free(elem_blk_parms); free(ss_elem_ndx); free(side_set_side_list); free(side_set_elem_list); return(EX_NOERR); }