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

📄 patran.c

📁 很经典的电磁计算(电容计算)软件 MIT90年代开发
💻 C
📖 第 1 页 / 共 2 页
字号:
/*Copyright (c) 1990 Massachusetts Institute of Technology, Cambridge, MA.All rights reserved.This Agreement gives you, the LICENSEE, certain rights and obligations.By using the software, you indicate that you have read, understood, andwill comply with the terms.Permission to use, copy and modify for internal, noncommercial purposesis hereby granted.  Any distribution of this program or any part thereofis strictly prohibited without prior written consent of M.I.T.Title to copyright to this software and to any associated documentationshall at all times remain with M.I.T. and LICENSEE agrees to preservesame.  LICENSEE agrees not to make any copies except for LICENSEE'Sinternal noncommercial use, or to use separately any portion of thissoftware without prior written consent of M.I.T.  LICENSEE agrees toplace the appropriate copyright notice on any such copies.Nothing in this Agreement shall be construed as conferring rights to usein advertising, publicity or otherwise any trademark or the name of"Massachusetts Institute of Technology" or "M.I.T."M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  Byway of example, but not limitation, M.I.T. MAKES NO REPRESENTATIONS ORWARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE ORTHAT THE USE OF THE LICENSED SOFTWARE COMPONENTS OR DOCUMENTATION WILLNOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.M.I.T. shall not be held liable for any liability nor for any direct,indirect or consequential damages with respect to any claim by LICENSEEor any third party on account of or arising from this Agreement or useof this software.*//**************************************************************************  This is the subroutine that handles PATRAN to FastCap interface.    Patfront returns a pointer to a linked list of charge structures.  Written by Songmin Kim, July 24, 1990.**************************************************************************/#include "mulGlobal.h"#define BIG 35000              /* Size of element and node serach table. */#define SMALL_NUMBER 0.005     /* See functions if_same_coord() and 				 grid_equiv_check(). */int type_number, ID, IV, KC, N1, N2, N3, N4, N5;int number_nodes, number_elements, number_grids=0, number_patches=0;NODE *list_nodes, *current_node, *node_search_table[BIG];ELEMENT *list_elements, *current_element, *element_search_table[BIG];GRID *start_grid;PATCH *start_patch;CFEG *start_cfeg;/* these are now only used for temporary name storage for patran surfaces */extern NAME *start_name;       	/* name data linked list (1 entry/component) */extern NAME *current_name;	/* tail pointer to above list */extern NAME *start_name_this_time;     /* name structs made on this call */char *title;       	/* overall name given in the title card */int conductor_count;/* these flags added to allow multiple calls; used to reset static variables */int first_grid;			/* note that current_name static is not */int first_patch;		/*   reset since the name list must */int first_cfeg;			/*   be preserved as new files are read */charge *patfront(stream, file_is_patran_type, surf_type, trans_vector,		 name_list, num_cond, name_suffix)  FILE *stream;int *file_is_patran_type, surf_type, *num_cond;double *trans_vector;Name **name_list;char *name_suffix;{  int *patch_patch_table, numq=0;  static char *line = NULL;  charge *make_charges_all_patches(), *firstq, *quickif();  double *corner0, *corner1, *corner2, *corner3;  if(line == NULL) CALLOC(line, BUFSIZ, char, ON, AMSC);  start_name_this_time = NULL;  first_grid = first_patch = first_cfeg = TRUE;  number_grids = number_patches = 0;  /* figure out input file type and read it in */  fgets(line, BUFSIZ, stream);  if(line[0] == '0') {    *file_is_patran_type = FALSE;    firstq = quickif(stream, line, title, surf_type, trans_vector,		     num_cond, name_list, name_suffix);  }  else {    *file_is_patran_type = TRUE;    input(stream, line, surf_type, trans_vector);    grid_equiv_check();    /*********************************************************************      This section of patfront is for assigning conductor numbers to patches      depending on their connectivity.                                    */    if(surf_type == CONDTR || surf_type == BOTH) {      CALLOC(patch_patch_table, number_patches*number_patches, int, ON, AMSC);      fill_patch_patch_table(patch_patch_table);      assign_conductor(patch_patch_table);    /*********************************************************************/      assign_names();    }    firstq = make_charges_all_patches(name_list, num_cond, surf_type,				      name_suffix);  }  return (firstq);}/****************************************************************************   This part of code is for reading in Patran Neutral files.****************************************************************************/input(stream, line, surf_type, trans_vector)  char *line;  FILE *stream;int surf_type;double *trans_vector;{  int END=0;  /* Reads in the first line from each card, and branch off.  ID, IV, KC,      N1, N2, N3, N4 and N5 are global variables accessible by subroutines. */  while (!END) {    if(line[0] == '2') {	/* if first line */      sscanf(line,"%d %d %d %d %d %d %d %d %d", 	   &type_number, &ID, &IV, &KC, &N1, &N2, &N3, &N4, &N5);          line[0] = '0';    }    else fscanf(stream,"%d %d %d %d %d %d %d %d %d", 		&type_number, &ID, &IV, &KC, &N1, &N2, &N3, &N4, &N5);          switch (type_number) {    case 25:      file_title(stream);      break;    case 26:      summary_data(stream);      break;    case 1:      node_data(stream, trans_vector);      break;    case 2:      element_data(stream);      break;    case 31:      grid_data(stream, trans_vector);      break;    case 33:      patch_data(stream);      break;    case 45:      CFEG_table(stream);      break;    case 21:      if(surf_type == CONDTR || surf_type == BOTH) name_data(stream);      else waste_line(KC, stream);      break;    case 99:      END = 1;      break;    default:      waste_line(KC,stream);      break;    }  }}/* Simply read in 'num_line' lines from stream and dump. */waste_line(num_line,stream)  int num_line;  FILE *stream;{  int c, tmp;  tmp=num_line+1;  while (tmp) {    c=getc(stream);    if (c=='\n') tmp--;    if (c == EOF) {      fprintf(stderr, "Premature end of file - bad format.\n");      exit(1);    }  }}/* Save the title of the Neutral file. */file_title(stream)  FILE *stream;{  char line[BUFSIZ], *delcr();    fgets(line, sizeof(line), stream);  if(title[0] == '\0') strcpy(title, delcr(line));}/* Since the summary card has informations on the number of elements and    nodes, this function allocates spaces for nodes and elements, and sets up   the global pointers to these arrays. */summary_data(stream)  FILE *stream;{  number_nodes = N1; number_elements = N2;  CALLOC(list_nodes, number_nodes, NODE, ON, AMSC);  CALLOC(list_elements, number_elements, ELEMENT, ON, AMSC);  current_node = list_nodes;  current_element = list_elements;  waste_line(1,stream); }/* Current_node is the global variable that points to the next entry in    node array, list_nodes, which is preallocated by summary_data function.    Node_search_table is sorted by node ID to make indexing of a node easier. */node_data(stream, trans_vector)  FILE *stream;double *trans_vector;{  double tmp_coord[3];  int i;  fscanf(stream,"%lf %lf %lf",tmp_coord,tmp_coord+1,tmp_coord+2);    waste_line(1,stream);    for (i=0; i<3; i++)       current_node->coord[i] = tmp_coord[i] + trans_vector[i];  node_search_table[ID] = current_node;  current_node++;}/* Current_element is the global variable that points to the next entry in    element array, list_elements, which is preallocated by summary_data   function.  Element_search_table is sorted by element ID to make indexing    of an element easier.  */element_data(stream)  FILE *stream;{  int num_nodes, corner[4], i, tmp;  float tmp1;  current_element->shape = IV;  if ((IV != 3) && (IV != 4)) waste_line(KC,stream);  else {    fscanf(stream,"%d %d %d %d %f %f %f",           &num_nodes,&tmp,&tmp,&tmp,&tmp1,&tmp1,&tmp1);     current_element->num_nodes = num_nodes;        /* IV==3 and 4 imply triangular and quad elements, respectively. */    if (IV==3) fscanf(stream,"%d %d %d",corner,corner+1,corner+2);    else fscanf(stream,"%d %d %d %d",corner,corner+1,corner+2,corner+3);        for (i=0; i<num_nodes; i++) current_element->corner[i] = corner[i];    element_search_table[ID] = current_element;    current_element++;      if (N1) waste_line(1,stream);  }}/* Grid data are linked together by next and prev pointers within GRID    structure.  Start_grid is the global variable that points to the very    first GRID structure created.  */grid_data(stream, trans_vector)  FILE *stream;double *trans_vector;{  static GRID *prev_grid=0;  GRID *current_grid;  double coord[3];  int i;  if(first_grid) {    prev_grid = NULL;    first_grid = FALSE;  }  CALLOC(current_grid, 1, GRID, ON, AMSC);  if (number_grids==0) start_grid=current_grid;  current_grid->ID = ID;  current_grid->prev = prev_grid;  if (prev_grid) prev_grid->next = current_grid;  fscanf(stream, "%lf %lf %lf", coord, coord+1, coord+2);  for (i=0; i<3; i++) current_grid->coord[i] = coord[i] + trans_vector[i];  prev_grid = current_grid;      current_grid->next=0;  number_grids++;}/* Patch data are linked together by next and prev pointers within PATCH    structure.  Start_patch is the global variable that points to the very    first PATCH structure created.  */patch_data(stream)  FILE *stream;{  static PATCH *prev_patch=0;  PATCH *current_patch;  double tmp;  int i, corner[4];  if(first_patch) {    prev_patch = NULL;    first_patch = FALSE;  }  CALLOC(current_patch, 1, PATCH, ON, AMSC);  if (number_patches==0) start_patch=current_patch;  current_patch->ID = ID;  current_patch->prev = prev_patch;  if (prev_patch) prev_patch->next = current_patch;  waste_line(9,stream);  fscanf(stream, "%f %f %f %d %d %d %d", 	 &tmp, &tmp, &tmp, corner, corner+1, corner+2, corner+3);  for (i=0; i<4; i++) current_patch->corner[i] = corner[i];  prev_patch = current_patch;  current_patch->next=0;  number_patches++;}/* CFEG data are linked together with next and prev pointers within CFEG    structure.  Start_cfeg is the global variable that points to the very   first CFEG structure created.  CFEG table has the result from meshing    a patch. */CFEG_table(stream)  FILE *stream;{  static CFEG *prev_cfeg=0;  CFEG *current_cfeg;  int tmp, NELS, LPH, LPH_ID, LSHAPE, NDIM, NODES, ICONF;  int i, *element_list, element_num1, element_num2;  if(first_cfeg) {    prev_cfeg = NULL;    first_cfeg = FALSE;  }  waste_line(1,stream);  fscanf(stream,"%d %d %d %d %d %d %d %d",          &NDIM, &LSHAPE, &NODES, &ICONF, &LPH, &LPH_ID, &tmp, &tmp);  if (LPH != 3) waste_line(KC-2,stream);  else {    CALLOC(current_cfeg, 1, CFEG, ON, AMSC);    if (!prev_cfeg) start_cfeg=current_cfeg;    current_cfeg->ID = ID;    current_cfeg->NELS = IV; NELS = IV;    current_cfeg->prev = prev_cfeg;    if (prev_cfeg) prev_cfeg->next = current_cfeg;        /* This is the list of elements associated with this particular patch. */    CALLOC(element_list, NELS, int, ON, AMSC);    current_cfeg->element_list = element_list;            current_cfeg->LPH = LPH;                 current_cfeg->LPH_ID = LPH_ID;    current_cfeg->LSHAPE = LSHAPE;    current_cfeg->NDIM = NDIM;    current_cfeg->NODES = NODES;    current_cfeg->ICONF = ICONF;        if (LSHAPE==3) {                  /* Triangular elements. */      for (i=1; i<=NELS/2; i++) {        fscanf(stream, "%d %d %d %d %d %d %d %d %d %d",           &tmp,&tmp,&tmp,&tmp,&element_num1,&tmp,&tmp,&tmp,&tmp,&element_num2);        *element_list++ = element_num1;        *element_list++ = element_num2;      }      if (NELS%2) {        fscanf(stream, "%d %d %d %d %d",&tmp,&tmp,&tmp,&tmp,&element_num1);        *element_list++ = element_num1;      }    }    else if (LSHAPE==4) {             /* Quad elements. */      for (i=1; i<=NELS/2; i++) {        fscanf(stream, "%d %d %d %d %d %d %d %d %d %d",           &tmp,&tmp,&tmp,&tmp,&element_num1,&tmp,&tmp,&tmp,&tmp,&element_num2);        *element_list++ = element_num1;        *element_list++ = element_num2;      }      if (NELS%2) {        fscanf(stream, "%d %d %d %d %d",&tmp,&tmp,&tmp,&tmp,&element_num1);        *element_list++ = element_num1;      }    }    prev_cfeg = current_cfeg;  }}/*  reads in name data cards and puts information into NAME struct linked list  - for every component (each must contain at least 1 conductor surface patch)    stores the component name and patch ID numbers in that component  - later Song's patch list is used in assign_names() to set the patch     conductor ID numbers  - the output routine looks at the first sm_patch struct associated with    each NAME struct to determine the number of the corresponding cond name*/name_data(stream)FILE *stream;{  int len, iv, i, j, ntype, id, patch_cnt = 0;  char line[BUFSIZ], *delcr();  SM_PATCH *current_patch = NULL;  if(start_name == NULL) {	/* if first time on first patfront() call */    CALLOC(start_name, 1, NAME, ON, AMSC);    current_name = start_name_this_time = start_name;  }  else{     CALLOC(current_name->next, 1, NAME, ON, AMSC);    current_name = current_name->next;    if(start_name_this_time == NULL) {	/* if 1st time on this patfront call */      start_name_this_time = current_name;    }  }  /* get conductor name and store */  fgets(line, sizeof(line), stream); /* eat CR */  fgets(line, sizeof(line), stream);  len = strlen(line);

⌨️ 快捷键说明

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