FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_fstr_output_femap.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  *****************************************************************************/
5 
7 
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_endian.h"
17 #include "hecmw_vis_combine.h"
18 
19 static void count_data_components(struct hecmwST_result_data *data,
20  int *tn_component, int *te_component) {
21  int i;
22  *tn_component = 0;
23  for (i = 0; i < data->nn_component; i++) *tn_component += data->nn_dof[i];
24 
25  *te_component = 0;
26  for (i = 0; i < data->ne_component; i++) *te_component += data->ne_dof[i];
27 }
28 
29 static void femap_write_elem(FILE *outfp, int mynode, int n_elem, int n_node,
30  int *global_elem_ID, int *elem_ID, int *elem_type,
31  int *section_ID, long long *elem_node_index,
32  int *elem_node_item, int *global_node_ID,
33  int *sect_opt) {
34  int i, j, m;
35  int ielm, icol, isid, isop, istyp, ietyp, itopo;
36  int nna[10], nnb[10], nn[20];
37 
38  for (i = 0; i < n_elem; i++) {
39  if (elem_ID[i * 2 + 1] != mynode) continue;
40 
41  for (m = 0; m < 20; m++) {
42  nn[m] = 0;
43  }
44  for (m = 0; m < 10; m++) {
45  nna[m] = 0;
46  nnb[m] = 0;
47  }
48 
49  ielm = global_elem_ID[i];
50  icol = 124;
51  isid = section_ID[i];
52  isop = sect_opt[isid];
53  for (j = 0; j < elem_node_index[i + 1] - elem_node_index[i]; j++) {
54  nn[j] = global_node_ID[elem_node_item[elem_node_index[i] + j] - 1];
55  }
56  ietyp = elem_type[i];
57  if (ietyp == 231) {
58  istyp = 25;
59  if (isop == 1) istyp = 19;
60  if (isop == 2) istyp = 35;
61  itopo = 2;
62  nna[0] = nn[0];
63  nna[1] = nn[1];
64  nna[2] = nn[2];
65  } else if (ietyp == 731) {
66  istyp = 17;
67  itopo = 2;
68  nna[0] = nn[0];
69  nna[1] = nn[1];
70  nna[2] = nn[2];
71  } else if (ietyp == 232) {
72  istyp = 26;
73  if (isop == 1) istyp = 20;
74  if (isop == 2) istyp = 36;
75  itopo = 3;
76  nna[0] = nn[0];
77  nna[1] = nn[1];
78  nna[2] = nn[2];
79  nna[4] = nn[5];
80  nna[5] = nn[3];
81  nna[6] = nn[4];
82  } else if (ietyp == 732) {
83  istyp = 18;
84  itopo = 3;
85  nna[0] = nn[0];
86  nna[1] = nn[1];
87  nna[2] = nn[2];
88  nna[4] = nn[5];
89  nna[5] = nn[3];
90  nna[6] = nn[4];
91  } else if (ietyp == 241) {
92  istyp = 25;
93  if (isop == 1) istyp = 19;
94  if (isop == 2) istyp = 35;
95  itopo = 4;
96  nna[0] = nn[0];
97  nna[1] = nn[1];
98  nna[2] = nn[2];
99  nna[3] = nn[3];
100  } else if (ietyp == 741) {
101  istyp = 17;
102  itopo = 4;
103  nna[0] = nn[0];
104  nna[1] = nn[1];
105  nna[2] = nn[2];
106  nna[3] = nn[3];
107  } else if (ietyp == 242) {
108  istyp = 26;
109  if (isop == 1) istyp = 20;
110  if (isop == 2) istyp = 36;
111  itopo = 5;
112  for (m = 0; m < 8; m++) nna[m] = nn[m];
113  } else if (ietyp == 742) {
114  istyp = 18;
115  itopo = 5;
116  for (m = 0; m < 8; m++) nna[m] = nn[m];
117  } else if (ietyp == 743) {
118  istyp = 18;
119  itopo = 5;
120  for (m = 0; m < 8; m++) nna[m] = nn[m];
121  } else if (ietyp == 341 || ietyp == 3414) {
122  istyp = 25;
123  itopo = 6;
124  nna[0] = nn[0];
125  nna[1] = nn[1];
126  nna[2] = nn[2];
127  nna[4] = nn[3];
128  } else if (ietyp == 351) {
129  istyp = 25;
130  itopo = 7;
131  nna[0] = nn[0];
132  nna[1] = nn[1];
133  nna[2] = nn[2];
134  nna[4] = nn[3];
135  nna[5] = nn[4];
136  nna[6] = nn[5];
137  } else if (ietyp == 361) {
138  istyp = 25;
139  itopo = 8;
140  for (m = 0; m < 8; m++) nna[m] = nn[m];
141  } else if (ietyp == 342 || ietyp == 3422) {
142  istyp = 26;
143  itopo = 10;
144  nna[0] = nn[0];
145  nna[1] = nn[1];
146  nna[2] = nn[2];
147  nna[4] = nn[3];
148  nna[8] = nn[6];
149  nna[9] = nn[4];
150  nnb[0] = nn[5];
151  nnb[2] = nn[7];
152  nnb[3] = nn[8];
153  nnb[4] = nn[9];
154  } else if (ietyp == 352) {
155  istyp = 26;
156  itopo = 11;
157  nna[0] = nn[0];
158  nna[1] = nn[1];
159  nna[2] = nn[2];
160  nna[4] = nn[3];
161  nna[5] = nn[4];
162  nna[6] = nn[5];
163  nna[8] = nn[8];
164  nna[9] = nn[6];
165  nnb[0] = nn[7];
166  nnb[2] = nn[12];
167  nnb[3] = nn[13];
168  nnb[4] = nn[14];
169  nnb[6] = nn[11];
170  nnb[7] = nn[9];
171  nnb[8] = nn[10];
172  } else if (ietyp == 362) {
173  istyp = 26;
174  itopo = 12;
175  for (m = 0; m < 10; m++) nna[m] = nn[m];
176  nnb[0] = nn[10];
177  nnb[1] = nn[11];
178  nnb[2] = nn[16];
179  nnb[3] = nn[17];
180  nnb[4] = nn[18];
181  nnb[5] = nn[19];
182  nnb[6] = nn[12];
183  nnb[7] = nn[13];
184  nnb[8] = nn[14];
185  nnb[9] = nn[15];
186  }
187 
188  fprintf(outfp, "%8d,%8d,%8d,%8d,%8d,1,0,0,0,0,0,0,0,\n", ielm, icol, isid,
189  istyp, itopo);
190  for (m = 0; m < 10; m++) fprintf(outfp, "%8d,", nna[m]);
191  fprintf(outfp, "\n");
192  for (m = 0; m < 10; m++) fprintf(outfp, "%8d,", nnb[m]);
193  fprintf(outfp, "\n");
194  fprintf(outfp, "0,0,0,\n");
195  fprintf(outfp, "0,0,0,\n");
196  fprintf(outfp, "0,0,0,\n");
197  fprintf(outfp, "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n");
198  }
199 }
200 
202  struct hecmwST_result_data *data, char *outfile,
203  HECMW_Comm VIS_COMM) {
204  int i, j, k, m;
205  int mynode, pesize;
206  HECMW_Status stat;
207  double tmp;
208  int tmp_int, tn_component, tmp_int2, te_component;
209  double *tmp_recv_d, *tmp_send_d;
210  int *tmp_recv_i, *tmp_elem_ID, *tmp_elem_type, *tmp_elem_global_ID,
211  *tmp_elem_node_item, *tmp_section_ID,
212  *tmp_node_global_ID, *tmp_send_i;
213  long long *tmp_elem_node_index;
214  int disp_comp, stress_comp, disp_base, stress_base, name_len;
215  int temp_comp, temp_base;
216  FILE *outfp;
217 
218  HECMW_Comm_rank(VIS_COMM, &mynode);
219  HECMW_Comm_size(VIS_COMM, &pesize);
220 
221  /* open file */
222  if (mynode == 0) {
223  strcat(outfile, ".neu");
224  outfp = fopen(outfile, "w");
225 
226  if (!outfp)
227  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output file");
228 
229  put_neutral_head(outfp);
230  /* start writing material data */
231  put_neutral_601(outfp, mesh);
232  put_neutral_402(outfp, mesh);
233  }
234 
235  /* output nodes */
236  if (mynode != 0) {
237  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
238  if (mesh->nn_internal > 0) {
240  0, VIS_COMM);
242  VIS_COMM);
243  }
244  } else {
245  fprintf(outfp, " -1\n");
246  fprintf(outfp, " 403\n");
247 
248  for (i = 0; i < mesh->nn_internal; i++)
249  fprintf(outfp, "%8d,0,0,1,46,0,0,0,0,0,0,%15.7e,%15.7e,%15.7e\n",
250  mesh->global_node_ID[i], mesh->node[i * 3], mesh->node[i * 3 + 1],
251  mesh->node[i * 3 + 2]);
252 
253  for (i = 1; i < pesize; i++) {
254  HECMW_Recv(&tmp_int, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
255  if (tmp_int > 0) {
256  tmp_recv_i = (int *)HECMW_calloc(tmp_int, sizeof(int));
257  tmp_recv_d = (double *)HECMW_calloc(tmp_int * 3, sizeof(double));
258  if ((tmp_recv_i == NULL) || (tmp_recv_d == NULL))
259  HECMW_vis_memory_exit("tmp_recv");
260 
261  HECMW_Recv(tmp_recv_i, tmp_int, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM,
262  &stat);
263  HECMW_Recv(tmp_recv_d, tmp_int * 3, HECMW_DOUBLE, i, HECMW_ANY_TAG,
264  VIS_COMM, &stat);
265 
266  for (j = 0; j < tmp_int; j++)
267  fprintf(outfp, "%8d,0,0,1,46,0,0,0,0,0,0,%15.7e,%15.7e,%15.7e\n",
268  tmp_recv_i[j], tmp_recv_d[j * 3], tmp_recv_d[j * 3 + 1],
269  tmp_recv_d[j * 3 + 2]);
270 
271  HECMW_free(tmp_recv_i);
272  HECMW_free(tmp_recv_d);
273  }
274  }
275  fprintf(outfp, " -1\n");
276  }
277 
278  /* output element */
279  if (mynode != 0) {
280  HECMW_Send(&mesh->n_elem, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
281  if (mesh->n_elem > 0) {
282  HECMW_Send(&mesh->n_node, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
283 
285  VIS_COMM);
287  VIS_COMM);
289  VIS_COMM);
291  VIS_COMM);
293  0, VIS_COMM);
295  HECMW_INT, MASTER_PE, 0, VIS_COMM);
297  VIS_COMM);
298  }
299  } else {
300  fprintf(outfp, " -1\n");
301  fprintf(outfp, " 404\n");
302 
303  femap_write_elem(
304  outfp, mynode, mesh->n_elem, mesh->n_node, mesh->global_elem_ID,
307 
308  for (j = 1; j < pesize; j++) {
309  HECMW_Recv(&tmp_int, 1, HECMW_INT, j, HECMW_ANY_TAG, VIS_COMM, &stat);
310 
311  if (tmp_int > 0) {
312  HECMW_Recv(&tmp_int2, 1, HECMW_INT, j, HECMW_ANY_TAG, VIS_COMM, &stat);
313 
314  tmp_elem_global_ID = (int *)HECMW_calloc(tmp_int, sizeof(int));
315  tmp_elem_ID = (int *)HECMW_calloc(tmp_int * 2, sizeof(int));
316  tmp_elem_type = (int *)HECMW_calloc(tmp_int, sizeof(int));
317  tmp_section_ID = (int *)HECMW_calloc(tmp_int, sizeof(int));
318  tmp_elem_node_index = (long long *)HECMW_calloc(tmp_int + 1, sizeof(long long));
319  if ((tmp_elem_global_ID == NULL) || (tmp_elem_ID == NULL) ||
320  (tmp_elem_type == NULL) || (tmp_section_ID == NULL))
321  HECMW_vis_memory_exit("tmp recv");
322 
323  HECMW_Recv(tmp_elem_global_ID, tmp_int, HECMW_INT, j, HECMW_ANY_TAG,
324  VIS_COMM, &stat);
325  HECMW_Recv(tmp_elem_ID, tmp_int * 2, HECMW_INT, j, HECMW_ANY_TAG,
326  VIS_COMM, &stat);
327  HECMW_Recv(tmp_elem_type, tmp_int, HECMW_INT, j, HECMW_ANY_TAG,
328  VIS_COMM, &stat);
329  HECMW_Recv(tmp_section_ID, tmp_int, HECMW_INT, j, HECMW_ANY_TAG,
330  VIS_COMM, &stat);
331  HECMW_Recv(tmp_elem_node_index, tmp_int + 1, HECMW_LONG_LONG, j,
332  HECMW_ANY_TAG, VIS_COMM, &stat);
333 
334  tmp_elem_node_item =
335  (int *)HECMW_calloc(tmp_elem_node_index[tmp_int], sizeof(int));
336  tmp_node_global_ID = (int *)HECMW_calloc(tmp_int2, sizeof(int));
337 
338  HECMW_Recv(tmp_elem_node_item, tmp_elem_node_index[tmp_int], HECMW_INT,
339  j, HECMW_ANY_TAG, VIS_COMM, &stat);
340  HECMW_Recv(tmp_node_global_ID, tmp_int2, HECMW_INT, j, HECMW_ANY_TAG,
341  VIS_COMM, &stat);
342 
343  femap_write_elem(outfp, j, tmp_int, tmp_int2, tmp_elem_global_ID,
344  tmp_elem_ID, tmp_elem_type, tmp_section_ID,
345  tmp_elem_node_index, tmp_elem_node_item,
346  tmp_node_global_ID, mesh->section->sect_opt);
347 
348  HECMW_free(tmp_elem_global_ID);
349  HECMW_free(tmp_elem_ID);
350  HECMW_free(tmp_elem_type);
351  HECMW_free(tmp_section_ID);
352  HECMW_free(tmp_elem_node_index);
353  HECMW_free(tmp_elem_node_item);
354  HECMW_free(tmp_node_global_ID);
355  }
356  }
357  fprintf(outfp, " -1\n");
358  }
359 
360  /* output data */
361 
362  if (mynode == 0) {
363  put_neutral_middle(outfp);
364  }
365  count_data_components(data, &tn_component, &te_component);
366 
367  /* output node-based data */
368 
369  /* temperature */
370 
371  temp_comp = -1;
372  for (j = 0; j < data->nn_component; j++) {
373  name_len = strlen(data->node_label[j]);
374  if (strncmp("TEMPERATURE", data->node_label[j], name_len) == 0) {
375  temp_comp = j;
376  }
377  }
378  if (temp_comp >= 0) {
379  temp_base = 0;
380  for (i = 0; i < temp_comp; i++) temp_base += data->nn_dof[i];
381  if (mynode != 0) {
382  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
383  if (mesh->nn_internal > 0) {
385  MASTER_PE, 0, VIS_COMM);
386 
387  tmp_send_d = (double *)HECMW_calloc(mesh->nn_internal, sizeof(double));
388 
389  for (i = 0; i < mesh->nn_internal; i++)
390  tmp_send_d[i] = data->node_val_item[i * tn_component + temp_base];
391 
393  VIS_COMM);
394 
395  HECMW_free(tmp_send_d);
396  }
397  } else {
398  fprintf(outfp, " -1\n");
399  fprintf(outfp, " 451\n");
400  fprintf(outfp, "1,1,1,\n");
401  fprintf(outfp, "Temperature\n");
402  fprintf(outfp, "1.0, 0.0, 0.0\n");
403  fprintf(outfp, "0,0,0,0,0,0,0,0,0,0,\n");
404  fprintf(outfp, "0,0,0,0,0,0,0,0,0,0,\n");
405  fprintf(outfp, "0,0,6,7,\n");
406  fprintf(outfp, "0,0,1,\n");
407 
408  for (i = 0; i < mesh->nn_internal; i++) {
409  tmp = data->node_val_item[i * tn_component + temp_base];
410  fprintf(outfp, "%8d,%15.7e,\n", mesh->global_node_ID[i], tmp);
411  }
412  for (i = 1; i < pesize; i++) {
413  HECMW_Recv(&tmp_int, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
414  if (tmp_int > 0) {
415  tmp_recv_i = (int *)HECMW_calloc(tmp_int, sizeof(int));
416  tmp_recv_d = (double *)HECMW_calloc(tmp_int, sizeof(double));
417  if ((tmp_recv_i == NULL) || (tmp_recv_d == NULL))
418  HECMW_vis_memory_exit("tmp_recv");
419  HECMW_Recv(tmp_recv_i, tmp_int, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM,
420  &stat);
421  HECMW_Recv(tmp_recv_d, tmp_int, HECMW_DOUBLE, i, HECMW_ANY_TAG,
422  VIS_COMM, &stat);
423  for (j = 0; j < tmp_int; j++)
424  fprintf(outfp, "%8d,%15.7e,\n", tmp_recv_i[j], tmp_recv_d[j]);
425  HECMW_free(tmp_recv_i);
426  HECMW_free(tmp_recv_d);
427  }
428  }
429  fprintf(outfp, "-1,0.\n");
430  }
431  return;
432  }
433 
434  /* displacement and stress */
435 
436  disp_comp = 0;
437  for (j = 0; j < data->nn_component; j++) {
438  name_len = strlen(data->node_label[j]);
439  if (strncmp("DISPLACEMENT", data->node_label[j], name_len) == 0) {
440  disp_comp = j;
441  }
442  }
443  stress_comp = 0;
444  for (j = 0; j < data->nn_component; j++) {
445  name_len = strlen(data->node_label[j]);
446  if (strncmp("NodalSTRESS", data->node_label[j], name_len) == 0 ||
447  strncmp("NodalSTRESSplus", data->node_label[j], name_len) == 0) {
448  stress_comp = j;
449  }
450  }
451 
452  disp_base = 0;
453  stress_base = 0;
454  for (i = 0; i < disp_comp; i++) disp_base += data->nn_dof[i];
455  for (i = 0; i < stress_comp; i++) stress_base += data->nn_dof[i];
456  if (mynode != 0) {
457  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
458  if (mesh->nn_internal > 0) {
460  0, VIS_COMM);
461 
462  tmp_send_d = (double *)HECMW_calloc(mesh->nn_internal, sizeof(double));
463 
464  for (i = 0; i < mesh->nn_internal; i++) {
465  tmp_send_d[i] =
466  sqrt(data->node_val_item[i * tn_component + disp_base] *
467  data->node_val_item[i * tn_component + disp_base] +
468  data->node_val_item[i * tn_component + disp_base + 1] *
469  data->node_val_item[i * tn_component + disp_base + 1] +
470  data->node_val_item[i * tn_component + disp_base + 2] *
471  data->node_val_item[i * tn_component + disp_base + 2]);
472  }
473 
475  VIS_COMM);
476  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
478  0, VIS_COMM);
479 
480  for (i = 0; i < mesh->nn_internal; i++)
481  tmp_send_d[i] = data->node_val_item[i * tn_component + disp_base];
482 
484  VIS_COMM);
485  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
487  0, VIS_COMM);
488 
489  for (i = 0; i < mesh->nn_internal; i++)
490  tmp_send_d[i] = data->node_val_item[i * tn_component + disp_base + 1];
491 
493  VIS_COMM);
494  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
496  0, VIS_COMM);
497 
498  for (i = 0; i < mesh->nn_internal; i++)
499  tmp_send_d[i] = data->node_val_item[i * tn_component + disp_base + 2];
500 
502  VIS_COMM);
503 
504  if (mesh->n_dof != 6) {
505  for (j = 0; j < 7; j++) {
506  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
508  MASTER_PE, 0, VIS_COMM);
509  for (i = 0; i < mesh->nn_internal; i++)
510  tmp_send_d[i] =
511  data->node_val_item[i * tn_component + stress_base + j];
513  VIS_COMM);
514  }
515  } else {
516  for (j = 0; j < 14; j++) {
517  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
519  MASTER_PE, 0, VIS_COMM);
520  for (i = 0; i < mesh->nn_internal; i++)
521  tmp_send_d[i] =
522  data->node_val_item[i * tn_component + stress_base + j];
524  VIS_COMM);
525  }
526  }
527  HECMW_free(tmp_send_d);
528  }
529  } else {
530  fprintf(outfp, " -1\n");
531  fprintf(outfp, " 451\n");
532  for (k = 0; k < 4; k++) {
533  fprintf(outfp, "1,%1d,1,\n", k + 1);
534  if (k == 0)
535  fprintf(outfp, "Total Translation\n");
536  else
537  fprintf(outfp, "T%1d Translation\n", k);
538  fprintf(outfp, "1.0, 0.0, 0.0\n");
539  if (k == 0)
540  fprintf(outfp, "2,3,4,0,0,0,0,0,0,0,\n");
541  else if (k == 1)
542  fprintf(outfp, "2,0,0,0,0,0,0,0,0,0,\n");
543  else if (k == 2)
544  fprintf(outfp, "0,3,0,0,0,0,0,0,0,0,\n");
545  else if (k == 3)
546  fprintf(outfp, "0,0,4,0,0,0,0,0,0,0,\n");
547  fprintf(outfp, "0,0,0,0,0,0,0,0,0,0,\n");
548  fprintf(outfp, "0,0,1,7,\n");
549  if (k == 0)
550  fprintf(outfp, "1,1,1,\n");
551  else
552  fprintf(outfp, "0,1,1,\n");
553 
554  for (i = 0; i < mesh->nn_internal; i++) {
555  if (k == 0)
556  tmp = sqrt(data->node_val_item[i * tn_component + disp_base] *
557  data->node_val_item[i * tn_component + disp_base] +
558  data->node_val_item[i * tn_component + disp_base + 1] *
559  data->node_val_item[i * tn_component + disp_base + 1] +
560  data->node_val_item[i * tn_component + disp_base + 2] *
561  data->node_val_item[i * tn_component + disp_base + 2]);
562  else
563  tmp = data->node_val_item[i * tn_component + disp_base + k - 1];
564  fprintf(outfp, "%8d,%15.7e,\n", mesh->global_node_ID[i], tmp);
565  }
566  for (i = 1; i < pesize; i++) {
567  HECMW_Recv(&tmp_int, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
568  if (tmp_int > 0) {
569  tmp_recv_i = (int *)HECMW_calloc(tmp_int, sizeof(int));
570  tmp_recv_d = (double *)HECMW_calloc(tmp_int, sizeof(double));
571  if ((tmp_recv_i == NULL) || (tmp_recv_d == NULL))
572  HECMW_vis_memory_exit("tmp_recv");
573  HECMW_Recv(tmp_recv_i, tmp_int, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM,
574  &stat);
575  HECMW_Recv(tmp_recv_d, tmp_int, HECMW_DOUBLE, i, HECMW_ANY_TAG,
576  VIS_COMM, &stat);
577  for (j = 0; j < tmp_int; j++)
578  fprintf(outfp, "%8d,%15.7e,\n", tmp_recv_i[j], tmp_recv_d[j]);
579  HECMW_free(tmp_recv_i);
580  HECMW_free(tmp_recv_d);
581  }
582  }
583  fprintf(outfp, "-1,0.\n");
584  }
585  if (mesh->n_dof != 6) {
586  char *nodal_stress_titles_solid[] = {
587  "Solid X Normal Stress", "Solid Y Normal Stress",
588  "Solid Z Normal Stress", "Solid XY Shear Stress",
589  "Solid YZ Shear Stress", "Solid XZ Shear Stress",
590  "Solid Von Mises Stress"};
591  for (k = 0; k < 7; k++) {
592  fprintf(outfp, "1,6001%1d,1,\n", k + 1);
593  fprintf(outfp, "%s\n", nodal_stress_titles_solid[k]);
594  fprintf(outfp, "1.0, 0.0, 0.0\n");
595  fprintf(outfp, "0,0,0,0,0,0,0,0,0,0,\n");
596  fprintf(outfp, "0,0,0,0,0,0,0,0,0,0,\n");
597  fprintf(outfp, "0,0,4,7,\n");
598  fprintf(outfp, "0,0,1,\n");
599 
600  for (i = 0; i < mesh->nn_internal; i++) {
601  tmp = data->node_val_item[i * tn_component + stress_base + k];
602  fprintf(outfp, "%8d,%15.7e,\n", mesh->global_node_ID[i], tmp);
603  }
604  for (i = 1; i < pesize; i++) {
605  HECMW_Recv(&tmp_int, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
606  if (tmp_int > 0) {
607  tmp_recv_i = (int *)HECMW_calloc(tmp_int, sizeof(int));
608  tmp_recv_d = (double *)HECMW_calloc(tmp_int, sizeof(double));
609  if ((tmp_recv_i == NULL) || (tmp_recv_d == NULL))
610  HECMW_vis_memory_exit("tmp_recv");
611  HECMW_Recv(tmp_recv_i, tmp_int, HECMW_INT, i, HECMW_ANY_TAG,
612  VIS_COMM, &stat);
613  HECMW_Recv(tmp_recv_d, tmp_int, HECMW_DOUBLE, i, HECMW_ANY_TAG,
614  VIS_COMM, &stat);
615  for (j = 0; j < tmp_int; j++)
616  fprintf(outfp, "%8d,%15.7e,\n", tmp_recv_i[j], tmp_recv_d[j]);
617  HECMW_free(tmp_recv_i);
618  HECMW_free(tmp_recv_d);
619  }
620  }
621  fprintf(outfp, "-1,0.\n");
622  }
623  } else if (mesh->n_dof == 6) {
624  char *nodal_stress_ids_shell[] = {
625  "1,70011,1,", "1,70012,1,", "1,70013,1,", "1,70014,1,", "1,70015,1,",
626  "1,70016,1,", "1,71011,1,", "1,71012,1,", "1,71013,1,", "1,71014,1,",
627  "1,71015,1,", "1,71016,1,", "1,70017,1,", "1,71017,1,"};
628  char *nodal_stress_titles_shell[] = {
629  "Plate Top X Normal Stress", "Plate Top Y Normal Stress",
630  "Plate Top Z Normal Stress", "Plate Top XY Shear Stress",
631  "Plate Top YZ Shear Stress", "Plate Top XZ Shear Stress",
632  "Plate Bot X Normal Stress", "Plate Bot Y Normal Stress",
633  "Plate Bot Z Normal Stress", "Plate Bot XY Shear Stress",
634  "Plate Bot YZ Shear Stress", "Plate Bot XZ Shear Stress",
635  "Plate Top Von Mises Stress", "Plate Bot Von Mises Stress"};
636  for (k = 0; k < 14; k++) {
637  fprintf(outfp, "%s\n", nodal_stress_ids_shell[k]);
638  fprintf(outfp, "%s\n", nodal_stress_titles_shell[k]);
639  fprintf(outfp, "1.0, 0.0, 0.0\n");
640  fprintf(outfp, "0,0,0,0,0,0,0,0,0,0,\n");
641  fprintf(outfp, "0,0,0,0,0,0,0,0,0,0,\n");
642  fprintf(outfp, "0,0,4,7,\n");
643  fprintf(outfp, "0,0,1,\n");
644 
645  for (i = 0; i < mesh->nn_internal; i++) {
646  tmp = data->node_val_item[i * tn_component + stress_base + k];
647  fprintf(outfp, "%8i,%15.7e,\n", mesh->global_node_ID[i], tmp);
648  }
649  for (i = 1; i < pesize; i++) {
650  HECMW_Recv(&tmp_int, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
651  if (tmp_int > 0) {
652  tmp_recv_i = (int *)HECMW_calloc(tmp_int, sizeof(int));
653  tmp_recv_d = (double *)HECMW_calloc(tmp_int, sizeof(double));
654  if ((tmp_recv_i == NULL) || (tmp_recv_d == NULL))
655  HECMW_vis_memory_exit("tmp_recv");
656 
657  HECMW_Recv(tmp_recv_i, tmp_int, HECMW_INT, i, HECMW_ANY_TAG,
658  VIS_COMM, &stat);
659  HECMW_Recv(tmp_recv_d, tmp_int, HECMW_DOUBLE, i, HECMW_ANY_TAG,
660  VIS_COMM, &stat);
661 
662  for (j = 0; j < tmp_int; j++)
663  fprintf(outfp, "%8d,%15.7e,\n", tmp_recv_i[j], tmp_recv_d[j]);
664 
665  HECMW_free(tmp_recv_i);
666  HECMW_free(tmp_recv_d);
667  }
668  }
669  fprintf(outfp, "-1,0.\n");
670  }
671  }
672  }
673 
674  /* starting output element-based data */
675 
676  if (data->ne_component > 0) {
677  stress_comp = 0;
678  for (j = 0; j < data->ne_component; j++) {
679  name_len = strlen(data->elem_label[j]);
680  if (strncmp("ElementalSTRESS", data->elem_label[j], name_len) == 0) {
681  stress_comp = j;
682  }
683  }
684 
685  stress_base = 0;
686  for (i = 0; i < stress_comp; i++) stress_base += data->ne_dof[i];
687 
688  if (mynode != 0) {
689  tmp_send_i = (int *)HECMW_calloc(mesh->nn_internal, sizeof(int));
690  tmp_send_d = (double *)HECMW_calloc(mesh->ne_internal, sizeof(double));
691 
692  for (j = 0; j < 7; j++) {
693  HECMW_Send(&mesh->ne_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
694 
695  for (i = 0; i < mesh->ne_internal; i++) {
696  tmp_int = mesh->elem_internal_list[i];
697  tmp_send_i[i] = mesh->global_elem_ID[tmp_int];
698  tmp_send_d[i] =
699  data->elem_val_item[tmp_int * te_component + stress_base + j];
700  }
701 
702  HECMW_Send(tmp_send_i, mesh->ne_internal, HECMW_INT, MASTER_PE, 0,
703  VIS_COMM);
705  VIS_COMM);
706  }
707 
708  } else {
709  char *elem_stress_titles_solid[] = {
710  "Solid X Normal Stress", "Solid Y Normal Stress",
711  "Solid Z Normal Stress", "Solid XY Shear Stress",
712  "Solid YZ Shear Stress", "Solid XZ Shear Stress",
713  "Solid Von Mises Stress"};
714 
715  for (k = 0; k < 7; k++) {
716  fprintf(outfp, "1,7001%1d,1,\n", k + 1);
717  fprintf(outfp, "%s\n", elem_stress_titles_solid[k]);
718  fprintf(outfp, "1.0, 0.0, 0.0\n");
719  fprintf(outfp, "0,0,0,0,0,0,0,0,0,0,\n");
720  fprintf(outfp, "0,0,0,0,0,0,0,0,0,0,\n");
721  fprintf(outfp, "0,0,4,8,\n");
722  fprintf(outfp, "0,0,1,\n");
723 
724  for (i = 0; i < mesh->ne_internal; i++) {
725  tmp_int = mesh->elem_internal_list[i];
726  tmp = data->elem_val_item[tmp_int * te_component + stress_base + k];
727  fprintf(outfp, "%8d,%15.7e,\n", mesh->global_elem_ID[tmp_int], tmp);
728  }
729  for (i = 1; i < pesize; i++) {
730  HECMW_Recv(&tmp_int, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
731  if (tmp_int > 0) {
732  tmp_recv_i = (int *)HECMW_calloc(tmp_int, sizeof(int));
733  tmp_recv_d = (double *)HECMW_calloc(tmp_int, sizeof(double));
734  if ((tmp_recv_i == NULL) || (tmp_recv_d == NULL))
735  HECMW_vis_memory_exit("tmp_recv");
736 
737  HECMW_Recv(tmp_recv_i, tmp_int, HECMW_INT, i, HECMW_ANY_TAG,
738  VIS_COMM, &stat);
739  HECMW_Recv(tmp_recv_d, tmp_int, HECMW_DOUBLE, i, HECMW_ANY_TAG,
740  VIS_COMM, &stat);
741 
742  for (j = 0; j < tmp_int; j++)
743  fprintf(outfp, "%8d,%15.7e,\n", tmp_recv_i[j], tmp_recv_d[j]);
744 
745  HECMW_free(tmp_recv_i);
746  HECMW_free(tmp_recv_d);
747  }
748  }
749  fprintf(outfp, "-1,0.\n");
750  }
751  }
752 
753  } /* end of if ne>0) */
754 
755  if (mynode == 0) {
756  fprintf(outfp, " -1\n");
757  fprintf(outfp, " -1\n");
758 
759  fclose(outfp);
760  }
761 
762  return;
763 }
764 
765 static void avs_write_header(FILE *outfp, int total_n_node, int total_n_elem,
766  int tn_component, int te_component,
767  int flag_oldUCD) {
768  if (flag_oldUCD) {
769  fprintf(outfp, "%d %d %d %d 0\n", total_n_node, total_n_elem, tn_component,
770  te_component);
771  } else {
772  fprintf(outfp, "1\n");
773  fprintf(outfp, "data\n");
774  fprintf(outfp, "step1\n");
775  fprintf(outfp, "%d %d\n", total_n_node, total_n_elem);
776  }
777 }
778 
779 static void avs_write_node_coord(FILE *outfp, int n_node, int *global_node_ID,
780  double *node, int flag_global_ID,
781  int nid_offset) {
782  int i;
783 
784  HECMW_assert(!flag_global_ID || global_node_ID);
785 
786  for (i = 0; i < n_node; i++) {
787  fprintf(outfp, "%8d %15.7e %15.7e %15.7e\n",
788  flag_global_ID ? global_node_ID[i] : i + 1 + nid_offset,
789  node[i * 3], node[i * 3 + 1], node[i * 3 + 2]);
790  }
791 }
792 
793 static const int *avs_elem_node_order(int elem_type) {
794  static const int i232[] = {0, 1, 2, 5, 3, 4};
795  static const int i342[] = {0, 1, 3, 2, 6, 7, 5, 8, 9, 4};
796  static const int i352[] = {0, 2, 1, 3, 5, 4, 7, 6, 8, 10, 9, 11, 12, 14, 13};
797  static const int i362[] = {0, 3, 2, 1, 4, 7, 6, 5, 11, 10,
798  9, 8, 15, 14, 13, 12, 16, 19, 18, 17};
799  static const int idefault[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
800  10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
801  const int *ii;
802 
803  if (elem_type == 232 || elem_type == 732)
804  ii = i232;
805  else if (elem_type == 341 || elem_type == 342 || elem_type == 3414)
806  ii = i342;
807  else if (elem_type == 351 || elem_type == 352)
808  ii = i352;
809  else if (elem_type == 361 || elem_type == 362)
810  ii = i362;
811  else
812  ii = idefault;
813 
814  return ii;
815 }
816 
817 static void avs_write_elem_conn(FILE *outfp, int mynode, int n_elem,
818  int *elem_ID, int *elem_type,
819  long long *elem_node_index, int *elem_node_item,
820  int *global_elem_ID, int *global_node_ID,
821  int *node_ID, int flag_global_ID,
822  int flag_skip_external, int flag_oldUCD,
823  int *nid_offsets, int eid_offset) {
824  int eid = 0;
825  int i, j, etype, node_num;
826  int nn[20];
827  const int *ii;
828 
829  HECMW_assert((flag_global_ID && global_elem_ID && global_node_ID) ||
830  (!flag_global_ID && (!nid_offsets || node_ID)));
831 
832  for (i = 0; i < n_elem; i++) {
833  if (flag_skip_external && elem_ID[i * 2 + 1] != mynode) continue;
834 
835  eid++;
836 
837  etype = elem_type[i];
838  if (flag_oldUCD && etype % 2 == 0) {
839  /* old UCD format does not support second order elements */
840  if (etype != 3414 && etype != 3614) {
841  etype--;
842  }
843  }
844  node_num = HECMW_get_max_node(etype);
845  if (HECMW_is_etype_33struct(etype)) node_num /= 2;
846 
847  for (j = 0; j < node_num; j++) {
848  int nid = elem_node_item[elem_node_index[i] + j] - 1;
849  if (flag_global_ID) {
850  nn[j] = global_node_ID[nid];
851  } else if (nid_offsets != NULL) {
852  int rank = node_ID[nid * 2 + 1];
853  int nid_in_rank = node_ID[nid * 2];
854  nn[j] = nid_offsets[rank] + nid_in_rank;
855  } else {
856  nn[j] = nid + 1;
857  }
858  }
859 
860  fprintf(outfp, "%8d %d %s ",
861  flag_global_ID ? global_elem_ID[i] : eid + eid_offset,
863 
864  ii = avs_elem_node_order(etype);
865  for (j = 0; j < node_num; j++) fprintf(outfp, "%8d ", nn[ii[j]]);
866  fprintf(outfp, "\n");
867  }
868 }
869 
870 static void avs_write_data_header(FILE *outfp, int tn_component,
871  int te_component, int flag_oldUCD) {
872  if (flag_oldUCD) return;
873  fprintf(outfp, "%8d %8d\n", tn_component, te_component);
874 }
875 
876 static void avs_write_node_data_header(FILE *outfp, int tn_component,
877  struct hecmwST_result_data *data,
878  int flag_Scalar) {
879  int j, ii;
880 
881  if (flag_Scalar) {
882  fprintf(outfp, "%8d", tn_component);
883  for (j = 0; j < tn_component; j++) fprintf(outfp, " 1");
884  fprintf(outfp, "\n");
885  for (j = 0; j < data->nn_component; j++) {
886  for (ii = 0; ii < data->nn_dof[j]; ii++)
887  fprintf(outfp, "%s_%d, unit_unknown\n", data->node_label[j], ii + 1);
888  }
889  } else {
890  fprintf(outfp, "%8d", data->nn_component);
891  for (j = 0; j < data->nn_component; j++)
892  fprintf(outfp, " %d", data->nn_dof[j]);
893  fprintf(outfp, "\n");
894  for (j = 0; j < data->nn_component; j++)
895  fprintf(outfp, "%s, unit_unknown\n", data->node_label[j]);
896  }
897 }
898 
899 static void avs_write_node_data(FILE *outfp, int n_node, int *global_node_ID,
900  int tn_component, double *node_val_item,
901  int flag_global_ID, int nid_offset) {
902  int i, k;
903 
904  HECMW_assert(!flag_global_ID || global_node_ID);
905 
906  for (i = 0; i < n_node; i++) {
907  fprintf(outfp, "%8d ",
908  flag_global_ID ? global_node_ID[i] : i + 1 + nid_offset);
909  for (k = 0; k < tn_component; k++)
910  fprintf(outfp, "%15.7e ", node_val_item[i * tn_component + k]);
911  fprintf(outfp, "\n");
912  }
913 }
914 
916  int i, j, n, refine, max_elem;
917  int *size;
918 
919  max_elem = 0;
920  refine = mesh->n_refine;
921  if (refine <= 0) return 0;
922 
923  size = mesh->n_node_refine_hist;
924 
925  for (n = 0; n < refine; n++) {
926  int nn = *size;
927  for (i = 0; i < nn; i++) {
928  if (max_elem < mesh->node_ID[2 * i]) {
929  max_elem = mesh->node_ID[2 * i];
930  }
931  }
932 
933  for (i = 0; i < nn; i++) {
934  if (mesh->node_ID[2 * i] < 0) {
935  mesh->node_ID[2 * i] = max_elem - mesh->node_ID[2 * i];
936  }
937  }
938  size++;
939  }
940 
941  return 0;
942 }
943 
944 
945 static void
946 avs_write_elem_data_header(FILE *outfp, int te_component, struct hecmwST_result_data *data,
947  int flag_Scalar) {
948  int j, ii;
949 
950  if (flag_Scalar) {
951  fprintf (outfp, "%8d", te_component);
952  for (j = 0; j < te_component; j++)
953  fprintf (outfp, " 1");
954  fprintf (outfp, "\n");
955  for (j = 0; j < data->ne_component; j++) {
956  for (ii = 0; ii < data->ne_dof[j]; ii++)
957  fprintf (outfp, "%s_%d, unit_unknown\n", data->elem_label[j], ii + 1);
958  }
959  } else {
960  fprintf (outfp, "%8d", data->ne_component);
961  for (j = 0; j < data->ne_component; j++)
962  fprintf (outfp, " %d", data->ne_dof[j]);
963  fprintf (outfp, "\n");
964  for (j = 0; j < data->ne_component; j++)
965  fprintf (outfp, "%s, unit_unknown\n", data->elem_label[j]);
966  }
967 }
968 
969 static void
970 avs_write_elem_data(FILE *outfp, int mynode,
971  int n_elem, int *elem_ID, int *global_elem_ID, int te_component, double *elem_val_item,
972  int flag_global_ID, int eid_offset) {
973  int i, in, k;
974  HECMW_assert(!flag_global_ID || global_elem_ID);
975 
976  in = 0;
977  for (i = 0; i < n_elem; i++) {
978  if (elem_ID[i * 2 + 1] != mynode)
979  continue;
980 
981  fprintf (outfp, "%8d ", flag_global_ID ? global_elem_ID[i] : in+1 + eid_offset);
982  for (k = 0; k < te_component; k++)
983  fprintf (outfp, "%15.7e ",
984  elem_val_item[i * te_component + k]);
985  fprintf (outfp, "\n");
986  in++;
987  }
988 }
989 
990 static void avs_output(struct hecmwST_local_mesh *mesh,
991  struct hecmwST_result_data *data, char *outfile,
992  HECMW_Comm VIS_COMM, int flag_oldUCD, int flag_global_ID,
993  int flag_Scalar) {
994  int mynode, pesize;
995  int total_n_node, total_n_elem;
996  int tn_component, te_component;
997  int *nid_offsets, *eid_offsets;
998  FILE *outfp;
999  HECMW_Status stat;
1000 
1001  int flag_skip_ext = 1;
1002 
1003  HECMW_Comm_rank(VIS_COMM, &mynode);
1004  HECMW_Comm_size(VIS_COMM, &pesize);
1005 
1006  /* count total number of node/elem */
1007  if (pesize > 1) {
1008  HECMW_Allreduce(&mesh->nn_internal, &total_n_node, 1, HECMW_INT, HECMW_SUM,
1009  VIS_COMM);
1010  HECMW_Allreduce(&mesh->ne_internal, &total_n_elem, 1, HECMW_INT, HECMW_SUM,
1011  VIS_COMM);
1012  } else {
1013  total_n_node = mesh->nn_internal;
1014  total_n_elem = mesh->n_elem;
1015  }
1016 
1017  /* count total number of data components */
1018  count_data_components(data, &tn_component, &te_component);
1019 
1020  if (mynode == 0) {
1021  /* allocate offset arrays */
1022  nid_offsets = (int *)HECMW_calloc(pesize + 1, sizeof(int));
1023  if (nid_offsets == NULL) HECMW_vis_memory_exit("nid_offset");
1024  eid_offsets = (int *)HECMW_calloc(pesize + 1, sizeof(int));
1025  if (eid_offsets == NULL) HECMW_vis_memory_exit("eid_offset");
1026 
1027  /* open file */
1028  outfp = fopen(outfile, "w");
1029  if (!outfp)
1030  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output file");
1031 
1032  /* write header */
1033  avs_write_header(outfp, total_n_node, total_n_elem, tn_component, te_component,
1034  flag_oldUCD);
1035  }
1036 
1037  /* write node coordinate */
1038  if (mynode != 0) {
1039  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1040  if (mesh->nn_internal > 0) {
1041  if (flag_global_ID)
1043  MASTER_PE, 0, VIS_COMM);
1045  VIS_COMM);
1046  }
1047  } else {
1048  int i;
1049 
1050  avs_write_node_coord(outfp, mesh->nn_internal, mesh->global_node_ID,
1051  mesh->node, flag_global_ID, 0);
1052 
1053  nid_offsets[0] = 0;
1054  nid_offsets[1] = mesh->nn_internal;
1055 
1056  for (i = 1; i < pesize; i++) {
1057  int tmp_nn_internal;
1058 
1059  HECMW_Recv(&tmp_nn_internal, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM,
1060  &stat);
1061  nid_offsets[i + 1] = nid_offsets[i] + tmp_nn_internal;
1062 
1063  if (tmp_nn_internal > 0) {
1064  int *tmp_global_node_ID = NULL;
1065  double *tmp_node;
1066 
1067  if (flag_global_ID) {
1068  tmp_global_node_ID =
1069  (int *)HECMW_calloc(tmp_nn_internal, sizeof(int));
1070  if (tmp_global_node_ID == NULL)
1071  HECMW_vis_memory_exit("tmp recv: global_node_ID");
1072 
1073  HECMW_Recv(tmp_global_node_ID, tmp_nn_internal, HECMW_INT, i,
1074  HECMW_ANY_TAG, VIS_COMM, &stat);
1075  }
1076 
1077  tmp_node = (double *)HECMW_calloc(tmp_nn_internal * 3, sizeof(double));
1078  if (tmp_node == NULL) HECMW_vis_memory_exit("tmp recv: node");
1079 
1080  HECMW_Recv(tmp_node, tmp_nn_internal * 3, HECMW_DOUBLE, i,
1081  HECMW_ANY_TAG, VIS_COMM, &stat);
1082 
1083  avs_write_node_coord(outfp, tmp_nn_internal, tmp_global_node_ID,
1084  tmp_node, flag_global_ID, nid_offsets[i]);
1085 
1086  if (flag_global_ID) HECMW_free(tmp_global_node_ID);
1087  HECMW_free(tmp_node);
1088  }
1089  }
1090  }
1091 
1092  /* modify element information due to refininer */
1093  if (mynode == 0) {
1094  if (modify_element_information(mesh) != 0) {
1095  printf("###ERROR: modify element information due to refininer \n");
1096  }
1097  }
1098 
1099  /* write element connectivity */
1100  if (mynode != 0) {
1101  HECMW_Send(&mesh->n_elem, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1102  HECMW_Send(&mesh->ne_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1103 
1104  if (mesh->n_elem > 0) {
1105  HECMW_Send(&mesh->n_node, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1106 
1108  VIS_COMM);
1110  VIS_COMM);
1112  0, VIS_COMM);
1114  HECMW_INT, MASTER_PE, 0, VIS_COMM);
1115 
1116  if (flag_global_ID) {
1118  VIS_COMM);
1120  VIS_COMM);
1121  } else {
1123  VIS_COMM);
1124  }
1125  }
1126  } else {
1127  int j;
1128 
1129  avs_write_elem_conn(outfp, mynode, mesh->n_elem, mesh->elem_ID,
1132  mesh->global_node_ID, mesh->node_ID, flag_global_ID,
1133  flag_skip_ext, flag_oldUCD, nid_offsets, 0);
1134 
1135  eid_offsets[0] = 0;
1136  eid_offsets[1] = mesh->ne_internal;
1137 
1138  for (j = 1; j < pesize; j++) {
1139  int tmp_n_elem;
1140  int tmp_ne_internal;
1141 
1142  HECMW_Recv(&tmp_n_elem, 1, HECMW_INT, j, HECMW_ANY_TAG, VIS_COMM, &stat);
1143  HECMW_Recv(&tmp_ne_internal, 1, HECMW_INT, j, HECMW_ANY_TAG, VIS_COMM,
1144  &stat);
1145  eid_offsets[j + 1] = eid_offsets[j] + tmp_ne_internal;
1146 
1147  if (tmp_n_elem > 0) {
1148  int tmp_n_node;
1149  int *tmp_elem_ID;
1150  int *tmp_elem_type;
1151  long long *tmp_elem_node_index;
1152  int *tmp_elem_node_item;
1153  int *tmp_global_elem_ID;
1154  int *tmp_global_node_ID;
1155  int *tmp_node_ID;
1156 
1157  HECMW_Recv(&tmp_n_node, 1, HECMW_INT, j, HECMW_ANY_TAG, VIS_COMM,
1158  &stat);
1159 
1160  tmp_elem_ID = (int *)HECMW_calloc(tmp_n_elem * 2, sizeof(int));
1161  tmp_elem_type = (int *)HECMW_calloc(tmp_n_elem, sizeof(int));
1162  tmp_elem_node_index = (long long *)HECMW_calloc(tmp_n_elem + 1, sizeof(long long));
1163  if ((tmp_elem_ID == NULL) || (tmp_elem_type == NULL) ||
1164  (tmp_elem_node_index == NULL))
1166  "tmp recv: elem_ID, elem_type, elem_node_index");
1167 
1168  HECMW_Recv(tmp_elem_ID, tmp_n_elem * 2, HECMW_INT, j, HECMW_ANY_TAG,
1169  VIS_COMM, &stat);
1170  HECMW_Recv(tmp_elem_type, tmp_n_elem, HECMW_INT, j, HECMW_ANY_TAG,
1171  VIS_COMM, &stat);
1172  HECMW_Recv(tmp_elem_node_index, tmp_n_elem + 1, HECMW_LONG_LONG, j,
1173  HECMW_ANY_TAG, VIS_COMM, &stat);
1174 
1175  tmp_elem_node_item =
1176  (int *)HECMW_calloc(tmp_elem_node_index[tmp_n_elem], sizeof(int));
1177  if (tmp_elem_node_item == NULL)
1178  HECMW_vis_memory_exit("tmp recv: elem_node_item");
1179 
1180  HECMW_Recv(tmp_elem_node_item, tmp_elem_node_index[tmp_n_elem],
1181  HECMW_INT, j, HECMW_ANY_TAG, VIS_COMM, &stat);
1182 
1183  if (flag_global_ID) {
1184  tmp_global_elem_ID = (int *)HECMW_calloc(tmp_n_elem, sizeof(int));
1185  tmp_global_node_ID = (int *)HECMW_calloc(tmp_n_node, sizeof(int));
1186  if ((tmp_global_elem_ID == NULL) || (tmp_global_node_ID == NULL))
1187  HECMW_vis_memory_exit("tmp recv: global_elem_ID, global_node_ID");
1188 
1189  HECMW_Recv(tmp_global_elem_ID, tmp_n_elem, HECMW_INT, j,
1190  HECMW_ANY_TAG, VIS_COMM, &stat);
1191  HECMW_Recv(tmp_global_node_ID, tmp_n_node, HECMW_INT, j,
1192  HECMW_ANY_TAG, VIS_COMM, &stat);
1193 
1194  tmp_node_ID = NULL;
1195  } else {
1196  tmp_global_elem_ID = NULL;
1197  tmp_global_node_ID = NULL;
1198 
1199  tmp_node_ID = (int *)HECMW_calloc(tmp_n_node * 2, sizeof(int));
1200  if (tmp_node_ID == NULL) HECMW_vis_memory_exit("tmp recv: node_ID");
1201 
1202  HECMW_Recv(tmp_node_ID, tmp_n_node * 2, HECMW_INT, j, HECMW_ANY_TAG,
1203  VIS_COMM, &stat);
1204  }
1205 
1206  avs_write_elem_conn(outfp, j, tmp_n_elem, tmp_elem_ID, tmp_elem_type,
1207  tmp_elem_node_index, tmp_elem_node_item,
1208  tmp_global_elem_ID, tmp_global_node_ID, tmp_node_ID,
1209  flag_global_ID, flag_skip_ext, flag_oldUCD,
1210  nid_offsets, eid_offsets[j]);
1211 
1212  HECMW_free(tmp_elem_ID);
1213  HECMW_free(tmp_elem_type);
1214  HECMW_free(tmp_elem_node_index);
1215  HECMW_free(tmp_elem_node_item);
1216 
1217  if (flag_global_ID) {
1218  HECMW_free(tmp_global_elem_ID);
1219  HECMW_free(tmp_global_node_ID);
1220  } else {
1221  HECMW_free(tmp_node_ID);
1222  }
1223  }
1224  }
1225  }
1226 
1227  /* write header for data */
1228  if (mynode == 0) {
1229  avs_write_data_header(outfp, tn_component, te_component, flag_oldUCD);
1230  avs_write_node_data_header(outfp, tn_component, data, flag_Scalar);
1231  }
1232 
1233  /* write node data */
1234  if (mynode != 0) {
1235  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1236  if (mesh->nn_internal > 0) {
1237  if (flag_global_ID)
1239  MASTER_PE, 0, VIS_COMM);
1240  HECMW_Send(data->node_val_item, mesh->nn_internal * tn_component,
1241  HECMW_DOUBLE, MASTER_PE, 0, VIS_COMM);
1242  }
1243  } else {
1244  int i;
1245 
1246  avs_write_node_data(outfp, mesh->nn_internal, mesh->global_node_ID,
1247  tn_component, data->node_val_item, flag_global_ID, 0);
1248 
1249  for (i = 1; i < pesize; i++) {
1250  int tmp_nn_internal;
1251 
1252  HECMW_Recv(&tmp_nn_internal, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM,
1253  &stat);
1254 
1255  if (tmp_nn_internal > 0) {
1256  int *tmp_global_node_ID = NULL;
1257  double *tmp_node_val_item;
1258 
1259  if (flag_global_ID) {
1260  tmp_global_node_ID =
1261  (int *)HECMW_calloc(tmp_nn_internal, sizeof(int));
1262  if (tmp_global_node_ID == NULL)
1263  HECMW_vis_memory_exit("tmp recv: global_node_ID (for data)");
1264 
1265  HECMW_Recv(tmp_global_node_ID, tmp_nn_internal, HECMW_INT, i,
1266  HECMW_ANY_TAG, VIS_COMM, &stat);
1267  }
1268 
1269  tmp_node_val_item = (double *)HECMW_calloc(
1270  tmp_nn_internal * tn_component, sizeof(double));
1271  if (tmp_node_val_item == NULL)
1272  HECMW_vis_memory_exit("tmp recv: node_val_item");
1273 
1274  HECMW_Recv(tmp_node_val_item, tmp_nn_internal * tn_component,
1275  HECMW_DOUBLE, i, HECMW_ANY_TAG, VIS_COMM, &stat);
1276 
1277  avs_write_node_data(outfp, tmp_nn_internal, tmp_global_node_ID,
1278  tn_component, tmp_node_val_item, flag_global_ID,
1279  nid_offsets[i]);
1280 
1281  if (flag_global_ID) HECMW_free(tmp_global_node_ID);
1282  HECMW_free(tmp_node_val_item);
1283  }
1284  }
1285  }
1286 
1287  /* write elem data header*/
1288  if (mynode == 0){
1289  if (te_component > 0){
1290  avs_write_elem_data_header(outfp, te_component, data, flag_Scalar);
1291  }
1292  }
1293 
1294  /* write elem data */
1295  if (mynode != 0) {
1296  if (te_component > 0){
1297  HECMW_Send (&mesh->n_elem, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1298  if (mesh->n_elem > 0){
1299  HECMW_Send (mesh->elem_ID, mesh->n_elem * 2, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1300  if (flag_global_ID)
1302  HECMW_Send (data->elem_val_item, mesh->n_elem * te_component, HECMW_DOUBLE, MASTER_PE, 0, VIS_COMM);
1303  }
1304  }
1305  } else {
1306  int i;
1307  if (te_component > 0){
1308  avs_write_elem_data(outfp, mynode, mesh->n_elem, mesh->elem_ID, mesh->global_elem_ID, te_component, data->elem_val_item, flag_global_ID, 0);
1309  for (i = 1; i < pesize; i++){
1310  int tmp_n_elem;
1311  HECMW_Recv (&tmp_n_elem, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
1312 
1313  if (tmp_n_elem > 0){
1314  int *tmp_elem_ID;
1315  double *tmp_elem_val_item;
1316  int *tmp_global_elem_ID = NULL;
1317 
1318  tmp_elem_ID = (int *) HECMW_calloc (tmp_n_elem * 2, sizeof (int));
1319  if (tmp_elem_ID == NULL)
1320  HECMW_vis_memory_exit ("tmp recv: elem_ID");
1321 
1322  HECMW_Recv (tmp_elem_ID, tmp_n_elem * 2, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
1323 
1324  if (flag_global_ID){
1325  tmp_global_elem_ID = (int *) HECMW_calloc (tmp_n_elem, sizeof (int));
1326  if (tmp_global_elem_ID == NULL)
1327  HECMW_vis_memory_exit ("tmp recv: global_elem_ID (for data)");
1328 
1329  HECMW_Recv (tmp_global_elem_ID, tmp_n_elem, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
1330  }
1331 
1332  tmp_elem_val_item = (double *) HECMW_calloc (tmp_n_elem * te_component, sizeof (double));
1333  if (tmp_elem_val_item == NULL)
1334  HECMW_vis_memory_exit ("tmp recv: elem_val_item");
1335 
1336  HECMW_Recv (tmp_elem_val_item, tmp_n_elem * te_component, HECMW_DOUBLE, i, HECMW_ANY_TAG, VIS_COMM, &stat);
1337 
1338  avs_write_elem_data(outfp, i, tmp_n_elem, tmp_elem_ID, tmp_global_elem_ID, te_component, tmp_elem_val_item, flag_global_ID, eid_offsets[i]);
1339 
1340  HECMW_free (tmp_elem_ID);
1341  if (flag_global_ID)
1342  HECMW_free (tmp_global_elem_ID);
1343  HECMW_free (tmp_elem_val_item);
1344  }
1345  }
1346  }
1347  }
1348 
1349  if (mynode == 0) {
1350  HECMW_free(nid_offsets);
1351  HECMW_free(eid_offsets);
1352  fclose(outfp);
1353  }
1354 
1355  return;
1356 }
1357 
1359  struct hecmwST_result_data *data, char *outfile,
1360  HECMW_Comm VIS_COMM) {
1361  int flag_oldUCD = 0;
1362  int flag_global_ID = 1;
1363  int flag_Scalar = 0;
1364  avs_output(mesh, data, outfile, VIS_COMM, flag_oldUCD, flag_global_ID,
1365  flag_Scalar);
1366 }
1367 
1369  struct hecmwST_result_data *data, char *outfile,
1370  HECMW_Comm VIS_COMM) {
1371  int flag_oldUCD = 1;
1372  int flag_global_ID = 0;
1373  int flag_Scalar = 0;
1374  avs_output(mesh, data, outfile, VIS_COMM, flag_oldUCD, flag_global_ID,
1375  flag_Scalar);
1376 }
1377 
1379  struct hecmwST_result_data *data, char *outfile,
1380  HECMW_Comm VIS_COMM) {
1381  int flag_oldUCD = 0;
1382  int flag_global_ID = 1;
1383  int flag_Scalar = 1;
1384  avs_output(mesh, data, outfile, VIS_COMM, flag_oldUCD, flag_global_ID,
1385  flag_Scalar);
1386 }
1387 
1389  struct hecmwST_result_data *data, char *outfile,
1390  HECMW_Comm VIS_COMM) {
1391  int i, j, k, ii, m;
1392  int mynode, pesize;
1393  HECMW_Status stat;
1394  int ielm, nn[20], tmp_int, tn_component, tmp_int2, te_component, tmp_nn[20];
1395  double *tmp_recv_d, *tmp_send_d;
1396  int *tmp_recv_i, *tmp_elem_ID, *tmp_elem_type, *tmp_elem_global_ID,
1397  *tmp_elem_node_item, *tmp_section_ID,
1398  *tmp_node_global_ID;
1399  long long *tmp_elem_node_index;
1400  FILE *fp, *fp2;
1401  int total_n_node, total_n_elem;
1402 
1403  int icell_type[1];
1404  float xyz[3];
1405  char keyword[8];
1406  char title[70];
1407  float version;
1408  int stepno;
1409  float timeval;
1410  int num_nodeveclen;
1411  int num_celldata;
1412  int null_flag;
1413  float null_value;
1414  char nodedata_label[16];
1415  char nodedata_unit[16];
1416  int ztype;
1417  int tmp_int_conv, *tmp_global_id, count, elem_type_bin;
1418  float tmp_d_conv;
1419  int node_num;
1420 
1421  HECMW_Comm_rank(VIS_COMM, &mynode);
1422  HECMW_Comm_size(VIS_COMM, &pesize);
1423  if ((mesh->elem_type[0] == 231) || (mesh->elem_type[0] == 232) ||
1424  (mesh->elem_type[0] == 731) || (mesh->elem_type[0] == 732)) {
1425  elem_type_bin = 2;
1426  node_num = 3;
1427  } else if ((mesh->elem_type[0] == 241) || (mesh->elem_type[0] == 242) ||
1428  (mesh->elem_type[0] == 741) || (mesh->elem_type[0] == 742) ||
1429  (mesh->elem_type[0] == 743)) {
1430  elem_type_bin = 3;
1431  node_num = 4;
1432  } else if ((mesh->elem_type[0] == 341) || (mesh->elem_type[0] == 342) ||
1433  (mesh->elem_type[0] == 3414)) {
1434  elem_type_bin = 4;
1435  node_num = 4;
1436  } else if ((mesh->elem_type[0] == 351) || (mesh->elem_type[0] == 352)) {
1437  elem_type_bin = 6;
1438  node_num = 6;
1439  } else if ((mesh->elem_type[0] == 361) || (mesh->elem_type[0] == 362)) {
1440  elem_type_bin = 7;
1441  node_num = 8;
1442  }
1443  if (pesize > 1) {
1444  HECMW_Allreduce(&mesh->nn_internal, &total_n_node, 1, HECMW_INT, HECMW_SUM,
1445  VIS_COMM);
1446  HECMW_Allreduce(&mesh->ne_internal, &total_n_elem, 1, HECMW_INT, HECMW_SUM,
1447  VIS_COMM);
1448  } else {
1449  total_n_node = mesh->nn_internal;
1450  total_n_elem = mesh->n_elem;
1451  }
1452  tn_component = 0;
1453  for (i = 0; i < data->nn_component; i++) tn_component += data->nn_dof[i];
1454  te_component = 0;
1455  for (i = 0; i < data->ne_component; i++) te_component += data->ne_dof[i];
1456  if (mynode == 0) {
1457  fp2 = fopen(outfile, "w");
1458  fprintf(fp2, "#UCD Binary format\n");
1459  fprintf(fp2, "#\n");
1460  fprintf(fp2, "data\n");
1461  fprintf(fp2, "bin_data.dat\n");
1462  fclose(fp2);
1463 
1464  fp = fopen("bin_data.dat", "wb");
1465 
1466  if (fp == NULL)
1467  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output file");
1468  fprintf(stderr, "Start writing binary output for AVS UCD format\n");
1469  snprintf(keyword, sizeof(keyword), "AVS UCD");
1470  version = 1.0;
1471 #ifdef CONVERSE_ORDER
1473 #endif
1474  strcpy(title, "ucd binary test data");
1475  stepno = 1;
1476 #ifdef CONVERSE_ORDER
1477  SWAP_INT(stepno);
1478 #endif
1479  timeval = 1.0;
1480 #ifdef CONVERSE_ORDER
1481  SWAP_FLOAT(timeval);
1482 #endif
1483  tmp_int_conv = total_n_node;
1484 #ifdef CONVERSE_ORDER
1485  SWAP_INT(tmp_int_conv);
1486 #endif
1487 
1488  fwrite(keyword, 7, 1, fp);
1489  fwrite(&version, 4, 1, fp);
1490  fwrite(title, 70, 1, fp);
1491  fwrite(&stepno, 4, 1, fp);
1492  fwrite(&timeval, 4, 1, fp);
1493  fwrite(&tmp_int_conv, 4, 1, fp);
1494  ztype = 1;
1495 #ifdef CONVERSE_ORDER
1496  SWAP_INT(ztype);
1497 #endif
1498 
1499  fwrite(&ztype, 4, 1, fp);
1500  }
1501 
1502  if (mynode != 0) {
1503  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1504  if (mesh->nn_internal > 0) {
1506  0, VIS_COMM);
1508  VIS_COMM);
1509  }
1510  }
1511  if (mynode == 0) {
1512  for (i = 0; i < mesh->nn_internal; i++) {
1513  tmp_int_conv = mesh->global_node_ID[i];
1514 #ifdef CONVERSE_ORDER
1515  SWAP_INT(tmp_int_conv);
1516 #endif
1517  fwrite(&tmp_int_conv, 4, 1, fp);
1518  xyz[0] = (float)mesh->node[i * 3];
1519  xyz[1] = (float)mesh->node[i * 3 + 1];
1520  xyz[2] = (float)mesh->node[i * 3 + 2];
1521 #ifdef CONVERSE_ORDER
1522  SWAP_FLOAT(xyz[0]);
1523  SWAP_FLOAT(xyz[1]);
1524  SWAP_FLOAT(xyz[2]);
1525 #endif
1526  fwrite(xyz, 4, 3, fp);
1527  }
1528  for (i = 1; i < pesize; i++) {
1529  HECMW_Recv(&tmp_int, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
1530  if (tmp_int > 0) {
1531  tmp_recv_i = (int *)HECMW_calloc(tmp_int, sizeof(int));
1532  tmp_recv_d = (double *)HECMW_calloc(tmp_int * 3, sizeof(double));
1533  if ((tmp_recv_i == NULL) || (tmp_recv_d == NULL))
1534  HECMW_vis_memory_exit("tmp_recv");
1535  HECMW_Recv(tmp_recv_i, tmp_int, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM,
1536  &stat);
1537  HECMW_Recv(tmp_recv_d, tmp_int * 3, HECMW_DOUBLE, i, HECMW_ANY_TAG,
1538  VIS_COMM, &stat);
1539  for (j = 0; j < tmp_int; j++) {
1540  tmp_int_conv = tmp_recv_i[j];
1541 #ifdef CONVERSE_ORDER
1542  SWAP_INT(tmp_int_conv);
1543 #endif
1544  fwrite(&tmp_int_conv, 4, 1, fp);
1545  xyz[0] = (float)tmp_recv_d[j * 3];
1546  xyz[1] = (float)tmp_recv_d[j * 3 + 1];
1547  xyz[2] = (float)tmp_recv_d[j * 3 + 2];
1548 #ifdef CONVERSE_ORDER
1549  SWAP_FLOAT(xyz[0]);
1550  SWAP_FLOAT(xyz[1]);
1551  SWAP_FLOAT(xyz[2]);
1552 #endif
1553  fwrite(xyz, 4, 3, fp);
1554  }
1555  HECMW_free(tmp_recv_i);
1556  HECMW_free(tmp_recv_d);
1557  }
1558  }
1559  }
1560  if (mynode != 0) {
1561  HECMW_Send(&mesh->n_elem, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1562  if (mesh->n_elem > 0) {
1564  VIS_COMM);
1566  VIS_COMM);
1567  }
1568  }
1569  if (mynode == 0) {
1570  tmp_global_id = (int *)HECMW_calloc(total_n_elem, sizeof(int));
1571  if (tmp_global_id == NULL) HECMW_vis_memory_exit("tmp_global_id");
1572  count = 0;
1573 
1574  for (i = 0; i < mesh->n_elem; i++) {
1575  if (mesh->elem_ID[i * 2 + 1] == mynode) {
1576  tmp_global_id[count] = mesh->global_elem_ID[i];
1577  count++;
1578  }
1579  }
1580  for (j = 1; j < pesize; j++) {
1581  HECMW_Recv(&tmp_int, 1, HECMW_INT, j, HECMW_ANY_TAG, VIS_COMM, &stat);
1582  if (tmp_int > 0) {
1583  tmp_elem_global_ID = (int *)HECMW_calloc(tmp_int, sizeof(int));
1584  tmp_elem_ID = (int *)HECMW_calloc(tmp_int * 2, sizeof(int));
1585  if ((tmp_elem_global_ID == NULL) || (tmp_elem_ID == NULL))
1586  HECMW_vis_memory_exit("tmp recv");
1587  HECMW_Recv(tmp_elem_global_ID, tmp_int, HECMW_INT, j, HECMW_ANY_TAG,
1588  VIS_COMM, &stat);
1589  HECMW_Recv(tmp_elem_ID, tmp_int * 2, HECMW_INT, j, HECMW_ANY_TAG,
1590  VIS_COMM, &stat);
1591 
1592  for (i = 0; i < tmp_int; i++) {
1593  if (tmp_elem_ID[i * 2 + 1] == j) {
1594  tmp_global_id[count] = tmp_elem_global_ID[i];
1595  count++;
1596  }
1597  }
1598  HECMW_free(tmp_elem_global_ID);
1599  HECMW_free(tmp_elem_ID);
1600  }
1601  }
1602  }
1603 
1604  if (mynode != 0) {
1605  HECMW_Send(&mesh->n_elem, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1606  if (mesh->n_elem > 0) {
1607  HECMW_Send(&mesh->n_node, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1608 
1610  VIS_COMM);
1612  VIS_COMM);
1614  0, VIS_COMM);
1616  HECMW_INT, MASTER_PE, 0, VIS_COMM);
1618  VIS_COMM);
1619  }
1620  }
1621 
1622  if (mynode == 0) {
1623  tmp_int_conv = total_n_elem;
1624 #ifdef CONVERSE_ORDER
1625  SWAP_INT(tmp_int_conv);
1626 #endif
1627  fwrite(&tmp_int_conv, 4, 1, fp);
1628  for (i = 0; i < total_n_elem; i++) {
1629  tmp_int_conv = tmp_global_id[i];
1630 #ifdef CONVERSE_ORDER
1631  SWAP_INT(tmp_int_conv);
1632 #endif
1633  fwrite(&tmp_int_conv, 4, 1, fp);
1634  }
1635  for (i = 0; i < total_n_elem; i++) {
1636  tmp_int_conv = 1;
1637 #ifdef CONVERSE_ORDER
1638  SWAP_INT(tmp_int_conv);
1639 #endif
1640  fwrite(&tmp_int_conv, 4, 1, fp);
1641  }
1642  icell_type[0] = (char)elem_type_bin;
1643  for (i = 0; i < total_n_elem; i++) {
1644  fwrite(&icell_type[0], 1, 1, fp);
1645  }
1646 
1647  for (i = 0; i < mesh->n_elem; i++) {
1648  if (mesh->elem_ID[i * 2 + 1] == mynode) {
1649  ielm = mesh->global_elem_ID[i];
1650  for (j = 0; j < node_num; j++)
1651  tmp_nn[j] =
1653  [mesh->elem_node_item[mesh->elem_node_index[i] + j] - 1];
1654  /* if(mesh->elem_type[0]==342) {
1655 for(m=0;m<4;m++)
1656 nn[m]=tmp_nn[m];
1657 nn[4]=tmp_nn[6];
1658 nn[5]=tmp_nn[5];
1659 nn[6]=tmp_nn[7];
1660 nn[7]=tmp_nn[4];
1661 nn[8]=tmp_nn[9];
1662 nn[9]=tmp_nn[8];
1663 }
1664 else {
1665  */
1666  for (m = 0; m < node_num; m++) nn[m] = tmp_nn[m];
1667  /* }
1668  */
1669 
1670  for (m = 0; m < node_num; m++) {
1671  tmp_int_conv = nn[m];
1672 #ifdef CONVERSE_ORDER
1673  SWAP_INT(tmp_int_conv);
1674 #endif
1675  fwrite(&tmp_int_conv, 4, 1, fp);
1676  }
1677  }
1678  }
1679  for (j = 1; j < pesize; j++) {
1680  HECMW_Recv(&tmp_int, 1, HECMW_INT, j, HECMW_ANY_TAG, VIS_COMM, &stat);
1681  if (tmp_int > 0) {
1682  HECMW_Recv(&tmp_int2, 1, HECMW_INT, j, HECMW_ANY_TAG, VIS_COMM, &stat);
1683  tmp_elem_global_ID = (int *)HECMW_calloc(tmp_int, sizeof(int));
1684  tmp_elem_ID = (int *)HECMW_calloc(tmp_int * 2, sizeof(int));
1685  tmp_elem_type = (int *)HECMW_calloc(tmp_int, sizeof(int));
1686  tmp_section_ID = (int *)HECMW_calloc(tmp_int, sizeof(int));
1687  tmp_elem_node_index = (long long *)HECMW_calloc(tmp_int + 1, sizeof(long long));
1688  if ((tmp_elem_global_ID == NULL) || (tmp_elem_ID == NULL) ||
1689  (tmp_elem_type == NULL) || (tmp_section_ID == NULL))
1690  HECMW_vis_memory_exit("tmp recv");
1691  HECMW_Recv(tmp_elem_global_ID, tmp_int, HECMW_INT, j, HECMW_ANY_TAG,
1692  VIS_COMM, &stat);
1693  HECMW_Recv(tmp_elem_ID, tmp_int * 2, HECMW_INT, j, HECMW_ANY_TAG,
1694  VIS_COMM, &stat);
1695  HECMW_Recv(tmp_elem_node_index, tmp_int + 1, HECMW_LONG_LONG, j,
1696  HECMW_ANY_TAG, VIS_COMM, &stat);
1697  tmp_elem_node_item =
1698  (int *)HECMW_calloc(tmp_elem_node_index[tmp_int], sizeof(int));
1699  tmp_node_global_ID = (int *)HECMW_calloc(tmp_int2, sizeof(int));
1700  HECMW_Recv(tmp_elem_node_item, tmp_elem_node_index[tmp_int], HECMW_INT,
1701  j, HECMW_ANY_TAG, VIS_COMM, &stat);
1702  HECMW_Recv(tmp_node_global_ID, tmp_int2, HECMW_INT, j, HECMW_ANY_TAG,
1703  VIS_COMM, &stat);
1704 
1705  for (i = 0; i < tmp_int; i++) {
1706  if (tmp_elem_ID[i * 2 + 1] == j) {
1707  ielm = tmp_elem_global_ID[i];
1708  for (m = 0; m < node_num; m++)
1709  tmp_nn[m] = tmp_node_global_ID
1710  [tmp_elem_node_item[tmp_elem_node_index[i] + m] - 1];
1711  /* if(mesh->elem_type[0]==342) {
1712 for(m=0;m<4;m++)
1713 nn[m]=tmp_nn[m];
1714 nn[4]=tmp_nn[6];
1715 nn[5]=tmp_nn[5];
1716 nn[6]=tmp_nn[7];
1717 nn[7]=tmp_nn[4];
1718 nn[8]=tmp_nn[9];
1719 nn[9]=tmp_nn[8];
1720 }
1721 else {
1722  */
1723  for (m = 0; m < node_num; m++) nn[m] = tmp_nn[m];
1724  /* }
1725  */
1726  for (m = 0; m < node_num; m++) {
1727  tmp_int_conv = nn[m];
1728 #ifdef CONVERSE_ORDER
1729  SWAP_INT(tmp_int_conv);
1730 #endif
1731  fwrite(&tmp_int_conv, 4, 1, fp);
1732  }
1733  }
1734  }
1735  HECMW_free(tmp_elem_global_ID);
1736  HECMW_free(tmp_elem_ID);
1737  HECMW_free(tmp_elem_type);
1738  HECMW_free(tmp_section_ID);
1739  HECMW_free(tmp_elem_node_index);
1740  HECMW_free(tmp_elem_node_item);
1741  HECMW_free(tmp_node_global_ID);
1742  }
1743  }
1744  HECMW_free(tmp_global_id);
1745  }
1746 
1747  if (mynode == 0) {
1748  tmp_int_conv = tn_component;
1749 #ifdef CONVERSE_ORDER
1750  SWAP_INT(tmp_int_conv);
1751 #endif
1752  fwrite(&tmp_int_conv, 4, 1, fp);
1753  tmp_int_conv = 1;
1754 #ifdef CONVERSE_ORDER
1755  SWAP_INT(tmp_int_conv);
1756 #endif
1757  fwrite(&tmp_int_conv, 4, 1, fp);
1758  for (j = 0; j < data->nn_component; j++) {
1759  for (ii = 0; ii < data->nn_dof[j]; ii++) {
1760  snprintf(nodedata_label, sizeof(nodedata_label), "%s%d\n", data->node_label[j], ii + 1);
1761  snprintf(nodedata_unit, sizeof(nodedata_unit), "%s", "m/s");
1762  num_nodeveclen = 1;
1763 #ifdef CONVERSE_ORDER
1764  SWAP_INT(num_nodeveclen);
1765 #endif
1766  null_flag = 0;
1767 #ifdef CONVERSE_ORDER
1768  SWAP_INT(null_flag);
1769 #endif
1770  null_value = -999.999;
1771 #ifdef CONVERSE_ORDER
1772  SWAP_FLOAT(null_value);
1773 #endif
1774  fwrite(nodedata_label, 16, 1, fp);
1775  fwrite(nodedata_unit, 16, 1, fp);
1776  fwrite(&num_nodeveclen, 4, 1, fp);
1777  fwrite(&null_flag, 4, 1, fp);
1778  fwrite(&null_value, 4, 1, fp);
1779  }
1780  }
1781  }
1782  if (mynode != 0) {
1783  HECMW_Send(&mesh->nn_internal, 1, HECMW_INT, MASTER_PE, 0, VIS_COMM);
1784  if (mesh->nn_internal > 0) {
1786  0, VIS_COMM);
1787  tmp_send_d = (double *)HECMW_calloc(mesh->nn_internal * tn_component,
1788  sizeof(double));
1789  for (i = 0; i < mesh->nn_internal * tn_component; i++)
1790  tmp_send_d[i] = data->node_val_item[i];
1791 
1792  HECMW_Send(tmp_send_d, mesh->nn_internal * tn_component, HECMW_DOUBLE,
1793  MASTER_PE, 0, VIS_COMM);
1794 
1795  HECMW_free(tmp_send_d);
1796  }
1797  }
1798 
1799  if (mynode == 0) {
1800  for (i = 0; i < mesh->nn_internal; i++) {
1801  for (k = 0; k < tn_component; k++) {
1802  tmp_d_conv = (float)data->node_val_item[i * tn_component + k];
1803 #ifdef CONVERSE_ORDER
1804  SWAP_FLOAT(tmp_d_conv);
1805 #endif
1806  fwrite(&tmp_d_conv, 4, 1, fp);
1807  }
1808  }
1809  for (i = 1; i < pesize; i++) {
1810  HECMW_Recv(&tmp_int, 1, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM, &stat);
1811  if (tmp_int > 0) {
1812  tmp_recv_i = (int *)HECMW_calloc(tmp_int, sizeof(int));
1813  tmp_recv_d =
1814  (double *)HECMW_calloc(tmp_int * tn_component, sizeof(double));
1815  if ((tmp_recv_i == NULL) || (tmp_recv_d == NULL))
1816  HECMW_vis_memory_exit("tmp_recv");
1817  HECMW_Recv(tmp_recv_i, tmp_int, HECMW_INT, i, HECMW_ANY_TAG, VIS_COMM,
1818  &stat);
1819  HECMW_Recv(tmp_recv_d, tmp_int * tn_component, HECMW_DOUBLE, i,
1820  HECMW_ANY_TAG, VIS_COMM, &stat);
1821  for (j = 0; j < tmp_int; j++) {
1822  for (k = 0; k < tn_component; k++) {
1823  tmp_d_conv = (float)tmp_recv_d[j * tn_component + k];
1824 #ifdef CONVERSE_ORDER
1825  SWAP_FLOAT(tmp_d_conv);
1826 #endif
1827  fwrite(&tmp_d_conv, 4, 1, fp);
1828  }
1829  }
1830  HECMW_free(tmp_recv_i);
1831  HECMW_free(tmp_recv_d);
1832  }
1833  }
1834  num_celldata = 0;
1835  fwrite(&num_celldata, 4, 1, fp);
1836  }
1837  if (mynode == 0) fclose(fp);
1838  return;
1839 }
1840 
1842  struct hecmwST_result_data *data,
1843  char *outfile) {
1844  FILE *outfp;
1845  int mynode;
1846  int total_n_node, total_n_elem;
1847  int tn_component, te_component;
1848 
1849  int flag_oldUCD = 1;
1850  int flag_global_ID = 0;
1851  int flag_Scalar = 0;
1852  int flag_skip_ext = 0;
1853 
1854  mynode = mesh->my_rank;
1855 
1856  /* count total number of node/elem */
1857  total_n_node = mesh->n_node;
1858  total_n_elem = mesh->n_elem;
1859 
1860  /* count total number of data components */
1861  count_data_components(data, &tn_component, &te_component);
1862 
1863  /* open file */
1864  outfp = fopen(outfile, "w");
1865  if (!outfp)
1866  HECMW_vis_print_exit("ERROR: HEC-MW-VIS-E0009: Cannot open output file");
1867 
1868  /* write header */
1869  avs_write_header(outfp, total_n_node, total_n_elem, tn_component, 0,
1870  flag_oldUCD);
1871 
1872  /* write node coordinate */
1873  avs_write_node_coord(outfp, mesh->n_node, mesh->global_node_ID, mesh->node,
1874  flag_global_ID, 0);
1875 
1876  /* write element connectivity */
1877  avs_write_elem_conn(outfp, mynode, mesh->n_elem, mesh->elem_ID,
1880  mesh->global_node_ID, mesh->node_ID, flag_global_ID,
1881  flag_skip_ext, flag_oldUCD, NULL, 0);
1882 
1883  /* write total number of data components */
1884  avs_write_data_header(outfp, tn_component, 0, flag_oldUCD);
1885 
1886  /* write header for node data */
1887  avs_write_node_data_header(outfp, tn_component, data, flag_Scalar);
1888 
1889  /* write node data */
1890  avs_write_node_data(outfp, mesh->n_node, mesh->global_node_ID, tn_component,
1891  data->node_val_item, flag_global_ID, 0);
1892 
1893  fclose(outfp);
1894  return;
1895 }
if(!(yy_init))
Definition: hecmw_ablex.c:1823
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
int HECMW_Allreduce(void *sendbuf, void *recvbuf, int count, HECMW_Datatype datatype, HECMW_Op op, HECMW_Comm comm)
Definition: hecmw_comm.c:404
int HECMW_Send(void *buffer, int count, HECMW_Datatype datatype, int dest, int tag, HECMW_Comm comm)
Definition: hecmw_comm.c:201
int HECMW_Recv(void *buffer, int count, HECMW_Datatype datatype, int source, int tag, HECMW_Comm comm, HECMW_Status *status)
Definition: hecmw_comm.c:251
#define HECMW_INT
Definition: hecmw_config.h:48
MPI_Status HECMW_Status
Definition: hecmw_config.h:36
#define HECMW_DOUBLE
Definition: hecmw_config.h:50
MPI_Comm HECMW_Comm
Definition: hecmw_config.h:30
#define HECMW_SUM
Definition: hecmw_config.h:60
#define HECMW_LONG_LONG
Definition: hecmw_config.h:54
int HECMW_ANY_TAG
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
int HECMW_get_max_node(int etype)
Definition: hecmw_etype.c:413
int HECMW_is_etype_33struct(int etype)
Definition: hecmw_etype.c:2030
char * HECMW_get_ucd_label(int etype)
Definition: hecmw_etype.c:1230
int HECMW_get_etype_class(int etype)
Definition: hecmw_etype.c:1397
int modify_element_information(const struct hecmwST_local_mesh *mesh)
void HECMW_fstr_output_femap(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, HECMW_Comm VIS_COMM)
void HECMW_separate_avs_output(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile)
void HECMW_microavs_output(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, HECMW_Comm VIS_COMM)
void HECMW_bin_avs_output(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, HECMW_Comm VIS_COMM)
void HECMW_avs_output(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, HECMW_Comm VIS_COMM)
void HECMW_reorder_avs_output(struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, char *outfile, HECMW_Comm VIS_COMM)
#define NULL
#define HECMW_calloc(nmemb, size)
Definition: hecmw_malloc.h:21
#define HECMW_free(ptr)
Definition: hecmw_malloc.h:24
#define MASTER_PE
Definition: hecmw_repart.h:17
#define HECMW_assert(cond)
Definition: hecmw_util.h:40
void put_neutral_middle(FILE *outfp)
void put_neutral_402(FILE *outfp, struct hecmwST_local_mesh *mesh)
void put_neutral_head(FILE *outfp)
void put_neutral_601(FILE *outfp, struct hecmwST_local_mesh *mesh)
#define SWAP_FLOAT(Var)
#define SWAP_INT(Var)
void HECMW_vis_print_exit(char *var)
void HECMW_vis_memory_exit(char *var)
void version(char *arg)
show version and revision of FrontISTR
Definition: main.c:256
void title()
Definition: neu2fstr.cpp:52
CNFData data
struct hecmwST_section * section
Definition: hecmw_struct.h:245
long long * elem_node_index
Definition: hecmw_struct.h:195