Ejemplo n.º 1
0
int NemSpread<T,INT>::read_elem_vars_1(int exoid, int index, INT *eb_ids,
                                       INT *eb_cnts, INT ***eb_map_ptr,
                                       INT **eb_cnts_local, int iblk,
                                       int eb_offset, INT *local_offset)
{
    /* Allocate memory for temporary storage */
    T *vals  = (T*)array_alloc(__FILE__, __LINE__, 1, eb_cnts[iblk], sizeof(T));

    /* now loop over each variable */
    for (int ivar = 0; ivar < Restart_Info.NVar_Elem; ivar++) {

        /* check if this variable exists for this element block */
        if (Restart_Info.GElem_TT[iblk*Restart_Info.NVar_Elem+ivar]) {

            /*
             * Read in the specified element variable values and their associated
             * global FEM element numbers.
             */

            check_exodus_error(ex_get_var(exoid,
                                          index,
                                          EX_ELEM_BLOCK,
                                          (ivar+1),
                                          eb_ids[iblk],
                                          eb_cnts[iblk],
                                          vals),
                               "ex_get_var");

            /*
             * Find out which FEM elements belong on this processor and copy
             * them to the restart vector.
             */
            for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {

                /* check to see if this element block needs this variable */
                if (Restart_Info.GElem_TT[iblk*Restart_Info.NVar_Elem+ivar]) {

                    /* calculate the offset for this variable */
                    size_t var_offset = ivar * (globals.Num_Internal_Elems[iproc] + globals.Num_Border_Elems[iproc]);

                    INT *elem_map = eb_map_ptr[iproc][iblk];
                    size_t num_elem = eb_cnts_local[iproc][iblk];

                    for (size_t i1 = 0; i1 < num_elem; i1++) {
                        size_t elem_loc = var_offset + i1 + local_offset[iproc];

                        Restart_Info.Elem_Vals[iproc][elem_loc] = vals[elem_map[i1]-eb_offset];
                    }
                }
            }
        } /* End "if (Restart_Info.GElem_TT[...])" */
    }
    safe_free((void **) &vals);
    return 0;
}
Ejemplo n.º 2
0
int NemSpread<T,INT>::compare_mesh_param(int exoid)
{
    int     ret = 1;

    ex_init_params info;
    info.title[0] = '\0';
    int error = ex_get_init_ext (exoid, &info);
    check_exodus_error (error, "ex_get_init");

    /* now check that the parameters match those retrieved from the mesh file */
    if (info.num_dim                    != globals.Num_Dim)      ret = 0;
    else if ((size_t)info.num_nodes     != globals.Num_Node)     ret = 0;
    else if ((size_t)info.num_elem      != globals.Num_Elem)     ret = 0;
    else if (info.num_elem_blk  != globals.Num_Elem_Blk) ret = 0;
    else if (info.num_node_sets != globals.Num_Node_Set) ret = 0;
    else if (info.num_side_sets != globals.Num_Side_Set) ret = 0;

    return (ret);
}
Ejemplo n.º 3
0
int NemSpread<T,INT>::read_nodal_vars(int exoid, int index)
{
    /* Allocate memory for temporary storage */
    T *vals = (T*)array_alloc(__FILE__, __LINE__, 1, globals.Num_Node, sizeof(T));

    /* Loop over each auxiliary variable */
    for (int var_num = 0; var_num < Restart_Info.NVar_Node; var_num++) {
        /*
         * Read in the specified nodal variable values and their associated
         * global FEM node numbers.
         */
        check_exodus_error(ex_get_var(exoid, index, EX_NODAL, (var_num+1),
                                      1, globals.Num_Node, vals),
                           "ex_get_var");

        /*
         * Find out which FEM nodes belong on this processor and copy
         * them to the restart vector.
         */
        for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {

            /* calculate the offset for this variable */
            size_t loc_count = globals.Num_Internal_Nodes[iproc]+globals.Num_Border_Nodes[iproc]+
                               globals.Num_External_Nodes[iproc];

            size_t var_offset = var_num * loc_count;

            for (size_t i2 = 0; i2 < loc_count; i2++) {
                size_t node_loc = var_offset + i2;
                Restart_Info.Node_Vals[iproc][node_loc] =
                    vals[globals.GNodes[iproc][i2]-1];
            }
        }

    } /* End "for (var_num = 0; var_num < Restart_Info.NVar_Node; var_num++)" */

    safe_free((void **) &vals);
    return 0;
}
Ejemplo n.º 4
0
int NemSpread<T,INT>::read_sset_vars_1(int exoid, int index, INT *ss_ids,
                                       INT *ss_cnts, int iset)
{
    /* Allocate memory for temporary storage */
    T *vals  = (T*)array_alloc(__FILE__, __LINE__, 1, ss_cnts[iset], sizeof(T));

    /* now loop over each variable */
    for (int ivar = 0; ivar < Restart_Info.NVar_Sset; ivar++) {

        /* check if this variable exists for this set */
        if (Restart_Info.GSset_TT[iset*Restart_Info.NVar_Sset+ivar]) {

            /* Read in the specified variable values */
            check_exodus_error(ex_get_var(exoid, index, EX_SIDE_SET,
                                          (ivar+1), ss_ids[iset], ss_cnts[iset],
                                          vals), "ex_get_var");

            for (int iproc = 0; iproc <Proc_Info[2]; iproc++) {
                size_t ss_offset = 0;
                size_t var_offset = ivar * globals.Proc_SS_Elem_List_Length[iproc];
                for (int i = 0; i < globals.Proc_Num_Side_Sets[iproc]; i++) {
                    if (globals.Proc_SS_Ids[iproc][i] == ss_ids[iset]) {

                        size_t num_elem = globals.Proc_SS_Elem_Count[iproc][i];
                        for (size_t i1 = 0; i1 < num_elem; i1++) {
                            INT gelem_loc = globals.Proc_SS_GEMap_List[iproc][i1+ss_offset];
                            assert(gelem_loc < ss_cnts[iset]);
                            Restart_Info.Sset_Vals[iproc][i1+ss_offset+var_offset] = vals[gelem_loc];
                        }
                        break;
                    }
                    ss_offset += globals.Proc_SS_Elem_Count[iproc][i];
                }
            }
        }
    }
    safe_free((void **) &vals);
    return 0;
}
Ejemplo n.º 5
0
void NemSpread<T,INT>::read_lb_init(int lb_exoid,
				    INT *Int_Space,
				    INT *Int_Node_Num,
				    INT *Bor_Node_Num,
				    INT *Ext_Node_Num,
				    INT *Int_Elem_Num,
				    INT *Bor_Elem_Num,
				    INT *Node_Comm_Num,
				    INT *Elem_Comm_Num,
				    char *Title
				    )

