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