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