/*
 *    read_lb_init:
 *
 *         This function reads the initial information contained in the
 * load balance file
 *
 *
 */
{
  const char *yo = "read_lb_init";

  /*********************BEGIN EXECUTABLE STATEMENTS****************************/

  /* Read Set-up information from the load-balance file on Proc 0 */

  /*
   * If debugging is not on go ahead and report errors from init. This
   * will show version mismatch information by default.
   */
  if(Debug_Flag == 0)
    ex_opts(EX_VERBOSE);

  /* Read the title of the LB File and about the size of the mesh */
  INT   num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets;
  int error = ex_get_init_global(lb_exoid, &num_nodes, &num_elem,
				 &num_elem_blk, &num_node_sets, &num_side_sets);

  check_exodus_error (error, "ex_get_init");

  if(Debug_Flag == 0)
    ex_opts(!EX_VERBOSE);

#ifdef DEBUG
  if(Debug_Flag >= 2) {
    printf("---------------------------------------------------------\n");
    printf("\t\tLoad balance file global information\n");
    printf("---------------------------------------------------------\n");
    printf("\tNumber of nodes: %d\n", num_nodes);
    printf("\tNumber of elements: %d\n", num_elem);
    printf("\tNumber of element blocks: %d\n", num_elem_blk);
    printf("---------------------------------------------------------\n");
  }
#endif

  /* Cross-check the load balance file info against the mesh info */
  if(((size_t)num_nodes != globals.Num_Node) || ((size_t)num_elem != globals.Num_Elem) ||
     (num_elem_blk != globals.Num_Elem_Blk)) {
    fprintf(stderr,
	    "%s: ERROR: Problem dimensions in the LB File don't match with those \
in mesh file",yo);
    exit(1);
  }
Ejemplo n.º 6
0
int NemSpread<T,INT>::read_var_param (int exoid, int max_name_length)
{
    const char  *yo="read_var_param";

    /* Get the number of time indices contained in the file */
    int ret_int = ex_inquire_int(exoid, EX_INQ_TIME);

    /* see if the user want to get all of the time indices */
    if (Restart_Info.Num_Times == -1) {

        Restart_Info.Num_Times = ret_int;

        if (ret_int > 0) {
            /* allocate array space */
            Restart_Info.Time_Idx.resize(Restart_Info.Num_Times);

            for (int cnt = 0; cnt < Restart_Info.Num_Times; cnt++)
                Restart_Info.Time_Idx[cnt] = cnt + 1;
        }
    }
    else {
        /* Check to see if the requested indeces are valid */
        for (int cnt = 0; cnt < Restart_Info.Num_Times; cnt++) {

            /* if the user wants the last time, then set it */
            if (Restart_Info.Time_Idx[cnt] == 0)
                Restart_Info.Time_Idx[cnt] = ret_int;

            if (Restart_Info.Time_Idx[cnt] > ret_int) {
                fprintf(stderr, "%s: Requested time index, %d, out of range.\n",
                        yo, Restart_Info.Time_Idx[cnt]);
                fprintf(stderr, "%s: Valid time indices in %s are from 1 to %d.\n",
                        yo, Exo_Res_File, ret_int);
                return -1;
            }

        }
    }

    /* if there are not any time steps, then return here without an error */
    if (Restart_Info.Num_Times == 0) {
        Restart_Info.Flag = 0;
        Restart_Info.NVar_Glob = 0;
        Restart_Info.NVar_Node = 0;
        Restart_Info.NVar_Elem = 0;
        return 0;
    }


    /***************** Global Variables ********************/
    if (ex_get_variable_param(exoid, EX_GLOBAL, &(Restart_Info.NVar_Glob)) < 0) {
        fprintf(stderr, "%s: Could not get global variable parameter from file\n",
                yo);
        return -1;
    }

    /* allocate space for the global variable names */
    if (Restart_Info.NVar_Glob > 0) {
        Restart_Info.GV_Name = (char **) array_alloc(__FILE__, __LINE__, 2,
                               Restart_Info.NVar_Glob,
                               max_name_length+1,
                               sizeof(char));

        /* get the global variable names */
        if (ex_get_variable_names(exoid, EX_GLOBAL, Restart_Info.NVar_Glob,
                                  Restart_Info.GV_Name) < 0) {
            fprintf(stderr, "%s: Could not get global variable names from file\n",
                    yo);
            return -1;
        }
    }

    /***************** Elemental Variables ********************/
    if (ex_get_variable_param(exoid, EX_ELEM_BLOCK, &(Restart_Info.NVar_Elem)) < 0) {
        fprintf(stderr, "%s: Could not get elemental variable param from file\n",
                yo);
        return -1;
    }

    /* allocate space for the elemental variable names */
    if (Restart_Info.NVar_Elem > 0) {
        Restart_Info.EV_Name = (char **) array_alloc(__FILE__, __LINE__, 2,
                               Restart_Info.NVar_Elem,
                               max_name_length+1,
                               sizeof(char));

        /* get the elemental variable names */
        if (ex_get_variable_names(exoid, EX_ELEM_BLOCK, Restart_Info.NVar_Elem,
                                  Restart_Info.EV_Name) < 0) {
            fprintf(stderr, "%s: Could not get elemental variable names from file\n",
                    yo);
            return -1;
        }

        /* and get the truth table */
        Restart_Info.GElem_TT.resize(globals.Num_Elem_Blk * Restart_Info.NVar_Elem);

        check_exodus_error(ex_get_truth_table(exoid, EX_ELEM_BLOCK,
                                              globals.Num_Elem_Blk,
                                              Restart_Info.NVar_Elem,
                                              TOPTR(Restart_Info.GElem_TT)),
                           "ex_get_truth_table");
    }

    /******************* Nodal Variables **********************/
    if (ex_get_variable_param(exoid, EX_NODAL, &(Restart_Info.NVar_Node)) < 0) {
        fprintf(stderr, "%s: Could not get nodal variable param from file\n",
                yo);
        return -1;
    }

    /* allocate space for the nodal variable names */
    if (Restart_Info.NVar_Node > 0) {
        Restart_Info.NV_Name = (char **) array_alloc(__FILE__, __LINE__, 2,
                               Restart_Info.NVar_Node,
                               max_name_length+1,
                               sizeof(char));

        /* get the nodal variable names */
        if (ex_get_variable_names(exoid, EX_NODAL, Restart_Info.NVar_Node,
                                  Restart_Info.NV_Name) < 0) {
            fprintf(stderr, "%s: Could not get nodal variable names from file\n",
                    yo);
            return -1;
        }
    }

    /******************* Sideset Variables **********************/
    if (ex_get_variable_param(exoid, EX_SIDE_SET, &(Restart_Info.NVar_Sset)) < 0) {
        fprintf(stderr, "%s: Could not get sideset variable param from file\n",
                yo);
        return -1;
    }

    /* allocate space for the variable names */
    if (Restart_Info.NVar_Sset > 0) {
        Restart_Info.SSV_Name = (char **) array_alloc(__FILE__, __LINE__, 2,
                                Restart_Info.NVar_Sset,
                                max_name_length+1,
                                sizeof(char));

        /* get the variable names */
        if (ex_get_variable_names(exoid, EX_SIDE_SET, Restart_Info.NVar_Sset,
                                  Restart_Info.SSV_Name) < 0) {
            fprintf(stderr, "%s: Could not get sideset variable names from file\n",
                    yo);
            return -1;
        }

        /* and get the truth table */
        Restart_Info.GSset_TT.resize(globals.Num_Side_Set * Restart_Info.NVar_Sset);

        check_exodus_error(ex_get_truth_table(exoid, EX_SIDE_SET,
                                              globals.Num_Side_Set,
                                              Restart_Info.NVar_Sset,
                                              TOPTR(Restart_Info.GSset_TT)),
                           "ex_get_truth_table");
    }

    /******************* Nodeset Variables **********************/
    if (ex_get_variable_param(exoid, EX_NODE_SET, &(Restart_Info.NVar_Nset)) < 0) {
        fprintf(stderr, "%s: Could not get nodeset variable param from file\n",
                yo);
        return -1;
    }

    /* allocate space for the variable names */
    if (Restart_Info.NVar_Nset > 0) {
        Restart_Info.NSV_Name = (char **) array_alloc(__FILE__, __LINE__, 2,
                                Restart_Info.NVar_Nset,
                                max_name_length+1,
                                sizeof(char));

        /* get the variable names */
        if (ex_get_variable_names(exoid, EX_NODE_SET, Restart_Info.NVar_Nset,
                                  Restart_Info.NSV_Name) < 0) {
            fprintf(stderr, "%s: Could not get nodeset variable names from file\n",
                    yo);
            return -1;
        }

        /* and get the truth table */
        Restart_Info.GNset_TT.resize(globals.Num_Node_Set * Restart_Info.NVar_Nset);

        check_exodus_error(ex_get_truth_table(exoid, EX_NODE_SET,
                                              globals.Num_Node_Set,
                                              Restart_Info.NVar_Nset,
                                              TOPTR(Restart_Info.GNset_TT)),
                           "ex_get_var_tab");
    }


#ifdef DEBUG
    if (Debug_Flag >= 2) {
        printf("\n\nRestart Parameters:\n");
        printf("\tNumber of time indices: %d\n", Restart_Info.Num_Times);
        for (int cnt = 0; cnt < Restart_Info.Num_Times; cnt++)
            printf("\t\tTime index: %d\n", Restart_Info.Time_Idx[cnt]);
        printf("\tNumber of global variables: %d\n", Restart_Info.NVar_Glob);
        for (int cnt = 0; cnt < Restart_Info.NVar_Glob; cnt++)
            printf("\t\tGlobal variable %d: %s\n", (cnt+1),
                   Restart_Info.GV_Name[cnt]);
        printf("\tNumber of elental variables: %d\n", Restart_Info.NVar_Elem);
        for (int cnt = 0; cnt < Restart_Info.NVar_Elem; cnt++)
            printf("\t\tElemental variable %d: %s\n", (cnt+1),
                   Restart_Info.EV_Name[cnt]);
        printf("\tNumber of nodal variables: %d\n", Restart_Info.NVar_Node);
        for (int cnt = 0; cnt < Restart_Info.NVar_Node; cnt++)
            printf("\t\tNodal variable %d: %s\n", (cnt+1), Restart_Info.NV_Name[cnt]);
    }
#endif

    return 0;

}
Ejemplo n.º 7
0
template <typename T, typename INT> void NemSpread<T, INT>::read_mesh_param()

/*
 *       Function which reads the sizing parameters from the EXODUS II database,
 *       which contains the mesh.  This is used to cross-check against the
 *       load balancer file.
 *
 *      ------------------------------------------------------------------------
 *
 *       Functions called:
 *
 *       check_exodus_error -- function which handles the error code returned by
 *                             calls to EXODUS II API routines.
 *
 *      ------------------------------------------------------------------------
 */
{

  /* Local variables */

  const char *yo = "read_mesh_param";
  char *      exofile;
  int         exoid, error;
  int         cpu_ws;
  float       version;

  /**************************** execution begins *******************************/
  cpu_ws = sizeof(float);

  /*
   *         Generate the name of the parallel mesh file for this processor.
   *         Note: Default case is the scalar mesh file.
   */

  exofile = ExoFile;

  /* initialize the io word size on all of the processors */
  io_ws = 0;

  int mode = EX_READ | int64api;

  /* Open the EXODUS II mesh file */
  exoid = ex_open(exofile, mode, &cpu_ws, &io_ws, &version);
  if (exoid == -1) {
    fprintf(stderr, "%s: ERROR openning up the mesh exoII file, %s\n", yo, exofile);
    exit(-1);
  }

  /* Read the initialization parameters */
  memset(GeomTitle, '\0', MAX_LINE_LENGTH * sizeof(char));
  ex_init_params info;
  info.title[0] = '\0';
  error         = ex_get_init_ext(exoid, &info);
  check_exodus_error(error, "ex_get_init");

  strncpy(GeomTitle, info.title, MAX_LINE_LENGTH);
  GeomTitle[MAX_LINE_LENGTH] = '\0';
  globals.Num_Dim            = info.num_dim;
  globals.Num_Node           = info.num_nodes;
  globals.Num_Elem           = info.num_elem;
  globals.Num_Elem_Blk       = info.num_elem_blk;
  globals.Num_Node_Set       = info.num_node_sets;
  globals.Num_Side_Set       = info.num_side_sets;

  printf("\nExodus file (%s)\n", exofile);
  printf("\tTitle of file: %s\n", GeomTitle);
  printf("\tDimensionality of problem = %d\n", globals.Num_Dim);
  printf("\tNumber of nodes           = " ST_ZU "\n", globals.Num_Node);
  printf("\tNumber of elements        = " ST_ZU "\n", globals.Num_Elem);
  printf("\tNumber of element blocks  = %d\n", globals.Num_Elem_Blk);
  printf("\tNumber of node sets       = %d\n", globals.Num_Node_Set);
  printf("\tNumber of side sets       = %d\n\n", globals.Num_Side_Set);

  /* Close the file */
  error = ex_close(exoid);
  check_exodus_error(error, "ex_close");

} /* END of routine read_mesh_params *****************************************/