FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_fstr_output_vtk.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
6 
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <math.h>
12 #include "hecmw_malloc.h"
13 #include "hecmw_etype.h"
14 #include "hecmw_vis_mem_util.h"
15 #include "hecmw_vis_comm_util.h"
16 #include "hecmw_vis_combine.h"
17 #include "hecmw_fstr_endian.h"
18 
19 void vtk_output (struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
20 {
21  int i, j, k;
22  int jS, jE;
23  int myrank, petot, steptot;
24  int n_node, n_elem, shift, etype;
25  int data_tot_n, data_tot_e;
26  int table342[10] = {0, 1, 2, 3, 6, 4, 5, 7, 8, 9};
27  char file_pvd[HECMW_FILENAME_LEN], file_pvtu[HECMW_FILENAME_LEN], file_vtu[HECMW_FILENAME_LEN], buf[HECMW_FILENAME_LEN];
28  char *data_label, *p;
29  static int is_first=0;
30  FILE *outfp;
31  HECMW_Status stat;
32 
33  HECMW_Comm_rank (VIS_COMM, &myrank);
34  HECMW_Comm_size (VIS_COMM, &petot);
35  n_node = mesh->n_node;
36  n_elem = mesh->n_elem;
37  data_tot_n = 0;
38  for(i=0; i<data->nn_component; i++){
39  data_tot_n += data->nn_dof[i];
40  }
41  data_tot_e = 0;
42  for(i=0; i<data->ne_component; i++){
43  data_tot_e += data->ne_dof[i];
44  }
45 
46  p = strrchr(outfile, (int)(unsigned char)'/');
47  if(NULL != p){
48  outfile = p+1;
49  }
50 
51  snprintf(file_vtu, sizeof(file_vtu), "%s/%s.%d.vtu", outfile1, outfile, myrank);
52  if(HECMW_ctrl_make_subdir(file_vtu)) {
53  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output directory");
54  }
55 
56  if (myrank == 0) {
57  /* outpu pvtu file */
58  snprintf(file_pvtu, sizeof(file_pvtu), "%s.pvtu", outfile1);
59  outfp = fopen (file_pvtu, "w");
60  if (!outfp)
61  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output file");
62  fprintf (outfp, "<?xml version=\"1.0\"?>\n");
63  fprintf (outfp, "<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" byte_order=\"%s\">\n", HECMW_endian_str());
64  fprintf (outfp, "<PUnstructuredGrid>\n");
65  fprintf (outfp, "<FieldData>\n");
66  for(i=0; i<data->ng_component; i++){
67  shift=0;
68  for(j=0; j<i; j++) shift += data->ng_dof[j];
69  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfTuples=\"%d\">",
70  strcmp(data->global_label[i], "TOTALTIME") == 0 ? "TimeValue" : data->global_label[i],
71  data->ng_dof[i]);
72  for(k=0; k<data->ng_dof[i]; k++){
73  fprintf (outfp, "%e ", (float)data->global_val_item[k+shift]);
74  }
75  fprintf (outfp, "</DataArray>\n");
76  }
77  fprintf (outfp, "</FieldData>\n");
78  fprintf (outfp, "<PPoints>\n");
79  fprintf (outfp, "<PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n");
80  fprintf (outfp, "</PPoints>\n");
81  fprintf (outfp, "<PCells>\n");
82  fprintf (outfp, "<PDataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\"/>\n");
83  fprintf (outfp, "<PDataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\"/>\n");
84  fprintf (outfp, "<PDataArray type=\"UInt8\" Name=\"types\" format=\"ascii\"/>\n");
85  fprintf (outfp, "</PCells>\n");
86  fprintf (outfp, "<PPointData>\n");
87  for(i=0; i<data->nn_component; i++){
88  if(
89  strcmp(data->node_label[i], "NodalPrincipalSTRAIN") == 0 ||
90  strcmp(data->node_label[i], "NodalPrincipalSTRESS") == 0
91  ) {
92  fprintf (outfp, "<PDataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" ComponentName0=\"1st\" ComponentName1=\"2nd\" ComponentName2=\"3rd\" format=\"ascii\"/>\n", data->node_label[i], data->nn_dof[i]);
93  } else {
94  fprintf (outfp, "<PDataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"ascii\"/>\n", data->node_label[i], data->nn_dof[i]);
95  }
96  }
97  fprintf (outfp, "</PPointData>\n");
98  fprintf (outfp, "<PCellData>\n");
99  fprintf (outfp, "<PDataArray type=\"Int16\" Name=\"Mesh_Type\" NumberOfComponents=\"1\" format=\"ascii\"/>\n");
100  for(i=0; i<data->ne_component; i++){
101  if(
102  strcmp(data->elem_label[i], "ElementalPrincipalSTRAIN") == 0 ||
103  strcmp(data->elem_label[i], "ElementalPrincipalSTRESS") == 0
104  ) {
105  fprintf (outfp, "<PDataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" ComponentName0=\"1st\" ComponentName1=\"2nd\" ComponentName2=\"3rd\" format=\"ascii\"/>\n", data->elem_label[i], data->ne_dof[i]);
106  } else {
107  fprintf (outfp, "<PDataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"ascii\"/>\n", data->elem_label[i], data->ne_dof[i]);
108  }
109  }
110  fprintf (outfp, "</PCellData>\n");
111  for(i=0; i<petot; i++){
112  snprintf (buf, sizeof(buf), "./%s/%s.%d.vtu", outfile, outfile, i);
113  fprintf (outfp, "<Piece Source=\"%s\"/>\n", buf);
114  }
115  fprintf (outfp, "</PUnstructuredGrid>\n");
116  fprintf (outfp, "</VTKFile>\n");
117  fclose (outfp);
118  }
119 
120  /* output vtu file */
121  outfp = fopen (file_vtu, "w");
122  if (!outfp)
123  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output file");
124  fprintf (outfp, "<?xml version=\"1.0\"?>\n");
125  fprintf (outfp, "<VTKFile type=\"UnstructuredGrid\" version=\"1.0\">\n");
126  fprintf (outfp, "<UnstructuredGrid>\n");
127  fprintf (outfp, "<FieldData>\n");
128  for(i=0; i<data->ng_component; i++){
129  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfTuples=\"%d\" >\n",
130  strcmp(data->global_label[i], "TOTALTIME") == 0 ? "TimeValue" : data->global_label[i],
131  data->ng_dof[i]);
132  shift=0;
133  for(j=0; j<i; j++){
134  shift += data->ng_dof[j];
135  }
136  for(k=0; k<data->ng_dof[i]; k++){
137  fprintf (outfp, "%e ", (float)data->global_val_item[k+shift]);
138  }
139  fprintf (outfp, "\n");
140  fprintf (outfp, "</DataArray>\n");
141  }
142  fprintf (outfp, "</FieldData>\n");
143  fprintf (outfp, "<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n", n_node, n_elem);
144  fprintf (outfp, "<Points>\n");
145  fprintf (outfp, "<DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n");
146  for(i=0; i<n_node; i++){
147  fprintf (outfp, "%e %e %e\n", (float)mesh->node[3*i], (float)mesh->node[3*i+1], (float)mesh->node[3*i+2]);
148  }
149  fprintf (outfp, "</DataArray>\n");
150  fprintf (outfp, "</Points>\n");
151  fprintf (outfp, "<Cells>\n");
152  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n");
153  for(i=0; i<n_elem; i++){
154  jS=mesh->elem_node_index[i];
155  jE=mesh->elem_node_index[i+1];
156  shift=0;
157  if(mesh->elem_type[i]==641) shift=2;
158  if(mesh->elem_type[i]==761) shift=3;
159  if(mesh->elem_type[i]==781) shift=4;
160  if(mesh->elem_type[i]==342){
161  for(j=jS; j<jE-shift; j++){
162  fprintf (outfp, "%d ", mesh->elem_node_item[jS+table342[j-jS]]-1);
163  }
164  }else{
165  for(j=jS; j<jE-shift; j++){
166  fprintf (outfp, "%d ", mesh->elem_node_item[j]-1);
167  }
168  }
169  fprintf (outfp, "\n");
170  }
171  fprintf (outfp, "</DataArray>\n");
172  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n");
173  shift=0;
174  for(i=0; i<n_elem; i++){
175  if(mesh->elem_type[i]==641) shift+=2;
176  if(mesh->elem_type[i]==761) shift+=3;
177  if(mesh->elem_type[i]==781) shift+=4;
178  fprintf (outfp, "%d ", mesh->elem_node_index[i+1]-shift);
179  }
180  fprintf (outfp, "\n");
181  fprintf (outfp, "</DataArray>\n");
182  fprintf (outfp, "<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n");
183  for(i=0; i<n_elem; i++){
184  fprintf (outfp, "%d ", HECMW_get_etype_vtk_shape(mesh->elem_type[i]));
185  }
186  fprintf (outfp, "\n");
187  fprintf (outfp, "</DataArray>\n");
188  fprintf (outfp, "</Cells>\n");
189  fprintf (outfp, "<PointData>\n");
190  for(i=0; i<data->nn_component; i++){
191  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"ascii\">\n", data->node_label[i], data->nn_dof[i]);
192  shift=0;
193  for(j=0; j<i; j++){
194  shift += data->nn_dof[j];
195  }
196  for(j=0; j<n_node; j++){
197  for(k=0; k<data->nn_dof[i]; k++){
198  fprintf (outfp, "%e ", (float)data->node_val_item[j*data_tot_n+k+shift]);
199  }
200  fprintf (outfp, "\n");
201  }
202  fprintf (outfp, "</DataArray>\n");
203  }
204  fprintf (outfp, "</PointData>\n");
205  fprintf (outfp, "<CellData>\n");
206  fprintf (outfp, "<DataArray type=\"Int16\" Name=\"Mesh_Type\" NumberOfComponents=\"1\" format=\"ascii\">\n");
207  for(i=0; i<n_elem; i++){
208  fprintf (outfp, "%d ", mesh->elem_type[i]);
209  }
210  fprintf (outfp, "\n");
211  fprintf (outfp, "</DataArray>\n");
212  for(i=0; i<data->ne_component; i++){
213  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"ascii\">\n", data->elem_label[i], data->ne_dof[i]);
214  shift=0;
215  for(j=0; j<i; j++){
216  shift += data->ne_dof[j];
217  }
218  for(j=0; j<n_elem; j++){
219  for(k=0; k<data->ne_dof[i]; k++){
220  fprintf (outfp, "%e ", (float)data->elem_val_item[j*data_tot_e+k+shift]);
221  }
222  fprintf (outfp, "\n");
223  }
224  fprintf (outfp, "</DataArray>\n");
225  }
226  fprintf (outfp, "</CellData>\n");
227  fprintf (outfp, "</Piece>\n");
228  fprintf (outfp, "</UnstructuredGrid>\n");
229  fprintf (outfp, "</VTKFile>\n");
230  fclose (outfp);
231 }
232 
233 void bin_vtk_output (struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
234 {
235  int i, j, k;
236  int jS, jE;
237  int myrank, petot, steptot;
238  int n_node, n_elem, shift, etype;
239  int data_tot_n, data_tot_e, in, ioffset;
240  int *offset;
241  uint8_t uint8;
242  uint16_t uint16;
243  uint32_t uint32;
244  uint64_t uint64;
245  float val, val1, val2, val3;
246  char file_pvd[HECMW_FILENAME_LEN], file_pvtu[HECMW_FILENAME_LEN], file_vtu[HECMW_FILENAME_LEN], buf[HECMW_FILENAME_LEN];
247  char *data_label;
248  static int is_first=0;
249  int table342[10] = {0, 1, 2, 3, 6, 4, 5, 7, 8, 9};
250  FILE *outfp;
251  HECMW_Status stat;
252 
253  HECMW_Comm_rank (VIS_COMM, &myrank);
254  HECMW_Comm_size (VIS_COMM, &petot);
255  n_node = mesh->n_node;
256  n_elem = mesh->n_elem;
257  data_tot_n = 0;
258  for(i=0; i<data->nn_component; i++){
259  data_tot_n += data->nn_dof[i];
260  }
261  data_tot_e = 0;
262  for(i=0; i<data->ne_component; i++){
263  data_tot_e += data->ne_dof[i];
264  }
265 
266  snprintf(file_vtu, sizeof(file_vtu), "%s/%s.%d.vtu", outfile1, outfile, myrank);
267  if(HECMW_ctrl_make_subdir(file_vtu)) {
268  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output directory");
269  }
270 
271  if (myrank == 0) {
272  /* outpu pvtu file */
273  snprintf(file_pvtu, sizeof(file_pvtu), "%s.pvtu", outfile1);
274  outfp = fopen (file_pvtu, "wb");
275  if (!outfp)
276  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output file");
277  fprintf (outfp, "<?xml version=\"1.0\"?>\n");
278  fprintf (outfp, "<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" byte_order=\"%s\" header_type=\"UInt32\">\n", HECMW_endian_str());
279  fprintf (outfp, "<PUnstructuredGrid>\n");
280  fprintf (outfp, "<FieldData>\n");
281  for(i=0; i<data->ng_component; i++){
282  shift=0;
283  for(j=0; j<i; j++) shift += data->ng_dof[j];
284  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfTuples=\"%d\">",
285  strcmp(data->global_label[i], "TOTALTIME") == 0 ? "TimeValue" : data->global_label[i],
286  data->ng_dof[i]);
287  for(k=0; k<data->ng_dof[i]; k++){
288  fprintf (outfp, "%e ", (float)data->global_val_item[k+shift]);
289  }
290  fprintf (outfp, "</DataArray>\n");
291  }
292  fprintf (outfp, "</FieldData>\n");
293  fprintf (outfp, "<PPoints>\n");
294  fprintf (outfp, "<PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n");
295  fprintf (outfp, "</PPoints>\n");
296  fprintf (outfp, "<PCells>\n");
297  fprintf (outfp, "<PDataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\"/>\n");
298  fprintf (outfp, "<PDataArray type=\"Int32\" Name=\"offsets\" format=\"appended\"/>\n");
299  fprintf (outfp, "<PDataArray type=\"Int32\" Name=\"types\" format=\"appended\"/>\n");
300  fprintf (outfp, "</PCells>\n");
301  fprintf (outfp, "<PPointData>\n");
302  for(i=0; i<data->nn_component; i++){
303  if(
304  strcmp(data->node_label[i], "NodalPrincipalSTRAIN") == 0 ||
305  strcmp(data->node_label[i], "NodalPrincipalSTRESS") == 0
306  ) {
307  fprintf (outfp, "<PDataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" ComponentName0=\"1st\" ComponentName1=\"2nd\" ComponentName2=\"3rd\" format=\"appended\"/>\n", data->node_label[i], data->nn_dof[i]);
308  } else {
309  fprintf (outfp, "<PDataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"appended\"/>\n", data->node_label[i], data->nn_dof[i]);
310  }
311  }
312  fprintf (outfp, "</PPointData>\n");
313  fprintf (outfp, "<PCellData>\n");
314  for(i=0; i<data->ne_component; i++){
315  if(
316  strcmp(data->elem_label[i], "ElementalPrincipalSTRAIN") == 0 ||
317  strcmp(data->elem_label[i], "ElementalPrincipalSTRESS") == 0
318  ) {
319  fprintf (outfp, "<PDataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" ComponentName0=\"1st\" ComponentName1=\"2nd\" ComponentName2=\"3rd\" format=\"appended\"/>\n", data->elem_label[i], data->ne_dof[i]);
320  } else {
321  fprintf (outfp, "<PDataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"appended\"/>\n", data->elem_label[i], data->ne_dof[i]);
322  }
323  }
324  fprintf (outfp, "<PDataArray type=\"Int32\" Name=\"Mesh_Type\" NumberOfComponents=\"1\" format=\"appended\"/>\n");
325  fprintf (outfp, "</PCellData>\n");
326  for(i=0; i<petot; i++){
327  snprintf (buf, sizeof(buf), "./%s/%s.%d.vtu", outfile, outfile, i);
328  fprintf (outfp, "<Piece Source=\"%s\"/>\n", buf);
329  }
330  fprintf (outfp, "</PUnstructuredGrid>\n");
331  fprintf (outfp, "</VTKFile>\n");
332  fclose (outfp);
333  is_first = 1;
334  }
335 
336  /* outpu vtu file */
337  ioffset = 5 + data->nn_component + data->ne_component;
338  offset = HECMW_malloc(sizeof(int)*ioffset);
339 
340  uint64 = 0;
341  for(i=0; i<n_elem; i++){
342  jS=mesh->elem_node_index[i];
343  jE=mesh->elem_node_index[i+1];
344  shift=0;
345  if(mesh->elem_type[i]==641) shift=2;
346  if(mesh->elem_type[i]==761) shift=3;
347  if(mesh->elem_type[i]==781) shift=4;
348  uint64 += jE-shift-jS;
349  }
350 
351  offset[0] = 0;
352  offset[1] = offset[0] + sizeof(int) + 3*n_node *sizeof(float);
353  offset[2] = offset[1] + sizeof(int) + (int)uint64*sizeof(int);
354  offset[3] = offset[2] + sizeof(int) + n_elem *sizeof(int);
355  offset[4] = offset[3] + sizeof(int) + n_elem *sizeof(int);
356  for(i=0; i<data->nn_component; i++){
357  offset[5+i] = offset[4+i] + sizeof(int) + data->nn_dof[i]*n_node*sizeof(int);
358  }
359  for(i=0; i<data->ne_component; i++){
360  offset[5+data->nn_component+i] = offset[4+data->nn_component+i] + sizeof(int) + data->ne_dof[i]*n_elem*sizeof(int);
361  }
362 
363  outfp = fopen (file_vtu, "wb");
364  if (!outfp)
365  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output file");
366  fprintf (outfp, "<?xml version=\"1.0\"?>\n");
367  fprintf (outfp, "<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" byte_order=\"%s\" header_type=\"UInt32\">\n", HECMW_endian_str());
368  fprintf (outfp, "<UnstructuredGrid>\n");
369  fprintf (outfp, "<FieldData>\n");
370  for(i=0; i<data->ng_component; i++){
371  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfTuples=\"%d\" >\n",
372  strcmp(data->global_label[i], "TOTALTIME") == 0 ? "TimeValue" : data->global_label[i],
373  data->ng_dof[i]);
374  shift=0;
375  for(j=0; j<i; j++){
376  shift += data->ng_dof[j];
377  }
378  for(k=0; k<data->ng_dof[i]; k++){
379  fprintf (outfp, "%e ", (float)data->global_val_item[k+shift]);
380  }
381  fprintf (outfp, "\n");
382  fprintf (outfp, "</DataArray>\n");
383  }
384  fprintf (outfp, "</FieldData>\n");
385  fprintf (outfp, "<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n", n_node, n_elem);
386  fprintf (outfp, "<Points>\n");
387  fprintf (outfp, "<DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"%d\">\n", offset[0]);
388  fprintf (outfp, "</DataArray>\n");
389  fprintf (outfp, "</Points>\n");
390  fprintf (outfp, "<Cells>\n");
391  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"%d\">\n", offset[1]);
392  fprintf (outfp, "</DataArray>\n");
393  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"%d\">\n", offset[2]);
394  fprintf (outfp, "</DataArray>\n");
395  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"types\" format=\"appended\" offset=\"%d\">\n", offset[3]);
396  fprintf (outfp, "</DataArray>\n");
397  fprintf (outfp, "</Cells>\n");
398  fprintf (outfp, "<PointData>\n");
399 
400  for(i=0; i<data->nn_component; i++){
401  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"appended\" offset=\"%d\">\n", data->node_label[i], data->nn_dof[i], offset[4+i]);
402  fprintf (outfp, "</DataArray>\n");
403  }
404 
405  fprintf (outfp, "</PointData>\n");
406  fprintf (outfp, "<CellData>\n");
407  for(i=0; i<data->ne_component; i++){
408  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"appended\" offset=\"%d\">\n", data->elem_label[i], data->ne_dof[i], offset[4+data->nn_component+i]);
409  fprintf (outfp, "</DataArray>\n");
410  }
411 
412  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"Mesh_Type\" NumberOfComponents=\"1\" format=\"appended\" offset=\"%d\">\n", offset[ioffset-1]);
413  fprintf (outfp, "</DataArray>\n");
414  fprintf (outfp, "</CellData>\n");
415  fprintf (outfp, "</Piece>\n");
416  fprintf (outfp, "</UnstructuredGrid>\n");
417  fprintf (outfp, "<AppendedData encoding=\"raw\">\n");
418 
419  fprintf (outfp, " _");
420  uint32 = (uint32_t)(3*n_node*sizeof(float));
421  fwrite (&uint32, sizeof(uint32), 1, outfp);
422  for(i=0; i<n_node; i++){
423  val = (float)mesh->node[3*i];
424  fwrite (&val, sizeof(float), 1, outfp);
425  val = (float)mesh->node[3*i+1];
426  fwrite (&val, sizeof(float), 1, outfp);
427  val = (float)mesh->node[3*i+2];
428  fwrite (&val, sizeof(float), 1, outfp);
429  }
430 
431  uint32 = (uint32_t)(uint64*sizeof(int));
432  fwrite (&uint32, sizeof(uint32), 1, outfp);
433  for(i=0; i<n_elem; i++){
434  jS=mesh->elem_node_index[i];
435  jE=mesh->elem_node_index[i+1];
436  shift=0;
437  if(mesh->elem_type[i]==641) shift=2;
438  if(mesh->elem_type[i]==761) shift=3;
439  if(mesh->elem_type[i]==781) shift=4;
440  if(mesh->elem_type[i]==342){
441  for(j=jS; j<jE-shift; j++){
442  in = (int)mesh->elem_node_item[jS+table342[j-jS]]-1;
443  fwrite (&in, sizeof(int), 1, outfp);
444  }
445  }else{
446  for(j=jS; j<jE-shift; j++){
447  in = (int)mesh->elem_node_item[j]-1;
448  fwrite (&in, sizeof(int), 1, outfp);
449  }
450  }
451  }
452 
453  uint32 = (uint32_t)(n_elem*sizeof(int));
454  fwrite (&uint32, sizeof(uint32), 1, outfp);
455  shift=0;
456  for(i=0; i<n_elem; i++){
457  if(mesh->elem_type[i]==641) shift+=2;
458  if(mesh->elem_type[i]==761) shift+=3;
459  if(mesh->elem_type[i]==781) shift+=4;
460  in = (int)mesh->elem_node_index[i+1]-shift;
461  fwrite (&in, sizeof(int), 1, outfp);
462  }
463 
464  uint32 = (uint32_t)(n_elem*sizeof(int));
465  fwrite (&uint32, sizeof(uint32), 1, outfp);
466  for(i=0; i<n_elem; i++){
467  //uint8 = (uint8_t)HECMW_get_etype_vtk_shape(mesh->elem_type[i]);
468  //fwrite (&uint8, sizeof(u_int8_t), 1, outfp);
470  fwrite (&in, sizeof(int), 1, outfp);
471  }
472 
473  for(i=0; i<data->nn_component; i++){
474  uint32 = (uint32_t)(data->nn_dof[i]*n_node*sizeof(int));
475  fwrite (&uint32, sizeof(uint32), 1, outfp);
476 
477  shift=0;
478  for(j=0; j<i; j++){
479  shift += data->nn_dof[j];
480  }
481  for(j=0; j<n_node; j++){
482  for(k=0; k<data->nn_dof[i]; k++){
483  val = (float)data->node_val_item[j*data_tot_n+k+shift];
484  fwrite (&val, sizeof(float), 1, outfp);
485  }
486  }
487  }
488 
489  for(i=0; i<data->ne_component; i++){
490  uint32 = (uint32_t)(data->ne_dof[i]*n_elem*sizeof(int));
491  fwrite (&uint32, sizeof(uint32), 1, outfp);
492 
493  shift=0;
494  for(j=0; j<i; j++){
495  shift += data->ne_dof[j];
496  }
497  for(j=0; j<n_elem; j++){
498  for(k=0; k<data->ne_dof[i]; k++){
499  val = (float)data->elem_val_item[j*data_tot_e+k+shift];
500  fwrite (&val, sizeof(float), 1, outfp);
501  }
502  }
503  }
504 
505  uint32 = (uint32_t)(n_elem*sizeof(int));
506  fwrite (&uint32, sizeof(uint32), 1, outfp);
507  for(i=0; i<n_elem; i++){
508  //uint16 = (uint16_t)mesh->elem_type[i];
509  //fwrite (&uint16, sizeof(u_int16_t), 1, outfp);
510  in = (int)mesh->elem_type[i];
511  fwrite (&in, sizeof(int), 1, outfp);
512  }
513 
514  fprintf (outfp, "</AppendedData>\n");
515  fprintf (outfp, "</VTKFile>\n");
516  fclose (outfp);
517 }
518 
519 void HECMW_vtk_output (struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
520 {
521  vtk_output (mesh, data, outfile, outfile1, VIS_COMM);
522 }
523 
524 void HECMW_bin_vtk_output (struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
525 {
526  bin_vtk_output (mesh, data, outfile, outfile1, VIS_COMM);
527 }
int is_first
int HECMW_Comm_rank(HECMW_Comm comm, int *rank)
Definition: hecmw_comm.c:18
int HECMW_Comm_size(HECMW_Comm comm, int *size)
Definition: hecmw_comm.c:37
#define HECMW_FILENAME_LEN
Definition: hecmw_config.h:74
MPI_Status HECMW_Status
Definition: hecmw_config.h:36
MPI_Comm HECMW_Comm
Definition: hecmw_config.h:30
int HECMW_ctrl_make_subdir(char *filename)
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
int HECMW_get_etype_vtk_shape(int etype)
Definition: hecmw_etype.c:1731
const char * HECMW_endian_str(void)
function for investigating endian of running CPU
void vtk_output(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
void HECMW_vtk_output(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
void HECMW_bin_vtk_output(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
void bin_vtk_output(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
#define NULL
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
void HECMW_vis_print_exit(char *var)
integer(kind=kint) myrank
PARALLEL EXECUTION.
Definition: m_fstr.f90:97
CNFData data
long long * elem_node_index
Definition: hecmw_struct.h:195