/[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 5962 by caltinay, Fri Feb 5 03:37:49 2016 UTC revision 5963 by caltinay, Mon Feb 22 06:59:27 2016 UTC
# Line 29  Line 29 
29    
30  /*  writes the mesh to the external file fname using the Dudley file format: */  /*  writes the mesh to the external file fname using the Dudley file format: */
31    
32  void Dudley_Mesh_write(Dudley_Mesh * in, char *fname)  void Dudley_Mesh_write(Dudley_Mesh* in, char* fname)
33  {  {
34      char error_msg[LenErrorMsg_MAX];      char error_msg[1024];
35      FILE *f;      FILE *f;
36      int NN, i, j, numDim;      int NN, i, j, numDim;
37      Dudley_TagMap *tag_map = in->TagMap;      Dudley_TagMap *tag_map = in->TagMap;
38    
39      if (in->MPIInfo->size > 1)      if (in->MPIInfo->size > 1)
40      {      {
41      Dudley_setError(IO_ERROR, "Mesh_write: only single processor runs are supported.");          Dudley_setError(IO_ERROR, "Mesh_write: only single processor runs are supported.");
42      return;          return;
43    
44      }      }
45      /* open file */      /* open file */
46      f = fopen(fname, "w");      f = fopen(fname, "w");
47      if (f == NULL)      if (f == NULL)
48      {      {
49      sprintf(error_msg, "Mesh_write: Opening file %s for writing failed.", fname);          sprintf(error_msg, "Mesh_write: Opening file %s for writing failed.", fname);
50      Dudley_setError(IO_ERROR, error_msg);          Dudley_setError(IO_ERROR, error_msg);
51      return;          return;
52      }      }
53    
54      /* write header */      /* write header */
# Line 59  void Dudley_Mesh_write(Dudley_Mesh * in, Line 59  void Dudley_Mesh_write(Dudley_Mesh * in,
59    
60      if (in->Nodes != NULL)      if (in->Nodes != NULL)
61      {      {
62      numDim = Dudley_Mesh_getDim(in);          numDim = Dudley_Mesh_getDim(in);
63      fprintf(f, "%1dD-Nodes %d\n", numDim, in->Nodes->numNodes);          fprintf(f, "%1dD-Nodes %d\n", numDim, in->Nodes->numNodes);
64      for (i = 0; i < in->Nodes->numNodes; i++)          for (i = 0; i < in->Nodes->numNodes; i++)
65      {          {
66          fprintf(f, "%d %d %d", in->Nodes->Id[i], in->Nodes->globalDegreesOfFreedom[i], in->Nodes->Tag[i]);              fprintf(f, "%d %d %d", in->Nodes->Id[i], in->Nodes->globalDegreesOfFreedom[i], in->Nodes->Tag[i]);
67          for (j = 0; j < numDim; j++)              for (j = 0; j < numDim; j++)
68          fprintf(f, " %20.15e", in->Nodes->Coordinates[INDEX2(j, i, numDim)]);                  fprintf(f, " %20.15e", in->Nodes->Coordinates[INDEX2(j, i, numDim)]);
69          fprintf(f, "\n");              fprintf(f, "\n");
70      }          }
71      }      }
72      else      else
73      {      {
74      fprintf(f, "0D-Nodes 0\n");          fprintf(f, "0D-Nodes 0\n");
75      }      }
76    
77      /*  write elements: */      /*  write elements: */
78    
79      if (in->Elements != NULL)      if (in->Elements != NULL)
80      {      {
81      fprintf(f, "%s %d\n", in->Elements->ename /*referenceElementSet->referenceElement->Type->Name */ ,          fprintf(f, "%s %d\n", in->Elements->ename /*referenceElementSet->referenceElement->Type->Name */ ,
82          in->Elements->numElements);                  in->Elements->numElements);
83      NN = in->Elements->numNodes;          NN = in->Elements->numNodes;
84      for (i = 0; i < in->Elements->numElements; i++)          for (i = 0; i < in->Elements->numElements; i++)
85      {          {
86          fprintf(f, "%d %d", in->Elements->Id[i], in->Elements->Tag[i]);              fprintf(f, "%d %d", in->Elements->Id[i], in->Elements->Tag[i]);
87          for (j = 0; j < NN; j++)              for (j = 0; j < NN; j++)
88          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)]]);
89          fprintf(f, "\n");              fprintf(f, "\n");
90      }          }
91      }      }
92      else      else
93      {      {
94      fprintf(f, "Tet4 0\n");          fprintf(f, "Tet4 0\n");
95      }      }
96    
97      /*  write face elements: */      /*  write face elements: */
98      if (in->FaceElements != NULL)      if (in->FaceElements != NULL)
99      {      {
100      fprintf(f, "%s %d\n", in->FaceElements->ename /*referenceElementSet->referenceElement->Type->Name */ ,          fprintf(f, "%s %d\n", in->FaceElements->ename /*referenceElementSet->referenceElement->Type->Name */ ,
101          in->FaceElements->numElements);                  in->FaceElements->numElements);
102      NN = in->FaceElements->numNodes;          NN = in->FaceElements->numNodes;
103      for (i = 0; i < in->FaceElements->numElements; i++)          for (i = 0; i < in->FaceElements->numElements; i++)
104      {          {
105          fprintf(f, "%d %d", in->FaceElements->Id[i], in->FaceElements->Tag[i]);              fprintf(f, "%d %d", in->FaceElements->Id[i], in->FaceElements->Tag[i]);
106          for (j = 0; j < NN; j++)              for (j = 0; j < NN; j++)
107          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)]]);
108          fprintf(f, "\n");              fprintf(f, "\n");
109      }          }
110      }      }
111      else      else
112      {      {
113      fprintf(f, "Tri3 0\n");          fprintf(f, "Tri3 0\n");
114      }      }
115    
116      /*  write points: */      /*  write points: */
117      if (in->Points != NULL)      if (in->Points != NULL)
118      {      {
119      fprintf(f, "%s %d\n", in->Points->ename /*referenceElementSet->referenceElement->Type->Name */ ,          fprintf(f, "%s %d\n", in->Points->ename /*referenceElementSet->referenceElement->Type->Name */ ,
120          in->Points->numElements);                  in->Points->numElements);
121      for (i = 0; i < in->Points->numElements; i++)          for (i = 0; i < in->Points->numElements; i++)
122      {          {
123          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],
124              in->Nodes->Id[in->Points->Nodes[INDEX2(0, i, 1)]]);                      in->Nodes->Id[in->Points->Nodes[INDEX2(0, i, 1)]]);
125      }          }
126      }      }
127      else      else
128      {      {
129      fprintf(f, "Point1 0\n");          fprintf(f, "Point1 0\n");
130      }      }
131    
132      /*  write tags: */      /*  write tags: */
133      if (tag_map)      if (tag_map)
134      {      {
135      fprintf(f, "Tags\n");          fprintf(f, "Tags\n");
136      while (tag_map)          while (tag_map)
137      {          {
138          fprintf(f, "%s %d\n", tag_map->name, tag_map->tag_key);              fprintf(f, "%s %d\n", tag_map->name, tag_map->tag_key);
139          tag_map = tag_map->next;              tag_map = tag_map->next;
140      }          }
141      }      }
142      fclose(f);      fclose(f);
143  #ifdef Dudley_TRACE  #ifdef Dudley_TRACE
# Line 160  void Dudley_PrintMesh_Info(Dudley_Mesh * Line 160  void Dudley_PrintMesh_Info(Dudley_Mesh *
160      /* write nodes: */      /* write nodes: */
161      if (in->Nodes != NULL)      if (in->Nodes != NULL)
162      {      {
163      numDim = Dudley_Mesh_getDim(in);          numDim = Dudley_Mesh_getDim(in);
164      fprintf(stdout, "\tNodes: %1dD-Nodes %d\n", numDim, in->Nodes->numNodes);          fprintf(stdout, "\tNodes: %1dD-Nodes %d\n", numDim, in->Nodes->numNodes);
165      if (full)          if (full)
166      {          {
167          fprintf(stdout, "\t     Id   Tag  gDOF   gNI grDfI  grNI:  Coordinates\n");              fprintf(stdout, "\t     Id   Tag  gDOF   gNI grDfI  grNI:  Coordinates\n");
168          for (i = 0; i < in->Nodes->numNodes; i++)              for (i = 0; i < in->Nodes->numNodes; i++)
169          {              {
170          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],
171              in->Nodes->globalDegreesOfFreedom[i], in->Nodes->globalNodesIndex[i],                          in->Nodes->globalDegreesOfFreedom[i], in->Nodes->globalNodesIndex[i],
172              in->Nodes->globalReducedDOFIndex[i], in->Nodes->globalReducedNodesIndex[i]);                          in->Nodes->globalReducedDOFIndex[i], in->Nodes->globalReducedNodesIndex[i]);
173          for (j = 0; j < numDim; j++)                  for (j = 0; j < numDim; j++)
174              fprintf(stdout, " %20.15e", in->Nodes->Coordinates[INDEX2(j, i, numDim)]);                      fprintf(stdout, " %20.15e", in->Nodes->Coordinates[INDEX2(j, i, numDim)]);
175          fprintf(stdout, "\n");                  fprintf(stdout, "\n");
176          }              }
177      }          }
178      }      }
179      else      else
180      {      {
181      fprintf(stdout, "\tNodes: 0D-Nodes 0\n");          fprintf(stdout, "\tNodes: 0D-Nodes 0\n");
182      }      }
183    
184      /* write elements: */      /* write elements: */
185      if (in->Elements != NULL)      if (in->Elements != NULL)
186      {      {
187      int mine = 0, overlap = 0;          int mine = 0, overlap = 0;
188      for (i = 0; i < in->Elements->numElements; i++)          for (i = 0; i < in->Elements->numElements; i++)
189      {          {
190          if (in->Elements->Owner[i] == in->MPIInfo->rank)              if (in->Elements->Owner[i] == in->MPIInfo->rank)
191          mine++;                  mine++;
192          else              else
193          overlap++;                  overlap++;
194      }          }
195      fprintf(stdout, "\tElements: %s %d (TypeId=%d) owner=%d overlap=%d\n",          fprintf(stdout, "\tElements: %s %d (TypeId=%d) owner=%d overlap=%d\n",
196          in->Elements->ename /*referenceElementSet->referenceElement->Type->Name */ , in->Elements->numElements,                  in->Elements->ename /*referenceElementSet->referenceElement->Type->Name */ , in->Elements->numElements,
197          in->Elements->etype /*referenceElementSet->referenceElement->Type->TypeId */ , mine, overlap);                  in->Elements->etype /*referenceElementSet->referenceElement->Type->TypeId */ , mine, overlap);
198      NN = in->Elements->numNodes;          NN = in->Elements->numNodes;
199      if (full)          if (full)
200      {          {
201          fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");              fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");
202          for (i = 0; i < in->Elements->numElements; i++)              for (i = 0; i < in->Elements->numElements; i++)
203          {              {
204          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],
205              in->Elements->Owner[i], in->Elements->Color[i]);                          in->Elements->Owner[i], in->Elements->Color[i]);
206          for (j = 0; j < NN; j++)                  for (j = 0; j < NN; j++)
207              fprintf(stdout, " %5d", in->Nodes->Id[in->Elements->Nodes[INDEX2(j, i, NN)]]);                      fprintf(stdout, " %5d", in->Nodes->Id[in->Elements->Nodes[INDEX2(j, i, NN)]]);
208          fprintf(stdout, "\n");                  fprintf(stdout, "\n");
209          }              }
210      }          }
211      }      }
212      else      else
213      {      {
214      fprintf(stdout, "\tElements: Tet4 0\n");          fprintf(stdout, "\tElements: Tet4 0\n");
215      }      }
216    
217      /* write face elements: */      /* write face elements: */
218      if (in->FaceElements != NULL)      if (in->FaceElements != NULL)
219      {      {
220      int mine = 0, overlap = 0;          int mine = 0, overlap = 0;
221      for (i = 0; i < in->FaceElements->numElements; i++)          for (i = 0; i < in->FaceElements->numElements; i++)
222      {          {
223          if (in->FaceElements->Owner[i] == in->MPIInfo->rank)              if (in->FaceElements->Owner[i] == in->MPIInfo->rank)
224          mine++;                  mine++;
225          else              else
226          overlap++;                  overlap++;
227      }          }
228      fprintf(stdout, "\tFace elements: %s %d (TypeId=%d) owner=%d overlap=%d\n",          fprintf(stdout, "\tFace elements: %s %d (TypeId=%d) owner=%d overlap=%d\n",
229          in->FaceElements->ename /*referenceElementSet->referenceElement->Type->Name */ ,                  in->FaceElements->ename /*referenceElementSet->referenceElement->Type->Name */ ,
230          in->FaceElements->numElements,                  in->FaceElements->numElements,
231          in->FaceElements->etype /*->referenceElementSet->referenceElement->Type->TypeId*/ , mine, overlap);                  in->FaceElements->etype /*->referenceElementSet->referenceElement->Type->TypeId*/ , mine, overlap);
232      NN = in->FaceElements->numNodes;          NN = in->FaceElements->numNodes;
233      if (full)          if (full)
234      {          {
235          fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");              fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");
236          for (i = 0; i < in->FaceElements->numElements; i++)              for (i = 0; i < in->FaceElements->numElements; i++)
237          {              {
238          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],
239              in->FaceElements->Owner[i], in->FaceElements->Color[i]);                          in->FaceElements->Owner[i], in->FaceElements->Color[i]);
240          for (j = 0; j < NN; j++)                  for (j = 0; j < NN; j++)
241              fprintf(stdout, " %5d", in->Nodes->Id[in->FaceElements->Nodes[INDEX2(j, i, NN)]]);                      fprintf(stdout, " %5d", in->Nodes->Id[in->FaceElements->Nodes[INDEX2(j, i, NN)]]);
242          fprintf(stdout, "\n");                  fprintf(stdout, "\n");
243          }              }
244      }          }
245      }      }
246      else      else
247      {      {
248      fprintf(stdout, "\tFace elements: Tri3 0\n");          fprintf(stdout, "\tFace elements: Tri3 0\n");
249      }      }
250    
251      /* write points: */      /* write points: */
252      if (in->Points != NULL)      if (in->Points != NULL)
253      {      {
254      int mine = 0, overlap = 0;          int mine = 0, overlap = 0;
255      for (i = 0; i < in->Points->numElements; i++)          for (i = 0; i < in->Points->numElements; i++)
256      {          {
257          if (in->Points->Owner[i] == in->MPIInfo->rank)              if (in->Points->Owner[i] == in->MPIInfo->rank)
258          mine++;                  mine++;
259          else              else
260          overlap++;                  overlap++;
261      }          }
262      fprintf(stdout, "\tPoints: %s %d (TypeId=%d) owner=%d overlap=%d\n",          fprintf(stdout, "\tPoints: %s %d (TypeId=%d) owner=%d overlap=%d\n",
263          in->Points->ename /*->referenceElementSet->referenceElement->Type->Name*/ , in->Points->numElements,                  in->Points->ename /*->referenceElementSet->referenceElement->Type->Name*/ , in->Points->numElements,
264          in->Points->etype /*referenceElementSet->referenceElement->Type->TypeId */ , mine, overlap);                  in->Points->etype /*referenceElementSet->referenceElement->Type->TypeId */ , mine, overlap);
265      if (full)          if (full)
266      {          {
267          fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");              fprintf(stdout, "\t     Id   Tag Owner Color:  Nodes\n");
268          for (i = 0; i < in->Points->numElements; i++)              for (i = 0; i < in->Points->numElements; i++)
269          {              {
270          fprintf(stdout, "\t  %5d %5d %5d %5d %5d\n", in->Points->Id[i], in->Points->Tag[i],                  fprintf(stdout, "\t  %5d %5d %5d %5d %5d\n", in->Points->Id[i], in->Points->Tag[i],
271              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)]]);
272          }              }
273      }          }
274      }      }
275      else      else
276      {      {
277      fprintf(stdout, "\tPoints: Point1 0\n");          fprintf(stdout, "\tPoints: Point1 0\n");
278      }      }
279    
280      /* write tags: */      /* write tags: */
281      if (tag_map)      if (tag_map)
282      {      {
283      fprintf(stdout, "\tTags:\n");          fprintf(stdout, "\tTags:\n");
284      while (tag_map)          while (tag_map)
285      {          {
286          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);
287          tag_map = tag_map->next;              tag_map = tag_map->next;
288      }          }
289      }      }
290  }  }
291    

Legend:
Removed from v.5962  
changed lines
  Added in v.5963

  ViewVC Help
Powered by ViewVC 1.1.26