FrontISTR  6.0.0
Large-scale structural analysis program with finit element method
hecmw_vis_surface_compute.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 /*----------------------------------------------------------------------
6  * Subroutines in this file on isosurface generation for hexahedra by Marching
7  *Cubes is based
8  * on the revision of Dr. Yuriko Takeshima's codes when she was working part
9  *time in RIST
10  *----------------------------------------------------------------------*/
11 
13 
14 #include <math.h>
15 #include "hecmw_vis_mem_util.h"
16 #include "hecmw_vis_case_table.h"
18 #include "hecmw_vis_patch_const.h"
19 #include "hecmw_malloc.h"
20 
22  struct hecmwST_result_data *data, int *bdflag,
23  int *sum_v, int *sum_t, int *tvertex, int *tpatch,
24  double *minc, double *maxc, Result *result,
25  int sf_i, int mynode, HECMW_Comm VIS_COMM)
26 
27 {
28  /* in_volume */
29  int i, j, k, mm;
30  Point **CS_verts_head;
31  Polygon **CS_polys_head;
32  int alpha_index, beta_index;
33  int sum_verts;
34  int sum_table;
35  Point **CS_verts_tail, **CS_verts_refer;
36  Polygon **CS_polys_tail;
37  Cube_polygons alpha_cube, beta_cube;
38 
39  int n_elem, tmp_int;
40  Cell *cell;
41  Tetra *tetra;
42 
43  int disamb_flag;
44 
45  Polygon *CS_polys, *CS_polys_tmp;
46  Point *CS_verts, *CS_verts_tmp;
47  int sum_polys, poly_num;
48  int num_nh_verts,
49  num_nh_patch; /* vertex on patches generated in non-hexahedra */
50  int flag_hexa, flag_tetra;
51  Hash_vertex *vertex_hash_table;
52  Tetra_point *tetra_point;
53  Head_patch_tetra *head_patch_tetra;
54  Tetra_point *p1, *p2;
55  Patch_tetra *t1, *t2;
56  Hash_vertex *h1, *h2;
57  int minus_patch;
58  double tmp_data[9];
59  int tn_component, c_base;
60  double tmp;
61 
62  sum_verts = 0;
63  num_nh_verts = 0;
64  num_nh_patch = 0;
65  sum_polys = 0;
66 
67  n_elem = mesh->n_elem;
68  tn_component = 0;
69  for (i = 0; i < data->nn_component; i++) tn_component += data->nn_dof[i];
70 
71  /* prism = (Prism *)HECMW_malloc(sizeof(Prism));
72  */
73  if (mesh->elem_type[0] > 300) {
74  flag_hexa = 0;
75  flag_tetra = 0;
76 
77  disamb_flag = 1;
78  /* fprintf(stderr, "sff inf: color=%d color_sub=%d con=%lf %lf %lf% lf\n",
79 sff->color_comp, sff->color_subcomp, sff->cont_equ[6],
80 sff->cont_equ[7], sff->cont_equ[8],sff->cont_equ[9]);
81 
82 snprintf(test_file, sizeof(test_file), "test_ucd.%d.%d.inp", time_step, mynode);
83 write_mesh_display(test_file, mesh, data);
84 HECMW_Barrier(VIS_COMM);
85  */
86  /*
87 for(i = 0; i < mesh->ne_internal; i++) {
88  tmp_int=mesh->elem_internal_list[i]-1;
89  */
90  for (i = 0; i < mesh->n_elem; i++)
91  if (mesh->elem_ID[i * 2 + 1] == mynode) {
92  tmp_int = i;
93  if ((mesh->elem_type[tmp_int] == 361) ||
94  (mesh->elem_type[tmp_int] == 362) ||
95  (mesh->elem_type[tmp_int] == 351) ||
96  (mesh->elem_type[tmp_int] == 352)) {
97  if (flag_hexa == 0) {
98  flag_hexa = 1;
99 
100  CS_polys_head = (Polygon **)HECMW_malloc(sizeof(Polygon *));
101  CS_verts_head = (Point **)HECMW_calloc(TABLE_SIZE, sizeof(Point *));
102  sum_table = TABLE_SIZE;
103  CS_verts_tail = (Point **)HECMW_calloc(sum_table, sizeof(Point *));
104  CS_verts_refer = (Point **)HECMW_calloc(sum_table, sizeof(Point *));
105  for (j = 0; j < sum_table; j++) {
106  if ((CS_verts_refer[j] = CS_verts_tail[j] = CS_verts_head[j] =
108  HECMW_vis_memory_exit("verts for hexahedra");
109  }
110 
111  CS_polys_tail = (Polygon **)HECMW_malloc(sizeof(Polygon *));
112  if ((*CS_polys_tail = *CS_polys_head =
114  HECMW_vis_memory_exit("CS_polys_tail");
115 
116  alpha_cube.isosurf = (int **)HECMW_malloc(sizeof(int *));
117  beta_cube.isosurf = (int **)HECMW_malloc(sizeof(int *));
118  cell = (Cell *)HECMW_malloc(sizeof(Cell));
119  }
120  get_data(sff, mesh, data, tmp_int, cell, tn_component);
121  if (sff->surface_style == 2) {
122  alpha_index = make_tile(mesh, cell, sff->iso_value, 0, &alpha_cube,
123  disamb_flag);
124  beta_index = make_tile(mesh, cell, sff->iso_value, 1, &beta_cube,
125  disamb_flag);
126  if (alpha_index && beta_index) {
127  if ((alpha_index + beta_index) == HEX_NODE_INDEX) {
128  if (!merge_vol_iso(0, cell, sff->iso_value, &alpha_cube, 0,
129  &beta_cube, bdflag[i], &sum_verts,
130  CS_verts_tail, CS_verts_refer, CS_verts_head,
131  CS_polys_tail)) {
132  return 0;
133  }
134  }
135  }
136 
137  } else if (sff->surface_style == 3) {
138  alpha_index = make_tile(mesh, cell, 0, 0, &alpha_cube, disamb_flag);
139  beta_index = make_tile(mesh, cell, 0, 1, &beta_cube, disamb_flag);
140  if (alpha_index && beta_index) {
141  if ((alpha_index + beta_index) == HEX_NODE_INDEX) {
142  if (!merge_vol_iso(0, cell, 0, &alpha_cube, 0, &beta_cube,
143  bdflag[i], &sum_verts, CS_verts_tail,
144  CS_verts_refer, CS_verts_head,
145  CS_polys_tail)) {
146  return 0;
147  }
148  }
149  }
150  }
151  } else if ((mesh->elem_type[tmp_int] == 341) ||
152  (mesh->elem_type[tmp_int] == 342)) {
153  /* tetrahedra */
154  if (flag_tetra == 0) {
155  flag_tetra = 1;
156  /* initialize */
157  tetra = (Tetra *)HECMW_malloc(sizeof(Tetra));
158  vertex_hash_table = (Hash_vertex *)HECMW_calloc(
159  mesh->n_node * 2, sizeof(Hash_vertex));
160  tetra_point = (Tetra_point *)HECMW_malloc(sizeof(Tetra_point));
161  head_patch_tetra =
163  if ((vertex_hash_table == NULL) || (tetra == NULL) ||
164  (tetra_point == NULL) || (head_patch_tetra == NULL))
165  HECMW_vis_memory_exit("initialize tetra");
166  for (j = 0; j < mesh->n_node * 2; j++) {
167  vertex_hash_table[j].ident = 0;
168  vertex_hash_table[j].next_vertex = NULL;
169  }
170  tetra_point->ident = 0;
171  head_patch_tetra->num_patch = 0;
172  }
173  get_tetra_data(sff, mesh, data, tmp_int, tetra, tn_component);
174  if (sff->surface_style == 3) sff->iso_value = 0.0;
175  find_intersection_tetra(tetra, sff->iso_value, tetra_point,
176  head_patch_tetra, vertex_hash_table);
177  }
178  }
179  if (flag_tetra == 1) {
180  num_nh_verts = tetra_point->ident;
181  num_nh_patch = head_patch_tetra->num_patch;
182  HECMW_free(tetra);
183  for (j = 0; j < mesh->n_node * 2; j++) {
184  h1 = vertex_hash_table[j].next_vertex;
185  for (i = 0; i < vertex_hash_table[j].ident; i++) {
186  h2 = h1->next_vertex;
187  HECMW_free(h1);
188  h1 = h2;
189  }
190  }
191  HECMW_free(vertex_hash_table);
192  }
193 
194  if (flag_hexa > 0) {
195  mfree(alpha_cube.isosurf);
196  mfree(beta_cube.isosurf);
197  mfree(CS_verts_tail);
198  mfree(CS_verts_refer);
199  mfree(CS_polys_tail);
200 
201  *sum_v = sum_verts;
202  *sum_t = sum_table;
203  HECMW_free(cell);
204 
205  CS_polys = *CS_polys_head;
206 
207  sum_polys = 0;
208 
209  while (CS_polys->plist != NULL) {
210  switch (CS_polys->type) {
211  case 0:
212  sum_polys++;
213  break;
214  case 1:
215  sum_polys++;
216  break;
217  case 2:
218  sum_polys += CS_polys->plist[0] - 2;
219  break;
220  }
221  CS_polys = CS_polys->nextpolygon;
222  }
223  }
224  /*sum_polys=sum_polys*2;*/
225  if ((sum_verts + num_nh_verts) > 0) {
226  result[sf_i].n_vertex = sum_verts + num_nh_verts;
227  result[sf_i].n_patch = sum_polys + num_nh_patch;
228  result[sf_i].vertex =
229  (double *)HECMW_calloc(result[sf_i].n_vertex * 3, sizeof(double));
230  result[sf_i].patch =
231  (int *)HECMW_calloc(result[sf_i].n_patch * 3, sizeof(int));
232  result[sf_i].color =
233  (double *)HECMW_calloc(result[sf_i].n_vertex, sizeof(double));
234  if ((result[sf_i].vertex == NULL) || (result[sf_i].patch == NULL) ||
235  (result[sf_i].color == NULL))
236  HECMW_vis_memory_exit("result");
237  }
238  mm = 0;
239  if (sum_verts > 0) {
240  /* make main vertex table of CS */
241  for (i = 0; i < sum_table; i++) {
242  CS_verts_tmp = CS_verts = CS_verts_head[i];
243  j = 0;
244  while (CS_verts->ident != 0) {
245  /* verts_geom[CS_verts->ident] = CS_verts->geom;
246 verts_field[CS_verts->ident] = CS_verts->field;
247 verts_color[CS_verts->ident] = CS_verts->cdata;
248 
249 fprintf(vfile, " %d %lf %lf %lf\n", *tvertex+CS_verts->ident,
250 verts_geom[CS_verts->ident].x,
251 verts_geom[CS_verts->ident].y,
252 verts_geom[CS_verts->ident].z);
253  */
254  result[sf_i].vertex[mm * 3] = CS_verts->geom.x;
255  result[sf_i].vertex[mm * 3 + 1] = CS_verts->geom.y;
256  result[sf_i].vertex[mm * 3 + 2] = CS_verts->geom.z;
257  result[sf_i].color[mm] = CS_verts->cdata;
258  mm++;
259  CS_verts = CS_verts->nextpoint;
260  if (!((++j) % VERTEX_PACK)) {
261  mfree(CS_verts_tmp);
262  CS_verts_tmp = CS_verts;
263  }
264  }
265  mfree(CS_verts_tmp);
266  }
267  mfree(CS_verts_head);
268 
269  /* make polygon table and decide vertex ID
270 of each object (alpha,beta,cross) */
271  /* trilist=(Triangle *)HECMW_calloc(sum_polys+1,sizeof(Triangle));
272  */
273  CS_polys_tmp = CS_polys = *CS_polys_head;
274  i = 0;
275  poly_num = 1;
276  minus_patch = 0;
277 
278  while (CS_polys->plist != NULL) {
279  switch (CS_polys->type) {
280  case 0:
281  /* fprintf(pfile, "%d ", poly_num+(*tpatch));
282  */
283  k = -1;
284  for (j = 1; j <= CS_polys->plist[0]; j++) {
285  k++;
286  /* fprintf(pfile, "%d ",
287 (*tvertex)+CS_polys->plist[j]);
288 
289 trilist[poly_num -1].vertex[k]=CS_polys->plist[j];
290  */
291  if ((sff->output_type == 1) || (sff->output_type == 2))
292  result[sf_i].patch[(poly_num - 1) * 3 + k] =
293  *tvertex + CS_polys->plist[j];
294  else
295  result[sf_i].patch[(poly_num - 1) * 3 + k] = CS_polys->plist[j];
296 
297  tmp_data[k * 3] =
298  result[sf_i].vertex[(CS_polys->plist[j] - 1) * 3];
299  tmp_data[k * 3 + 1] =
300  result[sf_i].vertex[(CS_polys->plist[j] - 1) * 3 + 1];
301  tmp_data[k * 3 + 2] =
302  result[sf_i].vertex[(CS_polys->plist[j] - 1) * 3 + 2];
303  }
304  if (((fabs(tmp_data[0] - tmp_data[3]) < EPSILON) &&
305  (fabs(tmp_data[1] - tmp_data[4]) < EPSILON) &&
306  (fabs(tmp_data[2] - tmp_data[5]) < EPSILON)) ||
307  ((fabs(tmp_data[0] - tmp_data[6]) < EPSILON) &&
308  (fabs(tmp_data[1] - tmp_data[7]) < EPSILON) &&
309  (fabs(tmp_data[2] - tmp_data[8]) < EPSILON)) ||
310  ((fabs(tmp_data[6] - tmp_data[3]) < EPSILON) &&
311  (fabs(tmp_data[7] - tmp_data[4]) < EPSILON) &&
312  (fabs(tmp_data[8] - tmp_data[5]) < EPSILON)))
313  minus_patch++;
314  else
315  poly_num++;
316 
317  break;
318  }
319 
320  CS_polys = CS_polys->nextpolygon;
321  if (!((++i) % POLYGON_PACK)) {
322  mfree(CS_polys_tmp->plist);
323 
324  mfree(CS_polys_tmp);
325  CS_polys_tmp = CS_polys;
326  }
327  }
328  /*#ifdef DEBUG
329 fprintf(stderr, "the previous patch num is %d now is %d\n",
330 result[sf_i].n_patch, result[sf_i].n_patch-minus_patch);
331 #endif
332  */
333  result[sf_i].n_patch -= minus_patch;
334 
335  mfree(CS_polys_tmp);
336  }
337  if (num_nh_verts > 0) {
338  p1 = tetra_point->nextpoint;
339  for (i = 0; i < tetra_point->ident; i++) {
340  for (j = 0; j < 3; j++)
341  result[sf_i].vertex[(sum_verts + p1->ident) * 3 + j] = p1->geom[j];
342  result[sf_i].color[sum_verts + p1->ident] = p1->cdata;
343  p2 = p1;
344  p1 = p1->nextpoint;
345  HECMW_free(p2);
346  }
347  HECMW_free(tetra_point);
348  }
349  if (num_nh_patch > 0) {
350  t1 = head_patch_tetra->patch_link;
351  for (i = 0; i < head_patch_tetra->num_patch; i++) {
352  for (j = 0; j < 3; j++) {
353  if (sff->output_type == 3)
354  result[sf_i].patch[(sum_polys - minus_patch + i) * 3 + j] =
355  t1->patch[j] + 1 + sum_verts;
356  else
357  result[sf_i].patch[(sum_polys - minus_patch + i) * 3 + j] =
358  *tvertex + t1->patch[j] + 1 + sum_verts;
359  }
360  t2 = t1;
361  t1 = t1->next_patch;
362  HECMW_free(t2);
363  }
364  HECMW_free(head_patch_tetra);
365  }
366 
367  /*
368 fprintf(stderr, "On surface %d PE %d: n_vertex is %d n_patch is %d\n", sf_i,
369 mynode, result[sf_i].n_vertex, result[sf_i].n_patch);
370  */
371  if (result[sf_i].n_vertex > 0) {
372  *minc = *maxc = result[sf_i].color[0];
373  for (i = 1; i <= result[sf_i].n_vertex; i++) {
374  if (result[sf_i].color[i - 1] < (*minc))
375  (*minc) = result[sf_i].color[i - 1];
376  if (result[sf_i].color[i - 1] > (*maxc))
377  (*maxc) = result[sf_i].color[i - 1];
378  }
379  /*
380 #ifdef DEBUG
381 fprintf(stderr,"On surface %d PE %d: minimum color=%lf maximum color=%lf\n",
382 sf_i, mynode, *minc,*maxc);
383 #endif
384  */
385  }
386  } /* endof if elem_type>300 */
387  else if ((mesh->elem_type[0] > 200) && (mesh->elem_type[0] < 300)) {
388  result[sf_i].n_patch = 0;
389  for (i = 0; i < n_elem; i++) {
390  if (mesh->elem_type[i] == 231)
391  result[sf_i].n_patch++;
392  else if (mesh->elem_type[i] == 241)
393  result[sf_i].n_patch += 2;
394  }
395  result[sf_i].n_vertex = mesh->n_node;
396  result[sf_i].vertex =
397  (double *)HECMW_calloc(mesh->n_node * 3, sizeof(double));
398  result[sf_i].color = (double *)HECMW_calloc(mesh->n_node, sizeof(double));
399  result[sf_i].patch =
400  (int *)HECMW_calloc(result[sf_i].n_patch * 3, sizeof(int));
401  if ((result[sf_i].vertex == NULL) || (result[sf_i].color == NULL) ||
402  (result[sf_i].patch == NULL))
403  HECMW_vis_memory_exit("result: vertex, color and patch");
404  for (i = 0; i < mesh->n_node; i++) {
405  for (j = 0; j < 3; j++)
406  result[sf_i].vertex[i * 3 + j] = mesh->node[i * 3 + j];
407  }
408  if (data->nn_dof[sff->color_comp] == 1) {
409  c_base = 0;
410  for (i = 0; i < sff->color_comp; i++) c_base += data->nn_dof[i];
411  } else if (data->nn_dof[sff->color_comp] > 1) {
412  c_base = 0;
413  for (i = 0; i < sff->color_comp; i++) c_base += data->nn_dof[i];
414  }
415 
416  if ((data->nn_dof[sff->color_comp] > 1) && (sff->color_subcomp == 0)) {
417  for (i = 0; i < mesh->n_node; i++) {
418  result[sf_i].color[i] = 0.0;
419  for (j = 0; j < data->nn_dof[sff->color_comp]; j++) {
420  tmp = data->node_val_item[c_base + i * tn_component + j];
421  result[sf_i].color[i] += tmp * tmp;
422  }
423  result[sf_i].color[i] = sqrt(result[sf_i].color[i]);
424  }
425  }
426 
427  else if (data->nn_dof[sff->color_comp] > 1) {
428  for (i = 0; i < mesh->n_node; i++) {
429  result[sf_i].color[i] = data->node_val_item[c_base + i * tn_component +
430  (sff->color_subcomp - 1)];
431  }
432  } else if (data->nn_dof[sff->color_comp] == 1) {
433  for (i = 0; i < mesh->n_node; i++) {
434  result[sf_i].color[i] = data->node_val_item[c_base + i * tn_component];
435  }
436  }
437  poly_num = 0;
438  for (i = 0; i < n_elem; i++) {
439  if (mesh->elem_type[i] == 231) {
440  for (j = 0; j < 3; j++)
441  result->patch[poly_num * 3 + j] =
442  mesh->elem_node_item[mesh->elem_node_index[i] + j] + *tvertex;
443  poly_num++;
444  } else if (mesh->elem_type[i] == 241) {
445  for (j = 0; j < 3; j++)
446  result->patch[poly_num * 3 + j] =
447  mesh->elem_node_item[mesh->elem_node_index[i] + j] + *tvertex;
448  poly_num++;
449  result->patch[poly_num * 3 + 0] =
450  mesh->elem_node_item[mesh->elem_node_index[i] + 0] + *tvertex;
451  result->patch[poly_num * 3 + 1] =
452  mesh->elem_node_item[mesh->elem_node_index[i] + 2] + *tvertex;
453  result->patch[poly_num * 3 + 2] =
454  mesh->elem_node_item[mesh->elem_node_index[i] + 3] + *tvertex;
455  poly_num++;
456  }
457  }
458  /*
459 fprintf(stderr, "n_vertex is %d n_patch is %d\n", result[sf_i].n_vertex,
460 result[sf_i].n_patch);
461  */
462  if (result[sf_i].n_vertex > 0) {
463  *minc = *maxc = result[sf_i].color[0];
464  for (i = 1; i <= result[sf_i].n_vertex; i++) {
465  if (result[sf_i].color[i - 1] < (*minc))
466  (*minc) = result[sf_i].color[i - 1];
467  if (result[sf_i].color[i - 1] > (*maxc))
468  (*maxc) = result[sf_i].color[i - 1];
469  }
470  /*
471 #ifdef DEBUG
472 fprintf(stderr,"On surface %d PE %d: minimum color=%lf maximum color=%lf\n",
473 sf_i, mynode, *minc,*maxc);
474 #endif
475  */
476  }
477  }
478 
479  (*tvertex) += result[sf_i].n_vertex;
480  (*tpatch) += result[sf_i].n_patch;
481  /* if(sum_verts>0) {
482  *minv=mincolor;
483  *maxv=maxcolor;
484 }
485 
486 mfree(verts_info);
487 mfree(verts_geom);
488 mfree(verts_field);
489 mfree(verts_color);
490 mfree(trilist);
491  */
492 
493  return (1);
494 }
495 
496 int HECMW_vis_chk_bounds(struct hecmwST_local_mesh *mesh, int *bdflag) {
497  int i;
498  int n_elem;
499 
500  n_elem = mesh->n_elem;
501  for (i = 0; i < n_elem; i++) {
502  *(bdflag + i) = 64;
503  }
504  return 1;
505 }
506 
507 #ifdef old
508 int chk_node_data(struct visual_buf *v, int s_comp, int c_comp) {
509  int *global_node_id;
510  double *shape_data;
511  double *color_data;
512  int imp_node;
513  int s_base, c_base;
514  int i, j, k;
515  int ne;
516  int n_export_node, export_base;
517  int n_import_node, import_base;
518 
519  HECMW_Status stat;
520 
521  s_base = c_base = 0;
522 
523  for (i = 0; i < s_comp; i++) {
524  s_base += v->node.n_free[i] * v->node.n;
525  }
526  for (i = 0; i < c_comp; i++) {
527  c_base += v->node.n_free[i] * v->node.n;
528  }
529 
530  export_base = 0;
531  import_base = 0;
532  for (i = 0; i < v->mesh->n_neighbor_pe; i++) {
533  ne = v->mesh->neighbor_pe[i];
534  n_export_node = v->mesh->export_index[i + 1] - v->mesh->export_index[i];
535  global_node_id = (int *)HECMW_calloc(n_export_node, sizeof(int));
536  shape_data = (double *)HECMW_calloc(n_export_node, sizeof(double));
537  color_data = (double *)HECMW_calloc(n_export_node, sizeof(double));
538  for (j = 0; j < n_export_node; j++) {
539  global_node_id[j] =
540  v->mesh->global_node_id[v->mesh->export_node[export_base + j] - 1];
541  shape_data[j] = (double)*(v->node.data + s_base +
542  v->mesh->export_node[export_base + j] - 1);
543  color_data[j] = (double)*(v->node.data + c_base +
544  v->mesh->export_node[export_base + j] - 1);
545  }
546  HECMW_Send(&n_export_node, 1, HECMW_INT, ne, 0, geofem_app_comm);
547  HECMW_Send(global_node_id, n_export_node, HECMW_INT, ne, 0,
548  geofem_app_comm);
549  HECMW_Send(shape_data, n_export_node, HECMW_DOUBLE, ne, 0, geofem_app_comm);
550  HECMW_Send(color_data, n_export_node, HECMW_DOUBLE, ne, 0, geofem_app_comm);
551 
552  HECMW_free(global_node_id);
553  HECMW_free(shape_data);
554  HECMW_free(color_data);
555  export_base = v->mesh->export_index[i + 1];
556 
557  n_import_node = v->mesh->import_index[i + 1] - v->mesh->import_index[i];
558  HECMW_Recv(&imp_node, 1, HECMW_INT, ne, HECMW_ANY_TAG, geofem_app_comm,
559  &stat);
560 
561  if (imp_node != n_import_node) {
562  GEOFEM_abort(711, "chk_node_data error\n");
563  }
564  global_node_id = (int *)HECMW_calloc(n_import_node, sizeof(int));
565  shape_data = (double *)HECMW_calloc(n_import_node, sizeof(double));
566  color_data = (double *)HECMW_calloc(n_import_node, sizeof(double));
567  HECMW_Recv(global_node_id, n_import_node, HECMW_INT, ne, HECMW_ANY_TAG,
568  geofem_app_comm, &stat);
569  HECMW_Recv(shape_data, n_import_node, HECMW_DOUBLE, ne, HECMW_ANY_TAG,
570  geofem_app_comm, &stat);
571  HECMW_Recv(color_data, n_import_node, HECMW_DOUBLE, ne, HECMW_ANY_TAG,
572  geofem_app_comm, &stat);
573  for (k = import_base; k < import_base + n_import_node; k++) {
574  for (j = 0; j < n_import_node; j++) {
575  if (v->mesh->global_node_id[v->mesh->import_node[k] - 1] ==
576  global_node_id[j]) {
577  v->node.data[s_base + v->mesh->import_node[k] - 1] = shape_data[j];
578  v->node.data[c_base + v->mesh->import_node[k] - 1] = color_data[j];
579  break;
580  }
581  }
582  }
583  HECMW_free(global_node_id);
584  HECMW_free(shape_data);
585  HECMW_free(color_data);
586  import_base = v->mesh->import_index[i + 1];
587  }
588 
589  return 1;
590 }
591 #endif
592 
593 /*
594 int chk_bounds(struct visual_buf *vol, int *bdflag)
595 {
596  int i, j, k, l;
597  int bd1, bd2;
598  int n_elem;
599 
600  n_elem = vol->mesh->n_elem;
601  for (i = 0; i < n_elem; i++) {
602  for (j = 0; j < i; j++) {
603  if (*(bdflag + j) < HEX_FACE_INDEX) {
604  bd1 = bd2 = 0;
605  for (k = 0; k < HEX_N_NODE; k++) {
606  for (l = 0; l < HEX_N_NODE; l++) {
607  if ((*(vol->mesh->elem + i + n_elem * k))
608  == (*(vol->mesh->elem + j + n_elem * l))) {
609  bd1 += 1 << k;
610  bd2 += 1 << l;
611  }
612  }
613  }
614  switch (bd1) {
615  case 15: *(bdflag + i) += 1; break;
616  case 102: *(bdflag + i) += 2; break;
617  case 240: *(bdflag + i) += 4; break;
618  case 153: *(bdflag + i) += 8; break;
619  case 204: *(bdflag + i) += 16; break;
620  case 51: *(bdflag + i) += 32; break;
621  default: break;
622  }
623  switch (bd2) {
624  case 15: *(bdflag + j) += 1; break;
625  case 102: *(bdflag + j) += 2; break;
626  case 240: *(bdflag + j) += 4; break;
627  case 153: *(bdflag + j) += 8; break;
628  case 204: *(bdflag + j) += 16; break;
629  case 51: *(bdflag + j) += 32; break;
630  default: break;
631  }
632  }
633 
634  if (*(bdflag + i) == HEX_FACE_INDEX) break;
635  }
636  }
637 
638  return 1;
639 
640 }
641 
642  */
643 void find_isoline(int isonum, int sum_polys, double mincolor, double maxcolor,
644  double *vcoord, int *plist, double *vcolor,
645  Isohead *isohead) {
646  int i, j, k;
647  double c[3];
648  double isocolor, deltac;
649  Fgeom g[3];
650 
651  if (isonum <= 0) {
652  fprintf(stderr, "isonumber input wrong\n");
653  exit(0);
654  }
655  deltac = (maxcolor - mincolor) / (isonum + 1);
656  for (k = 0; k < isonum; k++) {
657  isocolor = mincolor + (k + 1) * deltac;
658  for (i = 0; i < sum_polys; i++) {
659  for (j = 0; j < 3; j++) {
660  c[j] = vcolor[plist[i * 3 + j] - 1];
661  g[j].x = vcoord[(plist[i * 3 + j] - 1) * 3];
662  g[j].y = vcoord[(plist[i * 3 + j] - 1) * 3 + 1];
663  g[j].z = vcoord[(plist[i * 3 + j] - 1) * 3 + 2];
664  }
665  line_find(isocolor, c, g, k, isohead);
666  }
667  }
668 }
669 
670 int find_line_segment(double f[3][3], double c[3], double isocolor,
671  double iso_p[6]) {
672  int j, m, j1;
673  int pnum, flag;
674 
675  flag = 0;
676  pnum = -1;
677  for (j = 0; j < 3; j++) {
678  j1 = j + 1;
679  if (j1 == 3) j1 = 0;
680  if ((fabs(c[j] - c[j1]) < 0.0000001) &&
681  (fabs(c[j] - isocolor) < 0.0000001)) {
682  /*this edge is isoline*/
683  flag = 1;
684 
685  for (m = 0; m < 3; m++) iso_p[m] = f[j][m];
686  for (m = 0; m < 3; m++) iso_p[m + 3] = f[j1][m];
687  return 1;
688  } else if (((c[j] >= isocolor) && (c[j1] < isocolor)) ||
689  ((c[j] < isocolor) && (c[j1] >= isocolor))) {
690  pnum++;
691  for (m = 0; m < 3; m++)
692  iso_p[pnum * 3 + m] =
693  f[j][m] + (isocolor - c[j]) / (c[j1] - c[j]) * (f[j1][m] - f[j][m]);
694  }
695  }
696  if (pnum == 1) flag = 1;
697 
698  return flag;
699 }
700 
701 void line_find(double isocolor, double c[3], Fgeom g[3], int k,
702  Isohead *isohead) {
703  Isoline *p1, *p2;
704  int j, m, j1;
705  int pnum;
706  Fgeom isopoint[2];
707 
708  pnum = -1;
709  for (j = 0; j < 2; j++) {
710  isopoint[j].x = isopoint[j].y = isopoint[j].z = 0.0;
711  }
712  for (j = 0; j < 3; j++) {
713  j1 = j + 1;
714  if (j1 == 3) j1 = 0;
715  if ((fabs(c[j] - c[j1]) < 0.0000001) &&
716  (fabs(c[j] - isocolor) < 0.0000001)) {
717  /*this edge is isoline*/
718  isohead[k].linenum++;
719  p1 = isohead[k].nextline;
720  p2 = (Isoline *)HECMW_malloc(sizeof(Isoline));
721 
722  p2->point[0].x = g[j].x;
723  p2->point[0].y = g[j].y;
724  p2->point[0].z = g[j].z;
725  p2->point[1].x = g[j1].x;
726  p2->point[1].y = g[j1].y;
727  p2->point[1].z = g[j1].z;
728 
729  p2->nextline = p1;
730  isohead[k].nextline = p2;
731  return;
732  }
733 
734  else if (((c[j] >= isocolor) && (c[j1] < isocolor)) ||
735  ((c[j] < isocolor) && (c[j1] >= isocolor))) {
736  pnum++;
737  isopoint[pnum].x =
738  g[j].x + (isocolor - c[j]) / (c[j1] - c[j]) * (g[j1].x - g[j].x);
739  isopoint[pnum].y =
740  g[j].y + (isocolor - c[j]) / (c[j1] - c[j]) * (g[j1].y - g[j].y);
741  isopoint[pnum].z =
742  g[j].z + (isocolor - c[j]) / (c[j1] - c[j]) * (g[j1].z - g[j].z);
743  }
744  }
745  if (pnum == 1) {
746  isohead[k].linenum++;
747  p1 = isohead[k].nextline;
748  p2 = (Isoline *)HECMW_malloc(sizeof(Isoline));
749  for (m = 0; m < 2; m++) {
750  p2->point[m].x = isopoint[m].x;
751  p2->point[m].y = isopoint[m].y;
752  p2->point[m].z = isopoint[m].z;
753  }
754  p2->nextline = p1;
755  isohead[k].nextline = p2;
756  }
757 
758  return;
759 }
760 
761 void isoline_free(int isonum, Isohead *isohead) {
762  Isoline *p1, *p2;
763  int i;
764  for (i = 0; i < isonum; i++) {
765  p1 = isohead[i].nextline;
766  while (p1 != NULL) {
767  p2 = p1;
768  p1 = p1->nextline;
769  HECMW_free(p2);
770  }
771  }
772  HECMW_free(isohead);
773  return;
774 }
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
if(!(yy_init))
int HECMW_ANY_TAG
struct hecmwST_local_mesh * mesh
Definition: hecmw_repart.h:71
#define NULL
#define HECMW_calloc(nmemb, size)
Definition: hecmw_malloc.h:21
#define HECMW_free(ptr)
Definition: hecmw_malloc.h:24
#define HECMW_malloc(size)
Definition: hecmw_malloc.h:20
#define HEX_NODE_INDEX
Definition: hecmw_repart.h:22
#define TABLE_SIZE
#define POLYGON_PACK
#define VERTEX_PACK
int get_data(Surface *sff, struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int elemID, Cell *cell, int tn_component)
int make_tile(struct hecmwST_local_mesh *mesh, Cell *cell, double fvalue, int CS_type, Cube_polygons *cube_polys, int disamb_flag)
#define EPSILON
Polygon * alloc_polygons(int num)
Point * alloc_verts(int num)
void HECMW_vis_memory_exit(char *var)
void mfree(void *pointer)
int merge_vol_iso(int iso_type, Cell *cell, double falpha, Cube_polygons *alpha_cube, double fbeta, Cube_polygons *beta_cube, int bdflag, int *sum_verts, Point **CS_verts_tail, Point **CS_verts_refer, Point **CS_verts_head, Polygon **CS_polys_tail)
void isoline_free(int isonum, Isohead *isohead)
int HECMW_vis_surface_compute(Surface *sff, struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int *bdflag, int *sum_v, int *sum_t, int *tvertex, int *tpatch, double *minc, double *maxc, Result *result, int sf_i, int mynode, HECMW_Comm VIS_COMM)
int find_line_segment(double f[3][3], double c[3], double isocolor, double iso_p[6])
int HECMW_vis_chk_bounds(struct hecmwST_local_mesh *mesh, int *bdflag)
void line_find(double isocolor, double c[3], Fgeom g[3], int k, Isohead *isohead)
void find_isoline(int isonum, int sum_polys, double mincolor, double maxcolor, double *vcoord, int *plist, double *vcolor, Isohead *isohead)
void find_intersection_tetra(Tetra *tetra, double isovalue, Tetra_point *tetra_point, Head_patch_tetra *head_patch_tetra, Hash_vertex *vertex_hash_table)
int get_tetra_data(Surface *sff, struct hecmwST_local_mesh *mesh, struct hecmwST_result_data *data, int elemID, Tetra *tetra, int tn_component)
CNFData data
struct _hash_vertex_struct * next_vertex
struct _isoline_struct * nextline
struct _isoline_struct * nextline
struct _patch_tetra_struct * next_patch
struct _point_struct * nextpoint
struct _point_tetra_struct * nextpoint
struct _polygon_struct * nextpolygon
long long * elem_node_index
Definition: hecmw_struct.h:204