00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 static char const Id[] = "$Id: readpatran.c 2681 2009-07-31 04:30:53Z scholz $\n\n";
00025 static char const Td[] = "$Today: " __FILE__ " " __DATE__ " " __TIME__ " $\n\n";
00026
00027 #include "magpario.h"
00028
00029
00030
00031 int ReadPatran(GridData *gdata)
00032 {
00033 int i;
00034
00035 char msg[256],fmesh[256];
00036 FILE *fd;
00037
00038 int a1,a2,a3,a4;
00039 int it, id, iv, kc, n1, n2, n3, n4, n5;
00040
00041
00042 MagparFunctionLogBegin;
00043
00044 int rank,size;
00045 ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
00046 ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
00047
00048 if (rank) {
00049 gdata->ln_vert=0;
00050 gdata->ln_ele=0;
00051
00052 MagparFunctionInfoReturn(0);
00053 }
00054
00055
00056 ierr = PetscSNPrintf(fmesh,255,"%s%s",gdata->simname,".out");CHKERRQ(ierr);
00057 ierr = PetscFOpen(PETSC_COMM_WORLD,fmesh,"r",&fd);CHKERRQ(ierr);
00058 if (!rank && !fd) {
00059 SETERRQ1(PETSC_ERR_FILE_OPEN,"Cannot open %s\n",fmesh);
00060 }
00061 PetscPrintf(PETSC_COMM_WORLD,"Opening file %s\n",fmesh);
00062
00063
00064 fscanf(fd,"%i %i %i %i %i %i %i %i %i\n",
00065 &it,&id,&iv,&kc,&n1,&n2,&n3,&n4,&n5
00066 );
00067 assert(it==25);
00068 assert(id==0);
00069 assert(iv==0);
00070 assert(kc==1);
00071
00072 fgets(msg,256,fd);
00073 PetscPrintf(PETSC_COMM_WORLD,"Title: %s\n",msg);
00074
00075 fscanf(fd,"%i %i %i %i %i %i %i %i %i\n",
00076 &it,&id,&iv,&kc,&n1,&n2,&n3,&n4,&n5
00077 );
00078 assert(it==26);
00079 assert(id==0);
00080 assert(iv==0);
00081 assert(kc==1);
00082
00083 gdata->n_vert=n1;
00084 gdata->ln_vert=gdata->n_vert;
00085 PetscPrintf(PETSC_COMM_WORLD,"Number of grid vertices: %i\n",gdata->n_vert);
00086 gdata->n_ele=n2;
00087 gdata->ln_ele=gdata->n_ele;
00088 PetscPrintf(PETSC_COMM_WORLD,"Number of grid elements: %i\n",gdata->n_ele);
00089 PetscPrintf(PETSC_COMM_WORLD,"Number of materials: %i\n",n3);
00090 gdata->n_prop=n4;
00091 assert(gdata->n_prop>0);
00092 PetscPrintf(PETSC_COMM_WORLD,"Number of element prop.: %i\n",gdata->n_prop);
00093 PetscPrintf(PETSC_COMM_WORLD,"Number of coord. frames: %i\n",n5);
00094
00095 fgets(msg,256,fd);
00096 PetscPrintf(PETSC_COMM_WORLD,"Neutral file creation date, Patran Version:\n%s\n",msg);
00097
00098
00099
00100
00101
00102 ierr = PetscMalloc(ND*gdata->n_vert*sizeof(PetscReal),&gdata->vertxyz);CHKERRQ(ierr);
00103
00104
00105 for (i=0; i<gdata->n_vert; i++) {
00106 fscanf(fd,"%i %i %i %i %i %i %i %i %i\n",
00107 &it,&id,&iv,&kc,&n1,&n2,&n3,&n4,&n5
00108 );
00109 assert(it==1);
00110 assert(iv==0);
00111 assert(kc==2);
00112
00113
00114 assert(id-1==i);
00115
00116 #ifdef PETSC_USE_SINGLE
00117 fscanf(fd,"%f %f %f\n",
00118 #else
00119 fscanf(fd,"%lf %lf %lf\n",
00120 #endif
00121 gdata->vertxyz+ND*i+0,
00122 gdata->vertxyz+ND*i+1,
00123 gdata->vertxyz+ND*i+2
00124 );
00125
00126 fgets(msg,256,fd);
00127 }
00128
00129
00130
00131
00132 ierr = PetscMalloc(NV*gdata->n_ele*sizeof(int),&gdata->elevert);CHKERRQ(ierr);
00133 ierr = PetscMalloc(gdata->n_ele*sizeof(int),&gdata->eleprop);CHKERRQ(ierr);
00134
00135 for (i=0; i<gdata->n_ele; i++) {
00136 fscanf(fd,"%i %i %i %i %i %i %i %i %i\n",
00137 &it,&id,&iv,&kc,&n1,&n2,&n3,&n4,&n5
00138 );
00139
00140 assert(it==2);
00141 assert(kc==2);
00142 assert(n1==0);
00143
00144
00145 assert(iv==5);
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 fscanf(fd,"%i %i %i %i",&a1,&a2,&a3,&a4);
00157 assert(a1==NV);
00158
00159
00160 gdata->eleprop[i]=--a3;
00161 assert(gdata->eleprop[i]>=0);
00162 assert(gdata->eleprop[i]<gdata->n_prop);
00163
00164 fgets(msg,256,fd);
00165 fscanf(fd,"%i %i %i %i\n",
00166 gdata->elevert+i*NV+0,
00167 gdata->elevert+i*NV+1,
00168 gdata->elevert+i*NV+2,
00169 gdata->elevert+i*NV+3
00170 );
00171 gdata->elevert[i*NV+0]--;
00172 gdata->elevert[i*NV+1]--;
00173 gdata->elevert[i*NV+2]--;
00174 gdata->elevert[i*NV+3]--;
00175 }
00176
00177 ierr = PetscFClose(PETSC_COMM_WORLD,fd);CHKERRQ(ierr);
00178
00179
00180 MagparFunctionLogReturn(0);
00181 }
00182