The Higher Education and Research forge

Home My Page Projects Code Snippets Project Openings MMD
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

1 /*---------------------------------------------------------------------------*\
2     \o/\o/\o/
3     MMD
4     Version : 0.0.3
5     Web : https://github.com/alainbastide/MMD
6 -------------------------------------------------------------------------------
7 License
9     MMD is free software: you can redistribute it and/or modify it
10     under the terms of the GNU General Public License as published by the
11     Free Software Foundation, either version 3 of the License, or (at your
12     option) any later version.
14     MMD is distributed in the hope that it will be useful, but
15     WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17     General Public License for more details.
19     You should have received a copy of the GNU General Public License
20     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
22 Application
23     explain
25 Description
26     explain
28 Author
29     Alain Bastide, Université de La Réunion, FRANCE.  All rights reserved
31 \*---------------------------------------------------------------------------*/
33 #include "mmd.h"
34 #include "savedata.h"
37 void writeVTK(struct primalMesh * myPrimalMesh, struct readWriteVTK * myReadWriteVTK)
38 ////////////////////////////////////////////////////////////////////////////////////////////////////////
39 // Ecriture dans un fichier VTK du PRIMAL
40 ////////////////////////////////////////////////////////////////////////////////////////////////////////
41 {
42   
43   clock_t t=startFunction(__FUNCTION__);
44   
45   myReadWriteVTK->dataName = "Ma Simulation TEST";
46   
47   myReadWriteVTK->handle = fopen("test.vtk", "wt");
48   
49   fprintf(myReadWriteVTK->handle, "# vtk DataFile Version 2.0\n");
50   fprintf(myReadWriteVTK->handle, "%s\n\n", myReadWriteVTK->dataName);
51   
52   fprintf(myReadWriteVTK->handle, "ASCII\n");
53   
54   fprintf(myReadWriteVTK->handle, "DATASET UNSTRUCTURED_GRID\n");
55   
56   fprintf(myReadWriteVTK->handle, "POINTS %ld FLOAT\n",myPrimalMesh->vertexNumber);
57   
58   for (connectivity_int i=0;i<myPrimalMesh->vertexNumber;i++)
59     {
60       fprintf(myReadWriteVTK->handle,"%f %f %f\n"
61               ,myPrimalMesh->vertex[i][0]
62           ,myPrimalMesh->vertex[i][1]
63           ,myPrimalMesh->vertex[i][2]
64           );
65     }
66   
67   fprintf(myReadWriteVTK->handle, "\n");
68   
69   connectivity_int count = 0;
70   for (connectivity_int i=0;i<myPrimalMesh->cellNumber;i++)
71     count +=(myPrimalMesh->cellToVertexNumber[i]+1); // +1 = column of line count
72   
73   fprintf(myReadWriteVTK->handle, "CELLS %ld %ld\n",myPrimalMesh->cellNumber, count);
74   
75   for (connectivity_int i=0;i<myPrimalMesh->cellNumber;i++)
76     {
77       
78       fprintf(myReadWriteVTK->handle,"%d ",myPrimalMesh->cellToVertexNumber[i]);
79       for (connectivity_int j=0;j<myPrimalMesh->cellToVertexNumber[i];j++)
80         fprintf(myReadWriteVTK->handle,"%ld ",myPrimalMesh->cellToVertex[i][j]);
81       fprintf(myReadWriteVTK->handle,"\n");
82       
83     }
84   
85   fprintf(myReadWriteVTK->handle, "CELL_TYPES %ld\n",myPrimalMesh->cellNumber);
86   for (connectivity_int i=0;i<myPrimalMesh->cellNumber;i++)
87     {
88       
89       if(myPrimalMesh->cellToVertexNumber[i]==HEXAHEDRON)
90         fprintf(myReadWriteVTK->handle,"%d\n",VTK_HEXAHEDRON);
91       else
92         fprintf(myReadWriteVTK->handle,"???\n");
93       
94       
95     }
96   
97   fclose(myReadWriteVTK->handle);
98   
99   endFunction(__FUNCTION__, t);
100