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