/[escript]/branches/trilinos_from_5897/dudley/src/Mesh_write.cpp
ViewVC logotype

Diff of /branches/trilinos_from_5897/dudley/src/Mesh_write.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6008 by caltinay, Mon Feb 22 06:59:27 2016 UTC revision 6009 by caltinay, Wed Mar 2 04:13:26 2016 UTC
# Line 14  Line 14 
14  *  *
15  *****************************************************************************/  *****************************************************************************/
16    
 /************************************************************************************/  
   
 /*   Dudley: write Mesh */  
   
 /************************************************************************************/  
   
 #define ESNEEDPYTHON  
 #include "esysUtils/first.h"  
   
17  #include "Mesh.h"  #include "Mesh.h"
18    
19  /************************************************************************************/  namespace dudley {
   
 /*  writes the mesh to the external file fname using the Dudley file format: */  
20    
21    /// writes the mesh to the external file fname using the Dudley file format
22  void Dudley_Mesh_write(Dudley_Mesh* in, char* fname)  void Dudley_Mesh_write(Dudley_Mesh* in, char* fname)
23  {  {
24      char error_msg[1024];      char error_msg[1024];
# Line 37  void Dudley_Mesh_write(Dudley_Mesh* in, Line 27  void Dudley_Mesh_write(Dudley_Mesh* in,
27      Dudley_TagMap *tag_map = in->TagMap;      Dudley_TagMap *tag_map = in->TagMap;
28    
29      if (in->MPIInfo->size > 1)      if (in->MPIInfo->size > 1)
30      {          throw DudleyException("Mesh_write: only single processor runs are supported.");
         Dudley_setError(IO_ERROR, "Mesh_write: only single processor runs are supported.");  
         return;  
31    
     }  
32      /* open file */      /* open file */
33      f = fopen(fname, "w");      f = fopen(fname, "w");
34      if (f == NULL)      if (f == NULL)
35      {      {
36          sprintf(error_msg, "Mesh_write: Opening file %s for writing failed.", fname);          sprintf(error_msg, "Mesh_write: Opening file %s for writing failed.", fname);
37          Dudley_setError(IO_ERROR, error_msg);          throw DudleyException(error_msg);
         return;  
38      }      }
39    
40      /* write header */      /* write header */
# Line 56  void Dudley_Mesh_write(Dudley_Mesh* in, Line 42  void Dudley_Mesh_write(Dudley_Mesh* in,
42      fprintf(f, "%s\n", in->Name);      fprintf(f, "%s\n", in->Name);
43    
44      /*  write nodes: */      /*  write nodes: */
45        if (in->Nodes != NULL) {
     if (in->Nodes != NULL)  
     {  
46          numDim = Dudley_Mesh_getDim(in);          numDim = Dudley_Mesh_getDim(in);
47          fprintf(f, "%1dD-Nodes %d\n", numDim, in->Nodes->numNodes);          fprintf(f, "%1dD-Nodes %d\n", numDim, in->Nodes->numNodes);
48          for (i = 0; i < in->Nodes->numNodes; i++)          for (i = 0; i < in->Nodes->numNodes; i++)
# Line 68  void Dudley_Mesh_write(Dudley_Mesh* in, Line 52  void Dudley_Mesh_write(Dudley_Mesh* in,
52                  fprintf(f, " %20.15e", in->Nodes->Coordinates[INDEX2(j, i, numDim)]);                  fprintf(f, " %20.15e", in->Nodes->Coordinates[INDEX2(j, i, numDim)]);
53              fprintf(f, "\n");              fprintf(f, "\n");
54          }          }
55      }      } else {
     else  
     {  
56          fprintf(f, "0D-Nodes 0\n");          fprintf(f, "0D-Nodes 0\n");
57      }      }
58    
59      /*  write elements: */      /*  write elements: */
60        if (in->Elements != NULL) {
     if (in->Elements != NULL)  
     {  
61          fprintf(f, "%s %d\n", in->Elements->ename /*referenceElementSet->referenceElement->Type->Name */ ,          fprintf(f, "%s %d\n", in->Elements->ename /*referenceElementSet->referenceElement->Type->Name */ ,
62                  in->Elements->numElements);                  in->Elements->numElements);
63          NN = in->Elements->numNodes;          NN = in->Elements->numNodes;
64          for (i = 0; i < in->Elements->numElements; i++)          for (i = 0; i < in->Elements->numElements; i++) {
         {  
65              fprintf(f, "%d %d", in->Elements->Id[i], in->Elements->Tag[i]);              fprintf(f, "%d %d", in->Elements->Id[i], in->Elements->Tag[i]);
66              for (j = 0; j < NN; j++)              for (j = 0; j < NN; j++)
67                  fprintf(f, " %d", in->Nodes->Id[in->Elements->Nodes[INDEX2(j, i, NN)]]);                  fprintf(f, " %d", in->Nodes->Id[in->Elements->Nodes[INDEX2(j, i, NN)]]);
68              fprintf(f, "\n");              fprintf(f, "\n");
69          }          }
70      }      } else {
     else  
     {  
71          fprintf(f, "Tet4 0\n");          fprintf(f, "Tet4 0\n");
72      }      }
73    
74      /*  write face elements: */      /*  write face elements: */
75      if (in->FaceElements != NULL)      if (in->FaceElements != NULL) {
     {  
76          fprintf(f, "%s %d\n", in->FaceElements->ename /*referenceElementSet->referenceElement->Type->Name */ ,          fprintf(f, "%s %d\n", in->FaceElements->ename /*referenceElementSet->referenceElement->Type->Name */ ,
77                  in->FaceElements->numElements);                  in->FaceElements->numElements);
78          NN = in->FaceElements->numNodes;          NN = in->FaceElements->numNodes;
79          for (i = 0; i < in->FaceElements->numElements; i++)          for (i = 0; i < in->FaceElements->numElements; i++) {
         {  
80              fprintf(f, "%d %d", in->FaceElements->Id[i], in->FaceElements->Tag[i]);              fprintf(f, "%d %d", in->FaceElements->Id[i], in->FaceElements->Tag[i]);
81              for (j = 0; j < NN; j++)              for (j = 0; j < NN; j++)
82                  fprintf(f, " %d", in->Nodes->Id[in->FaceElements->Nodes[INDEX2(j, i, NN)]]);                  fprintf(f, " %d", in->Nodes->Id[in->FaceElements->Nodes[INDEX2(j, i, NN)]]);
83              fprintf(f, "\n");              fprintf(f, "\n");
84          }          }
85      }      } else {
     else  
     {  
86          fprintf(f, "Tri3 0\n");          fprintf(f, "Tri3 0\n");
87      }      }
88    
89      /*  write points: */      /*  write points: */
90      if (in->Points != NULL)      if (in->Points != NULL) {
     {  
91          fprintf(f, "%s %d\n", in->Points->ename /*referenceElementSet->referenceElement->Type->Name */ ,          fprintf(f, "%s %d\n", in->Points->ename /*referenceElementSet->referenceElement->Type->Name */ ,
92                  in->Points->numElements);                  in->Points->numElements);
93          for (i = 0; i < in->Points->numElements; i++)          for (i = 0; i < in->Points->numElements; i++) {
         {  
94              fprintf(f, "%d %d %d\n", in->Points->Id[i], in->Points->Tag[i],              fprintf(f, "%d %d %d\n", in->Points->Id[i], in->Points->Tag[i],
95                      in->Nodes->Id[in->Points->Nodes[INDEX2(0, i, 1)]]);                      in->Nodes->Id[in->Points->Nodes[INDEX2(0, i, 1)]]);
96          }          }
97      }      } else {
     else  
     {  
98          fprintf(f, "Point1 0\n");          fprintf(f, "Point1 0\n");
99      }      }
100    
101      /*  write tags: */      /*  write tags: */
102      if (tag_map)      if (tag_map) {
     {  
103          fprintf(f, "Tags\n");          fprintf(f, "Tags\n");
104          while (tag_map)          while (tag_map) {
         {  
105              fprintf(f, "%s %d\n", tag_map->name, tag_map->tag_key);              fprintf(f, "%s %d\n", tag_map->name, tag_map->tag_key);
106              tag_map = tag_map->next;              tag_map = tag_map->next;
107          }          }
# Line 158  void Dudley_PrintMesh_Info(Dudley_Mesh * Line 125  void Dudley_PrintMesh_Info(Dudley_Mesh *
125      fprintf(stdout, "\tReduced Integration order %d\n", in->reducedIntegrationOrder);      fprintf(stdout, "\tReduced Integration order %d\n", in->reducedIntegrationOrder);
126    
127      /* write nodes: */      /* write nodes: */
128      if (in->Nodes != NULL)      if (in->Nodes != NULL) {
     {  
129          numDim = Dudley_Mesh_getDim(in);          numDim = Dudley_Mesh_getDim(in);
130          fprintf(stdout, "\tNodes: %1dD-Nodes %d\n", numDim, in->Nodes->numNodes);          fprintf(stdout, "\tNodes: %1dD-Nodes %d\n", numDim, in->Nodes->numNodes);
131          if (full)          if (full) {
         {  
132              fprintf(stdout, "\t     Id   Tag  gDOF   gNI grDfI  grNI:  Coordinates\n");              fprintf(stdout, "\t     Id   Tag  gDOF   gNI grDfI  grNI:  Coordinates\n");
133              for (i = 0; i < in->Nodes->numNodes; i++)              for (i = 0; i < in->Nodes->numNodes; i++) {
             {  
134                  fprintf(stdout, "\t  %5d %5d %5d %5d %5d %5d: ", in->Nodes->Id[i], in->Nodes->Tag[i],                  fprintf(stdout, "\t  %5d %5d %5d %5d %5d %5d: ", in->Nodes->Id[i], in->Nodes->Tag[i],
135                          in->Nodes->globalDegreesOfFreedom[i], in->Nodes->globalNodesIndex[i],                          in->Nodes->globalDegreesOfFreedom[i], in->Nodes->globalNodesIndex[i],
136                          in->Nodes->globalReducedDOFIndex[i], in->Nodes->globalReducedNodesIndex[i]);                          in->Nodes->globalReducedDOFIndex[i], in->Nodes->globalReducedNodesIndex[i]);
# Line 175  void Dudley_PrintMesh_Info(Dudley_Mesh * Line 139  void Dudley_PrintMesh_Info(Dudley_Mesh *
139                  fprintf(stdout, "\n");                  fprintf(stdout, "\n");
140              }              }
141          }          }
142      }      } else {
     else  
     {  
143          fprintf(stdout, "\tNodes: 0D-Nodes 0\n");          fprintf(stdout, "\tNodes: 0D-Nodes 0\n");
144      }      }
145    
146      /* write elements: */      /* write elements: */
147      if (in->Elements != NULL)      if (in->Elements != NULL) {
     {  
148          int mine = 0, overlap = 0;          int mine = 0, overlap = 0;
149          for (i = 0; i < in->Elements->numElements; i++)          for (i = 0; i < in->Elements->numElements; i++) {
         {  
150              if (in->Elements->Owner[i] == in->MPIInfo->rank)              if (in->Elements->Owner[i] == in->MPIInfo->rank)
151                  mine++;                  mine++;
152              else              else
# Line 196  void Dudley_PrintMesh_Info(Dudley_Mesh * Line 156  void Dudley_PrintMesh_Info(Dudley_Mesh *
156                  in->Elements->ename /*referenceElementSet->referenceElement->Type->Name */ , in->Elements->numElements,                  in->Elements->ename /*referenceElementSet->referenceElement->Type->Name */ , in->Elements->numElements,
157                  in->Elements->etype /*referenceElementSet->referenceElement->Type->TypeId */ , mine, overlap);                  in->Elements->etype /*referenceElementSet->referenceElement->Type->TypeId */ , mine, overlap);
158          NN = in->Elements->numNodes;          NN = in->Elements->numNodes;
159          if (full)          if (full) {
         {  
160              fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");              fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");
161              for (i = 0; i < in->Elements->numElements; i++)              for (i = 0; i < in->Elements->numElements; i++) {
             {  
162                  fprintf(stdout, "\t  %5d %5d %5d %5d: ", in->Elements->Id[i], in->Elements->Tag[i],                  fprintf(stdout, "\t  %5d %5d %5d %5d: ", in->Elements->Id[i], in->Elements->Tag[i],
163                          in->Elements->Owner[i], in->Elements->Color[i]);                          in->Elements->Owner[i], in->Elements->Color[i]);
164                  for (j = 0; j < NN; j++)                  for (j = 0; j < NN; j++)
# Line 208  void Dudley_PrintMesh_Info(Dudley_Mesh * Line 166  void Dudley_PrintMesh_Info(Dudley_Mesh *
166                  fprintf(stdout, "\n");                  fprintf(stdout, "\n");
167              }              }
168          }          }
169      }      } else {
     else  
     {  
170          fprintf(stdout, "\tElements: Tet4 0\n");          fprintf(stdout, "\tElements: Tet4 0\n");
171      }      }
172    
173      /* write face elements: */      /* write face elements: */
174      if (in->FaceElements != NULL)      if (in->FaceElements != NULL) {
     {  
175          int mine = 0, overlap = 0;          int mine = 0, overlap = 0;
176          for (i = 0; i < in->FaceElements->numElements; i++)          for (i = 0; i < in->FaceElements->numElements; i++) {
         {  
177              if (in->FaceElements->Owner[i] == in->MPIInfo->rank)              if (in->FaceElements->Owner[i] == in->MPIInfo->rank)
178                  mine++;                  mine++;
179              else              else
# Line 230  void Dudley_PrintMesh_Info(Dudley_Mesh * Line 184  void Dudley_PrintMesh_Info(Dudley_Mesh *
184                  in->FaceElements->numElements,                  in->FaceElements->numElements,
185                  in->FaceElements->etype /*->referenceElementSet->referenceElement->Type->TypeId*/ , mine, overlap);                  in->FaceElements->etype /*->referenceElementSet->referenceElement->Type->TypeId*/ , mine, overlap);
186          NN = in->FaceElements->numNodes;          NN = in->FaceElements->numNodes;
187          if (full)          if (full) {
         {  
188              fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");              fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");
189              for (i = 0; i < in->FaceElements->numElements; i++)              for (i = 0; i < in->FaceElements->numElements; i++) {
             {  
190                  fprintf(stdout, "\t  %5d %5d %5d %5d: ", in->FaceElements->Id[i], in->FaceElements->Tag[i],                  fprintf(stdout, "\t  %5d %5d %5d %5d: ", in->FaceElements->Id[i], in->FaceElements->Tag[i],
191                          in->FaceElements->Owner[i], in->FaceElements->Color[i]);                          in->FaceElements->Owner[i], in->FaceElements->Color[i]);
192                  for (j = 0; j < NN; j++)                  for (j = 0; j < NN; j++)
# Line 242  void Dudley_PrintMesh_Info(Dudley_Mesh * Line 194  void Dudley_PrintMesh_Info(Dudley_Mesh *
194                  fprintf(stdout, "\n");                  fprintf(stdout, "\n");
195              }              }
196          }          }
197      }      } else {
     else  
     {  
198          fprintf(stdout, "\tFace elements: Tri3 0\n");          fprintf(stdout, "\tFace elements: Tri3 0\n");
199      }      }
200    
201      /* write points: */      /* write points: */
202      if (in->Points != NULL)      if (in->Points != NULL) {
     {  
203          int mine = 0, overlap = 0;          int mine = 0, overlap = 0;
204          for (i = 0; i < in->Points->numElements; i++)          for (i = 0; i < in->Points->numElements; i++) {
         {  
205              if (in->Points->Owner[i] == in->MPIInfo->rank)              if (in->Points->Owner[i] == in->MPIInfo->rank)
206                  mine++;                  mine++;
207              else              else
# Line 262  void Dudley_PrintMesh_Info(Dudley_Mesh * Line 210  void Dudley_PrintMesh_Info(Dudley_Mesh *
210          fprintf(stdout, "\tPoints: %s %d (TypeId=%d) owner=%d overlap=%d\n",          fprintf(stdout, "\tPoints: %s %d (TypeId=%d) owner=%d overlap=%d\n",
211                  in->Points->ename /*->referenceElementSet->referenceElement->Type->Name*/ , in->Points->numElements,                  in->Points->ename /*->referenceElementSet->referenceElement->Type->Name*/ , in->Points->numElements,
212                  in->Points->etype /*referenceElementSet->referenceElement->Type->TypeId */ , mine, overlap);                  in->Points->etype /*referenceElementSet->referenceElement->Type->TypeId */ , mine, overlap);
213          if (full)          if (full) {
         {  
214              fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");              fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");
215              for (i = 0; i < in->Points->numElements; i++)              for (i = 0; i < in->Points->numElements; i++)
216              {              {
# Line 271  void Dudley_PrintMesh_Info(Dudley_Mesh * Line 218  void Dudley_PrintMesh_Info(Dudley_Mesh *
218                          in->Points->Owner[i], in->Points->Color[i], in->Nodes->Id[in->Points->Nodes[INDEX2(0, i, 1)]]);                          in->Points->Owner[i], in->Points->Color[i], in->Nodes->Id[in->Points->Nodes[INDEX2(0, i, 1)]]);
219              }              }
220          }          }
221      }      } else {
     else  
     {  
222          fprintf(stdout, "\tPoints: Point1 0\n");          fprintf(stdout, "\tPoints: Point1 0\n");
223      }      }
224    
225      /* write tags: */      /* write tags: */
226      if (tag_map)      if (tag_map) {
     {  
227          fprintf(stdout, "\tTags:\n");          fprintf(stdout, "\tTags:\n");
228          while (tag_map)          while (tag_map) {
         {  
229              fprintf(stdout, "\t  %5d %s\n", tag_map->tag_key, tag_map->name);              fprintf(stdout, "\t  %5d %s\n", tag_map->tag_key, tag_map->name);
230              tag_map = tag_map->next;              tag_map = tag_map->next;
231          }          }
232      }      }
233  }  }
234    
235    } // namespace dudley
236    

Legend:
Removed from v.6008  
changed lines
  Added in v.6009

  ViewVC Help
Powered by ViewVC 1.1.26