⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expcab.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2006 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. *  *//******************************************************************************* expclb - ex_put_concat_all_blocks: write elem, edge, & face block parameters** entry conditions - *   input parameters:*       int                    exoid          exodus file id*       const ex_block_params* bparam         block parameters structure******************************************************************************/#include <stdlib.h>#include "exodusII.h"#include "exodusII_int.h"#include <string.h>/*! * writes the parameters used to describe all element, edge, and face blocks * \param     exoid          exodus file id * \param     param         block parameters structure */int ex_put_concat_all_blocks (int    exoid,                              const ex_block_params *param){  int i, varid, dimid, dims[2], strdim, *eb_stat, *ed_stat, *fa_stat;  int temp;  int iblk;  int status;  size_t num_elem_blk, num_edge_blk, num_face_blk;  int cur_num_elem_blk, nelnoddim, numelbdim, numattrdim, connid=-1;  int cur_num_edge_blk, numedbdim, nednoddim, cur_num_face_blk, numfabdim, nfanoddim;  int neledgdim=-1, nelfacdim=-1;  char errmsg[MAX_ERR_LENGTH];  int elem_work = 0; /* is DIM_NUM_EL_BLK defined? If so, there's work to do */  int edge_work = 0; /* is DIM_NUM_ED_BLK defined? If so, there's work to do */  int face_work = 0; /* is DIM_NUM_FA_BLK defined? If so, there's work to do */  static const char* dim_num_maps[] = {    DIM_NUM_NM,    DIM_NUM_EDM,    DIM_NUM_FAM,    DIM_NUM_EM,  };  static const char* dim_size_maps[] = {    DIM_NUM_NODES,    DIM_NUM_EDGE,    DIM_NUM_FACE,    DIM_NUM_ELEM,  };  static const ex_entity_type map_enums[] = {    EX_NODE_MAP,    EX_EDGE_MAP,    EX_FACE_MAP,    EX_ELEM_MAP  };  /* If param->define_maps is true, we must fill these with values from ex_put_init_ext     before entering define mode */  size_t num_maps[sizeof(dim_num_maps)/sizeof(dim_num_maps[0])];  int num_map_dims = sizeof(dim_num_maps)/sizeof(dim_num_maps[0]);  exerrval  = 0; /* clear error code */  /* inquire previously defined dimensions  */  if ((status = nc_inq_dimid(exoid, DIM_STR, &strdim)) != NC_NOERR) {    exerrval = status;    sprintf(errmsg,            "Error: failed to get string length in file id %d",exoid);    ex_err("ex_put_concat_all_blocks",errmsg,exerrval);    return (EX_FATAL);  }  if ( param->define_maps ) {    for ( i = 0; i < num_map_dims; ++i ) {      if ((status = nc_inq_dimid(exoid, dim_num_maps[i], &dimid)) != NC_NOERR) {        exerrval = status;        sprintf( errmsg, "Error: failed to find node map size of file id %d", exoid );        ex_err( "ex_put_concat_all_blocks", errmsg, exerrval );        return (EX_FATAL);      }      if ((status = nc_inq_dimlen(exoid, dimid, num_maps+i)) != NC_NOERR) {	exerrval = status;	sprintf( errmsg, "Error: failed to retrieve node map size of file id %d", exoid );	ex_err( "ex_put_concat_all_blocks", errmsg, exerrval );	return (EX_FATAL);      }    }  }#define EX_PREPARE_BLOCK(TNAME,WNAME,DNUMNAME,VSTATNAME,VIDNAME,LNUMNAME,SNUMNAME,SIDNAME,GSTAT) \  /* first check if any TNAME blocks are specified			\   * OK if zero...							\   */									\    if ((status = (nc_inq_dimid(exoid, DNUMNAME, &dimid))) == NC_NOERR) { \      WNAME = 1;							\									\      /* Get number of TNAME blocks defined for this file */		\      if ((status = nc_inq_dimlen(exoid,dimid,&LNUMNAME)) != NC_NOERR) { \	exerrval = status;						\	sprintf(errmsg,							\		"Error: failed to get number of " TNAME " blocks in file id %d", \		exoid);							\	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\	return (EX_FATAL);						\      }									\									\      /* Fill out the TNAME block status array */			\      if (!(GSTAT = malloc(LNUMNAME*sizeof(int)))) {			\	exerrval = EX_MEMFAIL;						\	sprintf(errmsg,							\		"Error: failed to allocate space for " TNAME " block status array in file id %d", \		exoid);							\	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\	return (EX_FATAL);						\      }									\									\      for (i=0;i<LNUMNAME;i++) {					\	if (SNUMNAME[i] == 0) /* Is this a NULL TNAME block? */		\	  GSTAT[i] = 0; /* change TNAME block status to NULL */		\	else								\	  GSTAT[i] = 1; /* change TNAME block status to TRUE */		\      }									\									\      /* Next, get variable id of status array */			\      if ((status = nc_inq_varid(exoid, VSTATNAME, &varid)) != NC_NOERR) { \	exerrval = status;						\	sprintf(errmsg,							\		"Error: failed to locate " TNAME " block status in file id %d", \		exoid);							\	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\	return (EX_FATAL);						\      }									\									\      status = nc_put_var_int(exoid, varid, GSTAT);			\									\      if (status != NC_NOERR) {						\	exerrval = status;						\	sprintf(errmsg,							\		"Error: failed to store " TNAME " block status array to file id %d", \		exoid);							\	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\	return (EX_FATAL);						\      }									\									\      free(GSTAT);							\									\      /* Next, fill out ids array */					\      /* first get id of ids array variable */				\      if ((status = nc_inq_varid(exoid, VIDNAME, &varid)) != NC_NOERR) { \	exerrval = status;						\	sprintf(errmsg,							\		"Error: failed to locate " TNAME " block ids array in file id %d", \		exoid);							\	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\	return (EX_FATAL);						\      }									\									\      /* then, write out id list */					\      status = nc_put_var_int(exoid, varid, SIDNAME);			\									\      if (status != NC_NOERR) {						\	exerrval = status;						\	sprintf(errmsg,							\		"Error: failed to store " TNAME " block id array in file id %d", \		exoid);							\	ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\	return (EX_FATAL);						\      }									\    }  EX_PREPARE_BLOCK("element",elem_work,DIM_NUM_EL_BLK,VAR_STAT_EL_BLK,VAR_ID_EL_BLK,		   num_elem_blk,param->num_elem_this_blk,param->elem_blk_id,eb_stat);  EX_PREPARE_BLOCK(   "edge",edge_work,DIM_NUM_ED_BLK,VAR_STAT_ED_BLK,VAR_ID_ED_BLK,		      num_edge_blk,param->num_edge_this_blk,param->edge_blk_id,ed_stat);  EX_PREPARE_BLOCK(   "face",face_work,DIM_NUM_FA_BLK,VAR_STAT_FA_BLK,VAR_ID_FA_BLK,		      num_face_blk,param->num_face_this_blk,param->face_blk_id,fa_stat);  if ( elem_work == 0 && edge_work == 0 && face_work == 0 && param->define_maps == 0 ) {    /* Nothing to do. This is not an error, but we can save     * ourselves from entering define mode by returning here.     */    return (EX_NOERR);  }  /* put netcdf file into define mode  */  if ((status = nc_redef(exoid)) != NC_NOERR)  {    exerrval = status;    sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid);    ex_err("ex_put_concat_all_blocks",errmsg,exerrval);    return (EX_FATAL);  }#define EX_PREPARE_ATTRIB_ARRAY(TNAME,CURBLK,DNAME,DVAL,ID,VANAME,VADIM0,VADIM1,VANNAME) \  if (DVAL[iblk] > 0) {							\    if ((status = nc_def_dim (exoid,					\			      DNAME(CURBLK+1),				\			      DVAL[iblk], &VADIM1)) != NC_NOERR) { \      exerrval = status;						\      sprintf(errmsg,							\	      "Error: failed to define number of attributes in " TNAME " block %d in file id %d", \	      ID[iblk],exoid);						\      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\      goto error_ret;         /* exit define mode and return */		\    }									\									\    dims[0] = VADIM0;							\    dims[1] = VADIM1;							\									\    if ((status = nc_def_var (exoid, VANAME(CURBLK+1),			\			      nc_flt_code(exoid), 2, dims, &temp)) != NC_NOERR) { \      exerrval = status;						\      sprintf(errmsg,							\	      "Error:  failed to define attributes for " TNAME " block %d in file id %d", \	      ID[iblk],exoid);						\      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\      goto error_ret;         /* exit define mode and return */		\    }									\									\    /* Attribute names... */						\    dims[0] = VADIM1;							\    dims[1] = strdim;							\									\    if ((status = nc_def_var(exoid, VANNAME(CURBLK+1), NC_CHAR, 2, dims, &temp)) != NC_NOERR) { \      exerrval = status;						\      sprintf(errmsg,							\	      "Error: failed to define " TNAME " attribute name array in file id %d",exoid); \      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\      goto error_ret;         /* exit define mode and return */		\    }									\  }#define EX_PREPARE_CONN(TNAME,BLK,BLKID,BLKSZ,VNAME,DNAME)		\  if ( DNAME > 0 ) {							\    dims[0] = BLKSZ;							\    dims[1] = DNAME;							\									\    if ((status = nc_def_var(exoid, VNAME(BLK+1),			\			     NC_INT, 2, dims, &connid)) != NC_NOERR) {	\      exerrval = status;						\      sprintf(errmsg,							\	      "Error: failed to create " TNAME " connectivity array for block %d in file id %d", \	      BLKID[iblk],exoid);					\      ex_err("ex_put_concat_all_blocks",errmsg,exerrval);		\      goto error_ret;         /* exit define mode and return */		\    }									\  }  /* Iterate over edge blocks ... */  for (iblk = 0; iblk < num_edge_blk; ++iblk) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -