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  long long 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  {
161  long long jj;
162  if(mesh->elem_type[i]==342){
163  for(jj=jS; jj<jE-shift; jj++){
164  fprintf (outfp, "%d ", mesh->elem_node_item[jS+table342[jj-jS]]-1);
165  }
166  }else{
167  for(jj=jS; jj<jE-shift; jj++){
168  fprintf (outfp, "%d ", mesh->elem_node_item[jj]-1);
169  }
170  }
171  }
172  fprintf (outfp, "\n");
173  }
174  fprintf (outfp, "</DataArray>\n");
175  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n");
176  shift=0;
177  for(i=0; i<n_elem; i++){
178  if(mesh->elem_type[i]==641) shift+=2;
179  if(mesh->elem_type[i]==761) shift+=3;
180  if(mesh->elem_type[i]==781) shift+=4;
181  fprintf (outfp, "%lld ", mesh->elem_node_index[i+1]-shift);
182  }
183  fprintf (outfp, "\n");
184  fprintf (outfp, "</DataArray>\n");
185  fprintf (outfp, "<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n");
186  for(i=0; i<n_elem; i++){
187  fprintf (outfp, "%d ", HECMW_get_etype_vtk_shape(mesh->elem_type[i]));
188  }
189  fprintf (outfp, "\n");
190  fprintf (outfp, "</DataArray>\n");
191  fprintf (outfp, "</Cells>\n");
192  fprintf (outfp, "<PointData>\n");
193  for(i=0; i<data->nn_component; i++){
194  shift=0;
195  for(j=0; j<i; j++){
196  shift += data->nn_dof[j];
197  }
198  if (strcmp(data->node_label[i], "DISPLACEMENT") == 0 && data->nn_dof[i] == 2) {
199  // Convert 2D displacement to 3D
200  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"3\" format=\"ascii\">\n", data->node_label[i]);
201  for(j=0; j<n_node; j++){
202  fprintf (outfp, "%e %e 0.0\n",
203  (float)data->node_val_item[j*data_tot_n+shift],
204  (float)data->node_val_item[j*data_tot_n+shift+1]);
205  }
206  } else {
207  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"ascii\">\n", data->node_label[i], data->nn_dof[i]);
208  for(j=0; j<n_node; j++){
209  for(k=0; k<data->nn_dof[i]; k++){
210  fprintf (outfp, "%e ", (float)data->node_val_item[j*data_tot_n+k+shift]);
211  }
212  fprintf (outfp, "\n");
213  }
214  }
215  fprintf (outfp, "</DataArray>\n");
216  }
217  fprintf (outfp, "</PointData>\n");
218  fprintf (outfp, "<CellData>\n");
219  fprintf (outfp, "<DataArray type=\"Int16\" Name=\"Mesh_Type\" NumberOfComponents=\"1\" format=\"ascii\">\n");
220  for(i=0; i<n_elem; i++){
221  fprintf (outfp, "%d ", mesh->elem_type[i]);
222  }
223  fprintf (outfp, "\n");
224  fprintf (outfp, "</DataArray>\n");
225  for(i=0; i<data->ne_component; i++){
226  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"ascii\">\n", data->elem_label[i], data->ne_dof[i]);
227  shift=0;
228  for(j=0; j<i; j++){
229  shift += data->ne_dof[j];
230  }
231  for(j=0; j<n_elem; j++){
232  for(k=0; k<data->ne_dof[i]; k++){
233  fprintf (outfp, "%e ", (float)data->elem_val_item[j*data_tot_e+k+shift]);
234  }
235  fprintf (outfp, "\n");
236  }
237  fprintf (outfp, "</DataArray>\n");
238  }
239  fprintf (outfp, "</CellData>\n");
240  fprintf (outfp, "</Piece>\n");
241  fprintf (outfp, "</UnstructuredGrid>\n");
242  fprintf (outfp, "</VTKFile>\n");
243  fclose (outfp);
244 }
245 
246 void bin_vtk_output (struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
247 {
248  int i, j, k;
249  long long jS, jE;
250  int myrank, petot, steptot;
251  int n_node, n_elem, shift, etype;
252  int data_tot_n, data_tot_e, in, ioffset;
253  int *offset;
254  int is_disp2d=0;
255  uint8_t uint8;
256  uint16_t uint16;
257  uint32_t uint32;
258  uint64_t uint64;
259  float val, val1, val2, val3;
260  char file_pvd[HECMW_FILENAME_LEN], file_pvtu[HECMW_FILENAME_LEN], file_vtu[HECMW_FILENAME_LEN], buf[HECMW_FILENAME_LEN];
261  char *data_label;
262  static int is_first=0;
263  int table342[10] = {0, 1, 2, 3, 6, 4, 5, 7, 8, 9};
264  FILE *outfp;
265  HECMW_Status stat;
266 
267  HECMW_Comm_rank (VIS_COMM, &myrank);
268  HECMW_Comm_size (VIS_COMM, &petot);
269  n_node = mesh->n_node;
270  n_elem = mesh->n_elem;
271  data_tot_n = 0;
272  for(i=0; i<data->nn_component; i++){
273  data_tot_n += data->nn_dof[i];
274  }
275  data_tot_e = 0;
276  for(i=0; i<data->ne_component; i++){
277  data_tot_e += data->ne_dof[i];
278  }
279 
280  snprintf(file_vtu, sizeof(file_vtu), "%s/%s.%d.vtu", outfile1, outfile, myrank);
281  if(HECMW_ctrl_make_subdir(file_vtu)) {
282  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output directory");
283  }
284 
285  if (myrank == 0) {
286  /* outpu pvtu file */
287  snprintf(file_pvtu, sizeof(file_pvtu), "%s.pvtu", outfile1);
288  outfp = fopen (file_pvtu, "wb");
289  if (!outfp)
290  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output file");
291  fprintf (outfp, "<?xml version=\"1.0\"?>\n");
292  fprintf (outfp, "<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" byte_order=\"%s\" header_type=\"UInt32\">\n", HECMW_endian_str());
293  fprintf (outfp, "<PUnstructuredGrid>\n");
294  fprintf (outfp, "<FieldData>\n");
295  for(i=0; i<data->ng_component; i++){
296  shift=0;
297  for(j=0; j<i; j++) shift += data->ng_dof[j];
298  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfTuples=\"%d\">",
299  strcmp(data->global_label[i], "TOTALTIME") == 0 ? "TimeValue" : data->global_label[i],
300  data->ng_dof[i]);
301  for(k=0; k<data->ng_dof[i]; k++){
302  fprintf (outfp, "%e ", (float)data->global_val_item[k+shift]);
303  }
304  fprintf (outfp, "</DataArray>\n");
305  }
306  fprintf (outfp, "</FieldData>\n");
307  fprintf (outfp, "<PPoints>\n");
308  fprintf (outfp, "<PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n");
309  fprintf (outfp, "</PPoints>\n");
310  fprintf (outfp, "<PCells>\n");
311  fprintf (outfp, "<PDataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\"/>\n");
312  fprintf (outfp, "<PDataArray type=\"Int32\" Name=\"offsets\" format=\"appended\"/>\n");
313  fprintf (outfp, "<PDataArray type=\"Int32\" Name=\"types\" format=\"appended\"/>\n");
314  fprintf (outfp, "</PCells>\n");
315  fprintf (outfp, "<PPointData>\n");
316  for(i=0; i<data->nn_component; i++){
317  if(
318  strcmp(data->node_label[i], "NodalPrincipalSTRAIN") == 0 ||
319  strcmp(data->node_label[i], "NodalPrincipalSTRESS") == 0
320  ) {
321  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]);
322  } else {
323  fprintf (outfp, "<PDataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"appended\"/>\n", data->node_label[i], data->nn_dof[i]);
324  }
325  }
326  fprintf (outfp, "</PPointData>\n");
327  fprintf (outfp, "<PCellData>\n");
328  for(i=0; i<data->ne_component; i++){
329  if(
330  strcmp(data->elem_label[i], "ElementalPrincipalSTRAIN") == 0 ||
331  strcmp(data->elem_label[i], "ElementalPrincipalSTRESS") == 0
332  ) {
333  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]);
334  } else {
335  fprintf (outfp, "<PDataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"%d\" format=\"appended\"/>\n", data->elem_label[i], data->ne_dof[i]);
336  }
337  }
338  fprintf (outfp, "<PDataArray type=\"Int32\" Name=\"Mesh_Type\" NumberOfComponents=\"1\" format=\"appended\"/>\n");
339  fprintf (outfp, "</PCellData>\n");
340  for(i=0; i<petot; i++){
341  snprintf (buf, sizeof(buf), "./%s/%s.%d.vtu", outfile, outfile, i);
342  fprintf (outfp, "<Piece Source=\"%s\"/>\n", buf);
343  }
344  fprintf (outfp, "</PUnstructuredGrid>\n");
345  fprintf (outfp, "</VTKFile>\n");
346  fclose (outfp);
347  is_first = 1;
348  }
349 
350  /* outpu vtu file */
351  ioffset = 5 + data->nn_component + data->ne_component;
352  offset = HECMW_malloc(sizeof(int)*ioffset);
353 
354  uint64 = 0;
355  for(i=0; i<n_elem; i++){
356  jS=mesh->elem_node_index[i];
357  jE=mesh->elem_node_index[i+1];
358  shift=0;
359  if(mesh->elem_type[i]==641) shift=2;
360  if(mesh->elem_type[i]==761) shift=3;
361  if(mesh->elem_type[i]==781) shift=4;
362  uint64 += jE-shift-jS;
363  }
364 
365  offset[0] = 0;
366  offset[1] = offset[0] + sizeof(int) + 3*n_node *sizeof(float);
367  offset[2] = offset[1] + sizeof(int) + (int)uint64*sizeof(int);
368  offset[3] = offset[2] + sizeof(int) + n_elem *sizeof(int);
369  offset[4] = offset[3] + sizeof(int) + n_elem *sizeof(int);
370  for(i=0; i<data->nn_component; i++){
371  offset[5+i] = offset[4+i] + sizeof(int) + data->nn_dof[i]*n_node*sizeof(int);
372  }
373  for(i=0; i<data->ne_component; i++){
374  offset[5+data->nn_component+i] = offset[4+data->nn_component+i] + sizeof(int) + data->ne_dof[i]*n_elem*sizeof(int);
375  }
376 
377  outfp = fopen (file_vtu, "wb");
378  if (!outfp)
379  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output file");
380  fprintf (outfp, "<?xml version=\"1.0\"?>\n");
381  fprintf (outfp, "<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" byte_order=\"%s\" header_type=\"UInt32\">\n", HECMW_endian_str());
382  fprintf (outfp, "<UnstructuredGrid>\n");
383  fprintf (outfp, "<FieldData>\n");
384  for(i=0; i<data->ng_component; i++){
385  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfTuples=\"%d\" >\n",
386  strcmp(data->global_label[i], "TOTALTIME") == 0 ? "TimeValue" : data->global_label[i],
387  data->ng_dof[i]);
388  shift=0;
389  for(j=0; j<i; j++){
390  shift += data->ng_dof[j];
391  }
392  for(k=0; k<data->ng_dof[i]; k++){
393  fprintf (outfp, "%e ", (float)data->global_val_item[k+shift]);
394  }
395  fprintf (outfp, "\n");
396  fprintf (outfp, "</DataArray>\n");
397  }
398  fprintf (outfp, "</FieldData>\n");
399  fprintf (outfp, "<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n", n_node, n_elem);
400  fprintf (outfp, "<Points>\n");
401  fprintf (outfp, "<DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"appended\" offset=\"%d\">\n", offset[0]);
402  fprintf (outfp, "</DataArray>\n");
403  fprintf (outfp, "</Points>\n");
404  fprintf (outfp, "<Cells>\n");
405  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"appended\" offset=\"%d\">\n", offset[1]);
406  fprintf (outfp, "</DataArray>\n");
407  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"offsets\" format=\"appended\" offset=\"%d\">\n", offset[2]);
408  fprintf (outfp, "</DataArray>\n");
409  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"types\" format=\"appended\" offset=\"%d\">\n", offset[3]);
410  fprintf (outfp, "</DataArray>\n");
411  fprintf (outfp, "</Cells>\n");
412  fprintf (outfp, "<PointData>\n");
413 
414  for(i=0; i<data->nn_component; i++){
415  if (strcmp(data->node_label[i], "DISPLACEMENT") == 0 && data->nn_dof[i] == 2) {
416  // Convert 2D displacement to 3D
417  is_disp2d = 1;
418  fprintf (outfp, "<DataArray type=\"Float32\" Name=\"%s\" NumberOfComponents=\"3\" format=\"appended\" offset=\"%d\">\n", data->node_label[i], offset[4+i]);
419  } else {
420  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]);
421  }
422  fprintf (outfp, "</DataArray>\n");
423  }
424 
425  fprintf (outfp, "</PointData>\n");
426  fprintf (outfp, "<CellData>\n");
427  for(i=0; i<data->ne_component; i++){
428  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]);
429  fprintf (outfp, "</DataArray>\n");
430  }
431 
432  fprintf (outfp, "<DataArray type=\"Int32\" Name=\"Mesh_Type\" NumberOfComponents=\"1\" format=\"appended\" offset=\"%d\">\n", offset[ioffset-1]);
433  fprintf (outfp, "</DataArray>\n");
434  fprintf (outfp, "</CellData>\n");
435  fprintf (outfp, "</Piece>\n");
436  fprintf (outfp, "</UnstructuredGrid>\n");
437  fprintf (outfp, "<AppendedData encoding=\"raw\">\n");
438 
439  fprintf (outfp, " _");
440  uint32 = (uint32_t)(3*n_node*sizeof(float));
441  fwrite (&uint32, sizeof(uint32), 1, outfp);
442  for(i=0; i<n_node; i++){
443  val = (float)mesh->node[3*i];
444  fwrite (&val, sizeof(float), 1, outfp);
445  val = (float)mesh->node[3*i+1];
446  fwrite (&val, sizeof(float), 1, outfp);
447  val = (float)mesh->node[3*i+2];
448  fwrite (&val, sizeof(float), 1, outfp);
449  }
450 
451  uint32 = (uint32_t)(uint64*sizeof(int));
452  fwrite (&uint32, sizeof(uint32), 1, outfp);
453  for(i=0; i<n_elem; i++){
454  jS=mesh->elem_node_index[i];
455  jE=mesh->elem_node_index[i+1];
456  shift=0;
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  {
461  long long jj;
462  if(mesh->elem_type[i]==342){
463  for(jj=jS; jj<jE-shift; jj++){
464  in = (int)mesh->elem_node_item[jS+table342[jj-jS]]-1;
465  fwrite (&in, sizeof(int), 1, outfp);
466  }
467  }else{
468  for(jj=jS; jj<jE-shift; jj++){
469  in = (int)mesh->elem_node_item[jj]-1;
470  fwrite (&in, sizeof(int), 1, outfp);
471  }
472  }
473  }
474  }
475 
476  uint32 = (uint32_t)(n_elem*sizeof(int));
477  fwrite (&uint32, sizeof(uint32), 1, outfp);
478  shift=0;
479  for(i=0; i<n_elem; i++){
480  if(mesh->elem_type[i]==641) shift+=2;
481  if(mesh->elem_type[i]==761) shift+=3;
482  if(mesh->elem_type[i]==781) shift+=4;
483  in = (int)mesh->elem_node_index[i+1]-shift;
484  fwrite (&in, sizeof(int), 1, outfp);
485  }
486 
487  uint32 = (uint32_t)(n_elem*sizeof(int));
488  fwrite (&uint32, sizeof(uint32), 1, outfp);
489  for(i=0; i<n_elem; i++){
490  //uint8 = (uint8_t)HECMW_get_etype_vtk_shape(mesh->elem_type[i]);
491  //fwrite (&uint8, sizeof(u_int8_t), 1, outfp);
493  fwrite (&in, sizeof(int), 1, outfp);
494  }
495 
496  for(i=0; i<data->nn_component; i++){
497  uint32 = (uint32_t)(data->nn_dof[i]*n_node*sizeof(int));
498  fwrite (&uint32, sizeof(uint32), 1, outfp);
499 
500  shift=0;
501  for(j=0; j<i; j++){
502  shift += data->nn_dof[j];
503  }
504  for(j=0; j<n_node; j++){
505  if (is_disp2d) {
506  // Convert 2D displacement to 3D
507  val1 = (float)data->node_val_item[j*data_tot_n+shift];
508  val2 = (float)data->node_val_item[j*data_tot_n+shift+1];
509  val3 = 0.0;
510  fwrite (&val1, sizeof(float), 1, outfp);
511  fwrite (&val2, sizeof(float), 1, outfp);
512  fwrite (&val3, sizeof(float), 1, outfp);
513  } else {
514  for(k=0; k<data->nn_dof[i]; k++){
515  val = (float)data->node_val_item[j*data_tot_n+k+shift];
516  fwrite (&val, sizeof(float), 1, outfp);
517  }
518  }
519  }
520  }
521 
522  for(i=0; i<data->ne_component; i++){
523  uint32 = (uint32_t)(data->ne_dof[i]*n_elem*sizeof(int));
524  fwrite (&uint32, sizeof(uint32), 1, outfp);
525 
526  shift=0;
527  for(j=0; j<i; j++){
528  shift += data->ne_dof[j];
529  }
530  for(j=0; j<n_elem; j++){
531  for(k=0; k<data->ne_dof[i]; k++){
532  val = (float)data->elem_val_item[j*data_tot_e+k+shift];
533  fwrite (&val, sizeof(float), 1, outfp);
534  }
535  }
536  }
537 
538  uint32 = (uint32_t)(n_elem*sizeof(int));
539  fwrite (&uint32, sizeof(uint32), 1, outfp);
540  for(i=0; i<n_elem; i++){
541  //uint16 = (uint16_t)mesh->elem_type[i];
542  //fwrite (&uint16, sizeof(u_int16_t), 1, outfp);
543  in = (int)mesh->elem_type[i];
544  fwrite (&in, sizeof(int), 1, outfp);
545  }
546 
547  fprintf (outfp, "</AppendedData>\n");
548  fprintf (outfp, "</VTKFile>\n");
549  fclose (outfp);
550 }
551 
552 void HECMW_vtk_output (struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
553 {
554  vtk_output (mesh, data, outfile, outfile1, VIS_COMM);
555 }
556 
557 void HECMW_bin_vtk_output (struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, char *outfile1, HECMW_Comm VIS_COMM)
558 {
559  bin_vtk_output (mesh, data, outfile, outfile1, VIS_COMM);
560 }
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:99
CNFData data
long long * elem_node_index
Definition: hecmw_struct.h:195