Página Principal | Lista Alfabética | Lista de Componentes | Lista de Arquivos | Componentes Membros | Arquivos Membros

nfr.c

Vá para a documentação deste arquivo.
00001 /*
00002 ** nfr.c - Reads a two-dimensional frame model from a neutral format file.
00003 **
00004 ** Description:
00005 ** ---------------------------------------------------------------
00006 **
00007 ** This file contains functions to read a two-dimensional frame
00008 ** model dada from a file and to store these data in the 
00009 ** adopted data structure.  
00010 ** This data structure is described in file "crs.c".
00011 ** The model  data is read from a stream file in the neutral file
00012 ** format adopted in Tecgraf and Civil Engineering Dept. of 
00013 ** PUC-Rio. Please, refer to specific documentation on this 
00014 ** format.
00015 **
00016 ** The API of this module is described in file "nfr.h".
00017 **
00018 ** ---------------------------------------------------------------
00019 **
00020 ** Created:    07-Sep-2003    Luiz F. Martha
00021 **
00022 */
00023 
00024 /*
00025 ** ---------------------------------------------------------------
00026 ** Global variables and symbols:
00027 */
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <string.h>
00031 
00032 #include "crs.h"
00033 #include "nfr.h"
00034 
00035 /*
00036 ** ---------------------------------------------------------------
00037 ** Local variables and symbols:
00038 */
00039 
00041 typedef struct _matdata {
00042    double    E;      /* Young's modulus           */
00043    double    Nu;     /* Poisson's ratio           */
00044 } MatData ;
00045 
00047 static MatData *mat_data = NULL;
00048 
00050 typedef struct _secprop {
00051    double Ax;
00052    double Ay;
00053    double Az;
00054    double Ix;
00055    double Iy;
00056    double Iz;
00057    double Cw;
00058    double Hy;
00059    double Hz;
00060 } SecProp;
00061 
00063 static SecProp *sec_prop = NULL;
00064 
00066 typedef struct _endlib {
00067    int    idx;
00068    int    idy;
00069    int    idz;
00070    int    irx;
00071    int    iry;
00072    int    irz;
00073    int    jdx;
00074    int    jdy;
00075    int    jdz;
00076    int    jrx;
00077    int    jry;
00078    int    jrz;
00079 } EndLib;
00080 
00082 static EndLib *end_lib = NULL;
00083 
00084 
00085 /*
00086 ** ---------------------------------------------------------------
00087 ** Private functions:
00088 */
00089 static int  NextLabel( FILE *fd, char *label );
00090 static void FreeData( void );
00091 static int  ReadNodalSupports( FILE *fd );
00092 static int  ReadMatData( FILE *fd );
00093 static int  ReadSecProp( FILE *fd );
00094 static int  ReadEndLib( FILE *fd );
00095 static int  ReadUnifLoad( FILE *fd );
00096 static void ReadBeamElems( FILE *fd );
00097 
00098 /*=========================  NextLabel  =========================*/
00099 
00100 static int  NextLabel( FILE *fd, char *label )
00101 {
00102  int c;
00103  
00104  while( ( c = fgetc( fd ) ) != '%' )           /* finds next % */
00105  {
00106   if( c == EOF )
00107   return( 0 );
00108  }
00109  if( fscanf( fd, "%s", label ) != 1 )          /* scan label string */
00110   return( 0 );
00111  else
00112   return( 1 );
00113 }
00114 
00115 /*=========================  FreeData  =========================*/
00116 
00117 static void FreeData( void )
00118 {
00119 /* Release memory used by auxiliary arrays.
00120  */
00121  if( mat_data )
00122   free( mat_data );
00123  mat_data = NULL;
00124  if( sec_prop )
00125   free( sec_prop );
00126  sec_prop = NULL;
00127  if( end_lib )
00128   free( end_lib );
00129  end_lib = NULL;
00130 }
00131 
00132 /*========================  ReadNodalSupports  =======================*/
00133 
00134 static int ReadNodalSupports( FILE *fd )
00135 {
00136  char      label[80];             /* sections labels             */
00137  int       found = 0;             /* flag for found nodal data   */
00138  int       nnodes;                /* read number of nodes        */
00139  int       node_id;               /* current node id             */
00140  int       i;                     /* counter                     */
00141  int       dx, dy, dz, rx, ry, rz;/* support codes (0=free,1=fix)*/
00142 
00143 /* Find nodal support data section in neutral file.
00144  */
00145  rewind( fd );
00146  while( 1 )
00147  {
00148   if( NextLabel( fd, label ) == 0 )
00149   {
00150    printf( "\n Invalid neutral file or label END doesn't exist.\n\n" );
00151    return( 0 );
00152   }
00153   else if( strcmp( label, "NODE.SUPPORT" ) == 0 )
00154   {
00155    found = 1;
00156    break;
00157   }
00158   else if( strcmp( label, "END" ) == 0 )
00159    break;
00160   else             /* not a target label */
00161    continue;
00162  }
00163  if( !found )
00164  {
00165   return( 1 );
00166  }
00167 
00168 /* Read number of nodes of this section.
00169  */
00170  fscanf( fd, "%d", &nnodes );
00171 
00172 /* Read node support conditions.
00173  */
00174  for( i = 0; i < nnodes; i++ )
00175  {
00176   fscanf( fd, "%d  %d %d %d %d %d %d", &node_id, &dx, &dy, &dz, &rx, &ry, &rz );
00177   if( rz == 1 )
00178    crsFixNodeRot( node_id-1 );
00179  }
00180 
00181  return( 1 );
00182 }
00183 
00184 /*========================  ReadMatData  =======================*/
00185 
00186 static int ReadMatData( FILE *fd )
00187 {
00188  char      label[80];             /* sections labels             */
00189  int       found = 0;             /* flag for found material data*/
00190  int       nmats;                 /* read number of materials    */
00191  int       mat_id;                /* material id (not used)      */
00192  int       i;                     /* counter                     */
00193 
00194 /* Find isotropic material data section in neutral file.
00195  */
00196  rewind( fd );
00197  while( 1 )
00198  {
00199   if( NextLabel( fd, label ) == 0 )
00200   {
00201    printf( "\n Invalid neutral file or label END doesn't exist.\n\n" );
00202    return( 0 );
00203   }
00204   else if( strcmp( label, "MATERIAL.ISOTROPIC" ) == 0 )
00205   {
00206    found = 1;
00207    break;
00208   }
00209   else if( strcmp( label, "END" ) == 0 )
00210    break;
00211   else             /* not a target label */
00212    continue;
00213  }
00214  if( !found )
00215  {
00216   printf( "\n Could not find material data in neutral file.\n\n" );
00217   return( 0 );
00218  }
00219 
00220 /* Read number of isotropic materials.
00221  */
00222  fscanf( fd, "%d", &nmats );
00223 
00224 /* Allocate memory for auxiliary array of material parameters.
00225  */
00226  mat_data = (MatData *)calloc( nmats, sizeof( MatData ) );
00227 
00228 /* Read material data.
00229  */
00230  for( i = 0; i < nmats; i++ )
00231  {
00232   fscanf( fd, "%d %lg %lg", &mat_id, &mat_data[i].E, &mat_data[i].Nu );
00233  }
00234 
00235  return( 1 );
00236 }
00237 
00238 /*========================  ReadSecProp  =======================*/
00239 
00240 static int ReadSecProp( FILE *fd )
00241 {
00242  char      label[80];             /* sections labels                  */
00243  int       found = 0;             /* flag for found cross-section data*/
00244  int       nsecs;                 /* read number of cross-sections    */
00245  int       sec_id;                /* cross-section id (not used)      */
00246  int       i;                     /* counter                          */
00247 
00248 /* Find cross-section data section in neutral file.
00249  */
00250  rewind( fd );
00251  while( 1 )
00252  {
00253   if( NextLabel( fd, label ) == 0 )
00254   {
00255    printf( "\n Invalid neutral file or label END doesn't exist.\n\n" );
00256    return( 0 );
00257   }
00258   else if( strcmp( label, "SECTION.PROPERTY" ) == 0 )
00259   {
00260    found = 1;
00261    break;
00262   }
00263   else if( strcmp( label, "END" ) == 0 )
00264    break;
00265   else             /* not a target label */
00266    continue;
00267  }
00268  if( !found )
00269  {
00270   printf( "\n Could not find cross-section data in neutral file.\n\n" );
00271   return( 0 );
00272  }
00273 
00274 /* Read number of cross-sections
00275  */
00276  fscanf( fd, "%d", &nsecs );
00277 
00278 /* Allocate memory for auxiliary array of cross-section parameters
00279  */
00280  sec_prop = (SecProp *)calloc( nsecs, sizeof( SecProp ) );
00281 
00282 /* Read cross-section data.
00283  */
00284  for( i = 0; i < nsecs; i++ )
00285  {
00286   fscanf( fd, "%d %lg %lg %lg %lg %lg %lg %lg %lg %lg", &sec_id,
00287               &sec_prop[i].Ax, &sec_prop[i].Ay, &sec_prop[i].Az, 
00288               &sec_prop[i].Ix, &sec_prop[i].Iy, &sec_prop[i].Iz, 
00289               &sec_prop[i].Cw, &sec_prop[i].Hy, &sec_prop[i].Hz );
00290  }
00291 
00292  return( 1 );
00293 }
00294 
00295 /*========================  ReadEndLib  =======================*/
00296 
00297 static int ReadEndLib( FILE *fd )
00298 {
00299  char      label[80];             /* sections labels             */
00300  int       found = 0;             /* flag for found endlib data  */
00301  int       nlibs;                 /* read number of endlibs      */
00302  int       lib_id;                /* endlib id (not used)        */
00303  int       i;                     /* counter                     */
00304 
00305 /* Find beam end-liberation data section in neutral file.
00306  */
00307  rewind( fd );
00308  while( 1 )
00309  {
00310   if( NextLabel( fd, label ) == 0 )
00311   {
00312    printf( "\n Invalid neutral file or label END doesn't exist.\n\n" );
00313    return( 0 );
00314   }
00315   else if( strcmp( label, "BEAM.END.LIBERATION" ) == 0 )
00316   {
00317    found = 1;
00318    break;
00319   }
00320   else if( strcmp( label, "END" ) == 0 )
00321    break;
00322   else             /* not a target label */
00323    continue;
00324  }
00325  if( !found )
00326  {
00327   return( 1 );
00328  }
00329 
00330 /* Read number of beam end-liberations.
00331  */
00332  fscanf( fd, "%d", &nlibs );
00333 
00334 /* Allocate memory for auxiliary array of beam end-liberations.
00335  */
00336  end_lib = (EndLib *)calloc( nlibs, sizeof( EndLib ) );
00337 
00338 /* Read end-liberation data.
00339  */
00340  for( i = 0; i < nlibs; i++ )
00341  {
00342   fscanf( fd, "%d %d %d %d %d %d %d %d %d %d %d %d %d", &lib_id, 
00343               &end_lib[i].idx, &end_lib[i].idy, &end_lib[i].idz,
00344               &end_lib[i].irx, &end_lib[i].iry, &end_lib[i].irz,
00345               &end_lib[i].jdx, &end_lib[i].jdy, &end_lib[i].jdz,
00346               &end_lib[i].jrx, &end_lib[i].jry, &end_lib[i].jrz );
00347  }
00348 
00349  return( 1 );
00350 }
00351 
00352 /*========================  ReadUnifLoad  =======================*/
00353 
00354 static int ReadUnifLoad( FILE *fd )
00355 {
00356  char      label[80];        /* sections labels                    */
00357  int       found = 0;        /* flag for found unif.load data      */
00358  int       nunfs;            /* read number of uniform loads       */
00359  int       member_id;        /* current member id                  */
00360  int       dir;              /* load direction (local or global)   */
00361  double    a1, a2;           /* ratio of starting and end load dist*/
00362  double    q[3];             /* load force components              */
00363  double    m[3];             /* load moment components             */
00364  int       i;                /* counter                            */
00365 
00366 /* Find beam uniform load data section in neutral file.
00367  */
00368  rewind( fd );
00369  while( 1 )
00370  {
00371   if( NextLabel( fd, label ) == 0 )
00372   {
00373    printf( "\n Invalid neutral file or label END doesn't exist.\n\n" );
00374    return( 0 );
00375   }
00376   else if( strcmp( label, "LOAD.CASE.BEAM.UNIFORM" ) == 0 )
00377   {
00378    found = 1;
00379    break;
00380   }
00381   else if( strcmp( label, "END" ) == 0 )
00382    break;
00383   else             /* not a target label */
00384    continue;
00385  }
00386  if( !found )
00387  {
00388   printf( "\n Could not find beam uniform load data in neutral file.\n\n" );
00389   return( 0 );
00390  }
00391 
00392 /* Read number of beam uniform loads
00393  */
00394  fscanf( fd, "%d", &nunfs );
00395 
00396 /* Read beam uniform load data.
00397  */
00398  for( i = 0; i < nunfs; i++ )
00399  {
00400   fscanf( fd, "%d", &member_id );
00401   fscanf( fd, "%d", &dir );
00402   fscanf( fd, "%lg %lg", &a1, &a2 );
00403   fscanf( fd, "%lg %lg %lg", &q[0], &q[1], &q[2] );
00404   fscanf( fd, "%lg %lg %lg", &m[0], &m[1], &m[2] );
00405   crsMemberUnifLoad( member_id-1, q[1] );
00406  }
00407 
00408  return( 1 );
00409 }
00410 
00411 /*=====================  ReadBeamElems  =======================*/
00412 
00413 static void ReadBeamElems( FILE *fd )
00414 {
00415  int       nelems;                /* read number of elements     */
00416  int       dummy_id;              /* dummy element id            */
00417  int       elem_id;               /* current element id          */
00418  int       node0_id;              /* element initial node id     */
00419  int       node1_id;              /* element final node id       */
00420  int       mat_id;                /* element material id         */
00421  int       sec_id;                /* element cross-section id    */
00422  int       ori_id;                /* non used elem. orientat. id */
00423  int       lib_id;                /* element end-liberation id   */
00424  int       i;                     /* counters                    */
00425 
00426  fscanf( fd, "%d", &nelems );
00427 
00428  for( i = 0; i < nelems; i++ )
00429  {
00430 /* Read element number, material index, section index, orientation 
00431  * index (not considered), and end-liberation index.
00432  */
00433   fscanf( fd, "%d %d %d %d %d", &dummy_id, &mat_id, &sec_id, &ori_id, &lib_id );
00434 
00435 /* Read element node incidence.
00436  * It is assumed that the read incidences contains numbers 
00437  * (index is the number decreased by one).
00438  */
00439   fscanf( fd, "%d %d", &node0_id, &node1_id );
00440 
00441 /* Add this element to project data structure.
00442  */
00443   elem_id = crsAddMember( node0_id-1, node1_id-1 );
00444 
00445 /* Set the elasticity modulus of this element.
00446  */
00447   crsMemberElasticity( elem_id, mat_data[mat_id-1].E );
00448 
00449 /* Set the moment of inertia of this element.
00450  */
00451   crsMemberInertia( elem_id, sec_prop[sec_id-1].Iz );
00452 
00453 /* Set the end liberations of this member.
00454  */
00455   if( end_lib[lib_id-1].irz == 0 )
00456    crsFreeMemberEndRot( elem_id, 0 );
00457   if( end_lib[lib_id-1].jrz == 0 )
00458    crsFreeMemberEndRot( elem_id, 1 );
00459  }
00460 }
00461 
00462 
00463 /*
00464 ** ---------------------------------------------------------------
00465 ** Entry points begin here:
00466 */
00467 
00468 /*=======================  nfrCrsModel  =======================*/
00469 
00470 void *nfrCrsModel( FILE *fd )
00471 {
00472  int       num_nodes = 0;
00473  int       num_elems = 0;
00474  char      label[80];             /* sections labels             */
00475  void      *model;                /* created model */
00476 
00477 /* Read total number of nodes and elements.
00478  */
00479  rewind( fd );
00480  while( 1 )
00481  {
00482   if( NextLabel( fd, label ) == 0 )
00483   {
00484    printf( "\n Invalid neutral file or label END doesn't exist.\n\n" );
00485    return( NULL );
00486   }
00487   else if( strcmp( label, "NODE" ) == 0 )
00488   {
00489    fscanf( fd,"%d", &num_nodes );
00490    if( (num_nodes > 0) && (num_elems > 0) )
00491     break;
00492   }
00493   else if( strcmp( label, "ELEMENT" ) == 0 )
00494   {
00495    fscanf( fd,"%d", &num_elems );
00496    if( (num_nodes > 0) && (num_elems > 0) )
00497     break;
00498   }
00499   else if( strcmp( label, "END" ) == 0 )
00500    break;
00501   else             /* not a target label */
00502    continue;
00503  }
00504 
00505  if( (num_nodes < 1) && (num_elems < 1) )
00506  {
00507   printf( "\n Could not find mesh dimensions in neutral file.\n\n" );
00508   return( NULL );
00509  }
00510 
00511 /* Initialiaze project database and return the created model pointer.
00512  */
00513  model = crsInitModel( num_nodes, num_elems );
00514 
00515  return( model );
00516 }
00517 
00518 /*========================  nfrCrsNodes  =======================*/
00519 
00520 int nfrCrsNodes( FILE *fd )
00521 {
00522  char      label[80];             /* sections labels             */
00523  int       found = 0;             /* flag for found nodal data   */
00524  int       nnodes;                /* read number of nodes        */
00525  int       dummy_id;              /* dummy node id               */
00526  int       node_id;               /* current node id             */
00527  int       i;                     /* counter                     */
00528  double    x, y, z;               /* coordinates of a node       */
00529 
00530 /* Find nodal coordinate data section in neutral file.
00531  */
00532  rewind( fd );
00533  while( 1 )
00534  {
00535   if( NextLabel( fd, label ) == 0 )
00536   {
00537    printf( "\n Invalid neutral file or label END doesn't exist.\n\n" );
00538    return( 0 );
00539   }
00540   else if( strcmp( label, "NODE.COORD" ) == 0 )
00541   {
00542    found = 1;
00543    break;
00544   }
00545   else if( strcmp( label, "END" ) == 0 )
00546    break;
00547   else             /* not a target label */
00548    continue;
00549  }
00550  if( !found )
00551  {
00552   printf( "\n Could not find nodal coordinate data in neutral file.\n\n" );
00553   return( 0 );
00554  }
00555 
00556 /* Read number of nodes of this section.
00557  */
00558  fscanf( fd, "%d", &nnodes );
00559 
00560 /* Read node number (not considered) and nodal coordinates.
00561  * It is assumed that the nodes are numbered in consecutive
00562  * order.
00563  */
00564  for( i = 0; i < nnodes; i++ )
00565  {
00566   fscanf( fd, "%d %lf %lf %lf", &dummy_id, &x, &y, &z );
00567   node_id = crsAddNode( x, y );
00568  }
00569 
00570 /* Read nodal support data.
00571  */
00572  if( ! ReadNodalSupports( fd ) )
00573   return( 0 );
00574 
00575  return( 1 );
00576 }
00577 
00578 /*=======================  nfrCrsMembers  =====================*/
00579 
00580 int nfrCrsMembers( FILE *fd )
00581 {
00582  char      label[80];             /* sections labels             */
00583  int       found = 0;             /* flag for found element data */
00584 
00585 /* Read arrays of material, cross-section, and end-liberation data.
00586  */
00587  if( ! ReadMatData( fd ) )
00588  {
00589   FreeData( );
00590   return( 0 );
00591  }
00592  if( ! ReadSecProp( fd ) )
00593  {
00594   FreeData( );
00595   return( 0 );
00596  }
00597  if( ! ReadEndLib( fd ) )
00598  {
00599   FreeData( );
00600   return( 0 );
00601  }
00602 
00603 /* Find element data sections in neutral file and read data.
00604  */
00605  rewind( fd );
00606  while( 1 )
00607  {
00608   if( NextLabel( fd, label ) == 0 )
00609   {
00610    printf( "\n Invalid neutral file or label END doesn't exist.\n\n" );
00611    return( 0 );
00612   }
00613   else if( strcmp( label, "ELEMENT.BEAM" ) == 0 )
00614   {
00615    ReadBeamElems( fd );
00616    found = 1;
00617   }
00618   else if( strcmp( label, "END" ) == 0 )
00619    break;
00620   else             /* not a target label */
00621    continue;
00622  }
00623  if( !found )
00624  {
00625   printf( "\n Could not find element data in neutral file.\n\n" );
00626   return( 0 );
00627  }
00628 
00629 /* Read beam uniform load data.
00630  */
00631  if( ! ReadUnifLoad( fd ) )
00632  {
00633   FreeData( );
00634   return( 0 );
00635  }
00636 
00637 /* Release memory used by auxiliary arrays.
00638  */
00639  FreeData( );
00640 
00641  return( 1 );
00642 }
00643 

Gerado em Tue Oct 5 04:55:00 2004 para Trab3 por doxygen 1.3.4