Salome HOME
Freshly added file
[modules/smesh.git] / src / DriverUNV / DriverUNV_W_SMESHDS_Mesh.cxx
1 using namespace std;
2 #include "DriverUNV_W_SMESHDS_Mesh.h"
3 #include "DriverUNV_W_SMDS_Mesh.h"
4
5 #include "SMDS_MeshElement.hxx"
6 #include "SMDS_MeshNode.hxx"
7
8
9
10
11
12 #include "utilities.h"
13
14 #define sNODE_UNV_ID "  2411"
15 #define sELT_UNV_ID  "  2412"
16 #define sUNV_SEPARATOR "    -1"
17 #define sNODE_UNV_DESCR "%10d         1         1        11\n"
18 #define sELT_SURF_DESC  "%10d        %2d         1         1        11         %1d\n"
19 #define sELT_VOLU_DESC  "%10d        %2d         1         1         9         %1d\n"
20 #define sELT_BEAM_DESC1 "%10d        %2d         1         1         7         %1d\n"
21 #define sELT_BEAM_DESC2 "         0         1         1\n"
22
23 DriverUNV_W_SMESHDS_Mesh::DriverUNV_W_SMESHDS_Mesh()
24 {
25         ;
26 }
27
28 DriverUNV_W_SMESHDS_Mesh::~DriverUNV_W_SMESHDS_Mesh()
29 {
30         ;
31 }
32
33 void DriverUNV_W_SMESHDS_Mesh::SetMesh(SMDS_Mesh * aMesh)
34 {
35         //myMesh = SMESHDS_Mesh *::DownCast(aMesh);
36         myMesh = aMesh;
37 }
38
39 void DriverUNV_W_SMESHDS_Mesh::SetFile(string aFile)
40 {
41         myFile = aFile;
42 }
43
44 void DriverUNV_W_SMESHDS_Mesh::SetFileId(FILE * aFileId)
45 {
46         myFileId = aFileId;
47 }
48
49 void DriverUNV_W_SMESHDS_Mesh::SetMeshId(int aMeshId)
50 {
51         myMeshId = aMeshId;
52 }
53
54 void DriverUNV_W_SMESHDS_Mesh::Write()
55 {
56
57         string myClass = string("SMDS_Mesh");
58         string myExtension = string("UNV");
59
60         DriverUNV_W_SMDS_Mesh *myWriter = new DriverUNV_W_SMDS_Mesh;
61
62         myWriter->SetMesh(myMesh);
63         myWriter->SetFile(myFile);
64         myWriter->SetMeshId(myMeshId);
65         //myWriter->SetFileId(myFileId);
66
67         myWriter->Write();
68
69 }
70
71 void DriverUNV_W_SMESHDS_Mesh::Add()
72 {
73         int nbNodes, nbCells;
74         int i;
75
76         char *file2Read = (char *)myFile.c_str();
77         myFileId = fopen(file2Read, "w+");
78         if (myFileId < 0)
79         {
80                 fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
81                 exit(EXIT_FAILURE);
82         }
83
84   /****************************************************************************
85   *                       NOMBRES D'OBJETS                                    *
86   ****************************************************************************/
87         fprintf(stdout, "\n(****************************)\n");
88         fprintf(stdout, "(* INFORMATIONS GENERALES : *)\n");
89         fprintf(stdout, "(****************************)\n");
90
91         /* Combien de noeuds ? */
92         nbNodes = myMesh->NbNodes();
93
94         /* Combien de mailles, faces ou aretes ? */
95         int nb_of_nodes, nb_of_edges, nb_of_faces, nb_of_volumes;
96         nb_of_edges = myMesh->NbEdges();
97         nb_of_faces = myMesh->NbFaces();
98         nb_of_volumes = myMesh->NbVolumes();
99         nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
100
101         fprintf(stdout, "%d %d\n", nbNodes, nbCells);
102 //fprintf(myFileId,"%d %d\n",nbNodes,nbCells);
103
104   /****************************************************************************
105   *                       ECRITURE DES NOEUDS                                 *
106   ****************************************************************************/
107         fprintf(stdout, "\n(************************)\n");
108         fprintf(stdout, "(* NOEUDS DU MAILLAGE : *)\n");
109         fprintf(stdout, "(************************)\n");
110
111
112         fprintf(myFileId, "%s\n", sUNV_SEPARATOR);
113         fprintf(myFileId, "%s\n", sNODE_UNV_ID);
114
115         SMDS_Iterator<const SMDS_MeshNode *> * itNodes=myMesh->nodesIterator();
116         while(itNodes->more())
117         {
118                 const SMDS_MeshNode * node = itNodes->next(); 
119
120                 fprintf(myFileId, sNODE_UNV_DESCR, node->GetID());
121                 fprintf(myFileId, "%25.16E%25.16E%25.16E\n", node->X(), node->Y(),
122                         node->Z());
123         }
124         delete itNodes;
125         fprintf(myFileId, "%s\n", sUNV_SEPARATOR);
126
127   /****************************************************************************
128   *                       ECRITURE DES ELEMENTS                                *
129   ****************************************************************************/
130         fprintf(stdout, "\n(**************************)\n");
131         fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
132         fprintf(stdout, "(**************************)");
133         /* Ecriture des connectivites, noms, numeros des mailles */
134
135         fprintf(myFileId, "%s\n", sUNV_SEPARATOR);
136         fprintf(myFileId, "%s\n", sELT_UNV_ID);
137
138         SMDS_Iterator<const SMDS_MeshEdge *> * itEdges=myMesh->edgesIterator();
139         while(itEdges->more())
140         {
141                 const SMDS_MeshEdge * elem = itEdges->next();
142                 SMDS_Iterator<const SMDS_MeshElement*> *itn=elem->nodesIterator();
143
144                 switch (elem->NbNodes())
145                 {
146                 case 2:
147                         fprintf(myFileId, sELT_BEAM_DESC1, elem->GetID(), 21,
148                                 elem->NbNodes());
149                         fprintf(myFileId, sELT_BEAM_DESC2);
150                         fprintf(myFileId, "%10d%10d\n", itn->next()->GetID(),
151                                 itn->next()->GetID());
152                         break;
153
154                 case 3:
155                         fprintf(myFileId, sELT_BEAM_DESC1, elem->GetID(), 24,
156                                 elem->NbNodes());
157                         fprintf(myFileId, sELT_BEAM_DESC2);
158                         fprintf(myFileId, "%10d%10d%10d\n", itn->next()->GetID(),
159                                 itn->next()->GetID(), itn->next()->GetID());
160                         break;
161                 }
162                 delete itn;
163         }
164         delete itEdges;
165
166         SMDS_Iterator<const SMDS_MeshFace*> * itFaces=myMesh->facesIterator();
167         while(itFaces->more())
168         {
169                 const SMDS_MeshElement * elem = itFaces->next();
170
171                 switch (elem->NbNodes())
172                 {
173                 case 3:
174                         // linear triangle
175                         fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 74,
176                                 elem->NbNodes());
177                         break;
178                 case 4:
179                         // linear quadrilateral
180                         fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 71,
181                                 elem->NbNodes());
182                         break;
183                 case 6:
184                         // parabolic triangle
185                         fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 72,
186                                 elem->NbNodes());
187                         break;
188                 case 8:
189                         // parabolic quadrilateral
190                         fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 75,
191                                 elem->NbNodes());
192                         break;
193                 default:
194                         fprintf(myFileId, "element not registered\n");
195                 }
196
197                 SMDS_Iterator<const SMDS_MeshElement*> *itn=elem->nodesIterator();
198                 while(itn->more()) fprintf(myFileId, "%10d", itn->next()->GetID());
199                 delete itn;
200
201                 fprintf(myFileId, "\n");
202         }
203         delete itFaces;
204
205         SMDS_Iterator<const SMDS_MeshVolume*> * itVolumes=myMesh->volumesIterator();
206         while(itVolumes->more())
207         {
208                 const SMDS_MeshElement * elem = itVolumes->next();
209
210                 switch (elem->NbNodes())
211                 {
212                 case 4:
213                         // linear tetrahedron
214                         fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 111,
215                                 elem->NbNodes());
216                         break;
217                 case 6:
218                         // linear tetrahedron
219                         fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 112,
220                                 elem->NbNodes());
221                         break;
222                 case 8:
223                         // linear brick
224                         fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 115,
225                                 elem->NbNodes());
226                         break;
227                 }
228
229                 SMDS_Iterator<const SMDS_MeshElement*> *itn=elem->nodesIterator();
230                 while(itn->more()) fprintf(myFileId, "%10d", itn->next()->GetID());
231                 delete itn;
232
233                 fprintf(myFileId, "\n");
234         }
235         delete itVolumes;
236         fprintf(myFileId, "%s\n", sUNV_SEPARATOR);
237
238         fclose(myFileId);
239 }