2 #include "DriverUNV_W_SMESHDS_Mesh.h"
3 #include "DriverUNV_W_SMDS_Mesh.h"
5 #include "SMDS_MeshElement.hxx"
6 #include "SMDS_MeshNode.hxx"
7 #include "SMDS_MeshEdgesIterator.hxx"
8 #include "SMDS_MeshFacesIterator.hxx"
9 #include "SMDS_MeshNodesIterator.hxx"
10 #include "SMDS_MeshVolumesIterator.hxx"
12 #include "utilities.h"
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"
23 DriverUNV_W_SMESHDS_Mesh::DriverUNV_W_SMESHDS_Mesh() {
27 DriverUNV_W_SMESHDS_Mesh::~DriverUNV_W_SMESHDS_Mesh() {
31 void DriverUNV_W_SMESHDS_Mesh::SetMesh(Handle(SMDS_Mesh)& aMesh) {
32 //myMesh = Handle(SMESHDS_Mesh)::DownCast(aMesh);
36 void DriverUNV_W_SMESHDS_Mesh::SetFile(string aFile) {
40 void DriverUNV_W_SMESHDS_Mesh::SetFileId(FILE* aFileId) {
44 void DriverUNV_W_SMESHDS_Mesh::SetMeshId(int aMeshId) {
48 void DriverUNV_W_SMESHDS_Mesh::Write() {
50 string myClass = string("SMDS_Mesh");
51 string myExtension = string("UNV");
53 DriverUNV_W_SMDS_Mesh* myWriter = new DriverUNV_W_SMDS_Mesh;
55 myWriter->SetMesh(myMesh);
56 myWriter->SetFile(myFile);
57 myWriter->SetMeshId(myMeshId);
58 //myWriter->SetFileId(myFileId);
64 void DriverUNV_W_SMESHDS_Mesh::Add() {
68 char* file2Read = (char*)myFile.c_str();
69 myFileId = fopen(file2Read,"w+");
72 fprintf(stderr,">> ERREUR : ouverture du fichier %s \n",file2Read);
76 /****************************************************************************
78 ****************************************************************************/
79 fprintf(stdout,"\n(****************************)\n");
80 fprintf(stdout,"(* INFORMATIONS GENERALES : *)\n");
81 fprintf(stdout,"(****************************)\n");
83 /* Combien de noeuds ? */
84 nbNodes = myMesh->NbNodes();
86 /* Combien de mailles, faces ou aretes ? */
87 Standard_Integer nb_of_nodes, nb_of_edges,nb_of_faces, nb_of_volumes;
88 nb_of_edges = myMesh->NbEdges();
89 nb_of_faces = myMesh->NbFaces();
90 nb_of_volumes = myMesh->NbVolumes();
91 nbCells = nb_of_edges + nb_of_faces + nb_of_volumes;
93 fprintf(stdout,"%d %d\n",nbNodes,nbCells);
94 //fprintf(myFileId,"%d %d\n",nbNodes,nbCells);
96 /****************************************************************************
97 * ECRITURE DES NOEUDS *
98 ****************************************************************************/
99 fprintf(stdout,"\n(************************)\n");
100 fprintf(stdout,"(* NOEUDS DU MAILLAGE : *)\n");
101 fprintf(stdout,"(************************)\n");
103 SMDS_MeshNodesIterator itNodes(myMesh);
105 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);
106 fprintf(myFileId,"%s\n", sNODE_UNV_ID );
108 for (;itNodes.More();itNodes.Next()) {
109 const Handle(SMDS_MeshElement)& elem = itNodes.Value();
110 const Handle(SMDS_MeshNode )& node = myMesh->GetNode(1, elem);
112 fprintf(myFileId, sNODE_UNV_DESCR, node->GetID());
113 fprintf(myFileId, "%25.16E%25.16E%25.16E\n", node->X(), node->Y(), node->Z());
115 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);
117 /****************************************************************************
118 * ECRITURE DES ELEMENTS *
119 ****************************************************************************/
120 fprintf(stdout,"\n(**************************)\n");
121 fprintf(stdout,"(* ELEMENTS DU MAILLAGE : *)\n");
122 fprintf(stdout,"(**************************)");
123 /* Ecriture des connectivites, noms, numeros des mailles */
125 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);
126 fprintf(myFileId,"%s\n", sELT_UNV_ID );
128 SMDS_MeshEdgesIterator itEdges(myMesh);
129 for (;itEdges.More();itEdges.Next()) {
130 const Handle(SMDS_MeshElement)& elem = itEdges.Value();
132 switch (elem->NbNodes()) {
134 fprintf(myFileId, sELT_BEAM_DESC1, elem->GetID(), 21, elem->NbNodes());
135 fprintf(myFileId, sELT_BEAM_DESC2);
136 fprintf(myFileId, "%10d%10d\n", elem->GetConnection(1), elem->GetConnection(2));
140 fprintf(myFileId, sELT_BEAM_DESC1, elem->GetID(), 24, elem->NbNodes());
141 fprintf(myFileId, sELT_BEAM_DESC2);
142 fprintf(myFileId, "%10d%10d%10d\n",elem->GetConnection(1), elem->GetConnection(2), elem->GetConnection(3));
148 SMDS_MeshFacesIterator itFaces(myMesh);
149 for (;itFaces.More();itFaces.Next()) {
150 const Handle(SMDS_MeshElement)& elem = itFaces.Value();
152 switch (elem->NbNodes()) {
155 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 74, elem->NbNodes());
158 // linear quadrilateral
159 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 71, elem->NbNodes());
162 // parabolic triangle
163 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 72, elem->NbNodes());
166 // parabolic quadrilateral
167 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 75, elem->NbNodes());
170 fprintf(myFileId, "element not registered\n");
173 for (i=0;i<elem->NbNodes();i++)
174 fprintf(myFileId,"%10d",elem->GetConnection(i+1));
176 fprintf(myFileId,"\n");
179 SMDS_MeshVolumesIterator itVolumes(myMesh);
180 for (;itVolumes.More();itVolumes.Next()) {
181 const Handle(SMDS_MeshElement)& elem = itVolumes.Value();
183 switch (elem->NbNodes()) {
185 // linear tetrahedron
186 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 111, elem->NbNodes());
189 // linear tetrahedron
190 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 112, elem->NbNodes());
194 fprintf(myFileId, sELT_SURF_DESC, elem->GetID(), 115, elem->NbNodes());
198 for (i=0;i<elem->NbNodes();i++)
199 fprintf(myFileId,"%10d",elem->GetConnection(i+1));
201 fprintf(myFileId,"\n");
203 fprintf(myFileId,"%s\n", sUNV_SEPARATOR);