1 #include "DriverUNV_W_SMDS_Mesh.h"
2 #include "SMDS_MeshElement.hxx"
3 #include "SMDS_MeshNode.hxx"
7 #define sNODE_UNV_ID " 2411"
8 #define sELT_UNV_ID " 2412"
9 #define sUNV_SEPARATOR " -1"
10 #define sNODE_UNV_DESCR "%10d 1 1 11\n"
11 #define sELT_SURF_DESC "%10d %2d 1 1 11 %1d\n"
12 #define sELT_VOLU_DESC "%10d %2d 1 1 9 %1d\n"
13 #define sELT_BEAM_DESC1 "%10d %2d 1 1 7 %1d\n"
14 #define sELT_BEAM_DESC2 " 0 1 1\n"
20 * Factory function which will be called by SMESHDriver
22 void * SMESH_createUNVMeshWriter()
24 return new DriverUNV_W_SMDS_Mesh();
29 DriverUNV_W_SMDS_Mesh::DriverUNV_W_SMDS_Mesh()
34 DriverUNV_W_SMDS_Mesh::~DriverUNV_W_SMDS_Mesh()
39 void DriverUNV_W_SMDS_Mesh::SetMesh(SMDS_Mesh * aMesh)
44 void DriverUNV_W_SMDS_Mesh::SetFile(string aFile)
49 void DriverUNV_W_SMDS_Mesh::SetFileId(FILE * aFileId)
54 void DriverUNV_W_SMDS_Mesh::SetMeshId(int aMeshId)
59 void DriverUNV_W_SMDS_Mesh::Add()
64 void DriverUNV_W_SMDS_Mesh::Write()
70 char *file2Read = (char *)myFile.c_str();
71 myFileId = fopen(file2Read, "w+");
74 fprintf(stderr, ">> ERREUR : ouverture du fichier %s \n", file2Read);
78 /****************************************************************************
80 ****************************************************************************/
81 fprintf(stdout, "\n(****************************)\n");
82 fprintf(stdout, "(* INFORMATIONS GENERALES : *)\n");
83 fprintf(stdout, "(****************************)\n");
85 /* Combien de noeuds ? */
86 nbNodes = myMesh->NbNodes();
88 /* Combien de mailles, faces ou aretes ? */
89 int nb_of_nodes, nb_of_edges, nb_of_faces, nb_of_volumes;
90 nb_of_edges = myMesh->NbEdges();
91 nb_of_faces = myMesh->NbFaces();
92 nb_of_volumes = myMesh->NbVolumes();
93 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
96 SCRUTE(nb_of_volumes);
98 fprintf(stdout, "%d %d\n", nbNodes, nbCells);
100 /****************************************************************************
101 * ECRITURE DES NOEUDS *
102 ****************************************************************************/
103 fprintf(stdout, "\n(************************)\n");
104 fprintf(stdout, "(* NOEUDS DU MAILLAGE : *)\n");
105 fprintf(stdout, "(************************)\n");
107 fprintf(myFileId, "%s\n", sUNV_SEPARATOR);
108 fprintf(myFileId, "%s\n", sNODE_UNV_ID);
110 SMDS_Iterator<const SMDS_MeshNode *> * itNodes=myMesh->nodesIterator();
111 while(itNodes->more())
113 const SMDS_MeshNode * node = itNodes->next();
115 fprintf(myFileId, sNODE_UNV_DESCR, node->GetID());
116 fprintf(myFileId, "%25.16E%25.16E%25.16E\n", node->X(), node->Y(),
120 fprintf(myFileId, "%s\n", sUNV_SEPARATOR);
122 /****************************************************************************
123 * ECRITURE DES ELEMENTS *
124 ****************************************************************************/
125 fprintf(stdout, "\n(**************************)\n");
126 fprintf(stdout, "(* ELEMENTS DU MAILLAGE : *)\n");
127 fprintf(stdout, "(**************************)");
128 /* Ecriture des connectivites, noms, numeros des mailles */
130 fprintf(myFileId, "%s\n", sUNV_SEPARATOR);
131 fprintf(myFileId, "%s\n", sELT_UNV_ID);
133 SMDS_Iterator<const SMDS_MeshEdge *> * itEdges=myMesh->edgesIterator();
134 while(itEdges->more())
136 const SMDS_MeshElement * elem = itEdges->next();
137 SMDS_Iterator<const SMDS_MeshElement*> *itn=elem->nodesIterator();
139 switch (elem->NbNodes())
142 fprintf(myFileId, sELT_BEAM_DESC1, elem->GetID(), 21,
144 fprintf(myFileId, sELT_BEAM_DESC2);
145 fprintf(myFileId, "%10d%10d\n", itn->next()->GetID(),
146 itn->next()->GetID());
150 fprintf(myFileId, sELT_BEAM_DESC1, elem->GetID(), 24,
152 fprintf(myFileId, sELT_BEAM_DESC2);
153 fprintf(myFileId, "%10d%10d%10d\n", itn->next()->GetID(),
154 itn->next()->GetID(), itn->next()->GetID());
162 SMDS_Iterator<const SMDS_MeshFace*> * itFaces=myMesh->facesIterator();
163 while(itFaces->more())
165 const SMDS_MeshElement * elem = itFaces->next();
167 switch (elem->NbNodes())
171 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 74,
175 // linear quadrilateral
176 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 71,
180 // parabolic triangle
181 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 72,
185 // parabolic quadrilateral
186 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 75,
190 fprintf(myFileId, "element not registered\n");
193 SMDS_Iterator<const SMDS_MeshElement*> *itn=elem->nodesIterator();
194 while(itn->more()) fprintf(myFileId, "%10d", itn->next()->GetID());
197 fprintf(myFileId, "\n");
201 SMDS_Iterator<const SMDS_MeshVolume*> * itVolumes=myMesh->volumesIterator();
202 while(itVolumes->more())
204 const SMDS_MeshElement * elem = itVolumes->next();
206 switch (elem->NbNodes())
209 // linear tetrahedron
210 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 111,
214 // linear tetrahedron
215 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 112,
220 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 115,
225 SMDS_Iterator<const SMDS_MeshElement*> *itn=elem->nodesIterator();
226 while(itn->more()) fprintf(myFileId, "%10d", itn->next()->GetID());
229 fprintf(myFileId, "\n");
233 fprintf(myFileId, "%s\n", sUNV_SEPARATOR);