/* CalculiX -> SALOME interface program, Bernhardi, NOV. 2011 */ /**************************************************************************** * THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; * * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT * WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU * LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS. * * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE * ALONG WITH THIS PROGRAM; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION, INC, * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *****************************************************************************/ /* CALMED: A small interface utility to translate CalculiX results files into MED files for post-processing with SALOME Calmed is a small program which can be used to translate CalculiX .frd files to .med files which in turn can be imported into SALOME-PostPro. I have run several examples with it, including larger ones, on Suse Linux 32 and 64 bit machines; and also a few examples on ubuntu and Gentoo. License is GNU GPL. Calmed comes without any warranty, however I hope it will perhaps be useful to someone... There certainly will still be lots of bugs in it! This is Calmed Version 8, it must be used with MED libraries version 3. How to compile from sources - Calmed must be linked against the HDF5 and MED libraries; therefore, install these libraries into proper locations (for example, /usr/local/lib) and issue an ldconfig command before trying to compile calmed6.c. - Mkdir a new directory; e.g. ~/calmed. - Put the tar archive into it and untar the tar archive - Edit the Makefile in order to configure it to your system. - Type make. The executable will be made. Usage: - Assume you have done a CalculiX analysis with results file haltewinkel.frd. Then, to invoke Calmed, issue a /calmed8 haltewinkel (without extension .frd!) - Calmed8 should then generate a file haltewinkel.rmed which can be imported into SALOME-PostPro using the import > medfile feature of post-pro. - Do suitable EXPANDs to find entries like DISP or STRESS (depending on the calculix analysis). These directories, in turn, contain the results of all time steps which have been calculated. - Right-click on one of the time stamps, and choose from one of the presentation type options. - To do an animation of the results, right-click on one of the field names (e.g. STRESS), and click on "sequenced animation". This works only if there are more than one time increments. - To to an (x,y) diagram of e.g. the displacement of a node, use "evolution of a point". Remarks - Currently, there are no element sets or node sets on the CalculiX .frd file; thus these sets are not translated. - Only averaged nodal results so far; no integration point data. - In CalculiX, most of the plane elements are expanded into volume elements internally. Results are output to the .frd file in 3-D format if the CalculiX "output-3D" file output directive is used. Calmed translates this data into MED volume element data; however, the node numbers will differ from the original ones. - Salome generates medfiles with extension .med while calmed generates files with extension .MED to avoid overwriting. - The SALOME presentation type "cut planes" seemingly works for linear elements only. Bug in Calmed? - GMSH (see www.geuz.org) can also import .MED files and can be used to post-process them. I tried only few examples so far; however, all the plots looked OK. - Comments are welcome! - My email adress: otto(klammeraffe)bernhardi(dot)com ======================================================================*/ #include #include #include #include #include #define MESGERR 1 #include void exitif(); /* return error message and exit. */ void countfrd(); /* count number of nodes and elements. */ void allocate(); /* allocate large data arrays. */ void readnodes(); /* read node point data from .frd file. */ void readelements(); /* read element connectivities from .frd file. */ void writemesh(); /* write mesh data to med file. */ void nodesort(); /* sort node point numbers. */ int findnode(); /* find node number in nodes array. */ void transdat(); /* read node point results data. */ FILE *fid; /* CalculiX results file. */ char inname[100]; /* input file name: .frd file. */ char outname[100]; /* output file namei: .med file. */ int ret; /* return key. */ char *sret; /* return key for fgets(). */ char line[201]; /* this holds one input line. */ char name[101]; /* name of dataset. */ int maxline=200; /* max 100 characters in one input line. */ int key; /* .frd file record key. */ char label; /* .frd file record data label. */ int node; /* node counter. */ int element; /* element counter. */ med_int maxnode; /* total number of nodes. */ med_int maxele[16]; /* total number of elements. */ int sumele; /* total number of all elements. */ int numnode; /* current number of node. */ int numele; /* current number of element. */ int elnumber[16]; /* number of elements for each type. */ med_int *unsorted; /* node point numbers, unsorted. */ int *nodenumbers; /* nope point numbers; sorted. */ int *nodeindex; /* pointers to node data. */ med_float *coords; /* node point coordinates. */ med_int *elnumbers[16]; /* element numbers. */ med_int *elem[16]; /* element connectivity. */ double x,y,z; /* node coordinates. */ int n[101]; /* nodes at current element. */ int eltype; /* type of current element. */ int dummy; /* nothing. */ char material[101]; /* material at element. */ int nelnode; /* number of nodes at current element. */ int nc,nc1; /* counts nodes during reading of elements. */ int i,j,k; /* loop counters. */ char setname[6]; /* results data set name. */ double value; /* time, frequency, BLF. */ char numnd[20]; /* number of nodes to follow. */ char text[21]; /* descriptive text. */ int ictype; /* analysis type. */ /* .eq.0 static. */ /* .eq.1 time step. */ /* .eq.2 frequency. */ /* .eq.3 load step. */ /* .eq.4 user named. */ int numstp; /* step number. */ char analys[11]; /* type of analysis. */ int format; /* .eq.0, short format; .eq.1, long format. */ med_int ncomps; /* number of entities in this data set. */ int irtype; /* type of nodal data (mat dependent). */ med_float *nodedata; /* node point results data. */ double temp; /* temporary value (Mises etc.) */ char comp[11]; /* component name. */ int menue; /* should be 1 */ int ictype; /* type of entity. */ /* .eq.1, scalar. */ /* .eq.2, vector with 3 components. */ /* .eq.4, matrix. */ /* .eq.12, vector w 3 amps and 3 phase angles. */ int icind1; /* sub-component index or row number. */ int icind2; /* column number for ictype .eq.4. */ int iexist; /* .eq 0, data provided; .eq.1, to be calculated. */ char icname[100]; /* name of the calculated component. */ med_float xx,yy,zz,xy,yz,zx; /* node point result data components. */ /* eltype= 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12, 0, 0, 0 */ int numnodes[16]= { 0, 8, 6, 4,20,15,10, 3, 6, 4, 8, 2, 3, 0, 0, 0}; /* seqabq contains MED element connectivities in abaqus sequence.*/ int seqabq[16][21]= { 0, 0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* null: MED_POINT1 */ 1, 1,2,3,4,5,6,7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C3D8: MED_HEXA8 */ 2, 1,2,3,4,5,6,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C3D6: MED_PENTA6 */ 3, 1,2,3,4,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C3D4: MED_TETRA4 */ 4, 1,2,3,4,5,6,7, 8, 9,10,11,12,17,18,19,20,13,14,15,16, /* C3D20: MED_HEXA20*/ 5, 1,2,3,4,5,6,7, 8, 9,13,14,15,10,11,12, 0, 0, 0, 0, 0, /* C3D15: MED_PENTA15*/ 6, 1,3,2,4,7,6,5, 8, 10,9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C3D10: MED_TETRA10*/ 7, 1,2,3,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* S3: MED_TRIA3 */ 8, 1,3,2,6,5,4,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* S6: MED_TRIA6*/ 9, 1,2,4,3,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* S4R: MED_QUAD4 */ 10, 1,4,3,2,8,7,6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* S8R: MED_QUAD8 */ 11, 1,2,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B31: MED_SEG2 */ 12, 1,3,2,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B32: MED_SEG3 */ 0, 0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* null: NULL */ 0, 0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* null: NULL */ 0, 0,0,0,0,0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* null: NULL */ }; med_idt mfid; /* .med formatted file. */ med_int spacedim=3; /* spatial dimension. */ med_int meshdim=3; /* mesh dimension. */ char maa[MED_NAME_SIZE+1]; char dtunit[MED_SNAME_SIZE+1]={""}; char description[MED_COMMENT_SIZE +1]; char comment[MED_COMMENT_SIZE+1]; /* comment written to medfile. */ char axisname[MED_SNAME_SIZE+1]; char axisunit[MED_SNAME_SIZE+1]; char nodename[MED_SNAME_SIZE+1]={""}; med_int famnumber[1]={0}; char elementname[MED_SNAME_SIZE+1]={" "}; char componentunit[21*MED_SNAME_SIZE+1]={" "}; med_float dt=0.0; /* date du pas de temps. */ char nomcha[MED_NAME_SIZE+1]; /* nom du champ. */ char component[21*MED_SNAME_SIZE+1]={""}; med_geometry_type typmai[16] = { MED_POINT1, MED_HEXA8, MED_PENTA6, MED_TETRA4, MED_HEXA20, MED_PENTA15, MED_TETRA10, MED_TRIA3, MED_TRIA6, MED_QUAD4, MED_QUAD8, MED_SEG2, MED_SEG3, MED_POINT1,MED_POINT1,MED_POINT1 }; char nommai[16][MED_SNAME_SIZE+1] = { "POINT1", "HEXA8", "PENTA6", "TETRA4", "HEXA20", "PENTA15", "TETRA10", "TRIA3", "TRIA6", "QUAD4", "QUAD8", "SEG2", "SEG3", "POINT1","POINT1","POINT1" }; /*============================================================================*/ int main (int argc, char **argv) { /* printf("argc=%d\n", argc); */ exitif(argc != 2,"usage: calmed frd_filename (without extension .frd)",NULL); exitif(strlen(argv[1])>90,"sorry frd filename too long. ", NULL); strcpy(inname, argv[1]); strcat(inname, ".frd"); printf("Calmed 8, Copyright(C) 2011 Bernhardi \n"); printf("Calmed comes with ABSOLUTELY NO WARRANTY. This is free\n"); printf("software, and you are welcome to redistribute it under\n"); printf("certain conditions, see http://www.gnu.org/licenses/gpl.html\n\n"); printf("Lecture du fichier %s\n",inname); fid = fopen(inname,"r"); exitif(fid==NULL,"Erreur a l'ouverture du fichier ",inname); countfrd(); /* determine number of elements, nodes, etc. */ allocate(); /* allocate large arrays. */ rewind(fid); readnodes(); /* read nodes: coordinates. */ printf("calmed: sorting nodes.\n"); for(i=0;i<=maxnode; i++) { nodeindex[i]=i; unsorted[i]=nodenumbers[i]; } nodesort(nodenumbers,nodeindex,maxnode); /* printf("arrays nodeindex, nodenumbers, unsorted. \n"); for(i=0;i<=maxnode;i++) { printf("%d %d %d\n", nodeindex[i], nodenumbers[i], unsorted[i]); } */ rewind(fid); readelements(); /* read element connectivities. */ /* Creation du fichier .med */ printf("calmed: attempting to open .rmed file. \n"); strcpy(outname, argv[1]); strcat(outname, ".rmed"); mfid=MEDfileOpen(outname, MED_ACC_RDWR); exitif(mfid<0,"Erreur a la creation du fichier ",outname); strncpy(maa, argv[1],MED_NAME_SIZE); strncpy(description,argv[1],MED_COMMENT_SIZE); strncpy(comment,argv[1],MED_COMMENT_SIZE); exitif(MEDfileCommentWr(mfid,comment), "Error cannot write comment to medfile", outname); writemesh(); /* write node point and element data to medfile. */ printf("calmed: rewinding input file .frd. Reading node point data blocks.\n"); rewind(fid); transdat(); /* read block of nodal results data. */ /* Fermeture du fichier: med file. */ printf("calmed: closing MED file %s.\n", inname); exitif(MEDfileClose(mfid)<0,"Erreur a la fermeture du fichier",outname); printf("calmed: closing calculix results file %s\n", inname); ret = fclose(fid); exitif(ret < 0,"lors de la fermeture du fichier",inname); printf("calmed: It was a pleasure serving you. Bye. \n"); printf("calmed: returning to system. \n"); exit(0); } /*============================================================================*/ void countfrd() { int i; /* Start counting elements and nodes on data set. */ for(i=1;i<=15;i++) maxele[i]=-1; sumele=-1; maxnode=-1; for(;;) { sret=fgets(line, maxline, fid); exitif(sret==NULL, "countfrd: unexpected end-of-line while reading from", inname); ret=sscanf(line, "%5d", &key); exitif(ret==0, "countfrd: unexpected error 1 while reading from", inname); /* printf("inname=%s, key=%d\n", inname, key); */ if(key==1) { ret=sscanf(line, "%5d %c %s", &key, &label, name); exitif(ret==0, "countfrd: unexpected error 1 while reading from", inname); /* printf("label=%c, name=%s\n", label, name); */ } if(key==2) { ret=sscanf(line, "%5d %c", &key, &label); exitif(ret==0, "countfrd: unexpected error 2 while reading from", inname); printf("countfrd: counting block of node coordinates. \n"); exitif(label!='C', "countfrd: wrong data line label; label=\n", label); for(;;) { sret=fgets(line, maxline, fid); exitif(sret==NULL, "countfrd: unexpected end-of-line while reading from", inname); ret=sscanf(line, "%5d", &key); exitif(ret==0, "countfrd: unexpected error 1 while reading from", inname); /* printf("countfrd: node point record key=%d\n", key); */ if(key==-1) { maxnode++; } else if(key==-3) { break; } else { /* printf("countfrd: ignoring key=%d\n", key); */ } } } if(key==3) { ret=sscanf(line, "%5d %c", &key, &label); exitif(ret==0, "countfrd: unexpected error 2 while reading from", inname); printf("countfrd: counting block of element connectivities. \n"); exitif(label!='C', "countfrd: wrong data line label; label=\n", label); for(;;) { sret=fgets(line, maxline, fid); exitif(sret==NULL, "countfrd: unexpected end-of-line while reading from", inname); ret=sscanf(line, "%5d", &key); exitif(ret==0, "countfrd: unexpected error 1 while reading from", inname); /* printf("countfrd: element record key=%d\n", key); */ if(key==-1) { ret=sscanf(line, "%3d %d %d %5d %s", &key,&element,&eltype,&dummy,material); exitif(ret==0, "countfrd: unexpected error 1 while reading from", inname); exitif(eltype<1||eltype>15, "countfrd: wrong eltype found.", NULL); /* printf("countfrd: key=%d, element=%d, eltype=%d, material=%s\n", key,element,eltype,material); */ sumele++; maxele[eltype]++; /* printf("maxele=%d\n", maxele[eltype]); */ } else if(key==-2) { } else if(key==-3) { break; } else { /* printf("countfrd: ignoring key=%d\n", key); */ } } } if(key==9999) break; } printf("countfrd: %d nodes found on dataset. \n", maxnode+1); for(i=1;i<=15;i++) { if(maxele[i]>=0) { printf("countfrd: %d elements of type %d found on dataset. \n", maxele[i]+1,i); } } exitif(maxnode<=0, "countfrd: no nodes found. Cannot proceed. ", NULL); exitif(sumele<=0, "countfrd: no elements found. Cannot proceed. ", NULL); } /*===========================================================================*/ void allocate() { int i; /* allocate memory: Mesh. */ printf("allocate: allocating large data arrays. \n"); nodenumbers=(int*)malloc(sizeof(int)*(maxnode+1)); exitif(nodenumbers==NULL,"allocate: allocation failure: node numbers.",NULL); unsorted=(med_int*)malloc(sizeof(med_int)*(maxnode+1)); exitif(unsorted==NULL,"allocate: allocation failure: node numbers.",NULL); nodeindex=(int*)malloc(sizeof(int)*(maxnode+1)); exitif(nodeindex==NULL,"allocate: allocation failure: node pointers",NULL); coords=(med_float*)malloc(sizeof(med_float)*3*(maxnode+1)); exitif(coords==NULL,"allocate: allocation failure: node coordinates.",NULL); for(i=1;i<=12;i++) { elem[i]=0; elnumbers[i]=0; if(maxele[i]>=0) { elem[i]=(med_int*)malloc(sizeof(med_int)*numnodes[i]*(maxele[i]+1)); exitif(elem[i]==NULL,"allocate: allocation failure: elements.",NULL); elnumbers[i]=(med_int*)malloc(sizeof(med_int)*(maxele[i]+1)); exitif(elnumbers==NULL,"allocation failure: element numbers.",NULL);} } } /*===========================================================================*/ void readnodes() { int i; /* start reading nodes. */ numnode=-1; for(;;) { sret=fgets(line, maxline, fid); exitif(sret==NULL, "readnodes: unexpected end-of-line while reading from", inname); ret=sscanf(line, "%5d", &key); exitif(ret==0, "readnodes: unexpected error 1 while reading from", inname); /* printf("readnodes: inname=%s, key=%d\n", inname, key); */ if(key==2) { ret=sscanf(line, "%5d %c", &key, &label); exitif(ret==0, "readnodes: unexpected error 2 while reading from", inname); printf("readnodes: reading block of node coordinates. \n"); exitif(label!='C', "readnodes: wrong data line label; label=\n", label); for(;;) { sret=fgets(line, maxline, fid); exitif(sret==NULL, "readnodes: unexpected end-of-line while reading from", inname); ret=sscanf(line, "%5d", &key); exitif(ret==0, "readnodes: unexpected error 1 while reading from", inname); /* printf("readnodes: node point record key=%d\n", key); */ if(key==-1) { numnode++; /* printf("readnodes: numnode=%d\n", numnode); */ exitif(numnode>maxnode, "readnodes: error, no memory left for nodes.", NULL); ret=sscanf(line, "%3d %d %lf %lf %lf", &key,&node,&x,&y,&z); exitif(ret==0, "readnodes: unexpected error 1 while reading from", inname); /* printf("readnodes: key=%d, node=%d, x=%g, y=%g, z=%g\n", key, node, x,y,z); */ nodenumbers[numnode]=node; coords[3*numnode+0]=x; coords[3*numnode+1]=y; coords[3*numnode+2]=z; /* printf("readnodes: key=%d, node=%d, x=%g, y=%g, z=%g\n", key, nodenumbers[numnode], coords[3*numnode+0],coords[3*numnode+1],coords[3*numnode+2]); */ } else if(key==-3) { break; } else { /* printf("readnodes: ignoring key=%d\n", key); */ } } } if(key==9999) { break; } } } /*===========================================================================*/ void readelements() { /* start reading elements. */ for(i=1;i<=15;i++) elnumber[i]=-1; numele=-1; for(;;) { sret=fgets(line, maxline, fid); exitif(sret==NULL, "readelements: unexpected end-of-line while reading from", inname); ret=sscanf(line, "%5d", &key); /* printf("readelements: key=%d, ret=%d\n", key,ret); */ exitif(ret==0, "readelements: unexpected error 1 while reading from", inname); if(key==3) { /* printf("readelements: reading next element. \n"); */ ret=sscanf(line, "%5d %c", &key, &label); exitif(ret==0, "readelements: unexpected error 2 while reading from", inname); printf("readelements: reading block of element connectivities. \n"); exitif(label!='C', "readelements: wrong data line label; label=\n", label); for(;;) { sret=fgets(line, maxline, fid); exitif(sret==NULL, "readelements: unexpected end-of-line while reading from", inname); ret=sscanf(line, "%5d", &key); exitif(ret==0, "readelements: unexpected error 3 while reading from", inname); /* printf("readelements: element record key=%d\n", key); */ if(key==-1) { if(elnumber[eltype]>=0&&nc>0) { for(i=1;i<=nelnode;i++) { k=seqabq[eltype][i]; /* printf("readelements: affe k=%d n=%d\n",k,n[k]); */ elem[eltype][numnodes[eltype]*(elnumber[eltype])+i-1] =findnode(nodenumbers,nodeindex,maxnode,n[k])+1; elnumbers[eltype][elnumber[eltype]]=element; } /* printf("readelements: nc=%d, nelnode=%d\n",nc, nelnode); printf("readelements: n= %d %d %d %d %d %d %d %d %d %d \ %d %d %d %d %d %d %d %d %d %d \n", n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10], n[11],n[12],n[13],n[14],n[15],n[16],n[17],n[18],n[19],n[20]); */ } ret=sscanf(line, "%3d %d %d %5d %s", &key,&element,&eltype,&dummy,material); exitif(ret==0, "readelements: unexpected error 4 while reading from", inname); exitif(eltype<1||eltype>12, "readelements: wrong eltype found.", NULL); /* printf("readelements: key=%d, element=%d, eltype=%d, material=%s\n", key,element,eltype,material); */ nc=0; nelnode=numnodes[eltype]; exitif(nelnode<1||nelnode>20, "readelements: wrong number of nodes at element.", NULL); numele++; elnumber[eltype]++; /* printf("readelements: numele=%d\n", numele); printf("readelements: elnumber[%d]=%d\n", eltype, elnumber[eltype]); */ exitif(elnumber[eltype]>maxele[eltype], "readelements: error, no memory left for elements.", NULL); } else if(key==-2) { ret=sscanf(line, "%5d %d %d %d %d %d %d %d %d %d %d \ %d %d %d %d %d %d %d %d %d %d", &key,&n[nc+1],&n[nc+2],&n[nc+3],&n[nc+4],&n[nc+5], &n[nc+6],&n[nc+7],&n[nc+8],&n[nc+9],&n[nc+10], &n[nc+11],&n[nc+12],&n[nc+13],&n[nc+14],&n[nc+15], &n[nc+16],&n[nc+17],&n[nc+18],&n[nc+19],&n[nc+20]); exitif(ret==0, "readelements: unexpected error 5 while reading from", inname); /* printf("ret=%d\n", ret); */ nc=nc+ret-1; } else if(key==-3) { if(elnumber[eltype]>=0&&nc>0) { for(i=1;i<=nelnode;i++) { k=seqabq[eltype][i]; elem[eltype][numnodes[eltype]*(elnumber[eltype])+i-1] =findnode(nodenumbers,nodeindex,maxnode,n[k])+1; elnumbers[eltype][elnumber[eltype]]=element; } } break; } else { /* printf("readelements: ignoring key=%d\n", key); */ } } } if(key==9999) { break; } } } /*===========================================================================*/ void transdat() { int i; /* read results data blocks. */ numnode=-1; nodedata=NULL; ncomps=0; for(;;) { sret=fgets(line, maxline, fid); exitif(sret==NULL, "transdat: unexpected end-of-line while reading from", inname); ret=sscanf(line, "%5d", &key); exitif(ret==0, "transdat: unexpected error 1 while reading from", inname); /* printf("transdat: inname=%s, key=%d\n",inname,key); */ if(key==100) { ret=sscanf(line, "%5d%c%6c%12lf%12c%20c%2d%5d%10s%2d", &key,&label,setname,&value,numnd,text,&ictype,&numstp,analys,&format); exitif(ret==0, "transdat: unexpected error 2 while reading from", inname); /* printf("transdat: reading block of node point results data. \n"); */ exitif(label!='C', "transdat: wrong data line label; label=\n", label); for(i=0;i<=5;i++) if(setname[i]==' ') setname[i]='_'; /* printf("transdat: key=%d,label=%c,setname=%s,value=%lf,numnd=%s\n", key,label,setname,value,numnd); printf("transdat: text=%s,ictype=%d,numstp=%d,analys=%s,format=%d\n", text,ictype,numstp,analys,format); */ for(;;) { sret=fgets(line, maxline, fid); exitif(sret==NULL, "transdat: unexpected end-of-line while reading from", inname); ret=sscanf(line, "%5d", &key); exitif(ret==0, "transdat: unexpected error 1 while reading from", inname); /* printf("transdat: node point data record key=%d\n", key); */ if(key==-4) { ret=sscanf(line, "%5d%10s%5d%5d",&key,name,&ncomps,&irtype); exitif(ret==0, "transdat: unexpected error 1 while reading from", inname); /* printf("transdat: key=%d,name=%s,ncomps=%d,irtype=%d \n", key,name,ncomps,irtype); */ exitif(ncomps>20, "transdat: too many sub-components in results data, file=", inname); exitif(ncomps<=0, "transdat: wrong number of sub-components, file=",inname); if(strncmp(name,"STRESS",6)==0) ncomps=7; if(strncmp(name,"DISP",4)==0) ncomps=4; /* printf("transdat: allocating new nodedata array.\n"); printf("transdat: ncomps=%d, maxnode=%d\n", ncomps, maxnode); */ nodedata=(med_float*)malloc(sizeof(med_float)*ncomps*(maxnode+1)); exitif(nodedata==NULL,"allocation failure: node point results data.",NULL); for(i=0;i<=maxnode;i++) nodedata[i]=0.0; for(i=0;i<21*MED_SNAME_SIZE;i++) component[i]=' '; nc=0; nc1=-1; } else if(key==-5) { nc++; ret=sscanf(line, "%5d%10s%5d%5d%5d%5d%5d%10s", &key,comp,&menue,&ictype,&icind1,&icind2,&iexist,icname); exitif(ret==0, "transdat: unexpected error 1 while reading from", inname); /* printf("transdat: nc=%d,key=%d,comp=%s,menue=%d,ictype=%d\n", nc,key,comp,menue,ictype); printf("transdat: icind1=%d,icind2=%d,iexist=%d,icname=%s\n", icind1,icind2,iexist,icname); */ strncpy(component+MED_SNAME_SIZE*(nc-1),comp,strlen(comp)); /* printf("transdat: component=%s\n",component+MED_SNAME_SIZE*(nc-1)); */ } else if(key==-1) { xx=0.0; yy=0.0; zz=0.0; xy=0.0; zx=0.0; yz=0.0; nc1++; exitif(nc1>maxnode,"error more data items that nodes\n", NULL); ret=sscanf(line,"%3d%10d%12lf%12lf%12lf%12lf%12lf%12lf", &key,&numnode,&xx,&yy,&zz,&xy,&yz,&zx); exitif(ret==0, "transdat: unexpected error 1 while reading from", inname); /* printf ("transdat: ret=%d,key=%d,numnode=%d,xx=%g,yy=%g,zz=%g,xy=%g,yz=%g,zx=%g\n", ret,key,numnode,xx,yy,zz,xy,yz,zx); */ if(isnan(xx)!=0)xx=0.0; if(isnan(yy)!=0)yy=0.0; if(isnan(zz)!=0)zz=0.0; if(isnan(xy)!=0)xy=0.0; if(isnan(zx)!=0)zx=0.0; if(isnan(yz)!=0)yz=0.0; exitif(nodedata==NULL,"transdat: data array not allocated.\ Wrong key sequence on .frd file?\n",NULL); k=findnode(nodenumbers,nodeindex,maxnode,numnode); if(ncomps>=1) nodedata[ncomps*k]=xx; if(ncomps>=2) nodedata[ncomps*k+1]=yy; if(ncomps>=3) nodedata[ncomps*k+2]=zz; if(ncomps>=4) nodedata[ncomps*k+3]=xy; if(ncomps>=5) nodedata[ncomps*k+4]=yz; if(ncomps>=6) nodedata[ncomps*k+5]=zx; /* printf("transdat: key=%d, ncomps=%d, nc=%d\n", key, ncomps,nc1); */ strcpy(component+MED_SNAME_SIZE*(ncomps)-1, "\n"); if(strncmp(name,"STRESS",6)==0) { strcpy(component+MED_SNAME_SIZE*6,"MISES\n"); temp=1.0/sqrt(2.0) *sqrt((xx-yy)*(xx-yy)+(yy-zz)*(yy-zz) +(zz-xx)*(zz-xx)+6.0*(yz*yz+zx*zx+xy*xy)); nodedata[ncomps*k+6]=temp; } if(strncmp(name,"DISP",4)==0) { strcpy(component+MED_SNAME_SIZE*3,"ALL\n"); temp=sqrt(xx*xx+yy*yy+zz*zz); nodedata[ncomps*k+3]=temp; } } else if(key==-3) { strcpy(nomcha,name); strcat(nomcha,setname); /* printf("transdat: creating field %s, ncomps=%d\n",nomcha,ncomps); */ /* printf("transdat: XXXcomponent=%s\n", component); */ ret=MEDfieldCr(mfid,nomcha,MED_FLOAT64,ncomps,component,componentunit, dtunit,maa); exitif(ret<0,"Erreur à la création du champ ",nomcha); printf("transdat: writing field %s, value=%lf, step=%d \n", nomcha,value,numstp); /* printf("transdat: ncomps=%d, nc1=%d\n", ncomps, nc1); */ /* for(i=0;i<=nc1;i++) printf("%g %g %g %g %g %g\n", nodedata[i*ncomps],nodedata[i*ncomps+1],nodedata[i*ncomps+2], nodedata[i*ncomps+3],nodedata[i*ncomps+4],nodedata[i*ncomps+5]); */ ret=MEDfieldValueWr(mfid,nomcha,(med_int)numstp,MED_NO_IT,(med_float)value, MED_NODE,MED_NONE,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,maxnode+1, (unsigned char*)nodedata); exitif(ret<0,"Erreur à l'ecriture du champ ",nomcha); /* printf("transdat: freeing nodedata array.\n"); */ free(nodedata); break; } else { /* printf("transdat: ignoring key=%d\n", key); */ } } } if(key==9999) { break; } } } /*===========================================================================*/ void writemesh() { int i,j,k; /* Creation du maillage de type MED_NON_STRUCURE */ if(MEDmeshCr(mfid,maa,spacedim,meshdim,MED_UNSTRUCTURED_MESH,description, dtunit,MED_SORT_DTIT,MED_CARTESIAN,axisname,axisunit)<0) { printf("writemesh: Erreur a la creation du maillage : "); exit(0); } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ printf("writemesh: writing node point data: \n"); /* for(j=0;j<=maxnode;j++) { printf("%d %d %g %g %g\n", j, unsorted[j], coords[3*j+0],coords[3*j+1],coords[3*j+2]); } */ if(MEDmeshNodeWr(mfid,maa,MED_NO_DT,MED_NO_IT,dt, MED_FULL_INTERLACE,maxnode+1,coords,MED_FALSE,nodename, MED_TRUE,unsorted,MED_FALSE,famnumber)<0) { printf("writemesh: Erreur a l'ecriture des coordonnees des noeuds"); exit(0); } for(i=1;i<=12;i++) { if(maxele[i]>=0) { /* ecriture des connectivites des elements */ printf("writemesh: writing elements of type %d, %s\n", i, nommai[i]); /* for(j=0;j<=maxele[i];j++) { printf("%d ", elnumbers[i][j]); for(k=1;k<=numnodes[i];k++) { printf("%d ", elem[i][numnodes[i]*j+k-1]); } printf("\n"); } */ if(MEDmeshElementWr(mfid,maa,MED_NO_DT,MED_NO_IT,dt, MED_CELL,typmai[i],MED_NODAL,MED_FULL_INTERLACE,maxele[i]+1,elem[i], MED_FALSE,elementname,MED_TRUE,elnumbers[i],MED_FALSE, famnumber)<0) { printf("writemesh: Impossible d'ecrire la connectivité des mailles type %s\n", nommai[i]); return; } } } /* Creation de la famille 0 */ ret=MEDfamilyCr(mfid,maa,"FAMILLE0",0,0,0); exitif(ret<0,"Erreur a la creation de la famille 0",NULL); } /*==============================================================================*/ void exitif(int expression,char* message, char* arg) { if(expression==0) return; if(message!=NULL) fprintf(stdout, "%s", message); if(arg!=NULL) fprintf(stdout, "%s", arg); fprintf(stdout, "\nexiting.\n"); exit(0); } /*==============================================================================*/ void nodesort(nodes,index,length) /* Taken from Brian Kernighan, Dennis Ritchie: "The C Programming Language". Second Edition, Prentice Hall, 1988. */ int *nodes; /* node point numbers. */ int *index; /* index to node point data. */ med_int length; /* length of arrays. */ { int gap, i,j, temp; for(gap=length/2; gap>0; gap/=2) { for(i=gap;i=0 && nodes[j]>nodes[j+gap]; j-=gap) { temp=nodes[j]; nodes[j]=nodes[j+gap]; nodes[j+gap]=temp; temp=index[j]; index[j]=index[j+gap]; index[j+gap]=temp; } } } } /*=============================================================================*/ int findnode(nodes,index,length,node) int *nodes; /* node point numbers. */ int *index; /* index to node point data. */ int node; /* node. */ med_int length; /* length of arrays. */ { int high, low, mid; int i; low=0; high=length+1; mid=length/2; for(i=1;i<=50;i++) { if(node<=nodes[mid]) high=mid; else low=mid+1; mid=(high+low)/2; if(high==low) { /* printf("findnode: low=%d, mid=%d, high=%d, node=%d, nodes=%d, index=%d\n", low,mid,high,node,nodes[high],index[high]); */ return(index[high]); } } printf("findnode: error: failed to find node. \n"); printf("findnode: length=%d, node=%d\n", length, node); exit(0); } /*=============================================================================*/